CppUnit project page FAQ CppUnit home page

ExceptionTestCaseDecorator< ExpectedException > Class Template Reference

Expected exception test case decorator. More...

#include <ExceptionTestCaseDecorator.h>

Inheritance diagram for ExceptionTestCaseDecorator< ExpectedException >:

Inheritance graph
[legend]
Collaboration diagram for ExceptionTestCaseDecorator< ExpectedException >:

Collaboration graph
[legend]

List of all members.

Public Types

typedef ExpectedException ExpectedExceptionType

Public Member Functions

 ExceptionTestCaseDecorator (TestCase *test)
 Decorates the specified test.
void runTest ()
 Checks that the expected exception is thrown by the decorated test. is thrown.

Private Member Functions

virtual void checkException (ExpectedExceptionType &e)
 Called when the exception is caught.


Detailed Description

template<class ExpectedException>
class ExceptionTestCaseDecorator< ExpectedException >

Expected exception test case decorator.

A decorator used to assert that a specific test case should throw an exception of a given type.

You should use this class only if you need to check the exception object state (that a specific cause is set for example). If you don't need to do that, you might consider using CPPUNIT_TEST_EXCEPTION() instead.

Intended use is to subclass and override checkException(). Example:

 class NetworkErrorTestCaseDecorator : 
           public ExceptionTestCaseDecorator<NetworkError>
 {
 public:
   NetworkErrorTestCaseDecorator( NetworkError::Cause expectedCause )
       : m_expectedCause( expectedCause )
   {
   }
 private:
   void checkException( ExpectedExceptionType &e )
   {
     CPPUNIT_ASSERT_EQUAL( m_expectedCause, e.getCause() );
   }

   NetworkError::Cause m_expectedCause;
 };

Member Typedef Documentation

template<class ExpectedException >
typedef ExpectedException ExceptionTestCaseDecorator< ExpectedException >::ExpectedExceptionType


Constructor & Destructor Documentation

template<class ExpectedException >
ExceptionTestCaseDecorator< ExpectedException >::ExceptionTestCaseDecorator ( TestCase test  )  [inline]

Decorates the specified test.

Parameters:
test TestCase to decorate. Assumes ownership of the test.


Member Function Documentation

template<class ExpectedException >
virtual void ExceptionTestCaseDecorator< ExpectedException >::checkException ( ExpectedExceptionType e  )  [inline, private, virtual]

Called when the exception is caught.

Should be overriden to check the exception.

template<class ExpectedException >
void ExceptionTestCaseDecorator< ExpectedException >::runTest (  )  [inline, virtual]

Checks that the expected exception is thrown by the decorated test. is thrown.

Calls the decorated test runTest() and checks that an exception of type ExpectedException is thrown. Call checkException() passing the exception that was caught so that some assertions can be made if needed.

Reimplemented from TestCaseDecorator.


The documentation for this class was generated from the following file:

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