aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/testing/gtest/ut/ut.cpp
blob: 0b6d69b2cfaf2074f7f7929abf62dbc00fb7065e (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
#include <library/cpp/testing/gtest/gtest.h>
#include <library/cpp/testing/hook/hook.h>

static int HookOrder = 0;
static int PreInitHook1 = 0;
static int PreInitHook2 = 0;
static int PreRunHook1 = 0;
static int PreRunHook2 = 0;
static int PostRunHook1 = 0;
static int PostRunHook2 = 0;

Y_TEST_HOOK_BEFORE_INIT(PreInit1) {
    PreInitHook1 = ++HookOrder;
}

Y_TEST_HOOK_BEFORE_INIT(PreInit2) {
    PreInitHook2 = ++HookOrder;
}

Y_TEST_HOOK_BEFORE_RUN(PreRun1) {
    PreRunHook1 = ++HookOrder;
}

Y_TEST_HOOK_BEFORE_RUN(PreRun2) {
    PreRunHook2 = ++HookOrder;
}

Y_TEST_HOOK_AFTER_RUN(PostRun1) {
    PostRunHook1 = ++HookOrder;
    Cerr << "PostRunHook1" << Endl;
}

Y_TEST_HOOK_AFTER_RUN(PostRun2) {
    PostRunHook2 = ++HookOrder;
    Cerr << "PostRunHook2" << Endl;
}

TEST(Gtest, HookOrder) {
    EXPECT_NEAR(PreInitHook1, PreInitHook2, 1);
    EXPECT_NEAR(PreRunHook1, PreRunHook2, 1);
    EXPECT_LE(std::max(PreInitHook1, PreInitHook2), std::min(PreRunHook1, PreRunHook2));
    EXPECT_EQ(PostRunHook1, 0);
    EXPECT_EQ(PostRunHook2, 0);
}

TEST(Gtest, Metrics) {
    RecordProperty("Metric1", 10);
}