From 2341569fb082d914fd70b3b93af6346715efaddd Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Fri, 3 May 2019 11:50:11 +0200 Subject: improve assert message in XMLDiff Change-Id: I561dca23621075753185d7ea2afc5fd174cd2b3d Reviewed-on: https://gerrit.libreoffice.org/71728 Tested-by: Jenkins Reviewed-by: Noel Grandin --- test/source/diff/diff.cxx | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) (limited to 'test/source/diff') diff --git a/test/source/diff/diff.cxx b/test/source/diff/diff.cxx index e3f7c115d809..483c3954c01a 100644 --- a/test/source/diff/diff.cxx +++ b/test/source/diff/diff.cxx @@ -356,12 +356,29 @@ bool XMLDiff::compareAttributes(xmlNodePtr node1, xmlNodePtr node2) // unequal number of attributes #ifdef CPPUNIT_ASSERT - std::stringstream failStream("Unequal number of attributes "); - - bool bAttr1 = attr1; - if (bAttr1) + if (attr1 || attr2) { - failStream << "Attr1: "; + std::stringstream failStream; + failStream << "Unequal number of attributes in "; + // print chain from document root + std::vector parents; + auto n = node1; + while (n) + { + if (n->name) + parents.push_back(std::string(reinterpret_cast(n->name))); + n = n->parent; + } + bool first = true; + for (auto it = parents.rbegin(); it != parents.rend(); ++it) + { + if (!first) + failStream << "->"; + first = false; + failStream << *it; + } + failStream << " Attr1: "; + attr1 = node1->properties; while (attr1 != nullptr) { xmlChar* val1 = xmlGetProp(node1, attr1->name); @@ -369,14 +386,9 @@ bool XMLDiff::compareAttributes(xmlNodePtr node1, xmlNodePtr node2) xmlFree(val1); attr1 = attr1->next; } - } - CPPUNIT_ASSERT_MESSAGE(failStream.str(), !bAttr1); - - bool bAttr2 = attr2; - if (bAttr2) - { - failStream << "Attr2: "; + failStream << " Attr2: "; + attr2 = node2->properties; while (attr2 != nullptr) { xmlChar* val2 = xmlGetProp(node2, attr2->name); @@ -384,8 +396,8 @@ bool XMLDiff::compareAttributes(xmlNodePtr node1, xmlNodePtr node2) xmlFree(val2); attr2 = attr2->next; } + CPPUNIT_ASSERT_MESSAGE(failStream.str(), false); } - CPPUNIT_ASSERT_MESSAGE(failStream.str(), !bAttr2); #else if (attr1 || attr2) return false; -- cgit