summaryrefslogtreecommitdiff
path: root/include/cppunit
diff options
context:
space:
mode:
authorBaptiste Lepilleur <gaiacrtn@free.fr>2001-10-05 21:27:15 +0000
committerBaptiste Lepilleur <gaiacrtn@free.fr>2001-10-05 21:27:15 +0000
commitfbd454f554f13680fe62b36fb7a5829f6dc0c396 (patch)
tree4ef06f5085f7e68ebc144dd78560afec3e3aadc2 /include/cppunit
parent6a1755ef0e36aeb1ac2df0a46e5dafe08a4699ee (diff)
downloadcppunit-fbd454f554f13680fe62b36fb7a5829f6dc0c396.tar.gz
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.
Diffstat (limited to 'include/cppunit')
-rw-r--r--include/cppunit/Asserter.h36
-rw-r--r--include/cppunit/Exception.h22
-rw-r--r--include/cppunit/Makefile.am5
-rw-r--r--include/cppunit/NotEqualException.h56
-rw-r--r--include/cppunit/SourceLine.h50
-rw-r--r--include/cppunit/TestAssert.h96
-rw-r--r--include/cppunit/TestFailure.h7
-rw-r--r--include/cppunit/TextTestResult.h7
-rw-r--r--include/cppunit/TextTestRunner.h6
-rw-r--r--include/cppunit/XmlTestResultOutputter.h1
10 files changed, 217 insertions, 69 deletions
diff --git a/include/cppunit/Asserter.h b/include/cppunit/Asserter.h
new file mode 100644
index 0000000..da6cab8
--- /dev/null
+++ b/include/cppunit/Asserter.h
@@ -0,0 +1,36 @@
+#ifndef CPPUNIT_ASSERTER_H
+#define CPPUNIT_ASSERTER_H
+
+#include <cppunit/Portability.h>
+#include <cppunit/SourceLine.h>
+#include <string>
+
+namespace CppUnit
+{
+
+namespace Asserter
+{
+
+ void fail( std::string message,
+ SourceLine sourceLine = SourceLine() );
+
+ void failIf( bool shouldFail,
+ std::string message,
+ SourceLine sourceLine = SourceLine() );
+
+ void failNotEqual( std::string expected,
+ std::string actual,
+ SourceLine sourceLine = SourceLine(),
+ std::string additionalMessage ="" );
+
+ void failNotEqualIf( bool shouldFail,
+ std::string expected,
+ std::string actual,
+ SourceLine sourceLine = SourceLine(),
+ std::string additionalMessage ="" );
+
+} // namespace Asserter
+} // namespace CppUnit
+
+
+#endif // CPPUNIT_ASSERTER_H
diff --git a/include/cppunit/Exception.h b/include/cppunit/Exception.h
index 8be5781..f94eca5 100644
--- a/include/cppunit/Exception.h
+++ b/include/cppunit/Exception.h
@@ -2,6 +2,7 @@
#define CPPUNIT_EXCEPTION_H
#include <cppunit/Portability.h>
+#include <cppunit/SourceLine.h>
#include <exception>
#include <string>
@@ -31,8 +32,14 @@ public:
Exception( std::string message = "",
- long lineNumber = UNKNOWNLINENUMBER,
- std::string fileName = UNKNOWNFILENAME);
+ SourceLine sourceLine = SourceLine() );
+
+#ifdef CPPUNIT_ENABLE_SOURCELINE_DEPRECATED
+ Exception( std::string message,
+ long lineNumber,
+ std::string fileName );
+#endif
+
Exception (const Exception& other);
virtual ~Exception () throw();
@@ -41,11 +48,15 @@ public:
const char *what() const throw ();
- long lineNumber ();
- std::string fileName ();
+ SourceLine sourceLine() const;
+
+#ifdef CPPUNIT_ENABLE_SOURCELINE_DEPRECATED
+ long lineNumber() const;
+ std::string fileName() const;
static const std::string UNKNOWNFILENAME;
static const long UNKNOWNLINENUMBER;
+#endif
virtual Exception *clone() const;
@@ -59,8 +70,7 @@ private:
typedef std::exception SuperClass;
std::string m_message;
- long m_lineNumber;
- std::string m_fileName;
+ SourceLine m_sourceLine;
};
diff --git a/include/cppunit/Makefile.am b/include/cppunit/Makefile.am
index 8dd451c..ed45597 100644
--- a/include/cppunit/Makefile.am
+++ b/include/cppunit/Makefile.am
@@ -7,9 +7,11 @@ libcppunitinclude_HEADERS = \
config-auto.h \
config-msvc6.h \
config-bcb5.h \
+ Asserter.h \
Exception.h \
NotEqualException.h \
Portability.h \
+ SourceLine.h \
Test.h \
TestAssert.h \
TestCase.h \
@@ -20,4 +22,5 @@ libcppunitinclude_HEADERS = \
TestSuite.h \
TextTestResult.h \
TextTestRunner.h \
- TestListener.h
+ TestListener.h \
+ XmlTestResultOutputter.h
diff --git a/include/cppunit/NotEqualException.h b/include/cppunit/NotEqualException.h
index f538222..ba48dbb 100644
--- a/include/cppunit/NotEqualException.h
+++ b/include/cppunit/NotEqualException.h
@@ -7,39 +7,49 @@
namespace CppUnit {
- class NotEqualException : public Exception
- {
- public:
- NotEqualException( std::string expected,
- std::string actual,
- long lineNumber = UNKNOWNLINENUMBER,
- std::string fileName = UNKNOWNFILENAME );
+class NotEqualException : public Exception
+{
+public:
+ NotEqualException( std::string expected,
+ std::string actual,
+ SourceLine sourceLine = SourceLine(),
+ std::string additionalMessage = "" );
- NotEqualException( const NotEqualException &other );
+#ifdef CPPUNIT_ENABLE_SOURCELINE_DEPRECATED
+ NotEqualException( std::string expected,
+ std::string actual,
+ long lineNumber,
+ std::string fileName );
+#endif
+ NotEqualException( const NotEqualException &other );
- virtual ~NotEqualException() throw();
- std::string expectedValue() const;
+ virtual ~NotEqualException() throw();
- std::string actualValue() const;
+ std::string expectedValue() const;
- /*! Copy operator.
- * @param other Object to copy.
- * @return Reference on this object.
- */
- NotEqualException &operator =( const NotEqualException &other );
+ std::string actualValue() const;
- Exception *clone() const;
+ std::string additionalMessage() const;
- bool isInstanceOf( const Type &type ) const;
+ /*! Copy operator.
+ * @param other Object to copy.
+ * @return Reference on this object.
+ */
+ NotEqualException &operator =( const NotEqualException &other );
- static Type type();
+ Exception *clone() const;
- private:
- std::string m_expected;
- std::string m_actual;
- };
+ bool isInstanceOf( const Type &type ) const;
+
+ static Type type();
+
+private:
+ std::string m_expected;
+ std::string m_actual;
+ std::string m_additionalMessage;
+};
} // namespace CppUnit
diff --git a/include/cppunit/SourceLine.h b/include/cppunit/SourceLine.h
new file mode 100644
index 0000000..d80f74b
--- /dev/null
+++ b/include/cppunit/SourceLine.h
@@ -0,0 +1,50 @@
+#ifndef CPPUNIT_SOURCELINE_H
+#define CPPUNIT_SOURCELINE_H
+
+#include <cppunit/Portability.h>
+#include <string>
+
+/** Constructs a SourceLine object initialized with the location where the macro is expanded.
+ * Used to write your own assertion macros.
+ * \see Asserter for example of usage.
+ */
+#define CPPUNIT_SOURCELINE() ::CppUnit::SourceLine( __FILE__, __LINE__ )
+
+
+namespace CppUnit
+{
+
+/*! \class SourceLine
+ * \brief This class represents the location of a line of text in a specified file.
+ */
+class SourceLine
+{
+public:
+ SourceLine();
+
+ SourceLine( const std::string &fileName,
+ int lineNumber );
+
+ /// Destructor.
+ virtual ~SourceLine();
+
+ bool isValid() const;
+
+ int lineNumber() const;
+
+ std::string fileName() const;
+
+ bool operator ==( const SourceLine &other ) const;
+ bool operator !=( const SourceLine &other ) const;
+
+private:
+ std::string m_fileName;
+ int m_lineNumber;
+};
+
+
+} // namespace CppUnit
+
+
+
+#endif // CPPUNIT_SOURCELINE_H
diff --git a/include/cppunit/TestAssert.h b/include/cppunit/TestAssert.h
index 2d7fd18..081591e 100644
--- a/include/cppunit/TestAssert.h
+++ b/include/cppunit/TestAssert.h
@@ -3,7 +3,7 @@
#include <cppunit/Portability.h>
#include <cppunit/Exception.h>
-#include <string>
+#include <cppunit/Asserter.h>
namespace CppUnit {
@@ -27,22 +27,23 @@ namespace CppUnit {
namespace TestAssert
{
+#ifdef CPPUNIT_ENABLE_SOURCELINE_DEPRECATED
void assertImplementation( bool condition,
std::string conditionExpression = "",
- long lineNumber = Exception::UNKNOWNLINENUMBER,
- std::string fileName = Exception::UNKNOWNFILENAME );
+ long lineNumber,
+ std::string fileName );
void assertNotEqualImplementation( std::string expected,
std::string actual,
- long lineNumber = Exception::UNKNOWNLINENUMBER,
- std::string fileName = Exception::UNKNOWNFILENAME );
+ long lineNumber,
+ std::string fileName );
template <class T>
void assertEquals( const T& expected,
const T& actual,
- long lineNumber = Exception::UNKNOWNLINENUMBER,
- std::string fileName = Exception::UNKNOWNFILENAME )
+ long lineNumber,
+ std::string fileName )
{
if ( !assertion_traits<T>::equal(expected,actual) ) // lazy toString conversion...
{
@@ -56,8 +57,30 @@ namespace CppUnit {
void assertEquals( double expected,
double actual,
double delta,
- long lineNumber = Exception::UNKNOWNLINENUMBER,
- std::string fileName = Exception::UNKNOWNFILENAME);
+ long lineNumber,
+ std::string fileName );
+
+#else // using SourceLine
+
+ template <class T>
+ void assertEquals( const T& expected,
+ const T& actual,
+ SourceLine sourceLine )
+ {
+ if ( !assertion_traits<T>::equal(expected,actual) ) // lazy toString conversion...
+ {
+ Asserter::failNotEqual( assertion_traits<T>::toString(expected),
+ assertion_traits<T>::toString(actual),
+ sourceLine );
+ }
+ }
+
+ void assertDoubleEquals( double expected,
+ double actual,
+ double delta,
+ SourceLine sourceLine );
+
+#endif
}
@@ -67,17 +90,15 @@ namespace CppUnit {
* redeeming qualities.
*/
#if CPPUNIT_HAVE_CPP_SOURCE_ANNOTATION
-
-# define CPPUNIT_ASSERT(condition)\
- (CppUnit::TestAssert::assertImplementation ((condition),(#condition),\
- __LINE__, __FILE__))
-
+# define CPPUNIT_ASSERT(condition) \
+ ( ::CppUnit::Asserter::failIf( !(condition), \
+ (#condition), \
+ CPPUNIT_SOURCELINE() ) )
#else
-
-# define CPPUNIT_ASSERT(condition)\
- (CppUnit::TestAssert::assertImplementation ((condition),"",\
- __LINE__, __FILE__))
-
+# define CPPUNIT_ASSERT(condition) \
+ ( ::CppUnit::Asserter::failIf( !(condition), \
+ "", \
+ CPPUNIT_SOURCELINE() ) )
#endif
/** Assertion with a user specified message.
@@ -86,32 +107,41 @@ namespace CppUnit {
* \param condition If this condition evaluates to \c false then the
* test failed.
*/
-#define CPPUNIT_ASSERT_MESSAGE(message,condition)\
- (CppUnit::TestAssert::assertImplementation( condition, \
- message, \
- __LINE__, \
- __FILE__ ) )
+#define CPPUNIT_ASSERT_MESSAGE(message,condition) \
+ ( ::CppUnit::Asserter::failIf( !(condition), \
+ message, \
+ CPPUNIT_SOURCELINE() ) )
/** Failure with a user specified message.
* \param message Message reported in diagnostic.
*/
-#define CPPUNIT_FAIL( message ) \
- CPPUNIT_ASSERT_MESSAGE( message, false )
+#define CPPUNIT_FAIL( message ) \
+ ( ::CppUnit::Asserter::fail( message, \
+ CPPUNIT_SOURCELINE() ) )
+#ifdef CPPUNIT_ENABLE_SOURCELINE_DEPRECATED
/// Generalized macro for primitive value comparisons
/** Equality and string representation can be defined with
* an appropriate assertion_traits class.
* A diagnostic is printed if actual and expected values disagree.
*/
-#define CPPUNIT_ASSERT_EQUAL(expected,actual)\
- (CppUnit::TestAssert::assertEquals ((expected),\
- (actual),__LINE__,__FILE__))
+#define CPPUNIT_ASSERT_EQUAL(expected,actual) \
+ ( ::CppUnit::TestAssert::assertEquals( (expected), \
+ (actual), \
+ __LINE__, __FILE__ ) )
+#else
+#define CPPUNIT_ASSERT_EQUAL(expected,actual) \
+ ( ::CppUnit::TestAssert::assertEquals( (expected), \
+ (actual), \
+ CPPUNIT_SOURCELINE() ) )
+#endif
/// Macro for primitive value comparisons
-#define CPPUNIT_ASSERT_DOUBLES_EQUAL(expected,actual,delta)\
- (CppUnit::TestAssert::assertEquals ((expected),\
- (actual),(delta),__LINE__,__FILE__))
-
+#define CPPUNIT_ASSERT_DOUBLES_EQUAL(expected,actual,delta) \
+ ( ::CppUnit::TestAssert::assertDoubleEquals( (expected), \
+ (actual), \
+ (delta), \
+ CPPUNIT_SOURCELINE() ) )
// Backwards compatibility
diff --git a/include/cppunit/TestFailure.h b/include/cppunit/TestFailure.h
index 9285a1b..2041c8c 100644
--- a/include/cppunit/TestFailure.h
+++ b/include/cppunit/TestFailure.h
@@ -6,8 +6,9 @@
namespace CppUnit {
-class Test;
class Exception;
+class SourceLine;
+class Test;
/*! \brief Record of a failed test execution.
@@ -31,7 +32,11 @@ public:
Exception *thrownException() const;
+ SourceLine sourceLine() const;
+
bool isError() const;
+
+ std::string failedTestName() const;
std::string toString() const;
diff --git a/include/cppunit/TextTestResult.h b/include/cppunit/TextTestResult.h
index 662a054..4558fab 100644
--- a/include/cppunit/TextTestResult.h
+++ b/include/cppunit/TextTestResult.h
@@ -1,11 +1,12 @@
#ifndef CPPUNIT_TEXTTESTRESULT_H
#define CPPUNIT_TEXTTESTRESULT_H
-#include <iostream>
#include <cppunit/TestResult.h>
+#include <iostream>
namespace CppUnit {
+class SourceLine;
class Exception;
class Test;
@@ -28,10 +29,12 @@ class TextTestResult : public TestResult
std::ostream &stream );
virtual void printFailureType( TestFailure *failure,
std::ostream &stream );
- virtual void printFailureLocation( Exception *thrownException,
+ virtual void printFailureLocation( SourceLine sourceLine,
std::ostream &stream );
virtual void printFailureDetail( Exception *thrownException,
std::ostream &stream );
+ virtual void printFailureWarning( std::ostream &stream );
+ virtual void printStatistics( std::ostream &stream );
};
/** insertion operator for easy output */
diff --git a/include/cppunit/TextTestRunner.h b/include/cppunit/TextTestRunner.h
index 5ad6f70..5c5180d 100644
--- a/include/cppunit/TextTestRunner.h
+++ b/include/cppunit/TextTestRunner.h
@@ -33,14 +33,14 @@ public:
TextTestRunner();
virtual ~TextTestRunner();
- void run( std::string testName ="",
+ bool run( std::string testName ="",
bool wait = false );
void addTest( Test *test );
protected:
- void runTest( Test *test );
- void runTestByName( std::string testName );
+ bool runTest( Test *test );
+ bool runTestByName( std::string testName );
void wait( bool doWait );
Test *findTestByName( std::string name ) const;
diff --git a/include/cppunit/XmlTestResultOutputter.h b/include/cppunit/XmlTestResultOutputter.h
index 98952a4..211ce02 100644
--- a/include/cppunit/XmlTestResultOutputter.h
+++ b/include/cppunit/XmlTestResultOutputter.h
@@ -91,6 +91,7 @@ public:
virtual Node *makeFailedTestNode( Test *test,
TestFailure *failure,
int testNumber );
+ virtual Node *makeFailureLocationNode( TestFailure *failure );
virtual Node *makeSucessfulTestNode( Test *test,
int testNumber );
protected: