瀏覽代碼

cbor is mostly tested

cbor
Ludovic 'Archivist' Lagouardette 4 年之前
父節點
當前提交
bb661ec363
共有 1 個檔案被更改,包括 56 行新增0 行删除
  1. +56
    -0
      tests/cbor_test.cpp

+ 56
- 0
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<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…
取消
儲存