diff options
author | Baptiste Lepilleur <gaiacrtn@free.fr> | 2001-06-11 18:56:23 +0000 |
---|---|---|
committer | Baptiste Lepilleur <gaiacrtn@free.fr> | 2001-06-11 18:56:23 +0000 |
commit | 0c5051a8acf83fd77a6094177eb0711d3f90d997 (patch) | |
tree | a0757b1cae952576f4497d40ccf3aa70a2bf84c8 /examples/cppunittest/ExceptionTest.cpp | |
parent | 021d0a2611777a06d948735e0ad36cb90ffd413b (diff) | |
download | cppunit-0c5051a8acf83fd77a6094177eb0711d3f90d997.tar.gz |
Examples/cppunittest/TestResultTest.
examples/cppunittest/TestResultTest.*: renamed TestListenerTest.*
* examples/cppunittest/*: added unit tests for:
HelperMacros, TestAssert, TestCaller, TestCase, TestFailure,
TestResult, TestSuite, TestDecoratorTest, TestSetUp, RepeatedTestTest,
Orthodox, Exception.
Diffstat (limited to 'examples/cppunittest/ExceptionTest.cpp')
-rw-r--r-- | examples/cppunittest/ExceptionTest.cpp | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/examples/cppunittest/ExceptionTest.cpp b/examples/cppunittest/ExceptionTest.cpp new file mode 100644 index 0000000..c56082e --- /dev/null +++ b/examples/cppunittest/ExceptionTest.cpp @@ -0,0 +1,106 @@ +#include "ExceptionTest.h" +#include <cppunit/Exception.h> +#include <cppunit/NotEqualException.h> +#include <memory> + + +CPPUNIT_TEST_SUITE_REGISTRATION( ExceptionTest ); + + +ExceptionTest::ExceptionTest() +{ +} + + +ExceptionTest::~ExceptionTest() +{ +} + + +void +ExceptionTest::setUp() +{ +} + + +void +ExceptionTest::tearDown() +{ +} + + +void +ExceptionTest::testConstructor() +{ + const std::string message( "a message" ); + const int lineNumber = 17; + const std::string fileName( "dir/afile.cpp" ); + + CppUnit::Exception e( message, lineNumber, fileName ); + + CPPUNIT_ASSERT_EQUAL( message, std::string( e.what() ) ); + CPPUNIT_ASSERT_EQUAL( lineNumber, int(e.lineNumber()) ); + CPPUNIT_ASSERT_EQUAL( fileName, e.fileName() ); +} + + +void +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() ); +} + + +void +ExceptionTest::testCopyConstructor() +{ + CppUnit::Exception e( "message", 17, "fileName.cpp" ); + CppUnit::Exception other( e ); + checkIsSame( e, other ); +} + + +void +ExceptionTest::testAssignment() +{ + CppUnit::Exception e( "message", 17, "fileName.cpp" ); + CppUnit::Exception other; + other = e; + checkIsSame( e, other ); +} + + +void +ExceptionTest::testClone() +{ + CppUnit::Exception e( "message", 17, "fileName.cpp" ); + std::auto_ptr<CppUnit::Exception> other( e.clone() ); + checkIsSame( e, *other.get() ); +} + + +void +ExceptionTest::testIsInstanceOf() +{ + CppUnit::Exception e( "message", 17, "fileName.cpp" ); + CPPUNIT_ASSERT( e.isInstanceOf( CppUnit::Exception::type() ) ); + CPPUNIT_ASSERT( !e.isInstanceOf( CppUnit::NotEqualException::type() ) ); +} + + +void +ExceptionTest::checkIsSame( CppUnit::Exception &e, + CppUnit::Exception &other ) +{ + 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() ); +} |