diff options
author | Baptiste Lepilleur <gaiacrtn@free.fr> | 2001-06-11 18:56:23 +0000 |
---|---|---|
committer | Baptiste Lepilleur <gaiacrtn@free.fr> | 2001-06-11 18:56:23 +0000 |
commit | 0c5051a8acf83fd77a6094177eb0711d3f90d997 (patch) | |
tree | a0757b1cae952576f4497d40ccf3aa70a2bf84c8 /examples/cppunittest/TestCaseTest.cpp | |
parent | 021d0a2611777a06d948735e0ad36cb90ffd413b (diff) | |
download | cppunit-0c5051a8acf83fd77a6094177eb0711d3f90d997.tar.gz |
Examples/cppunittest/TestResultTest.
examples/cppunittest/TestResultTest.*: renamed TestListenerTest.*
* examples/cppunittest/*: added unit tests for:
HelperMacros, TestAssert, TestCaller, TestCase, TestFailure,
TestResult, TestSuite, TestDecoratorTest, TestSetUp, RepeatedTestTest,
Orthodox, Exception.
Diffstat (limited to 'examples/cppunittest/TestCaseTest.cpp')
-rw-r--r-- | examples/cppunittest/TestCaseTest.cpp | 148 |
1 files changed, 148 insertions, 0 deletions
diff --git a/examples/cppunittest/TestCaseTest.cpp b/examples/cppunittest/TestCaseTest.cpp new file mode 100644 index 0000000..d749938 --- /dev/null +++ b/examples/cppunittest/TestCaseTest.cpp @@ -0,0 +1,148 @@ +#include "TestCaseTest.h" +#include "FailingTestCase.h" +#include <cppunit/TestResult.h> + +/* + - test have been done to check exception management in run(). other + tests need to be added to check the other aspect of TestCase. + */ + +CPPUNIT_TEST_SUITE_REGISTRATION( TestCaseTest ); + + +TestCaseTest::TestCaseTest() +{ +} + + +TestCaseTest::~TestCaseTest() +{ +} + + +void +TestCaseTest::setUp() +{ + m_result = new CppUnit::TestResult(); +} + + +void +TestCaseTest::tearDown() +{ + delete m_result; +} + + +void +TestCaseTest::testSetUpFailure() +{ + checkFailure( true, false, false ); +} + + +void +TestCaseTest::testRunTestFailure() +{ + checkFailure( false, true, false ); +} + + +void +TestCaseTest::testTearDownFailure() +{ + checkFailure( false, false, true ); +} + + +void +TestCaseTest::testFailAll() +{ + checkFailure( true, true, true ); +} + + +void +TestCaseTest::testNoFailure() +{ + checkFailure( false, false, false ); +} + + +void +TestCaseTest::checkFailure( bool failSetUp, + bool failRunTest, + bool failTearDown ) +{ + try + { + FailingTestCase test( failSetUp, failRunTest, failTearDown ); + test.run( m_result ); + test.verify( !failSetUp, !failSetUp ); + } + catch ( FailureException & ) + { + CPPUNIT_ASSERT_MESSAGE( "exception should have been catched", false ); + } +} + + +void +TestCaseTest::testCountTestCases() +{ + CppUnit::TestCase test; + CPPUNIT_ASSERT_EQUAL( 1, test.countTestCases() ); +} + + +void +TestCaseTest::testDefaultConstructor() +{ + CppUnit::TestCase test; + CPPUNIT_ASSERT_EQUAL( std::string(""), test.getName() ); +} + + +void +TestCaseTest::testConstructorWithName() +{ + std::string testName( "TestName" ); + CppUnit::TestCase test( testName ); + CPPUNIT_ASSERT_EQUAL( testName, test.getName() ); +} + + +void +TestCaseTest::testDefaultRun() +{ + CppUnit::TestCase test; + std::auto_ptr<CppUnit::TestResult> result( test.run() ); + + checkResult( 0, 0, 1, result.get() ); +} + + +void +TestCaseTest::testTwoRun() +{ + FailingTestCase test1( false, true, false ); + test1.run( m_result ); + test1.run( m_result ); + + FailingTestCase test2( false, false, false ); + test2.run( m_result ); + + checkResult( 2, 0, 1, m_result ); +} + + +void +TestCaseTest::checkResult( int failures, + int errors, + int testsRun, + CppUnit::TestResult *result ) +{ + CPPUNIT_ASSERT_EQUAL( testsRun, result->runTests() ); + CPPUNIT_ASSERT_EQUAL( errors, result->testErrors() ); + CPPUNIT_ASSERT_EQUAL( failures, result->testFailures() ); +} |