CppUnit project page FAQ

ExceptionTestCaseDecorator.h
Go to the documentation of this file.
1 #ifndef CPPUNIT_EXTENSIONS_EXCEPTIONTESTCASEDECORATOR_H
2 #define CPPUNIT_EXTENSIONS_EXCEPTIONTESTCASEDECORATOR_H
3 
4 #include <cppunit/Portability.h>
5 #include <cppunit/Exception.h>
7 
9 
10 
43 template<class ExpectedException>
45 {
46 public:
47  typedef ExpectedException ExpectedExceptionType;
48 
53  : TestCaseDecorator( test )
54  {
55  }
56 
65  void runTest()
66  {
67  try
68  {
70  }
71  catch ( ExpectedExceptionType &e )
72  {
73  checkException( e );
74  return;
75  }
76 
77  // Moved outside the try{} statement to handle the case where the
78  // expected exception type is Exception (expecting assertion failure).
79 #if CPPUNIT_USE_TYPEINFO_NAME
80  throw Exception( Message(
81  "expected exception not thrown",
82  "Expected exception type: " +
83  TypeInfoHelper::getClassName(
84  typeid( ExpectedExceptionType ) ) ) );
85 #else
86  throw Exception( Message("expected exception not thrown") );
87 #endif
88  }
89 
90 private:
96  {
97  }
98 };
99 
100 
102 
103 #endif // CPPUNIT_EXTENSIONS_EXCEPTIONTESTCASEDECORATOR_H
104 

Send comments to:
CppUnit Developers