ITK  4.9.0
Insight Segmentation and Registration Toolkit
itkTestingMacros.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 
19 #ifndef itkTestingMacros_h
20 #define itkTestingMacros_h
21 
22 #include "itkMacro.h"
23 
24 // object's Class must be specified to build on sun studio
25 #define EXERCISE_BASIC_OBJECT_METHODS( object, Class ) \
26  object->Print( std::cout ); \
27  std::cout << "Name of Class = " << object->GetNameOfClass() << std::endl; \
28  std::cout << "Name of Superclass = " << object->Class::Superclass::GetNameOfClass() << std::endl;
29 
30 
31 #define TRY_EXPECT_EXCEPTION( command ) \
32  try \
33  { \
34  std::cout << "Trying " << #command << std::endl; \
35  command; \
36  std::cerr << "Failed to catch expected exception" << std::endl; \
37  std::cerr << " In " __FILE__ ", line " << __LINE__ << std::endl;\
38  return EXIT_FAILURE; \
39  } \
40  catch( itk::ExceptionObject & excp ) \
41  { \
42  std::cout << "Caught expected exception" << std::endl; \
43  std::cout << excp << std::endl; \
44  }
45 
46 
47 #define TRY_EXPECT_NO_EXCEPTION( command ) \
48  try \
49  { \
50  std::cout << "Trying " << #command << std::endl; \
51  command; \
52  } \
53  catch( itk::ExceptionObject & excp ) \
54  { \
55  std::cerr << excp << std::endl; \
56  std::cerr << " In " __FILE__ ", line " << __LINE__ << std::endl; \
57  return EXIT_FAILURE; \
58  }
59 
60 #define TEST_EXPECT_TRUE_STATUS_VALUE( command, statusVal ) \
61  { \
62 CLANG_PRAGMA_PUSH \
63 CLANG_SUPPRESS_Wfloat_equal \
64  bool _TEST_EXPECT_TRUE_command(command); \
65 CLANG_PRAGMA_POP \
66  if( !(_TEST_EXPECT_TRUE_command) ) \
67  { \
68  std::cerr << "Error in " << #command << std::endl; \
69  std::cerr << " In " __FILE__ ", line " << __LINE__ << std::endl; \
70  std::cerr << "Expected true" << std::endl; \
71  std::cerr << " but got " << _TEST_EXPECT_TRUE_command << std::endl; \
72  statusVal = EXIT_FAILURE; \
73  } \
74  }
75 
76 #define TEST_EXPECT_TRUE( command ) \
77  { \
78 CLANG_PRAGMA_PUSH \
79 CLANG_SUPPRESS_Wfloat_equal \
80  bool _TEST_EXPECT_TRUE_command(command); \
81 CLANG_PRAGMA_POP \
82  if( !(_TEST_EXPECT_TRUE_command) ) \
83  { \
84  std::cerr << "Error in " << #command << std::endl; \
85  std::cerr << " In " __FILE__ ", line " << __LINE__ << std::endl; \
86  std::cerr << "Expected true" << std::endl; \
87  std::cerr << " but got " << _TEST_EXPECT_TRUE_command << std::endl; \
88  return EXIT_FAILURE; \
89  } \
90  }
91 
92 
93 #define TEST_EXPECT_EQUAL_STATUS_VALUE( lh, rh, statusVal ) \
94  { \
95 CLANG_PRAGMA_PUSH \
96 CLANG_SUPPRESS_Wfloat_equal \
97  bool _TEST_EXPECT_EQUAL_result((lh) == (rh)); \
98 CLANG_PRAGMA_POP \
99  if( !(_TEST_EXPECT_EQUAL_result) ) \
100  { \
101  std::cerr << "Error in " << #lh << " == " << #rh << std::endl; \
102  std::cerr << "\tIn " __FILE__ ", line " << __LINE__ << std::endl; \
103  std::cerr << "\tlh: " << (lh) << std::endl; \
104  std::cerr << "\trh: " << (rh) << std::endl; \
105  std::cerr << "Expression is not equal" << std::endl; \
106  statusVal = EXIT_FAILURE; \
107  } \
108  }
109 
110 #define TEST_EXPECT_EQUAL( lh, rh ) \
111  { \
112 CLANG_PRAGMA_PUSH \
113 CLANG_SUPPRESS_Wfloat_equal \
114  bool _TEST_EXPECT_EQUAL_result((lh) == (rh)); \
115 CLANG_PRAGMA_POP \
116  if( !(_TEST_EXPECT_EQUAL_result) ) \
117  { \
118  std::cerr << "Error in " << #lh << " == " << #rh << std::endl; \
119  std::cerr << "\tIn " __FILE__ ", line " << __LINE__ << std::endl; \
120  std::cerr << "\tlh: " << (lh) << std::endl; \
121  std::cerr << "\trh: " << (rh) << std::endl; \
122  std::cerr << "Expression is not equal" << std::endl; \
123  return EXIT_FAILURE; \
124  } \
125  }
126 
127 
128 #define TEST_SET_GET( variable, command ) \
129  if( variable.GetPointer() != command ) \
130  { \
131  std::cerr << "Error in " << #command << std::endl; \
132  std::cerr << " In " __FILE__ ", line " << __LINE__ << std::endl; \
133  std::cerr << "Expected " << variable.GetPointer() << std::endl; \
134  std::cerr << "but got " << command << std::endl; \
135  return EXIT_FAILURE; \
136  }
137 
138 
139 #define TEST_SET_GET_VALUE( variable, command ) \
140 CLANG_PRAGMA_PUSH \
141 CLANG_SUPPRESS_Wfloat_equal \
142  if( variable != command ) \
143 CLANG_PRAGMA_POP \
144  { \
145  std::cerr << "Error in " << #command << std::endl; \
146  std::cerr << " In " __FILE__ ", line " << __LINE__ << std::endl; \
147  std::cerr << "Expected " << variable << std::endl; \
148  std::cerr << "but got " << command << std::endl; \
149  return EXIT_FAILURE; \
150  }
151 
152 #define TEST_SET_GET_NULL_VALUE( command ) \
153  if( ITK_NULLPTR != command ) \
154  { \
155  std::cerr << "Error in " << #command << std::endl; \
156  std::cerr << " In " __FILE__ ", line " << __LINE__ << std::endl; \
157  std::cerr << "Expected " << "ITK_NULLPTR" << std::endl; \
158  std::cerr << "but got " << command << std::endl; \
159  return EXIT_FAILURE; \
160  }
161 
162 
163 #endif