General Purpose library for Freestanding C++ and POSIX systems
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

65 satır
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. /*gp::cbor_value data{alloc};
  13. auto gen = data.new_object();
  14. gen.push_back(gp::make_pair(gp::cbor_value{uint8_t(12), alloc}, gp::cbor_value{int32_t(-98), alloc}));
  15. gen.push_back(gp::make_pair(gp::cbor_value{uint8_t(13), alloc}, gp::cbor_value{uint32_t(98), alloc}));
  16. data = gen;*/
  17. using some_int = gp::fixed_variant<int, unsigned int, long long>;
  18. {
  19. some_int a{16};
  20. some_int b = 12u;
  21. b = a;
  22. gp_config::assertion(b.is_a<int>(), "b got wrong type assigned");
  23. }
  24. {
  25. some_int a{16u};
  26. some_int b = a;
  27. gp_config::assertion(b.is_a<unsigned int>(), "b got wrong type assigned");
  28. gp_config::assertion(b.value<unsigned int>() == 16, "b got wrong value assigned");
  29. }
  30. {
  31. some_int a{16u};
  32. some_int b = gp::move(a);
  33. gp_config::assertion(b.is_a<unsigned int>(), "b got wrong type assigned");
  34. gp_config::assertion(b.value<unsigned int>() == 16, "b got wrong value assigned");
  35. }
  36. {
  37. some_int a{16u};
  38. some_int b;
  39. new(&b) some_int(a);
  40. gp_config::assertion(b.is_a<unsigned int>(), "b got wrong type assigned");
  41. gp_config::assertion(b.value<unsigned int>() == 16, "b got wrong value assigned");
  42. }
  43. {
  44. some_int a{16u};
  45. some_int b;
  46. new(&b) some_int(gp::move(a));
  47. gp_config::assertion(b.is_a<unsigned int>(), "b got wrong type assigned");
  48. gp_config::assertion(b.value<unsigned int>() == 16, "b got wrong value assigned");
  49. }
  50. {
  51. gp::vector<some_int> vec{alloc};
  52. vec.emplace_back(12u);
  53. vec.emplace_back(-16);
  54. gp_config::assertion(vec[0].is_a<unsigned int>(), "vec0 got wrong type assigned");
  55. gp_config::assertion(vec[1].is_a<int>(), "vec1 got wrong type assigned");
  56. }
  57. return 0;
  58. }
  59. };
  60. append_test dummy_pg5zhr8bv(new cbor_test{});