ITK  4.2.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 << "Expression is not equal" << std::endl; \
75  return EXIT_FAILURE; \
76  } \
77  }
78 
79 
80 #define TEST_SET_GET( variable, command ) \
81  if( variable.GetPointer() != command ) \
82  { \
83  std::cerr << "Error in " << #command << std::endl; \
84  std::cerr << "Expected " << variable.GetPointer() << std::endl; \
85  std::cerr << "but got " << command << std::endl; \
86  return EXIT_FAILURE; \
87  }
88 
89 
90 #define TEST_SET_GET_VALUE( variable, command ) \
91  if( variable != command ) \
92  { \
93  std::cerr << "Error in " << #command << std::endl; \
94  std::cerr << "Expected " << variable << std::endl; \
95  std::cerr << "but got " << command << std::endl; \
96  return EXIT_FAILURE; \
97  }
98 
99 #define TEST_SET_GET_NULL_VALUE( command ) \
100  if( NULL != command ) \
101  { \
102  std::cerr << "Error in " << #command << std::endl; \
103  std::cerr << "Expected " << "NULL" << std::endl; \
104  std::cerr << "but got " << command << std::endl; \
105  return EXIT_FAILURE; \
106  }
107 
108 
109 #endif
110