text
stringlengths 0
2.2M
|
---|
message x;
|
auto buf1 = serialize(msg);
|
deserialize(buf1, x);
|
CHECK_EQ(to_string(msg), to_string(x));
|
CHECK(is_message(x).equal(i32, i64, ts, te, str, rs));
|
// serialize fully dynamic message again (do another roundtrip)
|
message y;
|
auto buf2 = serialize(x);
|
CHECK_EQ(buf1, buf2);
|
deserialize(buf2, y);
|
CHECK_EQ(to_string(msg), to_string(y));
|
CHECK(is_message(y).equal(i32, i64, ts, te, str, rs));
|
CHECK_EQ(to_string(recursive), to_string(roundtrip(recursive, false)));
|
}
|
CAF_TEST(multiple_messages) {
|
auto m = make_message(rs, te);
|
auto buf = serialize(te, m, msg);
|
test_enum t;
|
message m1;
|
message m2;
|
deserialize(buf, t, m1, m2);
|
CHECK_EQ(std::make_tuple(t, to_string(m1), to_string(m2)),
|
std::make_tuple(te, to_string(m), to_string(msg)));
|
CHECK(is_message(m1).equal(rs, te));
|
CHECK(is_message(m2).equal(i32, i64, ts, te, str, rs));
|
}
|
CAF_TEST(long_sequences) {
|
byte_buffer data;
|
binary_serializer sink{nullptr, data};
|
size_t n = std::numeric_limits<uint32_t>::max();
|
CHECK(sink.begin_sequence(n));
|
CHECK(sink.end_sequence());
|
binary_deserializer source{nullptr, data};
|
size_t m = 0;
|
CHECK(source.begin_sequence(m));
|
CHECK(source.end_sequence());
|
CHECK_EQ(n, m);
|
}
|
CAF_TEST(non_empty_vector) {
|
MESSAGE("deserializing into a non-empty vector overrides any content");
|
std::vector<int> foo{1, 2, 3};
|
std::vector<int> bar{0};
|
auto buf = serialize(foo);
|
deserialize(buf, bar);
|
CHECK_EQ(foo, bar);
|
}
|
CAF_TEST(variant_with_tree_types) {
|
MESSAGE("deserializing into a non-empty vector overrides any content");
|
using test_variant = variant<int, double, std::string>;
|
test_variant x{42};
|
CHECK_EQ(x, roundtrip(x, false));
|
x = 12.34;
|
CHECK_EQ(x, roundtrip(x, false));
|
x = std::string{"foobar"};
|
CHECK_EQ(x, roundtrip(x, false));
|
}
|
// -- our vector<bool> serialization packs into an uint64_t. Hence, the
|
// critical sizes to test are 0, 1, 63, 64, and 65.
|
CAF_TEST(bool_vector_size_0) {
|
std::vector<bool> xs;
|
CHECK_EQ(deep_to_string(xs), "[]");
|
CHECK_EQ(xs, roundtrip(xs));
|
CHECK_EQ(xs, msg_roundtrip(xs));
|
}
|
CAF_TEST(bool_vector_size_1) {
|
std::vector<bool> xs{true};
|
CHECK_EQ(deep_to_string(xs), "[true]");
|
CHECK_EQ(xs, roundtrip(xs));
|
CHECK_EQ(xs, msg_roundtrip(xs));
|
}
|
CAF_TEST(bool_vector_size_2) {
|
std::vector<bool> xs{true, true};
|
CHECK_EQ(deep_to_string(xs), "[true, true]");
|
CHECK_EQ(xs, roundtrip(xs));
|
CHECK_EQ(xs, msg_roundtrip(xs));
|
}
|
CAF_TEST(bool_vector_size_63) {
|
std::vector<bool> xs;
|
for (int i = 0; i < 63; ++i)
|
xs.push_back(i % 3 == 0);
|
CHECK_EQ(
|
deep_to_string(xs),
|
"[true, false, false, true, false, false, true, false, false, true, false, "
|
"false, true, false, false, true, false, false, true, false, false, true, "
|
"false, false, true, false, false, true, false, false, true, false, false, "
|
"true, false, false, true, false, false, true, false, false, true, false, "
|
"false, true, false, false, true, false, false, true, false, false, true, "
|
"false, false, true, false, false, true, false, false]");
|
CHECK_EQ(xs, roundtrip(xs));
|
CHECK_EQ(xs, msg_roundtrip(xs));
|
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.