diff options
| author | Baptiste Lepilleur <gaiacrtn@free.fr> | 2002-06-14 19:21:01 +0000 |
|---|---|---|
| committer | Baptiste Lepilleur <gaiacrtn@free.fr> | 2002-06-14 19:21:01 +0000 |
| commit | 73a038f1eaa268cec330d971fb550befec6f7798 (patch) | |
| tree | c3eba5d793e37413889acad5b0b9f70caf89b0f6 /examples/cppunittest | |
| parent | f39e160fba25476de7d41e2f19d756db7ee76dc7 (diff) | |
| download | cppunit-73a038f1eaa268cec330d971fb550befec6f7798.tar.gz | |
Include/cppunit/plugin/PlugInManager.
include/cppunit/plugin/PlugInManager.h:
* src/cppunit/PlugInManager.cpp: added two methods to use the plug-in
interface for Xml Outputter hooks.
* include/cppunit/plugin/TestPlugIn.h: added two methods to the plug-in
interface for Xml Outputter hooks.
* include/cppunit/plugin/TestPlugInAdapter.h:
* src/cppunit/plugin/TestPlugInAdapter.cpp: renamed TestPlugInDefaultImpl.
Added empty implementation for Xml outputter hook methods.
* include/cppunit/tools/StringTools.h:
* src/cppunit/tools/StringTools.cpp: added. Functions to manipulate string
(conversion, wrapping...)
* include/cppunit/tools/XmlElement.h:
* src/cppunit/XmlElement.cpp: renamed addNode() to addElement(). Added
methods to walk and modify XmlElement (for hook). Added documentation.
Use StringTools.
* include/cppunit/XmlOutputter.h:
* src/cppunit/XmlOutputter.cpp: added hook calls & management.
* include/cppunit/XmlOutputterHook.h:
* src/cppunit/XmlOutputterHook.cpp: added. Hook to customize XML output.
* src/DllPlugInTester/DllPlugInTester.cpp: call plug-in XmlOutputterHook
when writing XML output. Modified so that memory is freed before
unloading the test plug-in (caused crash when freeing the XmlDocument).
* examples/ReadMe.txt:
* examples/ClockerPlugIn/ReadMe.txt: added details about the plug-in
(usage, xml content...)
* examples/ClockerPlugIn/ClockerModel.h:
* examples/ClockerPlugIn/ClockerModel.cpp: extracted from ClockerListener.
Represents the test hierarchy and tracked time for each test.
* examples/ClockerPlugIn/ClockerListener.h:
* examples/ClockerPlugIn/ClockerListener.cpp: extracted test hierarchy
tracking to ClockerModel. Replaced the 'flat' view option with a 'text'
option to print the timed test tree to stdout.
* examples/ClockerPlugIn/ClockerPlugIn.cpp: updated to hook the XML
output and use the new classes.
* examples/ClockerPlugIn/ClockerXmlHook.h:
* examples/ClockerPlugIn/ClockerXmlHook.cpp: added. XmlOutputterHook to
includes the timed test hierarchy and test timing in the XML output.
* examples/cppunittest/XmlElementTest.h:
* examples/cppunittest/XmlElementTest.cpp: added new test cases.
* examples/cppunittest/XmlOutputterTest.h:
* examples/cppunittest/XmlOutputterTest.cpp: added tests for
XmlOutputterHook.
Diffstat (limited to 'examples/cppunittest')
| -rw-r--r-- | examples/cppunittest/XmlElementTest.cpp | 116 | ||||
| -rw-r--r-- | examples/cppunittest/XmlElementTest.h | 24 | ||||
| -rw-r--r-- | examples/cppunittest/XmlOutputterTest.cpp | 85 | ||||
| -rw-r--r-- | examples/cppunittest/XmlOutputterTest.h | 5 |
4 files changed, 227 insertions, 3 deletions
diff --git a/examples/cppunittest/XmlElementTest.cpp b/examples/cppunittest/XmlElementTest.cpp index e460458..26a0778 100644 --- a/examples/cppunittest/XmlElementTest.cpp +++ b/examples/cppunittest/XmlElementTest.cpp @@ -31,6 +31,116 @@ XmlElementTest::tearDown() void +XmlElementTest::testStringContentConstructor() +{ + CppUnit::XmlElement element( "aName", "someContent" ); + CPPUNIT_ASSERT_EQUAL( std::string("aName"), element.name() ); + CPPUNIT_ASSERT_EQUAL( std::string("someContent"), element.content() ); +} + + +void +XmlElementTest::testNumericContentConstructor() +{ + CppUnit::XmlElement element( "numericName", 123456789 ); + CPPUNIT_ASSERT_EQUAL( std::string("numericName"), element.name() ); + CPPUNIT_ASSERT_EQUAL( std::string("123456789"), element.content() ); +} + + +void +XmlElementTest::testSetName() +{ + CppUnit::XmlElement element( "aName" ); + element.setName( "anotherName" ); + CPPUNIT_ASSERT_EQUAL( std::string("anotherName"), element.name() ); +} + + +void +XmlElementTest::testSetStringContent() +{ + CppUnit::XmlElement element( "aName", "someContent" ); + element.setContent( "other" ); + CPPUNIT_ASSERT_EQUAL( std::string("other"), element.content() ); +} + + +void +XmlElementTest::testSetNumericContent() +{ + CppUnit::XmlElement element( "aName", "someContent" ); + element.setContent( 87654321 ); + CPPUNIT_ASSERT_EQUAL( std::string("87654321"), element.content() ); +} + + +void +XmlElementTest::testNodeCount() +{ + CppUnit::XmlElement node( "element", "content" ); + CPPUNIT_ASSERT_EQUAL( 0, node.elementCount() ); + + node.addElement( new CppUnit::XmlElement( "child1" ) ); + node.addElement( new CppUnit::XmlElement( "child2" ) ); + CPPUNIT_ASSERT_EQUAL( 2, node.elementCount() ); +} + + +void +XmlElementTest::testElementAtNegativeIndexThrow() +{ + CppUnit::XmlElement node( "element" ); + node.elementAt( -1 ); +} + + +void +XmlElementTest::testElementAtTooLargeIndexThrow() +{ + CppUnit::XmlElement node( "element" ); + node.elementAt( 0 ); +} + + +void +XmlElementTest::testElementAt() +{ + CppUnit::XmlElement node( "element" ); + CppUnit::XmlElement *element1 = new CppUnit::XmlElement( "element1" ); + CppUnit::XmlElement *element2 = new CppUnit::XmlElement( "element2" ); + node.addElement( element1 ); + node.addElement( element2 ); + + CPPUNIT_ASSERT( element1 == node.elementAt(0) ); + CPPUNIT_ASSERT( element2 == node.elementAt(1) ); +} + + +void +XmlElementTest::testElementForThrow() +{ + CppUnit::XmlElement node( "element" ); + node.addElement( new CppUnit::XmlElement( "element1" ) ); + node.elementFor( "name2" ); +} + + +void +XmlElementTest::testElementFor() +{ + CppUnit::XmlElement node( "element" ); + CppUnit::XmlElement *element1 = new CppUnit::XmlElement( "element1" ); + CppUnit::XmlElement *element2 = new CppUnit::XmlElement( "element2" ); + node.addElement( element1 ); + node.addElement( element2 ); + + CPPUNIT_ASSERT( element2 == node.elementFor( "element2" ) ); + CPPUNIT_ASSERT( element1 == node.elementFor( "element1" ) ); +} + + +void XmlElementTest::testEmptyNodeToString() { CppUnit::XmlElement node( "element" ); @@ -79,8 +189,8 @@ void XmlElementTest::testNodeWithChildrenToString() { CppUnit::XmlElement node( "element" ); - node.addNode( new CppUnit::XmlElement( "child1" ) ); - node.addNode( new CppUnit::XmlElement( "child2" ) ); + node.addElement( new CppUnit::XmlElement( "child1" ) ); + node.addElement( new CppUnit::XmlElement( "child2" ) ); std::string expectedXml = "<element><child1></child1>" "<child2></child2></element>"; CPPUNITTEST_ASSERT_XML_EQUAL( expectedXml, node.toString() ); @@ -109,7 +219,7 @@ void XmlElementTest::testNodeWithContentAndChildToString() { CppUnit::XmlElement node( "element", "content" ); - node.addNode( new CppUnit::XmlElement( "child1" ) ); + node.addElement( new CppUnit::XmlElement( "child1" ) ); std::string expectedXml = "<element><child1></child1>content</element>"; CPPUNITTEST_ASSERT_XML_EQUAL( expectedXml, node.toString() ); } diff --git a/examples/cppunittest/XmlElementTest.h b/examples/cppunittest/XmlElementTest.h index 5b24822..e4f4875 100644 --- a/examples/cppunittest/XmlElementTest.h +++ b/examples/cppunittest/XmlElementTest.h @@ -9,6 +9,18 @@ class XmlElementTest : public CppUnit::TestFixture { CPPUNIT_TEST_SUITE( XmlElementTest ); + CPPUNIT_TEST( testStringContentConstructor ); + CPPUNIT_TEST( testNumericContentConstructor ); + CPPUNIT_TEST( testSetName ); + CPPUNIT_TEST( testSetStringContent ); + CPPUNIT_TEST( testSetNumericContent ); + CPPUNIT_TEST( testNodeCount ); + CPPUNIT_TEST_EXCEPTION( testElementAtNegativeIndexThrow, std::invalid_argument ); + CPPUNIT_TEST_EXCEPTION( testElementAtTooLargeIndexThrow, std::invalid_argument ); + CPPUNIT_TEST( testElementAt ); + CPPUNIT_TEST_EXCEPTION( testElementForThrow, std::invalid_argument ); + CPPUNIT_TEST( testElementFor ); + CPPUNIT_TEST( testEmptyNodeToString ); CPPUNIT_TEST( testNodeWithAttributesToString ); CPPUNIT_TEST( testEscapedAttributeValueToString ); @@ -30,6 +42,18 @@ public: void setUp(); void tearDown(); + void testStringContentConstructor(); + void testNumericContentConstructor(); + void testSetName(); + void testSetStringContent(); + void testSetNumericContent(); + void testNodeCount(); + void testElementAtNegativeIndexThrow(); + void testElementAtTooLargeIndexThrow(); + void testElementAt(); + void testElementForThrow(); + void testElementFor(); + void testEmptyNodeToString(); void testNodeWithAttributesToString(); void testEscapedAttributeValueToString(); diff --git a/examples/cppunittest/XmlOutputterTest.cpp b/examples/cppunittest/XmlOutputterTest.cpp index 6e08d7d..84a1719 100644 --- a/examples/cppunittest/XmlOutputterTest.cpp +++ b/examples/cppunittest/XmlOutputterTest.cpp @@ -1,6 +1,7 @@ #include <cppunit/XmlOutputter.h> #include <cppunit/TestFailure.h> #include <cppunit/XmlOutputter.h> +#include <cppunit/XmlOutputterHook.h> #include "OutputSuite.h" #include "XmlOutputterTest.h" #include "XmlUniformiser.h" @@ -220,6 +221,89 @@ XmlOutputterTest::testWriteXmlResultWithThreeFailureTwoErrorsAndTwoSuccess() } +class XmlOutputterTest::MockHook : public CppUnit::XmlOutputterHook +{ +public: + MockHook( int &beginCalls, + int &endCalls, + int &statisticsCalls, + int &successfulTestCalls, + int &failedTestCalls ) + : m_successfulTestCalls( successfulTestCalls ) + , m_failedTestCalls( failedTestCalls ) + , m_beginCalls( beginCalls ) + , m_endCalls( endCalls ) + , m_statisticsCalls( statisticsCalls ) + { + } + + void beginDocument( CppUnit::XmlDocument *document, + CppUnit::XmlElement *rootNode ) + { + ++m_beginCalls; + } + + void endDocument( CppUnit::XmlDocument *document, + CppUnit::XmlElement *rootNode ) + { + ++m_endCalls; + } + + void failTestAdded( CppUnit::XmlDocument *document, + CppUnit::XmlElement *testNode, + CppUnit::Test *test, + CppUnit::TestFailure *failure ) + { + ++m_failedTestCalls; + } + + void successfulTestAdded( CppUnit::XmlDocument *document, + CppUnit::XmlElement *testNode, + CppUnit::Test *test ) + { + ++m_successfulTestCalls; + } + + void statisticsAdded( CppUnit::XmlDocument *document, + CppUnit::XmlElement *statisticsNode ) + { + ++m_statisticsCalls; + } + +private: + int &m_beginCalls; + int &m_endCalls; + int &m_statisticsCalls; + int &m_successfulTestCalls; + int &m_failedTestCalls; +}; + + +void +XmlOutputterTest::testHook() +{ + int begin =0, end =0, statistics =0, successful =0, failed =0; + MockHook hook( begin, end, statistics, successful, failed ); + + addTest( "test1" ); + addTest( "test2" ); + addTest( "test3" ); + addTestFailure( "testfail1", "assertion failed" ); + addTestError( "testerror1", "exception" ); + + CppUnit::OStringStream stream; + CppUnit::XmlOutputter outputter( m_result, stream ); + outputter.addHook( &hook ); + outputter.write(); + + CPPUNIT_ASSERT_EQUAL( 1, begin ); + CPPUNIT_ASSERT_EQUAL( 1, end ); + CPPUNIT_ASSERT_EQUAL( 1, statistics ); + CPPUNIT_ASSERT_EQUAL( 3, successful ); + CPPUNIT_ASSERT_EQUAL( 2, failed ); +} + + void XmlOutputterTest::addTest( std::string testName ) { @@ -270,3 +354,4 @@ XmlOutputterTest::makeDummyTest( std::string testName ) m_dummyTests.push_back( test ); return test; } + diff --git a/examples/cppunittest/XmlOutputterTest.h b/examples/cppunittest/XmlOutputterTest.h index 9f155e2..a1600ee 100644 --- a/examples/cppunittest/XmlOutputterTest.h +++ b/examples/cppunittest/XmlOutputterTest.h @@ -19,6 +19,7 @@ class XmlOutputterTest : public CppUnit::TestFixture CPPUNIT_TEST( testWriteXmlResultWithOneError ); CPPUNIT_TEST( testWriteXmlResultWithOneSuccess ); CPPUNIT_TEST( testWriteXmlResultWithThreeFailureTwoErrorsAndTwoSuccess ); + CPPUNIT_TEST( testHook ); CPPUNIT_TEST_SUITE_END(); public: @@ -37,7 +38,11 @@ public: void testWriteXmlResultWithOneSuccess(); void testWriteXmlResultWithThreeFailureTwoErrorsAndTwoSuccess(); + void testHook(); + private: + class MockHook; + /// Prevents the use of the copy constructor. XmlOutputterTest( const XmlOutputterTest © ); |
