19#ifndef itkTestingMacros_h
20#define itkTestingMacros_h
38#if defined(ITK_FUTURE_LEGACY_REMOVE)
40# if defined(__clang__) || defined(__GNUC__)
41# pragma GCC poison EXERCISE_BASIC_OBJECT_METHODS
42# pragma GCC poison TRY_EXPECT_EXCEPTION
43# pragma GCC poison TRY_EXPECT_NO_EXCEPTION
44# pragma GCC poison TEST_EXPECT_TRUE_STATUS_VALUE
45# pragma GCC poison TEST_EXPECT_TRUE
46# pragma GCC poison TEST_EXPECT_EQUAL_STATUS_VALUE
47# pragma GCC poison TEST_EXPECT_EQUAL
48# pragma GCC poison TEST_SET_GET
49# pragma GCC poison TEST_SET_GET_VALUE
50# pragma GCC poison TEST_SET_GET_NULL_VALUE
51# pragma GCC poison TEST_SET_GET_BOOLEAN
53# define EXERCISE_BASIC_OBJECT_METHODS "Replace EXERCISE_BASIC_OBJECT_METHODS with ITK_EXERCISE_BASIC_OBJECT_METHODS"
54# define TRY_EXPECT_EXCEPTION "Replace TRY_EXPECT_EXCEPTION with ITK_TRY_EXPECT_EXCEPTION"
55# define TRY_EXPECT_NO_EXCEPTION "Replace TRY_EXPECT_NO_EXCEPTION with ITK_TRY_EXPECT_NO_EXCEPTION"
56# define TEST_EXPECT_TRUE_STATUS_VALUE "Replace TEST_EXPECT_TRUE_STATUS_VALUE with ITK_TEST_EXPECT_TRUE_STATUS_VALUE"
57# define TEST_EXPECT_TRUE "Replace TEST_EXPECT_TRUE with ITK_TEST_EXPECT_TRUE"
58# define TEST_EXPECT_EQUAL_STATUS_VALUE \
59 "Replace TEST_EXPECT_EQUAL_STATUS_VALUE with ITK_TEST_EXPECT_EQUAL_STATUS_VALUE"
60# define TEST_EXPECT_EQUAL "Replace TEST_EXPECT_EQUAL with ITK_TEST_EXPECT_EQUAL"
61# define TEST_SET_GET "Replace TEST_SET_GET with ITK_TEST_SET_GET"
62# define TEST_SET_GET_VALUE "Replace TEST_SET_GET_VALUE with ITK_TEST_SET_GET_VALUE"
63# define TEST_SET_GET_NULL_VALUE "Replace TEST_SET_GET_NULL_VALUE with ITK_TEST_SET_GET_NULL_VALUE"
64# define TEST_SET_GET_BOOLEAN "Replace TEST_SET_GET_BOOLEAN with ITK_TEST_SET_GET_BOOLEAN"
67# define EXERCISE_BASIC_OBJECT_METHODS ITK_EXERCISE_BASIC_OBJECT_METHODS
68# define TRY_EXPECT_EXCEPTION ITK_TRY_EXPECT_EXCEPTION
69# define TRY_EXPECT_NO_EXCEPTION ITK_TRY_EXPECT_NO_EXCEPTION
70# define TEST_EXPECT_TRUE_STATUS_VALUE ITK_TEST_EXPECT_TRUE_STATUS_VALUE
71# define TEST_EXPECT_TRUE ITK_TEST_EXPECT_TRUE
72# define TEST_EXPECT_EQUAL_STATUS_VALUE ITK_TEST_EXPECT_EQUAL_STATUS_VALUE
73# define TEST_EXPECT_EQUAL ITK_TEST_EXPECT_EQUAL
74# define TEST_SET_GET ITK_TEST_SET_GET
75# define TEST_SET_GET_VALUE ITK_TEST_SET_GET_VALUE
76# define TEST_SET_GET_NULL_VALUE ITK_TEST_SET_GET_NULL_VALUE
77# define TEST_SET_GET_BOOLEAN ITK_TEST_SET_GET_BOOLEAN
82#define ITK_EXERCISE_BASIC_OBJECT_METHODS(object, ClassName, SuperclassName) \
83 object->Print(std::cout); \
84 std::cout << "Name of Class = " << object->GetNameOfClass() << std::endl; \
85 ITK_MACROEND_NOOP_STATEMENT
87#define ITK_EXERCISE_BASIC_OBJECT_METHODS(object, ClassName, SuperclassName) \
88 object->Print(std::cout); \
89 std::cout << "Name of Class = " << object->Self::GetNameOfClass() << std::endl; \
90 std::cout << "Name of Superclass = " << object->Superclass::GetNameOfClass() << std::endl; \
91 if (!std::strcmp(object->Self::GetNameOfClass(), #ClassName)) \
93 std::cout << "Class name is correct" << std::endl; \
97 std::cerr << "Class name provided does not match object's NameOfClass" << std::endl; \
98 return EXIT_FAILURE; \
100 if (!std::strcmp(object->Superclass::GetNameOfClass(), #SuperclassName)) \
102 std::cout << "Superclass name is correct" << std::endl; \
106 std::cerr << "Superclass name provided does not match object's Superclass::NameOfClass" << std::endl; \
107 return EXIT_FAILURE; \
109 ITK_MACROEND_NOOP_STATEMENT
113#define ITK_TRY_EXPECT_EXCEPTION(command) \
116 std::cout << "Trying " << #command << std::endl; \
118 std::cerr << "Failed to catch expected exception" << std::endl; \
119 std::cerr << " In " __FILE__ ", line " << __LINE__ << std::endl; \
120 return EXIT_FAILURE; \
122 catch (const itk::ExceptionObject & excp) \
124 std::cout << "Caught expected exception" << std::endl; \
125 std::cout << excp << std::endl; \
127 ITK_MACROEND_NOOP_STATEMENT
130#define ITK_TRY_EXPECT_NO_EXCEPTION(command) \
133 std::cout << "Trying " << #command << std::endl; \
136 catch (const itk::ExceptionObject & excp) \
138 std::cerr << excp << std::endl; \
139 std::cerr << " In " __FILE__ ", line " << __LINE__ << std::endl; \
140 return EXIT_FAILURE; \
142 ITK_MACROEND_NOOP_STATEMENT
144#define ITK_TEST_EXPECT_TRUE_STATUS_VALUE(command, statusVal) \
146 ITK_GCC_PRAGMA_PUSH \
147 ITK_GCC_SUPPRESS_Wfloat_equal \
148 bool _ITK_TEST_EXPECT_TRUE_command(command); \
150 if (!(_ITK_TEST_EXPECT_TRUE_command)) \
152 std::cerr << "Error in " << #command << std::endl; \
153 std::cerr << " In " __FILE__ ", line " << __LINE__ << std::endl; \
154 std::cerr << "Expected true" << std::endl; \
155 std::cerr << " but got " << _ITK_TEST_EXPECT_TRUE_command << std::endl; \
156 statusVal = EXIT_FAILURE; \
159 ITK_MACROEND_NOOP_STATEMENT
161#define ITK_TEST_EXPECT_TRUE(command) \
163 ITK_GCC_PRAGMA_PUSH \
164 ITK_GCC_SUPPRESS_Wfloat_equal \
165 bool _ITK_TEST_EXPECT_TRUE_command(command); \
167 if (!(_ITK_TEST_EXPECT_TRUE_command)) \
169 std::cerr << "Error in " << #command << std::endl; \
170 std::cerr << " In " __FILE__ ", line " << __LINE__ << std::endl; \
171 std::cerr << "Expected true" << std::endl; \
172 std::cerr << " but got " << _ITK_TEST_EXPECT_TRUE_command << std::endl; \
173 return EXIT_FAILURE; \
176 ITK_MACROEND_NOOP_STATEMENT
179#define ITK_TEST_EXPECT_EQUAL_STATUS_VALUE(lh, rh, statusVal) \
181 ITK_GCC_PRAGMA_PUSH \
182 ITK_GCC_SUPPRESS_Wfloat_equal \
183 bool _ITK_TEST_EXPECT_EQUAL_result((lh) == (rh)); \
185 if (!(_ITK_TEST_EXPECT_EQUAL_result)) \
187 std::cerr << "Error in " << #lh << " == " << #rh << std::endl; \
188 std::cerr << "\tIn " __FILE__ ", line " << __LINE__ << std::endl; \
189 std::cerr << "\tlh: " << (lh) << std::endl; \
190 std::cerr << "\trh: " << (rh) << std::endl; \
191 std::cerr << "Expression is not equal" << std::endl; \
192 statusVal = EXIT_FAILURE; \
195 ITK_MACROEND_NOOP_STATEMENT
197#define ITK_TEST_EXPECT_EQUAL(lh, rh) \
199 ITK_GCC_PRAGMA_PUSH \
200 ITK_GCC_SUPPRESS_Wfloat_equal \
201 bool _ITK_TEST_EXPECT_EQUAL_result((lh) == (rh)); \
203 if (!(_ITK_TEST_EXPECT_EQUAL_result)) \
205 std::cerr << "Error in " << #lh << " == " << #rh << std::endl; \
206 std::cerr << "\tIn " __FILE__ ", line " << __LINE__ << std::endl; \
207 std::cerr << "\tlh: " << (lh) << std::endl; \
208 std::cerr << "\trh: " << (rh) << std::endl; \
209 std::cerr << "Expression is not equal" << std::endl; \
210 return EXIT_FAILURE; \
213 ITK_MACROEND_NOOP_STATEMENT
216#define ITK_TEST_SET_GET(variable, command) \
217 if (variable != command) \
219 std::cerr << "Error in " << #command << std::endl; \
220 std::cerr << " In " __FILE__ ", line " << __LINE__ << std::endl; \
221 std::cerr << "Expected " << variable.GetPointer() << std::endl; \
222 std::cerr << "but got " << command << std::endl; \
223 return EXIT_FAILURE; \
225 ITK_MACROEND_NOOP_STATEMENT
228#define ITK_TEST_SET_GET_VALUE(variable, command) \
229 ITK_GCC_PRAGMA_PUSH \
230 ITK_GCC_SUPPRESS_Wfloat_equal \
231 if (variable != command) \
233 std::cerr << "Error in " << #command << std::endl; \
234 std::cerr << " In " __FILE__ ", line " << __LINE__ << std::endl; \
235 std::cerr << "Expected " << variable << std::endl; \
236 std::cerr << "but got " << command << std::endl; \
237 return EXIT_FAILURE; \
240 ITK_MACROEND_NOOP_STATEMENT
242#define ITK_TEST_SET_GET_NULL_VALUE(command) \
243 if (nullptr != command) \
245 std::cerr << "Error in " << #command << std::endl; \
246 std::cerr << " In " __FILE__ ", line " << __LINE__ << std::endl; \
247 std::cerr << "Expected " \
248 << "nullptr" << std::endl; \
249 std::cerr << "but got " << command << std::endl; \
250 return EXIT_FAILURE; \
252 ITK_MACROEND_NOOP_STATEMENT
254#define ITK_TEST_SET_GET_BOOLEAN(object, variable, value) \
255 object->Set##variable(false); \
256 object->Set##variable(true); \
257 if (object->Get##variable() != 1) \
259 std::cerr << "Error in Set/Get" #variable << ", Get" #variable << " is " << object->Get##variable() \
260 << " instead of 1" << std::endl; \
261 return EXIT_FAILURE; \
263 object->Set##variable(false); \
264 if (object->Get##variable() != 0) \
266 std::cerr << "Error in Set/Get" #variable << ", Get" #variable << " is " << object->Get##variable() \
267 << " instead of 0" << std::endl; \
268 return EXIT_FAILURE; \
270 object->variable##On(); \
271 if (object->Get##variable() != 1) \
273 std::cerr << "Error in On/Get" #variable << ", Get" #variable << " is " << object->Get##variable() \
274 << " instead of 1" << std::endl; \
275 return EXIT_FAILURE; \
277 object->variable##Off(); \
278 if (object->Get##variable() != 0) \
280 std::cerr << "Error in Off/Get" #variable << ", Get" #variable << " is " << object->Get##variable() \
281 << " instead of 0" << std::endl; \
282 return EXIT_FAILURE; \
284 object->Set##variable(value)
289#define itkNameOfTestExecutableMacro(argv) \
290 [argv](const std::string & functionName) { \
291 return ((argv == nullptr) || (argv[0] == nullptr) || (argv[0][0] == '\0')) ? ("<" + functionName + " executable>") \
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....