aboutsummaryrefslogtreecommitdiffstats
path: root/util/generic/objects_counter_ut.cpp
blob: d12a1e78c6b1ff309895ad6d3253d0edc7eb6cab (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include "object_counter.h" 
 
#include <library/cpp/testing/unittest/registar.h>
 
Y_UNIT_TEST_SUITE(ObjectsCounter) {
    struct TObject: public TObjectCounter<TObject> { 
    }; 
 
    Y_UNIT_TEST(Test1) {
        TObject obj; 
        TVector<TObject> objects;
        for (ui32 i = 0; i < 100; ++i) { 
            objects.push_back(obj); 
        } 
        UNIT_ASSERT_EQUAL(TObjectCounter<TObject>::ObjectCount(), 101); 
    } 
 
    Y_UNIT_TEST(TestEq) {
        TObject obj; 
        { 
            TObject obj1 = obj; 
            UNIT_ASSERT_EQUAL(TObjectCounter<TObject>::ObjectCount(), 2); 
        } 
        UNIT_ASSERT_EQUAL(TObjectCounter<TObject>::ObjectCount(), 1); 
    } 
 
    Y_UNIT_TEST(TestMove) {
        TObject obj; 
        UNIT_ASSERT_EQUAL(TObjectCounter<TObject>::ObjectCount(), 1); 
        { 
            TObject obj1 = std::move(obj); 
            UNIT_ASSERT_EQUAL(TObjectCounter<TObject>::ObjectCount(), 2); 
        } 
        UNIT_ASSERT_EQUAL(TObjectCounter<TObject>::ObjectCount(), 1); 
    } 
}