-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathetest.cc
73 lines (65 loc) · 1.51 KB
/
etest.cc
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
#ifndef DEPEND
#ifdef LINUX
#include <cstdlib>
#include <iostream>
using std::cout;
using std::cerr;
using std::endl;
#else
#include <stdlib.h>
#include <iostream.h>
#endif
#endif
#include "etest.hh"
bool runTest(TestCase *f);
void reportTests();
void cleanTests();
int successCount = 0;
int failureCount = 0;
static TestNode *headTestNode = 0;
TestNode *addTest(TestFactoryBase *f) {
TestNode *newCase = new TestNode(f, headTestNode);
headTestNode = newCase;
return headTestNode;
}
void reportTests() {
cout << "Tests ended. Total count = " << (successCount + failureCount) << endl;
cout << "SUCCESSFUL Tests = " << (successCount) << endl;
cout << "FAILED Tests = " << (failureCount) << endl;
}
bool runTest(TestCase *f) {
cout << "Running test: " << f->getGroup() << ":" << f->getScenario() << endl;
try {
f->body();
return true;
}
catch (...) {
cerr << "FAILED! " << f->getGroup() << ":" << f->getScenario() << endl;
return false;
}
}
void cleanTests() {
delete headTestNode;
headTestNode = 0;
}
int RUN_ALL_TESTS() {
TestNode *h = headTestNode;
while (h) {
TestCase *testCase = h->testfun_->createTest();
if (runTest(testCase)) {
successCount++;
}
else
{
testCase->reportEvents(cout);
failureCount++;
}
h = h->next_;
}
reportTests();
cleanTests();
if (failureCount > 0) {
return 1;
}
return 0;
}