summaryrefslogtreecommitdiff
path: root/examples/cppunittest/TestResultTest.cpp
diff options
context:
space:
mode:
authorBaptiste Lepilleur <gaiacrtn@free.fr>2002-02-28 09:58:40 +0000
committerBaptiste Lepilleur <gaiacrtn@free.fr>2002-02-28 09:58:40 +0000
commit2c7af6bda8b090a31dd39e3ca6e5c55ed7758fb9 (patch)
treebab900654046a7afabcf534647be53ea1d4a90a3 /examples/cppunittest/TestResultTest.cpp
parent36905b4f9faf4075abfa1c695c443185650c47a2 (diff)
downloadcppunit-2c7af6bda8b090a31dd39e3ca6e5c55ed7758fb9.tar.gz
NEW: updated and restructured.
NEW: updated and restructured. * include/cppunit/CompilerOutputter.h: * src/cppunit/CompilerOutputter.cpp: updated against TestResultChange. Changed TestResult to TestResultCollector. * include/cppunit/extensions/HelperMacros.h: minor documentation fix. * include/cppunit/Outputter.h: added. Abstract base class for all Outputter. * include/cppunit/Portability.h: made the fix on OStringStream suggested by Bob Summerwill to remove level 4 warning with VC++. * include/cppunit/TestAssert.h: added macro CPPUNIT_ASSERT_EQUAL_MESSAGE. * src/cppunit/TestFailure.cpp: * include/cppunit/TestFailure.h: added method clone() to duplicate a failure. Made all method virtual. * include/cppunit/TestListener.h: changed signature of addFailure() to addFailure( const TestFailure &failure ). Failure is now only a temporary object. * include/cppunit/Outputter.h: added. Abstract base class for all outputter. Used by TextTestRunner. * include/cppunit/SynchronizedObject.h: * src/cppunit/SynchronizedObject.cpp: added. Class extracted from TestResult. Base class for objects that can be accessed from different threads. * include/cppunit/TestResult.h: TestFailure.h is no longer included. * include/cppunit/TestResult.h: * src/cppunit/TestResult.cpp: extracted all methods related to keeping track of the result to the new TestResultCollector class which is a TestListener. * include/cppunit/TestResultCollector.h: * src/cppunit/TestResultCollector.cpp: added. TestListener which kept track of the result of the test run. All failure/error, and tests are tracked. * include/cppunit/TestSucessListener.h: * src/cppunit/TestSucessListener.cpp: added. TestListener extracted from TestResult. Is responsible for wasSucessful(). * include/cppunit/TestCase.h: * src/cppunit/TestCase.cpp: reindented. * include/cppunit/TextOutputter.h: * src/cppunit/TextOutputter.cpp: added. Copied from the deprecated TextTestResult and modified to act as an Ouputter. * include/cppunit/TextTestProgressListener.h: * src/cppunit/TextTestProgressListener.cpp: Copied from the deprecated TextTestResult and modified to print the dot while the test are running. * include/cppunit/TextTestResult.h: * src/cppunit/TextTestResult.cpp: updated against TestResult change. No compatiblity break. Deprecated. * include/cppunit/TextTestRunner.h: * src/cppunit/TextTestRunner.cpp: updated to work with the new TestResult. Use TextTestProgressListener and TextOutputter instead of TextTestResult. Any outputter with interface Outputter can be used to print the test result (CompilerOutputter, XmlOutputter, TextOutputter...) * include/cppunit/XmlOutputter.h: * src/cppunit/XmlOutputter.cpp: updated against TestResultChange. Changed TestResult to TestResultCollector. * src/msvc6/TestRunnerDlg.h: * src/msvc6/TestRunnerDlg.cpp: fixed the 'fullrowselect' feature of the list view. The dialog is a TestListener itself, it no longer use the GUITestResult class. * src/msvc6/TestRunner.rc: moved the "autorun test button" in such a way that it did not overlap the progress bar anymore. * src/msvc6/MfcSynchronizationObject.h: added. Generic SynchronizedObject lock for MFC. * src/msvc6/GUITestResult.h : * src/msvc6/GUITestResult.cpp : removed. * src/qttestrunner/TestRunnerModel.h: * src/qttestrunner/TestRunnerModel.cpp: changed addFailure() signature to reflect change on TestListener. * examples/cppunittest/CppUnitTestMain.cpp: updated to use the new Outputter abstraction and TextTestRunner facilities. * examples/cppunittest/FailingTestCase.h: * examples/cppunittest/FailingTestCase.cpp: removed. Replaced by MockTestCase. * examples/cppunittest/FailingTestCase.h: * examples/cppunittest/FailingTestCase.h: * examples/cppunittest/HelperMacrosTest.h: * examples/cppunittest/HelperMacrosTest.cpp: Updated against TestResult change. Use MockTestListener instead of TestResult to check for sucess or failure. * examples/cppunittest/MockTestListener.h: * examples/cppunittest/MockTestListener.cpp: the class now behave like a mock object. * examples/cppunittest/MockTestCase.h: * examples/cppunittest/MockTestCase.cpp: added. Mock TestCase object. * examples/cppunittest/OrthodoxTest.h: * examples/cppunittest/OrthodoxTest.cpp: Updated against TestResult change. Use MockTestListener instead of TestResult to check for sucess or failure. * examples/cppunittest/SynchronizedTestResult.h: Updated against TestResult change. * examples/cppunittest/TestCallerTest.h: * examples/cppunittest/TestCallerTest.cpp: Updated against TestResult change. Use MockTestListener instead of TestResult. * examples/cppunittest/TestCaseTest.h: * examples/cppunittest/TestCaseTest.cpp: Updated against TestResult change. Use MockTestListener and MockTestCase instead of FailingTestCase and TestResult. * examples/cppunittest/TestDecoratorTest.h: * examples/cppunittest/TestDecoratorTest.cpp: Updated against TestResult change. Use MockTestCase instead of FailingTestCase. * examples/cppunittest/TestListenerTest.h: * examples/cppunittest/TestListenerTest.cpp: removed. Those unit tests have been rewrote and moved to TestResultTest. * examples/cppunittest/TestResultTest.h: * examples/cppunittest/TestResultTest.cpp: Updated to test the new interface. Tests from TestListenerTest have been moved here. * examples/cppunittest/TestResultCollectorTest.h: * examples/cppunittest/TestResultCollectorTest.cpp: added. Tests for the class that been extracted from TestResult. * examples/cppunittest/TestSetUpTest.h: * examples/cppunittest/TestSetUpTest.cpp: renamed SetUp inner class to MockSetUp. Changed interface to be more akin to a Mock object. * examples/cppunittest/TestSuiteTest.h: * examples/cppunittest/TestSuiteTest.cpp: Updated against TestResult change, and rewrote to use MockTestCase instead of FailingTestCase. * examples/cppunittest/XmlOutputterTest.h: * examples/cppunittest/XmlOutputterTest.cpp: Updated against TestResult change. Added some utility methods to make the update easier.
Diffstat (limited to 'examples/cppunittest/TestResultTest.cpp')
-rw-r--r--examples/cppunittest/TestResultTest.cpp274
1 files changed, 45 insertions, 229 deletions
diff --git a/examples/cppunittest/TestResultTest.cpp b/examples/cppunittest/TestResultTest.cpp
index aa9175e..7122a92 100644
--- a/examples/cppunittest/TestResultTest.cpp
+++ b/examples/cppunittest/TestResultTest.cpp
@@ -1,12 +1,5 @@
#include "CoreSuite.h"
#include "TestResultTest.h"
-#include <cppunit/TestResult.h>
-
-/* Note:
- - the TestListener part of TestResult is tested in TestListenerTest.
- - bug identified: errors() and failures() are synchronized but returns
- reference! No unit test for that one (need multihread...).
- */
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( TestResultTest,
@@ -26,21 +19,19 @@ TestResultTest::~TestResultTest()
void
TestResultTest::setUp()
{
- m_lockCount = 0;
- m_unlockCount = 0;
m_result = new CppUnit::TestResult();
- m_synchronizedResult = new SynchronizedTestResult( this );
- m_test = new CppUnit::TestCase();
- m_test2 = new CppUnit::TestCase();
+ m_listener1 = new MockTestListener( "listener1" );
+ m_listener2 = new MockTestListener( "listener2" );
+ m_dummyTest = new CppUnit::TestCase();
}
void
TestResultTest::tearDown()
{
- delete m_test2;
- delete m_test;
- delete m_synchronizedResult;
+ delete m_dummyTest;
+ delete m_listener1;
+ delete m_listener2;
delete m_result;
}
@@ -48,7 +39,6 @@ TestResultTest::tearDown()
void
TestResultTest::testConstructor()
{
- checkResult( 0, 0, 0 );
CPPUNIT_ASSERT( !m_result->shouldStop() );
}
@@ -62,246 +52,72 @@ TestResultTest::testStop()
void
-TestResultTest::testAddTwoErrors()
-{
- std::string errorMessage1( "First Error" );
- m_result->addError( m_test, new CppUnit::Exception( errorMessage1 ) );
-
- std::string errorMessage2( "Second Error" );
- m_result->addError( m_test2, new CppUnit::Exception( errorMessage2 ) );
- checkResult( 0, 2, 0 );
- checkFailure( m_result->failures()[0],
- errorMessage1,
- m_test,
- true );
- checkFailure( m_result->failures()[1],
- errorMessage2,
- m_test2,
- true );
-}
-
-
-void
-TestResultTest::testAddTwoFailures()
-{
- std::string errorMessage1( "First Failure" );
- m_result->addFailure( m_test, new CppUnit::Exception( errorMessage1 ) );
-
- std::string errorMessage2( "Second Failure" );
- m_result->addFailure( m_test2, new CppUnit::Exception( errorMessage2 ) );
- checkResult( 2, 0, 0 );
- checkFailure( m_result->failures()[0],
- errorMessage1,
- m_test,
- false );
- checkFailure( m_result->failures()[1],
- errorMessage2,
- m_test2,
- false );
-}
-
-
-void
-TestResultTest::testStartTest()
-{
- m_result->startTest( m_test );
- m_result->startTest( m_test );
- checkResult( 0, 0, 2 );
-}
-
-
-void
-TestResultTest::testEndTest()
+TestResultTest::testAddError()
{
- // It doesn't actually do anything beyond TestListener stuffs...
-}
+ CppUnit::Exception *dummyException = new CppUnit::Exception( "some_error" );
+ m_listener1->setExpectFailure( m_dummyTest, dummyException, true );
+ m_result->addListener( m_listener1 );
+ m_result->addError( m_dummyTest, dummyException );
-void
-TestResultTest::testWasSuccessfulWithNoTest()
-{
- checkWasSuccessful( true );
+ m_listener1->verify();
}
void
-TestResultTest::testWasSuccessfulWithErrors()
+TestResultTest::testAddFailure()
{
- m_result->addError( m_test, new CppUnit::Exception( "Error1" ) );
- m_result->addError( m_test, new CppUnit::Exception( "Error2" ) );
- checkWasSuccessful( false );
-}
+ CppUnit::Exception *dummyException = new CppUnit::Exception( "some_error" );
+ m_listener1->setExpectFailure( m_dummyTest, dummyException, false );
+ m_result->addListener( m_listener1 );
+ m_result->addFailure( m_dummyTest, dummyException );
-void
-TestResultTest::testWasSuccessfulWithFailures()
-{
- m_result->addFailure( m_test, new CppUnit::Exception( "Failure1" ) );
- m_result->addFailure( m_test, new CppUnit::Exception( "Failure2" ) );
- checkWasSuccessful( false );
+ m_listener1->verify();
}
void
-TestResultTest::testWasSuccessfulWithErrorsAndFailures()
-{
- m_result->addError( m_test, new CppUnit::Exception( "Error1" ) );
- m_result->addFailure( m_test, new CppUnit::Exception( "Failure2" ) );
- checkWasSuccessful( false );
-}
-
-
-void
-TestResultTest::testWasSuccessfulWithSucessfulTest()
-{
- m_result->startTest( m_test );
- m_result->endTest( m_test );
- m_result->startTest( m_test2 );
- m_result->endTest( m_test2 );
- checkWasSuccessful( true );
-}
-
-
-void
-TestResultTest::testSynchronizationAddError()
-{
- m_synchronizedResult->addError( m_test, new CppUnit::Exception( "Error1" ) );
- checkSynchronization();
-}
-
-
-void
-TestResultTest::testSynchronizationAddFailure()
-{
- m_synchronizedResult->addFailure( m_test, new CppUnit::Exception( "Failure1" ) );
- checkSynchronization();
-}
-
-
-void
-TestResultTest::testSynchronizationStartTest()
-{
- m_synchronizedResult->startTest( m_test );
- checkSynchronization();
-}
-
-
-void
-TestResultTest::testSynchronizationEndTest()
-{
- m_synchronizedResult->endTest( m_test );
- checkSynchronization();
-}
-
-
-void
-TestResultTest::testSynchronizationRunTests()
-{
- m_synchronizedResult->runTests();
- checkSynchronization();
-}
-
-
-void
-TestResultTest::testSynchronizationTestErrors()
-{
- m_synchronizedResult->testErrors();
- checkSynchronization();
-}
-
-
-void
-TestResultTest::testSynchronizationTestFailures()
-{
- m_synchronizedResult->testFailures();
- checkSynchronization();
-}
-
-
-void
-TestResultTest::testSynchronizationFailures()
-{
- m_synchronizedResult->failures();
- checkSynchronization();
-}
-
-
-void
-TestResultTest::testSynchronizationWasSuccessful()
-{
- m_synchronizedResult->wasSuccessful();
- checkSynchronization();
-}
-
-
-void
-TestResultTest::testSynchronizationShouldStop()
-{
- m_synchronizedResult->shouldStop();
- checkSynchronization();
-}
-
-
-void
-TestResultTest::testSynchronizationStop()
-{
- m_synchronizedResult->stop();
- checkSynchronization();
-}
-
-
-void
-TestResultTest::checkResult( int failures,
- int errors,
- int testsRun )
+TestResultTest::testStartTest()
{
- CPPUNIT_ASSERT_EQUAL( testsRun, m_result->runTests() );
- CPPUNIT_ASSERT_EQUAL( errors, m_result->testErrors() );
- CPPUNIT_ASSERT_EQUAL( failures, m_result->testFailures() );
- CPPUNIT_ASSERT_EQUAL( errors + failures,
- m_result->testFailuresTotal() );
-}
-
+ m_listener1->setExpectStartTest( m_dummyTest );
+ m_result->addListener( m_listener1 );
+
+ m_result->startTest( m_dummyTest );
-void
-TestResultTest::checkFailure( CppUnit::TestFailure *failure,
- std::string expectedMessage,
- CppUnit::Test *expectedTest,
- bool expectedIsError )
-{
- std::string actualMessage( failure->thrownException()->what() );
- CPPUNIT_ASSERT_EQUAL( expectedMessage, actualMessage );
- CPPUNIT_ASSERT_EQUAL( expectedTest, failure->failedTest() );
- CPPUNIT_ASSERT_EQUAL( expectedIsError, failure->isError() );
+ m_listener1->verify();
}
void
-TestResultTest::checkWasSuccessful( bool shouldBeSuccessful )
+TestResultTest::testEndTest()
{
- CPPUNIT_ASSERT_EQUAL( shouldBeSuccessful, m_result->wasSuccessful() );
-}
+ m_listener1->setExpectEndTest( m_dummyTest );
+ m_result->addListener( m_listener1 );
+
+ m_result->endTest( m_dummyTest );
-
-void
-TestResultTest::locked()
-{
- CPPUNIT_ASSERT_EQUAL( m_lockCount, m_unlockCount );
- ++m_lockCount;
+ m_listener1->verify();
}
void
-TestResultTest::unlocked()
+TestResultTest::testTwoListener()
{
- ++m_unlockCount;
- CPPUNIT_ASSERT_EQUAL( m_lockCount, m_unlockCount );
-}
+ m_listener1->setExpectStartTest( m_dummyTest );
+ m_listener2->setExpectStartTest( m_dummyTest );
+ CppUnit::Exception *dummyException1 = new CppUnit::Exception( "some_error" );
+ m_listener1->setExpectFailure( m_dummyTest, dummyException1, true );
+ m_listener2->setExpectFailure( m_dummyTest, dummyException1, true );
+ m_listener1->setExpectEndTest( m_dummyTest );
+ m_listener2->setExpectEndTest( m_dummyTest );
+ m_result->addListener( m_listener1 );
+ m_result->addListener( m_listener2 );
+ m_result->startTest( m_dummyTest );
+ m_result->addError( m_dummyTest, dummyException1 );
+ m_result->endTest( m_dummyTest );
-void
-TestResultTest::checkSynchronization()
-{
- CPPUNIT_ASSERT_EQUAL( m_lockCount, m_unlockCount );
- CPPUNIT_ASSERT( m_lockCount > 0 );
+ m_listener1->verify();
+ m_listener2->verify();
}