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. --- examples/cppunittest/ExceptionTest.cpp | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) (limited to 'examples/cppunittest/ExceptionTest.cpp') diff --git a/examples/cppunittest/ExceptionTest.cpp b/examples/cppunittest/ExceptionTest.cpp index ae4948c..ab60eed 100644 --- a/examples/cppunittest/ExceptionTest.cpp +++ b/examples/cppunittest/ExceptionTest.cpp @@ -35,14 +35,12 @@ void ExceptionTest::testConstructor() { const std::string message( "a message" ); - const int lineNumber = 17; - const std::string fileName( "dir/afile.cpp" ); + const CppUnit::SourceLine sourceLine( "dir/afile.cpp", 17 ); - CppUnit::Exception e( message, lineNumber, fileName ); + CppUnit::Exception e( message, sourceLine ); CPPUNIT_ASSERT_EQUAL( message, std::string( e.what() ) ); - CPPUNIT_ASSERT_EQUAL( lineNumber, int(e.lineNumber()) ); - CPPUNIT_ASSERT_EQUAL( fileName, e.fileName() ); + CPPUNIT_ASSERT( sourceLine == e.sourceLine() ); } @@ -52,17 +50,15 @@ ExceptionTest::testDefaultConstructor() CppUnit::Exception e; CPPUNIT_ASSERT_EQUAL( std::string(""), std::string( e.what() ) ); - CPPUNIT_ASSERT_EQUAL( CppUnit::Exception::UNKNOWNLINENUMBER, - e.lineNumber() ); - CPPUNIT_ASSERT_EQUAL( CppUnit::Exception::UNKNOWNFILENAME, - e.fileName() ); + CPPUNIT_ASSERT( !e.sourceLine().isValid() ); } void ExceptionTest::testCopyConstructor() { - CppUnit::Exception e( "message", 17, "fileName.cpp" ); + CppUnit::SourceLine sourceLine( "fileName.cpp", 123 ); + CppUnit::Exception e( "message", sourceLine ); CppUnit::Exception other( e ); checkIsSame( e, other ); } @@ -71,7 +67,8 @@ ExceptionTest::testCopyConstructor() void ExceptionTest::testAssignment() { - CppUnit::Exception e( "message", 17, "fileName.cpp" ); + CppUnit::SourceLine sourceLine( "fileName.cpp", 123 ); + CppUnit::Exception e( "message", sourceLine ); CppUnit::Exception other; other = e; checkIsSame( e, other ); @@ -81,7 +78,8 @@ ExceptionTest::testAssignment() void ExceptionTest::testClone() { - CppUnit::Exception e( "message", 17, "fileName.cpp" ); + CppUnit::SourceLine sourceLine( "fileName.cpp", 123 ); + CppUnit::Exception e( "message", sourceLine ); std::auto_ptr other( e.clone() ); checkIsSame( e, *other.get() ); } @@ -90,7 +88,8 @@ ExceptionTest::testClone() void ExceptionTest::testIsInstanceOf() { - CppUnit::Exception e( "message", 17, "fileName.cpp" ); + CppUnit::SourceLine sourceLine( "fileName.cpp", 123 ); + CppUnit::Exception e( "message", sourceLine ); CPPUNIT_ASSERT( e.isInstanceOf( CppUnit::Exception::type() ) ); CPPUNIT_ASSERT( !e.isInstanceOf( CppUnit::NotEqualException::type() ) ); } @@ -103,6 +102,5 @@ ExceptionTest::checkIsSame( CppUnit::Exception &e, std::string eWhat( e.what() ); std::string otherWhat( other.what() ); CPPUNIT_ASSERT_EQUAL( eWhat, otherWhat ); - CPPUNIT_ASSERT_EQUAL( e.lineNumber(), other.lineNumber() ); - CPPUNIT_ASSERT_EQUAL( e.fileName(), other.fileName() ); + CPPUNIT_ASSERT( e.sourceLine() == other.sourceLine() ); } -- cgit v1.2.1