-
Notifications
You must be signed in to change notification settings - Fork 64
/
Copy pathtest.h
36 lines (28 loc) · 964 Bytes
/
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
#ifndef TEST_H_INCLUDED
#define TEST_H_INCLUDED
#include <iostream>
#include <list>
typedef void (*VoidFunction)();
class UnitTest
{
public:
UnitTest(const std::list<VoidFunction>*);
virtual void TestSetup() {}
virtual void TestCaseSetup() {}
const std::list<VoidFunction> GetCases() { return *_cases; }
void SetTestCaseList(const std::list<VoidFunction>* cases) { _cases = cases; }
private:
const std::list<VoidFunction>* _cases;
};
extern int _failedAssertions;
#define REGISTER_TEST(t, ...) static UnitTest* test = new t (new std::list<VoidFunction> { __VA_ARGS__ });
#define STRING(s) #s
#define ASSERT(c) \
if (c) \
std::cout << "Test " << __FILE__ << "::" << __func__ << " passed." << std::endl; \
else \
{ \
std::cout << "Assertion failed: " << STRING(c) << " in " __FILE__ " : " << std::dec << __LINE__ << std::endl; \
_failedAssertions++; \
}
#endif // TEST_H_INCLUDED