sw/qa/extras/mailmerge/mailmerge.cxx         |   48 ++++++++++++---------------
 sw/qa/extras/mailmerge/mailmerge2.cxx        |   43 +++++++++---------------
 sw/qa/extras/mailmerge/mailmergetestbase.cxx |    6 +--
 3 files changed, 43 insertions(+), 54 deletions(-)

New commits:
commit 27dea7e1fecade10a528d95e484359b8d80f057a
Author:     Xisco Fauli <[email protected]>
AuthorDate: Mon Jul 29 17:32:21 2024 +0200
Commit:     Xisco Fauli <[email protected]>
CommitDate: Mon Jul 29 20:45:38 2024 +0200

    CppunitTest_sw_mailmerge: simplify a bit
    
    Change-Id: I5eacde6d4622a9ff464cc30f6cb6124b1d2ca9af
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/171218
    Reviewed-by: Xisco Fauli <[email protected]>
    Tested-by: Jenkins

diff --git a/sw/qa/extras/mailmerge/mailmerge.cxx 
b/sw/qa/extras/mailmerge/mailmerge.cxx
index f15c46cb0f43..9bea3ee4d9f9 100644
--- a/sw/qa/extras/mailmerge/mailmerge.cxx
+++ b/sw/qa/extras/mailmerge/mailmerge.cxx
@@ -244,27 +244,23 @@ DECLARE_SHELL_MAILMERGE_TEST(testBookmarkCondition, 
"bookmarkcondition.fodt", "b
 {
     executeMailMerge();
 
-    dumpMMLayout();
-    xmlDocUniquePtr pLayout(
-        xmlParseMemory(reinterpret_cast<const 
char*>(xmlBufferContent(mpXmlBuffer)),
-                       xmlBufferLength(mpXmlBuffer)));
-
+    xmlDocUniquePtr pXmlDoc = parseMMLayoutDump();
     // check that conditions on sections and bookmarks are evaluated the same
-    assertXPath(pLayout, "/root/page"_ostr, 7);
-    assertXPath(pLayout, "/root/page[1]/body/section"_ostr, 1);
-    assertXPath(pLayout, 
"/root/page[1]/body/section[1]/txt[1]/SwParaPortion/SwLineLayout"_ostr, 
"portion"_ostr, u"In den Bergen war es anstrengend."_ustr);
-    assertXPath(pLayout, 
"/root/page[1]/body/txt[5]/SwParaPortion/SwLineLayout"_ostr, "portion"_ostr, 
u"Mein Urlaub war anstrengend . "_ustr);
-    assertXPath(pLayout, "/root/page[3]/body/section"_ostr, 1);
-    assertXPath(pLayout, 
"/root/page[3]/body/section[1]/txt[1]/SwParaPortion/SwLineLayout"_ostr, 
"portion"_ostr, u"In Barcelona war es schön."_ustr);
-    assertXPath(pLayout, 
"/root/page[3]/body/txt[5]/SwParaPortion/SwLineLayout"_ostr, "portion"_ostr, 
u"Mein Urlaub war schön . "_ustr);
-    assertXPath(pLayout, "/root/page[5]/body/section"_ostr, 1);
-    assertXPath(pLayout, 
"/root/page[5]/body/section[1]/txt[1]/SwParaPortion/SwLineLayout"_ostr, 
"portion"_ostr, u"In Paris war es erlebnisreich."_ustr);
-    assertXPath(pLayout, 
"/root/page[5]/body/txt[5]/SwParaPortion/SwLineLayout"_ostr, "portion"_ostr, 
u"Mein Urlaub war erlebnisreich . "_ustr);
-    assertXPath(pLayout, "/root/page[7]/body/section"_ostr, 3);
-    assertXPath(pLayout, 
"/root/page[7]/body/section[1]/txt[1]/SwParaPortion/SwLineLayout"_ostr, 
"portion"_ostr, u"In den Bergen war es anstrengend."_ustr);
-    assertXPath(pLayout, 
"/root/page[7]/body/section[2]/txt[1]/SwParaPortion/SwLineLayout"_ostr, 
"portion"_ostr, u"In Barcelona war es schön."_ustr);
-    assertXPath(pLayout, 
"/root/page[7]/body/section[3]/txt[1]/SwParaPortion/SwLineLayout"_ostr, 
"portion"_ostr, u"In Paris war es erlebnisreich."_ustr);
-    assertXPath(pLayout, 
"/root/page[7]/body/txt[5]/SwParaPortion/SwLineLayout"_ostr, "portion"_ostr, 
u"Mein Urlaub war anstrengend schön erlebnisreich . "_ustr);
+    assertXPath(pXmlDoc, "/root/page"_ostr, 7);
+    assertXPath(pXmlDoc, "/root/page[1]/body/section"_ostr, 1);
+    assertXPath(pXmlDoc, 
"/root/page[1]/body/section[1]/txt[1]/SwParaPortion/SwLineLayout"_ostr, 
"portion"_ostr, u"In den Bergen war es anstrengend."_ustr);
+    assertXPath(pXmlDoc, 
"/root/page[1]/body/txt[5]/SwParaPortion/SwLineLayout"_ostr, "portion"_ostr, 
u"Mein Urlaub war anstrengend . "_ustr);
+    assertXPath(pXmlDoc, "/root/page[3]/body/section"_ostr, 1);
+    assertXPath(pXmlDoc, 
"/root/page[3]/body/section[1]/txt[1]/SwParaPortion/SwLineLayout"_ostr, 
"portion"_ostr, u"In Barcelona war es schön."_ustr);
+    assertXPath(pXmlDoc, 
"/root/page[3]/body/txt[5]/SwParaPortion/SwLineLayout"_ostr, "portion"_ostr, 
u"Mein Urlaub war schön . "_ustr);
+    assertXPath(pXmlDoc, "/root/page[5]/body/section"_ostr, 1);
+    assertXPath(pXmlDoc, 
"/root/page[5]/body/section[1]/txt[1]/SwParaPortion/SwLineLayout"_ostr, 
"portion"_ostr, u"In Paris war es erlebnisreich."_ustr);
+    assertXPath(pXmlDoc, 
"/root/page[5]/body/txt[5]/SwParaPortion/SwLineLayout"_ostr, "portion"_ostr, 
u"Mein Urlaub war erlebnisreich . "_ustr);
+    assertXPath(pXmlDoc, "/root/page[7]/body/section"_ostr, 3);
+    assertXPath(pXmlDoc, 
"/root/page[7]/body/section[1]/txt[1]/SwParaPortion/SwLineLayout"_ostr, 
"portion"_ostr, u"In den Bergen war es anstrengend."_ustr);
+    assertXPath(pXmlDoc, 
"/root/page[7]/body/section[2]/txt[1]/SwParaPortion/SwLineLayout"_ostr, 
"portion"_ostr, u"In Barcelona war es schön."_ustr);
+    assertXPath(pXmlDoc, 
"/root/page[7]/body/section[3]/txt[1]/SwParaPortion/SwLineLayout"_ostr, 
"portion"_ostr, u"In Paris war es erlebnisreich."_ustr);
+    assertXPath(pXmlDoc, 
"/root/page[7]/body/txt[5]/SwParaPortion/SwLineLayout"_ostr, "portion"_ostr, 
u"Mein Urlaub war anstrengend schön erlebnisreich . "_ustr);
 }
 
 DECLARE_SHELL_MAILMERGE_TEST_SELECTION(testTdf95292, "linked-labels.odt", 
"10-testing-addresses.ods", "testing-addresses", 5)
diff --git a/sw/qa/extras/mailmerge/mailmerge2.cxx 
b/sw/qa/extras/mailmerge/mailmerge2.cxx
index 941d380e41c6..ff4b68d1dd3b 100644
--- a/sw/qa/extras/mailmerge/mailmerge2.cxx
+++ b/sw/qa/extras/mailmerge/mailmerge2.cxx
@@ -29,10 +29,6 @@ DECLARE_SHELL_MAILMERGE_TEST(tdf125522_shell, 
"tdf125522.odt", "10-testing-addre
     // prepare unit test and run
     executeMailMerge();
 
-    // reset currently opened layout of the original template,
-    // and create the layout of the document with 10 mails inside
-    dumpMMLayout();
-
     // there should be no any text frame in output
     CPPUNIT_ASSERT(mxSwTextDocument);
 
@@ -52,15 +48,11 @@ DECLARE_SHELL_MAILMERGE_TEST(testTd78611_shell, 
"tdf78611.odt", "10-testing-addr
     // prepare unit test and run
     executeMailMerge();
 
-    // reset currently opened layout of the original template,
-    // and create the layout of the document with 10 mails inside
-    dumpMMLayout();
-
     // check: each page (one page is one sub doc) has different paragraphs and 
header paragraphs.
     // All header paragraphs should have numbering.
+    xmlDocUniquePtr pXmlDoc = parseMMLayoutDump();
 
     // check first page
-    xmlDocUniquePtr pXmlDoc = parseLayoutDump();
     assertXPath(pXmlDoc,  
"/root/page[1]/body/txt[6]/SwParaPortion/SwLineLayout/SwFieldPortion"_ostr, 
"expand"_ostr, u"1"_ustr);
     assertXPath(pXmlDoc,  
"/root/page[1]/body/txt[8]/SwParaPortion/SwLineLayout/SwFieldPortion"_ostr, 
"expand"_ostr, u"1.1"_ustr);
     assertXPath(pXmlDoc,  
"/root/page[1]/body/txt[10]/SwParaPortion/SwLineLayout/SwFieldPortion"_ostr, 
"expand"_ostr, u"1.2"_ustr);
@@ -281,13 +273,9 @@ DECLARE_SHELL_MAILMERGE_TEST(testTdf81750_shell, 
"tdf81750.odt", "10-testing-add
     // prepare unit test and run
     executeMailMerge();
 
-    // reset currently opened layout of the original template,
-    // and create the layout of the document with 10 mails inside
-    dumpMMLayout();
-
     // check several pages page
     OUString aExpected(u"Text: Foo "_ustr);
-    xmlDocUniquePtr pXmlDoc = parseLayoutDump();
+    xmlDocUniquePtr pXmlDoc = parseMMLayoutDump();
     assertXPathContent(pXmlDoc, "/root/page[1]/body/txt[2]"_ostr, aExpected);
     assertXPathContent(pXmlDoc, "/root/page[3]/body/txt[2]"_ostr, aExpected);
     assertXPathContent(pXmlDoc, "/root/page[5]/body/txt[2]"_ostr, aExpected);
diff --git a/sw/qa/extras/mailmerge/mailmergetestbase.cxx 
b/sw/qa/extras/mailmerge/mailmergetestbase.cxx
index 1cc2bc35c3a2..f23dfc851367 100644
--- a/sw/qa/extras/mailmerge/mailmergetestbase.cxx
+++ b/sw/qa/extras/mailmerge/mailmergetestbase.cxx
@@ -295,13 +295,13 @@ public:
 
     /**
      Resets currently opened layout of the original template,
-     and creates the layout of the document with N mails inside
+     and returns the layout dump of the document with N mails inside
      (result run with text::MailMergeType::SHELL)
     */
-    void dumpMMLayout()
+    xmlDocUniquePtr parseMMLayoutDump()
     {
-        mpXmlBuffer = xmlBufferPtr();
         dumpLayout(static_cast<SfxBaseModel*>(mxSwTextDocument.get()));
+        return parseLayoutDump();
     }
 
     // Returns page number of the first page of a MM document inside the large 
MM document (used in the SHELL case).
commit 5c60be7cdfabe6fbe55166041f2df19ecdd82f73
Author:     Xisco Fauli <[email protected]>
AuthorDate: Mon Jul 29 16:41:51 2024 +0200
Commit:     Xisco Fauli <[email protected]>
CommitDate: Mon Jul 29 20:45:28 2024 +0200

    CppunitTest_sw_mailmerge: replace usage of parseDump
    
    Change-Id: I04f75abb16249fc384ea63b456696f8edf278b4a
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/171215
    Tested-by: Jenkins
    Reviewed-by: Xisco Fauli <[email protected]>

diff --git a/sw/qa/extras/mailmerge/mailmerge.cxx 
b/sw/qa/extras/mailmerge/mailmerge.cxx
index ce4a890ec97f..f15c46cb0f43 100644
--- a/sw/qa/extras/mailmerge/mailmerge.cxx
+++ b/sw/qa/extras/mailmerge/mailmerge.cxx
@@ -132,11 +132,13 @@ DECLARE_FILE_MAILMERGE_TEST(test2Pages, 
"simple-mail-merge-2pages.odt", "10-test
         CPPUNIT_ASSERT_EQUAL( u"Second page."_ustr, getRun( getParagraph( 5 ), 
1 )->getString());
         CPPUNIT_ASSERT_EQUAL( firstname, getRun( getParagraph( 6 ), 1 
)->getString());
         // Also verify the layout.
-        CPPUNIT_ASSERT_EQUAL( lastname, 
parseDump("/root/page[1]/body/txt[2]/SwParaPortion/SwLineLayout/SwFieldPortion"_ostr,
 "expand"_ostr));
-        CPPUNIT_ASSERT_EQUAL( u"Fixed text."_ustr, 
parseDump("/root/page[1]/body/txt[1]"_ostr, ""_ostr));
-        CPPUNIT_ASSERT_EQUAL( OUString(), 
parseDump("/root/page[1]/body/txt[4]"_ostr, ""_ostr));
-        CPPUNIT_ASSERT_EQUAL( u"Second page."_ustr, 
parseDump("/root/page[2]/body/txt[1]"_ostr, ""_ostr));
-        CPPUNIT_ASSERT_EQUAL( firstname, 
parseDump("/root/page[2]/body/txt[2]/SwParaPortion/SwLineLayout/SwFieldPortion"_ostr,
 "expand"_ostr));
+
+        xmlDocUniquePtr pXmlDoc = parseLayoutDump();
+        assertXPath(pXmlDoc, 
"/root/page[1]/body/txt[2]/SwParaPortion/SwLineLayout/SwFieldPortion"_ostr, 
"expand"_ostr, lastname);
+        assertXPathContent(pXmlDoc, "/root/page[1]/body/txt[1]"_ostr, u"Fixed 
text."_ustr);
+        assertXPathContent(pXmlDoc, "/root/page[1]/body/txt[4]"_ostr, 
OUString());
+        assertXPathContent(pXmlDoc, "/root/page[2]/body/txt[1]"_ostr, u"Second 
page."_ustr);
+        assertXPath(pXmlDoc,  
"/root/page[2]/body/txt[2]/SwParaPortion/SwLineLayout/SwFieldPortion"_ostr, 
"expand"_ostr, firstname);
     }
 }
 
diff --git a/sw/qa/extras/mailmerge/mailmerge2.cxx 
b/sw/qa/extras/mailmerge/mailmerge2.cxx
index 6eb3a35822d7..941d380e41c6 100644
--- a/sw/qa/extras/mailmerge/mailmerge2.cxx
+++ b/sw/qa/extras/mailmerge/mailmerge2.cxx
@@ -60,14 +60,15 @@ DECLARE_SHELL_MAILMERGE_TEST(testTd78611_shell, 
"tdf78611.odt", "10-testing-addr
     // All header paragraphs should have numbering.
 
     // check first page
-    CPPUNIT_ASSERT_EQUAL( u"1"_ustr, 
parseDump("/root/page[1]/body/txt[6]/SwParaPortion/SwLineLayout/SwFieldPortion"_ostr,
 "expand"_ostr));
-    CPPUNIT_ASSERT_EQUAL( u"1.1"_ustr, 
parseDump("/root/page[1]/body/txt[8]/SwParaPortion/SwLineLayout/SwFieldPortion"_ostr,
 "expand"_ostr));
-    CPPUNIT_ASSERT_EQUAL( u"1.2"_ustr, 
parseDump("/root/page[1]/body/txt[10]/SwParaPortion/SwLineLayout/SwFieldPortion"_ostr,
 "expand"_ostr));
+    xmlDocUniquePtr pXmlDoc = parseLayoutDump();
+    assertXPath(pXmlDoc,  
"/root/page[1]/body/txt[6]/SwParaPortion/SwLineLayout/SwFieldPortion"_ostr, 
"expand"_ostr, u"1"_ustr);
+    assertXPath(pXmlDoc,  
"/root/page[1]/body/txt[8]/SwParaPortion/SwLineLayout/SwFieldPortion"_ostr, 
"expand"_ostr, u"1.1"_ustr);
+    assertXPath(pXmlDoc,  
"/root/page[1]/body/txt[10]/SwParaPortion/SwLineLayout/SwFieldPortion"_ostr, 
"expand"_ostr, u"1.2"_ustr);
 
     // check some other pages
-    CPPUNIT_ASSERT_EQUAL( u"1"_ustr, 
parseDump("/root/page[3]/body/txt[6]/SwParaPortion/SwLineLayout/SwFieldPortion"_ostr,
 "expand"_ostr));
-    CPPUNIT_ASSERT_EQUAL( u"1.1"_ustr, 
parseDump("/root/page[5]/body/txt[8]/SwParaPortion/SwLineLayout/SwFieldPortion"_ostr,
 "expand"_ostr));
-    CPPUNIT_ASSERT_EQUAL( u"1.2"_ustr, 
parseDump("/root/page[7]/body/txt[10]/SwParaPortion/SwLineLayout/SwFieldPortion"_ostr,
 "expand"_ostr));
+    assertXPath(pXmlDoc,  
"/root/page[3]/body/txt[6]/SwParaPortion/SwLineLayout/SwFieldPortion"_ostr, 
"expand"_ostr, u"1"_ustr);
+    assertXPath(pXmlDoc,  
"/root/page[5]/body/txt[8]/SwParaPortion/SwLineLayout/SwFieldPortion"_ostr, 
"expand"_ostr, u"1.1"_ustr);
+    assertXPath(pXmlDoc,  
"/root/page[7]/body/txt[10]/SwParaPortion/SwLineLayout/SwFieldPortion"_ostr, 
"expand"_ostr, u"1.2"_ustr);
 }
 
 
@@ -77,9 +78,10 @@ DECLARE_FILE_MAILMERGE_TEST(testTd78611_file, 
"tdf78611.odt", "10-testing-addres
     for (int doc = 0; doc < 10; ++doc)
     {
         loadMailMergeDocument( doc );
-        CPPUNIT_ASSERT_EQUAL( u"1"_ustr, 
parseDump("/root/page[1]/body/txt[6]/SwParaPortion/SwLineLayout/SwFieldPortion"_ostr,
 "expand"_ostr));
-        CPPUNIT_ASSERT_EQUAL( u"1.1"_ustr, 
parseDump("/root/page[1]/body/txt[8]/SwParaPortion/SwLineLayout/SwFieldPortion"_ostr,
 "expand"_ostr));
-        CPPUNIT_ASSERT_EQUAL( u"1.2"_ustr, 
parseDump("/root/page[1]/body/txt[10]/SwParaPortion/SwLineLayout/SwFieldPortion"_ostr,
 "expand"_ostr));
+        xmlDocUniquePtr pXmlDoc = parseLayoutDump();
+        assertXPath(pXmlDoc,  
"/root/page[1]/body/txt[6]/SwParaPortion/SwLineLayout/SwFieldPortion"_ostr, 
"expand"_ostr, u"1"_ustr);
+        assertXPath(pXmlDoc,  
"/root/page[1]/body/txt[8]/SwParaPortion/SwLineLayout/SwFieldPortion"_ostr, 
"expand"_ostr, u"1.1"_ustr);
+        assertXPath(pXmlDoc,  
"/root/page[1]/body/txt[10]/SwParaPortion/SwLineLayout/SwFieldPortion"_ostr, 
"expand"_ostr, u"1.2"_ustr);
     }
 }
 
@@ -285,11 +287,12 @@ DECLARE_SHELL_MAILMERGE_TEST(testTdf81750_shell, 
"tdf81750.odt", "10-testing-add
 
     // check several pages page
     OUString aExpected(u"Text: Foo "_ustr);
-    CPPUNIT_ASSERT_EQUAL( aExpected, 
parseDump("/root/page[1]/body/txt[2]"_ostr, ""_ostr));
-    CPPUNIT_ASSERT_EQUAL( aExpected, 
parseDump("/root/page[3]/body/txt[2]"_ostr, ""_ostr));
-    CPPUNIT_ASSERT_EQUAL( aExpected, 
parseDump("/root/page[5]/body/txt[2]"_ostr, ""_ostr));
-    CPPUNIT_ASSERT_EQUAL( aExpected, 
parseDump("/root/page[7]/body/txt[2]"_ostr, ""_ostr));
-    CPPUNIT_ASSERT_EQUAL( aExpected, 
parseDump("/root/page[9]/body/txt[2]"_ostr, ""_ostr));
+    xmlDocUniquePtr pXmlDoc = parseLayoutDump();
+    assertXPathContent(pXmlDoc, "/root/page[1]/body/txt[2]"_ostr, aExpected);
+    assertXPathContent(pXmlDoc, "/root/page[3]/body/txt[2]"_ostr, aExpected);
+    assertXPathContent(pXmlDoc, "/root/page[5]/body/txt[2]"_ostr, aExpected);
+    assertXPathContent(pXmlDoc, "/root/page[7]/body/txt[2]"_ostr, aExpected);
+    assertXPathContent(pXmlDoc, "/root/page[9]/body/txt[2]"_ostr, aExpected);
 }
 
 

Reply via email to