-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.h
87 lines (72 loc) · 2.12 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
85
86
87
#pragma once
#include <iostream>
#include <cstdint>
#include <string>
#include "kvstore.h"
class Test {
protected:
static const std::string not_found;
uint64_t nr_tests;
uint64_t nr_passed_tests;
uint64_t nr_phases;
uint64_t nr_passed_phases;
#define EXPECT(exp, got) expect<decltype(got)>((exp), (got), __FILE__, __LINE__)
template<typename T>
void expect(const T &exp, const T &got,
const std::string &file, int line)
{
++nr_tests;
if (exp == got) {
++nr_passed_tests;
// std::cout << "passed" << nr_passed_tests << std::endl;
return;
}else{
// std::cout << "failed: " << nr_passed_tests << "/" << nr_tests << std::endl;
}
if (verbose) {
std::cerr << "TEST Error @" << file << ":" << line;
std::cerr << ", expected " << exp;
std::cerr << ", got " << got << std::endl;
}
}
void phase(void)
{
// Report
std::cout << " Phase " << (nr_phases+1) << ": ";
std::cout << nr_passed_tests << "/" << nr_tests << " ";
// Count
++nr_phases;
if (nr_tests == nr_passed_tests) {
++nr_passed_phases;
std::cout << "[PASS]" << std::endl;
} else
std::cout << "[FAIL]" << std::endl;
std::cout.flush();
// Reset
nr_tests = 0;
nr_passed_tests = 0;
}
void report(void)
{
std::cout << nr_passed_phases << "/" << nr_phases << " passed.";
std::cout << std::endl;
std::cout.flush();
nr_phases = 0;
nr_passed_phases = 0;
}
class KVStore store;
bool verbose;
public:
Test(const std::string &dir, bool v=true): store(dir), verbose(v)
{
nr_tests = 0;
nr_passed_tests = 0;
nr_phases = 0;
nr_passed_phases = 0;
}
virtual void start_test(void *args = NULL)
{
std::cout << "No test is implemented." << std::endl;
}
};
const std::string Test::not_found = "";