From 73a038f1eaa268cec330d971fb550befec6f7798 Mon Sep 17 00:00:00 2001 From: Baptiste Lepilleur Date: Fri, 14 Jun 2002 19:21:01 +0000 Subject: 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. --- examples/cppunittest/XmlElementTest.cpp | 116 +++++++++++++++++++++++++++++++- 1 file changed, 113 insertions(+), 3 deletions(-) (limited to 'examples/cppunittest/XmlElementTest.cpp') 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 @@ -30,6 +30,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() { @@ -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 = "" ""; 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 = "content"; CPPUNITTEST_ASSERT_XML_EQUAL( expectedXml, node.toString() ); } -- cgit v1.2.1