diff options
author | luigi1111 <luigi1111w@gmail.com> | 2024-01-18 18:00:25 -0500 |
---|---|---|
committer | luigi1111 <luigi1111w@gmail.com> | 2024-01-18 18:00:25 -0500 |
commit | 5d3679c43c8003c9dc917630685675bd5c2f3949 (patch) | |
tree | 37477df2235f89808df5f15681faee03e971a59d /tests/unit_tests | |
parent | Merge pull request #9061 (diff) | |
parent | serialization: fix infinite loops and clean up dispatching (diff) | |
download | monero-5d3679c43c8003c9dc917630685675bd5c2f3949.tar.xz |
Merge pull request #9069
a11e03a serialization: fix infinite loops and clean up dispatching (jeffro256)
Diffstat (limited to 'tests/unit_tests')
-rw-r--r-- | tests/unit_tests/serialization.cpp | 39 |
1 files changed, 34 insertions, 5 deletions
diff --git a/tests/unit_tests/serialization.cpp b/tests/unit_tests/serialization.cpp index 49f1dc310..ab81acefc 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()); +} |