forked from arstrube/FakeFunctions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRunAllTests.cpp
98 lines (88 loc) · 2.76 KB
/
RunAllTests.cpp
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
#include "CppUTest/CommandLineTestRunner.h"
#include "CppUTest/TestHarness.h"
#include "CppUTestExt/MockSupport.h"
extern "C" {
#include "User.h"
}
#include "Used_Fake.h" /// NEVER put this inside extern "C" {}
TEST_GROUP(Used_withDummy) {
};
TEST(Used_withDummy, add) {
LONGS_EQUAL(0, Used_add(5555, 123));
}
TEST(Used_withDummy, subtract) {
LONGS_EQUAL(0, Used_subtract(-34567, -34568));
}
TEST_GROUP(Used_withRealCode) {
void setup() {
UT_PTR_SET(Used_Fake::add, C::Used_add);
UT_PTR_SET(Used_Fake::subtract, C::Used_subtract);
}
};
TEST(Used_withRealCode, add) {
LONGS_EQUAL(5678, Used_add(5555, 123));
}
TEST(Used_withRealCode, subtract) {
LONGS_EQUAL(1, Used_subtract(-34567, -34568));
}
TEST_GROUP(User_withUsedRealCode) {
void setup() {
UT_PTR_SET(Used_Fake::add, C::Used_add);
UT_PTR_SET(Used_Fake::subtract, C::Used_subtract);
}
};
TEST(User_withUsedRealCode, multiply) {
LONGS_EQUAL(1000000, User_multiply(200000, 5));
}
TEST_GROUP(User_withUsedStubCode) {
void setup() {
UT_PTR_SET(Used_Fake::add, Stub::Used_add);
UT_PTR_SET(Used_Fake::subtract, Stub::Used_subtract);
}
};
TEST(User_withUsedStubCode, multiply) {
LONGS_EQUAL(330000, User_multiply(110000, 3));
}
TEST_GROUP(User_withUsedMockCode) {
void setup() {
UT_PTR_SET(Used_Fake::add, Mock::Used_add);
UT_PTR_SET(Used_Fake::subtract, Mock::Used_subtract);
}
void teardown() {
mock().clear();
}
};
TEST(User_withUsedMockCode, calculate) {
mock().expectOneCall("Used_add")
.withParameter("a", 0).withParameter("b", 3).andReturnValue(3);
mock().expectOneCall("Used_add")
.withParameter("a", 3).withParameter("b", 3).andReturnValue(6);
mock().expectOneCall("Used_add")
.withParameter("a", 6).withParameter("b", 3).andReturnValue(9);
mock().expectOneCall("Used_add")
.withParameter("a", 9).withParameter("b", 3).andReturnValue(12);
mock().expectOneCall("Used_subtract")
.withParameter("a", 12).withParameter("b", 3).andReturnValue(9);
LONGS_EQUAL(9, User_multiply(3, 3));
mock().checkExpectations();
}
TEST_GROUP(User_withUsedMixed) {
void setup() {
UT_PTR_SET(Used_Fake::add, Stub::Used_add);
UT_PTR_SET(Used_Fake::subtract, Mock::Used_subtract);
}
void teardown() {
mock().clear();
}
};
TEST(User_withUsedMixed, multiply) {
mock().expectOneCall("Used_subtract")
.withParameter("a", 20)
.withParameter("b", 5)
.andReturnValue(15);
LONGS_EQUAL(15, User_multiply(5, 3));
}
int main(int ac, char** av)
{
return CommandLineTestRunner::RunAllTests(ac, av);
}