Browse Source

fixed a bug of variant (missing remove_cvref)

cbor
Ludovic 'Archivist' Lagouardette 3 years ago
parent
commit
694827d2c4
3 changed files with 88 additions and 2 deletions
  1. +1
    -1
      include/gp/enveloppe/cbor.hpp
  2. +1
    -1
      include/gp/variant.hpp
  3. +86
    -0
      tests/cbor_test.cpp

+ 1
- 1
include/gp/enveloppe/cbor.hpp View File

@ -147,7 +147,7 @@ namespace gp {
template<typename T> template<typename T>
using cbor_composite = gp::fixed_variant< using cbor_composite = gp::fixed_variant<
undefined_t,
gp::undefined_t,
cbor_number, cbor_number,
gp::vector<std::byte>, gp::vector<std::byte>,
bool, bool,

+ 1
- 1
include/gp/variant.hpp View File

@ -31,7 +31,7 @@ namespace gp{
template<typename U, std::enable_if_t<list_contains_class<gp::remove_cvref_t<U>,T...>::value,int> = 0> template<typename U, std::enable_if_t<list_contains_class<gp::remove_cvref_t<U>,T...>::value,int> = 0>
fixed_variant(U& value) fixed_variant(U& value)
: index{r_index_of<U, T...>::value}
: index{r_index_of<gp::remove_cvref_t<U>, T...>::value}
{ {
using actual = gp::remove_cvref_t<U>; using actual = gp::remove_cvref_t<U>;
dtor = gp::function<void(void*)>([](void* thing){ dtor = gp::function<void(void*)>([](void* thing){

+ 86
- 0
tests/cbor_test.cpp View File

@ -105,6 +105,92 @@ struct cbor_test : public test_scaffold {
gp_config::assertion(serialized.begin() != ret_it, "could not encode"); gp_config::assertion(serialized.begin() != ret_it, "could not encode");
gp_config::assertion(serialized == serialized_manual, "data did not serialize correctly"); gp_config::assertion(serialized == serialized_manual, "data did not serialize correctly");
} }
{
gp::cbor_value data{alloc};
data = bool(false);
gp::array<std::byte, 1> serialized;
gp::array<std::byte, 1> serialized_manual{
std::byte(0b11100000+20)
};
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");
}
{
gp::cbor_value data{alloc};
data = bool(true);
gp::array<std::byte, 1> serialized;
gp::array<std::byte, 1> serialized_manual{
std::byte(0b11100000+21)
};
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");
}
{
gp::cbor_value data{gp::nullopt, alloc};
gp::array<std::byte, 1> serialized;
gp::array<std::byte, 1> serialized_manual{
std::byte(0b11100000+22)
};
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");
}
{
gp::cbor_value data{alloc};
gp::array<std::byte, 1> serialized;
gp::array<std::byte, 1> serialized_manual{
std::byte(0b11100000+23)
};
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");
}
{ {
gp::cbor_value data{alloc}; gp::cbor_value data{alloc};
data = gp::cbor_number(128); data = gp::cbor_number(128);

Loading…
Cancel
Save