-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuse_mocker_test.cc
97 lines (71 loc) · 1.57 KB
/
use_mocker_test.cc
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include "gtest/gtest.h"
#include "snapshot/snapshot.h"
#include "autowired/autowired.h"
namespace auto_wired::v1::test::use_mocker {
static int test_flag = 0;
class A {
public:
int a{1};
};
class B {
public:
AUTO_WIRED_DECLARE_BEGIN(B)
AUTO_WIRED_DECLARE_CLASS(a)
AUTO_WIRED_DECLARE_END()
virtual ~B() = default;
public:
virtual int F() {
return 2;
}
private:
A& a;
};
class BMocker : public B {
public:
BMocker() : B(auto_wired::AutoWired::MockInstance()) {}
virtual int F() override {
return 3;
}
};
class C {
public:
AUTO_WIRED_DECLARE_BEGIN(C, auto_wired::AutoWired::RegisterOptions::WithNeedInit())
AUTO_WIRED_DECLARE_CLASS(a)
AUTO_WIRED_DECLARE_CLASS(b)
AUTO_WIRED_DECLARE_END()
void Init() {
if (test_flag == 0) {
test_flag += a.a;
test_flag += b.F();
}
}
int c{3};
private:
A& a;
B& b;
};
class UseMockerTest : public testing::Test {
protected:
virtual void SetUp() override {}
};
TEST_F(UseMockerTest, no_mocker) {
test_flag = 0;
auto w = auto_wired::AutoWired();
auto& c = w.GetClassRef<C>();
EXPECT_EQ(c.c, 3);
w.InitAll();
EXPECT_EQ(test_flag, 3);
w.DeInitAll();
}
TEST_F(UseMockerTest, has_mocker) {
test_flag = 0;
auto w = auto_wired::AutoWired();
auto* b_mocker = new BMocker();
w.UseMocker<B>(b_mocker);
auto& c = w.GetClassRef<C>();
EXPECT_EQ(c.c, 3);
w.InitAll();
EXPECT_EQ(test_flag, 4);
w.DeInitAll();
}
} // namespace auto_wired::v1::test::use_mocker