From ed406a2966e62072fa6afaca8abc578db7c0c9fb Mon Sep 17 00:00:00 2001 From: Baptiste Lepilleur Date: Fri, 12 Apr 2002 18:28:48 +0000 Subject: Makefile. Makefile.am: added examples/qt to tar ball release. * TODO: heavily updated. * contrib/msvc/CppUnit*.wwtpl: changed base class for unit test to TestFixture. * include/cppunit/Test.h: removed toString() method. Not used by the framework and source of confusions with getName(). Added getChildTestCount() and getChildTestAt(), introducing the composite pattern at top level. Added utility methods findTest() and findTestPath(). * src/cppunit/Test.cpp: added. Implementation of new utility methods. * include/cppunit/TestCase.h: * src/cppunit/TestCase.cpp: inherits TestLeaf. Removed toString(), run(void) and defaultResult(). Removed default constructor. * src/cppunit/TestCase.cpp: * src/cppunit/TestSuite.cpp: fixed some includes that used "" instead of <>. * include/cppunit/TestComposite.h: * src/cppunit/TestComposite.cpp: added. Common implementation of Test for composite tests (TestSuite). * include/cppunit/TestFailure.h: * src/cppunit/TestFailure.cpp: removed toString(). * include/cppunit/TestLeaf.h: * src/cppunit/TestLeaf.cpp: added. Common implementation of Test for single test (TestCase). * include/cppunit/TestListener.h: added TimingListener example to documentation. * include/cppunit/TestPath.h: * src/cppunit/TestPath.cpp: added. List of test traversed to access a test in the test hierarchy. * include/cppunit/TestRunner.h: added. Generic TestRunner. * src/cppunit/TestRunner.cpp: moved to TextTestRunner.cpp. Added new implementation of includecppunit/TestRunner.h. * include/cppunit/TestSuite.h: * src/cppunit/TestSuite.cpp: inherits TestComposite and implements new Test interface. Removed toString(). * src/cppunit/TextTestRunner.cpp: moved from TestRunner.cpp. Implementation of include/cppunit/ui/text/TestRunner.h. * include/cppunit/extensions/RepeatedTest.h: * src/cppunit/RepeatedTest.cpp: removed toString(). * include/cppunit/extensions/TestDecorator.h: inherits TestLeaf. Removed toString() * include/cppunit/XmlOutputter.h: * src/cppunit/XmlOutputter.cpp: * examples/cppunittest/XmlOutputterTest.cpp: * examples/cppunittest/XmlOutputterTest.h: XML outputter now escape node content. Add unit test for that bug (#540944). Added style sheet support. Modified XML structure: failure message as its own element. * src/msvc/testrunner/TestRunnerModel.h: * src/msvc/testrunner/TestRunnerModel.cpp: used Test::findTest() to find a test by name instead of using RTTI. Added toAnsiString() for convertion when compiling as UNICODE. * src/msvc/testrunner/TreeHierarchyDlg.h: * src/msvc/testrunner/TreeHierarchyDlg.cpp: used new composite interface of Test to explorer the test hierarchy instead of RTTI. * examples/cppunittest/TestPathTest.h: * examples/cppunittest/TestPathTest.cpp: added, unit tests for TestPath. * examples/cppunittest/TestCaseTest.h: * examples/cppunittest/TestCaseTest.cpp: added test for TestLeaf. * examples/cppunittest/TestSuiteTest.h: * examples/cppunittest/TestSuiteTest.cpp: added test for TestComposite and new Test interface. --- examples/cppunittest/TestPathTest.cpp | 490 ++++++++++++++++++++++++++++++++++ 1 file changed, 490 insertions(+) create mode 100644 examples/cppunittest/TestPathTest.cpp (limited to 'examples/cppunittest/TestPathTest.cpp') diff --git a/examples/cppunittest/TestPathTest.cpp b/examples/cppunittest/TestPathTest.cpp new file mode 100644 index 0000000..bf89581 --- /dev/null +++ b/examples/cppunittest/TestPathTest.cpp @@ -0,0 +1,490 @@ +#include "CoreSuite.h" +#include "TestPathTest.h" + + +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( TestPathTest, + CppUnitTest::coreSuiteName() ); + + +TestPathTest::TestPathTest() +{ +} + + +TestPathTest::~TestPathTest() +{ +} + + +void +TestPathTest::setUp() +{ + m_path = new CppUnit::TestPath(); + m_test1 = new CppUnit::TestCase( "test1" ); + m_test2 = new CppUnit::TestCase( "test2" ); + m_test3 = new CppUnit::TestCase( "test3" ); + m_test4 = new CppUnit::TestCase( "test4" ); + + m_suite1 = new CppUnit::TestSuite( "All Tests" ); + m_suite2 = new CppUnit::TestSuite( "Custom" ); + m_testSuite2a = new CppUnit::TestCase( "MyTest::testDefaultConstructor" ); + m_testSuite2b = new CppUnit::TestCase( "MyTest::testConstructor" ); + m_suite2->addTest( m_testSuite2a ); + m_suite2->addTest( m_testSuite2b ); + m_suite1->addTest( m_suite2 ); +} + + +void +TestPathTest::tearDown() +{ + delete m_suite1; + delete m_path; + delete m_test4; + delete m_test3; + delete m_test2; + delete m_test1; +} + + +void +TestPathTest::testDefaultConstructor() +{ + CPPUNIT_ASSERT_EQUAL( 0, m_path->getTestCount() ); + CPPUNIT_ASSERT( !m_path->isValid() ); +} + + +void +TestPathTest::testAddTest() +{ + m_path->add( m_test1 ); + CPPUNIT_ASSERT_EQUAL( 1, m_path->getTestCount() ); + CPPUNIT_ASSERT( m_path->isValid() ); + CPPUNIT_ASSERT( m_test1 == m_path->getTestAt(0) ); +} + + +void +TestPathTest::testGetTestAtThrow1() +{ + m_path->getTestAt( 0 ); +} + + +void +TestPathTest::testGetTestAtThrow2() +{ + m_path->add( m_test1 ); + m_path->getTestAt( 1 ); +} + + +void +TestPathTest::testGetChildTest() +{ + m_path->add( m_test1 ); + CPPUNIT_ASSERT( m_test1 == m_path->getChildTest() ); +} + + +void +TestPathTest::testGetChildTestManyTests() +{ + m_path->add( m_test1 ); + m_path->add( m_test2 ); + m_path->add( m_test3 ); + CPPUNIT_ASSERT( m_test3 == m_path->getChildTest() ); +} + + +void +TestPathTest::testGetChildTestThrowIfNotValid() +{ + m_path->getChildTest(); +} + + +void +TestPathTest::testAddPath() +{ + CppUnit::TestPath path; + path.add( m_test2 ); + path.add( m_test3 ); + + m_path->add( m_test1 ); + m_path->add( path ); + + CPPUNIT_ASSERT_EQUAL( 3, m_path->getTestCount() ); + CPPUNIT_ASSERT( m_test1 == m_path->getTestAt(0) ); + CPPUNIT_ASSERT( m_test2 == m_path->getTestAt(1) ); + CPPUNIT_ASSERT( m_test3 == m_path->getTestAt(2) ); +} + + +void +TestPathTest::testAddInvalidPath() +{ + CppUnit::TestPath path; + m_path->add( path ); + + CPPUNIT_ASSERT( !m_path->isValid() ); +} + + +void +TestPathTest::testRemoveTests() +{ + m_path->add( m_test1 ); + m_path->add( m_test2 ); + + m_path->removeTests(); + + CPPUNIT_ASSERT( !m_path->isValid() ); +} + + +void +TestPathTest::testRemoveTest() +{ + m_path->add( m_test1 ); + m_path->add( m_test2 ); + + m_path->removeTest( 0 ); + + CPPUNIT_ASSERT_EQUAL( 1, m_path->getTestCount() ); + CPPUNIT_ASSERT( m_test2 == m_path->getTestAt(0) ); +} + + +void +TestPathTest::testRemoveTestThrow1() +{ + m_path->removeTest( -1 ); +} + + +void +TestPathTest::testRemoveTestThrow2() +{ + m_path->add( m_test1 ); + + m_path->removeTest( 1 ); +} + + +void +TestPathTest::testUp() +{ + m_path->add( m_test1 ); + + m_path->up(); + + CPPUNIT_ASSERT( !m_path->isValid() ); +} + + +void +TestPathTest::testUpThrow() +{ + m_path->up(); +} + + +void +TestPathTest::testInsert() +{ + m_path->add( m_test1 ); + + m_path->insert( m_test2, 0 ); + + CPPUNIT_ASSERT_EQUAL( 2, m_path->getTestCount() ); + CPPUNIT_ASSERT( m_test2 == m_path->getTestAt(0) ); + CPPUNIT_ASSERT( m_test1 == m_path->getTestAt(1) ); +} + + +void +TestPathTest::testInsertAtEnd() +{ + m_path->add( m_test1 ); + + m_path->insert( m_test2, 1 ); + + CPPUNIT_ASSERT_EQUAL( 2, m_path->getTestCount() ); + CPPUNIT_ASSERT( m_test1 == m_path->getTestAt(0) ); + CPPUNIT_ASSERT( m_test2 == m_path->getTestAt(1) ); +} + + +void +TestPathTest::testInsertThrow1() +{ + m_path->insert( m_test1, -1 ); +} + + +void +TestPathTest::testInsertThrow2() +{ + m_path->add( m_test1 ); + + m_path->insert( m_test1, 2 ); +} + + +void +TestPathTest::testInsertPath() +{ + CppUnit::TestPath path; + path.add( m_test2 ); + path.add( m_test3 ); + + m_path->add( m_test1 ); + m_path->add( m_test4 ); + m_path->insert( path, 1 ); + + CPPUNIT_ASSERT_EQUAL( 4, m_path->getTestCount() ); + CPPUNIT_ASSERT( m_test1 == m_path->getTestAt(0) ); + CPPUNIT_ASSERT( m_test2 == m_path->getTestAt(1) ); + CPPUNIT_ASSERT( m_test3 == m_path->getTestAt(2) ); + CPPUNIT_ASSERT( m_test4 == m_path->getTestAt(3) ); +} + + +void +TestPathTest::testInsertPathThrow() +{ + CppUnit::TestPath path; + path.add( m_test2 ); + + m_path->insert( path, 1 ); +} + + +void +TestPathTest::testInsertPathDontThrowIfInvalid() +{ + CppUnit::TestPath path; + m_path->insert( path, 1 ); +} + + +void +TestPathTest::testRootConstructor() +{ + CppUnit::TestPath path( m_test1 ); + CPPUNIT_ASSERT( path.isValid() ); + CPPUNIT_ASSERT_EQUAL( 1, path.getTestCount() ); + CPPUNIT_ASSERT( m_test1 == path.getTestAt(0) ); +} + + +void +TestPathTest::testPathSliceConstructorCopyUntilEnd() +{ + m_path->add( m_test1 ); + m_path->add( m_test2 ); + m_path->add( m_test3 ); + + CppUnit::TestPath path( *m_path, 1 ); + + CPPUNIT_ASSERT_EQUAL( 2, path.getTestCount() ); + CPPUNIT_ASSERT( m_test2 == path.getTestAt(0) ); + CPPUNIT_ASSERT( m_test3 == path.getTestAt(1) ); +} + + +void +TestPathTest::testPathSliceConstructorCopySpecifiedCount() +{ + m_path->add( m_test1 ); + m_path->add( m_test2 ); + m_path->add( m_test3 ); + + CppUnit::TestPath path( *m_path, 0, 1 ); + + CPPUNIT_ASSERT_EQUAL( 1, path.getTestCount() ); + CPPUNIT_ASSERT( m_test1 == path.getTestAt(0) ); +} + + +void +TestPathTest::testPathSliceConstructorCopyNone() +{ + m_path->add( m_test1 ); + + CppUnit::TestPath path( *m_path, 0, 0 ); + CPPUNIT_ASSERT_EQUAL( 0, path.getTestCount() ); +} + + +void +TestPathTest::testPathSliceConstructorNegativeIndex() +{ + m_path->add( m_test1 ); + m_path->add( m_test2 ); + + CppUnit::TestPath path( *m_path, -1, 2 ); + + CPPUNIT_ASSERT_EQUAL( 1, path.getTestCount() ); + CPPUNIT_ASSERT( m_test1 == path.getTestAt(0) ); +} + + +void +TestPathTest::testPathSliceConstructorAfterEndIndex() +{ + m_path->add( m_test1 ); + m_path->add( m_test2 ); + + CppUnit::TestPath path( *m_path, 2, 5 ); + + CPPUNIT_ASSERT_EQUAL( 0, path.getTestCount() ); +} + + +void +TestPathTest::testPathSliceConstructorNegativeIndexUntilEnd() +{ + m_path->add( m_test1 ); + m_path->add( m_test2 ); + + CppUnit::TestPath path( *m_path, -1 ); + + CPPUNIT_ASSERT_EQUAL( 2, path.getTestCount() ); + CPPUNIT_ASSERT( m_test1 == path.getTestAt(0) ); + CPPUNIT_ASSERT( m_test2 == path.getTestAt(1) ); +} + + +void +TestPathTest::testPathSliceConstructorNegativeIndexNone() +{ + m_path->add( m_test1 ); + m_path->add( m_test2 ); + + CppUnit::TestPath path( *m_path, -2, 1 ); + + CPPUNIT_ASSERT_EQUAL( 0, path.getTestCount() ); +} + + +void +TestPathTest::testToStringNoTest() +{ + std::string expected = "/"; + std::string actual = m_path->toString(); + + CPPUNIT_ASSERT_EQUAL( expected, actual ); +} + + +void +TestPathTest::testToStringOneTest() +{ + m_path->add( m_test1 ); + + std::string expected = "/test1"; + std::string actual = m_path->toString(); + + CPPUNIT_ASSERT_EQUAL( expected, actual ); +} + + +void +TestPathTest::testToStringHierarchy() +{ + m_path->add( m_suite1 ); + m_path->add( m_suite2 ); + m_path->add( m_suite2->getChildTestAt(0) ); + + std::string expected = "/All Tests/Custom/MyTest::testDefaultConstructor"; + std::string actual = m_path->toString(); + + CPPUNIT_ASSERT_EQUAL( expected, actual ); +} + + +void +TestPathTest::testPathStringConstructorRoot() +{ + CppUnit::TestPath path( m_suite1, "/All Tests" ); + + CPPUNIT_ASSERT_EQUAL( 1, path.getTestCount() ); + CPPUNIT_ASSERT( m_suite1 == path.getTestAt(0) ); +} + + +void +TestPathTest::testPathStringConstructorEmptyIsRoot() +{ + CppUnit::TestPath path( m_suite1, "" ); + + CPPUNIT_ASSERT_EQUAL( 1, path.getTestCount() ); + CPPUNIT_ASSERT( m_suite1 == path.getTestAt(0) ); +} + + +void +TestPathTest::testPathStringConstructorHierarchy() +{ + CppUnit::TestPath path( m_suite1, "/All Tests/Custom/MyTest::testDefaultConstructor" ); + + CPPUNIT_ASSERT_EQUAL( 3, path.getTestCount() ); + CPPUNIT_ASSERT( m_suite1 == path.getTestAt(0) ); + CPPUNIT_ASSERT( m_suite2 == path.getTestAt(1) ); + CPPUNIT_ASSERT( m_testSuite2a == path.getTestAt(2) ); +} + + +void +TestPathTest::testPathStringConstructorBadRootThrow() +{ + CppUnit::TestPath path( m_suite1, "/Custom" ); +} + + +void +TestPathTest::testPathStringConstructorRelativeRoot() +{ + CppUnit::TestPath path( m_suite1, "All Tests" ); + + CPPUNIT_ASSERT_EQUAL( 1, path.getTestCount() ); + CPPUNIT_ASSERT( m_suite1 == path.getTestAt(0) ); +} + + +void +TestPathTest::testPathStringConstructorRelativeRoot2() +{ + CppUnit::TestPath path( m_suite1, "Custom" ); + + CPPUNIT_ASSERT_EQUAL( 1, path.getTestCount() ); + CPPUNIT_ASSERT( m_suite2 == path.getTestAt(0) ); +} + + +void +TestPathTest::testPathStringConstructorThrow1() +{ + CppUnit::TestPath path( m_suite1, "/" ); +} + + +void +TestPathTest::testPathStringConstructorRelativeHierarchy() +{ + CppUnit::TestPath path( m_suite1, "Custom/MyTest::testConstructor" ); + + CPPUNIT_ASSERT_EQUAL( 2, path.getTestCount() ); + CPPUNIT_ASSERT( m_suite2 == path.getTestAt(0) ); + CPPUNIT_ASSERT( m_testSuite2b == path.getTestAt(1) ); +} + + +void +TestPathTest::testPathStringConstructorBadRelativeHierarchyThrow() +{ + CppUnit::TestPath path( m_suite1, "Custom/MyBadTest::testConstructor" ); +} -- cgit v1.2.1