-: 0:Source:ZIP/uUnit.h -: 0:Graph:mnyfmtts.gcno -: 0:Data:mnyfmtts.gcda -: 0:Runs:1 -: 0:Programs:1 -: 1:/* uUnit.h (C) 2011 adolfo@di-mare.com */ -: 2: -: 3:/** \file uUnit.h -: 4: \brief [u]Micro module for [Unit] program testing. -: 5: -: 6: \author Adolfo Di Mare -: 7: \date 2011 -: 8: \see http://www.di-mare.com/adolfo/p/BUnitXP.htm -: 9: -: 10:\code -: 11: #include "uUnit.h" // assertTrue() && assertFalse() -: 12: -: 13: // Example -: 14: int main( int argc , const char* argv[] ) { -: 15: std::cout << "TestCase [uUnit.h] yesYES" << std::endl; -: 16: assertTrue( 1==2 ); // ok? -: 17: assertFalse( 1==2 ); // ok! -: 18: return test_myImp(argc , argv); -: 19: } -: 20:\endcode -: 21:*/ -: 22: -: 23:#ifndef ADOLFO_UUNIT -: 24:#define ADOLFO_UUNIT -: 25: -: 26:/* #include "BUnit.h" // http://www.di-mare.com/adolfo/p/BUnit.htm */ -: 27:/* #include "BUnit.h" // http://www.di-mare.com/adolfo/p/BUnitXP.htm */ -: 28: -: 29:/** "C:/DIR/SubDir/file_name.ext" ==> "file_name.ext" */ -: 30:static /* "static" avoids "function already defined" linkage error */ #####: 31:const char* remove_dir_name( const char* str ) $$$$$: 31-block 0 -: 32:{ #####: 33: const char *p = str; /* p = str+strlen(str); */ #####: 34: while ( *p != 0 ) { ++p; } $$$$$: 34-block 0 $$$$$: 34-block 1 $$$$$: 34-block 2 #####: 35: while ( *p != '/' && *p != '\\' && *p != ':' ) { $$$$$: 35-block 0 $$$$$: 35-block 1 $$$$$: 35-block 2 $$$$$: 35-block 3 #####: 36: if ( p == str ) { return str; } $$$$$: 36-block 0 $$$$$: 36-block 1 #####: 37: --p; $$$$$: 37-block 0 -: 38: } #####: 39: return p+1; $$$$$: 39-block 0 -: 40:/* -: 41: Each object file will contain a local compiled copy of this function -: 42: because it is declared 'static'. This duplication is the price paid to -: 43: avoid using a uUnit.cpp file. -: 44:*/ -: 45:} -: 46: -: 47:#ifdef __cplusplus -: 48: #include /* std::cout */ -: 49: template inline /* inline avoids 'multiple definition' warning */ -: 50: void testThis( bool cond, const T* label, const T* fname, long lineno ); -: 51: template <> inline -: 52: void testThis( -: 53: bool cond, const char* label, const char* fname, long lineno -: 54: ) { -: 55: if (!cond) { -: 56: std::cout << "=\\_fail: " << label << " \n=/ ("; -: 57: std::cout << lineno << ") " << remove_dir_name(fname) << "\n"; -: 58: } -: 59: } -: 60:#else -: 61: #include /* printf() */ -: 62: static 202: 63: void testThis( 202: 63-block 0 -: 64: int cond, const char* label, const char* fname, long lineno -: 65: ) { 202: 66: if (!cond) { 202: 66-block 0 #####: 67: printf( "%s%s%s", "=\\_fail: " , label , " \n=/ (" ); $$$$$: 67-block 0 #####: 68: printf( "%ld%s%s%s", lineno , ") " , remove_dir_name(fname),"\n" ); -: 69: } 202: 70: } -: 71:#endif -: 72: -: 73: -: 74:#ifdef NDEBUG -: 75: #define assertTrue(x) ((void)0) -: 76: #define assertFalse(x) ((void)0) -: 77:#else /* debugging enabled */ -: 78: /** (cond ? () : cout << "cond" ) */ -: 79: #define assertTrue(cond) testThis(!!(cond), #cond, __FILE__,__LINE__ ) -: 80: /** (!(cond) ? () : cout << "!" << (cond)" ) */ -: 81: #define assertFalse(cond) testThis( !(cond),"!(" #cond ")", __FILE__,__LINE__ ) -: 82:#endif -: 83: -: 84:#endif -: 85: -: 86:/* EOF: uUnit.h */