diff options
author | Anton Samokhvalov <pg83@yandex.ru> | 2022-02-10 16:45:15 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:45:15 +0300 |
commit | 72cb13b4aff9bc9cf22e49251bc8fd143f82538f (patch) | |
tree | da2c34829458c7d4e74bdfbdf85dff449e9e7fb8 /util/generic/mem_copy_ut.cpp | |
parent | 778e51ba091dc39e7b7fcab2b9cf4dbedfb6f2b5 (diff) | |
download | ydb-72cb13b4aff9bc9cf22e49251bc8fd143f82538f.tar.gz |
Restoring authorship annotation for Anton Samokhvalov <pg83@yandex.ru>. Commit 1 of 2.
Diffstat (limited to 'util/generic/mem_copy_ut.cpp')
-rw-r--r-- | util/generic/mem_copy_ut.cpp | 188 |
1 files changed, 94 insertions, 94 deletions
diff --git a/util/generic/mem_copy_ut.cpp b/util/generic/mem_copy_ut.cpp index 8b55a11cf6..59b6747655 100644 --- a/util/generic/mem_copy_ut.cpp +++ b/util/generic/mem_copy_ut.cpp @@ -1,113 +1,113 @@ -#include "mem_copy.h" - +#include "mem_copy.h" + #include <library/cpp/testing/unittest/registar.h> - -namespace { + +namespace { class TAssignBCalled: public yexception { }; - struct TB { - inline TB& operator=(const TB&) { + struct TB { + inline TB& operator=(const TB&) { throw TAssignBCalled(); - - return *this; - } - }; - - struct TC: public TB { - }; -} - + + return *this; + } + }; + + struct TC: public TB { + }; +} + Y_DECLARE_PODTYPE(TB); - + Y_UNIT_TEST_SUITE(TestMemCopy) { Y_UNIT_TEST(Test1) { - char buf[] = "123"; - char buf1[sizeof(buf)]; - - UNIT_ASSERT_EQUAL(MemCopy(buf1, buf, sizeof(buf)), buf1); - - for (size_t i = 0; i < sizeof(buf); ++i) { - UNIT_ASSERT_VALUES_EQUAL(buf[i], buf1[i]); - } - } - - static int x = 0; - - struct TA { - inline TA() { - X = ++x; - } - - int X; - }; - + char buf[] = "123"; + char buf1[sizeof(buf)]; + + UNIT_ASSERT_EQUAL(MemCopy(buf1, buf, sizeof(buf)), buf1); + + for (size_t i = 0; i < sizeof(buf); ++i) { + UNIT_ASSERT_VALUES_EQUAL(buf[i], buf1[i]); + } + } + + static int x = 0; + + struct TA { + inline TA() { + X = ++x; + } + + int X; + }; + Y_UNIT_TEST(Test2) { - x = 0; - - TA a1[5]; - TA a2[5]; - - UNIT_ASSERT_VALUES_EQUAL(a1[0].X, 1); - UNIT_ASSERT_VALUES_EQUAL(a2[0].X, 6); - - MemCopy(a2, a1, 5); - - for (size_t i = 0; i < 5; ++i) { - UNIT_ASSERT_VALUES_EQUAL(a1[i].X, a2[i].X); - } - } - + x = 0; + + TA a1[5]; + TA a2[5]; + + UNIT_ASSERT_VALUES_EQUAL(a1[0].X, 1); + UNIT_ASSERT_VALUES_EQUAL(a2[0].X, 6); + + MemCopy(a2, a1, 5); + + for (size_t i = 0; i < 5; ++i) { + UNIT_ASSERT_VALUES_EQUAL(a1[i].X, a2[i].X); + } + } + Y_UNIT_TEST(Test3) { - TB b1[5]; - TB b2[5]; - - MemCopy(b2, b1, 5); - } - + TB b1[5]; + TB b2[5]; + + MemCopy(b2, b1, 5); + } + Y_UNIT_TEST(Test4) { - TC c1[5]; - TC c2[5]; - + TC c1[5]; + TC c2[5]; + UNIT_ASSERT_EXCEPTION(MemCopy(c2, c1, 5), TAssignBCalled); - } - - template <class T> - inline void FillX(T* b, T* e) { + } + + template <class T> + inline void FillX(T* b, T* e) { int tmp = 0; - - while (b != e) { + + while (b != e) { (b++)->X = ++tmp; - } - } - + } + } + Y_UNIT_TEST(Test5) { - struct TD { - int X; - }; - - TD orig[50]; - - for (ssize_t i = -15; i < 15; ++i) { - TD* b = orig + 20; - TD* e = b + 10; - - FillX(b, e); - - TD* to = b + i; - - MemMove(to, b, e - b - 1); - - for (size_t j = 0; j < (e - b) - (size_t)1; ++j) { - UNIT_ASSERT_VALUES_EQUAL(to[j].X, j + 1); - } - } - } - + struct TD { + int X; + }; + + TD orig[50]; + + for (ssize_t i = -15; i < 15; ++i) { + TD* b = orig + 20; + TD* e = b + 10; + + FillX(b, e); + + TD* to = b + i; + + MemMove(to, b, e - b - 1); + + for (size_t j = 0; j < (e - b) - (size_t)1; ++j) { + UNIT_ASSERT_VALUES_EQUAL(to[j].X, j + 1); + } + } + } + Y_UNIT_TEST(TestEmpty) { char* tmp = nullptr; - + UNIT_ASSERT(MemCopy(tmp, tmp, 0) == nullptr); UNIT_ASSERT(MemMove(tmp, tmp, 0) == nullptr); - } -} + } +} |