tizen 2.4 release
[external/xdelta3.git] / testing / test.h
1 // -*- Mode: C++ -*-
2
3 extern "C" {
4 #include "../xdelta3.h"
5 #include "../xdelta3-internal.h"
6 }
7
8 #include <unistd.h>
9 #include <math.h>
10 #include <string>
11
12 #define CHECK_EQ(x,y) CHECK_OP(x,y,==)
13 #define CHECK_NE(x,y) CHECK_OP(x,y,!=)
14 #define CHECK_LT(x,y) CHECK_OP(x,y,<)
15 #define CHECK_GT(x,y) CHECK_OP(x,y,>)
16 #define CHECK_LE(x,y) CHECK_OP(x,y,<=)
17 #define CHECK_GE(x,y) CHECK_OP(x,y,>=)
18
19 #define CHECK_OP(x,y,OP) \
20   do { \
21     typeof(x) _x(x); \
22     typeof(x) _y(y); \
23     if (!(_x OP _y)) { \
24       cerr << __FILE__ << ":" << __LINE__ << " Check failed: " << #x " " #OP " " #y << endl; \
25       cerr << __FILE__ << ":" << __LINE__ << " Expected: " << _x << endl; \
26       cerr << __FILE__ << ":" << __LINE__ << " Actual: " << _y << endl; \
27     abort(); \
28     } } while (false)
29 #undef CHECK
30 #define CHECK(x) \
31   do {if (!(x)) {                                      \
32   cerr << __FILE__ << ":" << __LINE__ << " Check failed: " << #x << endl; \
33   abort(); \
34     } } while (false)
35
36 #define DCHECK(x)
37
38 using std::string;
39
40 #include <vector>
41 using std::vector;
42
43 inline string CommandToString(const vector<const char*> &v) {
44   string s(v[0]);
45   for (size_t i = 1; i < v.size() && v[i] != NULL; i++) {
46     s.append(" ");
47     s.append(v[i]);
48   }
49   return s;
50 }
51
52 #include <iostream>
53 using std::cerr;
54 using std::endl;
55 using std::ostream;
56
57 #include <map> 
58 using std::map;
59 using std::pair;
60
61 #include <list>
62 using std::list;
63
64 template <typename T, typename U>
65 pair<T, U> make_pair(const T& t, const U& u) {
66   return pair<T, U>(t, u);
67 }
68
69 using std::min;
70 using std::max;
71
72