outputctl.h

Go to the documentation of this file.
00001 // vim:expandtab:autoindent:tabstop=4:shiftwidth=4:filetype=c:
00002 /*
00003  * Copyright (C) 2005 Dell Inc.
00004  *  by Michael Brown <Michael_E_Brown@dell.com>
00005  * Licensed under the Open Software License version 2.1 
00006  * 
00007  * Alternatively, you can redistribute it and/or modify 
00008  * it under the terms of the GNU General Public License as published 
00009  * by the Free Software Foundation; either version 2 of the License, 
00010  * or (at your option) any later version.
00011 
00012  * This program is distributed in the hope that it will be useful, but 
00013  * WITHOUT ANY WARRANTY; without even the implied warranty of 
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
00015  * See the GNU General Public License for more details.
00016  */
00017 
00018 
00019 #ifndef _OUTPUTCTL_H
00020 #define _OUTPUTCTL_H
00021 
00022 #include "smbios/compat.h"
00023 
00024 #include <exception>
00025 #include <typeinfo>     // for typeid()
00026 
00027 // A collection of macros to use in the unit tests.
00028 // They print things out in a standard format, or shorten unit tests.
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 // standard stuff
00047 
00048 // Standard test start/end header
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 // extra macros that make CPPUNIT tests shorter.
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  /* ! defined _OUTPUTCTL_H */

Generated on Tue Jan 17 02:59:08 2006 for SMBIOS Library by  doxygen 1.4.6