cid#1640468 Dereference after null check
[LibreOffice.git] / sc / qa / unit / PivotTableFormatsImportExport.cxx
blob437a25d5e7e6692fd5d6a6df040351ca0766e5eb
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
10 #include <sal/config.h>
12 #include "helper/qahelper.hxx"
14 #include <patattr.hxx>
15 #include <document.hxx>
16 #include <dpobject.hxx>
17 #include <attrib.hxx>
18 #include <globstr.hrc>
19 #include <scresid.hxx>
20 #include <rtl/string.hxx>
21 #include <editeng/brushitem.hxx>
22 #include <editeng/colritem.hxx>
24 using namespace css;
26 class ScPivotTableFormatsImportExport : public ScModelTestBase
28 public:
29 ScPivotTableFormatsImportExport();
32 ScPivotTableFormatsImportExport::ScPivotTableFormatsImportExport()
33 : ScModelTestBase(u"sc/qa/unit/data"_ustr)
37 namespace
39 ScAddress parseAddress(ScDocument& rDoc, OUString const& rAddressString)
41 ScAddress aAddress;
42 aAddress.Parse(rAddressString, rDoc);
43 return aAddress;
46 Color getBackgroundColor(ScDocument& rDoc, OUString const& rAddressString)
48 const ScPatternAttr* pPattern = rDoc.GetPattern(parseAddress(rDoc, rAddressString));
49 const SvxBrushItem& rItem = pPattern->GetItem(ATTR_BACKGROUND);
50 return rItem.GetColor();
53 Color getFontColor(ScDocument& rDoc, OUString const& rAddressString)
55 const ScPatternAttr* pPattern = rDoc.GetPattern(parseAddress(rDoc, rAddressString));
56 const SvxColorItem& rItem = pPattern->GetItem(ATTR_FONT_COLOR);
57 return rItem.getColor();
60 bool getCellProtection(ScDocument& rDoc, OUString const& rAddressString)
62 const ScPatternAttr* pPattern = rDoc.GetPattern(parseAddress(rDoc, rAddressString));
63 const ScProtectionAttr& rItem = pPattern->GetItem(ATTR_PROTECTION);
64 return rItem.GetProtection();
67 template <typename T> OUString checkNonEmptyAddresses(ScDocument& rDoc, T const& rArrayOfAddresses)
69 OUString aString;
70 for (auto const& rAddressString : rArrayOfAddresses)
72 ScAddress aAddress;
73 aAddress.Parse(rAddressString, rDoc);
74 const ScPatternAttr* pPattern = rDoc.GetPattern(aAddress);
75 if (pPattern->GetItem(ATTR_FONT_COLOR).getColor() != COL_BLACK
76 || pPattern->GetItem(ATTR_BACKGROUND).GetColor() != COL_TRANSPARENT
77 || !pPattern->GetItem(ATTR_PROTECTION).GetProtection())
79 aString += rAddressString + " ";
82 return aString;
85 } // end anonymous namespace
87 static void assertDataFieldInRow_RowLabelColor(ScDocument& rDoc)
89 CPPUNIT_ASSERT_EQUAL(COL_YELLOW, getBackgroundColor(rDoc, u"G6"_ustr));
90 CPPUNIT_ASSERT_EQUAL(COL_LIGHTRED, getFontColor(rDoc, u"G7"_ustr));
92 // Make sure the other cells have the font color or background set to default
93 std::vector<OUString> aEmptyAddresses{
94 u"G5"_ustr, u"H5"_ustr, u"I5"_ustr, u"J5"_ustr, u"K5"_ustr, u"H6"_ustr, u"I6"_ustr,
95 u"J6"_ustr, u"K6"_ustr, u"H7"_ustr, u"I7"_ustr, u"J7"_ustr, u"K7"_ustr,
97 CPPUNIT_ASSERT_EQUAL(OUString(), checkNonEmptyAddresses(rDoc, aEmptyAddresses));
100 CPPUNIT_TEST_FIXTURE(ScPivotTableFormatsImportExport,
101 testPivotTableCellFormat_1_DataFieldInRow_RowLabelColor)
103 createScDoc("xlsx/pivot-table/PivotTableCellFormatsTest_1_DataFieldInRow_RowLabelColor.xlsx");
104 assertDataFieldInRow_RowLabelColor(*getScDoc());
105 saveAndReload(u"Calc Office Open XML"_ustr);
106 assertDataFieldInRow_RowLabelColor(*getScDoc());
109 static void assertDataFieldInRow_ColumnLabelColor(ScDocument& rDoc)
111 CPPUNIT_ASSERT_EQUAL(Color(0x00B050), getBackgroundColor(rDoc, u"H5"_ustr));
113 // Make sure the other cells have the font color or background set to default
114 std::vector<OUString> aEmptyAddresses{
115 u"G5"_ustr, u"I5"_ustr, u"J5"_ustr, u"K5"_ustr, u"G6"_ustr, u"H6"_ustr, u"I6"_ustr,
116 u"J6"_ustr, u"K6"_ustr, u"G7"_ustr, u"H7"_ustr, u"I7"_ustr, u"J7"_ustr, u"K7"_ustr,
118 CPPUNIT_ASSERT_EQUAL(OUString(), checkNonEmptyAddresses(rDoc, aEmptyAddresses));
121 CPPUNIT_TEST_FIXTURE(ScPivotTableFormatsImportExport,
122 PivotTableCellFormatsTest_2_DataFieldInRow_ColumnLabelColor)
124 createScDoc(
125 "xlsx/pivot-table/PivotTableCellFormatsTest_2_DataFieldInRow_ColumnLabelColor.xlsx");
126 assertDataFieldInRow_ColumnLabelColor(*getScDoc());
127 saveAndReload(u"Calc Office Open XML"_ustr);
128 assertDataFieldInRow_ColumnLabelColor(*getScDoc());
131 static void assertDataFieldInColumn_ColumnLabelColor(ScDocument& rDoc)
133 CPPUNIT_ASSERT_EQUAL(COL_LIGHTRED, getFontColor(rDoc, u"H4"_ustr));
134 CPPUNIT_ASSERT_EQUAL(Color(0x92D050), getBackgroundColor(rDoc, u"I4"_ustr));
136 // Make sure the other cells have the font color or background set to default
137 std::vector<OUString> aEmptyAddresses{
138 u"G4"_ustr, u"G5"_ustr, u"H5"_ustr, u"I5"_ustr, u"G6"_ustr, u"H6"_ustr, u"I6"_ustr,
139 u"G7"_ustr, u"H7"_ustr, u"I7"_ustr, u"G8"_ustr, u"H8"_ustr, u"I8"_ustr,
141 CPPUNIT_ASSERT_EQUAL(OUString(), checkNonEmptyAddresses(rDoc, aEmptyAddresses));
144 CPPUNIT_TEST_FIXTURE(ScPivotTableFormatsImportExport,
145 PivotTableCellFormatsTest_3_DataFieldInColumn_ColumnLabelColor)
147 createScDoc(
148 "xlsx/pivot-table/PivotTableCellFormatsTest_3_DataFieldInColumn_ColumnLabelColor.xlsx");
149 assertDataFieldInColumn_ColumnLabelColor(*getScDoc());
150 saveAndReload(u"Calc Office Open XML"_ustr);
151 assertDataFieldInColumn_ColumnLabelColor(*getScDoc());
154 static void assertDataFieldInColumn_DataColor(ScDocument& rDoc)
156 CPPUNIT_ASSERT_EQUAL(COL_LIGHTRED, getFontColor(rDoc, u"H6"_ustr));
157 CPPUNIT_ASSERT_EQUAL(Color(0x92D050), getBackgroundColor(rDoc, u"I8"_ustr));
159 std::vector<OUString> aEmptyAddresses{
160 u"G4"_ustr, u"H4"_ustr, u"I4"_ustr, u"G5"_ustr, u"H5"_ustr, u"I5"_ustr, u"G6"_ustr,
161 u"I6"_ustr, u"G7"_ustr, u"H7"_ustr, u"I7"_ustr, u"G8"_ustr, u"H8"_ustr,
163 CPPUNIT_ASSERT_EQUAL(OUString(), checkNonEmptyAddresses(rDoc, aEmptyAddresses));
166 CPPUNIT_TEST_FIXTURE(ScPivotTableFormatsImportExport,
167 PivotTableCellFormatsTest_4_DataFieldInColumn_DataColor)
169 createScDoc("xlsx/pivot-table/PivotTableCellFormatsTest_4_DataFieldInColumn_DataColor.xlsx");
170 assertDataFieldInColumn_DataColor(*getScDoc());
171 saveAndReload(u"Calc Office Open XML"_ustr);
172 assertDataFieldInColumn_DataColor(*getScDoc());
175 static void assertDataFieldInColumnAndTwoRowFields_DataColor(ScDocument& rDoc)
177 CPPUNIT_ASSERT_EQUAL(COL_YELLOW, getBackgroundColor(rDoc, u"I7"_ustr));
178 CPPUNIT_ASSERT_EQUAL(COL_LIGHTRED, getBackgroundColor(rDoc, u"I10"_ustr));
179 CPPUNIT_ASSERT_EQUAL(Color(0x0070C0), getBackgroundColor(rDoc, u"J12"_ustr));
181 std::vector<OUString> aEmptyAddresses{
182 u"G4"_ustr, u"H4"_ustr, u"I4"_ustr, u"J4"_ustr, u"G5"_ustr, u"H5"_ustr, u"I5"_ustr,
183 u"J5"_ustr, u"G6"_ustr, u"H6"_ustr, u"I6"_ustr, u"J6"_ustr, u"G7"_ustr, u"H7"_ustr,
184 u"J7"_ustr, u"G8"_ustr, u"H8"_ustr, u"I8"_ustr, u"J8"_ustr, u"G9"_ustr, u"H9"_ustr,
185 u"I9"_ustr, u"J9"_ustr, u"G10"_ustr, u"H10"_ustr, u"J10"_ustr, u"G11"_ustr, u"H11"_ustr,
186 u"I11"_ustr, u"J11"_ustr, u"G12"_ustr, u"H12"_ustr, u"I12"_ustr, u"G13"_ustr, u"H13"_ustr,
187 u"I13"_ustr, u"J13"_ustr,
189 CPPUNIT_ASSERT_EQUAL(OUString(), checkNonEmptyAddresses(rDoc, aEmptyAddresses));
192 CPPUNIT_TEST_FIXTURE(ScPivotTableFormatsImportExport,
193 PivotTableCellFormatsTest_5_DataFieldInColumnAndTwoRowFields_DataColor)
195 createScDoc("xlsx/pivot-table//"
196 "PivotTableCellFormatsTest_5_DataFieldInColumnAndTwoRowFields_DataColor.xlsx");
197 assertDataFieldInColumnAndTwoRowFields_DataColor(*getScDoc());
198 saveAndReload(u"Calc Office Open XML"_ustr);
199 assertDataFieldInColumnAndTwoRowFields_DataColor(*getScDoc());
202 static void assertSingleDataFieldInColumn_DataColor(ScDocument& rDoc)
204 CPPUNIT_ASSERT_EQUAL(COL_YELLOW, getBackgroundColor(rDoc, u"J8"_ustr));
205 CPPUNIT_ASSERT_EQUAL(COL_LIGHTRED, getBackgroundColor(rDoc, u"J12"_ustr));
208 CPPUNIT_TEST_FIXTURE(ScPivotTableFormatsImportExport,
209 PivotTableCellFormatsTest_6_SingleDataFieldInColumn_DataColor)
211 createScDoc(
212 "xlsx/pivot-table//PivotTableCellFormatsTest_6_SingleDataFieldInColumn_DataColor.xlsx");
213 assertSingleDataFieldInColumn_DataColor(*getScDoc());
214 saveAndReload(u"Calc Office Open XML"_ustr);
215 assertSingleDataFieldInColumn_DataColor(*getScDoc());
218 static void assertTwoRowTwoColumnFields_DataColor(ScDocument& rDoc)
220 CPPUNIT_ASSERT_EQUAL(COL_YELLOW, getBackgroundColor(rDoc, u"I7"_ustr));
221 CPPUNIT_ASSERT_EQUAL(Color(0xFFC000), getBackgroundColor(rDoc, u"J8"_ustr));
222 CPPUNIT_ASSERT_EQUAL(Color(0x0070C0), getBackgroundColor(rDoc, u"J9"_ustr));
223 CPPUNIT_ASSERT_EQUAL(Color(0x00B0F0), getBackgroundColor(rDoc, u"J13"_ustr));
224 CPPUNIT_ASSERT_EQUAL(Color(0x92D050), getBackgroundColor(rDoc, u"K12"_ustr));
225 CPPUNIT_ASSERT_EQUAL(COL_LIGHTRED, getBackgroundColor(rDoc, u"L14"_ustr));
228 CPPUNIT_TEST_FIXTURE(ScPivotTableFormatsImportExport,
229 PivotTableCellFormatsTest_7_TwoRowTwoColumnFields_DataColor)
231 createScDoc(
232 "xlsx/pivot-table//PivotTableCellFormatsTest_7_TwoRowTwoColumnFields_DataColor.xlsx");
233 assertTwoRowTwoColumnFields_DataColor(*getScDoc());
234 saveAndReload(u"Calc Office Open XML"_ustr);
235 assertTwoRowTwoColumnFields_DataColor(*getScDoc());
238 static void assertDataFieldInRow_DataColor(ScDocument& rDoc)
240 CPPUNIT_ASSERT_EQUAL(Color(0x00B0F0), getBackgroundColor(rDoc, u"I6"_ustr));
241 CPPUNIT_ASSERT_EQUAL(COL_YELLOW, getBackgroundColor(rDoc, u"K7"_ustr));
243 // Make sure the other cells have the font color or background set to default
244 std::vector<OUString> aEmptyAddresses{
245 u"G5"_ustr, u"H5"_ustr, u"I5"_ustr, u"J5"_ustr, u"K5"_ustr, u"G6"_ustr, u"H6"_ustr,
246 u"J6"_ustr, u"K6"_ustr, u"G7"_ustr, u"H7"_ustr, u"I7"_ustr, u"J7"_ustr,
248 CPPUNIT_ASSERT_EQUAL(OUString(), checkNonEmptyAddresses(rDoc, aEmptyAddresses));
251 CPPUNIT_TEST_FIXTURE(ScPivotTableFormatsImportExport,
252 PivotTableCellFormatsTest_8_DataFieldInRow_DataColor)
254 createScDoc("xlsx/pivot-table/PivotTableCellFormatsTest_8_DataFieldInRow_DataColor.xlsx");
255 assertDataFieldInRow_DataColor(*getScDoc());
256 saveAndReload(u"Calc Office Open XML"_ustr);
257 assertDataFieldInRow_DataColor(*getScDoc());
260 static void assertMultipleSelections(ScDocument& rDoc)
262 CPPUNIT_ASSERT_EQUAL(COL_YELLOW, getBackgroundColor(rDoc, u"I5"_ustr));
263 CPPUNIT_ASSERT_EQUAL(COL_YELLOW, getBackgroundColor(rDoc, u"I6"_ustr));
264 CPPUNIT_ASSERT_EQUAL(COL_YELLOW, getBackgroundColor(rDoc, u"I7"_ustr));
267 CPPUNIT_TEST_FIXTURE(ScPivotTableFormatsImportExport,
268 PivotTableCellFormatsTest_9_MultipleSelections)
270 createScDoc("xlsx/pivot-table/PivotTableCellFormatsTest_9_MultipleSelections.xlsx");
271 assertMultipleSelections(*getScDoc());
272 saveAndReload(u"Calc Office Open XML"_ustr);
273 assertMultipleSelections(*getScDoc());
276 CPPUNIT_TEST_FIXTURE(ScPivotTableFormatsImportExport,
277 PivotTableCellFormatsTest_10_FormatDefinitionNotMatchingPivotTable)
279 // The pivot table format data in this document doesn't match the pivot table data, which can produce
280 // a crash during loading and resolving of formats. Specifically
282 // Load the document, which shouldn't result in a crash
283 createScDoc("xlsx/pivot-table/"
284 "PivotTableCellFormatsTest_10_FormatDefinitionNotMatchingPivotTable.xlsx");
285 ScDocument& rDoc = *getScDoc();
287 // Let's check the pivot table exists
288 ScDPCollection* pCollection = rDoc.GetDPCollection();
289 CPPUNIT_ASSERT_EQUAL(size_t(1), pCollection->GetCount());
291 auto aAddress = parseAddress(rDoc, u"G2"_ustr);
292 const ScDPObject* pDPObject = rDoc.GetDPAtCursor(aAddress);
293 CPPUNIT_ASSERT(pDPObject);
295 CPPUNIT_ASSERT_EQUAL(u"60"_ustr, rDoc.GetString(aAddress));
298 static void assertWholeDataColumnSelected(ScDocument& rDoc)
300 CPPUNIT_ASSERT_EQUAL(COL_YELLOW, getBackgroundColor(rDoc, u"G2"_ustr));
301 CPPUNIT_ASSERT_EQUAL(COL_YELLOW, getBackgroundColor(rDoc, u"G3"_ustr));
302 CPPUNIT_ASSERT_EQUAL(COL_YELLOW, getBackgroundColor(rDoc, u"G4"_ustr));
303 CPPUNIT_ASSERT_EQUAL(COL_YELLOW, getBackgroundColor(rDoc, u"G5"_ustr));
304 CPPUNIT_ASSERT_EQUAL(COL_YELLOW, getBackgroundColor(rDoc, u"G6"_ustr));
305 CPPUNIT_ASSERT_EQUAL(COL_YELLOW, getBackgroundColor(rDoc, u"G7"_ustr));
307 // Make sure the other cells have the font color or background set to default
308 std::vector<OUString> aEmptyAddresses{
309 u"F1"_ustr, u"G1"_ustr, u"F2"_ustr, u"F3"_ustr, u"F4"_ustr,
310 u"F5"_ustr, u"F6"_ustr, u"F7"_ustr, u"F8"_ustr, u"G8"_ustr,
312 CPPUNIT_ASSERT_EQUAL(OUString(), checkNonEmptyAddresses(rDoc, aEmptyAddresses));
315 CPPUNIT_TEST_FIXTURE(ScPivotTableFormatsImportExport,
316 PivotTableCellFormatsTest_11_WholeDataColumnSelected)
318 createScDoc("xlsx/pivot-table/PivotTableCellFormatsTest_11_WholeDataColumnSelected.xlsx");
319 assertWholeDataColumnSelected(*getScDoc());
320 saveAndReload(u"Calc Office Open XML"_ustr);
321 assertWholeDataColumnSelected(*getScDoc());
324 static void assertWholeLabelColumnSelected(ScDocument& rDoc)
326 CPPUNIT_ASSERT_EQUAL(COL_LIGHTRED, getBackgroundColor(rDoc, u"F2"_ustr));
327 CPPUNIT_ASSERT_EQUAL(COL_LIGHTRED, getBackgroundColor(rDoc, u"F3"_ustr));
328 CPPUNIT_ASSERT_EQUAL(COL_LIGHTRED, getBackgroundColor(rDoc, u"F4"_ustr));
329 CPPUNIT_ASSERT_EQUAL(COL_LIGHTRED, getBackgroundColor(rDoc, u"F5"_ustr));
330 CPPUNIT_ASSERT_EQUAL(COL_LIGHTRED, getBackgroundColor(rDoc, u"F6"_ustr));
331 CPPUNIT_ASSERT_EQUAL(COL_LIGHTRED, getBackgroundColor(rDoc, u"F7"_ustr));
333 // Make sure the other cells have the font color or background set to default
334 std::vector<OUString> aEmptyAddresses{
335 u"F1"_ustr, u"G1"_ustr, u"G2"_ustr, u"G3"_ustr, u"G4"_ustr,
336 u"G5"_ustr, u"G6"_ustr, u"G7"_ustr, u"F8"_ustr, u"G8"_ustr,
338 CPPUNIT_ASSERT_EQUAL(OUString(), checkNonEmptyAddresses(rDoc, aEmptyAddresses));
341 CPPUNIT_TEST_FIXTURE(ScPivotTableFormatsImportExport,
342 PivotTableCellFormatsTest_12_WholeLabelColumnSelected)
344 createScDoc("xlsx/pivot-table/PivotTableCellFormatsTest_12_WholeLabelColumnSelected.xlsx");
345 assertWholeLabelColumnSelected(*getScDoc());
346 saveAndReload(u"Calc Office Open XML"_ustr);
347 assertWholeLabelColumnSelected(*getScDoc());
350 static void assertSelectionInLabelAndData(ScDocument& rDoc)
352 CPPUNIT_ASSERT_EQUAL(COL_LIGHTRED, getBackgroundColor(rDoc, u"F5"_ustr));
353 CPPUNIT_ASSERT_EQUAL(COL_LIGHTRED, getBackgroundColor(rDoc, u"G5"_ustr));
355 // Make sure the other cells have the font color or background set to default
356 std::vector<OUString> aEmptyAddresses{
357 u"F1"_ustr, u"G1"_ustr, u"F2"_ustr, u"G2"_ustr, u"F3"_ustr, u"G3"_ustr, u"F4"_ustr,
358 u"G4"_ustr, u"F6"_ustr, u"G6"_ustr, u"F7"_ustr, u"G7"_ustr, u"F8"_ustr, u"G8"_ustr,
360 CPPUNIT_ASSERT_EQUAL(OUString(), checkNonEmptyAddresses(rDoc, aEmptyAddresses));
363 CPPUNIT_TEST_FIXTURE(ScPivotTableFormatsImportExport,
364 PivotTableCellFormatsTest_13_SelectionInLabelAndData)
366 createScDoc("xlsx/pivot-table/PivotTableCellFormatsTest_13_SelectionInLabelAndData.xlsx");
367 assertSelectionInLabelAndData(*getScDoc());
368 saveAndReload(u"Calc Office Open XML"_ustr);
369 assertSelectionInLabelAndData(*getScDoc());
372 static void assertTwoRowsDataFieldInColumn_LabelColor(ScDocument& rDoc)
374 CPPUNIT_ASSERT_EQUAL(COL_YELLOW, getBackgroundColor(rDoc, u"I4"_ustr));
375 CPPUNIT_ASSERT_EQUAL(COL_LIGHTRED, getBackgroundColor(rDoc, u"J4"_ustr));
377 // Make sure the other cells have the font color or background set to default
378 std::vector<OUString> aEmptyAddresses{
379 u"G4"_ustr, u"H4"_ustr, u"G5"_ustr, u"H5"_ustr, u"i5"_ustr, u"j5"_ustr, u"G6"_ustr,
380 u"H6"_ustr, u"i6"_ustr, u"j6"_ustr, u"G7"_ustr, u"H7"_ustr, u"i7"_ustr, u"j7"_ustr,
381 u"G8"_ustr, u"H8"_ustr, u"i8"_ustr, u"j8"_ustr, u"G9"_ustr, u"H9"_ustr, u"i9"_ustr,
382 u"j9"_ustr, u"G10"_ustr, u"H10"_ustr, u"i10"_ustr, u"j10"_ustr, u"G11"_ustr, u"H11"_ustr,
383 u"i11"_ustr, u"j11"_ustr, u"G12"_ustr, u"H12"_ustr, u"i12"_ustr, u"j12"_ustr, u"G13"_ustr,
384 u"H13"_ustr, u"i13"_ustr, u"j13"_ustr,
386 CPPUNIT_ASSERT_EQUAL(OUString(), checkNonEmptyAddresses(rDoc, aEmptyAddresses));
389 CPPUNIT_TEST_FIXTURE(ScPivotTableFormatsImportExport,
390 PivotTableCellFormatsTest_14_TwoRowsDataFieldInColumn_LabelColor)
392 createScDoc("xlsx/pivot-table/"
393 "PivotTableCellFormatsTest_14_TwoRowsDataFieldInColumn_LabelColor.xlsx");
394 assertTwoRowsDataFieldInColumn_LabelColor(*getScDoc());
395 saveAndReload(u"Calc Office Open XML"_ustr);
396 assertTwoRowsDataFieldInColumn_LabelColor(*getScDoc());
399 static void assertTwoDataFieldColumns_WholeDataColumnSelected(ScDocument& rDoc)
401 CPPUNIT_ASSERT_EQUAL(COL_YELLOW, getBackgroundColor(rDoc, u"H2"_ustr));
402 CPPUNIT_ASSERT_EQUAL(COL_YELLOW, getBackgroundColor(rDoc, u"H3"_ustr));
403 CPPUNIT_ASSERT_EQUAL(COL_YELLOW, getBackgroundColor(rDoc, u"H4"_ustr));
404 CPPUNIT_ASSERT_EQUAL(COL_YELLOW, getBackgroundColor(rDoc, u"H5"_ustr));
405 CPPUNIT_ASSERT_EQUAL(COL_YELLOW, getBackgroundColor(rDoc, u"H6"_ustr));
406 CPPUNIT_ASSERT_EQUAL(COL_YELLOW, getBackgroundColor(rDoc, u"H7"_ustr));
408 // Make sure the other cells have the font color or background set to default
409 std::vector<OUString> aEmptyAddresses{
410 u"F1"_ustr, u"G1"_ustr, u"H1"_ustr, u"F2"_ustr, u"G2"_ustr,
411 u"F3"_ustr, u"G3"_ustr, u"F4"_ustr, u"G4"_ustr, u"F5"_ustr,
412 u"G5"_ustr, u"F6"_ustr, u"G6"_ustr, u"F7"_ustr, u"G7"_ustr,
414 CPPUNIT_ASSERT_EQUAL(OUString(), checkNonEmptyAddresses(rDoc, aEmptyAddresses));
417 CPPUNIT_TEST_FIXTURE(ScPivotTableFormatsImportExport,
418 PivotTableCellFormatsTest_15_TwoDataFieldColumns_WholeDataColumnSelected)
420 createScDoc("xlsx/pivot-table/"
421 "PivotTableCellFormatsTest_15_TwoDataFieldColumns_WholeDataColumnSelected.xlsx");
422 assertTwoDataFieldColumns_WholeDataColumnSelected(*getScDoc());
423 saveAndReload(u"Calc Office Open XML"_ustr);
424 assertTwoDataFieldColumns_WholeDataColumnSelected(*getScDoc());
427 static void assertFields_WithCellProtection(ScDocument& rDoc)
429 CPPUNIT_ASSERT_EQUAL(false, getCellProtection(rDoc, u"F18"_ustr));
430 CPPUNIT_ASSERT_EQUAL(false, getCellProtection(rDoc, u"F19"_ustr));
431 CPPUNIT_ASSERT_EQUAL(false, getCellProtection(rDoc, u"F20"_ustr));
432 CPPUNIT_ASSERT_EQUAL(false, getCellProtection(rDoc, u"G18"_ustr));
433 CPPUNIT_ASSERT_EQUAL(false, getCellProtection(rDoc, u"G19"_ustr));
434 CPPUNIT_ASSERT_EQUAL(false, getCellProtection(rDoc, u"G20"_ustr));
436 // Make sure the other cells have the font color or background set to default
437 std::vector<OUString> aEmptyAddresses{
438 u"F15"_ustr, u"G15"_ustr, u"F16"_ustr, u"G16"_ustr,
439 u"F17"_ustr, u"G17"_ustr, u"G21"_ustr, u"F21"_ustr,
441 CPPUNIT_ASSERT_EQUAL(OUString(), checkNonEmptyAddresses(rDoc, aEmptyAddresses));
444 CPPUNIT_TEST_FIXTURE(ScPivotTableFormatsImportExport, Pivot_Table_with_Cell_Protection)
446 createScDoc("xlsx/pivot-table/Pivot_Table_with_Cell_Protection.xlsx");
447 assertFields_WithCellProtection(*getScDoc());
448 saveAndReload(u"Calc Office Open XML"_ustr);
449 assertFields_WithCellProtection(*getScDoc());
452 CPPUNIT_PLUGIN_IMPLEMENT();
454 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */