sc/qa/unit/PivotTableFormatsImportExport.cxx | 35 ++++++++-- sc/qa/unit/data/xlsx/pivot-table/PivotTableCellFormatsTest_10_FormatDefinitionNotMatchingPivotTable.xlsx |binary 2 files changed, 30 insertions(+), 5 deletions(-)
New commits: commit 3b50c9f54907c656d2ee23fddadc696ffdab1c94 Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> AuthorDate: Tue Apr 16 22:44:23 2024 +0900 Commit: Tomaž Vajngerl <qui...@gmail.com> CommitDate: Thu Apr 18 01:33:36 2024 +0200 pivot: test for issue when pivot table format not matching data Fix was added with [1][2] and this adds the tests to make sure this keeps working in the future. [1] 1d5630c5deeec5dca724c29ec8c886bfa71a2099 [2] https://gerrit.libreoffice.org/c/core/+/166138 Change-Id: I0a7e62ee6139cc5334c03e7022ce49306d578e1f Reviewed-on: https://gerrit.libreoffice.org/c/core/+/166149 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <qui...@gmail.com> diff --git a/sc/qa/unit/PivotTableFormatsImportExport.cxx b/sc/qa/unit/PivotTableFormatsImportExport.cxx index 40db2afb2292..f1cf83d225cd 100644 --- a/sc/qa/unit/PivotTableFormatsImportExport.cxx +++ b/sc/qa/unit/PivotTableFormatsImportExport.cxx @@ -36,20 +36,23 @@ ScPivotTableFormatsImportExport::ScPivotTableFormatsImportExport() namespace { -Color getBackgroundColor(ScDocument& rDoc, OUString const& rAddressString) +ScAddress parseAddress(ScDocument& rDoc, OUString const& rAddressString) { ScAddress aAddress; aAddress.Parse(rAddressString, rDoc); - const ScPatternAttr* pPattern = rDoc.GetPattern(aAddress); + return aAddress; +} + +Color getBackgroundColor(ScDocument& rDoc, OUString const& rAddressString) +{ + const ScPatternAttr* pPattern = rDoc.GetPattern(parseAddress(rDoc, rAddressString)); const SvxBrushItem& rItem = pPattern->GetItem(ATTR_BACKGROUND); return rItem.GetColor(); } Color getFontColor(ScDocument& rDoc, OUString const& rAddressString) { - ScAddress aAddress; - aAddress.Parse(rAddressString, rDoc); - const ScPatternAttr* pPattern = rDoc.GetPattern(aAddress); + const ScPatternAttr* pPattern = rDoc.GetPattern(parseAddress(rDoc, rAddressString)); const SvxColorItem& rItem = pPattern->GetItem(ATTR_FONT_COLOR); return rItem.getColor(); } @@ -310,6 +313,28 @@ CPPUNIT_TEST_FIXTURE(ScPivotTableFormatsImportExport, assertDocument(*getScDoc()); } +CPPUNIT_TEST_FIXTURE(ScPivotTableFormatsImportExport, + PivotTableCellFormatsTest_10_FormatDefinitionNotMatchingPivotTable) +{ + // The pivot table format data in this document doesn't match the pivot table data, which can produce + // 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"); + ScDocument& rDoc = *getScDoc(); + + // Let's check the pivot table exists + ScDPCollection* pCollection = rDoc.GetDPCollection(); + CPPUNIT_ASSERT_EQUAL(size_t(1), pCollection->GetCount()); + + auto aAddress = parseAddress(rDoc, u"G2"_ustr); + const ScDPObject* pDPObject = rDoc.GetDPAtCursor(aAddress); + CPPUNIT_ASSERT(pDPObject); + + CPPUNIT_ASSERT_EQUAL(u"60"_ustr, rDoc.GetString(aAddress)); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/qa/unit/data/xlsx/pivot-table/PivotTableCellFormatsTest_10_FormatDefinitionNotMatchingPivotTable.xlsx b/sc/qa/unit/data/xlsx/pivot-table/PivotTableCellFormatsTest_10_FormatDefinitionNotMatchingPivotTable.xlsx new file mode 100644 index 000000000000..c2fe60ccf69f Binary files /dev/null and b/sc/qa/unit/data/xlsx/pivot-table/PivotTableCellFormatsTest_10_FormatDefinitionNotMatchingPivotTable.xlsx differ