unit.h

Go to the documentation of this file.
00001 
00014 #ifndef UNIT_H
00015 #define UNIT_H
00016 
00017 #ifndef CTL_UNIT
00018 #error This is only for unit tests!
00019 #endif
00020 
00021 #include <stdlib.h>
00022 #include <stdio.h>
00023 #include "ctl/ctldef.h"
00024 #define PROFILE
00025 #include "ctl/profile.h"
00026 
00027 extern int error_count;
00028 
00029 
00030 int arg_find( const char* sz, size_t len );
00031 int arg_count( void );
00032 const char* arg_get( int index );
00033 
00040 #define Test_Error( test )\
00041 { \
00042     if ( !(test) ) \
00043     { \
00044         error_count++; \
00045         puts( ppFileLine("Failed: " ppTokStr(test) "\n" ) ); \
00046         ppDebRel(throwassert(#test);,fgetc(stdin);)\
00047     }\
00048 }
00049 
00054 #define UNIT_TEST(Test_Name)\
00055     {\
00056         int found = arg_find( "-x" #Test_Name, 0 );\
00057         if( 0 == found )\
00058         {\
00059             ctl_profile_average_begin(ppConcat(pf,Test_Name),#Test_Name);\
00060             Test_Name();\
00061             ctl_profile_average_end(ppConcat(pf,Test_Name));\
00062         }\
00063         else\
00064         {\
00065             /* Tell us we skipped a test, but don't tell us every cycle */\
00066             static bool bSaidSo = false;\
00067             if( !bSaidSo )\
00068             {\
00069                 bSaidSo = true;\
00070                 puts( "Skipped: " #Test_Name );\
00071             }\
00072         }\
00073     }
00074 
00082 #define Test_Named( name, test )        { if ( !(test) ) { error_count++; puts( ppFileLine("Failed: " name ppTokStr(test) "\n" ) ); throwassert(#test); } }
00083 
00084 #endif /* UNIT_H */
00085 

Generated on Fri Jan 2 15:28:35 2009 for Squat by  doxygen 1.5.6