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