1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
|
// This file is part of CAF, the C++ Actor Framework. See the file LICENSE in
// the main distribution directory for license terms and copyright or visit
// https://github.com/actor-framework/actor-framework/blob/master/LICENSE.
#define CAF_SUITE cow_tuple
#include "caf/cow_tuple.hpp"
#include "core-test.hpp"
using std::make_tuple;
using std::string;
using std::tuple;
using namespace caf;
CAF_TEST(default_construction) {
cow_tuple<string, string> x;
CHECK_EQ(x.unique(), true);
CHECK_EQ(get<0>(x), "");
CHECK_EQ(get<1>(x), "");
}
CAF_TEST(value_construction) {
cow_tuple<int, int> x{1, 2};
CHECK_EQ(x.unique(), true);
CHECK_EQ(get<0>(x), 1);
CHECK_EQ(get<1>(x), 2);
CHECK_EQ(x, make_cow_tuple(1, 2));
}
CAF_TEST(copy_construction) {
cow_tuple<int, int> x{1, 2};
cow_tuple<int, int> y{x};
CHECK_EQ(x, y);
CHECK_EQ(x.ptr(), y.ptr());
CHECK_EQ(x.unique(), false);
CHECK_EQ(y.unique(), false);
}
CAF_TEST(move_construction) {
cow_tuple<int, int> x{1, 2};
cow_tuple<int, int> y{std::move(x)};
CHECK_EQ(x.ptr(), nullptr);
CHECK_EQ(y, make_tuple(1, 2));
CHECK_EQ(y.unique(), true);
}
CAF_TEST(copy_assignment) {
cow_tuple<int, int> x{1, 2};
cow_tuple<int, int> y{3, 4};
CHECK_NE(x, y);
x = y;
CHECK_EQ(x, y);
CHECK_EQ(x.ptr(), y.ptr());
CHECK_EQ(x.unique(), false);
CHECK_EQ(y.unique(), false);
}
CAF_TEST(move_assignment) {
cow_tuple<int, int> x{1, 2};
cow_tuple<int, int> y{3, 4};
CHECK_NE(x, y);
x = std::move(y);
CHECK_EQ(x, make_tuple(3, 4));
CHECK_EQ(x.unique(), true);
}
CAF_TEST(make_cow_tuple) {
cow_tuple<int, int> x{1, 2};
auto y = make_cow_tuple(1, 2);
CHECK_EQ(x, y);
CHECK_EQ(x.unique(), true);
CHECK_EQ(y.unique(), true);
}
CAF_TEST(unsharing) {
auto x = make_cow_tuple(string{"old"}, string{"school"});
auto y = x;
CHECK_EQ(x.unique(), false);
CHECK_EQ(y.unique(), false);
get<0>(y.unshared()) = "new";
CHECK_EQ(x.unique(), true);
CHECK_EQ(y.unique(), true);
CHECK_EQ(x.data(), make_tuple("old", "school"));
CHECK_EQ(y.data(), make_tuple("new", "school"));
}
CAF_TEST(to_string) {
auto x = make_cow_tuple(1, string{"abc"});
CHECK_EQ(deep_to_string(x), R"__([1, "abc"])__");
}
BEGIN_FIXTURE_SCOPE(test_coordinator_fixture<>)
CAF_TEST(serialization) {
auto x = make_cow_tuple(1, 2, 3);
auto y = roundtrip(x);
CHECK_EQ(x, y);
CHECK_EQ(x.unique(), true);
CHECK_EQ(y.unique(), true);
CHECK_NE(x.ptr(), y.ptr());
}
END_FIXTURE_SCOPE()
|