G+Smo  24.08.0
Geometry + Simulation Modules
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CheckMacros.h
1 
14 #ifndef COMMON_CHECKSMACROS_H
15 #define COMMON_CHECKSMACROS_H
16 
17 #include "Config.h"
18 #include "TestResults.h"
19 #include "MemoryOutStream.h"
20 #include "gs/CheckMatrix.h"
21 #include "gs/CheckFiles.h"
22 
23 namespace UnitTest {
24 
25 #define CHECK_MATRIX_CLOSE(expected, actual, tolerance) \
26  UNITTEST_MULTILINE_MACRO_BEGIN \
27  UT_TRY \
28  ({ \
29  UnitTest::CheckMatrixClose(*UnitTest::CurrentTest::Results(), expected, actual, \
30  tolerance, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__)); \
31  }) \
32  UT_CATCH (std::exception, e, \
33  { \
34  UnitTest::MemoryOutStream message; \
35  message << "Unhandled exception (" << e.what() << ") in CHECK_MATRIX_CLOSE(" #expected ", " #actual ")"; \
36  UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \
37  message.GetText()); \
38  }) \
39  UT_CATCH_ALL \
40  ({ \
41  UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \
42  "Unhandled exception in CHECK_MATRIX_CLOSE(" #expected ", " #actual ")"); \
43  }) \
44  UNITTEST_MULTILINE_MACRO_END
45 
46 
47 // all the colum sums are equal to one (1)
48 #define CHECK_MATRIX_PARTITION_OF_UNIT_CLOSE(actual, tolerance) \
49  UNITTEST_MULTILINE_MACRO_BEGIN \
50  UT_TRY \
51  ({ \
52  UnitTest::CheckMatrixPartitionOfUnitClose(*UnitTest::CurrentTest::Results(), actual, \
53  tolerance, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__)); \
54  }) \
55  UT_CATCH (std::exception, e, \
56  { \
57  UnitTest::MemoryOutStream message; \
58  message << "Unhandled exception (" << e.what() << ") in CHECK_MATRIX_PARTITION_OF_UNIT_CLOSE(" #actual ")"; \
59  UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \
60  message.GetText()); \
61  }) \
62  UT_CATCH_ALL \
63  ({ \
64  UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \
65  "Unhandled exception in CHECK_MATRIX_PARTITION_OF_UNIT_CLOSE(" #actual ")"); \
66  }) \
67  UNITTEST_MULTILINE_MACRO_END
68 
69 #define CHECK_FILES_EQUAL(actual, expected) \
70  UNITTEST_MULTILINE_MACRO_BEGIN \
71  UT_TRY \
72  ({ \
73  UnitTest::CheckFilesEqual(*UnitTest::CurrentTest::Results(), actual, \
74  expected, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__)); \
75  }) \
76  UT_CATCH (std::exception, e, \
77  { \
78  UnitTest::MemoryOutStream message; \
79  message << "Unhandled exception (" << e.what() << ") in CHECK_FILES_EQUAL(" #actual ")"; \
80  UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \
81  message.GetText()); \
82  }) \
83  UT_CATCH_ALL \
84  ({ \
85  UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \
86  "Unhandled exception in CHECK_FILES_EQUAL(" #actual ")"); \
87  }) \
88  UNITTEST_MULTILINE_MACRO_END
89 
90 #define CHECK_FILES_EQUAL_IGNORE(actual, expected, ignoreLines) \
91  UNITTEST_MULTILINE_MACRO_BEGIN \
92  UT_TRY \
93  ({ \
94  UnitTest::CheckFilesEqual(*UnitTest::CurrentTest::Results(), actual, \
95  expected, ignoreLines, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__)); \
96  }) \
97  UT_CATCH (std::exception, e, \
98  { \
99  UnitTest::MemoryOutStream message; \
100  message << "Unhandled exception (" << e.what() << ") in CHECK_FILES_EQUAL(" #actual ")"; \
101  UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \
102  message.GetText()); \
103  }) \
104  UT_CATCH_ALL \
105  ({ \
106  UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \
107  "Unhandled exception in CHECK_FILES_EQUAL(" #actual ")"); \
108  }) \
109  UNITTEST_MULTILINE_MACRO_END
110 
111 #ifndef NDEBUG
112 #define CHECK_THROW_IN_DEBUG(condition, expectedException) \
113  CHECK_THROW(condition, expectedException)
114 #else
115 #define CHECK_THROW_IN_DEBUG(condition, expectedException)
116 #endif
117 
118 } // end namespace UnitTest
119 
120 #endif // COMMON_CHECKSMACROS_H
121