#include #include #include #include #include #include #include #include #include #include #include #include #include #include "packers.h" #include #include class TPackersTest: public TTestBase { private: UNIT_TEST_SUITE(TPackersTest); UNIT_TEST(TestPackers); UNIT_TEST_SUITE_END(); template void TestPacker(const TData& data); template void TestPacker(const TData* test, size_t size); public: void TestPackers(); }; UNIT_TEST_SUITE_REGISTRATION(TPackersTest); template void TPackersTest::TestPacker(const TData& data) { size_t len = TPacker().MeasureLeaf(data); size_t bufLen = len * 3; TArrayHolder buf(new char[bufLen]); memset(buf.Get(), -1, bufLen); TPacker().PackLeaf(buf.Get(), data, len); UNIT_ASSERT(TPacker().SkipLeaf(buf.Get()) == len); TData dataTmp; TPacker().UnpackLeaf(buf.Get(), dataTmp); UNIT_ASSERT(data == dataTmp); } template void TPackersTest::TestPacker(const TData* test, size_t size) { for (size_t i = 0; i < size; ++i) { TestPacker(test[i]); } } void TPackersTest::TestPackers() { { const TString test[] = {"", "a", "b", "c", "d", "aa", "ab", "ac", "ad", "aaa", "aab", "aac", "aad", "aba", "abb", "abc", "abd", "asdfjjmk.gjilsjgilsjilgjildsajgfilsjdfilgjm ldsa8oq43u 583uq4905 -q435 jiores u893q 5oiju fd-KE 89536 9Q2URE 12AI894T3 89 Q*(re43"}; TestPacker>(test, Y_ARRAY_SIZE(test)); for (size_t i = 0; i != Y_ARRAY_SIZE(test); ++i) { TestPacker>(UTF8ToWide(test[i])); } } { const ui64 test[] = { 0, 1, 2, 3, 4, 5, 6, 76, 100000, Max()}; TestPacker>(test, Y_ARRAY_SIZE(test)); } { const int test[] = { 0, 1, 2, 3, 4, 5, 6, 76, 100000, -1, -2, -3, -4, -5, -6, -76, -10000, Min(), Max()}; TestPacker>(test, Y_ARRAY_SIZE(test)); } { const float test[] = { 2.f, 3.f, 4.f, 0.f, -0.f, 1.f, -1.f, 1.1f, -1.1f, std::numeric_limits::min(), -std::numeric_limits::min(), std::numeric_limits::max(), -std::numeric_limits::max()}; TestPacker(test, Y_ARRAY_SIZE(test)); } { const double test[] = { 0., -0., 1., -1., 1.1, -1.1, std::numeric_limits::min(), -std::numeric_limits::min(), std::numeric_limits::max(), -std::numeric_limits::max()}; TestPacker(test, Y_ARRAY_SIZE(test)); } }