-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestcase.h
More file actions
78 lines (61 loc) · 2.05 KB
/
testcase.h
File metadata and controls
78 lines (61 loc) · 2.05 KB
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
#ifndef __TESTCASE_H__
#define __TESTCASE_H__
#include "types.h"
#include <iostream>
#include <map>
#include <string_view>
using namespace std;
class TestcaseBase {
public:
void registerCaselet(const char *caselet) { caselets_[caselet] = false; }
void enableCaselet(const char *caselet) {
if (caselets_.contains(caselet))
caselets_[caselet] = true;
}
bool caseletEnabled(const char *caselet) {
return caselets_.contains(caselet) ? caselets_[caselet] : false;
}
virtual void testRoutine() {}
virtual ~TestcaseBase() {}
void printAllCaselets() {}
static auto GetTestcaseByIndex(u8 index) {
auto it = next(smTestCases_.begin(), index);
return it == smTestCases_.end() ? nullptr : it->second;
}
static int PrintAllTestcases() {
auto i = 0;
cout << "select the case number you want to test" << endl;
cout << "\ttest all cases[Enter]." << endl;
for (auto t : smTestCases_) {
cout << "\ttest " << t.first << "[" << i++ << "]." << endl;
}
return i;
}
static void PushCase(const char *name, TestcaseBase *tc) {
smTestCases_[name] = tc;
}
static void TestAllCases() {
for (auto t : smTestCases_) {
t.second->testRoutine();
}
}
static void FreeAllCases() {
for (auto t : smTestCases_) {
delete t.second;
}
}
private:
static map<string_view, TestcaseBase *> smTestCases_;
map<string_view, bool> caselets_;
};
#define TEST_IF(testlet, expr) \
{ \
if (caseletEnabled(#testlet)) { \
expr; \
} \
}
#define INIT_CASE(class) \
static void __attribute__((constructor)) initTestCase() { \
TestcaseBase::PushCase(#class, new class()); \
}
#endif