summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2024-04-16 22:44:23 +0900
committerTomaž Vajngerl <quikee@gmail.com>2024-04-18 01:33:36 +0200
commit3b50c9f54907c656d2ee23fddadc696ffdab1c94 (patch)
tree0b42b0bfb5068a8f45e95778dc441c444a2e4465 /sc
parent589fb36b663cbd68afc26419629a4a95bd593a89 (diff)
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 <quikee@gmail.com>
Diffstat (limited to 'sc')
-rw-r--r--sc/qa/unit/PivotTableFormatsImportExport.cxx35
-rw-r--r--sc/qa/unit/data/xlsx/pivot-table/PivotTableCellFormatsTest_10_FormatDefinitionNotMatchingPivotTable.xlsxbin0 -> 12606 bytes
2 files changed, 30 insertions, 5 deletions
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
--- /dev/null
+++ b/sc/qa/unit/data/xlsx/pivot-table/PivotTableCellFormatsTest_10_FormatDefinitionNotMatchingPivotTable.xlsx
Binary files differ