sc/qa/unit/PivotTableFormatsImportExport.cxx |  620 +++++++++++++--------------
 1 file changed, 316 insertions(+), 304 deletions(-)

New commits:
commit 9d59980dfdad0e1425f6a49507b5f97995481930
Author:     Caolán McNamara <caolan.mcnam...@collabora.com>
AuthorDate: Wed May 1 08:44:47 2024 +0100
Commit:     Caolán McNamara <caolan.mcnam...@collabora.com>
CommitDate: Wed May 1 11:05:45 2024 +0200

    rearrange PivotTableFormatsImportExport to avoid clang crash
    
    apparently related to lambdas
    
    Change-Id: Iff0f2a411b4651e4902c348ae0dedc573c8512f5
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/166950
    Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com>
    Tested-by: Jenkins

diff --git a/sc/qa/unit/PivotTableFormatsImportExport.cxx 
b/sc/qa/unit/PivotTableFormatsImportExport.cxx
index 0ea8888867a1..3477d574918c 100644
--- a/sc/qa/unit/PivotTableFormatsImportExport.cxx
+++ b/sc/qa/unit/PivotTableFormatsImportExport.cxx
@@ -76,241 +76,249 @@ template <typename T> OUString 
checkNonEmptyAddresses(ScDocument& rDoc, T const&
 
 } // end anonymous namespace
 
+static void assertDataFieldInRow_RowLabelColor(ScDocument& rDoc)
+{
+    CPPUNIT_ASSERT_EQUAL(COL_YELLOW, getBackgroundColor(rDoc, u"G6"_ustr));
+    CPPUNIT_ASSERT_EQUAL(COL_LIGHTRED, getFontColor(rDoc, u"G7"_ustr));
+
+    // Make sure the other cells have the font color or background set to 
default
+    auto aEmptyAddresses = std::to_array<OUString>({
+        u"G5"_ustr,
+        u"H5"_ustr,
+        u"I5"_ustr,
+        u"J5"_ustr,
+        u"K5"_ustr,
+        u"H6"_ustr,
+        u"I6"_ustr,
+        u"J6"_ustr,
+        u"K6"_ustr,
+        u"H7"_ustr,
+        u"I7"_ustr,
+        u"J7"_ustr,
+        u"K7"_ustr,
+    });
+    CPPUNIT_ASSERT_EQUAL(OUString(), checkNonEmptyAddresses(rDoc, 
aEmptyAddresses));
+}
+
 CPPUNIT_TEST_FIXTURE(ScPivotTableFormatsImportExport,
                      testPivotTableCellFormat_1_DataFieldInRow_RowLabelColor)
 {
-    auto assertDocument = [](ScDocument& rDoc) {
-        CPPUNIT_ASSERT_EQUAL(COL_YELLOW, getBackgroundColor(rDoc, u"G6"_ustr));
-        CPPUNIT_ASSERT_EQUAL(COL_LIGHTRED, getFontColor(rDoc, u"G7"_ustr));
-
-        // Make sure the other cells have the font color or background set to 
default
-        auto aEmptyAddresses = std::to_array<OUString>({
-            u"G5"_ustr,
-            u"H5"_ustr,
-            u"I5"_ustr,
-            u"J5"_ustr,
-            u"K5"_ustr,
-            u"H6"_ustr,
-            u"I6"_ustr,
-            u"J6"_ustr,
-            u"K6"_ustr,
-            u"H7"_ustr,
-            u"I7"_ustr,
-            u"J7"_ustr,
-            u"K7"_ustr,
-        });
-        CPPUNIT_ASSERT_EQUAL(OUString(), checkNonEmptyAddresses(rDoc, 
aEmptyAddresses));
-    };
-
     
createScDoc("xlsx/pivot-table/PivotTableCellFormatsTest_1_DataFieldInRow_RowLabelColor.xlsx");
-    assertDocument(*getScDoc());
+    assertDataFieldInRow_RowLabelColor(*getScDoc());
     saveAndReload("Calc Office Open XML");
-    assertDocument(*getScDoc());
+    assertDataFieldInRow_RowLabelColor(*getScDoc());
+}
+
+static void assertDataFieldInRow_ColumnLabelColor(ScDocument& rDoc)
+{
+    CPPUNIT_ASSERT_EQUAL(Color(0x00B050), getBackgroundColor(rDoc, 
u"H5"_ustr));
+
+    // Make sure the other cells have the font color or background set to 
default
+    auto aEmptyAddresses = std::to_array<OUString>({
+        u"G5"_ustr,
+        u"I5"_ustr,
+        u"J5"_ustr,
+        u"K5"_ustr,
+        u"G6"_ustr,
+        u"H6"_ustr,
+        u"I6"_ustr,
+        u"J6"_ustr,
+        u"K6"_ustr,
+        u"G7"_ustr,
+        u"H7"_ustr,
+        u"I7"_ustr,
+        u"J7"_ustr,
+        u"K7"_ustr,
+    });
+    CPPUNIT_ASSERT_EQUAL(OUString(), checkNonEmptyAddresses(rDoc, 
aEmptyAddresses));
 }
 
 CPPUNIT_TEST_FIXTURE(ScPivotTableFormatsImportExport,
                      
PivotTableCellFormatsTest_2_DataFieldInRow_ColumnLabelColor)
 {
-    auto assertDocument = [](ScDocument& rDoc) {
-        CPPUNIT_ASSERT_EQUAL(Color(0x00B050), getBackgroundColor(rDoc, 
u"H5"_ustr));
-
-        // Make sure the other cells have the font color or background set to 
default
-        auto aEmptyAddresses = std::to_array<OUString>({
-            u"G5"_ustr,
-            u"I5"_ustr,
-            u"J5"_ustr,
-            u"K5"_ustr,
-            u"G6"_ustr,
-            u"H6"_ustr,
-            u"I6"_ustr,
-            u"J6"_ustr,
-            u"K6"_ustr,
-            u"G7"_ustr,
-            u"H7"_ustr,
-            u"I7"_ustr,
-            u"J7"_ustr,
-            u"K7"_ustr,
-        });
-        CPPUNIT_ASSERT_EQUAL(OUString(), checkNonEmptyAddresses(rDoc, 
aEmptyAddresses));
-    };
-
     createScDoc(
         
"xlsx/pivot-table/PivotTableCellFormatsTest_2_DataFieldInRow_ColumnLabelColor.xlsx");
-    assertDocument(*getScDoc());
+    assertDataFieldInRow_ColumnLabelColor(*getScDoc());
     saveAndReload("Calc Office Open XML");
-    assertDocument(*getScDoc());
+    assertDataFieldInRow_ColumnLabelColor(*getScDoc());
+}
+
+static void assertDataFieldInColumn_ColumnLabelColor(ScDocument& rDoc)
+{
+    CPPUNIT_ASSERT_EQUAL(COL_LIGHTRED, getFontColor(rDoc, u"H5"_ustr));
+    CPPUNIT_ASSERT_EQUAL(Color(0x92D050), getBackgroundColor(rDoc, 
u"I5"_ustr));
+
+    // Make sure the other cells have the font color or background set to 
default
+    auto aEmptyAddresses = std::to_array<OUString>({
+        u"G5"_ustr,
+        u"G6"_ustr,
+        u"H6"_ustr,
+        u"I6"_ustr,
+        u"G7"_ustr,
+        u"H7"_ustr,
+        u"I7"_ustr,
+        u"G8"_ustr,
+        u"H8"_ustr,
+        u"I8"_ustr,
+        u"G9"_ustr,
+        u"H9"_ustr,
+        u"I9"_ustr,
+    });
+    CPPUNIT_ASSERT_EQUAL(OUString(), checkNonEmptyAddresses(rDoc, 
aEmptyAddresses));
 }
 
 CPPUNIT_TEST_FIXTURE(ScPivotTableFormatsImportExport,
                      
PivotTableCellFormatsTest_3_DataFieldInColumn_ColumnLabelColor)
 {
-    auto assertDocument = [](ScDocument& rDoc) {
-        CPPUNIT_ASSERT_EQUAL(COL_LIGHTRED, getFontColor(rDoc, u"H5"_ustr));
-        CPPUNIT_ASSERT_EQUAL(Color(0x92D050), getBackgroundColor(rDoc, 
u"I5"_ustr));
-
-        // Make sure the other cells have the font color or background set to 
default
-        auto aEmptyAddresses = std::to_array<OUString>({
-            u"G5"_ustr,
-            u"G6"_ustr,
-            u"H6"_ustr,
-            u"I6"_ustr,
-            u"G7"_ustr,
-            u"H7"_ustr,
-            u"I7"_ustr,
-            u"G8"_ustr,
-            u"H8"_ustr,
-            u"I8"_ustr,
-            u"G9"_ustr,
-            u"H9"_ustr,
-            u"I9"_ustr,
-        });
-        CPPUNIT_ASSERT_EQUAL(OUString(), checkNonEmptyAddresses(rDoc, 
aEmptyAddresses));
-    };
-
     createScDoc(
         
"xlsx/pivot-table/PivotTableCellFormatsTest_3_DataFieldInColumn_ColumnLabelColor.xlsx");
-    assertDocument(*getScDoc());
+    assertDataFieldInColumn_ColumnLabelColor(*getScDoc());
     saveAndReload("Calc Office Open XML");
-    assertDocument(*getScDoc());
+    assertDataFieldInColumn_ColumnLabelColor(*getScDoc());
+}
+
+static void assertDataFieldInColumn_DataColor(ScDocument& rDoc)
+{
+    CPPUNIT_ASSERT_EQUAL(COL_LIGHTRED, getFontColor(rDoc, u"H7"_ustr));
+    CPPUNIT_ASSERT_EQUAL(Color(0x92D050), getBackgroundColor(rDoc, 
u"I9"_ustr));
+
+    auto aEmptyAddresses = std::to_array<OUString>({
+        u"G5"_ustr,
+        u"H5"_ustr,
+        u"I5"_ustr,
+        u"G6"_ustr,
+        u"H6"_ustr,
+        u"I6"_ustr,
+        u"G7"_ustr,
+        u"I7"_ustr,
+        u"G8"_ustr,
+        u"H8"_ustr,
+        u"I8"_ustr,
+        u"G9"_ustr,
+        u"H9"_ustr,
+    });
+    CPPUNIT_ASSERT_EQUAL(OUString(), checkNonEmptyAddresses(rDoc, 
aEmptyAddresses));
 }
 
 CPPUNIT_TEST_FIXTURE(ScPivotTableFormatsImportExport,
                      PivotTableCellFormatsTest_4_DataFieldInColumn_DataColor)
 {
-    auto assertDocument = [](ScDocument& rDoc) {
-        CPPUNIT_ASSERT_EQUAL(COL_LIGHTRED, getFontColor(rDoc, u"H7"_ustr));
-        CPPUNIT_ASSERT_EQUAL(Color(0x92D050), getBackgroundColor(rDoc, 
u"I9"_ustr));
-
-        auto aEmptyAddresses = std::to_array<OUString>({
-            u"G5"_ustr,
-            u"H5"_ustr,
-            u"I5"_ustr,
-            u"G6"_ustr,
-            u"H6"_ustr,
-            u"I6"_ustr,
-            u"G7"_ustr,
-            u"I7"_ustr,
-            u"G8"_ustr,
-            u"H8"_ustr,
-            u"I8"_ustr,
-            u"G9"_ustr,
-            u"H9"_ustr,
-        });
-        CPPUNIT_ASSERT_EQUAL(OUString(), checkNonEmptyAddresses(rDoc, 
aEmptyAddresses));
-    };
-
     
createScDoc("xlsx/pivot-table/PivotTableCellFormatsTest_4_DataFieldInColumn_DataColor.xlsx");
-    assertDocument(*getScDoc());
+    assertDataFieldInColumn_DataColor(*getScDoc());
     saveAndReload("Calc Office Open XML");
-    assertDocument(*getScDoc());
+    assertDataFieldInColumn_DataColor(*getScDoc());
+}
+
+static void assertDataFieldInColumnAndTwoRowFields_DataColor(ScDocument& rDoc)
+{
+    CPPUNIT_ASSERT_EQUAL(COL_YELLOW, getBackgroundColor(rDoc, u"I8"_ustr));
+    CPPUNIT_ASSERT_EQUAL(COL_LIGHTRED, getBackgroundColor(rDoc, u"I11"_ustr));
+    CPPUNIT_ASSERT_EQUAL(Color(0x0070C0), getBackgroundColor(rDoc, 
u"J13"_ustr));
+
+    auto aEmptyAddresses = std::to_array<OUString>({
+        u"G5"_ustr,  u"H5"_ustr,  u"I5"_ustr,  u"J5"_ustr,  u"G6"_ustr,  
u"H6"_ustr,  u"I6"_ustr,
+        u"J6"_ustr,  u"G7"_ustr,  u"H7"_ustr,  u"I7"_ustr,  u"J7"_ustr,  
u"G8"_ustr,  u"H8"_ustr,
+        u"J8"_ustr,  u"G9"_ustr,  u"H9"_ustr,  u"I9"_ustr,  u"J9"_ustr,  
u"G10"_ustr, u"H10"_ustr,
+        u"I10"_ustr, u"J10"_ustr, u"G11"_ustr, u"H11"_ustr, u"J11"_ustr, 
u"G12"_ustr, u"H12"_ustr,
+        u"I12"_ustr, u"J12"_ustr, u"G13"_ustr, u"H13"_ustr, u"I13"_ustr, 
u"G14"_ustr, u"H14"_ustr,
+        u"I14"_ustr, u"J14"_ustr,
+    });
+    CPPUNIT_ASSERT_EQUAL(OUString(), checkNonEmptyAddresses(rDoc, 
aEmptyAddresses));
 }
 
 CPPUNIT_TEST_FIXTURE(ScPivotTableFormatsImportExport,
                      
PivotTableCellFormatsTest_5_DataFieldInColumnAndTwoRowFields_DataColor)
 {
-    auto assertDocument = [](ScDocument& rDoc) {
-        CPPUNIT_ASSERT_EQUAL(COL_YELLOW, getBackgroundColor(rDoc, u"I8"_ustr));
-        CPPUNIT_ASSERT_EQUAL(COL_LIGHTRED, getBackgroundColor(rDoc, 
u"I11"_ustr));
-        CPPUNIT_ASSERT_EQUAL(Color(0x0070C0), getBackgroundColor(rDoc, 
u"J13"_ustr));
-
-        auto aEmptyAddresses = std::to_array<OUString>({
-            u"G5"_ustr,  u"H5"_ustr,  u"I5"_ustr,  u"J5"_ustr,  u"G6"_ustr,  
u"H6"_ustr,
-            u"I6"_ustr,  u"J6"_ustr,  u"G7"_ustr,  u"H7"_ustr,  u"I7"_ustr,  
u"J7"_ustr,
-            u"G8"_ustr,  u"H8"_ustr,  u"J8"_ustr,  u"G9"_ustr,  u"H9"_ustr,  
u"I9"_ustr,
-            u"J9"_ustr,  u"G10"_ustr, u"H10"_ustr, u"I10"_ustr, u"J10"_ustr, 
u"G11"_ustr,
-            u"H11"_ustr, u"J11"_ustr, u"G12"_ustr, u"H12"_ustr, u"I12"_ustr, 
u"J12"_ustr,
-            u"G13"_ustr, u"H13"_ustr, u"I13"_ustr, u"G14"_ustr, u"H14"_ustr, 
u"I14"_ustr,
-            u"J14"_ustr,
-        });
-        CPPUNIT_ASSERT_EQUAL(OUString(), checkNonEmptyAddresses(rDoc, 
aEmptyAddresses));
-    };
-
     createScDoc("xlsx/pivot-table//"
                 
"PivotTableCellFormatsTest_5_DataFieldInColumnAndTwoRowFields_DataColor.xlsx");
-    assertDocument(*getScDoc());
+    assertDataFieldInColumnAndTwoRowFields_DataColor(*getScDoc());
     saveAndReload("Calc Office Open XML");
-    assertDocument(*getScDoc());
+    assertDataFieldInColumnAndTwoRowFields_DataColor(*getScDoc());
+}
+
+static void assertSingleDataFieldInColumn_DataColor(ScDocument& rDoc)
+{
+    CPPUNIT_ASSERT_EQUAL(COL_YELLOW, getBackgroundColor(rDoc, u"J8"_ustr));
+    CPPUNIT_ASSERT_EQUAL(COL_LIGHTRED, getBackgroundColor(rDoc, u"J12"_ustr));
 }
 
 CPPUNIT_TEST_FIXTURE(ScPivotTableFormatsImportExport,
                      
PivotTableCellFormatsTest_6_SingleDataFieldInColumn_DataColor)
 {
-    auto assertDocument = [](ScDocument& rDoc) {
-        CPPUNIT_ASSERT_EQUAL(COL_YELLOW, getBackgroundColor(rDoc, u"J8"_ustr));
-        CPPUNIT_ASSERT_EQUAL(COL_LIGHTRED, getBackgroundColor(rDoc, 
u"J12"_ustr));
-    };
-
     createScDoc(
         
"xlsx/pivot-table//PivotTableCellFormatsTest_6_SingleDataFieldInColumn_DataColor.xlsx");
-    assertDocument(*getScDoc());
+    assertSingleDataFieldInColumn_DataColor(*getScDoc());
     saveAndReload("Calc Office Open XML");
-    assertDocument(*getScDoc());
+    assertSingleDataFieldInColumn_DataColor(*getScDoc());
+}
+
+static void assertTwoRowTwoColumnFields_DataColor(ScDocument& rDoc)
+{
+    CPPUNIT_ASSERT_EQUAL(COL_YELLOW, getBackgroundColor(rDoc, u"I7"_ustr));
+    CPPUNIT_ASSERT_EQUAL(Color(0xFFC000), getBackgroundColor(rDoc, 
u"J8"_ustr));
+    CPPUNIT_ASSERT_EQUAL(Color(0x0070C0), getBackgroundColor(rDoc, 
u"J9"_ustr));
+    CPPUNIT_ASSERT_EQUAL(Color(0x00B0F0), getBackgroundColor(rDoc, 
u"J13"_ustr));
+    CPPUNIT_ASSERT_EQUAL(Color(0x92D050), getBackgroundColor(rDoc, 
u"K12"_ustr));
+    CPPUNIT_ASSERT_EQUAL(COL_LIGHTRED, getBackgroundColor(rDoc, u"L14"_ustr));
 }
 
 CPPUNIT_TEST_FIXTURE(ScPivotTableFormatsImportExport,
                      
PivotTableCellFormatsTest_7_TwoRowTwoColumnFields_DataColor)
 {
-    auto assertDocument = [](ScDocument& rDoc) {
-        CPPUNIT_ASSERT_EQUAL(COL_YELLOW, getBackgroundColor(rDoc, u"I7"_ustr));
-        CPPUNIT_ASSERT_EQUAL(Color(0xFFC000), getBackgroundColor(rDoc, 
u"J8"_ustr));
-        CPPUNIT_ASSERT_EQUAL(Color(0x0070C0), getBackgroundColor(rDoc, 
u"J9"_ustr));
-        CPPUNIT_ASSERT_EQUAL(Color(0x00B0F0), getBackgroundColor(rDoc, 
u"J13"_ustr));
-        CPPUNIT_ASSERT_EQUAL(Color(0x92D050), getBackgroundColor(rDoc, 
u"K12"_ustr));
-        CPPUNIT_ASSERT_EQUAL(COL_LIGHTRED, getBackgroundColor(rDoc, 
u"L14"_ustr));
-    };
-
     createScDoc(
         
"xlsx/pivot-table//PivotTableCellFormatsTest_7_TwoRowTwoColumnFields_DataColor.xlsx");
-    assertDocument(*getScDoc());
+    assertTwoRowTwoColumnFields_DataColor(*getScDoc());
     saveAndReload("Calc Office Open XML");
-    assertDocument(*getScDoc());
+    assertTwoRowTwoColumnFields_DataColor(*getScDoc());
 }
 
+static void assertDataFieldInRow_DataColor(ScDocument& rDoc)
+{
+    CPPUNIT_ASSERT_EQUAL(Color(0x00B0F0), getBackgroundColor(rDoc, 
u"I6"_ustr));
+    CPPUNIT_ASSERT_EQUAL(COL_YELLOW, getBackgroundColor(rDoc, u"K7"_ustr));
+
+    // Make sure the other cells have the font color or background set to 
default
+    auto aEmptyAddresses = std::to_array<OUString>({
+        u"G5"_ustr,
+        u"H5"_ustr,
+        u"I5"_ustr,
+        u"J5"_ustr,
+        u"K5"_ustr,
+        u"G6"_ustr,
+        u"H6"_ustr,
+        u"J6"_ustr,
+        u"K6"_ustr,
+        u"G7"_ustr,
+        u"H7"_ustr,
+        u"I7"_ustr,
+        u"J7"_ustr,
+    });
+    CPPUNIT_ASSERT_EQUAL(OUString(), checkNonEmptyAddresses(rDoc, 
aEmptyAddresses));
+};
+
 CPPUNIT_TEST_FIXTURE(ScPivotTableFormatsImportExport,
                      PivotTableCellFormatsTest_8_DataFieldInRow_DataColor)
 {
-    auto assertDocument = [](ScDocument& rDoc) {
-        CPPUNIT_ASSERT_EQUAL(Color(0x00B0F0), getBackgroundColor(rDoc, 
u"I6"_ustr));
-        CPPUNIT_ASSERT_EQUAL(COL_YELLOW, getBackgroundColor(rDoc, u"K7"_ustr));
-
-        // Make sure the other cells have the font color or background set to 
default
-        auto aEmptyAddresses = std::to_array<OUString>({
-            u"G5"_ustr,
-            u"H5"_ustr,
-            u"I5"_ustr,
-            u"J5"_ustr,
-            u"K5"_ustr,
-            u"G6"_ustr,
-            u"H6"_ustr,
-            u"J6"_ustr,
-            u"K6"_ustr,
-            u"G7"_ustr,
-            u"H7"_ustr,
-            u"I7"_ustr,
-            u"J7"_ustr,
-        });
-        CPPUNIT_ASSERT_EQUAL(OUString(), checkNonEmptyAddresses(rDoc, 
aEmptyAddresses));
-    };
-
     
createScDoc("xlsx/pivot-table/PivotTableCellFormatsTest_8_DataFieldInRow_DataColor.xlsx");
-    assertDocument(*getScDoc());
+    assertDataFieldInRow_DataColor(*getScDoc());
     saveAndReload("Calc Office Open XML");
-    assertDocument(*getScDoc());
+    assertDataFieldInRow_DataColor(*getScDoc());
+}
+
+static void assertMultipleSelections(ScDocument& rDoc)
+{
+    CPPUNIT_ASSERT_EQUAL(COL_YELLOW, getBackgroundColor(rDoc, u"I6"_ustr));
+    CPPUNIT_ASSERT_EQUAL(COL_YELLOW, getBackgroundColor(rDoc, u"I7"_ustr));
+    CPPUNIT_ASSERT_EQUAL(COL_YELLOW, getBackgroundColor(rDoc, u"I8"_ustr));
 }
 
 CPPUNIT_TEST_FIXTURE(ScPivotTableFormatsImportExport,
                      PivotTableCellFormatsTest_9_MultipleSelections)
 {
-    auto assertDocument = [](ScDocument& rDoc) {
-        CPPUNIT_ASSERT_EQUAL(COL_YELLOW, getBackgroundColor(rDoc, u"I6"_ustr));
-        CPPUNIT_ASSERT_EQUAL(COL_YELLOW, getBackgroundColor(rDoc, u"I7"_ustr));
-        CPPUNIT_ASSERT_EQUAL(COL_YELLOW, getBackgroundColor(rDoc, u"I8"_ustr));
-    };
-
     
createScDoc("xlsx/pivot-table/PivotTableCellFormatsTest_9_MultipleSelections.xlsx");
-    assertDocument(*getScDoc());
+    assertMultipleSelections(*getScDoc());
     saveAndReload("Calc Office Open XML");
-    assertDocument(*getScDoc());
+    assertMultipleSelections(*getScDoc());
 }
 
 CPPUNIT_TEST_FIXTURE(ScPivotTableFormatsImportExport,
@@ -320,8 +328,8 @@ CPPUNIT_TEST_FIXTURE(ScPivotTableFormatsImportExport,
     // a crash during loading and resolving of formats. Specifically
 
     // Load the document, which shouldn't result in a crash
-    createScDoc(
-        
"xlsx/pivot-table/PivotTableCellFormatsTest_10_FormatDefinitionNotMatchingPivotTable.xlsx");
+    createScDoc("xlsx/pivot-table/"
+                
"PivotTableCellFormatsTest_10_FormatDefinitionNotMatchingPivotTable.xlsx");
     ScDocument& rDoc = *getScDoc();
 
     // Let's check the pivot table exists
@@ -335,172 +343,176 @@ CPPUNIT_TEST_FIXTURE(ScPivotTableFormatsImportExport,
     CPPUNIT_ASSERT_EQUAL(u"60"_ustr, rDoc.GetString(aAddress));
 }
 
+static void assertWholeDataColumnSelected(ScDocument& rDoc)
+{
+    CPPUNIT_ASSERT_EQUAL(COL_YELLOW, getBackgroundColor(rDoc, u"G2"_ustr));
+    CPPUNIT_ASSERT_EQUAL(COL_YELLOW, getBackgroundColor(rDoc, u"G3"_ustr));
+    CPPUNIT_ASSERT_EQUAL(COL_YELLOW, getBackgroundColor(rDoc, u"G4"_ustr));
+    CPPUNIT_ASSERT_EQUAL(COL_YELLOW, getBackgroundColor(rDoc, u"G5"_ustr));
+    CPPUNIT_ASSERT_EQUAL(COL_YELLOW, getBackgroundColor(rDoc, u"G6"_ustr));
+    CPPUNIT_ASSERT_EQUAL(COL_YELLOW, getBackgroundColor(rDoc, u"G7"_ustr));
+
+    // Make sure the other cells have the font color or background set to 
default
+    auto aEmptyAddresses = std::to_array<OUString>({
+        u"F1"_ustr,
+        u"G1"_ustr,
+        u"F2"_ustr,
+        u"F3"_ustr,
+        u"F4"_ustr,
+        u"F5"_ustr,
+        u"F6"_ustr,
+        u"F7"_ustr,
+        u"F8"_ustr,
+        u"G8"_ustr,
+    });
+    CPPUNIT_ASSERT_EQUAL(OUString(), checkNonEmptyAddresses(rDoc, 
aEmptyAddresses));
+}
+
 CPPUNIT_TEST_FIXTURE(ScPivotTableFormatsImportExport,
                      PivotTableCellFormatsTest_11_WholeDataColumnSelected)
 {
-    auto assertDocument = [](ScDocument& rDoc) {
-        CPPUNIT_ASSERT_EQUAL(COL_YELLOW, getBackgroundColor(rDoc, u"G2"_ustr));
-        CPPUNIT_ASSERT_EQUAL(COL_YELLOW, getBackgroundColor(rDoc, u"G3"_ustr));
-        CPPUNIT_ASSERT_EQUAL(COL_YELLOW, getBackgroundColor(rDoc, u"G4"_ustr));
-        CPPUNIT_ASSERT_EQUAL(COL_YELLOW, getBackgroundColor(rDoc, u"G5"_ustr));
-        CPPUNIT_ASSERT_EQUAL(COL_YELLOW, getBackgroundColor(rDoc, u"G6"_ustr));
-        CPPUNIT_ASSERT_EQUAL(COL_YELLOW, getBackgroundColor(rDoc, u"G7"_ustr));
-
-        // Make sure the other cells have the font color or background set to 
default
-        auto aEmptyAddresses = std::to_array<OUString>({
-            u"F1"_ustr,
-            u"G1"_ustr,
-            u"F2"_ustr,
-            u"F3"_ustr,
-            u"F4"_ustr,
-            u"F5"_ustr,
-            u"F6"_ustr,
-            u"F7"_ustr,
-            u"F8"_ustr,
-            u"G8"_ustr,
-        });
-        CPPUNIT_ASSERT_EQUAL(OUString(), checkNonEmptyAddresses(rDoc, 
aEmptyAddresses));
-    };
-
     
createScDoc("xlsx/pivot-table/PivotTableCellFormatsTest_11_WholeDataColumnSelected.xlsx");
-    assertDocument(*getScDoc());
+    assertWholeDataColumnSelected(*getScDoc());
     saveAndReload("Calc Office Open XML");
-    assertDocument(*getScDoc());
+    assertWholeDataColumnSelected(*getScDoc());
+}
+
+static void assertWholeLabelColumnSelected(ScDocument& rDoc)
+{
+    CPPUNIT_ASSERT_EQUAL(COL_LIGHTRED, getBackgroundColor(rDoc, u"F2"_ustr));
+    CPPUNIT_ASSERT_EQUAL(COL_LIGHTRED, getBackgroundColor(rDoc, u"F3"_ustr));
+    CPPUNIT_ASSERT_EQUAL(COL_LIGHTRED, getBackgroundColor(rDoc, u"F4"_ustr));
+    CPPUNIT_ASSERT_EQUAL(COL_LIGHTRED, getBackgroundColor(rDoc, u"F5"_ustr));
+    CPPUNIT_ASSERT_EQUAL(COL_LIGHTRED, getBackgroundColor(rDoc, u"F6"_ustr));
+    CPPUNIT_ASSERT_EQUAL(COL_LIGHTRED, getBackgroundColor(rDoc, u"F7"_ustr));
+
+    // Make sure the other cells have the font color or background set to 
default
+    auto aEmptyAddresses = std::to_array<OUString>({
+        u"F1"_ustr,
+        u"G1"_ustr,
+        u"G2"_ustr,
+        u"G3"_ustr,
+        u"G4"_ustr,
+        u"G5"_ustr,
+        u"G6"_ustr,
+        u"G7"_ustr,
+        u"F8"_ustr,
+        u"G8"_ustr,
+    });
+    CPPUNIT_ASSERT_EQUAL(OUString(), checkNonEmptyAddresses(rDoc, 
aEmptyAddresses));
 }
 
 CPPUNIT_TEST_FIXTURE(ScPivotTableFormatsImportExport,
                      PivotTableCellFormatsTest_12_WholeLabelColumnSelected)
 {
-    auto assertDocument = [](ScDocument& rDoc) {
-        CPPUNIT_ASSERT_EQUAL(COL_LIGHTRED, getBackgroundColor(rDoc, 
u"F2"_ustr));
-        CPPUNIT_ASSERT_EQUAL(COL_LIGHTRED, getBackgroundColor(rDoc, 
u"F3"_ustr));
-        CPPUNIT_ASSERT_EQUAL(COL_LIGHTRED, getBackgroundColor(rDoc, 
u"F4"_ustr));
-        CPPUNIT_ASSERT_EQUAL(COL_LIGHTRED, getBackgroundColor(rDoc, 
u"F5"_ustr));
-        CPPUNIT_ASSERT_EQUAL(COL_LIGHTRED, getBackgroundColor(rDoc, 
u"F6"_ustr));
-        CPPUNIT_ASSERT_EQUAL(COL_LIGHTRED, getBackgroundColor(rDoc, 
u"F7"_ustr));
-
-        // Make sure the other cells have the font color or background set to 
default
-        auto aEmptyAddresses = std::to_array<OUString>({
-            u"F1"_ustr,
-            u"G1"_ustr,
-            u"G2"_ustr,
-            u"G3"_ustr,
-            u"G4"_ustr,
-            u"G5"_ustr,
-            u"G6"_ustr,
-            u"G7"_ustr,
-            u"F8"_ustr,
-            u"G8"_ustr,
-        });
-        CPPUNIT_ASSERT_EQUAL(OUString(), checkNonEmptyAddresses(rDoc, 
aEmptyAddresses));
-    };
-
     
createScDoc("xlsx/pivot-table/PivotTableCellFormatsTest_12_WholeLabelColumnSelected.xlsx");
-    assertDocument(*getScDoc());
+    assertWholeLabelColumnSelected(*getScDoc());
     saveAndReload("Calc Office Open XML");
-    assertDocument(*getScDoc());
+    assertWholeLabelColumnSelected(*getScDoc());
+}
+
+static void assertSelectionInLabelAndData(ScDocument& rDoc)
+{
+    CPPUNIT_ASSERT_EQUAL(COL_LIGHTRED, getBackgroundColor(rDoc, u"F5"_ustr));
+    CPPUNIT_ASSERT_EQUAL(COL_LIGHTRED, getBackgroundColor(rDoc, u"G5"_ustr));
+
+    // Make sure the other cells have the font color or background set to 
default
+    auto aEmptyAddresses = std::to_array<OUString>({
+        u"F1"_ustr,
+        u"G1"_ustr,
+        u"F2"_ustr,
+        u"G2"_ustr,
+        u"F3"_ustr,
+        u"G3"_ustr,
+        u"F4"_ustr,
+        u"G4"_ustr,
+        u"F6"_ustr,
+        u"G6"_ustr,
+        u"F7"_ustr,
+        u"G7"_ustr,
+        u"F8"_ustr,
+        u"G8"_ustr,
+    });
+    CPPUNIT_ASSERT_EQUAL(OUString(), checkNonEmptyAddresses(rDoc, 
aEmptyAddresses));
 }
 
 CPPUNIT_TEST_FIXTURE(ScPivotTableFormatsImportExport,
                      PivotTableCellFormatsTest_13_SelectionInLabelAndData)
 {
-    auto assertDocument = [](ScDocument& rDoc) {
-        CPPUNIT_ASSERT_EQUAL(COL_LIGHTRED, getBackgroundColor(rDoc, 
u"F5"_ustr));
-        CPPUNIT_ASSERT_EQUAL(COL_LIGHTRED, getBackgroundColor(rDoc, 
u"G5"_ustr));
-
-        // Make sure the other cells have the font color or background set to 
default
-        auto aEmptyAddresses = std::to_array<OUString>({
-            u"F1"_ustr,
-            u"G1"_ustr,
-            u"F2"_ustr,
-            u"G2"_ustr,
-            u"F3"_ustr,
-            u"G3"_ustr,
-            u"F4"_ustr,
-            u"G4"_ustr,
-            u"F6"_ustr,
-            u"G6"_ustr,
-            u"F7"_ustr,
-            u"G7"_ustr,
-            u"F8"_ustr,
-            u"G8"_ustr,
-        });
-        CPPUNIT_ASSERT_EQUAL(OUString(), checkNonEmptyAddresses(rDoc, 
aEmptyAddresses));
-    };
-
     
createScDoc("xlsx/pivot-table/PivotTableCellFormatsTest_13_SelectionInLabelAndData.xlsx");
-    assertDocument(*getScDoc());
+    assertSelectionInLabelAndData(*getScDoc());
     saveAndReload("Calc Office Open XML");
-    assertDocument(*getScDoc());
+    assertSelectionInLabelAndData(*getScDoc());
+}
+
+static void assertTwoRowsDataFieldInColumn_LabelColor(ScDocument& rDoc)
+{
+    CPPUNIT_ASSERT_EQUAL(COL_YELLOW, getBackgroundColor(rDoc, u"I5"_ustr));
+    CPPUNIT_ASSERT_EQUAL(COL_LIGHTRED, getBackgroundColor(rDoc, u"J5"_ustr));
+
+    // Make sure the other cells have the font color or background set to 
default
+    auto aEmptyAddresses = std::to_array<OUString>({
+        u"G5"_ustr,  u"H5"_ustr,  u"G6"_ustr,  u"H6"_ustr,  u"i6"_ustr,  
u"j6"_ustr,  u"G7"_ustr,
+        u"H7"_ustr,  u"i7"_ustr,  u"j7"_ustr,  u"G8"_ustr,  u"H8"_ustr,  
u"i8"_ustr,  u"j8"_ustr,
+        u"G9"_ustr,  u"H9"_ustr,  u"i9"_ustr,  u"j9"_ustr,  u"G10"_ustr, 
u"H10"_ustr, u"i10"_ustr,
+        u"j10"_ustr, u"G11"_ustr, u"H11"_ustr, u"i11"_ustr, u"j11"_ustr, 
u"G12"_ustr, u"H12"_ustr,
+        u"i12"_ustr, u"j12"_ustr, u"G13"_ustr, u"H13"_ustr, u"i13"_ustr, 
u"j13"_ustr, u"G14"_ustr,
+        u"H14"_ustr, u"i14"_ustr, u"j14"_ustr,
+    });
+    CPPUNIT_ASSERT_EQUAL(OUString(), checkNonEmptyAddresses(rDoc, 
aEmptyAddresses));
 }
 
 CPPUNIT_TEST_FIXTURE(ScPivotTableFormatsImportExport,
                      
PivotTableCellFormatsTest_14_TwoRowsDataFieldInColumn_LabelColor)
 {
-    auto assertDocument = [](ScDocument& rDoc) {
-        CPPUNIT_ASSERT_EQUAL(COL_YELLOW, getBackgroundColor(rDoc, u"I5"_ustr));
-        CPPUNIT_ASSERT_EQUAL(COL_LIGHTRED, getBackgroundColor(rDoc, 
u"J5"_ustr));
-
-        // Make sure the other cells have the font color or background set to 
default
-        auto aEmptyAddresses = std::to_array<OUString>({
-            u"G5"_ustr,  u"H5"_ustr,  u"G6"_ustr,  u"H6"_ustr,  u"i6"_ustr,  
u"j6"_ustr,
-            u"G7"_ustr,  u"H7"_ustr,  u"i7"_ustr,  u"j7"_ustr,  u"G8"_ustr,  
u"H8"_ustr,
-            u"i8"_ustr,  u"j8"_ustr,  u"G9"_ustr,  u"H9"_ustr,  u"i9"_ustr,  
u"j9"_ustr,
-            u"G10"_ustr, u"H10"_ustr, u"i10"_ustr, u"j10"_ustr, u"G11"_ustr, 
u"H11"_ustr,
-            u"i11"_ustr, u"j11"_ustr, u"G12"_ustr, u"H12"_ustr, u"i12"_ustr, 
u"j12"_ustr,
-            u"G13"_ustr, u"H13"_ustr, u"i13"_ustr, u"j13"_ustr, u"G14"_ustr, 
u"H14"_ustr,
-            u"i14"_ustr, u"j14"_ustr,
-        });
-        CPPUNIT_ASSERT_EQUAL(OUString(), checkNonEmptyAddresses(rDoc, 
aEmptyAddresses));
-    };
-
-    createScDoc(
-        
"xlsx/pivot-table/PivotTableCellFormatsTest_14_TwoRowsDataFieldInColumn_LabelColor.xlsx");
-    assertDocument(*getScDoc());
+    createScDoc("xlsx/pivot-table/"
+                
"PivotTableCellFormatsTest_14_TwoRowsDataFieldInColumn_LabelColor.xlsx");
+    assertTwoRowsDataFieldInColumn_LabelColor(*getScDoc());
     saveAndReload("Calc Office Open XML");
-    assertDocument(*getScDoc());
+    assertTwoRowsDataFieldInColumn_LabelColor(*getScDoc());
+}
+
+static void assertTwoDataFieldColumns_WholeDataColumnSelected(ScDocument& rDoc)
+{
+    CPPUNIT_ASSERT_EQUAL(COL_YELLOW, getBackgroundColor(rDoc, u"H3"_ustr));
+    CPPUNIT_ASSERT_EQUAL(COL_YELLOW, getBackgroundColor(rDoc, u"H4"_ustr));
+    CPPUNIT_ASSERT_EQUAL(COL_YELLOW, getBackgroundColor(rDoc, u"H5"_ustr));
+    CPPUNIT_ASSERT_EQUAL(COL_YELLOW, getBackgroundColor(rDoc, u"H6"_ustr));
+    CPPUNIT_ASSERT_EQUAL(COL_YELLOW, getBackgroundColor(rDoc, u"H7"_ustr));
+    CPPUNIT_ASSERT_EQUAL(COL_YELLOW, getBackgroundColor(rDoc, u"H8"_ustr));
+
+    // Make sure the other cells have the font color or background set to 
default
+    auto aEmptyAddresses = std::to_array<OUString>({
+        u"F1"_ustr,
+        u"G1"_ustr,
+        u"H1"_ustr,
+        u"F2"_ustr,
+        u"G2"_ustr,
+        u"H2"_ustr,
+        u"F3"_ustr,
+        u"G3"_ustr,
+        u"F4"_ustr,
+        u"G4"_ustr,
+        u"F5"_ustr,
+        u"G5"_ustr,
+        u"F6"_ustr,
+        u"G6"_ustr,
+        u"F7"_ustr,
+        u"G7"_ustr,
+        u"F8"_ustr,
+        u"G8"_ustr,
+    });
+    CPPUNIT_ASSERT_EQUAL(OUString(), checkNonEmptyAddresses(rDoc, 
aEmptyAddresses));
 }
 
 CPPUNIT_TEST_FIXTURE(ScPivotTableFormatsImportExport,
                      
PivotTableCellFormatsTest_15_TwoDataFieldColumns_WholeDataColumnSelected)
 {
-    auto assertDocument = [](ScDocument& rDoc) {
-        CPPUNIT_ASSERT_EQUAL(COL_YELLOW, getBackgroundColor(rDoc, u"H3"_ustr));
-        CPPUNIT_ASSERT_EQUAL(COL_YELLOW, getBackgroundColor(rDoc, u"H4"_ustr));
-        CPPUNIT_ASSERT_EQUAL(COL_YELLOW, getBackgroundColor(rDoc, u"H5"_ustr));
-        CPPUNIT_ASSERT_EQUAL(COL_YELLOW, getBackgroundColor(rDoc, u"H6"_ustr));
-        CPPUNIT_ASSERT_EQUAL(COL_YELLOW, getBackgroundColor(rDoc, u"H7"_ustr));
-        CPPUNIT_ASSERT_EQUAL(COL_YELLOW, getBackgroundColor(rDoc, u"H8"_ustr));
-
-        // Make sure the other cells have the font color or background set to 
default
-        auto aEmptyAddresses = std::to_array<OUString>({
-            u"F1"_ustr,
-            u"G1"_ustr,
-            u"H1"_ustr,
-            u"F2"_ustr,
-            u"G2"_ustr,
-            u"H2"_ustr,
-            u"F3"_ustr,
-            u"G3"_ustr,
-            u"F4"_ustr,
-            u"G4"_ustr,
-            u"F5"_ustr,
-            u"G5"_ustr,
-            u"F6"_ustr,
-            u"G6"_ustr,
-            u"F7"_ustr,
-            u"G7"_ustr,
-            u"F8"_ustr,
-            u"G8"_ustr,
-        });
-        CPPUNIT_ASSERT_EQUAL(OUString(), checkNonEmptyAddresses(rDoc, 
aEmptyAddresses));
-    };
-
     createScDoc("xlsx/pivot-table/"
                 
"PivotTableCellFormatsTest_15_TwoDataFieldColumns_WholeDataColumnSelected.xlsx");
-    assertDocument(*getScDoc());
+    assertTwoDataFieldColumns_WholeDataColumnSelected(*getScDoc());
     saveAndReload("Calc Office Open XML");
-    assertDocument(*getScDoc());
+    assertTwoDataFieldColumns_WholeDataColumnSelected(*getScDoc());
 }
 
 CPPUNIT_PLUGIN_IMPLEMENT();

Reply via email to