-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.h
73 lines (63 loc) · 1.44 KB
/
test.h
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
// Test.h
#ifndef TEST_H
#define TEST_H #include <string>
#include <iostream>
#include <cassert>
using std::string;
using std::ostream;
using std::cout;
// The following have underscores because they are macros.
// (The motivation was to avoid a conflict with ios::fail).
// For consistency, succeed_() also has an underscore.
#define test_(cond) \
do_test(cond, #cond, __FILE__, __LINE__)
#define fail_(str) \
do_fail(str, __FILE__, __LINE__)
class Test {
public:
Test(ostream* osptr = &cout);
virtual ~Test(){}
virtual void run() = 0;
long getNumPassed() const;
long getNumFailed() const;
const ostream* getStream() const;
void setStream(ostream* osptr);
void succeed_();
long report() const;
virtual void reset();
protected:
void do_test(bool cond, const string& lbl,
const char* fname, long lineno);
void do_fail(const string& lbl,
const char* fname, long lineno);
private:
ostream* osptr;
long nPass;
long nFail;
// Disallowed:
Test(const Test&);
Test& operator=(const Test&);
};
inline Test::Test(ostream* osptr) {
this->osptr = osptr;
assert(osptr);
nPass = nFail = 0;
}
inline long Test::getNumPassed() const {
return nPass;
}
inline long Test::getNumFailed() const {
return nFail;
}
inline const ostream* Test::getStream() const {
return osptr;
}
inline void Test::setStream(ostream* osptr) {
this->osptr = osptr;
}
inline void Test::succeed_() { ++nPass;
}
inline void Test::reset() {
nPass = nFail = 0;
}
#endif // TEST_H