[2] | 1 | #ifndef TEST_H |
---|
| 2 | #define TEST_H |
---|
| 3 | |
---|
| 4 | #include <iostream> |
---|
| 5 | #include <sstream> |
---|
| 6 | #include <stdint.h> |
---|
[44] | 7 | #include "Common/include/ErrorMorpheo.h" |
---|
[2] | 8 | using namespace std; |
---|
| 9 | |
---|
| 10 | //-----[ Routine de test ]--------------------------------------- |
---|
| 11 | |
---|
| 12 | static uint32_t num_test; |
---|
| 13 | |
---|
[53] | 14 | void test_ko_error (void) |
---|
| 15 | { |
---|
| 16 | string msg = "Test ko : error in test \""+toString(num_test)+"\""; |
---|
| 17 | throw (ErrorMorpheo (msg)); |
---|
| 18 | } |
---|
| 19 | |
---|
[2] | 20 | template <class T> |
---|
[53] | 21 | void test_ko (char * file, uint32_t line, T exp1, T exp2) |
---|
[2] | 22 | { |
---|
[53] | 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 (); |
---|
[2] | 33 | }; |
---|
| 34 | |
---|
[50] | 35 | void test_ko (char * file, uint32_t line) |
---|
| 36 | { |
---|
[53] | 37 | cerr << "[" << num_test << "] : Test KO" |
---|
| 38 | << "\tline " << line << endl |
---|
| 39 | << " * Localisation" << endl |
---|
| 40 | << " - File : " << file << endl |
---|
| 41 | << " - Line : " << line << endl; |
---|
[50] | 42 | |
---|
[53] | 43 | test_ko_error (); |
---|
[50] | 44 | }; |
---|
| 45 | |
---|
[2] | 46 | void test_ok () |
---|
| 47 | { |
---|
[53] | 48 | cout << "[" << num_test << "] : Test OK" << endl; |
---|
[2] | 49 | |
---|
| 50 | num_test ++; |
---|
| 51 | }; |
---|
| 52 | |
---|
[53] | 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 | |
---|
[2] | 65 | template <class T> |
---|
[53] | 66 | void test_ok (char * file, uint32_t line, T exp) |
---|
[2] | 67 | { |
---|
[53] | 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 | { |
---|
[2] | 84 | if (exp1 != exp2) |
---|
[53] | 85 | test_ko <T> (file,line,exp1,exp2); |
---|
[2] | 86 | else |
---|
[53] | 87 | test_ok <T> (file,line,exp1); |
---|
[2] | 88 | }; |
---|
| 89 | |
---|
[53] | 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) |
---|
[50] | 93 | #define TEST_KO(str...) do {fprintf(stdout,str); fprintf(stdout,"\n"); test_ko(__FILE__,__LINE__);} while(0) |
---|
[2] | 94 | |
---|
[50] | 95 | |
---|
[2] | 96 | #endif |
---|