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 /src/cppunit/XmlElement.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 'src/cppunit/XmlElement.cpp')
| -rw-r--r-- | src/cppunit/XmlElement.cpp | 86 |
1 files changed, 74 insertions, 12 deletions
diff --git a/src/cppunit/XmlElement.cpp b/src/cppunit/XmlElement.cpp index 4a01405..be06941 100644 --- a/src/cppunit/XmlElement.cpp +++ b/src/cppunit/XmlElement.cpp @@ -1,3 +1,4 @@ +#include <cppunit/tools/StringTools.h> #include <cppunit/tools/XmlElement.h> @@ -17,7 +18,7 @@ XmlElement::XmlElement( std::string elementName, int numericContent ) : m_name( elementName ) { - m_content = asString( numericContent ); + setContent( numericContent ); } @@ -25,7 +26,45 @@ XmlElement::~XmlElement() { Elements::iterator itNode = m_elements.begin(); while ( itNode != m_elements.end() ) + { + XmlElement *element = *itNode; delete *itNode++; + } +} + + +std::string +XmlElement::name() const +{ + return m_name; +} + + +std::string +XmlElement::content() const +{ + return m_content; +} + + +void +XmlElement::setName( const std::string &name ) +{ + m_name = name; +} + + +void +XmlElement::setContent( const std::string &content ) +{ + m_content = content; +} + + +void +XmlElement::setContent( int numericContent ) +{ + m_content = StringTools::toString( numericContent ); } @@ -41,17 +80,49 @@ void XmlElement::addAttribute( std::string attributeName, int numericValue ) { - addAttribute( attributeName, asString( numericValue ) ); + addAttribute( attributeName, StringTools::toString( numericValue ) ); } void -XmlElement::addNode( XmlElement *node ) +XmlElement::addElement( XmlElement *node ) { m_elements.push_back( node ); } +int +XmlElement::elementCount() const +{ + return m_elements.size(); +} + + +XmlElement * +XmlElement::elementAt( int index ) const +{ + if ( index < 0 || index >= elementCount() ) + throw std::invalid_argument( "XmlElement::elementAt(), out of range index" ); + + return m_elements[ index ]; +} + + +XmlElement * +XmlElement::elementFor( const std::string &name ) const +{ + Elements::const_iterator itElement = m_elements.begin(); + for ( ; itElement != m_elements.end(); ++itElement ) + { + if ( (*itElement)->name() == name ) + return *itElement; + } + + throw std::invalid_argument( "XmlElement::elementFor(), not matching child element found" ); + return NULL; // make some compilers happy. +} + + std::string XmlElement::toString( const std::string &indent ) const { @@ -147,15 +218,6 @@ XmlElement::escape( std::string value ) const return escaped; } -// should be somewhere else... Future CppUnit::String ? -std::string -XmlElement::asString( int value ) -{ - OStringStream stream; - stream << value; - return stream.str(); -} - } // namespace CppUnit |
