[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 | |
---|
| 14 | template <class T> |
---|
| 15 | void test_ko (T exp1, T exp2, char * file, uint32_t line) |
---|
| 16 | { |
---|
[15] | 17 | string msg = ("<"+toString(num_test)+"> : Test KO\n" + |
---|
[3] | 18 | " * Localisation\n" + |
---|
| 19 | " - File : "+file+"\n" + |
---|
| 20 | " - Line : "+toString(line)+"\n" + |
---|
| 21 | " * Expression is different\n" + |
---|
| 22 | " - exp1 : "+toString(exp1)+"\n" + |
---|
| 23 | " - exp2 : "+toString(exp2)+"\n"); |
---|
| 24 | |
---|
| 25 | throw (ErrorMorpheo (msg)); |
---|
[2] | 26 | }; |
---|
| 27 | |
---|
[50] | 28 | void test_ko (char * file, uint32_t line) |
---|
| 29 | { |
---|
| 30 | string msg = ("<"+toString(num_test)+"> : Test KO\n" + |
---|
| 31 | " * Localisation\n" + |
---|
| 32 | " - File : "+file+"\n" + |
---|
| 33 | " - Line : "+toString(line)+"\n"); |
---|
| 34 | |
---|
| 35 | throw (ErrorMorpheo (msg)); |
---|
| 36 | }; |
---|
| 37 | |
---|
[2] | 38 | void test_ok () |
---|
| 39 | { |
---|
| 40 | cout << "{" << num_test << "} : Test OK" << endl; |
---|
| 41 | |
---|
| 42 | num_test ++; |
---|
| 43 | }; |
---|
| 44 | |
---|
| 45 | template <class T> |
---|
| 46 | void test(T exp1, T exp2, char * file, uint32_t line) |
---|
| 47 | { |
---|
| 48 | if (exp1 != exp2) |
---|
| 49 | test_ko <T> (exp1,exp2,file,line); |
---|
| 50 | else |
---|
| 51 | test_ok (); |
---|
| 52 | }; |
---|
| 53 | |
---|
[50] | 54 | #define TEST(type,exp1,exp2) do {test<type> (exp1,exp2,__FILE__,__LINE__);} while(0) |
---|
| 55 | #define TEST_STR(type,exp1,exp2,str...) do {fprintf(stdout,str); fprintf(stdout,"\n"); test<type> (exp1,exp2,__FILE__,__LINE__);} while(0) |
---|
| 56 | #define TEST_OK(str...) do {fprintf(stdout,str); fprintf(stdout,"\n"); test_ok();} while(0) |
---|
| 57 | #define TEST_KO(str...) do {fprintf(stdout,str); fprintf(stdout,"\n"); test_ko(__FILE__,__LINE__);} while(0) |
---|
[2] | 58 | |
---|
[50] | 59 | |
---|
[2] | 60 | #endif |
---|