forked from ennorehling/cutest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCuTestCPP.cpp
79 lines (62 loc) · 1.58 KB
/
CuTestCPP.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
#include "CuTestCPP.h"
const std::vector<TestFuncData>* BaseCuTest::getTestFuncs() const {
return &testFunctions;
}
CuSuiteWrapper::CuSuiteWrapper() {
suite = CuSuiteNew();
}
CuSuiteWrapper::~CuSuiteWrapper() {
CuSuiteDelete(suite);
}
void CuSuiteWrapper::addTest(BaseCuTest* test) {
const std::vector<TestFuncData>* testFuncs = test->getTestFuncs();
if (testFuncs->size() != 0) {
baseTests.push_back(test);
for (const TestFuncData& funcData : *(testFuncs))
SUITE_ADD_TEST_NAME(suite, [this](CuTest* tc) {this->runTest(tc);}, funcData.name);
}
}
void CuSuiteWrapper::runTest(CuTest* tc) {
if (testIndex == 0)
(*testsIt)->testStart();
(*testsIt)->tc = tc;
(*testsIt)->before();
try {
(*(*testsIt)->getTestFuncs())[testIndex++].func();
}
catch (int ex) {
nextTest();
throw ex;
}
nextTest();
}
void CuSuiteWrapper::nextTest() {
(*testsIt)->after();
if (testIndex == (*testsIt)->getTestFuncs()->size()) {
(*(testsIt++))->testEnd();
testIndex = 0;
}
}
bool CuSuiteWrapper::run() {
testIndex = 0;
testsIt = baseTests.begin();
CuSuiteRun(suite);
summary.clear();
details.clear();
CuString* cuStr = CuStringNew();
CuSuiteSummary(suite, cuStr);
summary.append(cuStr->buffer);
CuStringClear(cuStr);
CuSuiteDetails(suite, cuStr);
details.append(cuStr->buffer);
CuStringDelete(cuStr);
testSuccess = suite->failCount == 0;
return testSuccess;
}
CuTestResult CuSuiteWrapper::getTestResult() const {
return {testSuccess, summary.c_str(), details.c_str()};
}
void CuSuiteWrapper::printResult() const {
printf(summary.c_str());
printf(details.c_str());
}