From 0a810d68d0550ba6f7f28f2e0dfcef691bdca7b4 Mon Sep 17 00:00:00 2001 From: Baptiste Lepilleur Date: Sun, 16 Jun 2002 16:55:58 +0000 Subject: Release 1. release 1.9.8 * include/cppunit/plugin/TestPlugIn.h: updated documentation. * include/cppunit/tools/XmlDocument.h: updated documentation. * include/cppunit/tools/StringTools.h: * src/cppunit/StringTools.cpp: added split() and wrap() functions. * include/cppunit/CompilerOutputter.h: * src/cppunit/CompilerOutputter.cpp: extracted wrap() and splitMessageIntoLines() to StringTools. * include/cppunit/XmlOutputterHook.h: * src/cppunit/XmlOutputterHook.cpp: removed rooNode parameter from beginDocument() and endDocument(). It can be retreive from document. Renamed 'node' occurences to 'element'. * include/cppunit/XmlOutputter.h: * src/cppunit/XmlOutputter.cpp: updated against XmlOutputterHook changes. Renamed 'node' occurences to 'element'. * examples/ClockerPlugIn/ClockerXmlHook.h: * examples/ClockerPlugIn/ClockerXmlHook.cpp: updated against XmlOutputterHook changes. * examples/cppunittest/XmlElementTest.h: * examples/cppunittest/XmlElementTest.cpp: Renamed 'node' occurences to 'element'. * examples/cppunittest/XmlOutputterTest.cpp: updated against XmlOutputterHook changes. * examples/cppunittest/StringToolsTest.h: * examples/cppunittest/StringToolsTest.cpp: added. Unit tests for StringTools. Turn out that VC++ dismiss empty lines in tools output, which is the reason why empty lines where not printed in CompilerOutputter. --- include/cppunit/CompilerOutputter.h | 11 +++++--- include/cppunit/XmlOutputter.h | 12 +++++---- include/cppunit/XmlOutputterHook.h | 51 ++++++++++++++++++++++++++++++------- include/cppunit/plugin/TestPlugIn.h | 5 +++- include/cppunit/tools/StringTools.h | 8 ++++++ include/cppunit/tools/XmlDocument.h | 3 +++ 6 files changed, 71 insertions(+), 19 deletions(-) (limited to 'include/cppunit') diff --git a/include/cppunit/CompilerOutputter.h b/include/cppunit/CompilerOutputter.h index 5b9c418..a87cabd 100644 --- a/include/cppunit/CompilerOutputter.h +++ b/include/cppunit/CompilerOutputter.h @@ -105,6 +105,12 @@ public: void write(); + void setNoWrap(); + + void setWrapColumn( int wrapColumn ); + + int wrapColumn() const; + virtual void printSuccess(); virtual void printFailureReport(); virtual void printFailuresList(); @@ -114,7 +120,6 @@ public: virtual void printFailureType( TestFailure *failure ); virtual void printFailedTestName( TestFailure *failure ); virtual void printFailureMessage( TestFailure *failure ); - virtual std::string wrap( std::string message ); private: /// Prevents the use of the copy constructor. @@ -128,13 +133,11 @@ private: virtual std::string extractBaseName( const std::string &fileName ) const; - typedef std::vector Lines; - static Lines splitMessageIntoLines( std::string message ); - private: TestResultCollector *m_result; std::ostream &m_stream; std::string m_locationFormat; + int m_wrapColumn; }; diff --git a/include/cppunit/XmlOutputter.h b/include/cppunit/XmlOutputter.h index dc16913..190ed70 100644 --- a/include/cppunit/XmlOutputter.h +++ b/include/cppunit/XmlOutputter.h @@ -78,17 +78,19 @@ public: typedef std::map FailedTests; - /*! Returns the root element with its children. + /*! Sets the root element and adds its children. + * + * Set the root element of the XML Document and add its child elements. * * For all hooks, call beginDocument() just after creating the root element (it * is empty at this time), and endDocument() once all the datas have been added * to the root element. - * - * \return Root element. */ - virtual XmlElement *makeRootNode(); + virtual void setRootNode(); + virtual void addFailedTests( FailedTests &failedTests, XmlElement *rootNode ); + virtual void addSuccessfulTests( FailedTests &failedTests, XmlElement *rootNode ); @@ -111,7 +113,7 @@ public: XmlElement *testsNode ); virtual void addFailureLocation( TestFailure *failure, - XmlElement *testNode ); + XmlElement *testElement ); /*! Adds a successful test to the successful tests node. diff --git a/include/cppunit/XmlOutputterHook.h b/include/cppunit/XmlOutputterHook.h index b67c6cf..57d1440 100644 --- a/include/cppunit/XmlOutputterHook.h +++ b/include/cppunit/XmlOutputterHook.h @@ -15,27 +15,60 @@ class XmlElement; /*! \brief Hook to customize Xml output. + * + * XmlOutputterHook can be passed to XmlOutputter to customize the XmlDocument. + * + * Common customizations are: + * - adding some datas to successfull or failed test with + * failTestAdded() and successfulTestAdded(), + * - adding some statistics with statisticsAdded(), + * - adding other datas with beginDocument() or endDocument(). + * + * See examples/ClockerPlugIn which makes use of most the hook. + * + * %Test plug-ins can also implement hook to customize XML output. + * + * \see XmlOutputter, CppUnitTestPlugIn. */ class CPPUNIT_API XmlOutputterHook { public: - virtual void beginDocument( XmlDocument *document, - XmlElement *rootNode ); - - virtual void endDocument( XmlDocument *document, - XmlElement *rootNode ); - + /*! Called before any elements is added to the root element. + * \param document XML Document being created. + */ + virtual void beginDocument( XmlDocument *document ); + + /*! Called after adding all elements to the root element. + * \param document XML Document being created. + */ + virtual void endDocument( XmlDocument *document ); + + /*! Called after adding a fail test element. + * \param document XML Document being created. + * \param testElement element. + * \param test Test that failed. + * \param failure Test failure data. + */ virtual void failTestAdded( XmlDocument *document, - XmlElement *testNode, + XmlElement *testElement, Test *test, TestFailure *failure ); + /*! Called after adding a successful test element. + * \param document XML Document being created. + * \param testElement element. + * \param test Test that was successful. + */ virtual void successfulTestAdded( XmlDocument *document, - XmlElement *testNode, + XmlElement *testElement, Test *test ); + /*! Called after adding the statistic element. + * \param document XML Document being created. + * \param statisticsElement element. + */ virtual void statisticsAdded( XmlDocument *document, - XmlElement *statisticsNode ); + XmlElement *statisticsElement ); }; diff --git a/include/cppunit/plugin/TestPlugIn.h b/include/cppunit/plugin/TestPlugIn.h index 0eaf960..b77d50b 100644 --- a/include/cppunit/plugin/TestPlugIn.h +++ b/include/cppunit/plugin/TestPlugIn.h @@ -32,8 +32,11 @@ class XmlOutputter; * addListener() and removeListener() are called respectively before and after * the test run. * + * addXmlOutputterHooks() and removeXmlOutputterHooks() are called respectively + * before and after writing the XML output using a XmlOutputter. + * * \see CPPUNIT_PLUGIN_IMPLEMENT, CPPUNIT_PLUGIN_EXPORTED_FUNCTION_IMPL - * \see TestPlugInDefaultImpl. + * \see CppUnit::TestPlugInDefaultImpl, CppUnit::XmlOutputter. */ struct CppUnitTestPlugIn { diff --git a/include/cppunit/tools/StringTools.h b/include/cppunit/tools/StringTools.h index 8242c9e..cc325dc 100644 --- a/include/cppunit/tools/StringTools.h +++ b/include/cppunit/tools/StringTools.h @@ -3,6 +3,7 @@ #include #include +#include namespace CppUnit @@ -13,10 +14,17 @@ namespace CppUnit namespace StringTools { + typedef std::vector Strings; + std::string CPPUNIT_API toString( int value ); std::string CPPUNIT_API toString( double value ); + Strings CPPUNIT_API split( const std::string &text, + char separator ); + + std::string CPPUNIT_API wrap( const std::string &text, + int wrapColumn = 79 ); } // namespace StringTools diff --git a/include/cppunit/tools/XmlDocument.h b/include/cppunit/tools/XmlDocument.h index 3ed4107..564fb20 100644 --- a/include/cppunit/tools/XmlDocument.h +++ b/include/cppunit/tools/XmlDocument.h @@ -18,6 +18,9 @@ class XmlElement; /*! A XML Document. + * + * A XmlDocument represents a XML file. It holds a pointer on the root XmlElement + * of the document. It also holds the encoding and style sheet used. */ class CPPUNIT_API XmlDocument { -- cgit v1.2.1