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/containers/stack_array/ut | |
download | ydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz |
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'library/cpp/containers/stack_array/ut')
-rw-r--r-- | library/cpp/containers/stack_array/ut/tests_ut.cpp | 94 | ||||
-rw-r--r-- | library/cpp/containers/stack_array/ut/ya.make | 9 |
2 files changed, 103 insertions, 0 deletions
diff --git a/library/cpp/containers/stack_array/ut/tests_ut.cpp b/library/cpp/containers/stack_array/ut/tests_ut.cpp new file mode 100644 index 0000000000..3e96384f0e --- /dev/null +++ b/library/cpp/containers/stack_array/ut/tests_ut.cpp @@ -0,0 +1,94 @@ +#include <library/cpp/containers/stack_array/stack_array.h> +#include <library/cpp/testing/unittest/registar.h> + +Y_UNIT_TEST_SUITE(TestStackArray) { + using namespace NStackArray; + + static inline void* FillWithTrash(void* d, size_t l) { + memset(d, 0xCC, l); + + return d; + } + +#define ALLOC(type, len) FillWithTrash(alloca(sizeof(type) * len), sizeof(type) * len), len + + Y_UNIT_TEST(Test1) { + TStackArray<ui32> s(ALLOC(ui32, 10)); + + UNIT_ASSERT_VALUES_EQUAL(s.size(), 10); + + for (size_t i = 0; i < s.size(); ++i) { + UNIT_ASSERT_VALUES_EQUAL(s[i], 0xCCCCCCCC); + } + + for (auto&& x : s) { + UNIT_ASSERT_VALUES_EQUAL(x, 0xCCCCCCCC); + } + + for (size_t i = 0; i < s.size(); ++i) { + s[i] = i; + } + + size_t ss = 0; + + for (auto&& x : s) { + ss += x; + } + + UNIT_ASSERT_VALUES_EQUAL(ss, 45); + } + + static int N1 = 0; + + struct TX1 { + inline TX1() { + ++N1; + } + + inline ~TX1() { + --N1; + } + }; + + Y_UNIT_TEST(Test2) { + { + TStackArray<TX1> s(ALLOC(TX1, 10)); + + UNIT_ASSERT_VALUES_EQUAL(N1, 10); + } + + UNIT_ASSERT_VALUES_EQUAL(N1, 0); + } + + static int N2 = 0; + static int N3 = 0; + + struct TX2 { + inline TX2() { + if (N2 >= 5) { + ythrow yexception() << "ups"; + } + + ++N3; + ++N2; + } + + inline ~TX2() { + --N2; + } + }; + + Y_UNIT_TEST(Test3) { + bool haveException = false; + + try { + TStackArray<TX2> s(ALLOC_ON_STACK(TX2, 10)); + } catch (...) { + haveException = true; + } + + UNIT_ASSERT(haveException); + UNIT_ASSERT_VALUES_EQUAL(N2, 0); + UNIT_ASSERT_VALUES_EQUAL(N3, 5); + } +} diff --git a/library/cpp/containers/stack_array/ut/ya.make b/library/cpp/containers/stack_array/ut/ya.make new file mode 100644 index 0000000000..7db7340073 --- /dev/null +++ b/library/cpp/containers/stack_array/ut/ya.make @@ -0,0 +1,9 @@ +UNITTEST_FOR(library/cpp/containers/stack_array) + +OWNER(pg) + +SRCS( + tests_ut.cpp +) + +END() |