diff options
| author | Baptiste Lepilleur <gaiacrtn@free.fr> | 2002-05-23 17:38:39 +0000 |
|---|---|---|
| committer | Baptiste Lepilleur <gaiacrtn@free.fr> | 2002-05-23 17:38:39 +0000 |
| commit | 5ad4640702a80078748b38ebaeda37e69dce1189 (patch) | |
| tree | 9d1ecf8d28f0e9397c2f90565d96ccda6d08b98e /include/cppunit | |
| parent | 7edd0684368ed3c43fe2707d1d34d6b7590d9fd6 (diff) | |
| download | cppunit-5ad4640702a80078748b38ebaeda37e69dce1189.tar.gz | |
Include/cppunit/XmlOutputter.
include/cppunit/XmlOutputter.h:
* src/cppunit/XmlOutputter.cpp: extracted class XmlOutputter::Node to
XmlElement. Extracted xml 'prolog' generation to XmlDocument.
* include/cppunit/tools/XmlElement.h:
* src/cppunit/tools/XmlElement.cpp: added, extracted from XmlOutputter::Node.
* include/cppunit/tools/XmlDocument.h:
* src/cppunit/tools/XmlDocument.cpp: added, extracted from XmlOutputter. Handle
XML document prolog (encoding & style-sheet) and manage the root element.
* src/DllPlugInTester/DllPlugInTester.cpp: bug fix, flag --xsl was ignored.
* examples/cppunittest/XmlOutputterTest.h:
* examples/cppunittest/XmlOutputterTest.cpp: updated for XmlOuputter changes.
extracted tests for XmlOutputter::Node to XmlElementTest
* examples/cppunittest/XmlElementTest.h:
* examples/cppunittest/XmlElementTest.cpp: added, tests extracted from
XmlOutputterTest.
Diffstat (limited to 'include/cppunit')
| -rw-r--r-- | include/cppunit/Makefile.am | 2 | ||||
| -rw-r--r-- | include/cppunit/XmlOutputter.h | 60 | ||||
| -rw-r--r-- | include/cppunit/tools/Makefile.am | 5 | ||||
| -rw-r--r-- | include/cppunit/tools/XmlDocument.h | 67 | ||||
| -rw-r--r-- | include/cppunit/tools/XmlElement.h | 72 |
5 files changed, 155 insertions, 51 deletions
diff --git a/include/cppunit/Makefile.am b/include/cppunit/Makefile.am index 8cebcf8..dfe60f0 100644 --- a/include/cppunit/Makefile.am +++ b/include/cppunit/Makefile.am @@ -1,4 +1,4 @@ -SUBDIRS = extensions ui plugin config +SUBDIRS = extensions ui plugin config tools DISTCLEANFILES = config-auto.h diff --git a/include/cppunit/XmlOutputter.h b/include/cppunit/XmlOutputter.h index 2be3ffb..3336405 100644 --- a/include/cppunit/XmlOutputter.h +++ b/include/cppunit/XmlOutputter.h @@ -9,11 +9,8 @@ #endif #include <cppunit/Outputter.h> -#include <deque> #include <iostream> #include <map> -#include <string> -#include <utility> namespace CppUnit @@ -22,6 +19,8 @@ namespace CppUnit class Test; class TestFailure; class TestResultCollector; +class XmlDocument; +class XmlElement; /*! \brief Outputs a TestResultCollector in XML format. @@ -56,63 +55,23 @@ public: */ virtual void setStyleSheet( const std::string &styleSheet ); - /*! \brief An XML Element. - * \warning This class will probably be replaced with an abstract - * builder in future version. - */ - class CPPUNIT_API Node - { - public: - Node( std::string elementName, - std::string content ="" ); - Node( std::string elementName, - int numericContent ); - virtual ~Node(); - - void addAttribute( std::string attributeName, - std::string value ); - void addAttribute( std::string attributeName, - int numericValue ); - void addNode( Node *node ); - - std::string toString( const std::string &indent = "" ) const; - - private: - typedef std::pair<std::string,std::string> Attribute; - - std::string attributesAsString() const; - std::string escape( std::string value ) const; - static std::string asString( int value ); - - private: - std::string m_name; - std::string m_content; - typedef std::deque<Attribute> Attributes; - Attributes m_attributes; - typedef std::deque<Node *> Nodes; - Nodes m_nodes; - }; - - - virtual void writeProlog(); - virtual void writeTestsResult(); typedef std::map<Test *,TestFailure*> FailedTests; - virtual Node *makeRootNode(); + virtual XmlElement *makeRootNode(); virtual void addFailedTests( FailedTests &failedTests, - Node *rootNode ); + XmlElement *rootNode ); virtual void addSuccessfulTests( FailedTests &failedTests, - Node *rootNode ); - virtual void addStatistics( Node *rootNode ); + XmlElement *rootNode ); + virtual void addStatistics( XmlElement *rootNode ); virtual void addFailedTest( Test *test, TestFailure *failure, int testNumber, - Node *testsNode ); + XmlElement *testsNode ); virtual void addFailureLocation( TestFailure *failure, - Node *testNode ); + XmlElement *testNode ); virtual void addSuccessfulTest( Test *test, int testNumber, - Node *testsNode ); + XmlElement *testsNode ); protected: virtual void fillFailedTestsMap( FailedTests &failedTests ); @@ -121,6 +80,7 @@ protected: std::ostream &m_stream; std::string m_encoding; std::string m_styleSheet; + XmlDocument *m_xml; private: /// Prevents the use of the copy constructor. diff --git a/include/cppunit/tools/Makefile.am b/include/cppunit/tools/Makefile.am new file mode 100644 index 0000000..7035ef7 --- /dev/null +++ b/include/cppunit/tools/Makefile.am @@ -0,0 +1,5 @@ +libcppunitincludedir = $(includedir)/cppunit/tools + +libcppunitinclude_HEADERS = \ + XmlElement.h \ + XmlDocument.h
\ No newline at end of file diff --git a/include/cppunit/tools/XmlDocument.h b/include/cppunit/tools/XmlDocument.h new file mode 100644 index 0000000..3ed4107 --- /dev/null +++ b/include/cppunit/tools/XmlDocument.h @@ -0,0 +1,67 @@ +#ifndef CPPUNIT_TOOLS_XMLDOCUMENT_H +#define CPPUNIT_TOOLS_XMLDOCUMENT_H + +#include <cppunit/Portability.h> + +#if CPPUNIT_NEED_DLL_DECL +#pragma warning( push ) +#pragma warning( disable: 4251 ) // X needs to have dll-interface to be used by clients of class Z +#endif + +#include <string> + + +namespace CppUnit +{ + +class XmlElement; + + +/*! A XML Document. + */ +class CPPUNIT_API XmlDocument +{ +public: + /*! Constructs a XmlDocument object. + * \param encoding Encoding used in the XML file (default is Latin-1, ISO-8859-1 ). + */ + XmlDocument( const std::string &encoding = "", + const std::string &styleSheet = "" ); + + /// Destructor. + virtual ~XmlDocument(); + + std::string encoding() const; + void setEncoding( const std::string &encoding = "" ); + + std::string styleSheet() const; + void setStyleSheet( const std::string &styleSheet = "" ); + + void setRootElement( XmlElement *rootElement ); + XmlElement &rootElement() const; + + std::string toString() const; + +private: + /// Prevents the use of the copy constructor. + XmlDocument( const XmlDocument © ); + + /// Prevents the use of the copy operator. + void operator =( const XmlDocument © ); + +protected: + std::string m_encoding; + std::string m_styleSheet; + XmlElement *m_rootElement; +}; + + +#if CPPUNIT_NEED_DLL_DECL +#pragma warning( pop ) +#endif + + +} // namespace CppUnit + + +#endif // CPPUNIT_TOOLS_XMLDOCUMENT_H diff --git a/include/cppunit/tools/XmlElement.h b/include/cppunit/tools/XmlElement.h new file mode 100644 index 0000000..9b033f4 --- /dev/null +++ b/include/cppunit/tools/XmlElement.h @@ -0,0 +1,72 @@ +#ifndef CPPUNIT_TOOLS_XMLELEMENT_H +#define CPPUNIT_TOOLS_XMLELEMENT_H + +#include <cppunit/Portability.h> + +#if CPPUNIT_NEED_DLL_DECL +#pragma warning( push ) +#pragma warning( disable: 4251 ) // X needs to have dll-interface to be used by clients of class Z +#endif + +#include <deque> +#include <string> + + +namespace CppUnit +{ + +class XmlElement; + +#if CPPUNIT_NEED_DLL_DECL + template class CPPUNIT_API std::deque<XmlElement *>; +#endif + + +/*! A XML Element. + */ +class CPPUNIT_API XmlElement +{ +public: + XmlElement( std::string elementName, + std::string content ="" ); + XmlElement( std::string elementName, + int numericContent ); + virtual ~XmlElement(); + + void addAttribute( std::string attributeName, + std::string value ); + void addAttribute( std::string attributeName, + int numericValue ); + void addNode( XmlElement *element ); + + std::string toString( const std::string &indent = "" ) const; + +private: + typedef std::pair<std::string,std::string> Attribute; + + std::string attributesAsString() const; + std::string escape( std::string value ) const; + static std::string asString( int value ); + +private: + std::string m_name; + std::string m_content; + + typedef std::deque<Attribute> Attributes; + Attributes m_attributes; + + typedef std::deque<XmlElement *> Elements; + Elements m_elements; +}; + + + +} // namespace CppUnit + + +#if CPPUNIT_NEED_DLL_DECL +#pragma warning( pop ) +#endif + + +#endif // CPPUNIT_TOOLS_XMLELEMENT_H |
