CppUnit project page FAQ CppUnit home page

Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

ExceptionTestCaseDecorator.h

Go to the documentation of this file.
00001 #ifndef CPPUNIT_EXTENSIONS_EXCEPTIONTESTCASEDECORATOR_H
00002 #define CPPUNIT_EXTENSIONS_EXCEPTIONTESTCASEDECORATOR_H
00003 
00004 #include <cppunit/Portability.h>
00005 #include <cppunit/Exception.h>
00006 #include <cppunit/extensions/TestCaseDecorator.h>
00007 
00008 CPPUNIT_NS_BEGIN
00009 
00010 
00043 template<class ExpectedException>
00044 class ExceptionTestCaseDecorator : public TestCaseDecorator
00045 {
00046 public:
00047   typedef ExpectedException ExpectedExceptionType;
00048 
00052   ExceptionTestCaseDecorator( TestCase *test )
00053       : TestCaseDecorator( test )
00054   {
00055   }
00056 
00065   void runTest()
00066   {
00067     try
00068     {
00069       TestCaseDecorator::runTest();
00070     }
00071     catch ( ExpectedExceptionType &e )
00072     {
00073       checkException( e );
00074       return;
00075     }
00076 
00077     // Moved outside the try{} statement to handle the case where the
00078     // expected exception type is Exception (expecting assertion failure).
00079 #if CPPUNIT_USE_TYPEINFO_NAME
00080       throw Exception( Message(
00081                          "expected exception not thrown",
00082                          "Expected exception type: " + 
00083                            TypeInfoHelper::getClassName( 
00084                                typeid( ExpectedExceptionType ) ) ) );
00085 #else
00086       throw Exception( Message("expected exception not thrown") );
00087 #endif
00088   }
00089 
00090 private:
00095   virtual void checkException( ExpectedExceptionType &e )
00096   {
00097   }
00098 };
00099 
00100 
00101 CPPUNIT_NS_END
00102 
00103 #endif // CPPUNIT_EXTENSIONS_EXCEPTIONTESTCASEDECORATOR_H
00104 

SourceForge Logo hosts this site. Send comments to:
CppUnit Developers