aboutsummaryrefslogtreecommitdiff
path: root/tests/unit_tests
diff options
context:
space:
mode:
authorjeffro256 <jeffro256@tutanota.com>2023-11-17 02:19:45 -0600
committerjeffro256 <jeffro256@tutanota.com>2024-02-08 13:22:33 -0600
commit33e3f72d246ce58336a52c24d5bbb31fdd02600b (patch)
tree5f33b3b646c79a032e9275fd54fecc3db41c938c /tests/unit_tests
parentMerge pull request #9080 (diff)
downloadmonero-33e3f72d246ce58336a52c24d5bbb31fdd02600b.tar.xz
serialization: fix infinite loops and clean up dispatching
Resolves #8687
Diffstat (limited to 'tests/unit_tests')
-rw-r--r--tests/unit_tests/serialization.cpp39
1 files changed, 34 insertions, 5 deletions
diff --git a/tests/unit_tests/serialization.cpp b/tests/unit_tests/serialization.cpp
index 87571e5b5..0fdd83285 100644
--- a/tests/unit_tests/serialization.cpp
+++ b/tests/unit_tests/serialization.cpp
@@ -59,9 +59,7 @@ struct Struct
};
template <class Archive>
-struct serializer<Archive, Struct>
-{
- static bool serialize(Archive &ar, Struct &s) {
+static bool do_serialize(Archive &ar, Struct &s) {
ar.begin_object();
ar.tag("a");
ar.serialize_int(s.a);
@@ -71,8 +69,7 @@ struct serializer<Archive, Struct>
ar.serialize_blob(s.blob, sizeof(s.blob));
ar.end_object();
return true;
- }
-};
+}
struct Struct1
{
@@ -122,6 +119,23 @@ bool try_parse(const string &blob)
return serialization::parse_binary(blob, s1);
}
+namespace example_namespace
+{
+ struct ADLExampleStruct
+ {
+ std::string msg;
+ };
+
+ template <class Archive>
+ static bool do_serialize(Archive &ar, ADLExampleStruct &aes)
+ {
+ ar.begin_object();
+ FIELD_N("custom_fieldname", aes.msg);
+ ar.end_object();
+ return ar.good();
+ }
+}
+
TEST(Serialization, BinaryArchiveInts) {
uint64_t x = 0xff00000000, x1;
@@ -1178,3 +1192,18 @@ TEST(Serialization, difficulty_type)
ASSERT_EQ(v_original, v_unserialized);
}
+
+TEST(Serialization, adl_free_function)
+{
+ std::stringstream ss;
+ json_archive<true> ar(ss);
+
+ const std::string msg = "Howdy, World!";
+ example_namespace::ADLExampleStruct aes{msg};
+
+ ASSERT_TRUE(serialization::serialize(ar, aes));
+
+ // VVVVVVVVVVVVVVVVVVVVVVVVVV weird string serialization artifact
+ const std::string expected = "{\"custom_fieldname\": " + std::to_string(msg.size()) + '"' + epee::string_tools::buff_to_hex_nodelimer(msg) + "\"}";
+ EXPECT_EQ(expected, ss.str());
+}