1 | #ifndef TEST_H |
---|
2 | #define TEST_H |
---|
3 | |
---|
4 | #include <iostream> |
---|
5 | #include <sstream> |
---|
6 | #include <stdint.h> |
---|
7 | #include "Common/include/ErrorMorpheo.h" |
---|
8 | using namespace std; |
---|
9 | |
---|
10 | //-----[ Routine de test ]--------------------------------------- |
---|
11 | |
---|
12 | static uint32_t num_test; |
---|
13 | |
---|
14 | void test_ko_error (void) |
---|
15 | { |
---|
16 | string msg = "Test ko : error in test \""+toString(num_test)+"\""; |
---|
17 | throw (ErrorMorpheo (msg)); |
---|
18 | } |
---|
19 | |
---|
20 | template <class T> |
---|
21 | void test_ko (char * file, uint32_t line, T exp1, T exp2) |
---|
22 | { |
---|
23 | cerr << "[" << num_test << "] : Test KO" |
---|
24 | << "\tline " << line << endl |
---|
25 | << " * Localisation" << endl |
---|
26 | << " - File : " << file << endl |
---|
27 | << " - Line : " << line << endl |
---|
28 | << " * Expression is different" << endl |
---|
29 | << " - exp1 : "+toString(exp1) << endl |
---|
30 | << " - exp2 : "+toString(exp2) << endl; |
---|
31 | |
---|
32 | test_ko_error (); |
---|
33 | }; |
---|
34 | |
---|
35 | void test_ko (char * file, uint32_t line) |
---|
36 | { |
---|
37 | cerr << "[" << num_test << "] : Test KO" |
---|
38 | << "\tline " << line << endl |
---|
39 | << " * Localisation" << endl |
---|
40 | << " - File : " << file << endl |
---|
41 | << " - Line : " << line << endl; |
---|
42 | |
---|
43 | test_ko_error (); |
---|
44 | }; |
---|
45 | |
---|
46 | void test_ok () |
---|
47 | { |
---|
48 | cout << "[" << num_test << "] : Test OK" << endl; |
---|
49 | |
---|
50 | num_test ++; |
---|
51 | }; |
---|
52 | |
---|
53 | void test_ok (char * file, uint32_t line) |
---|
54 | { |
---|
55 | cout << "[" << num_test << "] : Test OK" |
---|
56 | << "\tline " << line << endl |
---|
57 | // << " * Localisation" << endl |
---|
58 | // << " - File : " << file << endl |
---|
59 | // << " - Line : " << line << endl |
---|
60 | ; |
---|
61 | |
---|
62 | num_test ++; |
---|
63 | }; |
---|
64 | |
---|
65 | template <class T> |
---|
66 | void test_ok (char * file, uint32_t line, T exp) |
---|
67 | { |
---|
68 | cout << "[" << num_test << "] : Test OK" |
---|
69 | << "\tline " << line |
---|
70 | << "\tvalue : " << toString(exp) << endl |
---|
71 | // << " * Localisation" << endl |
---|
72 | // << " - File : " << file << endl |
---|
73 | // << " - Line : " << line << endl |
---|
74 | // << " * Expression" << endl |
---|
75 | // << " - exp : "+toString(exp) << endl |
---|
76 | ; |
---|
77 | |
---|
78 | num_test ++; |
---|
79 | } |
---|
80 | |
---|
81 | template <class T> |
---|
82 | void test(char * file, uint32_t line, T exp1, T exp2) |
---|
83 | { |
---|
84 | if (exp1 != exp2) |
---|
85 | test_ko <T> (file,line,exp1,exp2); |
---|
86 | else |
---|
87 | test_ok <T> (file,line,exp1); |
---|
88 | }; |
---|
89 | |
---|
90 | #define TEST(type,exp1,exp2) do {test<type> (__FILE__,__LINE__,exp1,exp2);} while(0) |
---|
91 | #define TEST_STR(type,exp1,exp2,str...) do {fprintf(stdout,str); fprintf(stdout,"\n"); test<type> (__FILE__,__LINE__,exp1,exp2);} while(0) |
---|
92 | #define TEST_OK(str...) do {fprintf(stdout,str); fprintf(stdout,"\n"); test_ok(__FILE__,__LINE__);} while(0) |
---|
93 | #define TEST_KO(str...) do {fprintf(stdout,str); fprintf(stdout,"\n"); test_ko(__FILE__,__LINE__);} while(0) |
---|
94 | |
---|
95 | |
---|
96 | #endif |
---|