CppUnit project page FAQ

Public Types | Public Member Functions | Private Member Functions
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.
- Public Member Functions inherited from TestCaseDecorator
 TestCaseDecorator (TestCase *test)
 ~TestCaseDecorator ()
std::string getName () const
 Returns the name of the test case.
void setUp ()
 Set up context before running a test.
void tearDown ()
 Clean up after the test run.
- Public Member Functions inherited from TestCase
 TestCase (const std::string &name)
 Constructs a test case.
 TestCase ()
 Constructs a test case for a suite.
 ~TestCase ()
 Destructs a test case.
virtual void run (TestResult *result)
 Run the test and catch any exceptions that are triggered by it.
- Public Member Functions inherited from TestLeaf
int countTestCases () const
int getChildTestCount () const
TestdoGetChildTestAt (int index) const
- Public Member Functions inherited from Test
virtual ~Test ()
virtual TestgetChildTestAt (int index) const
 Returns the child test of the specified index.
virtual bool findTestPath (const std::string &testName, TestPath &testPath) const
 Finds the test with the specified name and its parents test.
virtual bool findTestPath (const Test *test, TestPath &testPath) const
 Finds the specified test and its parents test.
virtual TestfindTest (const std::string &testName) const
 Finds the test with the specified name in the hierarchy.
virtual TestPath resolveTestPath (const std::string &testPath) const
 Resolved the specified test path with this test acting as 'root'.
- Public Member Functions inherited from TestFixture
virtual ~TestFixture ()

Private Member Functions

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

Additional Inherited Members

- Protected Attributes inherited from TestCaseDecorator
TestCasem_test

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:
{
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:
testTestCase to decorate. Assumes ownership of the test.

Member Function Documentation

template<class ExpectedException >
virtual void ExceptionTestCaseDecorator< ExpectedException >::checkException ( ExpectedExceptionType )
inlineprivatevirtual

Called when the exception is caught.

Should be overriden to check the exception.

template<class ExpectedException >
void ExceptionTestCaseDecorator< ExpectedException >::runTest ( )
inlinevirtual

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:

Send comments to:
CppUnit Developers