From 811899e4a28f8b37c23c07fc524dbf1f3c1b6fb5 Mon Sep 17 00:00:00 2001 From: Markus Mohrhard Date: Fri, 27 Apr 2012 02:59:16 +0200 Subject: improve assert messages --- test/source/diff/diff.cxx | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/test/source/diff/diff.cxx b/test/source/diff/diff.cxx index 6b97f298b3b1..4d130232b881 100644 --- a/test/source/diff/diff.cxx +++ b/test/source/diff/diff.cxx @@ -31,6 +31,7 @@ #include #include #include +#include #include #include @@ -94,7 +95,7 @@ void XMLDiff::loadToleranceFile(xmlDocPtr xmlToleranceFile) { xmlNodePtr root = xmlDocGetRootElement(xmlToleranceFile); #if USE_CPPUNIT - CPPUNIT_ASSERT_MESSAGE("did not find tolerance file", xmlStrEqual( root->name, BAD_CAST("tolerances") )); + CPPUNIT_ASSERT_MESSAGE("did not find correct tolerance file", xmlStrEqual( root->name, BAD_CAST("tolerances") )); #else if(!xmlStrEqual( root->name, BAD_CAST("tolerances") )) { @@ -125,7 +126,9 @@ bool XMLDiff::compare() #if USE_CPPUNIT CPPUNIT_ASSERT(root1); CPPUNIT_ASSERT(root2); - CPPUNIT_ASSERT(xmlStrEqual(root1->name, root2->name)); + std::stringstream stringStream("Expected: "); + stringStream << (char*)root1->name << "\nFound: " << (char*) root2->name; + CPPUNIT_ASSERT(stringStream.str(), xmlStrEqual(root1->name, root2->name)); #else if (!root1 || !root2) return false; @@ -155,7 +158,9 @@ bool checkForEmptyChildren(xmlNodePtr node) bool XMLDiff::compareElements(xmlNode* node1, xmlNode* node2) { #if USE_CPPUNIT - CPPUNIT_ASSERT(xmlStrEqual( node1->name, node2->name )); + std::stringstream stringStream("Expected: "); + stringStream << (xmlChar*) node1->name << "\nFound: " << node2->name; + CPPUNIT_ASSERT_MESSAGE(stringStream.str(), xmlStrEqual( node1->name, node2->name )); #else if (!xmlStrEqual( node1->name, node2->name )) return false; @@ -248,7 +253,10 @@ bool XMLDiff::compareAttributes(xmlNodePtr node1, xmlNodePtr node2) { bool valInTolerance = compareValuesWithTolerance(dVal1, dVal2, itr->value, itr->relative); #if USE_CPPUNIT - CPPUNIT_ASSERT(valInTolerance); + std::stringstream stringStream("Expected Value: "); + stringStream << dVal1 << "; Found Value: " << dVal2 << "; Tolerance: " << itr->value; + stringStream << "; Relative: " << itr->relative; + CPPUNIT_ASSERT_MESSAGE(stringStream.str(), valInTolerance); #else if (!valInTolerance) return false; @@ -268,10 +276,12 @@ bool XMLDiff::compareAttributes(xmlNodePtr node1, xmlNodePtr node2) { #if USE_CPPUNIT - CPPUNIT_ASSERT(xmlStrEqual(val1, val2)); + std::stringstream stringStream("Expected: "); + stringStream << (char*)val1 << "\nFound: " << (char*)val2; + CPPUNIT_ASSERT_MESSAGE(stringStream.str(), xmlStrEqual(val1, val2)); #else - if(!xmlStrEqual( val1, val2 )) - return false; + if(!xmlStrEqual( val1, val2 )) + return false; #endif } -- cgit