00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef _OUTPUTCTL_H
00020 #define _OUTPUTCTL_H
00021
00022 #include "smbios/compat.h"
00023
00024 #include <exception>
00025 #include <typeinfo>
00026
00027
00028
00029
00030 class skip_test : public std::exception
00031 {}
00032 ;
00033
00034
00035 #ifdef LIBSMBIOS_HAS_PRETTY_FUNCTION
00036 #define WHEREAMI "\t%s... ", __PRETTY_FUNCTION__
00037 #else
00038 #define WHEREAMI "%s (line %d)... ", typeid(*this).name(), __LINE__
00039 #endif
00040
00041 #define startTest(arg1, arg2) do{ printf(arg1, arg2); printf(WHEREAMI) ;}while(0)
00042 #define passTest() do {printf( "[ ok ]\n" ); } while(0)
00043 #define failTest() do {printf( "[FAIL]\n" ); } while(0)
00044 #define skipTest() do {printf( "[SKIP]\n" ); } while(0)
00045
00046
00047
00048
00049 #ifdef LIBSMBIOS_HAS_PRETTY_FUNCTION
00050 #define STD_TEST_START(arg1, arg2) startTest(arg1, arg2); bool skip=false; cout << flush; try { checkSkipTest(__FUNCTION__)
00051 #else
00052 #define STD_TEST_START(arg1, arg2) startTest(arg1, arg2); bool skip=false; cout << flush; try {
00053 #endif
00054
00055 #define STD_TEST_END() \
00056 } catch (const skip_test &) { \
00057 skip = true; \
00058 } catch ( const smbios::IException &e ) { \
00059 failTest(); \
00060 CPPUNIT_FAIL( e.what() ); \
00061 } catch ( const std::exception &e ) { \
00062 failTest(); \
00063 CPPUNIT_FAIL( e.what() ); \
00064 } catch (...) { \
00065 failTest(); \
00066 throw; \
00067 } \
00068 if( skip ) \
00069 skipTest(); \
00070 else \
00071 passTest();
00072
00073
00074 #define ASSERT_THROWS( expr, exc ) \
00075 do { \
00076 bool caught = false; \
00077 try \
00078 { \
00079 expr; \
00080 } \
00081 catch( const exc & ) \
00082 { \
00083 caught = true; \
00084 } \
00085 catch( const std::exception &e ) \
00086 { \
00087 ostringstream ost; \
00088 ost << "Executed: " #expr "\nCaught wrong exception. Expected: " #exc; \
00089 ost << "\nLine: " << __LINE__; \
00090 ost << "\nFile: " << __FILE__; \
00091 ost << "\nException Caught: " << typeid(e).name(); \
00092 CPPUNIT_FAIL (ost.str().c_str()); \
00093 } \
00094 catch( ... ) \
00095 { \
00096 ostringstream ost; \
00097 ost << "Executed: " #expr "\nCaught wrong exception. Expected: " #exc; \
00098 ost << "\nLine: " << __LINE__; \
00099 ost << "\nFile: " << __FILE__; \
00100 CPPUNIT_FAIL (ost.str().c_str()); \
00101 } \
00102 if ( ! caught ) \
00103 CPPUNIT_FAIL ("Executed: " #expr "\nShould have thrown an exception, but did not. Expected: " #exc);\
00104 } while(0)
00105
00106
00107
00108 #endif