From 03f9bc2185cf4c105a4a2df26226993fc4c075cd Mon Sep 17 00:00:00 2001 From: Daniel Parker Date: Thu, 27 Jul 2023 11:39:26 -0400 Subject: [PATCH] Add cbor test with result allocator --- test/cbor/src/encode_cbor_tests.cpp | 34 ++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/test/cbor/src/encode_cbor_tests.cpp b/test/cbor/src/encode_cbor_tests.cpp index d5230df273..7933a9ccbf 100644 --- a/test/cbor/src/encode_cbor_tests.cpp +++ b/test/cbor/src/encode_cbor_tests.cpp @@ -186,7 +186,39 @@ TEST_CASE("encode_cbor overloads") template using MyScopedAllocator = std::scoped_allocator_adaptor>; -TEST_CASE("encode_cbor allocator_set overloads") +using custom_json = basic_json>; + +TEST_CASE("encode_cbor allocator_set") +{ + MyScopedAllocator result_alloc(1); + MyScopedAllocator temp_alloc(2); + + auto alloc_set = combine_allocators(result_alloc, temp_alloc); + + SECTION("json, stream") + { + custom_json person(json_object_arg, result_alloc); + person.try_emplace("name", "John Smith"); + + std::string s; + std::stringstream ss(s); + cbor::encode_cbor(alloc_set, person, ss); + custom_json other = cbor::decode_cbor(alloc_set,ss); + CHECK(other == person); + } + /* SECTION("custom, stream") + { + ns::Person person{"John Smith"}; + + std::string s; + std::stringstream ss(s); + cbor::encode_cbor(alloc_set, person, ss); + ns::Person other = cbor::decode_cbor(alloc_set,ss); + CHECK(other.name == person.name); + }*/ +} + +TEST_CASE("encode_cbor allocator_set for temp only") { MyScopedAllocator temp_alloc(1);