region_packer_ut.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #include "region_packer.h"
  2. #include <library/cpp/testing/unittest/registar.h>
  3. template <typename TValue>
  4. void TestPacker() {
  5. TValue values[] = {1, 2, 3, 42};
  6. TString buffer;
  7. TRegionPacker<TValue> p;
  8. using TValues = TArrayRef<TValue>;
  9. TValues valueRegion = TValues(values, Y_ARRAY_SIZE(values));
  10. size_t sz = p.MeasureLeaf(valueRegion);
  11. UNIT_ASSERT_VALUES_EQUAL(sz, 1 + sizeof(values));
  12. buffer.resize(sz);
  13. p.PackLeaf(buffer.begin(), valueRegion, sz);
  14. UNIT_ASSERT_VALUES_EQUAL(buffer[0], 4);
  15. p.UnpackLeaf(buffer.data(), valueRegion);
  16. UNIT_ASSERT_EQUAL(valueRegion.data(), (const TValue*)(buffer.begin() + 1));
  17. UNIT_ASSERT_EQUAL(valueRegion.size(), Y_ARRAY_SIZE(values));
  18. UNIT_ASSERT_EQUAL(0, memcmp(values, valueRegion.data(), sizeof(values)));
  19. }
  20. Y_UNIT_TEST_SUITE(RegionPacker) {
  21. Y_UNIT_TEST(Test0) {
  22. TestPacker<char>();
  23. TestPacker<signed char>();
  24. TestPacker<unsigned char>();
  25. TestPacker<i8>();
  26. TestPacker<ui8>();
  27. TestPacker<i16>();
  28. TestPacker<ui16>();
  29. TestPacker<i32>();
  30. TestPacker<ui32>();
  31. TestPacker<i64>();
  32. TestPacker<ui64>();
  33. }
  34. }