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/ClockerPlugIn/ClockerXmlHook.cpp | |
| 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/ClockerPlugIn/ClockerXmlHook.cpp')
| -rw-r--r-- | examples/ClockerPlugIn/ClockerXmlHook.cpp | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/examples/ClockerPlugIn/ClockerXmlHook.cpp b/examples/ClockerPlugIn/ClockerXmlHook.cpp new file mode 100644 index 0000000..445b868 --- /dev/null +++ b/examples/ClockerPlugIn/ClockerXmlHook.cpp @@ -0,0 +1,94 @@ +// ////////////////////////////////////////////////////////////////////////// +// Implementation file ClockerXmlHook.cpp for class ClockerXmlHook +// (c)Copyright 2000, Baptiste Lepilleur. +// Created: 2002/06/14 +// ////////////////////////////////////////////////////////////////////////// + +#include <cppunit/Test.h> +#include <cppunit/tools/XmlElement.h> +#include "ClockerModel.h" +#include "ClockerXmlHook.h" + + +ClockerXmlHook::ClockerXmlHook( ClockerModel *model ) + : m_model( model ) +{ +} + + +ClockerXmlHook::~ClockerXmlHook() +{ +} + + +void +ClockerXmlHook::endDocument( CppUnit::XmlDocument *document, + CppUnit::XmlElement *rootNode ) +{ + CppUnit::XmlElement *testTreeElement = new CppUnit::XmlElement( "TimedTestTree" ); + rootNode->addElement( testTreeElement ); + + addTimedTest( testTreeElement, 0 ); +} + + +void +ClockerXmlHook::addTimedTest( CppUnit::XmlElement *parentElement, + int testIndex ) +{ + std::string elementName = m_model->isSuite( testIndex ) ? "TimedSuite" : "TimedTest"; + CppUnit::XmlElement *testElement = new CppUnit::XmlElement( elementName ); + parentElement->addElement( testElement ); + testElement->addAttribute( "id", testIndex ); + + const CppUnit::TestPath &path = m_model->testPathFor( testIndex ); + testElement->addElement( new CppUnit::XmlElement( "Name", + path.getChildTest()->getName() ) ); + testElement->addElement( new CppUnit::XmlElement( "TestPath", path.toString() ) ); + testElement->addElement( new CppUnit::XmlElement( "Time", + ClockerModel::timeStringFor( + m_model->testTimeFor( testIndex ) ) ) ); + + if ( m_model->isSuite( testIndex ) ) + { + for ( int childIndex =0; childIndex < m_model->childCountFor( testIndex ); ++childIndex ) + addTimedTest( testElement, m_model->childAtFor( testIndex, childIndex ) ); + } +} + + +void +ClockerXmlHook::failTestAdded( CppUnit::XmlDocument *document, + CppUnit::XmlElement *testNode, + CppUnit::Test *test, + CppUnit::TestFailure *failure ) +{ + successfulTestAdded( document, testNode, test ); +} + + +void +ClockerXmlHook::successfulTestAdded( CppUnit::XmlDocument *document, + CppUnit::XmlElement *testNode, + CppUnit::Test *test ) +{ + int testIndex = m_model->indexOf( test ); + double time = (testIndex >= 0) ? m_model->testTimeFor( testIndex ) : 0.0; + const CppUnit::TestPath &path = m_model->testPathFor( testIndex ); + testNode->addElement( new CppUnit::XmlElement( "TestPath", path.toString() ) ); + testNode->addElement( new CppUnit::XmlElement( "Time", + ClockerModel::timeStringFor( time ) ) ); +} + + +void +ClockerXmlHook::statisticsAdded( CppUnit::XmlDocument *document, + CppUnit::XmlElement *statisticsNode ) +{ + statisticsNode->addElement( + new CppUnit::XmlElement( "TotalElapsedTime", + ClockerModel::timeStringFor( m_model->totalElapsedTime() ) ) ); + statisticsNode->addElement( + new CppUnit::XmlElement( "AverageTestCaseTime", + ClockerModel::timeStringFor( m_model->averageTestCaseTime() ) ) ); +} |
