Kaydet (Commit) 2341569f authored tarafından Noel Grandin's avatar Noel Grandin

improve assert message in XMLDiff

Change-Id: I561dca23621075753185d7ea2afc5fd174cd2b3d
Reviewed-on: https://gerrit.libreoffice.org/71728
Tested-by: Jenkins
Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst 9342656e
...@@ -356,12 +356,29 @@ bool XMLDiff::compareAttributes(xmlNodePtr node1, xmlNodePtr node2) ...@@ -356,12 +356,29 @@ bool XMLDiff::compareAttributes(xmlNodePtr node1, xmlNodePtr node2)
// unequal number of attributes // unequal number of attributes
#ifdef CPPUNIT_ASSERT #ifdef CPPUNIT_ASSERT
std::stringstream failStream("Unequal number of attributes "); if (attr1 || attr2)
bool bAttr1 = attr1;
if (bAttr1)
{ {
failStream << "Attr1: "; std::stringstream failStream;
failStream << "Unequal number of attributes in ";
// print chain from document root
std::vector<std::string> parents;
auto n = node1;
while (n)
{
if (n->name)
parents.push_back(std::string(reinterpret_cast<const char *>(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) while (attr1 != nullptr)
{ {
xmlChar* val1 = xmlGetProp(node1, attr1->name); xmlChar* val1 = xmlGetProp(node1, attr1->name);
...@@ -369,14 +386,9 @@ bool XMLDiff::compareAttributes(xmlNodePtr node1, xmlNodePtr node2) ...@@ -369,14 +386,9 @@ bool XMLDiff::compareAttributes(xmlNodePtr node1, xmlNodePtr node2)
xmlFree(val1); xmlFree(val1);
attr1 = attr1->next; attr1 = attr1->next;
} }
}
CPPUNIT_ASSERT_MESSAGE(failStream.str(), !bAttr1);
bool bAttr2 = attr2;
if (bAttr2)
{
failStream << "Attr2: ";
failStream << " Attr2: ";
attr2 = node2->properties;
while (attr2 != nullptr) while (attr2 != nullptr)
{ {
xmlChar* val2 = xmlGetProp(node2, attr2->name); xmlChar* val2 = xmlGetProp(node2, attr2->name);
...@@ -384,8 +396,8 @@ bool XMLDiff::compareAttributes(xmlNodePtr node1, xmlNodePtr node2) ...@@ -384,8 +396,8 @@ bool XMLDiff::compareAttributes(xmlNodePtr node1, xmlNodePtr node2)
xmlFree(val2); xmlFree(val2);
attr2 = attr2->next; attr2 = attr2->next;
} }
CPPUNIT_ASSERT_MESSAGE(failStream.str(), false);
} }
CPPUNIT_ASSERT_MESSAGE(failStream.str(), !bAttr2);
#else #else
if (attr1 || attr2) if (attr1 || attr2)
return false; return false;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment