summaryrefslogtreecommitdiff
path: root/src/cppunit
diff options
context:
space:
mode:
Diffstat (limited to 'src/cppunit')
-rw-r--r--src/cppunit/NotEqualException.cpp22
-rw-r--r--src/cppunit/TestAssert.cpp19
-rw-r--r--src/cppunit/TextTestResult.cpp19
3 files changed, 51 insertions, 9 deletions
diff --git a/src/cppunit/NotEqualException.cpp b/src/cppunit/NotEqualException.cpp
index 2fe9e76..1615c2b 100644
--- a/src/cppunit/NotEqualException.cpp
+++ b/src/cppunit/NotEqualException.cpp
@@ -7,9 +7,11 @@ NotEqualException::NotEqualException( std::string expected,
std::string actual,
long lineNumber,
std::string fileName ) :
- Exception( "Expected: " + expected + ", but was:" + actual,
+ Exception( "Expected: " + expected + ", but was: " + actual,
lineNumber,
- fileName )
+ fileName ),
+ m_expected( expected ),
+ m_actual( actual )
{
}
@@ -30,6 +32,8 @@ NotEqualException::~NotEqualException()
NotEqualException &
NotEqualException::operator =( const NotEqualException &other )
{
+ Exception::operator =( other );
+
if ( &other != this )
{
m_expected = other.m_expected;
@@ -61,4 +65,18 @@ NotEqualException::type()
}
+std::string
+NotEqualException::expectedValue() const
+{
+ return m_expected;
+}
+
+
+std::string
+NotEqualException::actualValue() const
+{
+ return m_actual;
+}
+
+
} // namespace CppUnit
diff --git a/src/cppunit/TestAssert.cpp b/src/cppunit/TestAssert.cpp
index 2750023..f93c19b 100644
--- a/src/cppunit/TestAssert.cpp
+++ b/src/cppunit/TestAssert.cpp
@@ -2,6 +2,7 @@
#include "cppunit/TestAssert.h"
#include "estring.h"
+#include <cppunit/NotEqualException.h>
namespace CppUnit {
@@ -18,6 +19,16 @@ void TestAssert::assertImplementation (bool condition,
}
+/// Reports failed equality
+void TestAssert::assertNotEqualImplementation( std::string expected,
+ std::string actual,
+ long lineNumber,
+ std::string fileName )
+{
+ throw NotEqualException( expected, actual, lineNumber, fileName );
+}
+
+
/// Check for a failed equality assertion
void TestAssert::assertEquals (double expected,
double actual,
@@ -26,10 +37,10 @@ void TestAssert::assertEquals (double expected,
std::string fileName)
{
if (fabs (expected - actual) > delta)
- assertImplementation (false,
- notEqualsMessage(expected, actual),
- lineNumber,
- fileName);
+ assertNotEqualImplementation( assertion_traits<double>::toString(expected),
+ assertion_traits<double>::toString(actual),
+ lineNumber,
+ fileName );
}
diff --git a/src/cppunit/TextTestResult.cpp b/src/cppunit/TextTestResult.cpp
index cbd226f..115da91 100644
--- a/src/cppunit/TextTestResult.cpp
+++ b/src/cppunit/TextTestResult.cpp
@@ -1,6 +1,7 @@
#include <iostream>
#include "cppunit/TextTestResult.h"
#include "cppunit/Exception.h"
+#include "cppunit/NotEqualException.h"
#include "cppunit/Test.h"
#include "estring.h"
@@ -82,9 +83,21 @@ TextTestResult::printFailures (std::ostream& stream)
<< ") "
<< "test: " << failure->failedTest()->getName() << " "
<< "line: " << (e ? estring (e->lineNumber ()) : "") << " "
- << (e ? e->fileName () : "") << " "
- << "\"" << failure->thrownException ()->what () << "\""
- << std::endl;
+ << (e ? e->fileName () : "") << " ";
+
+ if ( failure->thrownException()->isInstanceOf( NotEqualException::type() ) )
+ {
+ NotEqualException *e = (NotEqualException*)failure->thrownException();
+ stream << std::endl
+ << "expected: " << e->expectedValue() << std::endl
+ << "but was: " << e->actualValue();
+ }
+ else
+ {
+ stream << "\"" << failure->thrownException ()->what () << "\"";
+ }
+
+ stream << std::endl;
i++;
}
}