-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTest.cpp
85 lines (64 loc) · 1.54 KB
/
Test.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
#include "Test.h"
Test::Test(string name) : _name(name) {
_failed = 0;
_passed = 0;
}
string Test::getName() {
return _name;
}
int Test::getFailed() {
return _failed;
}
int Test::getPassed() {
return _passed;
}
bool Test::testFailed() {
_failed++;
return false;
}
bool Test::testSuccess() {
_passed++;
return true;
}
bool Test::assertTrue(const bool condition) {
if(condition == true) {
return testSuccess();
}
return testFailed();
}
bool Test::assertFalse(const bool condition) {
if(condition == false) {
return testSuccess();
}
return testFailed();
}
bool Test::assertEquals(const string a, const string b) {
if(a.compare(b) == 0) {
return testSuccess();
}
return testFailed();
}
bool Test::assertEquals(const char* a, const char* b, const int len) {
for(int i = 0; i < len; ++i) {
//std::cout << (int)*a;
//std::cout << " vs ";
//std::cout << (int)*b;
//std::cout.write(b, 1);
if(*a++ != *b++) {
return testFailed();
}
}
return testSuccess();
}
void Test::trace(string data) {
_traceBuffer << " - Error " << data << endl;
}
void Test::trace(string data, string data1) {
_traceBuffer << " - Error " << data << " " << data1 << endl;
}
void Test::trace(string data, string data1, string data2) {
_traceBuffer << " - Error " << data << " " << data1 << " " << data2 << endl;
}
const std::string Test::getTraceBuffer() {
return _traceBuffer.str();
}