diff options
Diffstat (limited to 'examples/cppunittest/FailingTestCase.cpp')
-rw-r--r-- | examples/cppunittest/FailingTestCase.cpp | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/examples/cppunittest/FailingTestCase.cpp b/examples/cppunittest/FailingTestCase.cpp new file mode 100644 index 0000000..f519438 --- /dev/null +++ b/examples/cppunittest/FailingTestCase.cpp @@ -0,0 +1,62 @@ +#include "FailingTestCase.h" + + +FailingTestCase::FailingTestCase( bool failSetUp, + bool failRunTest, + bool failTearDown ) : + CppUnit::TestCase( "FailingTestCase" ), + m_failSetUp( failSetUp ), + m_failRunTest( failRunTest ), + m_failTearDown( failTearDown ), + m_setUpCalled( false ), + m_runTestCalled( false ), + m_tearDownCalled( false ) +{ +} + + +FailingTestCase::~FailingTestCase() +{ +} + + +void +FailingTestCase::setUp() +{ + m_setUpCalled = true; + doFailure( m_failSetUp ); +} + + +void +FailingTestCase::tearDown() +{ + m_tearDownCalled = true; + doFailure( m_failTearDown ); +} + + +void +FailingTestCase::runTest() +{ + m_runTestCalled = true; + doFailure( m_failRunTest ); +} + + +void +FailingTestCase::doFailure( bool shouldFail ) +{ + if ( shouldFail ) + throw FailureException(); +} + + +void +FailingTestCase::verify( bool runTestCalled, + bool tearDownCalled ) +{ + CPPUNIT_ASSERT( m_setUpCalled ); + CPPUNIT_ASSERT_EQUAL( runTestCalled, m_runTestCalled ); + CPPUNIT_ASSERT_EQUAL( tearDownCalled, m_tearDownCalled ); +} |