From bb661ec36302fcfb86291880c5c8c02a5505c48e Mon Sep 17 00:00:00 2001 From: Ludovic 'Archivist' Lagouardette Date: Tue, 20 Oct 2020 16:21:04 +0200 Subject: [PATCH] cbor is mostly tested --- tests/cbor_test.cpp | 56 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/tests/cbor_test.cpp b/tests/cbor_test.cpp index 306ebcf..899fe3e 100644 --- a/tests/cbor_test.cpp +++ b/tests/cbor_test.cpp @@ -473,6 +473,62 @@ struct cbor_test : public test_scaffold { gp_config::assertion(serialized.begin() != ret_it, "could not encode"); gp_config::assertion(serialized == serialized_manual, "data did not serialize correctly"); } + { + gp::vector str{alloc}; + str.reserve(5); + for(auto a : {'h', 'e', 'l', 'l', 'o'}) + str.push_back((std::byte)a); + gp::cbor_value data{alloc}; + data = str; + gp::vector> meta{alloc}; + gp::repeat(2, [&](){ + meta.push_back(gp::make_pair(data, data)); + }); + data = meta; + + + gp::array serialized; + gp::array serialized_manual{ + std::byte(0b10100010), + std::byte(0b01000101), + std::byte('h'), + std::byte('e'), + std::byte('l'), + std::byte('l'), + std::byte('o'), + std::byte(0b01000101), + std::byte('h'), + std::byte('e'), + std::byte('l'), + std::byte('l'), + std::byte('o'), + std::byte(0b01000101), + std::byte('h'), + std::byte('e'), + std::byte('l'), + std::byte('l'), + std::byte('o'), + std::byte(0b01000101), + std::byte('h'), + std::byte('e'), + std::byte('l'), + std::byte('l'), + std::byte('o') + }; + + auto ret_it = data.encode(serialized.as_buffer()); + + gp_config::assertion(serialized.begin() != ret_it, "could not encode"); + gp_config::assertion(serialized == serialized_manual, "data did not serialize correctly"); + + gp::fill(serialized,(std::byte)0); + + auto decoded = gp::cbor_value::decode(alloc, serialized_manual.as_buffer()); + ret_it = decoded.first.encode(serialized.as_buffer()); + + gp_config::assertion(serialized.begin() != ret_it, "could not encode"); + gp_config::assertion(serialized == serialized_manual, "data did not serialize correctly"); + } return 0; }