diff options
| author | Baptiste Lepilleur <gaiacrtn@free.fr> | 2001-06-11 18:57:30 +0000 |
|---|---|---|
| committer | Baptiste Lepilleur <gaiacrtn@free.fr> | 2001-06-11 18:57:30 +0000 |
| commit | 77e014c1992793da5c059bc09eafd183bde8785d (patch) | |
| tree | 2600bca476036e5eda3c1d82809ca3382ed0bd1b /examples/cppunittest | |
| parent | 0c5051a8acf83fd77a6094177eb0711d3f90d997 (diff) | |
| download | cppunit-77e014c1992793da5c059bc09eafd183bde8785d.tar.gz | |
Examples/cppunittest/TestResultTest.
examples/cppunittest/TestResultTest.*: renamed TestListenerTest.*
Diffstat (limited to 'examples/cppunittest')
| -rw-r--r-- | examples/cppunittest/TestResultTest.cpp | 305 | ||||
| -rw-r--r-- | examples/cppunittest/TestResultTest.h | 102 |
2 files changed, 407 insertions, 0 deletions
diff --git a/examples/cppunittest/TestResultTest.cpp b/examples/cppunittest/TestResultTest.cpp new file mode 100644 index 0000000..4a80572 --- /dev/null +++ b/examples/cppunittest/TestResultTest.cpp @@ -0,0 +1,305 @@ +#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_REGISTRATION( TestResultTest ); + + +TestResultTest::TestResultTest() +{ +} + + +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(); +} + + +void +TestResultTest::tearDown() +{ + delete m_test2; + delete m_test; + delete m_synchronizedResult; + delete m_result; +} + + +void +TestResultTest::testConstructor() +{ + checkResult( 0, 0, 0 ); + CPPUNIT_ASSERT( !m_result->shouldStop() ); +} + + +void +TestResultTest::testStop() +{ + m_result->stop(); + CPPUNIT_ASSERT( m_result->shouldStop() ); +} + + +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->errors().at(0), + errorMessage1, + m_test ); + checkFailure( m_result->errors().at(1), + errorMessage2, + m_test2 ); +} + + +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().at(0), + errorMessage1, + m_test ); + checkFailure( m_result->failures().at(1), + errorMessage2, + m_test2 ); +} + + +void +TestResultTest::testStartTest() +{ + m_result->startTest( m_test ); + m_result->startTest( m_test ); + checkResult( 0, 0, 2 ); +} + + +void +TestResultTest::testEndTest() +{ + // It doesn't actually do anything beyond TestListener stuffs... +} + + +void +TestResultTest::testWasSuccessfulWithNoTest() +{ + checkWasSuccessful( true ); +} + + +void +TestResultTest::testWasSuccessfulWithErrors() +{ + m_result->addError( m_test, new CppUnit::Exception( "Error1" ) ); + m_result->addError( m_test, new CppUnit::Exception( "Error2" ) ); + checkWasSuccessful( false ); +} + + +void +TestResultTest::testWasSuccessfulWithFailures() +{ + m_result->addFailure( m_test, new CppUnit::Exception( "Failure1" ) ); + m_result->addFailure( m_test, new CppUnit::Exception( "Failure2" ) ); + checkWasSuccessful( false ); +} + + +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::testSynchronizationErrors() +{ + m_synchronizedResult->errors(); + 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 ) +{ + CPPUNIT_ASSERT_EQUAL( testsRun, m_result->runTests() ); + CPPUNIT_ASSERT_EQUAL( errors, m_result->testErrors() ); + CPPUNIT_ASSERT_EQUAL( failures, m_result->testFailures() ); +} + + +void +TestResultTest::checkFailure( CppUnit::TestFailure *failure, + std::string expectedMessage, + CppUnit::Test *expectedTest ) +{ + std::string actualMessage( failure->thrownException()->what() ); + CPPUNIT_ASSERT_EQUAL( expectedMessage, actualMessage ); + CPPUNIT_ASSERT_EQUAL( expectedTest, failure->failedTest() ); +} + + +void +TestResultTest::checkWasSuccessful( bool shouldBeSuccessful ) +{ + CPPUNIT_ASSERT_EQUAL( shouldBeSuccessful, m_result->wasSuccessful() ); +} + + +void +TestResultTest::locked() +{ + CPPUNIT_ASSERT_EQUAL( m_lockCount, m_unlockCount ); + ++m_lockCount; +} + + +void +TestResultTest::unlocked() +{ + ++m_unlockCount; + CPPUNIT_ASSERT_EQUAL( m_lockCount, m_unlockCount ); +} + + +void +TestResultTest::checkSynchronization() +{ + CPPUNIT_ASSERT_EQUAL( m_lockCount, m_unlockCount ); + CPPUNIT_ASSERT( m_lockCount > 0 ); +} diff --git a/examples/cppunittest/TestResultTest.h b/examples/cppunittest/TestResultTest.h new file mode 100644 index 0000000..d27b402 --- /dev/null +++ b/examples/cppunittest/TestResultTest.h @@ -0,0 +1,102 @@ +#ifndef TESTRESULTTEST_H +#define TESTRESULTTEST_H + +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/TestFailure.h> +#include "SynchronizedTestResult.h" + + +class TestResultTest : public CppUnit::TestCase, + public SynchronizedTestResult::SynchronizationObjectListener +{ + CPPUNIT_TEST_SUITE( TestResultTest ); + CPPUNIT_TEST( testConstructor ); + CPPUNIT_TEST( testStop ); + CPPUNIT_TEST( testAddTwoErrors ); + CPPUNIT_TEST( testAddTwoFailures ); + CPPUNIT_TEST( testStartTest ); + CPPUNIT_TEST( testEndTest ); + CPPUNIT_TEST( testWasSuccessfulWithErrors ); + CPPUNIT_TEST( testWasSuccessfulWithFailures ); + CPPUNIT_TEST( testWasSuccessfulWithErrorsAndFailures ); + CPPUNIT_TEST( testWasSuccessfulWithSucessfulTest ); + CPPUNIT_TEST( testSynchronizationAddError ); + CPPUNIT_TEST( testSynchronizationAddFailure ); + CPPUNIT_TEST( testSynchronizationStartTest ); + CPPUNIT_TEST( testSynchronizationEndTest ); + CPPUNIT_TEST( testSynchronizationRunTests ); + CPPUNIT_TEST( testSynchronizationTestErrors ); + CPPUNIT_TEST( testSynchronizationTestFailures ); + CPPUNIT_TEST( testSynchronizationErrors ); + CPPUNIT_TEST( testSynchronizationFailures ); + CPPUNIT_TEST( testSynchronizationWasSuccessful ); + CPPUNIT_TEST( testSynchronizationShouldStop ); + CPPUNIT_TEST( testSynchronizationStop ); + CPPUNIT_TEST_SUITE_END(); + +public: + TestResultTest(); + virtual ~TestResultTest(); + + virtual void setUp(); + virtual void tearDown(); + + void testConstructor(); + + void testStop(); + + void testAddTwoErrors(); + void testAddTwoFailures(); + void testStartTest(); + void testEndTest(); + + void testWasSuccessfulWithNoTest(); + void testWasSuccessfulWithErrors(); + void testWasSuccessfulWithFailures(); + void testWasSuccessfulWithErrorsAndFailures(); + void testWasSuccessfulWithSucessfulTest(); + + void testSynchronizationAddError(); + void testSynchronizationAddFailure(); + void testSynchronizationStartTest(); + void testSynchronizationEndTest(); + void testSynchronizationRunTests(); + void testSynchronizationTestErrors(); + void testSynchronizationTestFailures(); + void testSynchronizationErrors(); + void testSynchronizationFailures(); + void testSynchronizationWasSuccessful(); + void testSynchronizationShouldStop(); + void testSynchronizationStop(); + + virtual void locked(); + virtual void unlocked(); + +private: + TestResultTest( const TestResultTest © ); + void operator =( const TestResultTest © ); + + void checkResult( int failures, + int errors, + int testsRun ); + + void checkFailure( CppUnit::TestFailure *failure, + std::string expectedMessage, + CppUnit::Test *expectedTest ); + + void checkWasSuccessful( bool shouldBeSuccessful ); + + void checkSynchronization(); + +private: + CppUnit::TestResult *m_result; + SynchronizedTestResult *m_synchronizedResult; + CppUnit::Test *m_test; + CppUnit::Test *m_test2; + int m_lockCount; + int m_unlockCount; +}; + + + +#endif // TESTRESULTTEST_H |
