diff options
author | Devtools Arcadia <arcadia-devtools@yandex-team.ru> | 2022-02-07 18:08:42 +0300 |
---|---|---|
committer | Devtools Arcadia <arcadia-devtools@mous.vla.yp-c.yandex.net> | 2022-02-07 18:08:42 +0300 |
commit | 1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch) | |
tree | e26c9fed0de5d9873cce7e00bc214573dc2195b7 /library/cpp/packers/ut/region_packer_ut.cpp | |
download | ydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz |
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'library/cpp/packers/ut/region_packer_ut.cpp')
-rw-r--r-- | library/cpp/packers/ut/region_packer_ut.cpp | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/library/cpp/packers/ut/region_packer_ut.cpp b/library/cpp/packers/ut/region_packer_ut.cpp new file mode 100644 index 0000000000..0cb08ccf65 --- /dev/null +++ b/library/cpp/packers/ut/region_packer_ut.cpp @@ -0,0 +1,40 @@ +#include "region_packer.h" +#include <library/cpp/testing/unittest/registar.h> + +template <typename TValue> +void TestPacker() { + TValue values[] = {1, 2, 3, 42}; + TString buffer; + + TRegionPacker<TValue> p; + + using TValues = TArrayRef<TValue>; + TValues valueRegion = TValues(values, Y_ARRAY_SIZE(values)); + size_t sz = p.MeasureLeaf(valueRegion); + UNIT_ASSERT_VALUES_EQUAL(sz, 1 + sizeof(values)); + + buffer.resize(sz); + p.PackLeaf(buffer.begin(), valueRegion, sz); + UNIT_ASSERT_VALUES_EQUAL(buffer[0], 4); + + p.UnpackLeaf(buffer.data(), valueRegion); + UNIT_ASSERT_EQUAL(valueRegion.data(), (const TValue*)(buffer.begin() + 1)); + UNIT_ASSERT_EQUAL(valueRegion.size(), Y_ARRAY_SIZE(values)); + UNIT_ASSERT_EQUAL(0, memcmp(values, valueRegion.data(), sizeof(values))); +} + +Y_UNIT_TEST_SUITE(RegionPacker) { + Y_UNIT_TEST(Test0) { + TestPacker<char>(); + TestPacker<signed char>(); + TestPacker<unsigned char>(); + TestPacker<i8>(); + TestPacker<ui8>(); + TestPacker<i16>(); + TestPacker<ui16>(); + TestPacker<i32>(); + TestPacker<ui32>(); + TestPacker<i64>(); + TestPacker<ui64>(); + } +} |