-
Notifications
You must be signed in to change notification settings - Fork 529
Expand file tree
/
Copy pathSetPluginTest.cpp
More file actions
133 lines (114 loc) · 2.56 KB
/
Copy pathSetPluginTest.cpp
File metadata and controls
133 lines (114 loc) · 2.56 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
#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 UtestShell
{
public:
void setup()
{
UT_PTR_SET(fp1, stub_func1);
UT_PTR_SET(fp2, stub_func2);
UT_PTR_SET(fp2, stub_func2);
}
void testBody()
{
CHECK(fp1 == stub_func1);
CHECK(fp2 == stub_func2);
}
};
TEST(SetPointerPluginTest, installTwoFunctionPointer)
{
FunctionPointerUtest *tst = new FunctionPointerUtest();
;
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());
delete tst;
}
class MaxFunctionPointerUtest: public UtestShell
{
public:
int numOfFpSets;
MaxFunctionPointerUtest(int num) :
numOfFpSets(num)
{
}
void setup()
{
for (int i = 0; i < numOfFpSets; ++i)
UT_PTR_SET(fp1, stub_func1);
}
};
IGNORE_TEST(SetPointerPluginTest, installTooMuchFunctionPointer)
{
MaxFunctionPointerUtest *tst = new MaxFunctionPointerUtest(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 UtestShell
{
public:
void setup()
{
UT_PTR_SET(orig_double_ptr, &stub_double);
}
void testBody()
{
CHECK(orig_double_ptr == &stub_double);
}
};
TEST(SetPointerPluginTest, doublePointer)
{
SetDoublePointerUtest *doubletst = new SetDoublePointerUtest();
myRegistry_->addTest(doubletst);
CHECK(orig_double_ptr == &orig_double);
delete doubletst;
}