diff options
| author | Baptiste Lepilleur <gaiacrtn@free.fr> | 2002-06-16 16:55:58 +0000 |
|---|---|---|
| committer | Baptiste Lepilleur <gaiacrtn@free.fr> | 2002-06-16 16:55:58 +0000 |
| commit | 0a810d68d0550ba6f7f28f2e0dfcef691bdca7b4 (patch) | |
| tree | a060d291bf0dfb6c75720ecbce7f27927b326a5b /src/cppunit | |
| parent | 73a038f1eaa268cec330d971fb550befec6f7798 (diff) | |
| download | cppunit-0a810d68d0550ba6f7f28f2e0dfcef691bdca7b4.tar.gz | |
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.
Diffstat (limited to 'src/cppunit')
| -rw-r--r-- | src/cppunit/CompilerOutputter.cpp | 58 | ||||
| -rw-r--r-- | src/cppunit/StringTools.cpp | 51 | ||||
| -rw-r--r-- | src/cppunit/XmlOutputter.cpp | 63 | ||||
| -rw-r--r-- | src/cppunit/XmlOutputterHook.cpp | 12 |
4 files changed, 107 insertions, 77 deletions
diff --git a/src/cppunit/CompilerOutputter.cpp b/src/cppunit/CompilerOutputter.cpp index 4bc9e31..4628d4c 100644 --- a/src/cppunit/CompilerOutputter.cpp +++ b/src/cppunit/CompilerOutputter.cpp @@ -4,6 +4,7 @@ #include <cppunit/TestResultCollector.h> #include <cppunit/CompilerOutputter.h> #include <algorithm> +#include <cppunit/tools/StringTools.h> namespace CppUnit @@ -15,6 +16,7 @@ CompilerOutputter::CompilerOutputter( TestResultCollector *result, : m_result( result ) , m_stream( stream ) , m_locationFormat( locationFormat ) + , m_wrapColumn( 79 ) { } @@ -170,7 +172,12 @@ CompilerOutputter::printFailureMessage( TestFailure *failure ) m_stream << std::endl; Exception *thrownException = failure->thrownException(); m_stream << thrownException->message().shortDescription() << std::endl; - m_stream << wrap( thrownException->message().details() ) << std::endl; + + std::string message = thrownException->message().details(); + if ( m_wrapColumn > 0 ) + message = StringTools::wrap( message, m_wrapColumn ); + + m_stream << message << std::endl; } @@ -186,50 +193,25 @@ CompilerOutputter::printStatistics() } -std::string -CompilerOutputter::wrap( std::string message ) +void +CompilerOutputter::setWrapColumn( int wrapColumn ) { - Lines lines = splitMessageIntoLines( message ); - std::string wrapped; - for ( Lines::iterator it = lines.begin(); it != lines.end(); ++it ) - { - std::string line( *it ); - const int maxLineLength = 79; - int index =0; - while ( index < line.length() ) - { - std::string lineSlice( line.substr( index, maxLineLength ) ); - wrapped += lineSlice; - index += maxLineLength; - if ( index < line.length() ) - wrapped += "\n"; - } - wrapped += '\n'; - } - return wrapped; + m_wrapColumn = wrapColumn; } -CompilerOutputter::Lines -CompilerOutputter::splitMessageIntoLines( std::string message ) +void +CompilerOutputter::setNoWrap() { - Lines lines; - - std::string::iterator itStart = message.begin(); - while ( true ) - { - std::string::iterator itEol = std::find( itStart, - message.end(), - '\n' ); - lines.push_back( message.substr( itStart - message.begin(), - itEol - itStart ) ); - if ( itEol == message.end() ) - break; - itStart = itEol +1; - } - return lines; + m_wrapColumn = 0; } +int +CompilerOutputter::wrapColumn() const +{ + return m_wrapColumn; +} + } // namespace CppUnit diff --git a/src/cppunit/StringTools.cpp b/src/cppunit/StringTools.cpp index 9bfb939..7dc50ea 100644 --- a/src/cppunit/StringTools.cpp +++ b/src/cppunit/StringTools.cpp @@ -1,4 +1,5 @@ #include <cppunit/tools/StringTools.h> +#include <algorithm> namespace CppUnit @@ -22,6 +23,56 @@ namespace StringTools } + Strings split( const std::string &text, + char separator ) + { + Strings splittedText; + + std::string::const_iterator itStart = text.begin(); + while ( !text.empty() ) + { + std::string::const_iterator itSeparator = std::find( itStart, + text.end(), + separator ); + splittedText.push_back( text.substr( itStart - text.begin(), + itSeparator - itStart ) ); + if ( itSeparator == text.end() ) + break; + itStart = itSeparator +1; + } + + return splittedText; + } + + + std::string wrap( const std::string &text, + int wrapColumn ) + { + const char lineBreak = '\n'; + Strings lines = split( text, lineBreak ); + + std::string wrapped; + for ( Strings::const_iterator it = lines.begin(); it != lines.end(); ++it ) + { + if ( it != lines.begin() ) + wrapped += lineBreak; + + const std::string &line = *it; + int index =0; + while ( index < line.length() ) + { + std::string lineSlice( line.substr( index, wrapColumn ) ); + wrapped += lineSlice; + index += wrapColumn; + if ( index < line.length() ) + wrapped += lineBreak; + } + } + + return wrapped; + } + + } // namespace StringTools diff --git a/src/cppunit/XmlOutputter.cpp b/src/cppunit/XmlOutputter.cpp index 9fc59f7..a1c4345 100644 --- a/src/cppunit/XmlOutputter.cpp +++ b/src/cppunit/XmlOutputter.cpp @@ -57,7 +57,7 @@ XmlOutputter::removeHook( XmlOutputterHook *hook ) void XmlOutputter::write() { - m_xml->setRootElement( makeRootNode() ); + setRootNode(); m_stream << m_xml->toString(); } @@ -69,13 +69,14 @@ XmlOutputter::setStyleSheet( const std::string &styleSheet ) } -XmlElement * -XmlOutputter::makeRootNode() +void +XmlOutputter::setRootNode() { XmlElement *rootNode = new XmlElement( "TestRun" ); + m_xml->setRootElement( rootNode ); for ( Hooks::const_iterator it = m_hooks.begin(); it != m_hooks.end(); ++it ) - (*it)->beginDocument( m_xml, rootNode ); + (*it)->beginDocument( m_xml ); FailedTests failedTests; fillFailedTestsMap( failedTests ); @@ -85,9 +86,7 @@ XmlOutputter::makeRootNode() addStatistics( rootNode ); for ( Hooks::const_iterator itEnd = m_hooks.begin(); itEnd != m_hooks.end(); ++itEnd ) - (*itEnd)->endDocument( m_xml, rootNode ); - - return rootNode; + (*itEnd)->endDocument( m_xml ); } @@ -141,16 +140,16 @@ XmlOutputter::addSuccessfulTests( FailedTests &failedTests, void XmlOutputter::addStatistics( XmlElement *rootNode ) { - XmlElement *statisticsNode = new XmlElement( "Statistics" ); - 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() ) ); + XmlElement *statisticsElement = new XmlElement( "Statistics" ); + rootNode->addElement( statisticsElement ); + statisticsElement->addElement( new XmlElement( "Tests", m_result->runTests() ) ); + statisticsElement->addElement( new XmlElement( "FailuresTotal", + m_result->testFailuresTotal() ) ); + statisticsElement->addElement( new XmlElement( "Errors", m_result->testErrors() ) ); + statisticsElement->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 ); + (*it)->statisticsAdded( m_xml, statisticsElement ); } @@ -162,30 +161,30 @@ XmlOutputter::addFailedTest( Test *test, { Exception *thrownException = failure->thrownException(); - XmlElement *testNode = new XmlElement( "FailedTest" ); - testsNode->addElement( testNode ); - testNode->addAttribute( "id", testNumber ); - testNode->addElement( new XmlElement( "Name", test->getName() ) ); - testNode->addElement( new XmlElement( "FailureType", - failure->isError() ? "Error" : - "Assertion" ) ); + XmlElement *testElement = new XmlElement( "FailedTest" ); + testsNode->addElement( testElement ); + testElement->addAttribute( "id", testNumber ); + testElement->addElement( new XmlElement( "Name", test->getName() ) ); + testElement->addElement( new XmlElement( "FailureType", + failure->isError() ? "Error" : + "Assertion" ) ); if ( failure->sourceLine().isValid() ) - addFailureLocation( failure, testNode ); + addFailureLocation( failure, testElement ); - testNode->addElement( new XmlElement( "Message", thrownException->what() ) ); + testElement->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 ); + (*it)->failTestAdded( m_xml, testElement, test, failure ); } void XmlOutputter::addFailureLocation( TestFailure *failure, - XmlElement *testNode ) + XmlElement *testElement ) { XmlElement *locationNode = new XmlElement( "Location" ); - testNode->addElement( locationNode ); + testElement->addElement( locationNode ); SourceLine sourceLine = failure->sourceLine(); locationNode->addElement( new XmlElement( "File", sourceLine.fileName() ) ); locationNode->addElement( new XmlElement( "Line", sourceLine.lineNumber() ) ); @@ -197,13 +196,13 @@ XmlOutputter::addSuccessfulTest( Test *test, int testNumber, XmlElement *testsNode ) { - XmlElement *testNode = new XmlElement( "Test" ); - testsNode->addElement( testNode ); - testNode->addAttribute( "id", testNumber ); - testNode->addElement( new XmlElement( "Name", test->getName() ) ); + XmlElement *testElement = new XmlElement( "Test" ); + testsNode->addElement( testElement ); + testElement->addAttribute( "id", testNumber ); + testElement->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 ); + (*it)->successfulTestAdded( m_xml, testElement, test ); } diff --git a/src/cppunit/XmlOutputterHook.cpp b/src/cppunit/XmlOutputterHook.cpp index 4cacd06..40ff4d7 100644 --- a/src/cppunit/XmlOutputterHook.cpp +++ b/src/cppunit/XmlOutputterHook.cpp @@ -6,22 +6,20 @@ namespace CppUnit void -XmlOutputterHook::beginDocument( XmlDocument *document, - XmlElement *rootNode ) +XmlOutputterHook::beginDocument( XmlDocument *document ) { } void -XmlOutputterHook::endDocument( XmlDocument *document, - XmlElement *rootNode ) +XmlOutputterHook::endDocument( XmlDocument *document ) { } void XmlOutputterHook::failTestAdded( XmlDocument *document, - XmlElement *testNode, + XmlElement *testElement, Test *test, TestFailure *failure ) { @@ -30,7 +28,7 @@ XmlOutputterHook::failTestAdded( XmlDocument *document, void XmlOutputterHook::successfulTestAdded( XmlDocument *document, - XmlElement *testNode, + XmlElement *testElement, Test *test ) { } @@ -38,7 +36,7 @@ XmlOutputterHook::successfulTestAdded( XmlDocument *document, void XmlOutputterHook::statisticsAdded( XmlDocument *document, - XmlElement *statisticsNode ) + XmlElement *statisticsElement ) { } |
