forked from cpputest/cpputest
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSetPluginTest.cpp
More file actions
172 lines (148 loc) · 3.37 KB
/
Copy pathSetPluginTest.cpp
File metadata and controls
172 lines (148 loc) · 3.37 KB
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#include "CppUTest/TestHarness.h"
#include "CppUTest/TestRegistry.h"
#include "CppUTest/TestOutput.h"
#include "CppUTest/TestPlugin.h"
static void orig_func1()
{
}
static void stub_func1()
{
}
static void orig_func2()
{
}
static void stub_func2()
{
}
static void (*fp1)();
static void (*fp2)();
TEST_GROUP(SetPointerPluginTest)
{
SetPointerPlugin* plugin_;
TestRegistry* myRegistry_;
StringBufferTestOutput* output_;
TestResult* result_;
void setup()
{
myRegistry_ = new TestRegistry();
plugin_ = new SetPointerPlugin("TestSetPlugin");
myRegistry_->setCurrentRegistry(myRegistry_);
myRegistry_->installPlugin(plugin_);
output_ = new StringBufferTestOutput();
result_ = new TestResult(*output_);
}
void teardown()
{
myRegistry_->setCurrentRegistry(0);
delete myRegistry_;
delete plugin_;
delete output_;
delete result_;
}
};
class FunctionPointerUtest : public Utest
{
public:
void setup() _override
{
UT_PTR_SET(fp1, stub_func1);
UT_PTR_SET(fp2, stub_func2);
UT_PTR_SET(fp2, stub_func2);
}
void testBody() _override
{
CHECK(fp1 == stub_func1);
CHECK(fp2 == stub_func2);
}
};
class FunctionPointerUtestShell: public UtestShell
{
public:
virtual Utest* createTest()
{
return new FunctionPointerUtest();
}
};
TEST(SetPointerPluginTest, installTwoFunctionPointer)
{
FunctionPointerUtestShell *tst = new FunctionPointerUtestShell();
;
fp1 = orig_func1;
fp2 = orig_func2;
myRegistry_->addTest(tst);
myRegistry_->runAllTests(*result_);
CHECK(fp1 == orig_func1);
CHECK(fp2 == orig_func2);
LONGS_EQUAL(0, result_->getFailureCount());
LONGS_EQUAL(2, result_->getCheckCount());
delete tst;
}
class MaxFunctionPointerUtest : public Utest
{
public:
int numOfFpSets;
MaxFunctionPointerUtest(int num) :
numOfFpSets(num)
{
}
void setup()
{
for (int i = 0; i < numOfFpSets; ++i)
{
UT_PTR_SET(fp1, stub_func1);
}
}
};
class MaxFunctionPointerUtestShell: public UtestShell
{
public:
int numOfFpSets;
MaxFunctionPointerUtestShell(int num) :
numOfFpSets(num)
{
}
virtual Utest* createTest()
{
return new MaxFunctionPointerUtest(numOfFpSets);
}
};
TEST(SetPointerPluginTest, installTooMuchFunctionPointer)
{
MaxFunctionPointerUtestShell *tst = new MaxFunctionPointerUtestShell(SetPointerPlugin::MAX_SET + 1);
myRegistry_->addTest(tst);
myRegistry_->runAllTests(*result_);
LONGS_EQUAL(1, result_->getFailureCount());
delete tst;
}
static double orig_double = 3.0;
static double* orig_double_ptr = &orig_double;
static double stub_double = 4.0;
class SetDoublePointerUtest : public Utest
{
public:
void setup()
{
UT_PTR_SET(orig_double_ptr, &stub_double);
}
void testBody()
{
CHECK(orig_double_ptr == &stub_double);
}
};
class SetDoublePointerUtestShell: public UtestShell
{
public:
Utest * createTest()
{
return new SetDoublePointerUtest();
}
};
TEST(SetPointerPluginTest, doublePointer)
{
SetDoublePointerUtestShell *doubletst = new SetDoublePointerUtestShell();
myRegistry_->addTest(doubletst);
myRegistry_->runAllTests(*result_);
CHECK(orig_double_ptr == &orig_double);
LONGS_EQUAL(1, result_->getCheckCount());
delete doubletst;
}