General Purpose library for Freestanding C++ and POSIX systems
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

67 řádky
2.0 KiB

  1. #include <gp/allocator/arena.hpp>
  2. #include <gp/array.hpp>
  3. #include <gp/enveloppe/cbor.hpp>
  4. #include "test_scaffold.h"
  5. struct cbor_test : public test_scaffold {
  6. cbor_test() {
  7. name = __FILE__ ":1";
  8. }
  9. virtual int run() {
  10. gp::array<char, 4096> store;
  11. gp::arena alloc{&*store.begin(), store.size()};
  12. using some_int = gp::fixed_variant<int, unsigned int, long long>;
  13. {
  14. some_int a{16};
  15. some_int b = 12u;
  16. b = a;
  17. gp_config::assertion(b.is_a<int>(), "b got wrong type assigned");
  18. }
  19. {
  20. some_int a{16u};
  21. some_int b = a;
  22. gp_config::assertion(b.is_a<unsigned int>(), "b got wrong type assigned");
  23. gp_config::assertion(b.value<unsigned int>() == 16, "b got wrong value assigned");
  24. }
  25. {
  26. some_int a{16u};
  27. some_int b = gp::move(a);
  28. gp_config::assertion(b.is_a<unsigned int>(), "b got wrong type assigned");
  29. gp_config::assertion(b.value<unsigned int>() == 16, "b got wrong value assigned");
  30. }
  31. {
  32. some_int a{16u};
  33. some_int b;
  34. new(&b) some_int(a);
  35. gp_config::assertion(b.is_a<unsigned int>(), "b got wrong type assigned");
  36. gp_config::assertion(b.value<unsigned int>() == 16, "b got wrong value assigned");
  37. }
  38. {
  39. some_int a{16u};
  40. some_int b;
  41. new(&b) some_int(gp::move(a));
  42. gp_config::assertion(b.is_a<unsigned int>(), "b got wrong type assigned");
  43. gp_config::assertion(b.value<unsigned int>() == 16, "b got wrong value assigned");
  44. }
  45. {
  46. gp::vector<some_int> vec{alloc};
  47. vec.emplace_back(12u);
  48. vec.emplace_back(-16);
  49. gp_config::assertion(vec[0].is_a<unsigned int>(), "vec0 got wrong type assigned");
  50. gp_config::assertion(vec[1].is_a<int>(), "vec1 got wrong type assigned");
  51. }
  52. {
  53. gp::cbor_value data{alloc};
  54. auto gen = data.new_object();
  55. gen.push_back(gp::make_pair(gp::cbor_value{uint8_t(12), alloc}, gp::cbor_value{int32_t(-98), alloc}));
  56. gen.push_back(gp::make_pair(gp::cbor_value{uint8_t(13), alloc}, gp::cbor_value{uint32_t(98), alloc}));
  57. data = gen;
  58. }
  59. return 0;
  60. }
  61. };
  62. append_test dummy_pg5zhr8bv(new cbor_test{});