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 { public: virtual ~skip_test() throw() {}; }
00032 ;
00033
00034
00035 #ifdef LIBSMBIOS_HAS_PRETTY_FUNCTION
00036 #define WHEREAMI "\t" << __PRETTY_FUNCTION__ << "... "
00037 #else
00038 #define WHEREAMI typeid(*this).name() << " (line " << __LINE__ << ")... "
00039 #endif
00040
00041 #define GET_FLAGS() std::ios::fmtflags old_opts = cout.flags()
00042 #define RESTORE_FLAGS() cout.flags(old_opts)
00043
00044 #define startTest(arg) do{GET_FLAGS(); cout << arg << WHEREAMI; RESTORE_FLAGS();}while(0)
00045 #define passTest(arg) do{GET_FLAGS(); cout << "[ ok ]" << arg << endl; RESTORE_FLAGS();} while(0)
00046 #define failTest(arg) do{GET_FLAGS(); cout << "[FAIL]" << arg << endl; RESTORE_FLAGS();} while(0)
00047 #define skipTest(arg) do{GET_FLAGS(); cout << "[SKIP]" << arg << endl; RESTORE_FLAGS();} while(0)
00048
00049
00050
00051
00052 #ifdef LIBSMBIOS_HAS_PRETTY_FUNCTION
00053 #define STD_TEST_START_CHECKSKIP(arg) startTest(arg); bool skip=false; cout << flush; try { checkSkipTest(__FUNCTION__)
00054 #define STD_TEST_START(arg) startTest(arg); bool skip=false; cout << flush; try {
00055 #else
00056 #define STD_TEST_START_CHECKSKIP(arg) startTest(arg); bool skip=false; cout << flush; try {
00057 #define STD_TEST_START(arg) startTest(arg); bool skip=false; cout << flush; try {
00058 #endif
00059
00060 #define STD_TEST_END(arg) \
00061 } catch (const skip_test &) { \
00062 skip = true; \
00063 } catch ( const CppUnit::Exception &e ) { \
00064 failTest(arg); \
00065 throw; \
00066 } catch ( const std::exception &e ) { \
00067 failTest(arg); \
00068 CPPUNIT_FAIL( e.what() ); \
00069 } catch (...) { \
00070 failTest(arg); \
00071 throw; \
00072 } \
00073 if( skip ) \
00074 skipTest(arg); \
00075 else \
00076 passTest(arg)
00077
00078
00079 #define ASSERT_THROWS( expr, exc ) \
00080 do { \
00081 bool caught = false; \
00082 try \
00083 { \
00084 expr; \
00085 } \
00086 catch( const exc & ) \
00087 { \
00088 caught = true; \
00089 } \
00090 catch( const std::exception &e ) \
00091 { \
00092 ostringstream ost; \
00093 ost << "Executed: " #expr "\nCaught wrong exception. Expected: " #exc; \
00094 ost << "\nLine: " << __LINE__; \
00095 ost << "\nFile: " << __FILE__; \
00096 ost << "\nException Caught: " << typeid(e).name(); \
00097 CPPUNIT_FAIL (ost.str().c_str()); \
00098 } \
00099 catch( ... ) \
00100 { \
00101 ostringstream ost; \
00102 ost << "Executed: " #expr "\nCaught wrong exception. Expected: " #exc; \
00103 ost << "\nLine: " << __LINE__; \
00104 ost << "\nFile: " << __FILE__; \
00105 CPPUNIT_FAIL (ost.str().c_str()); \
00106 } \
00107 if ( ! caught ) \
00108 CPPUNIT_FAIL ("Executed: " #expr "\nShould have thrown an exception, but did not. Expected: " #exc);\
00109 } while(0)
00110
00111
00112
00113 #endif