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
|
#ifndef _TEST_UTIL_HPP_
#define _TEST_UTIL_HPP_
#include <sys/time.h> // gettimeofday()
#include <string>
#include <vector>
struct TestErrMsg
{
const char* fileName;
unsigned lineNo;
std::string errMsg;
TestErrMsg(const char* FN, unsigned LN, const char* Err):
fileName(FN), lineNo(LN), errMsg(Err) {}
};
class TestErrMsgMgr
{
public:
static std::vector<TestErrMsg> getError();
static void
addError(const char* fileName, unsigned lineNo, const char* Err) {
_errMsg.push_back(TestErrMsg(fileName, lineNo, Err));
}
static bool noError() {
return _errMsg.empty();
}
private:
static std::vector<TestErrMsg> _errMsg;
};
#define ASSERT(c, e) \
if (!(c)) { TestErrMsgMgr::addError(__FILE__, __LINE__, (e)); }
class TestClock
{
public:
void start() { gettimeofday(&_start, 0); }
void stop() { gettimeofday(&_end, 0); }
double getElapseInSecond() {
return (_end.tv_sec - _start.tv_sec)
+ ((long)_end.tv_usec - (long)_start.tv_usec) / 1000000.0;
}
private:
struct timeval _start, _end;
};
// write to /dev/null, the only purpose is to make the data fed to the
// function alive.
extern void test_printf(const char* format, ...)
__attribute__ ((format (printf, 1, 2)));
#endif //_TEST_UTIL_HPP_
|