-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestCaseTests.cpp
More file actions
304 lines (258 loc) · 10.5 KB
/
TestCaseTests.cpp
File metadata and controls
304 lines (258 loc) · 10.5 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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
#include "TestCPP.h"
#include "TestCase/TestCaseTests.h"
#include "TestCase/TestCaseTestChunks.h"
using TestCPP::Util::debugLog;
using std::cerr;
using std::cout;
using std::endl;
using TCPPStr = TestCPP::TestCPPCommon::Strings;
namespace TestCPP {
namespace Testing {
namespace TestCaseTests {
void TestConstructCase () {
debugLog("Construct basic");
auto test = unique_ptr<TestCase>(new TestCase(
"ConstructCase case Test - bare minimum",
function<void()>([](){})
));
debugLog("Construct with nullptr string");
Assertions::assertThrows(
[]() {
debugLog("Construct with nullptr string", true);
debugLog(" - assertThrows lambda");
auto testShouldThrow = unique_ptr<TestCase>(
new TestCase(
nullptr,
function<void()>([](){})
));
},
"Should have thrown on nullptr string!"
);
debugLog("Done with nullptr string construction test");
parameterVariationTestChunks();
}
/**
* Targets various types of non-move assignments.
*/
void TestAssignTestCase() {
const auto test = unique_ptr<TestCase>(new TestCase(
"Assignment case Test - const TestCase",
function<void()>([]() {})
));
const auto test2 = unique_ptr<TestCase>(new TestCase(
"Assignment case Test 2 - const TestCase",
function<void()>([]() {})
));
Assertions::assertTrue(
test->go(),
"Should have succeeded basic no-op test!"
);
const TestCase& testCopy = *test;
TestCase testCopy2 = *test2;
testCopy2 = testCopy;
Assertions::assertTrue(
testCopy2.go(),
"Should have succeeded basic no-op test!"
);
}
void TestMoveAssignTestCase() {
auto test = unique_ptr<TestCase>(new TestCase(
"Move Assignment case Test - const TestCase",
function<void()>([]() {})
));
auto test2 = unique_ptr<TestCase>(new TestCase(
"Move Assignment case Test 2 - const TestCase",
function<void()>([]() {})
));
Assertions::assertTrue(
test->go(),
"Should have succeeded basic no-op test!"
);
TestCase tempCpy = *test;
*test = std::move(*test2);
*test2 = std::move(tempCpy);
Assertions::assertTrue(
test->go(),
"Should have succeeded basic no-op test!"
);
}
void TestTestCaseGo () {
auto test = unique_ptr<TestCase>(new TestCase(
"SUB-TEST TestCaseGo case Test",
function<void()>([](){}),
true
));
Assertions::assertTrue(
test->go(),
"Should have succeeded basic no-op test!"
);
}
void TestTestCaseGoThrowStr () {
const string throwStr = "Test throw string!";
auto test = unique_ptr<TestCase>(new TestCase(
"SUB-TEST TestCaseGo case Test - throws str",
#ifdef TESTCPP_STACKTRACE_ENABLED
// We use C++14 when stacktraces are enabled, which
// allows us to avoid needing to use
// -Wno-unused-lambda-capture to avoid MSVC C3493
// since the implementations can be reconciled in
// the newer standard.
function<void()>([&toThrow = throwStr](){
throw toThrow;
}),
#else
function<void()>([&throwStr](){
throw throwStr;
}),
#endif
true, false, true, false,
TestCase::TestCaseOutCompareOptions::CONTAINS
));
Assertions::assertFalse(
test->go(),
"Should have succeeded str throws test!"
);
Assertions::assertTrue(
test->checkLog(throwStr),
"Something is off, expected output does not exist!"
);
}
void TestTestCaseGoThrowChr () {
constexpr const char * throwChr =
"Test throw const char *!";
auto test = unique_ptr<TestCase>(new TestCase(
"SUB-TEST TestCaseGo case Test - throws chr",
#ifdef TESTCPP_STACKTRACE_ENABLED
// We use C++14 when stacktraces are enabled, which
// allows us to avoid needing to use
// -Wno-unused-lambda-capture to avoid MSVC C3493
// since the implementations can be reconciled in
// the newer standard.
function<void()>([&toThrow = throwChr](){
throw toThrow;
}),
#else
function<void()>([&throwChr](){
throw throwChr;
}),
#endif
true, false, true, false,
TestCase::TestCaseOutCompareOptions::CONTAINS
));
Assertions::assertFalse(
test->go(),
"Should have succeeded chr throws test!"
);
string tcLog(throwChr);
Assertions::assertTrue(
test->checkLog(tcLog),
"Something is off, expected output does not exist!"
);
}
void TestTestCaseGoThrowInt () {
auto test = unique_ptr<TestCase>(new TestCase(
"SUB-TEST TestCaseGo case Test - throws int",
function<void()>([](){
throw -1;
}),
true, false, true, false,
TestCase::TestCaseOutCompareOptions::CONTAINS
));
Assertions::assertFalse(
test->go(),
"Should have succeeded catchall throws test!"
);
Assertions::assertTrue(
test->checkLog(TCPPStr::UNK_EXC),
"Something is off, expected output does not exist!"
);
}
void TestTestCaseSetNotifyPassed () {
auto test = unique_ptr<TestCase>(new TestCase(
"TestCaseSetNotifyPassed case Test",
function<void()>([](){}),
false, false, true, false,
TestCase::TestCaseOutCompareOptions::CONTAINS
));
Assertions::assertTrue(
test->go(),
"TestSetNotifyPassed go() 1"
);
stringstream tcLog;
tcLog << "Test ";
tcLog << "TestCaseSetNotifyPassed case Test passed! (";
Assertions::assertTrue(
!test->checkLog(tcLog.str()),
"TestSetNotifyPassed checkLog() 1"
);
Assertions::assertTrue(
!test->checkLog(string("s)")),
"TestSetNotifyPassed checkLog() 2"
);
test->setNotifyPassed(true);
Assertions::assertTrue(
test->go(),
"TestSetNotifyPassed go() 2"
);
Assertions::assertTrue(
test->checkLog(tcLog.str()),
"TestSetNotifyPassed checkLog() 3"
);
Assertions::assertTrue(
test->checkLog(string("s)")),
"TestSetNotifyPassed checkLog() 4"
);
test->clearLogCapture();
test->setNotifyPassed(false);
Assertions::assertTrue(
test->go(),
"TestSetNotifyPassed go() 3"
);
Assertions::assertTrue(
!test->checkLog(tcLog.str()),
"TestSetNotifyPassed checkLog() 5"
);
Assertions::assertTrue(
!test->checkLog(string("s)")),
"TestSetNotifyPassed checkLog() 6"
);
}
void TestTestCaseCheckStdout() {
auto test = unique_ptr<TestCase>(new TestCase(
"TestCaseCheckStdout case Test",
function<void()>([]() {
cout << "Test output to stdout!" << endl;
}),
false, true, false, false,
TestCase::TestCaseOutCompareOptions::EXACT
));
Assertions::assertTrue(
test->go(),
"TestCheckStdout go() 1"
);
Assertions::assertTrue(
test->checkStdout("Test output to stdout!\n"),
"TestCheckStdout checkStdout() 1"
);
}
void TestTestCaseCheckStderr() {
auto test = unique_ptr<TestCase>(new TestCase(
"TestCaseCheckStderr case Test",
function<void()>([]() {
cerr << "Test output to stderr!" << endl;
}),
false, false, false, true,
TestCase::TestCaseOutCompareOptions::EXACT
));
Assertions::assertTrue(
test->go(),
"TestCheckStderr go() 1"
);
Assertions::assertTrue(
test->checkStderr("Test output to stderr!\n"),
"TestCheckStderr checkStderr() 1"
);
}
}
}
}