ITK  4.3.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 #ifndef __itkTestingMacros_h
19 #define __itkTestingMacros_h
20 
21 
22 // object's Class must be specified to build on sun studio
23 #define EXERCISE_BASIC_OBJECT_METHODS( object, Class ) \
24  object->Print( std::cout ); \
25  std::cout << "Name of Class = " << object->GetNameOfClass() << std::endl; \
26  std::cout << "Name of Superclass = " << object->Class::Superclass::GetNameOfClass() << std::endl;
27 
28 
29 #define TRY_EXPECT_EXCEPTION( command ) \
30  try \
31  { \
32  std::cout << "Trying " << #command << std::endl; \
33  command; \
34  std::cerr << "Failed to catch expected exception" << std::endl; \
35  return EXIT_FAILURE; \
36  } \
37  catch( itk::ExceptionObject & excp ) \
38  { \
39  std::cout << "Caught expected exception" << std::endl; \
40  std::cout << excp << std::endl; \
41  }
42 
43 
44 #define TRY_EXPECT_NO_EXCEPTION( command ) \
45  try \
46  { \
47  std::cout << "Trying " << #command << std::endl; \
48  command; \
49  } \
50  catch( itk::ExceptionObject & excp ) \
51  { \
52  std::cerr << excp << std::endl; \
53  return EXIT_FAILURE; \
54  }
55 
56 #define TEST_EXPECT_TRUE( command ) \
57  { \
58  bool _TEST_EXPECT_TRUE_command(command); \
59  if( !(_TEST_EXPECT_TRUE_command) ) \
60  { \
61  std::cerr << "Error in " << #command << std::endl; \
62  std::cerr << "Expected true" << std::endl; \
63  std::cerr << "but got " << _TEST_EXPECT_TRUE_command << std::endl; \
64  return EXIT_FAILURE; \
65  } \
66  }
67 
68 #define TEST_EXPECT_EQUAL( lh, rh ) \
69  { \
70  bool _TEST_EXPECT_EQUAL_result((lh) == (rh)); \
71  if( !(_TEST_EXPECT_EQUAL_result) ) \
72  { \
73  std::cerr << "Error in " << #lh << " == " << #rh << std::endl; \
74  std::cerr << "\tlh: " << (lh) << std::endl; \
75  std::cerr << "\trh: " << (rh) << std::endl; \
76  std::cerr << "Expression is not equal" << std::endl; \
77  return EXIT_FAILURE; \
78  } \
79  }
80 
81 
82 #define TEST_SET_GET( variable, command ) \
83  if( variable.GetPointer() != command ) \
84  { \
85  std::cerr << "Error in " << #command << std::endl; \
86  std::cerr << "Expected " << variable.GetPointer() << std::endl; \
87  std::cerr << "but got " << command << std::endl; \
88  return EXIT_FAILURE; \
89  }
90 
91 
92 #define TEST_SET_GET_VALUE( variable, command ) \
93  if( variable != command ) \
94  { \
95  std::cerr << "Error in " << #command << std::endl; \
96  std::cerr << "Expected " << variable << std::endl; \
97  std::cerr << "but got " << command << std::endl; \
98  return EXIT_FAILURE; \
99  }
100 
101 #define TEST_SET_GET_NULL_VALUE( command ) \
102  if( NULL != command ) \
103  { \
104  std::cerr << "Error in " << #command << std::endl; \
105  std::cerr << "Expected " << "NULL" << std::endl; \
106  std::cerr << "but got " << command << std::endl; \
107  return EXIT_FAILURE; \
108  }
109 
110 
111 #endif
112