From da8e822d28d281276f4cef78b7e7c7f2660de232 Mon Sep 17 00:00:00 2001 From: Baptiste Lepilleur Date: Mon, 11 Jun 2001 19:00:52 +0000 Subject: Include/cppunit/Exception. include/cppunit/Exception.h: now inherit from std::exception instead of ::exception. Added clone(), type(), and isInstanceOf() methods for subclassing support. Changed UNKNOWNLINENUMBER type to long for consistence with lineNumber(). * include/cppunit/NotEqualException.h: addded, exception to be used with assertEquals(). * include/cppunit/TestAssert.h: changed TestAssert into a namespace instead of a class. This remove the need of template member methods and does not cause compiler internal error on VC++. Macro CPPUNIT_ASSERT_MESSAGE has been added to fail test with a specified message. * include/cppunit/TestCaller.h: added "Expected exception" support. Based on Tim Jansen patch (#403745), but use a traits instead of RTTI to distingh between "No expected exception" and "Excepted exception". Exception type name is reported using RTTI if CPPUNIT_USE_TYPEINFO is defined. --- include/cppunit/Exception.h | 47 +++++++++++++++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 14 deletions(-) (limited to 'include/cppunit/Exception.h') diff --git a/include/cppunit/Exception.h b/include/cppunit/Exception.h index eb43119..d324e9e 100644 --- a/include/cppunit/Exception.h +++ b/include/cppunit/Exception.h @@ -12,31 +12,50 @@ namespace CppUnit { * */ - class Exception : public exception + class Exception : public std::exception { public: - Exception (std::string message = "", - long lineNumber = UNKNOWNLINENUMBER, - std::string fileName = UNKNOWNFILENAME); + class Type + { + public: + Type( std::string type ) : m_type ( type ) {} + + bool operator ==( const Type &other ) const + { + return m_type == other.m_type; + } + private: + const std::string m_type; + }; + + + Exception( std::string message = "", + long lineNumber = UNKNOWNLINENUMBER, + std::string fileName = UNKNOWNFILENAME); Exception (const Exception& other); - virtual ~Exception (); + virtual ~Exception (); - Exception& operator= (const Exception& other); + Exception& operator= (const Exception& other); - const char *what() const throw (); + const char *what() const throw (); - long lineNumber (); - std::string fileName (); + long lineNumber (); + std::string fileName (); static const std::string UNKNOWNFILENAME; - static const int UNKNOWNLINENUMBER; + static const long UNKNOWNLINENUMBER; - private: - std::string m_message; - long m_lineNumber; - std::string m_fileName; + virtual Exception *clone() const; + virtual bool isInstanceOf( const Type &type ) const; + + static Type type(); + + private: + std::string m_message; + long m_lineNumber; + std::string m_fileName; }; } // namespace CppUnit -- cgit v1.2.1