test/source/diff/diff.cxx |   43 +++++++++++++++++++++++++++++++++++--------
 1 file changed, 35 insertions(+), 8 deletions(-)

New commits:
commit 093d1a22e497f34f83ef117c1307740f011ca0c1
Author:     Noel Grandin <[email protected]>
AuthorDate: Thu Jan 22 09:14:59 2026 +0200
Commit:     Noel Grandin <[email protected]>
CommitDate: Fri Jan 23 10:25:12 2026 +0100

    improve unit test assert message when diffing
    
    Change-Id: Icffb187e004852ddfd190b42318ff53ba6a0f859
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/197788
    Reviewed-by: Noel Grandin <[email protected]>
    Tested-by: Jenkins

diff --git a/test/source/diff/diff.cxx b/test/source/diff/diff.cxx
index dac6c1e4ed01..fa801ab6c67f 100644
--- a/test/source/diff/diff.cxx
+++ b/test/source/diff/diff.cxx
@@ -81,7 +81,8 @@ private:
     bool compareElements(xmlNode* node1, xmlNode* node2);
 
     /// Error message for cppunit that prints out when expected and found are 
not equal.
-    void cppunitAssertEqual(const xmlChar *expected, const xmlChar *found);
+    void cppunitAssertEqual(const xmlNodePtr node, const xmlAttrPtr attr, 
const xmlChar *expected, const xmlChar *found);
+    void cppunitAssertEqual(const xmlNodePtr node, const xmlChar *expected, 
const xmlChar *found);
 
     /// Error message for cppunit that prints out when expected and found are 
not equal - for doubles.
     void cppunitAssertEqualDouble(const xmlNodePtr node, const xmlAttrPtr 
attr, double expected, double found, double delta);
@@ -173,7 +174,7 @@ bool XMLDiff::compare()
 #if USE_CPPUNIT
     CPPUNIT_ASSERT(root1);
     CPPUNIT_ASSERT(root2);
-    cppunitAssertEqual(root1->name, root2->name);
+    cppunitAssertEqual(nullptr, root1->name, root2->name);
 #else
     if (!root1 || !root2)
         return false;
@@ -203,7 +204,7 @@ bool checkForEmptyChildren(xmlNodePtr node)
 bool XMLDiff::compareElements(xmlNode* node1, xmlNode* node2)
 {
 #if USE_CPPUNIT
-    cppunitAssertEqual(node1->name, node2->name);
+    cppunitAssertEqual(nullptr, node1->name, node2->name);
 #else
     if (!xmlStrEqual( node1->name, node2->name ))
         return false;
@@ -244,11 +245,34 @@ bool XMLDiff::compareElements(xmlNode* node1, xmlNode* 
node2)
     return true;
 }
 
-void XMLDiff::cppunitAssertEqual(const xmlChar *expected, const xmlChar *found)
+void XMLDiff::cppunitAssertEqual(const xmlNodePtr node, const xmlAttrPtr attr, 
const xmlChar *expected, const xmlChar *found)
 {
 #if USE_CPPUNIT
+    xmlChar * path = xmlGetNodePath(node);
+    std::stringstream stringStream;
+    stringStream
+        << "Reference: " << fileName
+        << "
- Node: " << (path ? reinterpret_cast<const char*>(path) : "null")
+        << "
- Attr: " << (attr ? reinterpret_cast<const char*>(attr->name) : "null")
+        << "
- Expected: " << reinterpret_cast<const char*>(expected)
+        << "
- Found: " << reinterpret_cast<const char*>(found);
+    xmlFree(path);
+
+    CPPUNIT_ASSERT_MESSAGE(stringStream.str(), xmlStrEqual(expected, found));
+#endif
+}
+
+void XMLDiff::cppunitAssertEqual(const xmlNodePtr node, const xmlChar 
*expected, const xmlChar *found)
+{
+#if USE_CPPUNIT
+    xmlChar * path = xmlGetNodePath(node);
     std::stringstream stringStream;
-    stringStream << "Reference: " << fileName << "
- Expected: " << reinterpret_cast<const char*>(expected) << "
- Found: " << reinterpret_cast<const char*>(found);
+    stringStream
+        << "Reference: " << fileName
+        << "
- Parent Node: " << (path ? reinterpret_cast<const char*>(path) : "null")
+        << "
- Expected Child Node: " << reinterpret_cast<const char*>(expected)
+        << "
- Found Child Node: " << reinterpret_cast<const char*>(found);
+    xmlFree(path);
 
     CPPUNIT_ASSERT_MESSAGE(stringStream.str(), xmlStrEqual(expected, found));
 #endif
@@ -259,7 +283,10 @@ void XMLDiff::cppunitAssertEqualDouble(const xmlNodePtr 
node, const xmlAttrPtr a
 #if USE_CPPUNIT
     xmlChar * path = xmlGetNodePath(node);
     std::stringstream stringStream;
-    stringStream << "Reference: " << fileName << "
- Node: " << reinterpret_cast<const char*>(path) << "
- Attr: " << reinterpret_cast<const char*>(attr->name);
+    stringStream
+        << "Reference: " << fileName
+        << "
- Node: " << reinterpret_cast<const char*>(path)
+        << "
- Attr: " << reinterpret_cast<const char*>(attr->name);
     xmlFree(path);
 
     CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(stringStream.str(), expected, found, 
delta);
@@ -291,7 +318,7 @@ bool XMLDiff::compareAttributes(xmlNodePtr node1, 
xmlNodePtr node2)
     for(attr1 = node1->properties, attr2 = node2->properties; attr1 != nullptr 
&& attr2 != nullptr; attr1 = attr1->next, attr2 = attr2->next)
     {
 #if USE_CPPUNIT
-        cppunitAssertEqual(attr1->name, attr2->name);
+        cppunitAssertEqual(node1, attr1->name, attr2->name);
 #else
         if (!xmlStrEqual( attr1->name, attr2->name ))
             return false;
@@ -343,7 +370,7 @@ bool XMLDiff::compareAttributes(xmlNodePtr node1, 
xmlNodePtr node2)
         {
 
 #if USE_CPPUNIT
-            cppunitAssertEqual(val1, val2);
+            cppunitAssertEqual(node1, attr1, val1, val2);
 #else
             if(!xmlStrEqual( val1, val2 ))
                 return false;

Reply via email to