CppUnit project page FAQ

Public Types | Public Member Functions | Private Member Functions | List of all members
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]

Public Types

typedef ExpectedException ExpectedExceptionType
 

Public Member Functions

 ExceptionTestCaseDecorator (TestCase *test)
 Decorates the specified test. More...
 
void runTest ()
 Checks that the expected exception is thrown by the decorated test. is thrown. More...
 
- Public Member Functions inherited from TestCaseDecorator
 TestCaseDecorator (TestCase *test)
 
 ~TestCaseDecorator ()
 
std::string getName () const
 Returns the test name. More...
 
void setUp ()
 Set up context before running a test. More...
 
void tearDown ()
 Clean up after the test run. More...
 
void runTest ()
 FIXME: this should probably be pure virtual. More...
 
- Public Member Functions inherited from TestCase
 TestCase (const std::string &name)
 Constructs a test case. More...
 
 TestCase ()
 Constructs a test case for a suite. More...
 
 ~TestCase ()
 Destructs a test case. More...
 
virtual void run (TestResult *result)
 Run the test and catch any exceptions that are triggered by it. More...
 
std::string getName () const
 Returns the name of the test case. More...
 
- 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. More...
 
virtual bool findTestPath (const std::string &testName, TestPath &testPath) const
 Finds the test with the specified name and its parents test. More...
 
virtual bool findTestPath (const Test *test, TestPath &testPath) const
 Finds the specified test and its parents test. More...
 
virtual TestfindTest (const std::string &testName) const
 Finds the test with the specified name in the hierarchy. More...
 
virtual TestPath resolveTestPath (const std::string &testPath) const
 Resolved the specified test path with this test acting as 'root'. More...
 
- Public Member Functions inherited from TestFixture
virtual ~TestFixture ()
 

Private Member Functions

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

Additional Inherited Members

- Protected Member Functions inherited from Test
virtual void checkIsValidIndex (int index) const
 
- 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;
};
Expected exception test case decorator.
Definition: ExceptionTestCaseDecorator.h:45
virtual void checkException(ExpectedExceptionType &)
Called when the exception is caught.
Definition: ExceptionTestCaseDecorator.h:95
ExpectedException ExpectedExceptionType
Definition: ExceptionTestCaseDecorator.h:47
#define CPPUNIT_ASSERT_EQUAL(expected, actual)
Asserts that two values are equals.
Definition: TestAssert.h:332

Member Typedef Documentation

◆ ExpectedExceptionType

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

Constructor & Destructor Documentation

◆ ExceptionTestCaseDecorator()

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

◆ checkException()

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

Called when the exception is caught.

Should be overriden to check the exception.

◆ runTest()

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 TestCase.


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

Send comments to:
CppUnit Developers