forked from znort987/blockparser
-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.h
84 lines (68 loc) · 2.19 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
74
75
76
77
78
79
80
81
82
83
84
#ifndef __TEST_H__
#define __TEST_H__
#include <string>
#include <vector>
struct Test {
private:
static void runFilter(
const char *filter,
int &failCount,
int &testCount
);
public:
Test();
virtual ~Test() {}
virtual int run() = 0;
virtual bool isActive() { return true; }
virtual const std::string &getName() const = 0;
static void runAll(char *filters[] = 0);
static void pushMsg(const char *msg, ...);
static void check(
bool &ok,
bool cond,
const char *func,
const char *file,
int line,
const char *cStr,
const char *msg = 0,
...
);
};
class SimpleTest:public Test {
private:
typedef int (*Func)();
const std::string name;
Func func;
bool active;
public:
SimpleTest(
Func _func,
const char *_name,
bool _active = true
) : name(_name),
func(_func),
active(_active)
{
}
virtual int run() { return (*func)(); }
virtual bool isActive() { return active; }
virtual const std::string &getName() const { return name; }
};
#define TEST_DECLARE(x) static SimpleTest t_##x(x, #x);
#define TEST_CHECK(var, cond, ...) \
do \
{ \
Test::check( \
(var), \
(cond), \
__func__, \
__FILE__, \
__LINE__, \
#cond, \
##__VA_ARGS__ \
); \
} \
while(0) \
#define TEST_CHECKS(var, cond) \
TEST_CHECK(var, cond, 0)
#endif // __TEST_H__