diff options
author | Vasily Gerasimov <UgnineSirdis@gmail.com> | 2022-02-10 16:49:10 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:49:10 +0300 |
commit | 1eb755fbca92172a6aec2f57371b2b3a19dfab43 (patch) | |
tree | 5d5cb817648f650d76cf1076100726fd9b8448e8 /util/generic/ptr_ut.cpp | |
parent | 6cdc8f140213c595e4ad38bc3d97fcef1146b8c3 (diff) | |
download | ydb-1eb755fbca92172a6aec2f57371b2b3a19dfab43.tar.gz |
Restoring authorship annotation for Vasily Gerasimov <UgnineSirdis@gmail.com>. Commit 2 of 2.
Diffstat (limited to 'util/generic/ptr_ut.cpp')
-rw-r--r-- | util/generic/ptr_ut.cpp | 124 |
1 files changed, 62 insertions, 62 deletions
diff --git a/util/generic/ptr_ut.cpp b/util/generic/ptr_ut.cpp index 210e562a36c..c2dcff23f6b 100644 --- a/util/generic/ptr_ut.cpp +++ b/util/generic/ptr_ut.cpp @@ -4,8 +4,8 @@ #include <library/cpp/testing/unittest/registar.h> -#include <util/generic/hash_set.h> -#include <util/generic/is_in.h> +#include <util/generic/hash_set.h> +#include <util/generic/is_in.h> #include <util/stream/output.h> #include <util/system/thread.h> @@ -31,9 +31,9 @@ class TPointerTest: public TTestBase { UNIT_TEST(TestCopyOnWritePtr2); UNIT_TEST(TestOperatorBool); UNIT_TEST(TestMakeShared); - UNIT_TEST(TestComparison); + UNIT_TEST(TestComparison); UNIT_TEST(TestSimpleIntrusivePtrCtorTsan); - UNIT_TEST(TestRefCountedPtrsInHashSet) + UNIT_TEST(TestRefCountedPtrsInHashSet) UNIT_TEST_SUITE_END(); private: @@ -83,10 +83,10 @@ private: void TestCopyOnWritePtr2(); void TestOperatorBool(); void TestMakeShared(); - void TestComparison(); - template <class T, class TRefCountedPtr> - void TestRefCountedPtrsInHashSetImpl(); - void TestRefCountedPtrsInHashSet(); + void TestComparison(); + template <class T, class TRefCountedPtr> + void TestRefCountedPtrsInHashSetImpl(); + void TestRefCountedPtrsInHashSet(); }; UNIT_TEST_SUITE_REGISTRATION(TPointerTest); @@ -709,73 +709,73 @@ void TPointerTest::TestMakeShared() { } } -template <class TPtr> -void TestPtrComparison(const TPtr& ptr) { - UNIT_ASSERT(ptr == ptr); - UNIT_ASSERT(!(ptr != ptr)); - UNIT_ASSERT(ptr == ptr.Get()); - UNIT_ASSERT(!(ptr != ptr.Get())); -} - -void TPointerTest::TestComparison() { +template <class TPtr> +void TestPtrComparison(const TPtr& ptr) { + UNIT_ASSERT(ptr == ptr); + UNIT_ASSERT(!(ptr != ptr)); + UNIT_ASSERT(ptr == ptr.Get()); + UNIT_ASSERT(!(ptr != ptr.Get())); +} + +void TPointerTest::TestComparison() { THolder<A> ptr1(new A); TAutoPtr<A> ptr2; TSimpleSharedPtr<int> ptr3(new int(6)); TIntrusivePtr<A> ptr4; - TIntrusiveConstPtr<A> ptr5 = ptr4; + TIntrusiveConstPtr<A> ptr5 = ptr4; UNIT_ASSERT(ptr1 != nullptr); UNIT_ASSERT(ptr2 == nullptr); UNIT_ASSERT(ptr3 != nullptr); UNIT_ASSERT(ptr4 == nullptr); - UNIT_ASSERT(ptr5 == nullptr); - - TestPtrComparison(ptr1); - TestPtrComparison(ptr2); - TestPtrComparison(ptr3); - TestPtrComparison(ptr4); - TestPtrComparison(ptr5); + UNIT_ASSERT(ptr5 == nullptr); + + TestPtrComparison(ptr1); + TestPtrComparison(ptr2); + TestPtrComparison(ptr3); + TestPtrComparison(ptr4); + TestPtrComparison(ptr5); } - -template <class T, class TRefCountedPtr> -void TPointerTest::TestRefCountedPtrsInHashSetImpl() { - THashSet<TRefCountedPtr> hashSet; - TRefCountedPtr p1(new T()); - UNIT_ASSERT(!IsIn(hashSet, p1)); - UNIT_ASSERT(hashSet.insert(p1).second); - UNIT_ASSERT(IsIn(hashSet, p1)); - UNIT_ASSERT_VALUES_EQUAL(hashSet.size(), 1); - UNIT_ASSERT(!hashSet.insert(p1).second); - - TRefCountedPtr p2(new T()); - UNIT_ASSERT(!IsIn(hashSet, p2)); - UNIT_ASSERT(hashSet.insert(p2).second); - UNIT_ASSERT(IsIn(hashSet, p2)); - UNIT_ASSERT_VALUES_EQUAL(hashSet.size(), 2); -} - + +template <class T, class TRefCountedPtr> +void TPointerTest::TestRefCountedPtrsInHashSetImpl() { + THashSet<TRefCountedPtr> hashSet; + TRefCountedPtr p1(new T()); + UNIT_ASSERT(!IsIn(hashSet, p1)); + UNIT_ASSERT(hashSet.insert(p1).second); + UNIT_ASSERT(IsIn(hashSet, p1)); + UNIT_ASSERT_VALUES_EQUAL(hashSet.size(), 1); + UNIT_ASSERT(!hashSet.insert(p1).second); + + TRefCountedPtr p2(new T()); + UNIT_ASSERT(!IsIn(hashSet, p2)); + UNIT_ASSERT(hashSet.insert(p2).second); + UNIT_ASSERT(IsIn(hashSet, p2)); + UNIT_ASSERT_VALUES_EQUAL(hashSet.size(), 2); +} + struct TCustomIntrusivePtrOps: TDefaultIntrusivePtrOps<A> { -}; - +}; + struct TCustomDeleter: TDelete { -}; - +}; + struct TCustomCounter: TSimpleCounter { - using TSimpleCounterTemplate::TSimpleCounterTemplate; -}; - -void TPointerTest::TestRefCountedPtrsInHashSet() { - // test common case - TestRefCountedPtrsInHashSetImpl<TString, TSimpleSharedPtr<TString>>(); - TestRefCountedPtrsInHashSetImpl<TString, TAtomicSharedPtr<TString>>(); - TestRefCountedPtrsInHashSetImpl<A, TIntrusivePtr<A>>(); - TestRefCountedPtrsInHashSetImpl<A, TIntrusiveConstPtr<A>>(); - - // test with custom ops - TestRefCountedPtrsInHashSetImpl<TString, TSharedPtr<TString, TCustomCounter, TCustomDeleter>>(); - TestRefCountedPtrsInHashSetImpl<A, TIntrusivePtr<A, TCustomIntrusivePtrOps>>(); - TestRefCountedPtrsInHashSetImpl<A, TIntrusiveConstPtr<A, TCustomIntrusivePtrOps>>(); -} + using TSimpleCounterTemplate::TSimpleCounterTemplate; +}; + +void TPointerTest::TestRefCountedPtrsInHashSet() { + // test common case + TestRefCountedPtrsInHashSetImpl<TString, TSimpleSharedPtr<TString>>(); + TestRefCountedPtrsInHashSetImpl<TString, TAtomicSharedPtr<TString>>(); + TestRefCountedPtrsInHashSetImpl<A, TIntrusivePtr<A>>(); + TestRefCountedPtrsInHashSetImpl<A, TIntrusiveConstPtr<A>>(); + + // test with custom ops + TestRefCountedPtrsInHashSetImpl<TString, TSharedPtr<TString, TCustomCounter, TCustomDeleter>>(); + TestRefCountedPtrsInHashSetImpl<A, TIntrusivePtr<A, TCustomIntrusivePtrOps>>(); + TestRefCountedPtrsInHashSetImpl<A, TIntrusiveConstPtr<A, TCustomIntrusivePtrOps>>(); +} class TRefCountedWithStatistics: public TNonCopyable { public: |