diff options
author | Baptiste Lepilleur <gaiacrtn@free.fr> | 2002-02-28 09:58:40 +0000 |
---|---|---|
committer | Baptiste Lepilleur <gaiacrtn@free.fr> | 2002-02-28 09:58:40 +0000 |
commit | 2c7af6bda8b090a31dd39e3ca6e5c55ed7758fb9 (patch) | |
tree | bab900654046a7afabcf534647be53ea1d4a90a3 /examples/cppunittest/MockTestCase.cpp | |
parent | 36905b4f9faf4075abfa1c695c443185650c47a2 (diff) | |
download | cppunit-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/MockTestCase.cpp')
-rw-r--r-- | examples/cppunittest/MockTestCase.cpp | 173 |
1 files changed, 173 insertions, 0 deletions
diff --git a/examples/cppunittest/MockTestCase.cpp b/examples/cppunittest/MockTestCase.cpp new file mode 100644 index 0000000..6749272 --- /dev/null +++ b/examples/cppunittest/MockTestCase.cpp @@ -0,0 +1,173 @@ +#include "FailureException.h" +#include "MockTestCase.h" + + +MockTestCase::MockTestCase( std::string name ) + : CppUnit::TestCase( name ) + , m_hasSetUpExpectation( false ) + , m_expectedSetUpCall( 0 ) + , m_actualSetUpCall( 0 ) + , m_hasTearDownExpectation( false ) + , m_expectedTearDownCall( 0 ) + , m_actualTearDownCall( 0 ) + , m_expectRunTestCall( false ) + , m_expectedRunTestCallCount( 0 ) + , m_actualRunTestCallCount( 0 ) + , m_expectCountTestCasesCall( false ) + , m_expectedCountTestCasesCallCount( 0 ) + , m_actualCountTestCasesCallCount( 0 ) + , m_setUpThrow( false ) + , m_tearDownThrow( false ) + , m_runTestThrow( false ) +{ +} + + +MockTestCase::~MockTestCase() +{ +} + + +int +MockTestCase::countTestCases() const +{ + ++m_actualCountTestCasesCallCount; + if ( m_expectCountTestCasesCall ) + { + CPPUNIT_ASSERT_MESSAGE( getName() + ": unexpected MockTestCase::countTestCases() call", + m_actualCountTestCasesCallCount <= m_expectedCountTestCasesCallCount ); + } + + return SuperClass::countTestCases(); +} + + +void +MockTestCase::setUp() +{ + if ( m_hasSetUpExpectation ) + { + ++m_actualSetUpCall; + CPPUNIT_ASSERT_MESSAGE( getName() + ": unexpected MockTestCase::setUp() call", + m_actualSetUpCall <= m_expectedSetUpCall ); + } + + if ( m_setUpThrow ) + throw FailureException(); +} + +void +MockTestCase::tearDown() +{ + if ( m_hasTearDownExpectation ) + { + ++m_actualTearDownCall; + CPPUNIT_ASSERT_MESSAGE( getName() + ": unexpected MockTestCase::tearDown() call", + m_actualTearDownCall <= m_expectedTearDownCall ); + } + + if ( m_tearDownThrow ) + throw FailureException(); +} + + +void +MockTestCase::runTest() +{ + ++m_actualRunTestCallCount; + if ( m_expectRunTestCall ) + { + CPPUNIT_ASSERT_MESSAGE( getName() + ": unexpected MockTestCase::runTest() call", + m_actualRunTestCallCount <= m_expectedRunTestCallCount ); + } + + if ( m_runTestThrow ) + throw FailureException(); +} + + +void +MockTestCase::setExpectedSetUpCall( int callCount ) +{ + m_hasSetUpExpectation = true; + m_expectedSetUpCall = callCount; +} + + +void +MockTestCase::setExpectedTearDownCall( int callCount ) +{ +} + + +void +MockTestCase::setExpectedRunTestCall( int callCount ) +{ + m_expectRunTestCall = true; + m_expectedRunTestCallCount = callCount ; +} + + +void +MockTestCase::setExpectedCountTestCasesCall( int callCount ) +{ + m_expectCountTestCasesCall = true; + m_expectedCountTestCasesCallCount = callCount; +} + + +void +MockTestCase::makeSetUpThrow() +{ + m_setUpThrow = true; +} + + +void +MockTestCase::makeTearDownThrow() +{ + m_tearDownThrow = true; +} + + +void +MockTestCase::makeRunTestThrow() +{ + m_runTestThrow = true; +} + + +void +MockTestCase::verify() +{ + if ( m_hasSetUpExpectation ) + { + CPPUNIT_ASSERT_EQUAL_MESSAGE( m_expectedSetUpCall, + m_actualSetUpCall, + getName() + ": bad MockTestCase::setUp() " + "call count" ); + } + + if ( m_hasTearDownExpectation ) + { + CPPUNIT_ASSERT_EQUAL_MESSAGE( m_expectedTearDownCall, + m_actualTearDownCall, + getName() + ": bad MockTestCase::setUp() " + "call count" ); + } + + if ( m_expectCountTestCasesCall ) + { + CPPUNIT_ASSERT_EQUAL_MESSAGE( m_expectedCountTestCasesCallCount, + m_actualCountTestCasesCallCount, + getName() + ": bad MockTestCase::countTestCases() " + "call count" ); + } + if ( m_expectRunTestCall ) + { + CPPUNIT_ASSERT_EQUAL_MESSAGE( m_expectedRunTestCallCount, + m_actualRunTestCallCount, + getName() + ": bad MockTestCase::runTest() " + "call count" ); + } +} |