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. --- src/cppunit/XmlOutputter.cpp | 74 +++++++++++++++++++++++++++++++------------- 1 file changed, 53 insertions(+), 21 deletions(-) (limited to 'src/cppunit/XmlOutputter.cpp') diff --git a/src/cppunit/XmlOutputter.cpp b/src/cppunit/XmlOutputter.cpp index 42e6b32..9fc59f7 100644 --- a/src/cppunit/XmlOutputter.cpp +++ b/src/cppunit/XmlOutputter.cpp @@ -3,9 +3,11 @@ #include #include #include +#include #include #include #include +#include namespace CppUnit @@ -38,6 +40,20 @@ XmlOutputter::~XmlOutputter() } +void +XmlOutputter::addHook( XmlOutputterHook *hook ) +{ + m_hooks.push_back( hook ); +} + + +void +XmlOutputter::removeHook( XmlOutputterHook *hook ) +{ + m_hooks.erase( std::find( m_hooks.begin(), m_hooks.end(), hook ) ); +} + + void XmlOutputter::write() { @@ -58,6 +74,9 @@ XmlOutputter::makeRootNode() { XmlElement *rootNode = new XmlElement( "TestRun" ); + for ( Hooks::const_iterator it = m_hooks.begin(); it != m_hooks.end(); ++it ) + (*it)->beginDocument( m_xml, rootNode ); + FailedTests failedTests; fillFailedTestsMap( failedTests ); @@ -65,6 +84,9 @@ XmlOutputter::makeRootNode() addSuccessfulTests( failedTests, rootNode ); addStatistics( rootNode ); + for ( Hooks::const_iterator itEnd = m_hooks.begin(); itEnd != m_hooks.end(); ++itEnd ) + (*itEnd)->endDocument( m_xml, rootNode ); + return rootNode; } @@ -87,7 +109,7 @@ XmlOutputter::addFailedTests( FailedTests &failedTests, XmlElement *rootNode ) { XmlElement *testsNode = new XmlElement( "FailedTests" ); - rootNode->addNode( testsNode ); + rootNode->addElement( testsNode ); const TestResultCollector::Tests &tests = m_result->tests(); for ( int testNumber = 0; testNumber < tests.size(); ++testNumber ) @@ -104,7 +126,7 @@ XmlOutputter::addSuccessfulTests( FailedTests &failedTests, XmlElement *rootNode ) { XmlElement *testsNode = new XmlElement( "SuccessfulTests" ); - rootNode->addNode( testsNode ); + rootNode->addElement( testsNode ); const TestResultCollector::Tests &tests = m_result->tests(); for ( int testNumber = 0; testNumber < tests.size(); ++testNumber ) @@ -120,12 +142,15 @@ void XmlOutputter::addStatistics( XmlElement *rootNode ) { XmlElement *statisticsNode = new XmlElement( "Statistics" ); - rootNode->addNode( statisticsNode ); - statisticsNode->addNode( new XmlElement( "Tests", m_result->runTests() ) ); - statisticsNode->addNode( new XmlElement( "FailuresTotal", - m_result->testFailuresTotal() ) ); - statisticsNode->addNode( new XmlElement( "Errors", m_result->testErrors() ) ); - statisticsNode->addNode( new XmlElement( "Failures", m_result->testFailures() ) ); + rootNode->addElement( statisticsNode ); + statisticsNode->addElement( new XmlElement( "Tests", m_result->runTests() ) ); + statisticsNode->addElement( new XmlElement( "FailuresTotal", + m_result->testFailuresTotal() ) ); + statisticsNode->addElement( new XmlElement( "Errors", m_result->testErrors() ) ); + statisticsNode->addElement( new XmlElement( "Failures", m_result->testFailures() ) ); + + for ( Hooks::const_iterator it = m_hooks.begin(); it != m_hooks.end(); ++it ) + (*it)->statisticsAdded( m_xml, statisticsNode ); } @@ -138,40 +163,47 @@ XmlOutputter::addFailedTest( Test *test, Exception *thrownException = failure->thrownException(); XmlElement *testNode = new XmlElement( "FailedTest" ); - testsNode->addNode( testNode ); + testsNode->addElement( testNode ); testNode->addAttribute( "id", testNumber ); - testNode->addNode( new XmlElement( "Name", test->getName() ) ); - testNode->addNode( new XmlElement( "FailureType", - failure->isError() ? "Error" : "Assertion" ) ); + testNode->addElement( new XmlElement( "Name", test->getName() ) ); + testNode->addElement( new XmlElement( "FailureType", + failure->isError() ? "Error" : + "Assertion" ) ); if ( failure->sourceLine().isValid() ) addFailureLocation( failure, testNode ); - testNode->addNode( new XmlElement( "Message", thrownException->what() ) ); + testNode->addElement( new XmlElement( "Message", thrownException->what() ) ); + + for ( Hooks::const_iterator it = m_hooks.begin(); it != m_hooks.end(); ++it ) + (*it)->failTestAdded( m_xml, testNode, test, failure ); } void XmlOutputter::addFailureLocation( TestFailure *failure, - XmlElement *testNode ) + XmlElement *testNode ) { XmlElement *locationNode = new XmlElement( "Location" ); - testNode->addNode( locationNode ); + testNode->addElement( locationNode ); SourceLine sourceLine = failure->sourceLine(); - locationNode->addNode( new XmlElement( "File", sourceLine.fileName() ) ); - locationNode->addNode( new XmlElement( "Line", sourceLine.lineNumber() ) ); + locationNode->addElement( new XmlElement( "File", sourceLine.fileName() ) ); + locationNode->addElement( new XmlElement( "Line", sourceLine.lineNumber() ) ); } void XmlOutputter::addSuccessfulTest( Test *test, - int testNumber, - XmlElement *testsNode ) + int testNumber, + XmlElement *testsNode ) { XmlElement *testNode = new XmlElement( "Test" ); - testsNode->addNode( testNode ); + testsNode->addElement( testNode ); testNode->addAttribute( "id", testNumber ); - testNode->addNode( new XmlElement( "Name", test->getName() ) ); + testNode->addElement( new XmlElement( "Name", test->getName() ) ); + + for ( Hooks::const_iterator it = m_hooks.begin(); it != m_hooks.end(); ++it ) + (*it)->successfulTestAdded( m_xml, testNode, test ); } -- cgit v1.2.1