Переглянути джерело

fixed a bug of variant (missing remove_cvref)

cbor
Ludovic 'Archivist' Lagouardette 4 роки тому
джерело
коміт
694827d2c4
3 змінених файлів з 88 додано та 2 видалено
  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 Переглянути файл

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

+ 1
- 1
include/gp/variant.hpp Переглянути файл

@ -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>
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>;
dtor = gp::function<void(void*)>([](void* thing){

+ 86
- 0
tests/cbor_test.cpp Переглянути файл

@ -105,6 +105,92 @@ 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::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};
data = gp::cbor_number(128);

Завантаження…
Відмінити
Зберегти