diff options
| author | Baptiste Lepilleur <gaiacrtn@free.fr> | 2002-06-13 17:17:42 +0000 |
|---|---|---|
| committer | Baptiste Lepilleur <gaiacrtn@free.fr> | 2002-06-13 17:17:42 +0000 |
| commit | 7f0766499db248afe9985a5700c22f9a8ce7ce6c (patch) | |
| tree | ba70577fe0ed4343b5127d1e8848cbe0ccebf4fe /src/cppunit | |
| parent | abd178318ae3cdb6cc0a700e77414a33ef9297ca (diff) | |
| download | cppunit-7f0766499db248afe9985a5700c22f9a8ce7ce6c.tar.gz | |
Include/cppunit/NotEqualException.
include/cppunit/NotEqualException.h:
* src/cppunit/NotEqualException.cpp: removed.
* include/cppunit/Exception.h:
* src/cppunit/Exception.cpp: removed 'type' related stuffs.
* include/cppunit/TextTestResult.h:
* src/cppunit/TextTestResult.cpp: delegate printing to TextOutputter.
* examples/simple/ExampleTestCase.h:
* examples/simple/ExampleTestCase.cpp: reindented.
* src/qttestrunner/build:
* src/qttestrunner/qttestrunner.pro:
* src/qttestrunner/TestBrowserDlgImpl.h:
* src/qttestrunner/TestRunnerModel.h: applied Thomas Neidhart's patch,
'Some minor fixes to compile QTTestrunner under Linux.'.
Diffstat (limited to 'src/cppunit')
| -rw-r--r-- | src/cppunit/Asserter.cpp | 32 | ||||
| -rw-r--r-- | src/cppunit/CompilerOutputter.cpp | 2 | ||||
| -rw-r--r-- | src/cppunit/Exception.cpp | 14 | ||||
| -rw-r--r-- | src/cppunit/Makefile.am | 3 | ||||
| -rw-r--r-- | src/cppunit/NotEqualException.cpp | 115 | ||||
| -rw-r--r-- | src/cppunit/TestAssert.cpp | 1 | ||||
| -rw-r--r-- | src/cppunit/TextOutputter.cpp | 6 | ||||
| -rw-r--r-- | src/cppunit/TextTestResult.cpp | 133 | ||||
| -rw-r--r-- | src/cppunit/cppunit.dsp | 8 | ||||
| -rw-r--r-- | src/cppunit/cppunit_dll.dsp | 8 |
10 files changed, 31 insertions, 291 deletions
diff --git a/src/cppunit/Asserter.cpp b/src/cppunit/Asserter.cpp index 659e328..e43c19b 100644 --- a/src/cppunit/Asserter.cpp +++ b/src/cppunit/Asserter.cpp @@ -1,6 +1,6 @@ #include <cppunit/Asserter.h> +#include <cppunit/Exception.h> #include <cppunit/Message.h> -#include <cppunit/NotEqualException.h> namespace CppUnit @@ -45,20 +45,34 @@ failIf( bool shouldFail, failIf( shouldFail, Message( "assertion failed", message ), sourceLine ); } -/* @@fixme Need to take NotEqualException down before including that change. + void failNotEqual( std::string expected, std::string actual, const SourceLine &sourceLine, - const Message &additionalMessage ) + const Message &additionalMessage, + std::string shortDescription ) { - Message message( "equality assertion failed", + Message message( shortDescription, "Expected: " + expected, "Actual : " + actual ); message.addDetail( additionalMessage ); fail( message, sourceLine ); } -*/ + + +void +failNotEqualIf( bool shouldFail, + std::string expected, + std::string actual, + const SourceLine &sourceLine, + const Message &additionalMessage, + std::string shortDescription ) +{ + if ( shouldFail ) + failNotEqual( expected, actual, sourceLine, additionalMessage, shortDescription ); +} + void failNotEqual( std::string expected, @@ -66,10 +80,10 @@ failNotEqual( std::string expected, const SourceLine &sourceLine, std::string additionalMessage ) { - throw NotEqualException( expected, - actual, - sourceLine, - additionalMessage ); + Message message; + if ( !additionalMessage.empty() ) + message.addDetail( additionalMessage ); + failNotEqual( expected, actual, sourceLine, message ); } diff --git a/src/cppunit/CompilerOutputter.cpp b/src/cppunit/CompilerOutputter.cpp index 2355fc9..e71f067 100644 --- a/src/cppunit/CompilerOutputter.cpp +++ b/src/cppunit/CompilerOutputter.cpp @@ -1,4 +1,4 @@ -#include <cppunit/NotEqualException.h> +#include <cppunit/Exception.h> #include <cppunit/SourceLine.h> #include <cppunit/TestFailure.h> #include <cppunit/TestResultCollector.h> diff --git a/src/cppunit/Exception.cpp b/src/cppunit/Exception.cpp index 2c01324..871a40a 100644 --- a/src/cppunit/Exception.cpp +++ b/src/cppunit/Exception.cpp @@ -116,18 +116,4 @@ Exception::clone() const } -bool -Exception::isInstanceOf( const Type &exceptionType ) const -{ - return exceptionType == type(); -} - - -Exception::Type -Exception::type() -{ - return Type( "CppUnit::Exception" ); -} - - } // namespace CppUnit diff --git a/src/cppunit/Makefile.am b/src/cppunit/Makefile.am index 4376042..80b1888 100644 --- a/src/cppunit/Makefile.am +++ b/src/cppunit/Makefile.am @@ -1,5 +1,5 @@ # -# $Id: Makefile.am,v 1.33 2002-06-13 15:31:01 blep Exp $ +# $Id: Makefile.am,v 1.34 2002-06-13 18:17:42 blep Exp $ # EXTRA_DIST = cppunit.dsp cppunit_dll.dsp DllMain.cpp @@ -16,7 +16,6 @@ libcppunit_la_SOURCES = \ DynamicLibraryManagerException.cpp \ Exception.cpp \ Message.cpp \ - NotEqualException.cpp \ RepeatedTest.cpp \ PlugInManager.cpp \ SourceLine.cpp \ diff --git a/src/cppunit/NotEqualException.cpp b/src/cppunit/NotEqualException.cpp deleted file mode 100644 index 912597c..0000000 --- a/src/cppunit/NotEqualException.cpp +++ /dev/null @@ -1,115 +0,0 @@ -#include <cppunit/NotEqualException.h> - -namespace CppUnit { - - -NotEqualException::NotEqualException( std::string expected, - std::string actual, - SourceLine sourceLine , - std::string additionalMessage ) : - Exception( Message( "equality assertion failed", - "Expected: " + expected, - "Actual : " + actual ), - sourceLine), - m_expected( expected ), - m_actual( actual ), - m_additionalMessage( additionalMessage ) -{ - if ( !m_additionalMessage.empty() ) - m_message.addDetail( m_additionalMessage ); -} - - -#ifdef CPPUNIT_ENABLE_SOURCELINE_DEPRECATED -/*! - * \deprecated Use other constructor instead. - */ -NotEqualException::NotEqualException( std::string expected, - std::string actual, - long lineNumber, - std::string fileName ) : - Exception( Message( "equality assertion failed", - "Expected: " + expected, - "Actual : " + actual ), - lineNumber, - fileName ), - m_expected( expected ), - m_actual( actual ) -{ -} -#endif - - -NotEqualException::NotEqualException( const NotEqualException &other ) : - Exception( other ), - m_expected( other.m_expected ), - m_actual( other.m_actual ), - m_additionalMessage( other.m_additionalMessage ) -{ -} - - -NotEqualException::~NotEqualException() throw() -{ -} - - -NotEqualException & -NotEqualException::operator =( const NotEqualException &other ) -{ - Exception::operator =( other ); - - if ( &other != this ) - { - m_expected = other.m_expected; - m_actual = other.m_actual; - m_additionalMessage = other.m_additionalMessage; - } - return *this; -} - - -Exception * -NotEqualException::clone() const -{ - return new NotEqualException( *this ); -} - - -bool -NotEqualException::isInstanceOf( const Type &exceptionType ) const -{ - return exceptionType == type() || - Exception::isInstanceOf( exceptionType ); -} - - -Exception::Type -NotEqualException::type() -{ - return Type( "CppUnit::NotEqualException" ); -} - - -std::string -NotEqualException::expectedValue() const -{ - return m_expected; -} - - -std::string -NotEqualException::actualValue() const -{ - return m_actual; -} - - -std::string -NotEqualException::additionalMessage() const -{ - return m_additionalMessage; -} - - -} // namespace CppUnit diff --git a/src/cppunit/TestAssert.cpp b/src/cppunit/TestAssert.cpp index b5999e1..e66db3c 100644 --- a/src/cppunit/TestAssert.cpp +++ b/src/cppunit/TestAssert.cpp @@ -5,7 +5,6 @@ #endif #include <cppunit/TestAssert.h> -#include <cppunit/NotEqualException.h> namespace CppUnit { diff --git a/src/cppunit/TextOutputter.cpp b/src/cppunit/TextOutputter.cpp index 577d808..8ca92f7 100644 --- a/src/cppunit/TextOutputter.cpp +++ b/src/cppunit/TextOutputter.cpp @@ -1,8 +1,8 @@ -#include <cppunit/NotEqualException.h> -#include <cppunit/TestFailure.h> +#include <cppunit/Exception.h> #include <cppunit/SourceLine.h> -#include <cppunit/TestResultCollector.h> +#include <cppunit/TestFailure.h> #include <cppunit/TextOutputter.h> +#include <cppunit/TestResultCollector.h> namespace CppUnit diff --git a/src/cppunit/TextTestResult.cpp b/src/cppunit/TextTestResult.cpp index a8483b7..918b620 100644 --- a/src/cppunit/TextTestResult.cpp +++ b/src/cppunit/TextTestResult.cpp @@ -1,8 +1,8 @@ #include <cppunit/Exception.h> -#include <cppunit/NotEqualException.h> #include <cppunit/Test.h> #include <cppunit/TestFailure.h> #include <cppunit/TextTestResult.h> +#include <cppunit/TextOutputter.h> #include <iostream> @@ -32,137 +32,10 @@ TextTestResult::startTest( Test *test ) void -TextTestResult::printFailures( std::ostream &stream ) -{ - TestFailures::const_iterator itFailure = failures().begin(); - int failureNumber = 1; - while ( itFailure != failures().end() ) - { - stream << std::endl; - printFailure( *itFailure++, failureNumber++, stream ); - } -} - - -void -TextTestResult::printFailure( TestFailure *failure, - int failureNumber, - std::ostream &stream ) -{ - printFailureListMark( failureNumber, stream ); - stream << ' '; - printFailureTestName( failure, stream ); - stream << ' '; - printFailureType( failure, stream ); - stream << ' '; - printFailureLocation( failure->sourceLine(), stream ); - stream << std::endl; - printFailureDetail( failure->thrownException(), stream ); - stream << std::endl; -} - - -void -TextTestResult::printFailureListMark( int failureNumber, - std::ostream &stream ) -{ - stream << failureNumber << ")"; -} - - -void -TextTestResult::printFailureTestName( TestFailure *failure, - std::ostream &stream ) -{ - stream << "test: " << failure->failedTest()->getName(); -} - - -void -TextTestResult::printFailureType( TestFailure *failure, - std::ostream &stream ) -{ - stream << "(" - << (failure->isError() ? "E" : "F") - << ")"; -} - - -void -TextTestResult::printFailureLocation( SourceLine sourceLine, - std::ostream &stream ) -{ - if ( !sourceLine.isValid() ) - return; - - stream << "line: " << sourceLine.lineNumber() - << ' ' << sourceLine.fileName(); -} - - -void -TextTestResult::printFailureDetail( Exception *thrownException, - std::ostream &stream ) -{ - if ( thrownException->isInstanceOf( NotEqualException::type() ) ) - { - NotEqualException *e = (NotEqualException*)thrownException; - stream << "expected: " << e->expectedValue() << std::endl - << "but was: " << e->actualValue(); - if ( !e->additionalMessage().empty() ) - { - stream << std::endl; - stream << "additional message:" << std::endl - << e->additionalMessage(); - } - } - else - { - stream << " \"" << thrownException->what() << "\""; - } -} - - -void TextTestResult::print( std::ostream& stream ) { - printHeader( stream ); - stream << std::endl; - printFailures( stream ); -} - - -void -TextTestResult::printHeader( std::ostream &stream ) -{ - if (wasSuccessful ()) - stream << std::endl << "OK (" << runTests () << " tests)" - << std::endl; - else - { - stream << std::endl; - printFailureWarning( stream ); - printStatistics( stream ); - } -} - - -void -TextTestResult::printFailureWarning( std::ostream &stream ) -{ - stream << "!!!FAILURES!!!" << std::endl; -} - - -void -TextTestResult::printStatistics( std::ostream &stream ) -{ - stream << "Test Results:" << std::endl; - - stream << "Run: " << runTests() - << " Failures: " << testFailures() - << " Errors: " << testErrors() - << std::endl; + TextOutputter outputter( this, stream ); + outputter.write(); } diff --git a/src/cppunit/cppunit.dsp b/src/cppunit/cppunit.dsp index c22fbca..abaa6ba 100644 --- a/src/cppunit/cppunit.dsp +++ b/src/cppunit/cppunit.dsp @@ -261,14 +261,6 @@ SOURCE=..\..\include\cppunit\Message.h # End Source File # Begin Source File -SOURCE=.\NotEqualException.cpp -# End Source File -# Begin Source File - -SOURCE=..\..\include\cppunit\NotEqualException.h -# End Source File -# Begin Source File - SOURCE=.\SourceLine.cpp # End Source File # Begin Source File diff --git a/src/cppunit/cppunit_dll.dsp b/src/cppunit/cppunit_dll.dsp index ec00f3c..4336150 100644 --- a/src/cppunit/cppunit_dll.dsp +++ b/src/cppunit/cppunit_dll.dsp @@ -207,14 +207,6 @@ SOURCE=..\..\include\cppunit\Message.h # End Source File # Begin Source File -SOURCE=.\NotEqualException.cpp -# End Source File -# Begin Source File - -SOURCE=..\..\include\cppunit\NotEqualException.h -# End Source File -# Begin Source File - SOURCE=.\SourceLine.cpp # End Source File # Begin Source File |
