From 0c5051a8acf83fd77a6094177eb0711d3f90d997 Mon Sep 17 00:00:00 2001 From: Baptiste Lepilleur Date: Mon, 11 Jun 2001 18:56:23 +0000 Subject: 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. --- examples/cppunittest/TestCaseTest.cpp | 148 ++++++++++++++++++++++++++++++++++ 1 file changed, 148 insertions(+) create mode 100644 examples/cppunittest/TestCaseTest.cpp (limited to 'examples/cppunittest/TestCaseTest.cpp') 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 + +/* + - 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 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() ); +} -- cgit v1.2.1