aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/testing/gtest_extensions/ut/probe_ut.cpp
blob: a9d53f896a3465aebaae29da7f66710d19802cb6 (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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <library/cpp/testing/gtest/gtest.h>

using namespace testing;

TEST(ProbeStateTest, Example) {
    // check that our test function does not make a copy of passed argument
    auto copyless = [](auto&& x) {
        TProbe p(std::move(x));
        p.Touch();
        return p;
    };

    TProbeState state;
    auto probe = copyless(TProbe(&state));
    EXPECT_EQ(1, state.Touches);
    EXPECT_THAT(state, HasCopyMoveCounts(0, 2));
}

TEST(ProbeTest, Construct) {
    TProbeState state;
    {
        TProbe probe(&state);
        EXPECT_THAT(state, IsAlive());
    }
    EXPECT_THAT(state, IsDead());
}

TEST(ProbeTest, Copy) {
    TProbeState state;

    TProbe probe(&state);
    TProbe copy(probe);
    EXPECT_THAT(state, HasCopyMoveCounts(1, 0));
    EXPECT_THAT(state, NoAssignments());
    EXPECT_THAT(state, NoMoves());

    TProbe copy2 = TProbe::ExplicitlyCreateInvalidProbe();
    copy2 = probe;
    EXPECT_EQ(1, state.CopyAssignments);
}

TEST(ProbeTest, Move) {
    TProbeState state;
    TProbe probe(&state);
    TProbe probe2(std::move(probe));
    EXPECT_FALSE(probe.IsValid());
    EXPECT_THAT(state, NoCopies());

    EXPECT_THAT(state, HasCopyMoveCounts(0, 1));

    TProbe probe3 = TProbe::ExplicitlyCreateInvalidProbe();
    probe3 = std::move(probe2);
    EXPECT_EQ(1, state.MoveAssignments);
}