Browse Source

cbor is mostly tested

cbor
Ludovic 'Archivist' Lagouardette 3 years ago
parent
commit
bb661ec363
1 changed files with 56 additions and 0 deletions
  1. +56
    -0
      tests/cbor_test.cpp

+ 56
- 0
tests/cbor_test.cpp View File

@ -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<std::byte> 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<gp::pair<gp::cbor_value, gp::cbor_value>> meta{alloc};
gp::repeat(2, [&](){
meta.push_back(gp::make_pair(data, data));
});
data = meta;
gp::array<std::byte, 31> serialized;
gp::array<std::byte, 31> 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;
}

Loading…
Cancel
Save