diff options
| author | Baptiste Lepilleur <gaiacrtn@free.fr> | 2002-08-27 20:51:18 +0000 |
|---|---|---|
| committer | Baptiste Lepilleur <gaiacrtn@free.fr> | 2002-08-27 20:51:18 +0000 |
| commit | c86c65b7d821fe4bb046c489528108843513e63d (patch) | |
| tree | 0df76dcf21360b74ec3a401f8b077da5d839f2e9 /examples/cppunittest/TestResultTest.cpp | |
| parent | 69a36d9356412dddb51d8f31fbbac45ac52f7f30 (diff) | |
| download | cppunit-c86c65b7d821fe4bb046c489528108843513e63d.tar.gz | |
CodingGuideLines.
CodingGuideLines.txt: updated for OS/390 C++ limitation.
* examples/cppunittests/MockFunctor.h: added. Mock Functor to help
testing.
* examples/cppunittests/MockProtector.h: qdded. Mock Protector to help
testing.
* examples/cppunittests/TestResultTest.h
* examples/cppunittests/TestResultTest.cpp: added tests for
pushProtector(), popProtector() and protect().
* include/cppunit/TestAssert.h: removed default message value from
assertEquals(). Caused compilation error on OS/390.
* include/cppunit/plugin/PlugInParameters.h:
* src/cppunit/PlugInParameters.cpp: renamed commandLine() to
getCommandLine().
* src/msvc6/testrunner/TestRunnerDlg.h:
* src/msvc6/testrunner/TestRunnerDlg.cpp: bug fix, disabled Browse
button while running tests.
Diffstat (limited to 'examples/cppunittest/TestResultTest.cpp')
| -rw-r--r-- | examples/cppunittest/TestResultTest.cpp | 107 |
1 files changed, 106 insertions, 1 deletions
diff --git a/examples/cppunittest/TestResultTest.cpp b/examples/cppunittest/TestResultTest.cpp index 1ff6c1c..048aacd 100644 --- a/examples/cppunittest/TestResultTest.cpp +++ b/examples/cppunittest/TestResultTest.cpp @@ -1,4 +1,7 @@ #include "CoreSuite.h" +#include "MockFunctor.h" +#include "MockProtector.h" +#include "MockTestCase.h" #include "TestResultTest.h" @@ -22,7 +25,7 @@ TestResultTest::setUp() m_result = new CPPUNIT_NS::TestResult(); m_listener1 = new MockTestListener( "listener1" ); m_listener2 = new MockTestListener( "listener2" ); - m_dummyTest = new CPPUNIT_NS::TestCase(); + m_dummyTest = new MockTestCase( "dummy-test" ); } @@ -161,3 +164,105 @@ TestResultTest::testTwoListener() m_listener1->verify(); m_listener2->verify(); } + + +void +TestResultTest::testDefaultProtectSucceed() +{ + MockFunctor functor; + functor.setShouldSucceed(); + m_listener1->setExpectNoFailure(); + + m_result->addListener( m_listener1 ); + CPPUNIT_ASSERT( m_result->protect( functor, m_dummyTest ) ); + m_listener1->verify(); + functor.verify(); +} + + +void +TestResultTest::testDefaultProtectFail() +{ + MockFunctor functor; + functor.setShouldFail(); + m_listener1->setExpectNoFailure(); + + m_result->addListener( m_listener1 ); + CPPUNIT_ASSERT( !m_result->protect( functor, m_dummyTest ) ); + m_listener1->verify(); + functor.verify(); +} + + +void +TestResultTest::testDefaultProtectFailIfThrow() +{ + MockFunctor functor; + functor.setThrowFailureException(); + m_listener1->setExpectFailure(); + + m_result->addListener( m_listener1 ); + CPPUNIT_ASSERT( !m_result->protect( functor, m_dummyTest ) ); + m_listener1->verify(); + functor.verify(); +} + + +void +TestResultTest::testProtectChainPushOneTrap() +{ + MockFunctor functor; + MockProtector *protector = new MockProtector(); + functor.setThrowMockProtectorException(); + protector->setExpectException(); + m_listener1->setExpectFailure(); + + m_result->pushProtector( protector ); + m_result->addListener( m_listener1 ); + CPPUNIT_ASSERT( !m_result->protect( functor, m_dummyTest ) ); + protector->verify(); + m_listener1->verify(); + functor.verify(); +} + + +void +TestResultTest::testProtectChainPushOnePassThrough() +{ + MockFunctor functor; + MockProtector *protector = new MockProtector(); + functor.setThrowFailureException(); + protector->setExpectNoException(); + m_listener1->setExpectFailure(); + + m_result->pushProtector( protector ); + m_result->addListener( m_listener1 ); + CPPUNIT_ASSERT( !m_result->protect( functor, m_dummyTest ) ); + protector->verify(); + m_listener1->verify(); + functor.verify(); +} + + +void +TestResultTest::testProtectChainPushTwoTrap() +{ + MockFunctor functor; + functor.setThrowMockProtectorException(); + // protector1 catch the exception retrown by protector2 + MockProtector *protector1 = new MockProtector(); + protector1->setExpectException(); + // protector2 catch the exception and rethrow it + MockProtector *protector2 = new MockProtector(); + protector2->setExpectCatchAndPropagateException(); + m_listener1->setExpectFailure(); + + m_result->pushProtector( protector1 ); + m_result->pushProtector( protector2 ); + m_result->addListener( m_listener1 ); + CPPUNIT_ASSERT( !m_result->protect( functor, m_dummyTest ) ); + protector1->verify(); + protector2->verify(); + m_listener1->verify(); + functor.verify(); +} |
