diff options
| author | Baptiste Lepilleur <gaiacrtn@free.fr> | 2001-09-29 16:53:48 +0000 |
|---|---|---|
| committer | Baptiste Lepilleur <gaiacrtn@free.fr> | 2001-09-29 16:53:48 +0000 |
| commit | bef9647de57c10e9b3c2779e9eff21aebb05c3ec (patch) | |
| tree | 84f1d8c4323b83ad1773bc86b0e6be4e2eb7dee7 /examples/cppunittest/TestCallerTest.cpp | |
| parent | 53929c98380419c90d224ef610ff273f4e6abb3c (diff) | |
| download | cppunit-bef9647de57c10e9b3c2779e9eff21aebb05c3ec.tar.gz | |
Example/cppunittest/TestCaller.
example/cppunittest/TestCaller.*: remove some memory leaks.
TestCaller exception catching features is now tested correctly.
Previous test tested nothing!
Diffstat (limited to 'examples/cppunittest/TestCallerTest.cpp')
| -rw-r--r-- | examples/cppunittest/TestCallerTest.cpp | 39 |
1 files changed, 33 insertions, 6 deletions
diff --git a/examples/cppunittest/TestCallerTest.cpp b/examples/cppunittest/TestCallerTest.cpp index cef9a5b..929cb39 100644 --- a/examples/cppunittest/TestCallerTest.cpp +++ b/examples/cppunittest/TestCallerTest.cpp @@ -2,7 +2,6 @@ #include "FailureException.h" #include <cppunit/extensions/TestSuiteBuilder.h> #include <cppunit/extensions/HelperMacros.h> -#include <cppunit/TestResult.h> CPPUNIT_TEST_SUITE_REGISTRATION( TestCallerTest ); @@ -22,6 +21,12 @@ TestCallerTest::ExceptionThrower::testThrowException() } +void +TestCallerTest::ExceptionThrower::testThrowNothing() +{ +} + + TestCallerTest::TestCallerTest() : m_testName( "TrackedTestCaseCaller" ) @@ -44,6 +49,7 @@ TestCallerTest::suite() suite.addTestCaller( "testPointerConstructor", &TestCallerTest::testPointerConstructor ); suite.addTestCaller( "testExpectFailureException", &TestCallerTest::testExpectFailureException ); suite.addTestCaller( "testExpectException", &TestCallerTest::testExpectException ); + suite.addTestCaller( "testExpectedExceptionNotCaught", &TestCallerTest::testExpectedExceptionNotCaught ); return suite.takeSuite(); } @@ -58,6 +64,7 @@ TestCallerTest::setUp() m_tearDownCount = 0; m_testCount = 0; TrackedTestCase::setTracker( this ); + m_result = new CppUnit::TestResult(); } @@ -65,6 +72,7 @@ void TestCallerTest::tearDown() { TrackedTestCase::removeTracker(); + delete m_result; } @@ -112,7 +120,7 @@ TestCallerTest::testBasicConstructor() checkTestName( caller.getName() ); checkNothingButConstructorCalled(); - delete caller.run(); + caller.run( m_result ); checkRunningSequenceCalled(); } // Force destruction of the test caller. @@ -131,7 +139,7 @@ TestCallerTest::testReferenceConstructor() checkTestName( caller.getName() ); checkNothingButConstructorCalled(); - delete caller.run(); + caller.run( m_result ); checkRunningSequenceCalled(); } // Force destruction of the test caller. @@ -150,7 +158,7 @@ TestCallerTest::testPointerConstructor() checkTestName( caller.getName() ); checkNothingButConstructorCalled(); - delete caller.run(); + caller.run( m_result ); checkRunningSequenceCalled(); } // Force destruction of the test caller. @@ -164,7 +172,8 @@ TestCallerTest::testExpectFailureException() CppUnit::TestCaller<ExceptionThrower,FailureException> caller( m_testName, &ExceptionThrower::testThrowFailureException ); - caller.run(); + caller.run( m_result ); + CPPUNIT_ASSERT( m_result->wasSuccessful() ); } @@ -174,7 +183,25 @@ TestCallerTest::testExpectException() CppUnit::TestCaller<ExceptionThrower,CppUnit::Exception> caller( m_testName, &ExceptionThrower::testThrowException ); - caller.run(); + caller.run( m_result ); + CPPUNIT_ASSERT( m_result->wasSuccessful() ); +} + + +void +TestCallerTest::testExpectedExceptionNotCaught() +{ + CppUnit::TestCaller<ExceptionThrower,FailureException> caller( + m_testName, + &ExceptionThrower::testThrowNothing ); + caller.run( m_result ); + CPPUNIT_ASSERT( !m_result->wasSuccessful() ); + CPPUNIT_ASSERT_EQUAL( 1, int(m_result->failures().size()) ); +// Can differentiate throw 'new Exception' from throw 'Exception' +// only by text message which is unsafe. +// Possible solution: subclass Exception: +// CppUnit::Exception *e = m_result->failues()[0]->thrownException(); +// CPPUNIT_ASSERT( e->isInstanceOf( FailureException::type() ) ); } |
