From fbd454f554f13680fe62b36fb7a5829f6dc0c396 Mon Sep 17 00:00:00 2001 From: Baptiste Lepilleur Date: Fri, 5 Oct 2001 21:27:15 +0000 Subject: Include/cppunit/Asserter. include/cppunit/Asserter.h : * src/cppunit/Asserter.cpp : added. Helper to create assertion macros. * src/cppunit/cppunit.dsp : * src/cppunit/Makefile.am : * include/cppunit/Makefile.am : added Asserter.h and Asserter.cpp. * include/cppunit/Exception.h : * src/cppunit/Exception.cpp : added constructor that take a SourceLine argument. Deprecated static constant and old constructor. Fixed some constness issues. * examples/cppunittest/ExceptionTest.cpp : Refactored. * NEWS : partially updated (need to be more detailed) * include/cppunit/NotEqualException.h : * src/cppunit/NotEqualException.cpp : added constructor that take a SourceLine argument. Deprecated old constructor. Added a third element to compose message. * examples/cppunittest/NotEqualExceptionTest.cpp : moved to "Core" suite. Added test for SourceLine() and additionalMessage(). Refactored. * include/cppunit/SourceLine.h : * src/cppunit/SourceLine.cpp : added. Result of applying IntroduceParameterObject refactoring on filename & line number... * include/cppunit/TestAssert.h : * src/cppunit/TestAssert.cpp : deprecated old assert functions. added functions assertEquals() and assertDoubleEquals() which use SourceLine. * src/cppunit/TestCase.cpp : Modified for SourceLine. * include/cppunit/TestFailure.h : * src/cppunit/TestFailure.cpp : added failedTestName(), and sourceLine(). * src/msvc6/testrunner/TestRunnerDlg.cpp : modified to use SourceLine. * include/cppunit/TextTestResult.h : * src/cppunit/TextTestResult.cpp : corrected include order and switched to angled brackets. Refactored. Don't print failure location if not available. Not equal failure dump additional message if available. * src/cppunit/TextTestRunner.cpp : run() now returns a boolean to indicate if the run was sucessful. * src/cppunit/XmlTestResultOutputter.cpp : replaced itoa() with OStringStream. Refactored. * examples/cppunittest/XmlUniformiser.h : * examples/cppunittest/XmlUniformiser.cpp : CPPUNITTEST_ASSERT_XML_EQUAL capture failure location. Refactored checkXmlEqual(). * examples/cppunittest/XmlUniformiserTest.h : * examples/cppunittest/XmlUniformiserTest.cpp : added test for CPPUNITTEST_ASSERT_XML_EQUAL. * include/cppunit/XmlTestResultOutputter.h : * src/cppunit/XmlTestResultOutputter.cpp : updated to use SourceLine. --- src/cppunit/Exception.cpp | 65 +++++++++++++++++++++++++++++++++++------------ 1 file changed, 49 insertions(+), 16 deletions(-) (limited to 'src/cppunit/Exception.cpp') diff --git a/src/cppunit/Exception.cpp b/src/cppunit/Exception.cpp index 0246c98..3a4efd0 100644 --- a/src/cppunit/Exception.cpp +++ b/src/cppunit/Exception.cpp @@ -4,28 +4,51 @@ namespace CppUnit { +#ifdef CPPUNIT_ENABLE_SOURCELINE_DEPRECATED +/*! + * \deprecated Use SourceLine::isValid() instead. + */ const std::string Exception::UNKNOWNFILENAME = ""; +/*! + * \deprecated Use SourceLine::isValid() instead. + */ const long Exception::UNKNOWNLINENUMBER = -1; +#endif /// Construct the exception -Exception::Exception (const Exception& other) : std::exception (other) +Exception::Exception( const Exception &other ) : + std::exception( other ) { - m_message = other.m_message; - m_lineNumber = other.m_lineNumber; - m_fileName = other.m_fileName; + m_message = other.m_message; + m_sourceLine = other.m_sourceLine; } +/*! + * \deprecated Use other constructor instead. + */ +Exception::Exception( std::string message, + SourceLine sourceLine ) : + m_message( message ), + m_sourceLine( sourceLine ) +{ +} + + +#ifdef CPPUNIT_ENABLE_SOURCELINE_DEPRECATED +/*! + * \deprecated Use other constructor instead. + */ Exception::Exception( std::string message, long lineNumber, std::string fileName ) : m_message( message ), - m_lineNumber( lineNumber ), - m_fileName( fileName ) + m_sourceLine( fileName, lineNumber ) { } +#endif /// Destruct the exception @@ -36,15 +59,14 @@ Exception::~Exception () throw() /// Perform an assignment Exception& -Exception::operator=( const Exception& other ) +Exception::operator =( const Exception& other ) { - SuperClass::operator= (other); + SuperClass::operator =(other); - if (&other != this) + if ( &other != this ) { - m_message = other.m_message; - m_lineNumber = other.m_lineNumber; - m_fileName = other.m_fileName; + m_message = other.m_message; + m_sourceLine = other.m_sourceLine; } return *this; @@ -58,21 +80,32 @@ Exception::what() const throw () return m_message.c_str (); } +/// Location where the error occured +SourceLine +Exception::sourceLine() const +{ + return m_sourceLine; +} + +#ifdef CPPUNIT_ENABLE_SOURCELINE_DEPRECATED /// The line on which the error occurred long -Exception::lineNumber() +Exception::lineNumber() const { - return m_lineNumber; + return m_sourceLine.isValid() ? m_sourceLine.lineNumber() : + UNKNOWNLINENUMBER; } /// The file in which the error occurred std::string -Exception::fileName() +Exception::fileName() const { - return m_fileName; + return m_sourceLine.isValid() ? m_sourceLine.fileName() : + UNKNOWNFILENAME; } +#endif Exception * -- cgit v1.2.1