19#ifndef itkTestingMacros_h
20#define itkTestingMacros_h
38#define EXERCISE_BASIC_OBJECT_METHODS \
39 static_assert(false, "Replace EXERCISE_BASIC_OBJECT_METHODS with ITK_EXERCISE_BASIC_OBJECT_METHODS")
40#define TRY_EXPECT_EXCEPTION static_assert(false, "Replace TRY_EXPECT_EXCEPTION with ITK_TRY_EXPECT_EXCEPTION")
41#define TRY_EXPECT_NO_EXCEPTION static_assert(fasle, "Replace TRY_EXPECT_NO_EXCEPTION with ITK_TRY_EXPECT_NO_EXCEPTION")
42#define TEST_EXPECT_TRUE_STATUS_VALUE \
43 static_assert(false, "Replace TEST_EXPECT_TRUE_STATUS_VALUE with ITK_TEST_EXPECT_TRUE_STATUS_VALUE")
44#define TEST_EXPECT_TRUE static_assert(false, "Replace TEST_EXPECT_TRUE with ITK_TEST_EXPECT_TRUE")
45#define TEST_EXPECT_EQUAL_STATUS_VALUE "Replace TEST_EXPECT_EQUAL_STATUS_VALUE with ITK_TEST_EXPECT_EQUAL_STATUS_VALUE"
46#define TEST_EXPECT_EQUAL static_assert(false, "Replace TEST_EXPECT_EQUAL with ITK_TEST_EXPECT_EQUAL")
47#define TEST_SET_GET static_assert(false, "Replace TEST_SET_GET with ITK_TEST_SET_GET")
48#define TEST_SET_GET_VALUE static_assert(false, "Replace TEST_SET_GET_VALUE with ITK_TEST_SET_GET_VALUE")
49#define TEST_SET_GET_NULL_VALUE static_assert(false, "Replace TEST_SET_GET_NULL_VALUE with ITK_TEST_SET_GET_NULL_VALUE")
50#define TEST_SET_GET_BOOLEAN static_assert(false, "Replace TEST_SET_GET_BOOLEAN with ITK_TEST_SET_GET_BOOLEAN")
55#define ITK_EXERCISE_BASIC_OBJECT_METHODS(object, ClassName, SuperclassName) \
56 object->Print(std::cout); \
57 std::cout << "Name of Class = " << object->GetNameOfClass() << std::endl; \
58 ITK_MACROEND_NOOP_STATEMENT
60#define ITK_EXERCISE_BASIC_OBJECT_METHODS(object, ClassName, SuperclassName) \
61 object->Print(std::cout); \
62 std::cout << "Name of Class = " << object->Self::GetNameOfClass() << std::endl; \
63 std::cout << "Name of Superclass = " << object->Superclass::GetNameOfClass() << std::endl; \
64 if (!std::strcmp(object->Self::GetNameOfClass(), #ClassName)) \
66 std::cout << "Class name is correct" << std::endl; \
70 std::cerr << "Class name provided does not match object's NameOfClass" << std::endl; \
71 return EXIT_FAILURE; \
73 if (!std::strcmp(object->Superclass::GetNameOfClass(), #SuperclassName)) \
75 std::cout << "Superclass name is correct" << std::endl; \
79 std::cerr << "Superclass name provided does not match object's Superclass::NameOfClass" << std::endl; \
80 return EXIT_FAILURE; \
82 ITK_MACROEND_NOOP_STATEMENT
86#define ITK_TRY_EXPECT_EXCEPTION(command) \
89 std::cout << "Trying " << #command << std::endl; \
91 std::cerr << "Failed to catch expected exception" << std::endl; \
92 std::cerr << " In " __FILE__ ", line " << __LINE__ << std::endl; \
93 return EXIT_FAILURE; \
95 catch (const itk::ExceptionObject & excp) \
97 std::cout << "Caught expected exception" << std::endl; \
98 std::cout << excp << std::endl; \
100 ITK_MACROEND_NOOP_STATEMENT
103#define ITK_TRY_EXPECT_NO_EXCEPTION(command) \
106 std::cout << "Trying " << #command << std::endl; \
109 catch (const itk::ExceptionObject & excp) \
111 std::cerr << excp << std::endl; \
112 std::cerr << " In " __FILE__ ", line " << __LINE__ << std::endl; \
113 return EXIT_FAILURE; \
115 ITK_MACROEND_NOOP_STATEMENT
117#define ITK_TEST_EXPECT_TRUE_STATUS_VALUE(command, statusVal) \
119 ITK_GCC_PRAGMA_PUSH \
120 ITK_GCC_SUPPRESS_Wfloat_equal \
121 bool _ITK_TEST_EXPECT_TRUE_command(command); \
123 if (!(_ITK_TEST_EXPECT_TRUE_command)) \
125 std::cerr << "Error in " << #command << std::endl; \
126 std::cerr << " In " __FILE__ ", line " << __LINE__ << std::endl; \
127 std::cerr << "Expected true" << std::endl; \
128 std::cerr << " but got " << _ITK_TEST_EXPECT_TRUE_command << std::endl; \
129 statusVal = EXIT_FAILURE; \
132 ITK_MACROEND_NOOP_STATEMENT
134#define ITK_TEST_EXPECT_TRUE(command) \
136 ITK_GCC_PRAGMA_PUSH \
137 ITK_GCC_SUPPRESS_Wfloat_equal \
138 bool _ITK_TEST_EXPECT_TRUE_command(command); \
140 if (!(_ITK_TEST_EXPECT_TRUE_command)) \
142 std::cerr << "Error in " << #command << std::endl; \
143 std::cerr << " In " __FILE__ ", line " << __LINE__ << std::endl; \
144 std::cerr << "Expected true" << std::endl; \
145 std::cerr << " but got " << _ITK_TEST_EXPECT_TRUE_command << std::endl; \
146 return EXIT_FAILURE; \
149 ITK_MACROEND_NOOP_STATEMENT
152#define ITK_TEST_EXPECT_EQUAL_STATUS_VALUE(lh, rh, statusVal) \
154 ITK_GCC_PRAGMA_PUSH \
155 ITK_GCC_SUPPRESS_Wfloat_equal \
156 bool _ITK_TEST_EXPECT_EQUAL_result((lh) == (rh)); \
158 if (!(_ITK_TEST_EXPECT_EQUAL_result)) \
160 std::cerr << "Error in " << #lh << " == " << #rh << std::endl; \
161 std::cerr << "\tIn " __FILE__ ", line " << __LINE__ << std::endl; \
162 std::cerr << "\tlh: " << (lh) << std::endl; \
163 std::cerr << "\trh: " << (rh) << std::endl; \
164 std::cerr << "Expression is not equal" << std::endl; \
165 statusVal = EXIT_FAILURE; \
168 ITK_MACROEND_NOOP_STATEMENT
170#define ITK_TEST_EXPECT_EQUAL(lh, rh) \
172 ITK_GCC_PRAGMA_PUSH \
173 ITK_GCC_SUPPRESS_Wfloat_equal \
174 bool _ITK_TEST_EXPECT_EQUAL_result((lh) == (rh)); \
176 if (!(_ITK_TEST_EXPECT_EQUAL_result)) \
178 std::cerr << "Error in " << #lh << " == " << #rh << std::endl; \
179 std::cerr << "\tIn " __FILE__ ", line " << __LINE__ << std::endl; \
180 std::cerr << "\tlh: " << (lh) << std::endl; \
181 std::cerr << "\trh: " << (rh) << std::endl; \
182 std::cerr << "Expression is not equal" << std::endl; \
183 return EXIT_FAILURE; \
186 ITK_MACROEND_NOOP_STATEMENT
189#define ITK_TEST_SET_GET(variable, command) \
190 if (variable != command) \
192 std::cerr << "Error in " << #command << std::endl; \
193 std::cerr << " In " __FILE__ ", line " << __LINE__ << std::endl; \
194 std::cerr << "Expected " << variable.GetPointer() << std::endl; \
195 std::cerr << "but got " << command << std::endl; \
196 return EXIT_FAILURE; \
198 ITK_MACROEND_NOOP_STATEMENT
201#define ITK_TEST_SET_GET_VALUE(variable, command) \
202 ITK_GCC_PRAGMA_PUSH \
203 ITK_GCC_SUPPRESS_Wfloat_equal \
204 if (variable != command) \
206 std::cerr << "Error in " << #command << std::endl; \
207 std::cerr << " In " __FILE__ ", line " << __LINE__ << std::endl; \
208 std::cerr << "Expected " << variable << std::endl; \
209 std::cerr << "but got " << command << std::endl; \
210 return EXIT_FAILURE; \
213 ITK_MACROEND_NOOP_STATEMENT
215#define ITK_TEST_SET_GET_NULL_VALUE(command) \
216 if (nullptr != command) \
218 std::cerr << "Error in " << #command << std::endl; \
219 std::cerr << " In " __FILE__ ", line " << __LINE__ << std::endl; \
220 std::cerr << "Expected " \
221 << "nullptr" << std::endl; \
222 std::cerr << "but got " << command << std::endl; \
223 return EXIT_FAILURE; \
225 ITK_MACROEND_NOOP_STATEMENT
227#define ITK_TEST_SET_GET_BOOLEAN(object, variable, value) \
228 object->Set##variable(false); \
229 object->Set##variable(true); \
230 if (object->Get##variable() != 1) \
232 std::cerr << "Error in Set/Get" #variable << ", Get" #variable << " is " << object->Get##variable() \
233 << " instead of 1" << std::endl; \
234 return EXIT_FAILURE; \
236 object->Set##variable(false); \
237 if (object->Get##variable() != 0) \
239 std::cerr << "Error in Set/Get" #variable << ", Get" #variable << " is " << object->Get##variable() \
240 << " instead of 0" << std::endl; \
241 return EXIT_FAILURE; \
243 object->variable##On(); \
244 if (object->Get##variable() != 1) \
246 std::cerr << "Error in On/Get" #variable << ", Get" #variable << " is " << object->Get##variable() \
247 << " instead of 1" << std::endl; \
248 return EXIT_FAILURE; \
250 object->variable##Off(); \
251 if (object->Get##variable() != 0) \
253 std::cerr << "Error in Off/Get" #variable << ", Get" #variable << " is " << object->Get##variable() \
254 << " instead of 0" << std::endl; \
255 return EXIT_FAILURE; \
257 object->Set##variable(value)
262#define itkNameOfTestExecutableMacro(argv) \
263 [argv](const std::string & functionName) { \
264 return ((argv == nullptr) || (argv[0] == nullptr) || (argv[0][0] == '\0')) ? ("<" + functionName + " executable>") \
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....