ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkTestingMacros.h
Go to the documentation of this file.
00001 /*=========================================================================
00002  *
00003  *  Copyright Insight Software Consortium
00004  *
00005  *  Licensed under the Apache License, Version 2.0 (the "License");
00006  *  you may not use this file except in compliance with the License.
00007  *  You may obtain a copy of the License at
00008  *
00009  *         http://www.apache.org/licenses/LICENSE-2.0.txt
00010  *
00011  *  Unless required by applicable law or agreed to in writing, software
00012  *  distributed under the License is distributed on an "AS IS" BASIS,
00013  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  *  See the License for the specific language governing permissions and
00015  *  limitations under the License.
00016  *
00017  *=========================================================================*/
00018 #ifndef __itkTestingMacros_h
00019 #define __itkTestingMacros_h
00020 
00021 
00022 // object's Class must be specified to build on sun studio
00023 #define EXERCISE_BASIC_OBJECT_METHODS( object, Class ) \
00024     object->Print( std::cout );  \
00025     std::cout << "Name of Class = " << object->GetNameOfClass() << std::endl; \
00026     std::cout << "Name of Superclass = " << object->Class::Superclass::GetNameOfClass() << std::endl;
00027 
00028 
00029 #define TRY_EXPECT_EXCEPTION( command ) \
00030   try \
00031     {  \
00032     std::cout << "Trying " << #command << std::endl; \
00033     command;  \
00034     std::cerr << "Failed to catch expected exception" << std::endl;  \
00035     return EXIT_FAILURE;  \
00036     }  \
00037   catch( itk::ExceptionObject & excp )  \
00038     {  \
00039     std::cout << "Caught expected exception" << std::endl;  \
00040     std::cout << excp << std::endl; \
00041     }
00042 
00043 
00044 #define TRY_EXPECT_NO_EXCEPTION( command ) \
00045   try \
00046     {  \
00047     std::cout << "Trying " << #command << std::endl; \
00048     command;  \
00049     }  \
00050   catch( itk::ExceptionObject & excp )  \
00051     {  \
00052     std::cerr << excp << std::endl; \
00053     return EXIT_FAILURE;  \
00054     }
00055 
00056 #define TEST_EXPECT_TRUE( command )                                     \
00057   {                                                                     \
00058   bool _TEST_EXPECT_TRUE_command(command);                              \
00059   if( !(_TEST_EXPECT_TRUE_command) )                                    \
00060     {                                                                   \
00061     std::cerr << "Error in " << #command << std::endl;                  \
00062     std::cerr << "Expected true" << std::endl;                          \
00063     std::cerr << "but got  " <<  _TEST_EXPECT_TRUE_command << std::endl; \
00064     return EXIT_FAILURE;                                                \
00065     }                                                                   \
00066   }
00067 
00068 #define TEST_EXPECT_EQUAL( lh, rh )                                     \
00069   {                                                                     \
00070     bool _TEST_EXPECT_EQUAL_result((lh) == (rh));                       \
00071     if( !(_TEST_EXPECT_EQUAL_result) )                                  \
00072     {                                                                   \
00073     std::cerr << "Error in " << #lh << " == " << #rh << std::endl;      \
00074     std::cerr << "Expression is not equal" << std::endl;               \
00075     return EXIT_FAILURE;                                                \
00076     }                                                                   \
00077   }
00078 
00079 
00080 #define TEST_SET_GET( variable, command ) \
00081   if( variable.GetPointer() != command )   \
00082     {   \
00083     std::cerr << "Error in " << #command << std::endl; \
00084     std::cerr << "Expected " << variable.GetPointer() << std::endl; \
00085     std::cerr << "but got  " << command << std::endl; \
00086     return EXIT_FAILURE; \
00087     }
00088 
00089 
00090 #define TEST_SET_GET_VALUE( variable, command ) \
00091   if( variable != command )   \
00092     {   \
00093     std::cerr << "Error in " << #command << std::endl; \
00094     std::cerr << "Expected " << variable << std::endl;   \
00095     std::cerr << "but got  " << command << std::endl; \
00096     return EXIT_FAILURE; \
00097     }
00098 
00099 #define TEST_SET_GET_NULL_VALUE( command ) \
00100   if( NULL != command )   \
00101     {   \
00102     std::cerr << "Error in " << #command << std::endl; \
00103     std::cerr << "Expected " << "NULL" << std::endl;   \
00104     std::cerr << "but got  " << command << std::endl; \
00105     return EXIT_FAILURE; \
00106     }
00107 
00108 
00109 #endif
00110