diff options
-rw-r--r-- | sc/CppunitTest_sc_subsequent_export-test.mk | 12 | ||||
-rw-r--r-- | sc/CppunitTest_sc_subsequent_export-test2.mk | 12 | ||||
-rw-r--r-- | sc/CppunitTest_sc_subsequent_filters-test.mk | 12 | ||||
-rw-r--r-- | sc/CppunitTest_sc_subsequent_filters-test2.mk | 12 | ||||
-rw-r--r-- | sc/CppunitTest_sc_subsequent_filters_test.mk | 137 | ||||
-rw-r--r-- | sc/Module_sc.mk | 7 | ||||
-rw-r--r-- | sc/qa/unit/subsequent_export-test.cxx | 1974 | ||||
-rw-r--r-- | sc/qa/unit/subsequent_export-test2.cxx | 2301 | ||||
-rw-r--r-- | sc/qa/unit/subsequent_filters-test.cxx | 2799 | ||||
-rw-r--r-- | sc/qa/unit/subsequent_filters-test2.cxx | 2882 | ||||
-rw-r--r-- | sc/subsequent_setup.mk (renamed from sc/CppunitTest_sc_subsequent_export_test.mk) | 40 |
11 files changed, 5285 insertions, 4903 deletions
diff --git a/sc/CppunitTest_sc_subsequent_export-test.mk b/sc/CppunitTest_sc_subsequent_export-test.mk new file mode 100644 index 000000000000..1ca3ac158292 --- /dev/null +++ b/sc/CppunitTest_sc_subsequent_export-test.mk @@ -0,0 +1,12 @@ +# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*- +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# + +$(eval $(call sc_subsequent_test,export-test)) + +# vim: set noet sw=4 ts=4: diff --git a/sc/CppunitTest_sc_subsequent_export-test2.mk b/sc/CppunitTest_sc_subsequent_export-test2.mk new file mode 100644 index 000000000000..061b22299467 --- /dev/null +++ b/sc/CppunitTest_sc_subsequent_export-test2.mk @@ -0,0 +1,12 @@ +# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*- +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# + +$(eval $(call sc_subsequent_test,export-test2)) + +# vim: set noet sw=4 ts=4: diff --git a/sc/CppunitTest_sc_subsequent_filters-test.mk b/sc/CppunitTest_sc_subsequent_filters-test.mk new file mode 100644 index 000000000000..aab51ef0f6c5 --- /dev/null +++ b/sc/CppunitTest_sc_subsequent_filters-test.mk @@ -0,0 +1,12 @@ +# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*- +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# + +$(eval $(call sc_subsequent_test,filters-test)) + +# vim: set noet sw=4 ts=4: diff --git a/sc/CppunitTest_sc_subsequent_filters-test2.mk b/sc/CppunitTest_sc_subsequent_filters-test2.mk new file mode 100644 index 000000000000..94bf7d8da7d6 --- /dev/null +++ b/sc/CppunitTest_sc_subsequent_filters-test2.mk @@ -0,0 +1,12 @@ +# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*- +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# + +$(eval $(call sc_subsequent_test,filters-test2)) + +# vim: set noet sw=4 ts=4: diff --git a/sc/CppunitTest_sc_subsequent_filters_test.mk b/sc/CppunitTest_sc_subsequent_filters_test.mk deleted file mode 100644 index a3040d0747cc..000000000000 --- a/sc/CppunitTest_sc_subsequent_filters_test.mk +++ /dev/null @@ -1,137 +0,0 @@ -# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*- -# -# This file is part of the LibreOffice project. -# -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at http://mozilla.org/MPL/2.0/. -# - -$(eval $(call gb_CppunitTest_CppunitTest,sc_subsequent_filters_test)) - -$(eval $(call gb_CppunitTest_use_common_precompiled_header,sc_subsequent_filters_test)) - -$(eval $(call gb_CppunitTest_add_exception_objects,sc_subsequent_filters_test, \ - sc/qa/unit/subsequent_filters-test \ -)) - -$(eval $(call gb_CppunitTest_use_externals,sc_subsequent_filters_test, \ - boost_headers \ - mdds_headers \ - libxml2 \ -)) - -$(eval $(call gb_CppunitTest_use_libraries,sc_subsequent_filters_test, \ - basegfx \ - comphelper \ - cppu \ - cppuhelper \ - drawinglayer \ - editeng \ - for \ - forui \ - i18nlangtag \ - msfilter \ - oox \ - sal \ - salhelper \ - sax \ - sb \ - sc \ - scqahelper \ - sfx \ - sot \ - subsequenttest \ - svl \ - svt \ - svx \ - svxcore \ - test \ - tk \ - tl \ - ucbhelper \ - unotest \ - utl \ - vbahelper \ - vcl \ - xo \ -)) - -$(eval $(call gb_CppunitTest_set_include,sc_subsequent_filters_test,\ - -I$(SRCDIR)/sc/source/ui/inc \ - -I$(SRCDIR)/sc/inc \ - -I$(SRCDIR)/sc/source/filter/inc \ - $$(INCLUDE) \ -)) - -$(eval $(call gb_CppunitTest_use_api,sc_subsequent_filters_test,\ - udkapi \ - offapi \ - oovbaapi \ -)) - -$(eval $(call gb_CppunitTest_use_ure,sc_subsequent_filters_test)) -$(eval $(call gb_CppunitTest_use_vcl,sc_subsequent_filters_test)) - -$(eval $(call gb_CppunitTest_use_components,sc_subsequent_filters_test,\ - basic/util/sb \ - basctl/util/basctl \ - chart2/source/chartcore \ - chart2/source/controller/chartcontroller \ - comphelper/util/comphelp \ - configmgr/source/configmgr \ - dbaccess/util/dba \ - embeddedobj/util/embobj \ - emfio/emfio \ - eventattacher/source/evtatt \ - filter/source/config/cache/filterconfig1 \ - forms/util/frm \ - framework/util/fwk \ - i18npool/source/search/i18nsearch \ - i18npool/util/i18npool \ - linguistic/source/lng \ - oox/util/oox \ - package/source/xstor/xstor \ - package/util/package2 \ - sax/source/expatwrap/expwrap \ - scaddins/source/analysis/analysis \ - scaddins/source/datefunc/date \ - sc/util/sc \ - sc/util/scfilt \ - sc/util/vbaobj \ - sfx2/util/sfx \ - sot/util/sot \ - svl/util/svl \ - svl/source/fsstor/fsstorage \ - svtools/util/svt \ - toolkit/util/tk \ - ucb/source/core/ucb1 \ - ucb/source/ucp/file/ucpfile1 \ - ucb/source/ucp/tdoc/ucptdoc1 \ - unotools/util/utl \ - unoxml/source/rdf/unordf \ - unoxml/source/service/unoxml \ - uui/util/uui \ - vcl/vcl.common \ - xmloff/util/xo \ - xmlsecurity/util/xmlsecurity \ -)) - -$(eval $(call gb_CppunitTest_use_components,sc_subsequent_filters_test,\ - xmlsecurity/util/xsec_xmlsec \ -)) - -$(eval $(call gb_CppunitTest_use_externals,sc_subsequent_filters_test,\ - orcus \ - orcus-parser \ - boost_filesystem \ - boost_system \ - boost_iostreams \ - zlib \ -)) - -$(eval $(call gb_CppunitTest_use_configuration,sc_subsequent_filters_test)) - -$(eval $(call gb_CppunitTest_use_more_fonts,sc_subsequent_filters_test)) - -# vim: set noet sw=4 ts=4: diff --git a/sc/Module_sc.mk b/sc/Module_sc.mk index 1d31df9b44fa..a75da398136f 100644 --- a/sc/Module_sc.mk +++ b/sc/Module_sc.mk @@ -10,6 +10,7 @@ include $(SRCDIR)/sc/common_unoapi_tests.mk include $(SRCDIR)/sc/ucalc_setup.mk +include $(SRCDIR)/sc/subsequent_setup.mk $(eval $(call gb_Module_Module,sc)) @@ -75,8 +76,10 @@ $(eval $(call gb_Module_add_slowcheck_targets,sc, \ CppunitTest_sc_new_cond_format_api \ CppunitTest_sc_pdf_export \ CppunitTest_sc_pivottable_filters_test \ - CppunitTest_sc_subsequent_filters_test \ - CppunitTest_sc_subsequent_export_test \ + CppunitTest_sc_subsequent_filters-test \ + CppunitTest_sc_subsequent_filters-test2 \ + CppunitTest_sc_subsequent_export-test \ + CppunitTest_sc_subsequent_export-test2 \ CppunitTest_sc_uicalc \ )) diff --git a/sc/qa/unit/subsequent_export-test.cxx b/sc/qa/unit/subsequent_export-test.cxx index 439143d0153d..adbf755bb462 100644 --- a/sc/qa/unit/subsequent_export-test.cxx +++ b/sc/qa/unit/subsequent_export-test.cxx @@ -202,101 +202,8 @@ public: void testShapeAutofitXLSX(); void testHyperlinkXLSX(); void testMoveCellAnchoredShapesODS(); - void testMatrixMultiplicationXLSX(); void testPreserveTextWhitespaceXLSX(); void testPreserveTextWhitespace2XLSX(); - void testTextDirectionXLSX(); - void testTdf120168(); - void testTdf66668(); - void testTdf130108(); - void testTdf76949(); - void testTdf107586(); - void testTdf55417(); - void testTdf129985(); - void testTdf73063(); - - xmlDocUniquePtr testTdf95640(std::u16string_view rFileName, sal_Int32 nSourceFormat, - sal_Int32 nDestFormat); - void testTdf95640_ods_to_xlsx(); - void testTdf95640_ods_to_xlsx_with_standard_list(); - void testTdf95640_xlsx_to_xlsx(); - void testDateAutofilterXLSX(); - void testDateAutofilterODS(); - void testAutofilterColorsODF(); - void testAutofilterColorsOOXML(); - void testAutofilterColorsStyleOOXML(); - - void testRefStringXLSX(); - void testRefStringConfigXLSX(); - void testRefStringUnspecified(); - void testHeaderImageODS(); - - void testTdf88657ODS(); - void testTdf41722(); - void testTdf113621(); - void testEscapeCharInNumberFormatXLSX(); - void testNatNumInNumberFormatXLSX(); - void testExponentWithoutSignFormatXLSX(); - void testExtendedLCIDXLSX(); - - void testHiddenRepeatedRowsODS(); - void testHyperlinkTargetFrameODS(); - void testOpenDocumentAsReadOnly(); - void testKeepSettingsOfBlankRows(); - - void testTdf133595(); - void testTdf134769(); - void testTdf106181(); - void testTdf105272(); - void testTdf118990(); - void testTdf121612(); - void testTdf112936(); - void testPivotCacheAfterExportXLSX(); - void testTdf114969XLSX(); - void testTdf115192XLSX(); - void testTdf91634XLSX(); - void testTdf115159(); - void testTdf112567(); - void testTdf112567b(); - void testTdf123645XLSX(); - void testTdf125173XLSX(); - void testTdf79972XLSX(); - void testTdf126024XLSX(); - void testTdf126177XLSX(); - void testCommentTextVAlignment(); - void testCommentTextHAlignment(); - void testValidationCopyPaste(); - - void testXltxExport(); - void testRotatedImageODS(); - void testTdf128976(); - void testTdf120502(); - void testTdf131372(); - void testTdf81470(); - void testTdf122331(); - void testTdf83779(); - void testTdf121716_ExportEvenHeaderFooterXLSX(); - void testTdf134459_HeaderFooterColorXLSX(); - void testTdf134817_HeaderFooterTextWith2SectionXLSX(); - void testTdf121718_UseFirstPageNumberXLSX(); - void testHeaderFontStyleXLSX(); - void testTdf135828_Shape_Rect(); - void testTdf123353(); - void testTdf140098(); - void testTdf133688_precedents(); - void testTdf91251_missingOverflowRoundtrip(); - void testTdf137000_handle_upright(); - void testTdf126305_DataValidatyErrorAlert(); - void testTdf76047_externalLink(); - void testTdf87973_externalLinkSkipUnuseds(); - void testTdf51022_lostPrintRange(); - void testTdf138741_externalLinkSkipUnusedsCrash(); - void testTdf138824_linkToParentDirectory(); - void testTdf129969(); - void testTdf84874(); - void testTdf136721_paper_size(); - void testTdf139258_rotated_image(); - void testTdf126541_SheetVisibilityImportXlsx(); void testTdf113646(); CPPUNIT_TEST_SUITE(ScExportTest); @@ -400,106 +307,13 @@ public: CPPUNIT_TEST(testShapeAutofitXLSX); CPPUNIT_TEST(testHyperlinkXLSX); CPPUNIT_TEST(testMoveCellAnchoredShapesODS); - CPPUNIT_TEST(testMatrixMultiplicationXLSX); - CPPUNIT_TEST(testTextDirectionXLSX); - CPPUNIT_TEST(testTdf120168); - CPPUNIT_TEST(testTdf66668); - CPPUNIT_TEST(testTdf130108); - CPPUNIT_TEST(testTdf76949); - CPPUNIT_TEST(testTdf107586); - CPPUNIT_TEST(testTdf55417); - CPPUNIT_TEST(testTdf129985); - CPPUNIT_TEST(testTdf73063); - CPPUNIT_TEST(testTdf95640_ods_to_xlsx); - CPPUNIT_TEST(testTdf95640_ods_to_xlsx_with_standard_list); - CPPUNIT_TEST(testTdf95640_xlsx_to_xlsx); - CPPUNIT_TEST(testDateAutofilterXLSX); - CPPUNIT_TEST(testDateAutofilterODS); - CPPUNIT_TEST(testAutofilterColorsODF); - CPPUNIT_TEST(testAutofilterColorsOOXML); - CPPUNIT_TEST(testAutofilterColorsStyleOOXML); - - CPPUNIT_TEST(testRefStringXLSX); - CPPUNIT_TEST(testRefStringConfigXLSX); - CPPUNIT_TEST(testRefStringUnspecified); - CPPUNIT_TEST(testHeaderImageODS); - - CPPUNIT_TEST(testTdf88657ODS); - CPPUNIT_TEST(testTdf41722); - CPPUNIT_TEST(testTdf113621); - CPPUNIT_TEST(testEscapeCharInNumberFormatXLSX); - CPPUNIT_TEST(testNatNumInNumberFormatXLSX); - CPPUNIT_TEST(testExponentWithoutSignFormatXLSX); - CPPUNIT_TEST(testExtendedLCIDXLSX); - - CPPUNIT_TEST(testHiddenRepeatedRowsODS); - CPPUNIT_TEST(testHyperlinkTargetFrameODS); - CPPUNIT_TEST(testOpenDocumentAsReadOnly); - CPPUNIT_TEST(testKeepSettingsOfBlankRows); - - CPPUNIT_TEST(testTdf133595); - CPPUNIT_TEST(testTdf134769); - CPPUNIT_TEST(testTdf106181); - CPPUNIT_TEST(testTdf105272); - CPPUNIT_TEST(testTdf118990); - CPPUNIT_TEST(testTdf121612); - CPPUNIT_TEST(testTdf112936); - CPPUNIT_TEST(testPivotCacheAfterExportXLSX); - CPPUNIT_TEST(testTdf114969XLSX); - CPPUNIT_TEST(testTdf115192XLSX); - CPPUNIT_TEST(testTdf91634XLSX); - CPPUNIT_TEST(testTdf115159); - CPPUNIT_TEST(testTdf112567); - CPPUNIT_TEST(testTdf112567b); - CPPUNIT_TEST(testTdf123645XLSX); - CPPUNIT_TEST(testTdf125173XLSX); - CPPUNIT_TEST(testTdf79972XLSX); - CPPUNIT_TEST(testTdf126024XLSX); - CPPUNIT_TEST(testTdf126177XLSX); - CPPUNIT_TEST(testCommentTextVAlignment); - CPPUNIT_TEST(testCommentTextHAlignment); - CPPUNIT_TEST(testValidationCopyPaste); - - CPPUNIT_TEST(testXltxExport); - CPPUNIT_TEST(testRotatedImageODS); - CPPUNIT_TEST(testTdf128976); - CPPUNIT_TEST(testTdf120502); - CPPUNIT_TEST(testTdf131372); - CPPUNIT_TEST(testTdf81470); - CPPUNIT_TEST(testTdf122331); - CPPUNIT_TEST(testTdf83779); - CPPUNIT_TEST(testTdf121716_ExportEvenHeaderFooterXLSX); - CPPUNIT_TEST(testTdf134459_HeaderFooterColorXLSX); - CPPUNIT_TEST(testTdf134817_HeaderFooterTextWith2SectionXLSX); - CPPUNIT_TEST(testTdf121718_UseFirstPageNumberXLSX); - CPPUNIT_TEST(testHeaderFontStyleXLSX); - CPPUNIT_TEST(testTdf135828_Shape_Rect); - CPPUNIT_TEST(testTdf123353); - CPPUNIT_TEST(testTdf140098); - CPPUNIT_TEST(testTdf133688_precedents); - CPPUNIT_TEST(testTdf91251_missingOverflowRoundtrip); - CPPUNIT_TEST(testTdf137000_handle_upright); - CPPUNIT_TEST(testTdf126305_DataValidatyErrorAlert); - CPPUNIT_TEST(testTdf76047_externalLink); - CPPUNIT_TEST(testTdf87973_externalLinkSkipUnuseds); - CPPUNIT_TEST(testTdf51022_lostPrintRange); - CPPUNIT_TEST(testTdf138741_externalLinkSkipUnusedsCrash); - CPPUNIT_TEST(testTdf138824_linkToParentDirectory); - CPPUNIT_TEST(testTdf129969); - CPPUNIT_TEST(testTdf84874); - CPPUNIT_TEST(testTdf136721_paper_size); - CPPUNIT_TEST(testTdf139258_rotated_image); - CPPUNIT_TEST(testTdf126541_SheetVisibilityImportXlsx); CPPUNIT_TEST(testTdf113646); CPPUNIT_TEST_SUITE_END(); private: - - ScDocShellRef loadDocAndSetupModelViewController(std::u16string_view rFileName, sal_Int32 nFormat, bool bReadWrite); void testExcelCellBorders( sal_uLong nFormatType ); uno::Reference<uno::XInterface> m_xCalcComponent; - }; void ScExportTest::registerNamespaces(xmlXPathContextPtr& pXmlXPathCtx) @@ -4319,412 +4133,13 @@ void ScExportTest::testMoveCellAnchoredShapesODS() xDocSh2->DoClose(); } -void ScExportTest::testMatrixMultiplicationXLSX() -{ - ScDocShellRef xShell = loadDoc(u"matrix-multiplication.", FORMAT_XLSX); - CPPUNIT_ASSERT(xShell.is()); - - ScDocShellRef xDocSh = saveAndReload(&(*xShell), FORMAT_XLSX); - CPPUNIT_ASSERT(xDocSh.is()); - - xmlDocUniquePtr pDoc = XPathHelper::parseExport2(*this, *xDocSh, m_xSFactory, "xl/worksheets/sheet1.xml", FORMAT_XLSX); - CPPUNIT_ASSERT(pDoc); - - OUString CellFormulaRange = getXPath(pDoc, - "/x:worksheet/x:sheetData/x:row[4]/x:c/x:f","ref"); - - // make sure that the CellFormulaRange is G5:G6. - CPPUNIT_ASSERT_EQUAL(OUString("G5:G6"), CellFormulaRange); - - OUString CellFormulaType = getXPath(pDoc, - "/x:worksheet/x:sheetData/x:row[4]/x:c/x:f","t"); - - // make sure that the CellFormulaType is array. - CPPUNIT_ASSERT_EQUAL(OUString("array"), CellFormulaType); - - xDocSh->DoClose(); -} - -void ScExportTest::testRefStringXLSX() -{ - ScDocShellRef xDocSh = loadDoc(u"ref_string.", FORMAT_XLSX); - CPPUNIT_ASSERT_MESSAGE("Failed to open doc", xDocSh.is()); - - //make sure ref syntax gets saved for MSO-produced docs - xDocSh = saveAndReload( &(*xDocSh), FORMAT_XLSX); - CPPUNIT_ASSERT_MESSAGE("Failed to reload doc", xDocSh.is()); - - ScDocument& rDoc = xDocSh->GetDocument(); - ScCalcConfig aCalcConfig = rDoc.GetCalcConfig(); - CPPUNIT_ASSERT_EQUAL(formula::FormulaGrammar::CONV_XL_A1, aCalcConfig.meStringRefAddressSyntax); - - xDocSh->DoClose(); -} - -void ScExportTest::testRefStringConfigXLSX() -{ - // this doc is configured with CalcA1 ref syntax - ScDocShellRef xDocSh = loadDoc(u"empty.", FORMAT_XLSX); - CPPUNIT_ASSERT_MESSAGE("Failed to open doc", xDocSh.is()); - - xDocSh = saveAndReload( &(*xDocSh), FORMAT_XLSX); - CPPUNIT_ASSERT_MESSAGE("Failed to reload doc", xDocSh.is()); - - ScDocument& rDoc = xDocSh->GetDocument(); - ScCalcConfig aConfig = rDoc.GetCalcConfig(); - CPPUNIT_ASSERT_EQUAL_MESSAGE("String ref syntax doesn't match", formula::FormulaGrammar::CONV_OOO, - aConfig.meStringRefAddressSyntax); - - xDocSh->DoClose(); - - // this doc has no entry for ref syntax - xDocSh = loadDoc(u"empty-noconf.", FORMAT_XLSX); - CPPUNIT_ASSERT_MESSAGE("Failed to open 2nd doc", xDocSh.is()); - - ScDocument& rDoc2 = xDocSh->GetDocument(); - aConfig = rDoc2.GetCalcConfig(); - // therefore after import, ref syntax should be set to CalcA1 | ExcelA1 - CPPUNIT_ASSERT_EQUAL_MESSAGE("String ref syntax doesn't match", formula::FormulaGrammar::CONV_A1_XL_A1, - aConfig.meStringRefAddressSyntax); - - //set ref syntax to something else than ExcelA1 (native to xlsx format) ... - aConfig.meStringRefAddressSyntax = formula::FormulaGrammar::CONV_XL_R1C1; - rDoc2.SetCalcConfig( aConfig ); - - ScDocShellRef xNewDocSh = saveAndReload( &(*xDocSh), FORMAT_XLSX); - CPPUNIT_ASSERT_MESSAGE("Failed to reload 2nd doc", xNewDocSh.is()); - - // ... and make sure it got saved - ScDocument& rDoc3 = xNewDocSh->GetDocument(); - aConfig = rDoc3.GetCalcConfig(); - CPPUNIT_ASSERT_EQUAL_MESSAGE("String ref syntax doesn't match", formula::FormulaGrammar::CONV_XL_R1C1, - aConfig.meStringRefAddressSyntax); - - xDocSh->DoClose(); - xNewDocSh->DoClose(); -} - -void ScExportTest::testRefStringUnspecified() -{ - ScDocShell* pShell = new ScDocShell( - SfxModelFlags::EMBEDDED_OBJECT | - SfxModelFlags::DISABLE_EMBEDDED_SCRIPTS | - SfxModelFlags::DISABLE_DOCUMENT_RECOVERY); - pShell->DoInitNew(); - - ScDocument& rDoc = pShell->GetDocument(); - ScCalcConfig aConfig = rDoc.GetCalcConfig(); - CPPUNIT_ASSERT_EQUAL_MESSAGE("Default string ref syntax value doesn't match", formula::FormulaGrammar::CONV_UNSPECIFIED, - aConfig.meStringRefAddressSyntax); - - // change formula syntax (i.e. not string ref syntax) to ExcelA1 - rDoc.SetGrammar( formula::FormulaGrammar::GRAM_NATIVE_XL_A1 ); - - ScDocShellRef xDocSh = saveAndReload(pShell, FORMAT_ODS); - CPPUNIT_ASSERT_MESSAGE("Failed to reload doc", xDocSh.is()); - - // with string ref syntax at its default value, we should've saved ExcelA1 - ScDocument& rDoc2 = xDocSh->GetDocument(); - aConfig = rDoc2.GetCalcConfig(); - CPPUNIT_ASSERT_EQUAL_MESSAGE("String ref syntax doesn't match", formula::FormulaGrammar::CONV_XL_A1, - aConfig.meStringRefAddressSyntax); - - xDocSh->DoClose(); -} - -void ScExportTest::testHeaderImageODS() -{ - // Graphic as header background was lost on export. - ScDocShellRef xShell = loadDoc(u"header-image.", FORMAT_ODS); - ScDocShellRef xDocSh = saveAndReload(&(*xShell), FORMAT_ODS); - uno::Reference<style::XStyleFamiliesSupplier> xStyleFamiliesSupplier(xDocSh->GetModel(), uno::UNO_QUERY); - uno::Reference<container::XNameAccess> xStyleFamilies = xStyleFamiliesSupplier->getStyleFamilies(); - uno::Reference<container::XNameAccess> xPageStyles(xStyleFamilies->getByName("PageStyles"), uno::UNO_QUERY); - uno::Reference<beans::XPropertySet> xStyle(xPageStyles->getByName("Default"), uno::UNO_QUERY); - - uno::Reference<graphic::XGraphic> xGraphic; - xStyle->getPropertyValue("HeaderBackGraphic") >>= xGraphic; - CPPUNIT_ASSERT(xGraphic.is()); - xDocSh->DoClose(); -} - -void ScExportTest::testTextDirectionXLSX() -{ - ScDocShellRef xDocSh = loadDoc(u"writingMode.", FORMAT_XLSX); - CPPUNIT_ASSERT(xDocSh.is()); - - xmlDocUniquePtr pDoc = XPathHelper::parseExport2(*this, *xDocSh, m_xSFactory, "xl/styles.xml", FORMAT_XLSX); - CPPUNIT_ASSERT(pDoc); - - assertXPath(pDoc, "/x:styleSheet/x:cellXfs/x:xf[2]/x:alignment", "readingOrder", "1");//LTR - assertXPath(pDoc, "/x:styleSheet/x:cellXfs/x:xf[3]/x:alignment", "readingOrder", "2");//RTL - - xDocSh->DoClose(); -} - -void ScExportTest::testTdf120168() -{ - ScDocShellRef xDocSh = loadDoc(u"tdf120168.", FORMAT_XLSX); - CPPUNIT_ASSERT(xDocSh.is()); - - xmlDocUniquePtr pDoc = XPathHelper::parseExport2(*this, *xDocSh, m_xSFactory, "xl/styles.xml", FORMAT_XLSX); - CPPUNIT_ASSERT(pDoc); - - // Without the fix in place, this test would have failed with - // - Expected: left - // - Actual : general - assertXPath(pDoc, "/x:styleSheet/x:cellXfs/x:xf[2]/x:alignment", "horizontal", "left"); - assertXPath(pDoc, "/x:styleSheet/x:cellXfs/x:xf[3]/x:alignment", "horizontal", "right"); - - xDocSh->DoClose(); -} - -void ScExportTest::testTdf66668() -{ - // Would hang on exporting without the fix in place - ScDocShellRef xDocSh = loadDoc(u"tdf66668.", FORMAT_XLSX); - CPPUNIT_ASSERT_MESSAGE("Failed to open doc", xDocSh.is()); - - xmlDocUniquePtr pDoc = XPathHelper::parseExport2(*this, *xDocSh, m_xSFactory, "xl/styles.xml", FORMAT_XLSX); - CPPUNIT_ASSERT(pDoc); - xDocSh->DoClose(); -} - -void ScExportTest::testTdf130108() -{ - ScDocShellRef xDocSh = loadDoc(u"tdf130108.", FORMAT_ODS); - CPPUNIT_ASSERT(xDocSh.is()); - - xmlDocUniquePtr pDoc = XPathHelper::parseExport2(*this, *xDocSh, m_xSFactory, "xl/styles.xml", FORMAT_XLSX); - CPPUNIT_ASSERT(pDoc); - - assertXPath(pDoc, "/x:styleSheet/x:dxfs/x:dxf/x:font/x:b", "val", "1"); - assertXPath(pDoc, "/x:styleSheet/x:dxfs/x:dxf/x:font/x:i", "val", "0"); - assertXPath(pDoc, "/x:styleSheet/x:dxfs/x:dxf/x:font/x:color", "rgb", "FFFFFFFF"); - assertXPath(pDoc, "/x:styleSheet/x:dxfs/x:dxf/x:font/x:sz", "val", "10"); - assertXPath(pDoc, "/x:styleSheet/x:dxfs/x:dxf/x:fill/x:patternFill/x:bgColor", "rgb", "FFCC0000"); - - xDocSh->DoClose(); -} - -void ScExportTest::testTdf76949() -{ - ScDocShellRef xDocSh = loadDoc(u"tdf76949.", FORMAT_ODS); - CPPUNIT_ASSERT(xDocSh.is()); - - xmlDocUniquePtr pSheet = XPathHelper::parseExport2(*this, *xDocSh, m_xSFactory, "xl/worksheets/sheet1.xml", FORMAT_XLSX); - CPPUNIT_ASSERT(pSheet); - - assertXPathContent(pSheet, "/x:worksheet/x:sheetData/x:row/x:c/x:f", "_xlfn.CHISQ.DIST(1,1,1)"); - - xDocSh->DoClose(); -} - -void ScExportTest::testTdf107586() -{ - ScDocShellRef xDocSh = loadDoc(u"tdf107586.", FORMAT_XLSX); - CPPUNIT_ASSERT(xDocSh.is()); - - xmlDocUniquePtr pSheet = XPathHelper::parseExport2(*this, *xDocSh, m_xSFactory, "xl/worksheets/sheet1.xml", FORMAT_XLSX); - CPPUNIT_ASSERT(pSheet); - - // Without the fix in place, this test would have failed with - // XPath '/x:worksheet/x:sheetPr/x:tabColor' number of nodes is incorrect - assertXPath(pSheet, "/x:worksheet/x:sheetPr/x:tabColor", "rgb", "FF9BBB59"); - - xDocSh->DoClose(); -} - -void ScExportTest::testTdf55417() -{ - ScDocShellRef xDocSh = loadDoc(u"tdf55417.", FORMAT_XLSX); - CPPUNIT_ASSERT(xDocSh.is()); - - xmlDocUniquePtr pDoc = XPathHelper::parseExport2(*this, *xDocSh, m_xSFactory, "xl/styles.xml", FORMAT_XLSX); - CPPUNIT_ASSERT(pDoc); - assertXPath(pDoc, "/x:styleSheet/x:cellXfs/x:xf[1]/x:alignment", 1); - assertXPath(pDoc, "/x:styleSheet/x:cellXfs/x:xf[2]/x:alignment", 1); - - xDocSh->DoClose(); -} - -void ScExportTest::testTdf129985() -{ - ScDocShellRef xDocSh = loadDoc(u"tdf129985.", FORMAT_XLSX); - CPPUNIT_ASSERT(xDocSh.is()); - - xmlDocUniquePtr pDoc = XPathHelper::parseExport2(*this, *xDocSh, m_xSFactory, "xl/styles.xml", FORMAT_XLSX); - CPPUNIT_ASSERT(pDoc); - - assertXPath(pDoc, "/x:styleSheet/x:numFmts/x:numFmt[2]", "formatCode", "m/d/yyyy"); - - xDocSh->DoClose(); -} - -void ScExportTest::testTdf73063() -{ - ScDocShellRef xDocSh = loadDoc(u"tdf73063.", FORMAT_XLSX); - CPPUNIT_ASSERT(xDocSh.is()); - - xmlDocUniquePtr pDoc = XPathHelper::parseExport2(*this, *xDocSh, m_xSFactory, "xl/styles.xml", FORMAT_XLSX); - CPPUNIT_ASSERT(pDoc); - - assertXPath(pDoc, "/x:styleSheet/x:numFmts/x:numFmt[2]", "formatCode", "[$-1C1A]dddd\", \"d\". \"mmmm\\ yyyy;@"); - - xDocSh->DoClose(); -} - -xmlDocUniquePtr ScExportTest::testTdf95640(std::u16string_view rFileName, sal_Int32 nSourceFormat, - sal_Int32 nDestFormat) -{ - ScDocShellRef xShell = loadDoc(rFileName, nSourceFormat); - CPPUNIT_ASSERT(xShell); - - auto pXPathFile = ScBootstrapFixture::exportTo(&(*xShell), nDestFormat); - xShell->DoClose(); - - return XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/worksheets/sheet1.xml"); -} - -void ScExportTest::testTdf95640_ods_to_xlsx() -{ - // Roundtripping sort options with user defined list to XLSX - xmlDocUniquePtr pDoc = testTdf95640(u"tdf95640.", FORMAT_ODS, FORMAT_XLSX); - - assertXPath(pDoc, "//x:worksheet/x:autoFilter", "ref", "A1:B4"); - - assertXPath(pDoc, "//x:worksheet/x:autoFilter/x:sortState/x:sortCondition", "ref", "A2:A4"); - - assertXPath(pDoc, "//x:worksheet/x:autoFilter/x:sortState/x:sortCondition", "customList", - "Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec"); -} - -void ScExportTest::testTdf95640_ods_to_xlsx_with_standard_list() -{ - // Roundtripping sort options with user defined list to XLSX - xmlDocUniquePtr pDoc = testTdf95640(u"tdf95640_standard_list.", FORMAT_ODS, FORMAT_XLSX); - - assertXPath(pDoc, "//x:worksheet/x:autoFilter", "ref", "A1:B4"); - - assertXPath(pDoc, "//x:worksheet/x:autoFilter/x:sortState/x:sortCondition", "ref", "A2:A4"); - - assertXPath(pDoc, "//x:worksheet/x:autoFilter/x:sortState/x:sortCondition", "customList", - "Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday"); -} - -void ScExportTest::testTdf95640_xlsx_to_xlsx() -{ - // XLSX Roundtripping sort options with custom sort list - note - // that compared to ODS source documents above, here we _actually_ - // can use custom lists (beyond the global user defines), like - // low, medium, high - xmlDocUniquePtr pDoc = testTdf95640(u"tdf95640.", FORMAT_XLSX, FORMAT_XLSX); - - assertXPath(pDoc, "//x:worksheet/x:autoFilter", "ref", "A1:B4"); - - assertXPath(pDoc, "//x:worksheet/x:autoFilter/x:sortState/x:sortCondition", "ref", "A2:A4"); - - assertXPath(pDoc, "//x:worksheet/x:autoFilter/x:sortState/x:sortCondition", "customList", - "Low,Medium,High"); -} - -void ScExportTest::testDateAutofilterXLSX() -{ - // XLSX Roundtripping autofilter with date list - ScDocShellRef xDocSh = loadDoc(u"dateAutofilter.", FORMAT_XLSX); - CPPUNIT_ASSERT(xDocSh.is()); - - xmlDocUniquePtr pDoc = XPathHelper::parseExport2(*this, *xDocSh, m_xSFactory, "xl/worksheets/sheet1.xml", FORMAT_XLSX); - CPPUNIT_ASSERT(pDoc); - - assertXPath(pDoc, "//x:autoFilter", "ref", "A1:B4"); - assertXPath(pDoc, "//x:autoFilter/x:filterColumn/x:filters/x:dateGroupItem[1]", "day", "02"); - assertXPath(pDoc, "//x:autoFilter/x:filterColumn/x:filters/x:dateGroupItem[1]", "month", "03"); - assertXPath(pDoc, "//x:autoFilter/x:filterColumn/x:filters/x:dateGroupItem[1]", "year", "2017"); - assertXPath(pDoc, "//x:autoFilter/x:filterColumn/x:filters/x:dateGroupItem[1]", "dateTimeGrouping", "day"); - - assertXPath(pDoc, "//x:autoFilter/x:filterColumn/x:filters/x:dateGroupItem[2]", "day", "01"); - assertXPath(pDoc, "//x:autoFilter/x:filterColumn/x:filters/x:dateGroupItem[2]", "month", "10"); - assertXPath(pDoc, "//x:autoFilter/x:filterColumn/x:filters/x:dateGroupItem[2]", "year", "2014"); - assertXPath(pDoc, "//x:autoFilter/x:filterColumn/x:filters/x:dateGroupItem[2]", "dateTimeGrouping", "day"); - - xDocSh->DoClose(); -} - -void ScExportTest::testDateAutofilterODS() -{ - ScDocShellRef xDocSh = loadDoc(u"tdf142231.", FORMAT_ODS); - CPPUNIT_ASSERT(xDocSh.is()); - - xmlDocUniquePtr pDoc = XPathHelper::parseExport2(*this, *xDocSh, m_xSFactory, "content.xml", FORMAT_ODS); - CPPUNIT_ASSERT(pDoc); - - assertXPath(pDoc, "//table:filter/table:filter-and/table:filter-condition[1]", "value", "Calc"); - assertXPath(pDoc, "//table:filter/table:filter-and/table:filter-condition[2]", "value", "2021-05-04"); -} - -void ScExportTest::testAutofilterColorsODF() -{ - ScDocShellRef xDocSh = loadDoc(u"autofilter-colors.", FORMAT_ODS); - CPPUNIT_ASSERT(xDocSh.is()); - - xmlDocUniquePtr pDoc = XPathHelper::parseExport2(*this, *xDocSh, m_xSFactory, "content.xml", FORMAT_ODS); - CPPUNIT_ASSERT(pDoc); - - assertXPath(pDoc, "//table:filter/table:filter-and/table:filter-condition[1]", "value", "#e8f2a1"); - assertXPath(pDoc, "//table:filter/table:filter-and/table:filter-condition[1][@loext:data-type='background-color']"); - assertXPath(pDoc, "//table:filter/table:filter-and/table:filter-condition[2]", "value", "#3465a4"); - assertXPath(pDoc, "//table:filter/table:filter-and/table:filter-condition[2][@loext:data-type='text-color']"); -} - -void ScExportTest::testAutofilterColorsOOXML() -{ - ScDocShellRef xDocSh = loadDoc(u"autofilter-colors.", FORMAT_XLSX); - CPPUNIT_ASSERT(xDocSh.is()); - - xmlDocUniquePtr pDoc = XPathHelper::parseExport2(*this, *xDocSh, m_xSFactory, - "xl/tables/table1.xml", FORMAT_XLSX); - CPPUNIT_ASSERT(pDoc); - - assertXPath(pDoc, "/x:table/x:autoFilter/x:filterColumn/x:colorFilter", "dxfId", "4"); -} - -void ScExportTest::testAutofilterColorsStyleOOXML() -{ - ScDocShellRef xDocSh = loadDoc(u"autofilter-colors.", FORMAT_XLSX); - CPPUNIT_ASSERT(xDocSh.is()); - - xmlDocUniquePtr pDoc - = XPathHelper::parseExport2(*this, *xDocSh, m_xSFactory, "xl/styles.xml", FORMAT_XLSX); - CPPUNIT_ASSERT(pDoc); - - assertXPath(pDoc, "/x:styleSheet/x:dxfs/x:dxf[5]/x:fill/x:patternFill/x:bgColor", "rgb", - "FFFFD7D7"); -} - -void ScExportTest::testTdf88657ODS() -{ - ScDocShellRef xDocSh = loadDoc(u"tdf88657.", FORMAT_ODS); - CPPUNIT_ASSERT(xDocSh.is()); - - xmlDocUniquePtr pDoc = XPathHelper::parseExport2(*this, *xDocSh, m_xSFactory, "styles.xml", FORMAT_ODS); - CPPUNIT_ASSERT(pDoc); - - assertXPath(pDoc, "//number:fraction", "min-denominator-digits", "3"); - - xDocSh->DoClose(); -} - void ScExportTest::testConditionalFormatRangeListXLSX() { ScDocShellRef xDocSh = loadDoc(u"conditionalformat_rangelist.", FORMAT_ODS); CPPUNIT_ASSERT(xDocSh.is()); - xmlDocUniquePtr pDoc = XPathHelper::parseExport2(*this, *xDocSh, m_xSFactory, "xl/worksheets/sheet1.xml", FORMAT_XLSX); CPPUNIT_ASSERT(pDoc); - assertXPath(pDoc, "//x:conditionalFormatting", "sqref", "F4 F10"); - xDocSh->DoClose(); } @@ -4732,12 +4147,9 @@ void ScExportTest::testConditionalFormatContainsTextXLSX() { ScDocShellRef xDocSh = loadDoc(u"conditionalformat_containstext.", FORMAT_ODS); CPPUNIT_ASSERT(xDocSh.is()); - xmlDocUniquePtr pDoc = XPathHelper::parseExport2(*this, *xDocSh, m_xSFactory, "xl/worksheets/sheet1.xml", FORMAT_XLSX); CPPUNIT_ASSERT(pDoc); - assertXPathContent(pDoc, "//x:conditionalFormatting/x:cfRule/x:formula", "NOT(ISERROR(SEARCH(\"test\",A1)))"); - xDocSh->DoClose(); } @@ -4745,45 +4157,34 @@ void ScExportTest::testConditionalFormatPriorityCheckXLSX() { ScDocShellRef xDocSh = loadDoc(u"conditional_fmt_checkpriority.", FORMAT_XLSX); CPPUNIT_ASSERT(xDocSh.is()); - xmlDocUniquePtr pDoc = XPathHelper::parseExport2(*this, *xDocSh, m_xSFactory, "xl/worksheets/sheet1.xml", FORMAT_XLSX); CPPUNIT_ASSERT(pDoc); - constexpr bool bHighPriorityExtensionA1 = true; // Should A1's extension cfRule has higher priority than normal cfRule ? constexpr bool bHighPriorityExtensionA3 = false; // Should A3's extension cfRule has higher priority than normal cfRule ? - size_t nA1NormalPriority = 0; size_t nA1ExtPriority = 0; size_t nA3NormalPriority = 0; size_t nA3ExtPriority = 0; - for (size_t nIdx = 1; nIdx <= 2; ++nIdx) { OString aIdx = OString::number(nIdx); OUString aCellAddr = getXPath(pDoc, "//x:conditionalFormatting[" + aIdx + "]", "sqref"); OUString aPriority = getXPath(pDoc, "//x:conditionalFormatting[" + aIdx + "]/x:cfRule", "priority"); - CPPUNIT_ASSERT_MESSAGE("conditionalFormatting sqref must be either A1 or A3", aCellAddr == "A1" || aCellAddr == "A3"); - if (aCellAddr == "A1") nA1NormalPriority = aPriority.toUInt32(); else nA3NormalPriority = aPriority.toUInt32(); - aCellAddr = getXPathContent(pDoc, "//x:extLst/x:ext[1]/x14:conditionalFormattings/x14:conditionalFormatting[" + aIdx + "]/xm:sqref"); aPriority = getXPath(pDoc, "//x:extLst/x:ext[1]/x14:conditionalFormattings/x14:conditionalFormatting[" + aIdx + "]/x14:cfRule", "priority"); - CPPUNIT_ASSERT_MESSAGE("x14:conditionalFormatting sqref must be either A1 or A3", aCellAddr == "A1" || aCellAddr == "A3"); - if (aCellAddr == "A1") nA1ExtPriority = aPriority.toUInt32(); else nA3ExtPriority = aPriority.toUInt32(); } - CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong priorities for A1", bHighPriorityExtensionA1, nA1ExtPriority < nA1NormalPriority); CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong priorities for A3", bHighPriorityExtensionA3, nA3ExtPriority < nA3NormalPriority); - xDocSh->DoClose(); } @@ -4791,1389 +4192,14 @@ void ScExportTest::testConditionalFormatOriginXLSX() { ScDocShellRef xDocSh = loadDoc(u"conditional_fmt_origin.", FORMAT_XLSX); CPPUNIT_ASSERT(xDocSh.is()); - xmlDocUniquePtr pDoc = XPathHelper::parseExport2(*this, *xDocSh, m_xSFactory, "xl/worksheets/sheet1.xml", FORMAT_XLSX); CPPUNIT_ASSERT(pDoc); - // tdf#124953 : The range-list is B3:C6 F1:G2, origin address in the formula should be B1, not B3. OUString aFormula = getXPathContent(pDoc, "//x:conditionalFormatting/x:cfRule/x:formula"); CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong origin address in formula", OUString("NOT(ISERROR(SEARCH(\"BAC\",B1)))"), aFormula); - - xDocSh->DoClose(); -} - -void ScExportTest::testTdf41722() -{ - ScDocShellRef xDocSh = loadDoc(u"tdf41722.", FORMAT_XLSX); - CPPUNIT_ASSERT(xDocSh.is()); - - xmlDocUniquePtr pDoc = XPathHelper::parseExport2(*this, *xDocSh, m_xSFactory, "xl/worksheets/sheet1.xml", FORMAT_XLSX); - CPPUNIT_ASSERT(pDoc); - - assertXPath(pDoc, "//x:conditionalFormatting/x:cfRule[1]", "operator", "containsText"); - assertXPath(pDoc, "//x:conditionalFormatting/x:cfRule[2]", "operator", "containsText"); - assertXPath(pDoc, "//x:conditionalFormatting/x:cfRule[3]", "operator", "containsText"); - - xDocSh->DoClose(); -} - -void ScExportTest::testTdf113621() -{ - ScDocShellRef xDocSh = loadDoc(u"tdf113621.", FORMAT_XLSX); - CPPUNIT_ASSERT(xDocSh.is()); - - xmlDocUniquePtr pDoc = XPathHelper::parseExport2(*this, *xDocSh, m_xSFactory, "xl/worksheets/sheet1.xml", FORMAT_XLSX); - CPPUNIT_ASSERT(pDoc); - - assertXPath(pDoc, "//x:conditionalFormatting", "sqref", "A1:A1048576"); - - xDocSh->DoClose(); -} - -void ScExportTest::testEscapeCharInNumberFormatXLSX() -{ - ScDocShellRef xDocSh = loadDoc(u"tdf81939.", FORMAT_XLSX); - CPPUNIT_ASSERT( xDocSh.is() ); - xDocSh = saveAndReload( &(*xDocSh), FORMAT_XLSX); - CPPUNIT_ASSERT( xDocSh.is() ); - - xmlDocUniquePtr pDoc = XPathHelper::parseExport2(*this, *xDocSh, m_xSFactory, "xl/styles.xml", FORMAT_XLSX); - CPPUNIT_ASSERT(pDoc); - - const sal_Unicode cEuro (8364); // € symbol - assertXPath(pDoc, "/x:styleSheet/x:numFmts/x:numFmt[2]", "formatCode", "00\\ 00\\ 00\\ 00\\ 00"); - assertXPath(pDoc, "/x:styleSheet/x:numFmts/x:numFmt[3]", "formatCode", "00\\.00\\.00\\.000\\.0"); // tdf#81939 - // "_-* #,##0\ _€_-;\-* #,##0\ _€_-;_-* "- "_€_-;_-@_-" // tdf#81222 - OUString rFormatStrExpected ( "_-* #,##0\\ _" + OUStringChar(cEuro) + "_-;\\-* #,##0\\ _" + - OUStringChar(cEuro) + "_-;_-* \"- \"_" + OUStringChar(cEuro) + "_-;_-@_-" ); - assertXPath(pDoc, "/x:styleSheet/x:numFmts/x:numFmt[4]", "formatCode", rFormatStrExpected ); - // "_-* #,##0" €"_-;\-* #,##0" €"_-;_-* "- €"_-;_-@_-"); - rFormatStrExpected = "_-* #,##0\" " + OUStringChar(cEuro) + "\"_-;\\-* #,##0\" " + - OUStringChar(cEuro) + "\"_-;_-* \"- " + OUStringChar(cEuro) + "\"_-;_-@_-"; - assertXPath(pDoc, "/x:styleSheet/x:numFmts/x:numFmt[5]", "formatCode", rFormatStrExpected ); - // remove escape char in fraction - assertXPath(pDoc, "/x:styleSheet/x:numFmts/x:numFmt[6]", "formatCode", "# ?/?;[RED]\\-# #/#####"); - - xDocSh->DoClose(); -} - -void ScExportTest::testNatNumInNumberFormatXLSX() -{ - ScDocShellRef xDocSh = loadDoc(u"tdf79398_NatNum5.", FORMAT_ODS); - CPPUNIT_ASSERT( xDocSh.is() ); - xDocSh = saveAndReload( &(*xDocSh), FORMAT_XLSX); // Convert [NatNum5] to [DBNum2] in Chinese - CPPUNIT_ASSERT( xDocSh.is() ); - - xmlDocUniquePtr pDoc = XPathHelper::parseExport2(*this, *xDocSh, m_xSFactory, "xl/styles.xml", FORMAT_XLSX); - CPPUNIT_ASSERT(pDoc); - - assertXPath(pDoc, "/x:styleSheet/x:numFmts/x:numFmt[3]", "formatCode", "[DBNum2][$-804]General;[RED][DBNum2][$-804]General"); - - xDocSh->DoClose(); -} - -void ScExportTest::testExponentWithoutSignFormatXLSX() -{ - ScDocShellRef xDocSh = loadDoc(u"tdf102370_ExponentWithoutSign.", FORMAT_ODS); - CPPUNIT_ASSERT( xDocSh.is() ); - xDocSh = saveAndReload( &(*xDocSh), FORMAT_XLSX); - CPPUNIT_ASSERT( xDocSh.is() ); - - xDocSh = saveAndReload( &(*xDocSh), FORMAT_ODS); - CPPUNIT_ASSERT(xDocSh.is()); - - ScDocument& rDoc = xDocSh->GetDocument(); - sal_uInt32 nNumberFormat; - rDoc.GetNumberFormat(0, 0, 0, nNumberFormat); - const SvNumberformat* pNumberFormat = rDoc.GetFormatTable()->GetEntry(nNumberFormat); - const OUString& rFormatStr = pNumberFormat->GetFormatstring(); - - CPPUNIT_ASSERT_EQUAL_MESSAGE("Number format lost exponent without sign during Excel export", OUString("0.00E0"), rFormatStr); - - xDocSh->DoClose(); -} - -void ScExportTest::testExtendedLCIDXLSX() -{ - ScDocShellRef xDocSh = loadDoc(u"tdf36038_ExtendedLCID.", FORMAT_ODS); - CPPUNIT_ASSERT( xDocSh.is() ); - xDocSh = saveAndReload( &(*xDocSh), FORMAT_XLSX); - CPPUNIT_ASSERT( xDocSh.is() ); - - xmlDocUniquePtr pDoc = XPathHelper::parseExport2(*this, *xDocSh, m_xSFactory, "xl/styles.xml", FORMAT_XLSX); - CPPUNIT_ASSERT(pDoc); - // Check export - assertXPath(pDoc, "/x:styleSheet/x:numFmts/x:numFmt[2]", "formatCode", "[$-107041E]dd\\-mm\\-yyyy"); - assertXPath(pDoc, "/x:styleSheet/x:numFmts/x:numFmt[3]", "formatCode", "[$-D07041E]dd\\-mm\\-yyyy"); - assertXPath(pDoc, "/x:styleSheet/x:numFmts/x:numFmt[4]", "formatCode", "[$-1030411]dd\\-mm\\-ee"); - assertXPath(pDoc, "/x:styleSheet/x:numFmts/x:numFmt[5]", "formatCode", "[$-1B030411]dd\\-mm\\-ee"); - assertXPath(pDoc, "/x:styleSheet/x:numFmts/x:numFmt[6]", "formatCode", "[$-108040D]dd\\-mm\\-yyyy"); - //assertXPath(pDoc, "/x:styleSheet/x:numFmts/x:numFmt[7]", "formatCode", "[$-108040D]dd\\-mm\\-yyyy"); - assertXPath(pDoc, "/x:styleSheet/x:numFmts/x:numFmt[7]", "formatCode", "[$-1060401]dd\\-mm\\-yyyy"); - assertXPath(pDoc, "/x:styleSheet/x:numFmts/x:numFmt[8]", "formatCode", "[$-2060401]dd\\-mm\\-yyyy"); - - // Check import - ScDocument& rDoc = xDocSh->GetDocument(); - SvNumberFormatter* pNumFormatter = rDoc.GetFormatTable(); - sal_uInt32 nNumberFormat; - const OUString aLang[5] = { "[$-41E]", "[$-411]", "[$-40D]", "[$-401]", "[$-500]" }; - const OUString aCalendar[5] = { "[~buddhist]DD-MM-YYYY", "DD-MM-EE", "[~jewish]DD-MM-YYYY", "[~hijri]DD-MM-YYYY", "[~dangi]YYYY/MM/DD" }; - // Note: ja-JP Gengou calendar is an implicit secondary (non-gregorian) - // calendar, the explicit [~gengou] calendar modifier does not need to be - // present, the E and EE keywords are used instead of YY and YYYY. - for ( sal_Int16 nCol = 1; nCol <= 2; nCol++ ) - { - for ( sal_Int16 nRow = 1; nRow <= 4; nRow++ ) - { - rDoc.GetNumberFormat(nCol, nRow, 0, nNumberFormat); - const SvNumberformat* pNumberFormat = pNumFormatter->GetEntry(nNumberFormat); - const OUString& rFormatStr = pNumberFormat->GetFormatstring(); - const OUString aExpectedFormatStr = aLang[nRow-1] + ( (nCol==2 && nRow!=3) ? OUString("[NatNum1]") : OUString() ) + aCalendar[nRow-1]; - - CPPUNIT_ASSERT_EQUAL_MESSAGE("Number format lost extended LCID during Excel export", aExpectedFormatStr, rFormatStr); - } - } - - xDocSh->DoClose(); -} - -void ScExportTest::testHiddenRepeatedRowsODS() -{ - ScDocShellRef xDocSh = loadDoc(u"empty.", FORMAT_ODS); - CPPUNIT_ASSERT( xDocSh.is() ); - - { - ScDocument& rDoc = xDocSh->GetDocument(); - rDoc.SetRowHidden(0, 20, 0, true); - } - - xDocSh = saveAndReload( &(*xDocSh), FORMAT_ODS); - ScDocument& rDoc = xDocSh->GetDocument(); - SCROW nFirstRow = 0; - SCROW nLastRow = 0; - bool bHidden = rDoc.RowHidden(0, 0, &nFirstRow, &nLastRow); - CPPUNIT_ASSERT(bHidden); - CPPUNIT_ASSERT_EQUAL(SCROW(0), nFirstRow); - CPPUNIT_ASSERT_EQUAL(SCROW(20), nLastRow); - xDocSh->DoClose(); -} - -void ScExportTest::testHyperlinkTargetFrameODS() -{ - ScDocShellRef xDocSh = loadDoc(u"hyperlink_frame.", FORMAT_ODS); - CPPUNIT_ASSERT(xDocSh.is()); - - ScDocument& rDoc = xDocSh->GetDocument(); - const EditTextObject* pEditText = rDoc.GetEditText(ScAddress(2, 5, 0)); - CPPUNIT_ASSERT(pEditText); - - const SvxFieldData* pData = pEditText->GetFieldData(0, 0, text::textfield::Type::URL); - CPPUNIT_ASSERT_MESSAGE("Failed to get the URL data.", pData); - CPPUNIT_ASSERT_EQUAL_MESSAGE("Failed to get the URL data.", text::textfield::Type::URL, pData->GetClassId()); - - const SvxURLField* pURLData = static_cast<const SvxURLField*>(pData); - OUString aTargetFrame = pURLData->GetTargetFrame(); - CPPUNIT_ASSERT_EQUAL(OUString("_blank"), aTargetFrame); - - xmlDocUniquePtr pDoc = XPathHelper::parseExport2(*this, *xDocSh, m_xSFactory, "content.xml", FORMAT_ODS); - CPPUNIT_ASSERT(pDoc); - OUString aTargetFrameExport = getXPath(pDoc, - "/office:document-content/office:body/office:spreadsheet/table:table/table:table-row[2]/table:table-cell[2]/text:p/text:a", "target-frame-name"); - CPPUNIT_ASSERT_EQUAL(OUString("_blank"), aTargetFrameExport); - - xDocSh->DoClose(); -} - -void ScExportTest::testOpenDocumentAsReadOnly() -{ - ScDocShellRef xDocSh = loadDoc(u"open-as-read-only.", FORMAT_XLSX); - CPPUNIT_ASSERT(xDocSh->IsSecurityOptOpenReadOnly()); - ScDocShellRef xDocSh2 = saveAndReload(xDocSh.get(), FORMAT_XLSX); - CPPUNIT_ASSERT(xDocSh2->IsSecurityOptOpenReadOnly()); - xDocSh->DoClose(); - xDocSh2->DoClose(); -} - -void ScExportTest::testKeepSettingsOfBlankRows() -{ - ScDocShellRef xDocSh = loadDoc(u"tdf41425.", FORMAT_XLSX); - CPPUNIT_ASSERT(xDocSh.is()); - - std::shared_ptr<utl::TempFile> pXPathFile = ScBootstrapFixture::exportTo(&(*xDocSh), FORMAT_XLSX); - xmlDocUniquePtr pSheet = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/worksheets/sheet1.xml"); - CPPUNIT_ASSERT(pSheet); - - // saved blank row with not default setting in A2 - assertXPath(pSheet, "/x:worksheet/x:sheetData/x:row", 2); - - xDocSh->DoClose(); -} - -void ScExportTest::testTdf133595() -{ - ScDocShellRef xDocSh = loadDoc(u"tdf133595.", FORMAT_XLSX); - CPPUNIT_ASSERT(xDocSh.is()); - - std::shared_ptr<utl::TempFile> pXPathFile = ScBootstrapFixture::exportTo(&(*xDocSh), FORMAT_XLSX); - xmlDocUniquePtr pSheet = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/worksheets/sheet1.xml"); - CPPUNIT_ASSERT(pSheet); - - // without the fix in place, mc:AlternateContent would have been added to sheet1 - assertXPath(pSheet, "/x:worksheet/mc:AlternateContent", 0); - - xDocSh->DoClose(); -} - -void ScExportTest::testTdf134769() -{ - ScDocShellRef xDocSh = loadDoc(u"tdf134769.", FORMAT_XLSX); - CPPUNIT_ASSERT(xDocSh.is()); - - std::shared_ptr<utl::TempFile> pXPathFile = ScBootstrapFixture::exportTo(&(*xDocSh), FORMAT_XLSX); - xmlDocUniquePtr pSheet = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/worksheets/sheet1.xml"); - CPPUNIT_ASSERT(pSheet); - - // without the fix in place, the legacyDrawing would have been exported after the checkbox - // and Excel would have claimed the document is corrupted - // Use their ids to check the order - assertXPath(pSheet, "/x:worksheet/x:drawing", "id", "rId2"); - assertXPath(pSheet, "/x:worksheet/x:legacyDrawing", "id", "rId3"); - assertXPath(pSheet, "/x:worksheet/mc:AlternateContent/mc:Choice/x:controls/mc:AlternateContent/mc:Choice/x:control", "id", "rId4"); - - xDocSh->DoClose(); -} - -void ScExportTest::testTdf106181() -{ - ScDocShellRef xDocSh = loadDoc(u"tdf106181.", FORMAT_ODS); - CPPUNIT_ASSERT(xDocSh.is()); - - std::shared_ptr<utl::TempFile> pXPathFile = ScBootstrapFixture::exportTo(&(*xDocSh), FORMAT_XLSX); - xmlDocUniquePtr pSheet = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/worksheets/sheet1.xml"); - CPPUNIT_ASSERT(pSheet); - - assertXPath(pSheet, "/x:worksheet/mc:AlternateContent/mc:Choice/x:controls/mc:AlternateContent/mc:Choice/x:control", "name", "Check Box"); - assertXPath(pSheet, "/x:worksheet/mc:AlternateContent/mc:Choice/x:controls/mc:AlternateContent/mc:Choice/x:control/x:controlPr", "altText", "Check Box 1"); - - xmlDocUniquePtr pDrawing = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/drawings/drawing1.xml"); - CPPUNIT_ASSERT(pDrawing); - - assertXPath(pDrawing, "/xdr:wsDr/mc:AlternateContent/mc:Choice/xdr:twoCellAnchor/xdr:sp/xdr:nvSpPr/xdr:cNvPr", "name", "Check Box 1"); - assertXPath(pDrawing, "/xdr:wsDr/mc:AlternateContent/mc:Choice/xdr:twoCellAnchor/xdr:sp/xdr:nvSpPr/xdr:cNvPr", "descr", "Check Box"); - assertXPath(pDrawing, "/xdr:wsDr/mc:AlternateContent/mc:Choice/xdr:twoCellAnchor/xdr:sp/xdr:nvSpPr/xdr:cNvPr", "hidden", "0"); - - xDocSh->DoClose(); -} - -void ScExportTest::testTdf105272() -{ - ScDocShellRef xDocSh = loadDoc(u"tdf105272.", FORMAT_XLSX); - CPPUNIT_ASSERT(xDocSh.is()); - xDocSh = saveAndReload(xDocSh.get(), FORMAT_XLSX); - ScDocument& rDoc = xDocSh->GetDocument(); - //without the fix in place,it would fail - //Expected: Table1[[#This Row],[Total]]/Table1[[#This Row],['# Athletes]] - //Actual : table1[[#this row],[total]]/table1[[#this row],['# athletes]] - - ASSERT_FORMULA_EQUAL(rDoc, ScAddress(7, 3, 0), - "Table1[[#This Row],[Total]]/Table1[[#This Row],['# Athletes]]", - "Wrong formula"); -} - -void ScExportTest::testTdf118990() -{ - ScDocShellRef xDocSh = loadDoc(u"tdf118990.", FORMAT_XLSX); - CPPUNIT_ASSERT(xDocSh.is()); - xDocSh = saveAndReload(xDocSh.get(), FORMAT_XLSX); - ScDocument& rDoc = xDocSh->GetDocument(); - - // TODO: also test A1, which contains a UNC reference to \\localhost\share\lookupsource.xlsx, - // but currently looses "localhost" part when normalized in INetURLObject, becoming - // file:///share/lookupsource.xlsx - which is incorrect, since it points to local filesystem - // and not to Windows network share. - - ASSERT_FORMULA_EQUAL(rDoc, ScAddress(0, 1, 0), - "VLOOKUP(B1,'file://192.168.1.1/share/lookupsource.xlsx'#$Sheet1.A1:B5,2)", - "Wrong Windows share (using host IP) URL in A2"); - - ASSERT_FORMULA_EQUAL(rDoc, ScAddress(0, 2, 0), - "VLOOKUP(B1,'file://NETWORKHOST/share/lookupsource.xlsx'#$Sheet1.A1:B5,2)", - "Wrong Windows share (using hostname) URL in A3"); - - xDocSh->DoClose(); -} - -void ScExportTest::testTdf121612() -{ - ScDocShellRef xDocSh = loadDoc(u"tdf121612.", FORMAT_ODS); - CPPUNIT_ASSERT(xDocSh.is()); - xDocSh = saveAndReload(xDocSh.get(), FORMAT_XLSX); - - ScDocument& rDoc = xDocSh->GetDocument(); - - // There should be a pivot table - CPPUNIT_ASSERT(rDoc.HasPivotTable()); - - // DP collection is not lost after export and has one entry - ScDPCollection* pDPColl = rDoc.GetDPCollection(); - CPPUNIT_ASSERT(pDPColl); - CPPUNIT_ASSERT_EQUAL(size_t(1), pDPColl->GetCount()); - - xDocSh->DoClose(); -} - -void ScExportTest::testTdf112936() -{ - ScDocShellRef xDocSh = loadDoc(u"tdf112936.", FORMAT_XLSX); - CPPUNIT_ASSERT(xDocSh.is()); - - xmlDocUniquePtr pDoc = XPathHelper::parseExport2(*this, *xDocSh, m_xSFactory, "xl/pivotCache/pivotCacheDefinition1.xml", FORMAT_XLSX); - CPPUNIT_ASSERT(pDoc); - - assertXPath(pDoc, "//x:pivotCacheDefinition", "recordCount", "4"); - assertXPath(pDoc, "//x:pivotCacheDefinition", "createdVersion", "3"); - - xDocSh->DoClose(); -} - -void ScExportTest::testXltxExport() -{ - // Create new document - ScDocShell* pShell = new ScDocShell( - SfxModelFlags::EMBEDDED_OBJECT | - SfxModelFlags::DISABLE_EMBEDDED_SCRIPTS | - SfxModelFlags::DISABLE_DOCUMENT_RECOVERY); - pShell->DoInitNew(); - - // Export as template and check content type - xmlDocUniquePtr pDoc = XPathHelper::parseExport2(*this, *pShell, m_xSFactory, "[Content_Types].xml", FORMAT_XLTX); - CPPUNIT_ASSERT(pDoc); - assertXPath(pDoc, "/ContentType:Types/ContentType:Override[@PartName='/xl/workbook.xml']", - "ContentType", "application/vnd.openxmlformats-officedocument.spreadsheetml.template.main+xml"); -} - -void ScExportTest::testPivotCacheAfterExportXLSX() -{ - ScDocShellRef xDocSh = loadDoc(u"numgroup_example.", FORMAT_ODS); - CPPUNIT_ASSERT(xDocSh.is()); - - // export only - std::shared_ptr<utl::TempFile> pTemp = saveAs(xDocSh.get(), FORMAT_XLSX); - - ScDocument& rDoc = xDocSh->GetDocument(); - CPPUNIT_ASSERT(rDoc.HasPivotTable()); - - // Two pivot tables - ScDPCollection* pDPColl = rDoc.GetDPCollection(); - CPPUNIT_ASSERT(pDPColl); - CPPUNIT_ASSERT_EQUAL(size_t(2), pDPColl->GetCount()); - - // One cache - ScDPCollection::SheetCaches& rSheetCaches = pDPColl->GetSheetCaches(); - CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), rSheetCaches.size()); - const ScDPCache* pCache = rSheetCaches.getExistingCache(ScRange(0, 0, 0, 3, 30, 0)); - CPPUNIT_ASSERT_MESSAGE("Pivot cache is expected for A1:D31 on the first sheet.", pCache); - - // See if XLSX export didn't damage group info of the 1st pivot table - const ScDPNumGroupInfo* pInfo = pCache->GetNumGroupInfo(1); - CPPUNIT_ASSERT_MESSAGE("No number group info :(", pInfo); - - xDocSh->DoClose(); -} - -void ScExportTest::testTdf114969XLSX() -{ - ScDocShellRef xDocSh = loadDoc(u"sheet_name_with_dots.", FORMAT_ODS); - CPPUNIT_ASSERT(xDocSh.is()); - - xmlDocUniquePtr pDoc = XPathHelper::parseExport2(*this, *xDocSh, m_xSFactory, "xl/worksheets/sheet1.xml", FORMAT_XLSX); - CPPUNIT_ASSERT(pDoc); - assertXPath(pDoc, "/x:worksheet/x:hyperlinks/x:hyperlink[1]", "location", "'1.1.1.1'!C1"); - assertXPath(pDoc, "/x:worksheet/x:hyperlinks/x:hyperlink[2]", "location", "'1.1.1.1'!C2"); - - xDocSh->DoClose(); -} - -void ScExportTest::testTdf115192XLSX() -{ - ScDocShellRef xDocSh = loadDoc(u"test_115192.", FORMAT_XLSX); - CPPUNIT_ASSERT(xDocSh.is()); - - xmlDocUniquePtr pDoc = XPathHelper::parseExport2(*this, *xDocSh, m_xSFactory, "xl/drawings/_rels/drawing1.xml.rels", FORMAT_XLSX); - CPPUNIT_ASSERT(pDoc); - assertXPath(pDoc, "/r:Relationships/r:Relationship[@Id='rId1']", "TargetMode", "External"); - assertXPathNoAttribute(pDoc, "/r:Relationships/r:Relationship[@Id='rId2']", "TargetMode"); - assertXPath(pDoc, "/r:Relationships/r:Relationship[@Id='rId3']", "TargetMode", "External"); - - xDocSh->DoClose(); -} - -void ScExportTest::testTdf91634XLSX() -{ - ScDocShellRef xDocSh = loadDoc(u"image_hyperlink.", FORMAT_XLSX); - CPPUNIT_ASSERT(xDocSh.is()); - std::shared_ptr<utl::TempFile> pXPathFile = ScBootstrapFixture::exportTo(&(*xDocSh), FORMAT_XLSX); - - xmlDocUniquePtr pDoc = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/drawings/drawing1.xml"); - CPPUNIT_ASSERT(pDoc); - assertXPath(pDoc, "/xdr:wsDr/xdr:twoCellAnchor/xdr:pic/xdr:nvPicPr/xdr:cNvPr/a:hlinkClick", 1); - - xmlDocUniquePtr pXmlRels = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/drawings/_rels/drawing1.xml.rels"); - CPPUNIT_ASSERT(pXmlRels); - assertXPath(pXmlRels, "/r:Relationships/r:Relationship[@Id='rId1']", "Target", "https://www.google.com/"); - assertXPath(pXmlRels, "/r:Relationships/r:Relationship[@Id='rId1']", "TargetMode", "External"); - - xDocSh->DoClose(); -} - -void ScExportTest::testValidationCopyPaste() -{ - ScDocShellRef xDocSh = loadDoc(u"validation-copypaste.", FORMAT_ODS); - CPPUNIT_ASSERT(xDocSh.is()); - ScDocument& rSrcDoc = xDocSh->GetDocument(); - - // Copy B1 from src doc to clip - ScDocument aClipDoc(SCDOCMODE_CLIP); - ScRange aSrcRange(1, 0, 1); - ScClipParam aClipParam(aSrcRange, false); - ScMarkData aMark(rSrcDoc.GetSheetLimits()); - aMark.SetMarkArea(aSrcRange); - rSrcDoc.CopyToClip(aClipParam, &aClipDoc, &aMark, false, false); - - // Create second document, paste B1 from clip - ScDocShell* pShell2 - = new ScDocShell(SfxModelFlags::EMBEDDED_OBJECT | SfxModelFlags::DISABLE_EMBEDDED_SCRIPTS - | SfxModelFlags::DISABLE_DOCUMENT_RECOVERY); - pShell2->DoInitNew(); - ScDocument& rDestDoc = pShell2->GetDocument(); - ScRange aDstRange(1, 0, 0); - ScMarkData aMark2(rDestDoc.GetSheetLimits()); - aMark2.SetMarkArea(aDstRange); - rDestDoc.CopyFromClip(aDstRange, aMark2, InsertDeleteFlags::ALL, nullptr, &aClipDoc); - - // save as XLSX - std::shared_ptr<utl::TempFile> pXPathFile - = ScBootstrapFixture::exportTo(&(*pShell2), FORMAT_XLSX); - - // check validation - xmlDocUniquePtr pDoc - = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/worksheets/sheet1.xml"); - CPPUNIT_ASSERT(pDoc); - assertXPathContent(pDoc, "/x:worksheet/x:dataValidations/x:dataValidation/x:formula1", "#REF!"); -} - -void ScExportTest::testTdf115159() -{ - ScDocShellRef xShell = loadDoc(u"tdf115159.", FORMAT_XLSX); - CPPUNIT_ASSERT(xShell.is()); - ScDocShellRef xDocSh = saveAndReload(xShell.get(), FORMAT_XLSX); - CPPUNIT_ASSERT(xDocSh.is()); - xShell->DoClose(); - - xmlDocUniquePtr pDoc = XPathHelper::parseExport2(*this, *xDocSh, m_xSFactory, "xl/workbook.xml", FORMAT_XLSX); - CPPUNIT_ASSERT(pDoc); - - //assert the existing OOXML built-in name is not duplicated - assertXPath(pDoc, "/x:workbook/x:definedNames/x:definedName", 1); - xDocSh->DoClose(); } -void ScExportTest::testTdf112567() -{ - // Set the system locale to Hungarian (a language with different range separator) - SvtSysLocaleOptions aOptions; - OUString sLocaleConfigString = aOptions.GetLanguageTag().getBcp47(); - aOptions.SetLocaleConfigString("hu-HU"); - aOptions.Commit(); - comphelper::ScopeGuard g([&aOptions, &sLocaleConfigString] { - aOptions.SetLocaleConfigString(sLocaleConfigString); - aOptions.Commit(); - }); - - ScDocShellRef xShell = loadDoc(u"tdf112567.", FORMAT_XLSX); - CPPUNIT_ASSERT(xShell.is()); - ScDocShellRef xDocSh = saveAndReload(xShell.get(), FORMAT_XLSX); - CPPUNIT_ASSERT(xDocSh.is()); - xShell->DoClose(); - - xmlDocUniquePtr pDoc = XPathHelper::parseExport2(*this, *xDocSh, m_xSFactory, "xl/workbook.xml", FORMAT_XLSX); - CPPUNIT_ASSERT(pDoc); - - //assert the existing OOXML built-in name is not duplicated - assertXPath(pDoc, "/x:workbook/x:definedNames/x:definedName", 1); - - xDocSh->DoClose(); -} - -void ScExportTest::testTdf112567b() -{ - // Set the system locale to Hungarian (a language with different range separator) - SvtSysLocaleOptions aOptions; - OUString sLocaleConfigString = aOptions.GetLanguageTag().getBcp47(); - aOptions.SetLocaleConfigString("hu-HU"); - aOptions.Commit(); - comphelper::ScopeGuard g([&aOptions, &sLocaleConfigString] { - aOptions.SetLocaleConfigString(sLocaleConfigString); - aOptions.Commit(); - }); - - ScDocShellRef xShell = loadDoc(u"tdf112567.", FORMAT_ODS); - CPPUNIT_ASSERT(xShell.is()); - ScDocShellRef xDocSh = saveAndReload(xShell.get(), FORMAT_XLSX); - CPPUNIT_ASSERT(xDocSh.is()); - xShell->DoClose(); - - xmlDocUniquePtr pDoc = XPathHelper::parseExport2(*this, *xDocSh, m_xSFactory, "xl/workbook.xml", FORMAT_XLSX); - CPPUNIT_ASSERT(pDoc); - - //assert the existing OOXML built-in name is not duplicated - assertXPath(pDoc, "/x:workbook/x:definedNames/x:definedName", 1); - - //and it contains "," instead of ";" - assertXPathContent(pDoc, "/x:workbook/x:definedNames/x:definedName[1]", "Sheet1!$A:$A,Sheet1!$1:$1"); - - xDocSh->DoClose(); -} - -void ScExportTest::testTdf123645XLSX() -{ - ScDocShellRef xDocSh = loadDoc(u"chart_hyperlink.", FORMAT_XLSX); - CPPUNIT_ASSERT(xDocSh.is()); - std::shared_ptr<utl::TempFile> pXPathFile = ScBootstrapFixture::exportTo(&(*xDocSh), FORMAT_XLSX); - - xmlDocUniquePtr pDoc = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/drawings/drawing1.xml"); - CPPUNIT_ASSERT(pDoc); - assertXPath(pDoc, "/xdr:wsDr/xdr:twoCellAnchor[1]/xdr:graphicFrame/xdr:nvGraphicFramePr/xdr:cNvPr/a:hlinkClick", 1); - assertXPath(pDoc, "/xdr:wsDr/xdr:twoCellAnchor[2]/xdr:graphicFrame/xdr:nvGraphicFramePr/xdr:cNvPr/a:hlinkClick", 1); - assertXPath(pDoc, "/xdr:wsDr/xdr:twoCellAnchor[3]/xdr:graphicFrame/xdr:nvGraphicFramePr/xdr:cNvPr/a:hlinkClick", 1); - - xmlDocUniquePtr pXmlRels = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/drawings/_rels/drawing1.xml.rels"); - CPPUNIT_ASSERT(pXmlRels); - assertXPath(pXmlRels, "/r:Relationships/r:Relationship[@Id='rId1']", "TargetMode", "External"); - assertXPathNoAttribute(pXmlRels, "/r:Relationships/r:Relationship[@Id='rId3']", "TargetMode"); - assertXPath(pXmlRels, "/r:Relationships/r:Relationship[@Id='rId5']", "TargetMode", "External"); - assertXPath(pXmlRels, "/r:Relationships/r:Relationship[@Id='rId1']", "Target", "file:///C:/TEMP/test.xlsx"); - assertXPath(pXmlRels, "/r:Relationships/r:Relationship[@Id='rId3']", "Target", "#Sheet2!A1"); - assertXPath(pXmlRels, "/r:Relationships/r:Relationship[@Id='rId5']", "Target", "https://bugs.documentfoundation.org/show_bug.cgi?id=123645"); - - xDocSh->DoClose(); -} - -void ScExportTest::testTdf125173XLSX() -{ - ScDocShellRef xDocSh = loadDoc(u"text_box_hyperlink.", FORMAT_ODS); - CPPUNIT_ASSERT(xDocSh.is()); - std::shared_ptr<utl::TempFile> pXPathFile = ScBootstrapFixture::exportTo(&(*xDocSh), FORMAT_XLSX); - - xmlDocUniquePtr pDoc = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/drawings/drawing1.xml"); - CPPUNIT_ASSERT(pDoc); - assertXPath(pDoc, "/xdr:wsDr/xdr:twoCellAnchor/xdr:sp/xdr:nvSpPr/xdr:cNvPr/a:hlinkClick", 1); - - xmlDocUniquePtr pXmlRels = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/drawings/_rels/drawing1.xml.rels"); - CPPUNIT_ASSERT(pXmlRels); - assertXPath(pXmlRels, "/r:Relationships/r:Relationship[@Id='rId1']", "Target", "http://www.google.com/"); - assertXPath(pXmlRels, "/r:Relationships/r:Relationship[@Id='rId1']", "TargetMode", "External"); - - xDocSh->DoClose(); -} - -void ScExportTest::testTdf79972XLSX() -{ - ScDocShellRef xDocSh = loadDoc(u"tdf79972.", FORMAT_XLSX); - CPPUNIT_ASSERT(xDocSh.is()); - std::shared_ptr<utl::TempFile> pXPathFile = ScBootstrapFixture::exportTo(&(*xDocSh), FORMAT_XLSX); - - xmlDocUniquePtr pDoc = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/worksheets/sheet1.xml"); - CPPUNIT_ASSERT(pDoc); - assertXPath(pDoc, "/x:worksheet/x:hyperlinks/x:hyperlink", "ref", "A1"); - - xmlDocUniquePtr pXmlRels = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/worksheets/_rels/sheet1.xml.rels"); - CPPUNIT_ASSERT(pXmlRels); - assertXPath(pXmlRels, "/r:Relationships/r:Relationship", "Target", "https://bugs.documentfoundation.org/show_bug.cgi?id=79972"); - assertXPath(pXmlRels, "/r:Relationships/r:Relationship", "TargetMode", "External"); - - xDocSh->DoClose(); -} - -void ScExportTest::testTdf126024XLSX() -{ - ScDocShellRef xDocSh = loadDoc(u"hyperlink_formula.", FORMAT_XLSX); - CPPUNIT_ASSERT(xDocSh.is()); - std::shared_ptr<utl::TempFile> pXPathFile = ScBootstrapFixture::exportTo(&(*xDocSh), FORMAT_XLSX); - - xmlDocUniquePtr pDoc = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/worksheets/sheet1.xml"); - CPPUNIT_ASSERT(pDoc); - assertXPath(pDoc, "/x:worksheet/x:hyperlinks/x:hyperlink", "ref", "A2"); - - xmlDocUniquePtr pXmlRels = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/worksheets/_rels/sheet1.xml.rels"); - CPPUNIT_ASSERT(pXmlRels); - assertXPath(pXmlRels, "/r:Relationships/r:Relationship", "Target", "https://bugs.documentfoundation.org/"); - assertXPath(pXmlRels, "/r:Relationships/r:Relationship", "TargetMode", "External"); - - xDocSh->DoClose(); -} - -void ScExportTest::testTdf126177XLSX() -{ - ScDocShellRef xDocSh = loadDoc(u"hyperlink_export.", FORMAT_XLSX); - CPPUNIT_ASSERT(xDocSh.is()); - std::shared_ptr<utl::TempFile> pXPathFile = ScBootstrapFixture::exportTo(&(*xDocSh), FORMAT_XLSX); - - xmlDocUniquePtr pDoc = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/worksheets/sheet1.xml"); - CPPUNIT_ASSERT(pDoc); - assertXPath(pDoc, "/x:worksheet/x:hyperlinks/x:hyperlink", "location", "Munka1!A5"); - - xmlDocUniquePtr pXmlRels = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/worksheets/_rels/sheet1.xml.rels"); - CPPUNIT_ASSERT(pXmlRels); - OUString aTarget = getXPath(pXmlRels, "/r:Relationships/r:Relationship", "Target"); - CPPUNIT_ASSERT(aTarget.endsWith("test.xlsx")); - assertXPath(pXmlRels, "/r:Relationships/r:Relationship", "TargetMode", "External"); - - xDocSh->DoClose(); -} - -void ScExportTest::testCommentTextVAlignment() -{ - // Testing comment text alignments. - ScDocShellRef xShell = loadDoc(u"CommentTextVAlign.", FORMAT_ODS); - CPPUNIT_ASSERT(xShell.is()); - - std::shared_ptr<utl::TempFile> pXPathFile - = ScBootstrapFixture::exportTo(&(*xShell), FORMAT_XLSX); - - xmlDocUniquePtr pVmlDrawing - = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/drawings/vmlDrawing1.vml"); - CPPUNIT_ASSERT(pVmlDrawing); - - assertXPathContent(pVmlDrawing, "/xml/v:shape/xx:ClientData/xx:TextVAlign", "Center"); - - xShell->DoClose(); -} - -void ScExportTest::testCommentTextHAlignment() -{ - // Testing comment text alignments. - ScDocShellRef xShell = loadDoc(u"CommentTextHAlign.", FORMAT_ODS); - CPPUNIT_ASSERT(xShell.is()); - - std::shared_ptr<utl::TempFile> pXPathFile - = ScBootstrapFixture::exportTo(&(*xShell), FORMAT_XLSX); - - xmlDocUniquePtr pVmlDrawing - = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/drawings/vmlDrawing1.vml"); - CPPUNIT_ASSERT(pVmlDrawing); - - assertXPathContent(pVmlDrawing, "/xml/v:shape/xx:ClientData/xx:TextHAlign", "Center"); - - xShell->DoClose(); -} - -void ScExportTest::testRotatedImageODS() -{ - // Error was, that the length values in shapes were not - // written in the given unit into the file. - css::uno::Reference<css::sheet::XGlobalSheetSettings> xGlobalSheetSettings - = css::sheet::GlobalSheetSettings::create(comphelper::getProcessComponentContext()); - xGlobalSheetSettings->setMetric(static_cast<sal_Int16>(FieldUnit::MM)); - - ScDocShellRef xDocSh = loadDoc(u"tdf103092_RotatedImage.", FORMAT_ODS, true); - CPPUNIT_ASSERT(xDocSh.is()); - - std::shared_ptr<utl::TempFile> pTemp = saveAs(xDocSh.get(), FORMAT_ODS); - CPPUNIT_ASSERT(pTemp); - xmlDocUniquePtr pXmlDoc = XPathHelper::parseExport(pTemp, m_xSFactory, "content.xml"); - CPPUNIT_ASSERT(pXmlDoc); - - const OUString sTransform = getXPath( - pXmlDoc, - "/office:document-content/office:body/office:spreadsheet/" - "table:table/table:shapes/draw:frame", - "transform"); - // Attribute transform has the structure skew (...) rotate (...) translate (x y) - // parts are separated by blank - OUString sTranslate(sTransform.copy(sTransform.lastIndexOf('('))); - sTranslate = sTranslate.copy(1, sTranslate.getLength()-2); // remove '(' and ')' - const OUString sX(sTranslate.getToken(0, ' ')); - const OUString sY(sTranslate.getToken(1, ' ')); - CPPUNIT_ASSERT(sX.endsWith("mm")); - CPPUNIT_ASSERT(sY.endsWith("mm")); - - xDocSh->DoClose(); -} - -void ScExportTest::testTdf128976() -{ - ScDocShellRef xShell = loadDoc(u"tdf128976.", FORMAT_XLS); - CPPUNIT_ASSERT(xShell.is()); - - ScDocShellRef xDocSh = saveAndReload(xShell.get(), FORMAT_XLS); - xShell->DoClose(); - CPPUNIT_ASSERT(xDocSh.is()); - - ScDocument& rDoc = xDocSh->GetDocument(); - - // Trying to save very small fractional default column width to XLS (where only integer values - // between 0 and 255 are allowed as default) resulted in negative (-1) value after correction, - // and was written as 65535 (invalid default width). As the result, all columns had large width - // when reopened: 28415 (and Excel warned about invalid format). - const sal_uInt16 nColumn0Width = rDoc.GetColWidth(SCCOL(0), SCTAB(0), false); - CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(45), nColumn0Width); - - xDocSh->DoClose(); -} - -void ScExportTest::testTdf120502() -{ - // Create an empty worksheet; resize last column on its first sheet; export to XLSX, and check - // that the last exported column number is correct - css::uno::Reference<css::frame::XDesktop2> xDesktop - = css::frame::Desktop::create(comphelper::getProcessComponentContext()); - CPPUNIT_ASSERT(xDesktop); - - css::uno::Sequence<css::beans::PropertyValue> args(1); - args[0].Name = "Hidden"; - args[0].Value <<= true; - - css::uno::Reference<css::lang::XComponent> xComponent - = xDesktop->loadComponentFromURL("private:factory/scalc", "_blank", 0, args); - CPPUNIT_ASSERT(xComponent); - - // Get the document model - SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(xComponent); - CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell); - - ScDocShellRef xShell = dynamic_cast<ScDocShell*>(pFoundShell); - CPPUNIT_ASSERT(xShell); - - ScDocument& rDoc = xShell->GetDocument(); - const SCCOL nMaxCol = rDoc.MaxCol(); // 0-based - - const auto nOldWidth = rDoc.GetColWidth(nMaxCol, 0); - rDoc.SetColWidth(nMaxCol, 0, nOldWidth + 100); - - std::shared_ptr<utl::TempFile> pXPathFile - = ScBootstrapFixture::exportTo(&(*xShell), FORMAT_XLSX); - xShell->DoClose(); - xmlDocUniquePtr pSheet1 - = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/worksheets/sheet1.xml"); - CPPUNIT_ASSERT(pSheet1); - - // This was 1025 when nMaxCol+1 was 1024 - assertXPath(pSheet1, "/x:worksheet/x:cols/x:col", "max", OUString::number(nMaxCol + 1)); -} - -void ScExportTest::testTdf131372() -{ - ScDocShellRef xShell = loadDoc(u"tdf131372.", FORMAT_ODS); - CPPUNIT_ASSERT(xShell); - - auto pXPathFile = ScBootstrapFixture::exportTo(&(*xShell), FORMAT_XLSX); - - xmlDocUniquePtr pSheet = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/worksheets/sheet1.xml"); - CPPUNIT_ASSERT(pSheet); - - assertXPathContent(pSheet, "/x:worksheet/x:sheetData/x:row/x:c[1]/x:f", "NA()"); - assertXPathContent(pSheet, "/x:worksheet/x:sheetData/x:row/x:c[2]/x:f", "#N/A"); - - xShell->DoClose(); - -} -void ScExportTest::testTdf81470() -{ - ScDocShellRef xShell = loadDoc(u"tdf81470.", FORMAT_XLS); - CPPUNIT_ASSERT(xShell); - - //without the fix in place, it would have crashed at export time - auto pXPathFile = ScBootstrapFixture::exportTo(&(*xShell), FORMAT_XLSX); - - //also check revisions are exported - xmlDocUniquePtr pHeaders = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/revisions/revisionHeaders.xml"); - CPPUNIT_ASSERT(pHeaders); - - assertXPath(pHeaders, "/x:headers/x:header[1]", "dateTime", "2014-07-11T13:46:00.000000000Z"); - assertXPath(pHeaders, "/x:headers/x:header[1]", "userName", "Kohei Yoshida"); - assertXPath(pHeaders, "/x:headers/x:header[2]", "dateTime", "2014-07-11T18:38:00.000000000Z"); - assertXPath(pHeaders, "/x:headers/x:header[2]", "userName", "Kohei Yoshida"); - assertXPath(pHeaders, "/x:headers/x:header[3]", "dateTime", "2014-07-11T18:43:00.000000000Z"); - assertXPath(pHeaders, "/x:headers/x:header[3]", "userName", "Kohei Yoshida"); - - xShell->DoClose(); -} - -void ScExportTest::testTdf122331() -{ - ScDocShellRef xShell = loadDoc(u"tdf122331.", FORMAT_ODS); - CPPUNIT_ASSERT(xShell); - - auto pXPathFile = ScBootstrapFixture::exportTo(&(*xShell), FORMAT_XLSX); - - xmlDocUniquePtr pSheet = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/worksheets/sheet1.xml"); - CPPUNIT_ASSERT(pSheet); - - assertXPath(pSheet, "/x:worksheet/x:sheetPr", "filterMode", "true"); - assertXPath(pSheet, "/x:worksheet/x:autoFilter", "ref", "A1:B761"); - assertXPath(pSheet, "/x:worksheet/x:autoFilter/x:filterColumn", "colId", "1"); - - xShell->DoClose(); -} - -void ScExportTest::testTdf83779() -{ - // Roundtripping TRUE/FALSE constants (not functions) must convert them to functions - ScDocShellRef xShell = loadDoc(u"tdf83779.", FORMAT_XLSX); - CPPUNIT_ASSERT(xShell); - - auto pXPathFile = ScBootstrapFixture::exportTo(&(*xShell), FORMAT_XLSX); - - xmlDocUniquePtr pVmlDrawing - = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/worksheets/sheet1.xml"); - CPPUNIT_ASSERT(pVmlDrawing); - - assertXPathContent(pVmlDrawing, "/x:worksheet/x:sheetData/x:row[1]/x:c/x:f", "FALSE()"); - assertXPathContent(pVmlDrawing, "/x:worksheet/x:sheetData/x:row[2]/x:c/x:f", "TRUE()"); - - xShell->DoClose(); -} - -void ScExportTest::testTdf121716_ExportEvenHeaderFooterXLSX() -{ - // Header and footer on even pages should be exported properly - // If there are separate odd/even header, but only 1 footer for all pages (this is possible only in LibreOffice) - // then the footer will be duplicated to have the same footer separately for even/odd pages - - ScDocShellRef xShell = loadDoc(u"tdf121716_EvenHeaderFooter.", FORMAT_ODS); - CPPUNIT_ASSERT(xShell.is()); - - ScDocShellRef xDocSh = saveAndReload(&(*xShell), FORMAT_XLSX); - CPPUNIT_ASSERT(xDocSh.is()); - - std::shared_ptr<utl::TempFile> pXPathFile = ScBootstrapFixture::exportTo(&(*xDocSh), FORMAT_XLSX); - xmlDocUniquePtr pDoc = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/worksheets/sheet1.xml"); - CPPUNIT_ASSERT(pDoc); - - assertXPath(pDoc, "/x:worksheet/x:headerFooter", "differentOddEven", "true"); - assertXPathContent(pDoc, "/x:worksheet/x:headerFooter/x:oddHeader", "&Lodd/right&Cpage&Rheader"); - assertXPathContent(pDoc, "/x:worksheet/x:headerFooter/x:oddFooter", "&Lboth&C&12page&Rfooter"); - assertXPathContent(pDoc, "/x:worksheet/x:headerFooter/x:evenHeader", "&Lpage&Cheader&Reven/left"); - assertXPathContent(pDoc, "/x:worksheet/x:headerFooter/x:evenFooter", "&Lboth&C&12page&Rfooter"); - - pDoc = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/worksheets/sheet2.xml"); - CPPUNIT_ASSERT(pDoc); - - assertXPath(pDoc, "/x:worksheet/x:headerFooter", "differentOddEven", "true"); - assertXPathContent(pDoc, "/x:worksheet/x:headerFooter/x:oddHeader", "&Coddh"); - assertXPathContent(pDoc, "/x:worksheet/x:headerFooter/x:oddFooter", "&Coddf"); - assertXPathContent(pDoc, "/x:worksheet/x:headerFooter/x:evenHeader", "&Cevenh"); - assertXPathContent(pDoc, "/x:worksheet/x:headerFooter/x:evenFooter", "&Levenf"); - - xDocSh->DoClose(); -} - -void ScExportTest::testTdf134459_HeaderFooterColorXLSX() -{ - // Colors in header and footer should be exported, and imported properly - ScDocShellRef xShell = loadDoc(u"tdf134459_HeaderFooterColor.", FORMAT_XLSX); - CPPUNIT_ASSERT(xShell.is()); - - ScDocShellRef xDocSh = saveAndReload(&(*xShell), FORMAT_XLSX); - CPPUNIT_ASSERT(xDocSh.is()); - - xmlDocUniquePtr pDoc = XPathHelper::parseExport2(*this, *xDocSh, m_xSFactory, "xl/worksheets/sheet1.xml", FORMAT_XLSX); - CPPUNIT_ASSERT(pDoc); - - assertXPathContent(pDoc, "/x:worksheet/x:headerFooter/x:oddHeader", "&L&Kc06040l&C&K4c3789c&Rr"); - assertXPathContent(pDoc, "/x:worksheet/x:headerFooter/x:oddFooter", "&Ll&C&K64cf5fc&R&Kcd15aar"); - - xDocSh->DoClose(); -} - -void ScExportTest::testTdf134817_HeaderFooterTextWith2SectionXLSX() -{ - // Header/footer text with multiple selection should be exported, and imported properly - ScDocShellRef xShell = loadDoc(u"tdf134817_HeaderFooterTextWith2Section.", FORMAT_XLSX); - CPPUNIT_ASSERT(xShell.is()); - - ScDocShellRef xDocSh = saveAndReload(&(*xShell), FORMAT_XLSX); - CPPUNIT_ASSERT(xDocSh.is()); - - xmlDocUniquePtr pDoc = XPathHelper::parseExport2(*this, *xDocSh, m_xSFactory, "xl/worksheets/sheet1.xml", FORMAT_XLSX); - CPPUNIT_ASSERT(pDoc); - - assertXPathContent(pDoc, "/x:worksheet/x:headerFooter/x:oddHeader", "&L&\"Abadi,Regular\"&11aaa&\"Bembo,Regular\"&20bbb"); - assertXPathContent(pDoc, "/x:worksheet/x:headerFooter/x:oddFooter", "&R&\"Cambria,Regular\"&14camb&\"Dante,Regular\"&18dant"); - - xDocSh->DoClose(); -} - -void ScExportTest::testTdf121718_UseFirstPageNumberXLSX() -{ - // If "First page number" is not checked then useFirstPageNumb, and firstPageNumber should not be exported. - ScDocShellRef xShell = loadDoc(u"tdf121718_UseFirstPageNumber.", FORMAT_ODS); - CPPUNIT_ASSERT(xShell.is()); - - ScDocShellRef xDocSh = saveAndReload(&(*xShell), FORMAT_XLSX); - CPPUNIT_ASSERT(xDocSh.is()); - - std::shared_ptr<utl::TempFile> pXPathFile = ScBootstrapFixture::exportTo(&(*xDocSh), FORMAT_XLSX); - xmlDocUniquePtr pDoc = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/worksheets/sheet1.xml"); - CPPUNIT_ASSERT(pDoc); - - assertXPath(pDoc, "/x:worksheet/x:pageSetup", "useFirstPageNumber", "true"); - assertXPath(pDoc, "/x:worksheet/x:pageSetup", "firstPageNumber", "10"); - - pDoc = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/worksheets/sheet2.xml"); - CPPUNIT_ASSERT(pDoc); - - assertXPathNoAttribute(pDoc, "/x:worksheet/x:pageSetup", "useFirstPageNumber"); - assertXPathNoAttribute(pDoc, "/x:worksheet/x:pageSetup", "firstPageNumber"); - - xDocSh->DoClose(); -} - -void ScExportTest::testHeaderFontStyleXLSX() -{ - ScDocShellRef xShell = loadDoc(u"tdf134826.", FORMAT_XLSX); - CPPUNIT_ASSERT(xShell.is()); - - ScDocument& rDoc = xShell->GetDocument(); - SfxStyleSheetBase* pStyleSheet = rDoc.GetStyleSheetPool()->Find(rDoc.GetPageStyle(0), SfxStyleFamily::Page); - const SfxItemSet& rItemSet = pStyleSheet->GetItemSet(); - const ScPageHFItem& rHFItem = rItemSet.Get(ATTR_PAGE_HEADERRIGHT); - const EditTextObject* pTextObj = rHFItem.GetLeftArea(); - - std::vector<EECharAttrib> rLst; - - // first line is bold. - pTextObj->GetCharAttribs(0, rLst); - bool bHasBold = std::any_of(rLst.begin(), rLst.end(), [](const EECharAttrib& rAttrib) { - return rAttrib.pAttr->Which() == EE_CHAR_WEIGHT && - static_cast<const SvxWeightItem&>(*rAttrib.pAttr).GetWeight() == WEIGHT_BOLD; }); - CPPUNIT_ASSERT_MESSAGE("First line should be bold.", bHasBold); - - // second line is italic. - pTextObj->GetCharAttribs(1, rLst); - bool bHasItalic = std::any_of(rLst.begin(), rLst.end(), [](const EECharAttrib& rAttrib) { - return rAttrib.pAttr->Which() == EE_CHAR_ITALIC && - static_cast<const SvxPostureItem&>(*rAttrib.pAttr).GetPosture() == ITALIC_NORMAL; }); - CPPUNIT_ASSERT_MESSAGE("Second line should be italic.", bHasItalic); - - xShell->DoClose(); -} - -void ScExportTest::testTdf135828_Shape_Rect() -{ - if (!IsDefaultDPI()) - return; - // tdf#135828 Check that the width and the height of rectangle of the shape is correct. - // tdf#123613 Check the positioning, and allow massive rounding errors because of the back and - // forth conversion between emu and hmm. - ScDocShellRef xShell = loadDoc(u"tdf135828_Shape_Rect.", FORMAT_XLSX); - CPPUNIT_ASSERT(xShell.is()); - - ScDocShellRef xDocSh = saveAndReload(&(*xShell), FORMAT_XLSX); - CPPUNIT_ASSERT(xDocSh.is()); - - std::shared_ptr<utl::TempFile> pXPathFile = ScBootstrapFixture::exportTo(&(*xDocSh), FORMAT_XLSX); - - xmlDocUniquePtr pDrawing = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/drawings/drawing1.xml"); - CPPUNIT_ASSERT(pDrawing); - - double nXPosOfTopleft = getXPath(pDrawing, "/xdr:wsDr/xdr:twoCellAnchor/xdr:sp/xdr:spPr/a:xfrm/a:off", "x" ).toDouble(); - double nYPosOfTopleft = getXPath(pDrawing, "/xdr:wsDr/xdr:twoCellAnchor/xdr:sp/xdr:spPr/a:xfrm/a:off", "y" ).toDouble(); - double nWidth = getXPath(pDrawing, "/xdr:wsDr/xdr:twoCellAnchor/xdr:sp/xdr:spPr/a:xfrm/a:ext", "cx").toDouble(); - double nHeight = getXPath(pDrawing, "/xdr:wsDr/xdr:twoCellAnchor/xdr:sp/xdr:spPr/a:xfrm/a:ext", "cy").toDouble(); - - CPPUNIT_ASSERT_DOUBLES_EQUAL( 854640, nXPosOfTopleft, 10000); - CPPUNIT_ASSERT_DOUBLES_EQUAL( -570600, nYPosOfTopleft, 10000); - CPPUNIT_ASSERT_DOUBLES_EQUAL( 294840, nWidth, 10000); - CPPUNIT_ASSERT_DOUBLES_EQUAL( 1988280, nHeight, 10000); -} - -void ScExportTest::testTdf123353() -{ - ScDocShellRef xShell = loadDoc(u"tdf123353.", FORMAT_XLSX); - CPPUNIT_ASSERT(xShell.is()); - - ScDocShellRef xDocSh = saveAndReload(&(*xShell), FORMAT_XLSX); - CPPUNIT_ASSERT(xDocSh.is()); - - std::shared_ptr<utl::TempFile> pXPathFile = ScBootstrapFixture::exportTo(&(*xDocSh), FORMAT_XLSX); - - xmlDocUniquePtr pDoc = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/worksheets/sheet1.xml"); - CPPUNIT_ASSERT(pDoc); - - assertXPath(pDoc, "/x:worksheet/x:autoFilter/x:filterColumn/x:filters", "blank", "1"); - - xShell->DoClose(); -} - -void ScExportTest::testTdf140098() -{ - ScDocShellRef xShell = loadDoc(u"tdf140098.", FORMAT_ODS); - CPPUNIT_ASSERT(xShell.is()); - - ScDocShellRef xDocSh = saveAndReload(&(*xShell), FORMAT_XLSX); - CPPUNIT_ASSERT(xDocSh.is()); - - std::shared_ptr<utl::TempFile> pXPathFile = ScBootstrapFixture::exportTo(&(*xDocSh), FORMAT_XLSX); - - xmlDocUniquePtr pDoc = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/worksheets/sheet1.xml"); - CPPUNIT_ASSERT(pDoc); - - assertXPath(pDoc, "/x:worksheet/x:autoFilter/x:filterColumn/x:filters", "blank", "1"); - - xShell->DoClose(); -} - -void ScExportTest::testTdf133688_precedents() -{ - // tdf#133688 Check that we do not export detective shapes. - ScDocShellRef xShell = loadDoc(u"tdf133688_dont_save_precedents_to_xlsx.", FORMAT_ODS); - CPPUNIT_ASSERT(xShell.is()); - - std::shared_ptr<utl::TempFile> pXPathFile - = ScBootstrapFixture::exportTo(&(*xShell), FORMAT_XLSX); - xmlDocUniquePtr pDrawing - = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/drawings/drawing1.xml"); - CPPUNIT_ASSERT(pDrawing); - - // We do not export any shapes. - assertXPath(pDrawing, "/xdr:wsDr/xdr:twoCellAnchor[1]", 0); -} - -void ScExportTest::testTdf91251_missingOverflowRoundtrip() -{ - // tdf#91251 check whether textBox overflow property (horzOverflow and vertOverflow) is - // getting preserved after roundtrip - ScDocShellRef xShell = loadDoc(u"tdf91251_missingOverflowRoundtrip.", FORMAT_XLSX); - CPPUNIT_ASSERT(xShell.is()); - - ScDocShellRef xDocSh = saveAndReload(&(*xShell), FORMAT_XLSX); - CPPUNIT_ASSERT(xDocSh.is()); - - std::shared_ptr<utl::TempFile> pXPathFile = ScBootstrapFixture::exportTo(&(*xDocSh), FORMAT_XLSX); - - xmlDocUniquePtr pDrawing = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/drawings/drawing1.xml"); - CPPUNIT_ASSERT(pDrawing); - - assertXPath(pDrawing, "/xdr:wsDr/xdr:twoCellAnchor/xdr:sp/xdr:txBody/a:bodyPr", "horzOverflow", "clip"); - assertXPath(pDrawing, "/xdr:wsDr/xdr:twoCellAnchor/xdr:sp/xdr:txBody/a:bodyPr", "horzOverflow", "clip"); -} - -void ScExportTest::testTdf137000_handle_upright() -{ - // tdf#106197 When exporting the "upright" attribute, we must set - // TextPreRotateAngle to 0. - // (Upright is an xml attribute of xdr:txBody/a:bodyPr. It is set when - // in a textbox menu we choose: do not rotate this element.) - ScDocShellRef xShell = loadDoc(u"tdf137000_export_upright.", FORMAT_XLSX); - CPPUNIT_ASSERT(xShell.is()); - - std::shared_ptr<utl::TempFile> pXPathFile - = ScBootstrapFixture::exportTo(&(*xShell), FORMAT_XLSX); - xmlDocUniquePtr pDrawing - = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/drawings/drawing1.xml"); - CPPUNIT_ASSERT(pDrawing); - - assertXPath(pDrawing, "/xdr:wsDr/xdr:twoCellAnchor/xdr:sp/xdr:txBody/a:bodyPr", - "rot", "-5400000"); -} - -void ScExportTest::testTdf126305_DataValidatyErrorAlert() -{ - ScDocShellRef xShell = loadDoc(u"tdf126305.", FORMAT_ODS); - CPPUNIT_ASSERT(xShell.is()); - - ScDocShellRef xDocSh = saveAndReload(&(*xShell), FORMAT_XLSX); - CPPUNIT_ASSERT(xDocSh.is()); - - std::shared_ptr<utl::TempFile> pXPathFile = ScBootstrapFixture::exportTo(&(*xDocSh), FORMAT_XLSX); - xmlDocUniquePtr pDoc = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/worksheets/sheet1.xml"); - CPPUNIT_ASSERT(pDoc); - - assertXPath(pDoc, "/x:worksheet/x:dataValidations/x:dataValidation[1]", "errorStyle", "stop"); - assertXPath(pDoc, "/x:worksheet/x:dataValidations/x:dataValidation[2]", "errorStyle", "warning"); - assertXPath(pDoc, "/x:worksheet/x:dataValidations/x:dataValidation[3]", "errorStyle", "information"); - - xDocSh->DoClose(); -} - -void ScExportTest::testTdf76047_externalLink() -{ - ScDocShellRef pShell = loadDoc(u"tdf76047_externalLink.", FORMAT_XLSX); - CPPUNIT_ASSERT(pShell.is()); - - // load data from external links. (tdf76047_externalLinkSource.ods) - // that file has to be in the same directory as tdf76047_externalLink.xlsx - pShell->ReloadAllLinks(); - ScDocument& rDoc = pShell->GetDocument(); - - // compare the data loaded from external links with the expected result stored in the test file - for (int nCol = 1; nCol <= 5; nCol++) - { - for (int nRow = 3; nRow <= 5; nRow++) - { - OUString aStr1 = rDoc.GetString(ScAddress(nCol, nRow, 0)); - OUString aStr2 = rDoc.GetString(ScAddress(nCol, nRow + 5, 0)); - OUString aStr3 = rDoc.GetString(ScAddress(nCol, nRow + 11, 0)); - - CPPUNIT_ASSERT_EQUAL(aStr1, aStr3); - CPPUNIT_ASSERT_EQUAL(aStr2, aStr3); - } - } -} - -void ScExportTest::testTdf87973_externalLinkSkipUnuseds() -{ - ScDocShellRef pShell = loadDoc(u"tdf87973_externalLinkSkipUnuseds.", FORMAT_ODS); - CPPUNIT_ASSERT(pShell.is()); - - // try to load data from external link: tdf132105_external.ods - // that file has to be in the same directory as tdf87973_externalLinkSkipUnuseds.ods - pShell->ReloadAllLinks(); - ScDocument& rDoc = pShell->GetDocument(); - - // change external link to: 87973_externalSource.ods - OUString aFormula, aFormula2; - rDoc.GetFormula(3, 1, 0, aFormula); - auto nIdxOfFilename = aFormula.indexOf("tdf132105_external.ods"); - aFormula = aFormula.replaceAt(nIdxOfFilename, 22, "87973_externalSource.ods"); - auto nIdxOfFile = aFormula.indexOf("file"); - - // saveAndReload save the file to a temporary directory - // the link must be changed to point to that directory - utl::TempFile aTempFile; - auto aTempFilename = aTempFile.GetURL(); - auto nIdxOfTmpFile = aTempFilename.lastIndexOf('/'); - aTempFilename = aTempFilename.copy(0, nIdxOfTmpFile + 1); - - aFormula = aFormula.replaceAt(nIdxOfFile, nIdxOfFilename - nIdxOfFile, aTempFilename); - rDoc.SetFormula(ScAddress(3, 1, 0), aFormula, formula::FormulaGrammar::GRAM_NATIVE_UI); - - // tdf#138832: test the same thing with singleref link - rDoc.GetFormula(3, 2, 0, aFormula); - nIdxOfFilename = aFormula.indexOf("tdf132105_external.ods"); - aFormula = aFormula.replaceAt(nIdxOfFilename, 22, "87973_externalSource.ods"); - nIdxOfFile = aFormula.indexOf("file"); - - aFormula = aFormula.replaceAt(nIdxOfFile, nIdxOfFilename - nIdxOfFile, aTempFilename); - rDoc.SetFormula(ScAddress(3, 2, 0), aFormula, formula::FormulaGrammar::GRAM_NATIVE_UI); - - // save and load back - ScDocShellRef pDocSh = saveAndReload(&(*pShell), FORMAT_XLSX); - CPPUNIT_ASSERT(pDocSh.is()); - - // check if the new filename is present in the link (and not replaced by '[2]') - ScDocument& rDoc2 = pDocSh->GetDocument(); - rDoc2.GetFormula(3, 1, 0, aFormula2); - CPPUNIT_ASSERT(aFormula2.indexOf("tdf132105_external.ods") < 0); - CPPUNIT_ASSERT(aFormula2.indexOf("87973_externalSource.ods") >= 0); - rDoc2.GetFormula(3, 2, 0, aFormula2); - CPPUNIT_ASSERT(aFormula2.indexOf("tdf132105_external.ods") < 0); - CPPUNIT_ASSERT(aFormula2.indexOf("87973_externalSource.ods") >= 0); - - pDocSh->DoClose(); -} - -void ScExportTest::testTdf51022_lostPrintRange() -{ - ScDocShellRef pShell = loadDoc(u"tdf87973_externalLinkSkipUnuseds.", FORMAT_ODS); - CPPUNIT_ASSERT(pShell.is()); - - pShell->ReloadAllLinks(); - ScDocument& rDoc = pShell->GetDocument(); - - //Add print ranges - ScRange aRange1(1, 2, 0, 3, 4, 0); - ScRange aRange2(1, 6, 0, 3, 7, 0); - rDoc.AddPrintRange(0, aRange1); - rDoc.AddPrintRange(0, aRange2); - - // save and load back - ScDocShellRef pDocSh = saveAndReload(&(*pShell), FORMAT_ODS); - CPPUNIT_ASSERT(pDocSh.is()); - - // check if the same print ranges are present - ScDocument& rDoc2 = pDocSh->GetDocument(); - CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(2), rDoc2.GetPrintRangeCount(0)); - CPPUNIT_ASSERT_EQUAL(aRange1, *rDoc2.GetPrintRange(0, 0)); - CPPUNIT_ASSERT_EQUAL(aRange2, *rDoc2.GetPrintRange(0, 1)); - - pDocSh->DoClose(); -} - -void ScExportTest::testTdf138741_externalLinkSkipUnusedsCrash() -{ - ScDocShellRef xShell = loadDoc(u"tdf138741_externalLinkSkipUnusedsCrash.", FORMAT_XLSX); - CPPUNIT_ASSERT(xShell); - - //without the fix in place, it would have crashed at export time - ScBootstrapFixture::exportTo(&(*xShell), FORMAT_XLSX); - - xShell->DoClose(); -} - -void ScExportTest::testTdf138824_linkToParentDirectory() -{ - ScDocShellRef xShell = loadDoc(u"childDir/tdf138824_linkToParentDirectory.", FORMAT_ODS); - CPPUNIT_ASSERT(xShell.is()); - - ScDocument& rDoc = xShell->GetDocument(); - - // saveAndReload save the file to a temporary directory - // the link must be changed to point to that parent directory - utl::TempFile aTempFile; - auto aTempFilename = aTempFile.GetURL(); - auto nIdxOfTmpFile = aTempFilename.lastIndexOf('/'); - nIdxOfTmpFile = aTempFilename.lastIndexOf('/', nIdxOfTmpFile); - aTempFilename = aTempFilename.copy(0, nIdxOfTmpFile + 1); - - // change external link to tmp directory - OUString aFormula; - rDoc.GetFormula(3, 1, 0, aFormula); - auto nIdxOfFilename = aFormula.indexOf("tdf138824_externalSource.ods"); - auto nIdxOfFile = aFormula.indexOf("file"); - - aFormula = aFormula.replaceAt(nIdxOfFile, nIdxOfFilename - nIdxOfFile, aTempFilename); - rDoc.SetFormula(ScAddress(3, 1, 0), aFormula, formula::FormulaGrammar::GRAM_NATIVE_UI); - - ScDocShellRef xDocSh = saveAndReload(&(*xShell), FORMAT_XLSX); - CPPUNIT_ASSERT(xDocSh.is()); - - std::shared_ptr<utl::TempFile> pXPathFile - = ScBootstrapFixture::exportTo(&(*xDocSh), FORMAT_XLSX); - xmlDocUniquePtr pDoc = XPathHelper::parseExport( - pXPathFile, m_xSFactory, "xl/externalLinks/_rels/externalLink1.xml.rels"); - CPPUNIT_ASSERT(pDoc); - - // test also the Linux specific bug tdf#121472 - assertXPath(pDoc, "/r:Relationships/r:Relationship", "Target", - "../tdf138824_externalSource.ods"); - - xDocSh->DoClose(); -} - -void ScExportTest::testTdf129969() -{ - ScDocShellRef xShell = loadDoc(u"external_hyperlink.", FORMAT_ODS); - CPPUNIT_ASSERT(xShell.is()); - - ScDocShellRef xDocSh = saveAndReload(&(*xShell), FORMAT_XLSX); - CPPUNIT_ASSERT(xDocSh.is()); - ScDocument& rDoc = xDocSh->GetDocument(); - ScAddress aPos(0, 0, 0); - const EditTextObject* pEditText = rDoc.GetEditText(aPos); - const SvxFieldData* pData = pEditText->GetFieldData(0, 0, text::textfield::Type::URL); - const SvxURLField* pURLData = static_cast<const SvxURLField*>(pData); - CPPUNIT_ASSERT(pURLData->GetURL().endsWith("/%23folder/test.ods#Sheet2.B10")); - - xDocSh->DoClose(); -} - -void ScExportTest::testTdf84874() -{ - ScDocShellRef xShell = loadDoc(u"tdf84874.", FORMAT_ODS); - CPPUNIT_ASSERT(xShell.is()); - - ScDocShellRef xDocSh = saveAndReload(xShell.get(), FORMAT_XLSX); - xShell->DoClose(); - CPPUNIT_ASSERT(xDocSh.is()); - - ScDocument& rDoc = xDocSh->GetDocument(); - - const ScValidationData* pData = rDoc.GetValidationEntry(1); - OUString aTitle, aText; - pData->GetInput(aTitle, aText); - sal_uInt32 nPromptTitleLen = aTitle.getLength(); - sal_uInt32 nPromptTextLen = aText.getLength(); - - CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt32>(255), nPromptTitleLen); - CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt32>(255), nPromptTextLen); - - ScValidErrorStyle eErrStyle = SC_VALERR_STOP; - pData->GetErrMsg(aTitle, aText, eErrStyle); - sal_uInt32 nErrorTitleLen = aTitle.getLength(); - sal_uInt32 nErrorTextLen = aText.getLength(); - - CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt32>(255), nErrorTitleLen); - CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt32>(255), nErrorTextLen); - - xDocSh->DoClose(); -} - -void ScExportTest::testTdf136721_paper_size() -{ - ScDocShellRef xShell = loadDoc(u"tdf136721_letter_sized_paper.", FORMAT_XLSX); - CPPUNIT_ASSERT(xShell.is()); - - std::shared_ptr<utl::TempFile> pXPathFile = ScBootstrapFixture::exportTo(&(*xShell), FORMAT_XLSX); - xmlDocUniquePtr pDoc = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/worksheets/sheet1.xml"); - CPPUNIT_ASSERT(pDoc); - - assertXPath(pDoc, "/x:worksheet/x:pageSetup", "paperSize", "70"); -} - -void ScExportTest::testTdf139258_rotated_image() -{ - // Check that the topleft position of the image is correct. - ScDocShellRef xShell = loadDoc(u"tdf139258_rotated_image.", FORMAT_ODS); - CPPUNIT_ASSERT(xShell.is()); - - std::shared_ptr<utl::TempFile> pXPathFile - = ScBootstrapFixture::exportTo(&(*xShell), FORMAT_XLSX); - - xmlDocUniquePtr pDrawing - = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/drawings/drawing1.xml"); - CPPUNIT_ASSERT(pDrawing); - - assertXPathContent(pDrawing, "/xdr:wsDr/xdr:twoCellAnchor/xdr:from/xdr:col", "1"); - assertXPathContent(pDrawing, "/xdr:wsDr/xdr:twoCellAnchor/xdr:from/xdr:row", "12"); - assertXPathContent(pDrawing, "/xdr:wsDr/xdr:twoCellAnchor/xdr:to/xdr:col", "6"); - assertXPathContent(pDrawing, "/xdr:wsDr/xdr:twoCellAnchor/xdr:to/xdr:row", "25"); -} - -ScDocShellRef ScExportTest::loadDocAndSetupModelViewController(std::u16string_view rFileName, sal_Int32 nFormat, bool bReadWrite) -{ - uno::Reference< frame::XDesktop2 > xDesktop = frame::Desktop::create(::comphelper::getProcessComponentContext()); - CPPUNIT_ASSERT(xDesktop.is()); - - // create a frame - Reference< frame::XFrame > xTargetFrame = xDesktop->findFrame("_blank", 0); - CPPUNIT_ASSERT(xTargetFrame.is()); - - // 1. Open the document - ScDocShellRef xDocSh = loadDoc(rFileName, nFormat, bReadWrite); - CPPUNIT_ASSERT_MESSAGE(OString("Failed to load " + OUStringToOString(rFileName, RTL_TEXTENCODING_UTF8)).getStr(), xDocSh.is()); - - uno::Reference< frame::XModel2 > xModel2 = xDocSh->GetModel(); - CPPUNIT_ASSERT(xModel2.is()); - - Reference< frame::XController2 > xController = xModel2->createDefaultViewController(xTargetFrame); - CPPUNIT_ASSERT(xController.is()); - - // introduce model/view/controller to each other - xController->attachModel(xModel2); - xModel2->connectController(xController); - xTargetFrame->setComponent(xController->getComponentWindow(), xController); - xController->attachFrame(xTargetFrame); - xModel2->setCurrentController(xController); - - return xDocSh; -} - -void ScExportTest::testTdf126541_SheetVisibilityImportXlsx() -{ - // Import an ods file with 'Hide' global grid visibility setting. - ScDocShellRef xShell = loadDocAndSetupModelViewController(u"tdf126541_GridOffGlobally.", FORMAT_ODS, true); - CPPUNIT_ASSERT(!xShell->GetDocument().GetViewOptions().GetOption(VOPT_GRID)); - - // Importing xlsx file should set the global grid visibility setting to 'Show' - // Sheet based grid line visibility setting should not overwrite the global setting. - xShell = loadDocAndSetupModelViewController(u"tdf126541_GridOff.", FORMAT_XLSX, true); - CPPUNIT_ASSERT(xShell->GetDocument().GetViewOptions().GetOption(VOPT_GRID)); -} - void ScExportTest::testTdf113646() { ScDocShellRef xShell = loadDoc(u"tdf113646.", FORMAT_ODS); diff --git a/sc/qa/unit/subsequent_export-test2.cxx b/sc/qa/unit/subsequent_export-test2.cxx new file mode 100644 index 000000000000..5bfcaf0778fe --- /dev/null +++ b/sc/qa/unit/subsequent_export-test2.cxx @@ -0,0 +1,2301 @@ + +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include <sal/config.h> + +#include <string_view> + +#include <officecfg/Office/Common.hxx> +#include <config_features.h> + +#include <sfx2/sfxmodelfactory.hxx> + +#include "helper/debughelper.hxx" +#include "helper/qahelper.hxx" +#include "helper/xpath.hxx" +#include "helper/shared_test_impl.hxx" + +#include <userdat.hxx> +#include <docsh.hxx> +#include <patattr.hxx> +#include <docpool.hxx> +#include <scitems.hxx> +#include <attrib.hxx> +#include <stlpool.hxx> +#include <document.hxx> +#include <formulacell.hxx> +#include <tokenarray.hxx> +#include <editutil.hxx> +#include <scopetools.hxx> +#include <cellvalue.hxx> +#include <postit.hxx> +#include <tokenstringcontext.hxx> +#include <chgtrack.hxx> +#include <validat.hxx> +#include <global.hxx> +#include <scmod.hxx> +#include <dpcache.hxx> +#include <dpobject.hxx> +#include <clipparam.hxx> +#include <viewopti.hxx> + +#include <svx/svdpage.hxx> +#include <svx/svdograf.hxx> +#include <tabprotection.hxx> +#include <editeng/wghtitem.hxx> +#include <editeng/postitem.hxx> +#include <editeng/editdata.hxx> +#include <editeng/eeitem.hxx> +#include <editeng/editobj.hxx> +#include <editeng/section.hxx> +#include <editeng/crossedoutitem.hxx> +#include <editeng/borderline.hxx> +#include <editeng/escapementitem.hxx> +#include <editeng/fontitem.hxx> +#include <editeng/fhgtitem.hxx> +#include <editeng/udlnitem.hxx> +#include <editeng/flditem.hxx> +#include <editeng/colritem.hxx> +#include <formula/grammar.hxx> +#include <unotools/useroptions.hxx> +#include <comphelper/scopeguard.hxx> +#include <unotools/syslocaleoptions.hxx> +#include <tools/datetime.hxx> +#include <tools/fldunit.hxx> +#include <svl/zformat.hxx> + +#include <test/xmltesttools.hxx> +#include <com/sun/star/drawing/XDrawPageSupplier.hpp> +#include <com/sun/star/awt/XBitmap.hpp> +#include <com/sun/star/frame/Desktop.hpp> +#include <com/sun/star/graphic/GraphicType.hpp> +#include <com/sun/star/sheet/GlobalSheetSettings.hpp> + +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; + +class ScExportTest2 : public ScBootstrapFixture, public XmlTestTools +{ +protected: + virtual void registerNamespaces(xmlXPathContextPtr& pXmlXPathCtx) override; + +public: + ScExportTest2(); + + virtual void setUp() override; + virtual void tearDown() override; + + void testMatrixMultiplicationXLSX(); + void testTextDirectionXLSX(); + void testTdf120168(); + void testTdf66668(); + void testTdf130108(); + void testTdf76949(); + void testTdf107586(); + void testTdf55417(); + void testTdf129985(); + void testTdf73063(); + + xmlDocUniquePtr testTdf95640(std::u16string_view rFileName, sal_Int32 nSourceFormat, + sal_Int32 nDestFormat); + void testTdf95640_ods_to_xlsx(); + void testTdf95640_ods_to_xlsx_with_standard_list(); + void testTdf95640_xlsx_to_xlsx(); + void testDateAutofilterXLSX(); + void testDateAutofilterODS(); + void testAutofilterColorsODF(); + void testAutofilterColorsOOXML(); + void testAutofilterColorsStyleOOXML(); + + void testRefStringXLSX(); + void testRefStringConfigXLSX(); + void testRefStringUnspecified(); + void testHeaderImageODS(); + + void testTdf88657ODS(); + void testTdf41722(); + void testTdf113621(); + void testEscapeCharInNumberFormatXLSX(); + void testNatNumInNumberFormatXLSX(); + void testExponentWithoutSignFormatXLSX(); + void testExtendedLCIDXLSX(); + + void testHiddenRepeatedRowsODS(); + void testHyperlinkTargetFrameODS(); + void testOpenDocumentAsReadOnly(); + void testKeepSettingsOfBlankRows(); + + void testTdf133595(); + void testTdf134769(); + void testTdf106181(); + void testTdf105272(); + void testTdf118990(); + void testTdf121612(); + void testTdf112936(); + void testPivotCacheAfterExportXLSX(); + void testTdf114969XLSX(); + void testTdf115192XLSX(); + void testTdf91634XLSX(); + void testTdf115159(); + void testTdf112567(); + void testTdf112567b(); + void testTdf123645XLSX(); + void testTdf125173XLSX(); + void testTdf79972XLSX(); + void testTdf126024XLSX(); + void testTdf126177XLSX(); + void testCommentTextVAlignment(); + void testCommentTextHAlignment(); + void testValidationCopyPaste(); + + void testXltxExport(); + void testRotatedImageODS(); + void testTdf128976(); + void testTdf120502(); + void testTdf131372(); + void testTdf81470(); + void testTdf122331(); + void testTdf83779(); + void testTdf121716_ExportEvenHeaderFooterXLSX(); + void testTdf134459_HeaderFooterColorXLSX(); + void testTdf134817_HeaderFooterTextWith2SectionXLSX(); + void testTdf121718_UseFirstPageNumberXLSX(); + void testHeaderFontStyleXLSX(); + void testTdf135828_Shape_Rect(); + void testTdf123353(); + void testTdf140098(); + void testTdf133688_precedents(); + void testTdf91251_missingOverflowRoundtrip(); + void testTdf137000_handle_upright(); + void testTdf126305_DataValidatyErrorAlert(); + void testTdf76047_externalLink(); + void testTdf87973_externalLinkSkipUnuseds(); + void testTdf51022_lostPrintRange(); + void testTdf138741_externalLinkSkipUnusedsCrash(); + void testTdf138824_linkToParentDirectory(); + void testTdf129969(); + void testTdf84874(); + void testTdf136721_paper_size(); + void testTdf139258_rotated_image(); + void testTdf126541_SheetVisibilityImportXlsx(); + + CPPUNIT_TEST_SUITE(ScExportTest2); + + CPPUNIT_TEST(testMatrixMultiplicationXLSX); + CPPUNIT_TEST(testTextDirectionXLSX); + CPPUNIT_TEST(testTdf120168); + CPPUNIT_TEST(testTdf66668); + CPPUNIT_TEST(testTdf130108); + CPPUNIT_TEST(testTdf76949); + CPPUNIT_TEST(testTdf107586); + CPPUNIT_TEST(testTdf55417); + CPPUNIT_TEST(testTdf129985); + CPPUNIT_TEST(testTdf73063); + CPPUNIT_TEST(testTdf95640_ods_to_xlsx); + CPPUNIT_TEST(testTdf95640_ods_to_xlsx_with_standard_list); + CPPUNIT_TEST(testTdf95640_xlsx_to_xlsx); + CPPUNIT_TEST(testDateAutofilterXLSX); + CPPUNIT_TEST(testDateAutofilterODS); + CPPUNIT_TEST(testAutofilterColorsODF); + CPPUNIT_TEST(testAutofilterColorsOOXML); + CPPUNIT_TEST(testAutofilterColorsStyleOOXML); + + CPPUNIT_TEST(testRefStringXLSX); + CPPUNIT_TEST(testRefStringConfigXLSX); + CPPUNIT_TEST(testRefStringUnspecified); + CPPUNIT_TEST(testHeaderImageODS); + + CPPUNIT_TEST(testTdf88657ODS); + CPPUNIT_TEST(testTdf41722); + CPPUNIT_TEST(testTdf113621); + CPPUNIT_TEST(testEscapeCharInNumberFormatXLSX); + CPPUNIT_TEST(testNatNumInNumberFormatXLSX); + CPPUNIT_TEST(testExponentWithoutSignFormatXLSX); + CPPUNIT_TEST(testExtendedLCIDXLSX); + + CPPUNIT_TEST(testHiddenRepeatedRowsODS); + CPPUNIT_TEST(testHyperlinkTargetFrameODS); + CPPUNIT_TEST(testOpenDocumentAsReadOnly); + CPPUNIT_TEST(testKeepSettingsOfBlankRows); + + CPPUNIT_TEST(testTdf133595); + CPPUNIT_TEST(testTdf134769); + CPPUNIT_TEST(testTdf106181); + CPPUNIT_TEST(testTdf105272); + CPPUNIT_TEST(testTdf118990); + CPPUNIT_TEST(testTdf121612); + CPPUNIT_TEST(testTdf112936); + CPPUNIT_TEST(testPivotCacheAfterExportXLSX); + CPPUNIT_TEST(testTdf114969XLSX); + CPPUNIT_TEST(testTdf115192XLSX); + CPPUNIT_TEST(testTdf91634XLSX); + CPPUNIT_TEST(testTdf115159); + CPPUNIT_TEST(testTdf112567); + CPPUNIT_TEST(testTdf112567b); + CPPUNIT_TEST(testTdf123645XLSX); + CPPUNIT_TEST(testTdf125173XLSX); + CPPUNIT_TEST(testTdf79972XLSX); + CPPUNIT_TEST(testTdf126024XLSX); + CPPUNIT_TEST(testTdf126177XLSX); + CPPUNIT_TEST(testCommentTextVAlignment); + CPPUNIT_TEST(testCommentTextHAlignment); + CPPUNIT_TEST(testValidationCopyPaste); + + CPPUNIT_TEST(testXltxExport); + CPPUNIT_TEST(testRotatedImageODS); + CPPUNIT_TEST(testTdf128976); + CPPUNIT_TEST(testTdf120502); + CPPUNIT_TEST(testTdf131372); + CPPUNIT_TEST(testTdf81470); + CPPUNIT_TEST(testTdf122331); + CPPUNIT_TEST(testTdf83779); + CPPUNIT_TEST(testTdf121716_ExportEvenHeaderFooterXLSX); + CPPUNIT_TEST(testTdf134459_HeaderFooterColorXLSX); + CPPUNIT_TEST(testTdf134817_HeaderFooterTextWith2SectionXLSX); + CPPUNIT_TEST(testTdf121718_UseFirstPageNumberXLSX); + CPPUNIT_TEST(testHeaderFontStyleXLSX); + CPPUNIT_TEST(testTdf135828_Shape_Rect); + CPPUNIT_TEST(testTdf123353); + CPPUNIT_TEST(testTdf140098); + CPPUNIT_TEST(testTdf133688_precedents); + CPPUNIT_TEST(testTdf91251_missingOverflowRoundtrip); + CPPUNIT_TEST(testTdf137000_handle_upright); + CPPUNIT_TEST(testTdf126305_DataValidatyErrorAlert); + CPPUNIT_TEST(testTdf76047_externalLink); + CPPUNIT_TEST(testTdf87973_externalLinkSkipUnuseds); + CPPUNIT_TEST(testTdf51022_lostPrintRange); + CPPUNIT_TEST(testTdf138741_externalLinkSkipUnusedsCrash); + CPPUNIT_TEST(testTdf138824_linkToParentDirectory); + CPPUNIT_TEST(testTdf129969); + CPPUNIT_TEST(testTdf84874); + CPPUNIT_TEST(testTdf136721_paper_size); + CPPUNIT_TEST(testTdf139258_rotated_image); + CPPUNIT_TEST(testTdf126541_SheetVisibilityImportXlsx); + + CPPUNIT_TEST_SUITE_END(); + +private: + ScDocShellRef loadDocAndSetupModelViewController(std::u16string_view rFileName, + sal_Int32 nFormat, bool bReadWrite); + uno::Reference<uno::XInterface> m_xCalcComponent; +}; + +ScExportTest2::ScExportTest2() + : ScBootstrapFixture("sc/qa/unit/data") +{ +} + +void ScExportTest2::setUp() +{ + test::BootstrapFixture::setUp(); + + // This is a bit of a fudge, we do this to ensure that ScGlobals::ensure, + // which is a private symbol to us, gets called + m_xCalcComponent + = getMultiServiceFactory()->createInstance("com.sun.star.comp.Calc.SpreadsheetDocument"); + CPPUNIT_ASSERT_MESSAGE("no calc component!", m_xCalcComponent.is()); +} + +void ScExportTest2::tearDown() +{ + uno::Reference<lang::XComponent>(m_xCalcComponent, UNO_QUERY_THROW)->dispose(); + test::BootstrapFixture::tearDown(); +} + +void ScExportTest2::registerNamespaces(xmlXPathContextPtr& pXmlXPathCtx) +{ + static const struct + { + xmlChar* pPrefix; + xmlChar* pURI; + } aNamespaces[] = { + { BAD_CAST("w"), BAD_CAST("http://schemas.openxmlformats.org/wordprocessingml/2006/main") }, + { BAD_CAST("x"), BAD_CAST("http://schemas.openxmlformats.org/spreadsheetml/2006/main") }, + { BAD_CAST("v"), BAD_CAST("urn:schemas-microsoft-com:vml") }, + { BAD_CAST("c"), BAD_CAST("http://schemas.openxmlformats.org/drawingml/2006/chart") }, + { BAD_CAST("a"), BAD_CAST("http://schemas.openxmlformats.org/drawingml/2006/main") }, + { BAD_CAST("mc"), BAD_CAST("http://schemas.openxmlformats.org/markup-compatibility/2006") }, + { BAD_CAST("wps"), + BAD_CAST("http://schemas.microsoft.com/office/word/2010/wordprocessingShape") }, + { BAD_CAST("wpg"), + BAD_CAST("http://schemas.microsoft.com/office/word/2010/wordprocessingGroup") }, + { BAD_CAST("wp"), + BAD_CAST("http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing") }, + { BAD_CAST("office"), BAD_CAST("urn:oasis:names:tc:opendocument:xmlns:office:1.0") }, + { BAD_CAST("table"), BAD_CAST("urn:oasis:names:tc:opendocument:xmlns:table:1.0") }, + { BAD_CAST("text"), BAD_CAST("urn:oasis:names:tc:opendocument:xmlns:text:1.0") }, + { BAD_CAST("style"), BAD_CAST("urn:oasis:names:tc:opendocument:xmlns:style:1.0") }, + { BAD_CAST("draw"), BAD_CAST("urn:oasis:names:tc:opendocument:xmlns:drawing:1.0") }, + { BAD_CAST("xlink"), BAD_CAST("http://www.w3c.org/1999/xlink") }, + { BAD_CAST("xdr"), + BAD_CAST("http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing") }, + { BAD_CAST("xx"), BAD_CAST("urn:schemas-microsoft-com:office:excel") }, + { BAD_CAST("r"), BAD_CAST("http://schemas.openxmlformats.org/package/2006/relationships") }, + { BAD_CAST("number"), BAD_CAST("urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0") }, + { BAD_CAST("loext"), + BAD_CAST("urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0") }, + { BAD_CAST("tableooo"), BAD_CAST("http://openoffice.org/2009/table") }, + { BAD_CAST("ContentType"), + BAD_CAST("http://schemas.openxmlformats.org/package/2006/content-types") }, + { BAD_CAST("x14"), + BAD_CAST("http://schemas.microsoft.com/office/spreadsheetml/2009/9/main") }, + { BAD_CAST("xm"), BAD_CAST("http://schemas.microsoft.com/office/excel/2006/main") }, + { BAD_CAST("x12ac"), + BAD_CAST("http://schemas.microsoft.com/office/spreadsheetml/2011/1/ac") }, + }; + for (size_t i = 0; i < SAL_N_ELEMENTS(aNamespaces); ++i) + { + xmlXPathRegisterNs(pXmlXPathCtx, aNamespaces[i].pPrefix, aNamespaces[i].pURI); + } +} + +void ScExportTest2::testMatrixMultiplicationXLSX() +{ + ScDocShellRef xShell = loadDoc(u"matrix-multiplication.", FORMAT_XLSX); + CPPUNIT_ASSERT(xShell.is()); + + ScDocShellRef xDocSh = saveAndReload(&(*xShell), FORMAT_XLSX); + CPPUNIT_ASSERT(xDocSh.is()); + + xmlDocUniquePtr pDoc = XPathHelper::parseExport2(*this, *xDocSh, m_xSFactory, + "xl/worksheets/sheet1.xml", FORMAT_XLSX); + CPPUNIT_ASSERT(pDoc); + + OUString CellFormulaRange = getXPath(pDoc, "/x:worksheet/x:sheetData/x:row[4]/x:c/x:f", "ref"); + + // make sure that the CellFormulaRange is G5:G6. + CPPUNIT_ASSERT_EQUAL(OUString("G5:G6"), CellFormulaRange); + + OUString CellFormulaType = getXPath(pDoc, "/x:worksheet/x:sheetData/x:row[4]/x:c/x:f", "t"); + + // make sure that the CellFormulaType is array. + CPPUNIT_ASSERT_EQUAL(OUString("array"), CellFormulaType); + + xDocSh->DoClose(); +} + +void ScExportTest2::testRefStringXLSX() +{ + ScDocShellRef xDocSh = loadDoc(u"ref_string.", FORMAT_XLSX); + CPPUNIT_ASSERT_MESSAGE("Failed to open doc", xDocSh.is()); + + //make sure ref syntax gets saved for MSO-produced docs + xDocSh = saveAndReload(&(*xDocSh), FORMAT_XLSX); + CPPUNIT_ASSERT_MESSAGE("Failed to reload doc", xDocSh.is()); + + ScDocument& rDoc = xDocSh->GetDocument(); + ScCalcConfig aCalcConfig = rDoc.GetCalcConfig(); + CPPUNIT_ASSERT_EQUAL(formula::FormulaGrammar::CONV_XL_A1, aCalcConfig.meStringRefAddressSyntax); + + xDocSh->DoClose(); +} + +void ScExportTest2::testRefStringConfigXLSX() +{ + // this doc is configured with CalcA1 ref syntax + ScDocShellRef xDocSh = loadDoc(u"empty.", FORMAT_XLSX); + CPPUNIT_ASSERT_MESSAGE("Failed to open doc", xDocSh.is()); + + xDocSh = saveAndReload(&(*xDocSh), FORMAT_XLSX); + CPPUNIT_ASSERT_MESSAGE("Failed to reload doc", xDocSh.is()); + + ScDocument& rDoc = xDocSh->GetDocument(); + ScCalcConfig aConfig = rDoc.GetCalcConfig(); + CPPUNIT_ASSERT_EQUAL_MESSAGE("String ref syntax doesn't match", + formula::FormulaGrammar::CONV_OOO, + aConfig.meStringRefAddressSyntax); + + xDocSh->DoClose(); + + // this doc has no entry for ref syntax + xDocSh = loadDoc(u"empty-noconf.", FORMAT_XLSX); + CPPUNIT_ASSERT_MESSAGE("Failed to open 2nd doc", xDocSh.is()); + + ScDocument& rDoc2 = xDocSh->GetDocument(); + aConfig = rDoc2.GetCalcConfig(); + // therefore after import, ref syntax should be set to CalcA1 | ExcelA1 + CPPUNIT_ASSERT_EQUAL_MESSAGE("String ref syntax doesn't match", + formula::FormulaGrammar::CONV_A1_XL_A1, + aConfig.meStringRefAddressSyntax); + + //set ref syntax to something else than ExcelA1 (native to xlsx format) ... + aConfig.meStringRefAddressSyntax = formula::FormulaGrammar::CONV_XL_R1C1; + rDoc2.SetCalcConfig(aConfig); + + ScDocShellRef xNewDocSh = saveAndReload(&(*xDocSh), FORMAT_XLSX); + CPPUNIT_ASSERT_MESSAGE("Failed to reload 2nd doc", xNewDocSh.is()); + + // ... and make sure it got saved + ScDocument& rDoc3 = xNewDocSh->GetDocument(); + aConfig = rDoc3.GetCalcConfig(); + CPPUNIT_ASSERT_EQUAL_MESSAGE("String ref syntax doesn't match", + formula::FormulaGrammar::CONV_XL_R1C1, + aConfig.meStringRefAddressSyntax); + + xDocSh->DoClose(); + xNewDocSh->DoClose(); +} + +void ScExportTest2::testRefStringUnspecified() +{ + ScDocShell* pShell + = new ScDocShell(SfxModelFlags::EMBEDDED_OBJECT | SfxModelFlags::DISABLE_EMBEDDED_SCRIPTS + | SfxModelFlags::DISABLE_DOCUMENT_RECOVERY); + pShell->DoInitNew(); + + ScDocument& rDoc = pShell->GetDocument(); + ScCalcConfig aConfig = rDoc.GetCalcConfig(); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Default string ref syntax value doesn't match", + formula::FormulaGrammar::CONV_UNSPECIFIED, + aConfig.meStringRefAddressSyntax); + + // change formula syntax (i.e. not string ref syntax) to ExcelA1 + rDoc.SetGrammar(formula::FormulaGrammar::GRAM_NATIVE_XL_A1); + + ScDocShellRef xDocSh = saveAndReload(pShell, FORMAT_ODS); + CPPUNIT_ASSERT_MESSAGE("Failed to reload doc", xDocSh.is()); + + // with string ref syntax at its default value, we should've saved ExcelA1 + ScDocument& rDoc2 = xDocSh->GetDocument(); + aConfig = rDoc2.GetCalcConfig(); + CPPUNIT_ASSERT_EQUAL_MESSAGE("String ref syntax doesn't match", + formula::FormulaGrammar::CONV_XL_A1, + aConfig.meStringRefAddressSyntax); + + xDocSh->DoClose(); +} + +void ScExportTest2::testHeaderImageODS() +{ + // Graphic as header background was lost on export. + ScDocShellRef xShell = loadDoc(u"header-image.", FORMAT_ODS); + ScDocShellRef xDocSh = saveAndReload(&(*xShell), FORMAT_ODS); + uno::Reference<style::XStyleFamiliesSupplier> xStyleFamiliesSupplier(xDocSh->GetModel(), + uno::UNO_QUERY); + uno::Reference<container::XNameAccess> xStyleFamilies + = xStyleFamiliesSupplier->getStyleFamilies(); + uno::Reference<container::XNameAccess> xPageStyles(xStyleFamilies->getByName("PageStyles"), + uno::UNO_QUERY); + uno::Reference<beans::XPropertySet> xStyle(xPageStyles->getByName("Default"), uno::UNO_QUERY); + + uno::Reference<graphic::XGraphic> xGraphic; + xStyle->getPropertyValue("HeaderBackGraphic") >>= xGraphic; + CPPUNIT_ASSERT(xGraphic.is()); + xDocSh->DoClose(); +} + +void ScExportTest2::testTextDirectionXLSX() +{ + ScDocShellRef xDocSh = loadDoc(u"writingMode.", FORMAT_XLSX); + CPPUNIT_ASSERT(xDocSh.is()); + + xmlDocUniquePtr pDoc + = XPathHelper::parseExport2(*this, *xDocSh, m_xSFactory, "xl/styles.xml", FORMAT_XLSX); + CPPUNIT_ASSERT(pDoc); + + assertXPath(pDoc, "/x:styleSheet/x:cellXfs/x:xf[2]/x:alignment", "readingOrder", "1"); //LTR + assertXPath(pDoc, "/x:styleSheet/x:cellXfs/x:xf[3]/x:alignment", "readingOrder", "2"); //RTL + + xDocSh->DoClose(); +} + +void ScExportTest2::testTdf120168() +{ + ScDocShellRef xDocSh = loadDoc(u"tdf120168.", FORMAT_XLSX); + CPPUNIT_ASSERT(xDocSh.is()); + + xmlDocUniquePtr pDoc + = XPathHelper::parseExport2(*this, *xDocSh, m_xSFactory, "xl/styles.xml", FORMAT_XLSX); + CPPUNIT_ASSERT(pDoc); + + // Without the fix in place, this test would have failed with + // - Expected: left + // - Actual : general + assertXPath(pDoc, "/x:styleSheet/x:cellXfs/x:xf[2]/x:alignment", "horizontal", "left"); + assertXPath(pDoc, "/x:styleSheet/x:cellXfs/x:xf[3]/x:alignment", "horizontal", "right"); + + xDocSh->DoClose(); +} + +void ScExportTest2::testTdf66668() +{ + // Would hang on exporting without the fix in place + ScDocShellRef xDocSh = loadDoc(u"tdf66668.", FORMAT_XLSX); + CPPUNIT_ASSERT_MESSAGE("Failed to open doc", xDocSh.is()); + + xmlDocUniquePtr pDoc + = XPathHelper::parseExport2(*this, *xDocSh, m_xSFactory, "xl/styles.xml", FORMAT_XLSX); + CPPUNIT_ASSERT(pDoc); + xDocSh->DoClose(); +} + +void ScExportTest2::testTdf130108() +{ + ScDocShellRef xDocSh = loadDoc(u"tdf130108.", FORMAT_ODS); + CPPUNIT_ASSERT(xDocSh.is()); + + xmlDocUniquePtr pDoc + = XPathHelper::parseExport2(*this, *xDocSh, m_xSFactory, "xl/styles.xml", FORMAT_XLSX); + CPPUNIT_ASSERT(pDoc); + + assertXPath(pDoc, "/x:styleSheet/x:dxfs/x:dxf/x:font/x:b", "val", "1"); + assertXPath(pDoc, "/x:styleSheet/x:dxfs/x:dxf/x:font/x:i", "val", "0"); + assertXPath(pDoc, "/x:styleSheet/x:dxfs/x:dxf/x:font/x:color", "rgb", "FFFFFFFF"); + assertXPath(pDoc, "/x:styleSheet/x:dxfs/x:dxf/x:font/x:sz", "val", "10"); + assertXPath(pDoc, "/x:styleSheet/x:dxfs/x:dxf/x:fill/x:patternFill/x:bgColor", "rgb", + "FFCC0000"); + + xDocSh->DoClose(); +} + +void ScExportTest2::testTdf76949() +{ + ScDocShellRef xDocSh = loadDoc(u"tdf76949.", FORMAT_ODS); + CPPUNIT_ASSERT(xDocSh.is()); + + xmlDocUniquePtr pSheet = XPathHelper::parseExport2(*this, *xDocSh, m_xSFactory, + "xl/worksheets/sheet1.xml", FORMAT_XLSX); + CPPUNIT_ASSERT(pSheet); + + assertXPathContent(pSheet, "/x:worksheet/x:sheetData/x:row/x:c/x:f", "_xlfn.CHISQ.DIST(1,1,1)"); + + xDocSh->DoClose(); +} + +void ScExportTest2::testTdf107586() +{ + ScDocShellRef xDocSh = loadDoc(u"tdf107586.", FORMAT_XLSX); + CPPUNIT_ASSERT(xDocSh.is()); + + xmlDocUniquePtr pSheet = XPathHelper::parseExport2(*this, *xDocSh, m_xSFactory, + "xl/worksheets/sheet1.xml", FORMAT_XLSX); + CPPUNIT_ASSERT(pSheet); + + // Without the fix in place, this test would have failed with + // XPath '/x:worksheet/x:sheetPr/x:tabColor' number of nodes is incorrect + assertXPath(pSheet, "/x:worksheet/x:sheetPr/x:tabColor", "rgb", "FF9BBB59"); + + xDocSh->DoClose(); +} + +void ScExportTest2::testTdf55417() +{ + ScDocShellRef xDocSh = loadDoc(u"tdf55417.", FORMAT_XLSX); + CPPUNIT_ASSERT(xDocSh.is()); + + xmlDocUniquePtr pDoc + = XPathHelper::parseExport2(*this, *xDocSh, m_xSFactory, "xl/styles.xml", FORMAT_XLSX); + CPPUNIT_ASSERT(pDoc); + assertXPath(pDoc, "/x:styleSheet/x:cellXfs/x:xf[1]/x:alignment", 1); + assertXPath(pDoc, "/x:styleSheet/x:cellXfs/x:xf[2]/x:alignment", 1); + + xDocSh->DoClose(); +} + +void ScExportTest2::testTdf129985() +{ + ScDocShellRef xDocSh = loadDoc(u"tdf129985.", FORMAT_XLSX); + CPPUNIT_ASSERT(xDocSh.is()); + + xmlDocUniquePtr pDoc + = XPathHelper::parseExport2(*this, *xDocSh, m_xSFactory, "xl/styles.xml", FORMAT_XLSX); + CPPUNIT_ASSERT(pDoc); + + assertXPath(pDoc, "/x:styleSheet/x:numFmts/x:numFmt[2]", "formatCode", "m/d/yyyy"); + + xDocSh->DoClose(); +} + +void ScExportTest2::testTdf73063() +{ + ScDocShellRef xDocSh = loadDoc(u"tdf73063.", FORMAT_XLSX); + CPPUNIT_ASSERT(xDocSh.is()); + + xmlDocUniquePtr pDoc + = XPathHelper::parseExport2(*this, *xDocSh, m_xSFactory, "xl/styles.xml", FORMAT_XLSX); + CPPUNIT_ASSERT(pDoc); + + assertXPath(pDoc, "/x:styleSheet/x:numFmts/x:numFmt[2]", "formatCode", + "[$-1C1A]dddd\", \"d\". \"mmmm\\ yyyy;@"); + + xDocSh->DoClose(); +} + +xmlDocUniquePtr ScExportTest2::testTdf95640(std::u16string_view rFileName, sal_Int32 nSourceFormat, + sal_Int32 nDestFormat) +{ + ScDocShellRef xShell = loadDoc(rFileName, nSourceFormat); + CPPUNIT_ASSERT(xShell); + + auto pXPathFile = ScBootstrapFixture::exportTo(&(*xShell), nDestFormat); + xShell->DoClose(); + + return XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/worksheets/sheet1.xml"); +} + +void ScExportTest2::testTdf95640_ods_to_xlsx() +{ + // Roundtripping sort options with user defined list to XLSX + xmlDocUniquePtr pDoc = testTdf95640(u"tdf95640.", FORMAT_ODS, FORMAT_XLSX); + + assertXPath(pDoc, "//x:worksheet/x:autoFilter", "ref", "A1:B4"); + + assertXPath(pDoc, "//x:worksheet/x:autoFilter/x:sortState/x:sortCondition", "ref", "A2:A4"); + + assertXPath(pDoc, "//x:worksheet/x:autoFilter/x:sortState/x:sortCondition", "customList", + "Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec"); +} + +void ScExportTest2::testTdf95640_ods_to_xlsx_with_standard_list() +{ + // Roundtripping sort options with user defined list to XLSX + xmlDocUniquePtr pDoc = testTdf95640(u"tdf95640_standard_list.", FORMAT_ODS, FORMAT_XLSX); + + assertXPath(pDoc, "//x:worksheet/x:autoFilter", "ref", "A1:B4"); + + assertXPath(pDoc, "//x:worksheet/x:autoFilter/x:sortState/x:sortCondition", "ref", "A2:A4"); + + assertXPath(pDoc, "//x:worksheet/x:autoFilter/x:sortState/x:sortCondition", "customList", + "Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday"); +} + +void ScExportTest2::testTdf95640_xlsx_to_xlsx() +{ + // XLSX Roundtripping sort options with custom sort list - note + // that compared to ODS source documents above, here we _actually_ + // can use custom lists (beyond the global user defines), like + // low, medium, high + xmlDocUniquePtr pDoc = testTdf95640(u"tdf95640.", FORMAT_XLSX, FORMAT_XLSX); + + assertXPath(pDoc, "//x:worksheet/x:autoFilter", "ref", "A1:B4"); + + assertXPath(pDoc, "//x:worksheet/x:autoFilter/x:sortState/x:sortCondition", "ref", "A2:A4"); + + assertXPath(pDoc, "//x:worksheet/x:autoFilter/x:sortState/x:sortCondition", "customList", + "Low,Medium,High"); +} + +void ScExportTest2::testDateAutofilterXLSX() +{ + // XLSX Roundtripping autofilter with date list + ScDocShellRef xDocSh = loadDoc(u"dateAutofilter.", FORMAT_XLSX); + CPPUNIT_ASSERT(xDocSh.is()); + + xmlDocUniquePtr pDoc = XPathHelper::parseExport2(*this, *xDocSh, m_xSFactory, + "xl/worksheets/sheet1.xml", FORMAT_XLSX); + CPPUNIT_ASSERT(pDoc); + + assertXPath(pDoc, "//x:autoFilter", "ref", "A1:B4"); + assertXPath(pDoc, "//x:autoFilter/x:filterColumn/x:filters/x:dateGroupItem[1]", "day", "02"); + assertXPath(pDoc, "//x:autoFilter/x:filterColumn/x:filters/x:dateGroupItem[1]", "month", "03"); + assertXPath(pDoc, "//x:autoFilter/x:filterColumn/x:filters/x:dateGroupItem[1]", "year", "2017"); + assertXPath(pDoc, "//x:autoFilter/x:filterColumn/x:filters/x:dateGroupItem[1]", + "dateTimeGrouping", "day"); + + assertXPath(pDoc, "//x:autoFilter/x:filterColumn/x:filters/x:dateGroupItem[2]", "day", "01"); + assertXPath(pDoc, "//x:autoFilter/x:filterColumn/x:filters/x:dateGroupItem[2]", "month", "10"); + assertXPath(pDoc, "//x:autoFilter/x:filterColumn/x:filters/x:dateGroupItem[2]", "year", "2014"); + assertXPath(pDoc, "//x:autoFilter/x:filterColumn/x:filters/x:dateGroupItem[2]", + "dateTimeGrouping", "day"); + + xDocSh->DoClose(); +} + +void ScExportTest2::testDateAutofilterODS() +{ + ScDocShellRef xDocSh = loadDoc(u"tdf142231.", FORMAT_ODS); + CPPUNIT_ASSERT(xDocSh.is()); + + xmlDocUniquePtr pDoc + = XPathHelper::parseExport2(*this, *xDocSh, m_xSFactory, "content.xml", FORMAT_ODS); + CPPUNIT_ASSERT(pDoc); + + assertXPath(pDoc, "//table:filter/table:filter-and/table:filter-condition[1]", "value", "Calc"); + assertXPath(pDoc, "//table:filter/table:filter-and/table:filter-condition[2]", "value", + "2021-05-04"); +} + +void ScExportTest2::testAutofilterColorsODF() +{ + ScDocShellRef xDocSh = loadDoc(u"autofilter-colors.", FORMAT_ODS); + CPPUNIT_ASSERT(xDocSh.is()); + + xmlDocUniquePtr pDoc + = XPathHelper::parseExport2(*this, *xDocSh, m_xSFactory, "content.xml", FORMAT_ODS); + CPPUNIT_ASSERT(pDoc); + + assertXPath(pDoc, "//table:filter/table:filter-and/table:filter-condition[1]", "value", + "#e8f2a1"); + assertXPath(pDoc, "//table:filter/table:filter-and/" + "table:filter-condition[1][@loext:data-type='background-color']"); + assertXPath(pDoc, "//table:filter/table:filter-and/table:filter-condition[2]", "value", + "#3465a4"); + assertXPath( + pDoc, + "//table:filter/table:filter-and/table:filter-condition[2][@loext:data-type='text-color']"); +} + +void ScExportTest2::testAutofilterColorsOOXML() +{ + ScDocShellRef xDocSh = loadDoc(u"autofilter-colors.", FORMAT_XLSX); + CPPUNIT_ASSERT(xDocSh.is()); + + xmlDocUniquePtr pDoc = XPathHelper::parseExport2(*this, *xDocSh, m_xSFactory, + "xl/tables/table1.xml", FORMAT_XLSX); + CPPUNIT_ASSERT(pDoc); + + assertXPath(pDoc, "/x:table/x:autoFilter/x:filterColumn/x:colorFilter", "dxfId", "4"); +} + +void ScExportTest2::testAutofilterColorsStyleOOXML() +{ + ScDocShellRef xDocSh = loadDoc(u"autofilter-colors.", FORMAT_XLSX); + CPPUNIT_ASSERT(xDocSh.is()); + + xmlDocUniquePtr pDoc + = XPathHelper::parseExport2(*this, *xDocSh, m_xSFactory, "xl/styles.xml", FORMAT_XLSX); + CPPUNIT_ASSERT(pDoc); + + assertXPath(pDoc, "/x:styleSheet/x:dxfs/x:dxf[5]/x:fill/x:patternFill/x:bgColor", "rgb", + "FFFFD7D7"); +} + +void ScExportTest2::testTdf88657ODS() +{ + ScDocShellRef xDocSh = loadDoc(u"tdf88657.", FORMAT_ODS); + CPPUNIT_ASSERT(xDocSh.is()); + + xmlDocUniquePtr pDoc + = XPathHelper::parseExport2(*this, *xDocSh, m_xSFactory, "styles.xml", FORMAT_ODS); + CPPUNIT_ASSERT(pDoc); + + assertXPath(pDoc, "//number:fraction", "min-denominator-digits", "3"); + + xDocSh->DoClose(); +} + +void ScExportTest2::testTdf41722() +{ + ScDocShellRef xDocSh = loadDoc(u"tdf41722.", FORMAT_XLSX); + CPPUNIT_ASSERT(xDocSh.is()); + + xmlDocUniquePtr pDoc = XPathHelper::parseExport2(*this, *xDocSh, m_xSFactory, + "xl/worksheets/sheet1.xml", FORMAT_XLSX); + CPPUNIT_ASSERT(pDoc); + + assertXPath(pDoc, "//x:conditionalFormatting/x:cfRule[1]", "operator", "containsText"); + assertXPath(pDoc, "//x:conditionalFormatting/x:cfRule[2]", "operator", "containsText"); + assertXPath(pDoc, "//x:conditionalFormatting/x:cfRule[3]", "operator", "containsText"); + + xDocSh->DoClose(); +} + +void ScExportTest2::testTdf113621() +{ + ScDocShellRef xDocSh = loadDoc(u"tdf113621.", FORMAT_XLSX); + CPPUNIT_ASSERT(xDocSh.is()); + + xmlDocUniquePtr pDoc = XPathHelper::parseExport2(*this, *xDocSh, m_xSFactory, + "xl/worksheets/sheet1.xml", FORMAT_XLSX); + CPPUNIT_ASSERT(pDoc); + + assertXPath(pDoc, "//x:conditionalFormatting", "sqref", "A1:A1048576"); + + xDocSh->DoClose(); +} + +void ScExportTest2::testEscapeCharInNumberFormatXLSX() +{ + ScDocShellRef xDocSh = loadDoc(u"tdf81939.", FORMAT_XLSX); + CPPUNIT_ASSERT(xDocSh.is()); + xDocSh = saveAndReload(&(*xDocSh), FORMAT_XLSX); + CPPUNIT_ASSERT(xDocSh.is()); + + xmlDocUniquePtr pDoc + = XPathHelper::parseExport2(*this, *xDocSh, m_xSFactory, "xl/styles.xml", FORMAT_XLSX); + CPPUNIT_ASSERT(pDoc); + + const sal_Unicode cEuro(8364); // € symbol + assertXPath(pDoc, "/x:styleSheet/x:numFmts/x:numFmt[2]", "formatCode", + "00\\ 00\\ 00\\ 00\\ 00"); + assertXPath(pDoc, "/x:styleSheet/x:numFmts/x:numFmt[3]", "formatCode", + "00\\.00\\.00\\.000\\.0"); // tdf#81939 + // "_-* #,##0\ _€_-;\-* #,##0\ _€_-;_-* "- "_€_-;_-@_-" // tdf#81222 + OUString rFormatStrExpected("_-* #,##0\\ _" + OUStringChar(cEuro) + "_-;\\-* #,##0\\ _" + + OUStringChar(cEuro) + "_-;_-* \"- \"_" + OUStringChar(cEuro) + + "_-;_-@_-"); + assertXPath(pDoc, "/x:styleSheet/x:numFmts/x:numFmt[4]", "formatCode", rFormatStrExpected); + // "_-* #,##0" €"_-;\-* #,##0" €"_-;_-* "- €"_-;_-@_-"); + rFormatStrExpected = "_-* #,##0\" " + OUStringChar(cEuro) + "\"_-;\\-* #,##0\" " + + OUStringChar(cEuro) + "\"_-;_-* \"- " + OUStringChar(cEuro) + + "\"_-;_-@_-"; + assertXPath(pDoc, "/x:styleSheet/x:numFmts/x:numFmt[5]", "formatCode", rFormatStrExpected); + // remove escape char in fraction + assertXPath(pDoc, "/x:styleSheet/x:numFmts/x:numFmt[6]", "formatCode", + "# ?/?;[RED]\\-# #/#####"); + + xDocSh->DoClose(); +} + +void ScExportTest2::testNatNumInNumberFormatXLSX() +{ + ScDocShellRef xDocSh = loadDoc(u"tdf79398_NatNum5.", FORMAT_ODS); + CPPUNIT_ASSERT(xDocSh.is()); + xDocSh = saveAndReload(&(*xDocSh), FORMAT_XLSX); // Convert [NatNum5] to [DBNum2] in Chinese + CPPUNIT_ASSERT(xDocSh.is()); + + xmlDocUniquePtr pDoc + = XPathHelper::parseExport2(*this, *xDocSh, m_xSFactory, "xl/styles.xml", FORMAT_XLSX); + CPPUNIT_ASSERT(pDoc); + + assertXPath(pDoc, "/x:styleSheet/x:numFmts/x:numFmt[3]", "formatCode", + "[DBNum2][$-804]General;[RED][DBNum2][$-804]General"); + + xDocSh->DoClose(); +} + +void ScExportTest2::testExponentWithoutSignFormatXLSX() +{ + ScDocShellRef xDocSh = loadDoc(u"tdf102370_ExponentWithoutSign.", FORMAT_ODS); + CPPUNIT_ASSERT(xDocSh.is()); + xDocSh = saveAndReload(&(*xDocSh), FORMAT_XLSX); + CPPUNIT_ASSERT(xDocSh.is()); + + xDocSh = saveAndReload(&(*xDocSh), FORMAT_ODS); + CPPUNIT_ASSERT(xDocSh.is()); + + ScDocument& rDoc = xDocSh->GetDocument(); + sal_uInt32 nNumberFormat; + rDoc.GetNumberFormat(0, 0, 0, nNumberFormat); + const SvNumberformat* pNumberFormat = rDoc.GetFormatTable()->GetEntry(nNumberFormat); + const OUString& rFormatStr = pNumberFormat->GetFormatstring(); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("Number format lost exponent without sign during Excel export", + OUString("0.00E0"), rFormatStr); + + xDocSh->DoClose(); +} + +void ScExportTest2::testExtendedLCIDXLSX() +{ + ScDocShellRef xDocSh = loadDoc(u"tdf36038_ExtendedLCID.", FORMAT_ODS); + CPPUNIT_ASSERT(xDocSh.is()); + xDocSh = saveAndReload(&(*xDocSh), FORMAT_XLSX); + CPPUNIT_ASSERT(xDocSh.is()); + + xmlDocUniquePtr pDoc + = XPathHelper::parseExport2(*this, *xDocSh, m_xSFactory, "xl/styles.xml", FORMAT_XLSX); + CPPUNIT_ASSERT(pDoc); + // Check export + assertXPath(pDoc, "/x:styleSheet/x:numFmts/x:numFmt[2]", "formatCode", + "[$-107041E]dd\\-mm\\-yyyy"); + assertXPath(pDoc, "/x:styleSheet/x:numFmts/x:numFmt[3]", "formatCode", + "[$-D07041E]dd\\-mm\\-yyyy"); + assertXPath(pDoc, "/x:styleSheet/x:numFmts/x:numFmt[4]", "formatCode", + "[$-1030411]dd\\-mm\\-ee"); + assertXPath(pDoc, "/x:styleSheet/x:numFmts/x:numFmt[5]", "formatCode", + "[$-1B030411]dd\\-mm\\-ee"); + assertXPath(pDoc, "/x:styleSheet/x:numFmts/x:numFmt[6]", "formatCode", + "[$-108040D]dd\\-mm\\-yyyy"); + //assertXPath(pDoc, "/x:styleSheet/x:numFmts/x:numFmt[7]", "formatCode", "[$-108040D]dd\\-mm\\-yyyy"); + assertXPath(pDoc, "/x:styleSheet/x:numFmts/x:numFmt[7]", "formatCode", + "[$-1060401]dd\\-mm\\-yyyy"); + assertXPath(pDoc, "/x:styleSheet/x:numFmts/x:numFmt[8]", "formatCode", + "[$-2060401]dd\\-mm\\-yyyy"); + + // Check import + ScDocument& rDoc = xDocSh->GetDocument(); + SvNumberFormatter* pNumFormatter = rDoc.GetFormatTable(); + sal_uInt32 nNumberFormat; + const OUString aLang[5] = { "[$-41E]", "[$-411]", "[$-40D]", "[$-401]", "[$-500]" }; + const OUString aCalendar[5] = { "[~buddhist]DD-MM-YYYY", "DD-MM-EE", "[~jewish]DD-MM-YYYY", + "[~hijri]DD-MM-YYYY", "[~dangi]YYYY/MM/DD" }; + // Note: ja-JP Gengou calendar is an implicit secondary (non-gregorian) + // calendar, the explicit [~gengou] calendar modifier does not need to be + // present, the E and EE keywords are used instead of YY and YYYY. + for (sal_Int16 nCol = 1; nCol <= 2; nCol++) + { + for (sal_Int16 nRow = 1; nRow <= 4; nRow++) + { + rDoc.GetNumberFormat(nCol, nRow, 0, nNumberFormat); + const SvNumberformat* pNumberFormat = pNumFormatter->GetEntry(nNumberFormat); + const OUString& rFormatStr = pNumberFormat->GetFormatstring(); + const OUString aExpectedFormatStr + = aLang[nRow - 1] + ((nCol == 2 && nRow != 3) ? OUString("[NatNum1]") : OUString()) + + aCalendar[nRow - 1]; + + CPPUNIT_ASSERT_EQUAL_MESSAGE("Number format lost extended LCID during Excel export", + aExpectedFormatStr, rFormatStr); + } + } + + xDocSh->DoClose(); +} + +void ScExportTest2::testHiddenRepeatedRowsODS() +{ + ScDocShellRef xDocSh = loadDoc(u"empty.", FORMAT_ODS); + CPPUNIT_ASSERT(xDocSh.is()); + + { + ScDocument& rDoc = xDocSh->GetDocument(); + rDoc.SetRowHidden(0, 20, 0, true); + } + + xDocSh = saveAndReload(&(*xDocSh), FORMAT_ODS); + ScDocument& rDoc = xDocSh->GetDocument(); + SCROW nFirstRow = 0; + SCROW nLastRow = 0; + bool bHidden = rDoc.RowHidden(0, 0, &nFirstRow, &nLastRow); + CPPUNIT_ASSERT(bHidden); + CPPUNIT_ASSERT_EQUAL(SCROW(0), nFirstRow); + CPPUNIT_ASSERT_EQUAL(SCROW(20), nLastRow); + xDocSh->DoClose(); +} + +void ScExportTest2::testHyperlinkTargetFrameODS() +{ + ScDocShellRef xDocSh = loadDoc(u"hyperlink_frame.", FORMAT_ODS); + CPPUNIT_ASSERT(xDocSh.is()); + + ScDocument& rDoc = xDocSh->GetDocument(); + const EditTextObject* pEditText = rDoc.GetEditText(ScAddress(2, 5, 0)); + CPPUNIT_ASSERT(pEditText); + + const SvxFieldData* pData = pEditText->GetFieldData(0, 0, text::textfield::Type::URL); + CPPUNIT_ASSERT_MESSAGE("Failed to get the URL data.", pData); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Failed to get the URL data.", text::textfield::Type::URL, + pData->GetClassId()); + + const SvxURLField* pURLData = static_cast<const SvxURLField*>(pData); + OUString aTargetFrame = pURLData->GetTargetFrame(); + CPPUNIT_ASSERT_EQUAL(OUString("_blank"), aTargetFrame); + + xmlDocUniquePtr pDoc + = XPathHelper::parseExport2(*this, *xDocSh, m_xSFactory, "content.xml", FORMAT_ODS); + CPPUNIT_ASSERT(pDoc); + OUString aTargetFrameExport + = getXPath(pDoc, + "/office:document-content/office:body/office:spreadsheet/table:table/" + "table:table-row[2]/table:table-cell[2]/text:p/text:a", + "target-frame-name"); + CPPUNIT_ASSERT_EQUAL(OUString("_blank"), aTargetFrameExport); + + xDocSh->DoClose(); +} + +void ScExportTest2::testOpenDocumentAsReadOnly() +{ + ScDocShellRef xDocSh = loadDoc(u"open-as-read-only.", FORMAT_XLSX); + CPPUNIT_ASSERT(xDocSh->IsSecurityOptOpenReadOnly()); + ScDocShellRef xDocSh2 = saveAndReload(xDocSh.get(), FORMAT_XLSX); + CPPUNIT_ASSERT(xDocSh2->IsSecurityOptOpenReadOnly()); + xDocSh->DoClose(); + xDocSh2->DoClose(); +} + +void ScExportTest2::testKeepSettingsOfBlankRows() +{ + ScDocShellRef xDocSh = loadDoc(u"tdf41425.", FORMAT_XLSX); + CPPUNIT_ASSERT(xDocSh.is()); + + std::shared_ptr<utl::TempFile> pXPathFile + = ScBootstrapFixture::exportTo(&(*xDocSh), FORMAT_XLSX); + xmlDocUniquePtr pSheet + = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/worksheets/sheet1.xml"); + CPPUNIT_ASSERT(pSheet); + + // saved blank row with not default setting in A2 + assertXPath(pSheet, "/x:worksheet/x:sheetData/x:row", 2); + + xDocSh->DoClose(); +} + +void ScExportTest2::testTdf133595() +{ + ScDocShellRef xDocSh = loadDoc(u"tdf133595.", FORMAT_XLSX); + CPPUNIT_ASSERT(xDocSh.is()); + + std::shared_ptr<utl::TempFile> pXPathFile + = ScBootstrapFixture::exportTo(&(*xDocSh), FORMAT_XLSX); + xmlDocUniquePtr pSheet + = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/worksheets/sheet1.xml"); + CPPUNIT_ASSERT(pSheet); + + // without the fix in place, mc:AlternateContent would have been added to sheet1 + assertXPath(pSheet, "/x:worksheet/mc:AlternateContent", 0); + + xDocSh->DoClose(); +} + +void ScExportTest2::testTdf134769() +{ + ScDocShellRef xDocSh = loadDoc(u"tdf134769.", FORMAT_XLSX); + CPPUNIT_ASSERT(xDocSh.is()); + + std::shared_ptr<utl::TempFile> pXPathFile + = ScBootstrapFixture::exportTo(&(*xDocSh), FORMAT_XLSX); + xmlDocUniquePtr pSheet + = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/worksheets/sheet1.xml"); + CPPUNIT_ASSERT(pSheet); + + // without the fix in place, the legacyDrawing would have been exported after the checkbox + // and Excel would have claimed the document is corrupted + // Use their ids to check the order + assertXPath(pSheet, "/x:worksheet/x:drawing", "id", "rId2"); + assertXPath(pSheet, "/x:worksheet/x:legacyDrawing", "id", "rId3"); + assertXPath(pSheet, + "/x:worksheet/mc:AlternateContent/mc:Choice/x:controls/mc:AlternateContent/" + "mc:Choice/x:control", + "id", "rId4"); + + xDocSh->DoClose(); +} + +void ScExportTest2::testTdf106181() +{ + ScDocShellRef xDocSh = loadDoc(u"tdf106181.", FORMAT_ODS); + CPPUNIT_ASSERT(xDocSh.is()); + + std::shared_ptr<utl::TempFile> pXPathFile + = ScBootstrapFixture::exportTo(&(*xDocSh), FORMAT_XLSX); + xmlDocUniquePtr pSheet + = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/worksheets/sheet1.xml"); + CPPUNIT_ASSERT(pSheet); + + assertXPath(pSheet, + "/x:worksheet/mc:AlternateContent/mc:Choice/x:controls/mc:AlternateContent/" + "mc:Choice/x:control", + "name", "Check Box"); + assertXPath(pSheet, + "/x:worksheet/mc:AlternateContent/mc:Choice/x:controls/mc:AlternateContent/" + "mc:Choice/x:control/x:controlPr", + "altText", "Check Box 1"); + + xmlDocUniquePtr pDrawing + = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/drawings/drawing1.xml"); + CPPUNIT_ASSERT(pDrawing); + + assertXPath( + pDrawing, + "/xdr:wsDr/mc:AlternateContent/mc:Choice/xdr:twoCellAnchor/xdr:sp/xdr:nvSpPr/xdr:cNvPr", + "name", "Check Box 1"); + assertXPath( + pDrawing, + "/xdr:wsDr/mc:AlternateContent/mc:Choice/xdr:twoCellAnchor/xdr:sp/xdr:nvSpPr/xdr:cNvPr", + "descr", "Check Box"); + assertXPath( + pDrawing, + "/xdr:wsDr/mc:AlternateContent/mc:Choice/xdr:twoCellAnchor/xdr:sp/xdr:nvSpPr/xdr:cNvPr", + "hidden", "0"); + + xDocSh->DoClose(); +} + +void ScExportTest2::testTdf105272() +{ + ScDocShellRef xDocSh = loadDoc(u"tdf105272.", FORMAT_XLSX); + CPPUNIT_ASSERT(xDocSh.is()); + xDocSh = saveAndReload(xDocSh.get(), FORMAT_XLSX); + ScDocument& rDoc = xDocSh->GetDocument(); + //without the fix in place,it would fail + //Expected: Table1[[#This Row],[Total]]/Table1[[#This Row],['# Athletes]] + //Actual : table1[[#this row],[total]]/table1[[#this row],['# athletes]] + + ASSERT_FORMULA_EQUAL(rDoc, ScAddress(7, 3, 0), + "Table1[[#This Row],[Total]]/Table1[[#This Row],['# Athletes]]", + "Wrong formula"); +} + +void ScExportTest2::testTdf118990() +{ + ScDocShellRef xDocSh = loadDoc(u"tdf118990.", FORMAT_XLSX); + CPPUNIT_ASSERT(xDocSh.is()); + xDocSh = saveAndReload(xDocSh.get(), FORMAT_XLSX); + ScDocument& rDoc = xDocSh->GetDocument(); + + // TODO: also test A1, which contains a UNC reference to \\localhost\share\lookupsource.xlsx, + // but currently looses "localhost" part when normalized in INetURLObject, becoming + // file:///share/lookupsource.xlsx - which is incorrect, since it points to local filesystem + // and not to Windows network share. + + ASSERT_FORMULA_EQUAL(rDoc, ScAddress(0, 1, 0), + "VLOOKUP(B1,'file://192.168.1.1/share/lookupsource.xlsx'#$Sheet1.A1:B5,2)", + "Wrong Windows share (using host IP) URL in A2"); + + ASSERT_FORMULA_EQUAL(rDoc, ScAddress(0, 2, 0), + "VLOOKUP(B1,'file://NETWORKHOST/share/lookupsource.xlsx'#$Sheet1.A1:B5,2)", + "Wrong Windows share (using hostname) URL in A3"); + + xDocSh->DoClose(); +} + +void ScExportTest2::testTdf121612() +{ + ScDocShellRef xDocSh = loadDoc(u"tdf121612.", FORMAT_ODS); + CPPUNIT_ASSERT(xDocSh.is()); + xDocSh = saveAndReload(xDocSh.get(), FORMAT_XLSX); + + ScDocument& rDoc = xDocSh->GetDocument(); + + // There should be a pivot table + CPPUNIT_ASSERT(rDoc.HasPivotTable()); + + // DP collection is not lost after export and has one entry + ScDPCollection* pDPColl = rDoc.GetDPCollection(); + CPPUNIT_ASSERT(pDPColl); + CPPUNIT_ASSERT_EQUAL(size_t(1), pDPColl->GetCount()); + + xDocSh->DoClose(); +} + +void ScExportTest2::testTdf112936() +{ + ScDocShellRef xDocSh = loadDoc(u"tdf112936.", FORMAT_XLSX); + CPPUNIT_ASSERT(xDocSh.is()); + + xmlDocUniquePtr pDoc = XPathHelper::parseExport2( + *this, *xDocSh, m_xSFactory, "xl/pivotCache/pivotCacheDefinition1.xml", FORMAT_XLSX); + CPPUNIT_ASSERT(pDoc); + + assertXPath(pDoc, "//x:pivotCacheDefinition", "recordCount", "4"); + assertXPath(pDoc, "//x:pivotCacheDefinition", "createdVersion", "3"); + + xDocSh->DoClose(); +} + +void ScExportTest2::testXltxExport() +{ + // Create new document + ScDocShell* pShell + = new ScDocShell(SfxModelFlags::EMBEDDED_OBJECT | SfxModelFlags::DISABLE_EMBEDDED_SCRIPTS + | SfxModelFlags::DISABLE_DOCUMENT_RECOVERY); + pShell->DoInitNew(); + + // Export as template and check content type + xmlDocUniquePtr pDoc = XPathHelper::parseExport2(*this, *pShell, m_xSFactory, + "[Content_Types].xml", FORMAT_XLTX); + CPPUNIT_ASSERT(pDoc); + assertXPath(pDoc, "/ContentType:Types/ContentType:Override[@PartName='/xl/workbook.xml']", + "ContentType", + "application/vnd.openxmlformats-officedocument.spreadsheetml.template.main+xml"); +} + +void ScExportTest2::testPivotCacheAfterExportXLSX() +{ + ScDocShellRef xDocSh = loadDoc(u"numgroup_example.", FORMAT_ODS); + CPPUNIT_ASSERT(xDocSh.is()); + + // export only + std::shared_ptr<utl::TempFile> pTemp = saveAs(xDocSh.get(), FORMAT_XLSX); + + ScDocument& rDoc = xDocSh->GetDocument(); + CPPUNIT_ASSERT(rDoc.HasPivotTable()); + + // Two pivot tables + ScDPCollection* pDPColl = rDoc.GetDPCollection(); + CPPUNIT_ASSERT(pDPColl); + CPPUNIT_ASSERT_EQUAL(size_t(2), pDPColl->GetCount()); + + // One cache + ScDPCollection::SheetCaches& rSheetCaches = pDPColl->GetSheetCaches(); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), rSheetCaches.size()); + const ScDPCache* pCache = rSheetCaches.getExistingCache(ScRange(0, 0, 0, 3, 30, 0)); + CPPUNIT_ASSERT_MESSAGE("Pivot cache is expected for A1:D31 on the first sheet.", pCache); + + // See if XLSX export didn't damage group info of the 1st pivot table + const ScDPNumGroupInfo* pInfo = pCache->GetNumGroupInfo(1); + CPPUNIT_ASSERT_MESSAGE("No number group info :(", pInfo); + + xDocSh->DoClose(); +} + +void ScExportTest2::testTdf114969XLSX() +{ + ScDocShellRef xDocSh = loadDoc(u"sheet_name_with_dots.", FORMAT_ODS); + CPPUNIT_ASSERT(xDocSh.is()); + + xmlDocUniquePtr pDoc = XPathHelper::parseExport2(*this, *xDocSh, m_xSFactory, + "xl/worksheets/sheet1.xml", FORMAT_XLSX); + CPPUNIT_ASSERT(pDoc); + assertXPath(pDoc, "/x:worksheet/x:hyperlinks/x:hyperlink[1]", "location", "'1.1.1.1'!C1"); + assertXPath(pDoc, "/x:worksheet/x:hyperlinks/x:hyperlink[2]", "location", "'1.1.1.1'!C2"); + + xDocSh->DoClose(); +} + +void ScExportTest2::testTdf115192XLSX() +{ + ScDocShellRef xDocSh = loadDoc(u"test_115192.", FORMAT_XLSX); + CPPUNIT_ASSERT(xDocSh.is()); + + xmlDocUniquePtr pDoc = XPathHelper::parseExport2( + *this, *xDocSh, m_xSFactory, "xl/drawings/_rels/drawing1.xml.rels", FORMAT_XLSX); + CPPUNIT_ASSERT(pDoc); + assertXPath(pDoc, "/r:Relationships/r:Relationship[@Id='rId1']", "TargetMode", "External"); + assertXPathNoAttribute(pDoc, "/r:Relationships/r:Relationship[@Id='rId2']", "TargetMode"); + assertXPath(pDoc, "/r:Relationships/r:Relationship[@Id='rId3']", "TargetMode", "External"); + + xDocSh->DoClose(); +} + +void ScExportTest2::testTdf91634XLSX() +{ + ScDocShellRef xDocSh = loadDoc(u"image_hyperlink.", FORMAT_XLSX); + CPPUNIT_ASSERT(xDocSh.is()); + std::shared_ptr<utl::TempFile> pXPathFile + = ScBootstrapFixture::exportTo(&(*xDocSh), FORMAT_XLSX); + + xmlDocUniquePtr pDoc + = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/drawings/drawing1.xml"); + CPPUNIT_ASSERT(pDoc); + assertXPath(pDoc, "/xdr:wsDr/xdr:twoCellAnchor/xdr:pic/xdr:nvPicPr/xdr:cNvPr/a:hlinkClick", 1); + + xmlDocUniquePtr pXmlRels + = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/drawings/_rels/drawing1.xml.rels"); + CPPUNIT_ASSERT(pXmlRels); + assertXPath(pXmlRels, "/r:Relationships/r:Relationship[@Id='rId1']", "Target", + "https://www.google.com/"); + assertXPath(pXmlRels, "/r:Relationships/r:Relationship[@Id='rId1']", "TargetMode", "External"); + + xDocSh->DoClose(); +} + +void ScExportTest2::testValidationCopyPaste() +{ + ScDocShellRef xDocSh = loadDoc(u"validation-copypaste.", FORMAT_ODS); + CPPUNIT_ASSERT(xDocSh.is()); + ScDocument& rSrcDoc = xDocSh->GetDocument(); + + // Copy B1 from src doc to clip + ScDocument aClipDoc(SCDOCMODE_CLIP); + ScRange aSrcRange(1, 0, 1); + ScClipParam aClipParam(aSrcRange, false); + ScMarkData aMark(rSrcDoc.GetSheetLimits()); + aMark.SetMarkArea(aSrcRange); + rSrcDoc.CopyToClip(aClipParam, &aClipDoc, &aMark, false, false); + + // Create second document, paste B1 from clip + ScDocShell* pShell2 + = new ScDocShell(SfxModelFlags::EMBEDDED_OBJECT | SfxModelFlags::DISABLE_EMBEDDED_SCRIPTS + | SfxModelFlags::DISABLE_DOCUMENT_RECOVERY); + pShell2->DoInitNew(); + ScDocument& rDestDoc = pShell2->GetDocument(); + ScRange aDstRange(1, 0, 0); + ScMarkData aMark2(rDestDoc.GetSheetLimits()); + aMark2.SetMarkArea(aDstRange); + rDestDoc.CopyFromClip(aDstRange, aMark2, InsertDeleteFlags::ALL, nullptr, &aClipDoc); + + // save as XLSX + std::shared_ptr<utl::TempFile> pXPathFile + = ScBootstrapFixture::exportTo(&(*pShell2), FORMAT_XLSX); + + // check validation + xmlDocUniquePtr pDoc + = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/worksheets/sheet1.xml"); + CPPUNIT_ASSERT(pDoc); + assertXPathContent(pDoc, "/x:worksheet/x:dataValidations/x:dataValidation/x:formula1", "#REF!"); +} + +void ScExportTest2::testTdf115159() +{ + ScDocShellRef xShell = loadDoc(u"tdf115159.", FORMAT_XLSX); + CPPUNIT_ASSERT(xShell.is()); + ScDocShellRef xDocSh = saveAndReload(xShell.get(), FORMAT_XLSX); + CPPUNIT_ASSERT(xDocSh.is()); + xShell->DoClose(); + + xmlDocUniquePtr pDoc + = XPathHelper::parseExport2(*this, *xDocSh, m_xSFactory, "xl/workbook.xml", FORMAT_XLSX); + CPPUNIT_ASSERT(pDoc); + + //assert the existing OOXML built-in name is not duplicated + assertXPath(pDoc, "/x:workbook/x:definedNames/x:definedName", 1); + + xDocSh->DoClose(); +} + +void ScExportTest2::testTdf112567() +{ + // Set the system locale to Hungarian (a language with different range separator) + SvtSysLocaleOptions aOptions; + OUString sLocaleConfigString = aOptions.GetLanguageTag().getBcp47(); + aOptions.SetLocaleConfigString("hu-HU"); + aOptions.Commit(); + comphelper::ScopeGuard g([&aOptions, &sLocaleConfigString] { + aOptions.SetLocaleConfigString(sLocaleConfigString); + aOptions.Commit(); + }); + + ScDocShellRef xShell = loadDoc(u"tdf112567.", FORMAT_XLSX); + CPPUNIT_ASSERT(xShell.is()); + ScDocShellRef xDocSh = saveAndReload(xShell.get(), FORMAT_XLSX); + CPPUNIT_ASSERT(xDocSh.is()); + xShell->DoClose(); + + xmlDocUniquePtr pDoc + = XPathHelper::parseExport2(*this, *xDocSh, m_xSFactory, "xl/workbook.xml", FORMAT_XLSX); + CPPUNIT_ASSERT(pDoc); + + //assert the existing OOXML built-in name is not duplicated + assertXPath(pDoc, "/x:workbook/x:definedNames/x:definedName", 1); + + xDocSh->DoClose(); +} + +void ScExportTest2::testTdf112567b() +{ + // Set the system locale to Hungarian (a language with different range separator) + SvtSysLocaleOptions aOptions; + OUString sLocaleConfigString = aOptions.GetLanguageTag().getBcp47(); + aOptions.SetLocaleConfigString("hu-HU"); + aOptions.Commit(); + comphelper::ScopeGuard g([&aOptions, &sLocaleConfigString] { + aOptions.SetLocaleConfigString(sLocaleConfigString); + aOptions.Commit(); + }); + + ScDocShellRef xShell = loadDoc(u"tdf112567.", FORMAT_ODS); + CPPUNIT_ASSERT(xShell.is()); + ScDocShellRef xDocSh = saveAndReload(xShell.get(), FORMAT_XLSX); + CPPUNIT_ASSERT(xDocSh.is()); + xShell->DoClose(); + + xmlDocUniquePtr pDoc + = XPathHelper::parseExport2(*this, *xDocSh, m_xSFactory, "xl/workbook.xml", FORMAT_XLSX); + CPPUNIT_ASSERT(pDoc); + + //assert the existing OOXML built-in name is not duplicated + assertXPath(pDoc, "/x:workbook/x:definedNames/x:definedName", 1); + + //and it contains "," instead of ";" + assertXPathContent(pDoc, "/x:workbook/x:definedNames/x:definedName[1]", + "Sheet1!$A:$A,Sheet1!$1:$1"); + + xDocSh->DoClose(); +} + +void ScExportTest2::testTdf123645XLSX() +{ + ScDocShellRef xDocSh = loadDoc(u"chart_hyperlink.", FORMAT_XLSX); + CPPUNIT_ASSERT(xDocSh.is()); + std::shared_ptr<utl::TempFile> pXPathFile + = ScBootstrapFixture::exportTo(&(*xDocSh), FORMAT_XLSX); + + xmlDocUniquePtr pDoc + = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/drawings/drawing1.xml"); + CPPUNIT_ASSERT(pDoc); + assertXPath(pDoc, + "/xdr:wsDr/xdr:twoCellAnchor[1]/xdr:graphicFrame/xdr:nvGraphicFramePr/xdr:cNvPr/" + "a:hlinkClick", + 1); + assertXPath(pDoc, + "/xdr:wsDr/xdr:twoCellAnchor[2]/xdr:graphicFrame/xdr:nvGraphicFramePr/xdr:cNvPr/" + "a:hlinkClick", + 1); + assertXPath(pDoc, + "/xdr:wsDr/xdr:twoCellAnchor[3]/xdr:graphicFrame/xdr:nvGraphicFramePr/xdr:cNvPr/" + "a:hlinkClick", + 1); + + xmlDocUniquePtr pXmlRels + = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/drawings/_rels/drawing1.xml.rels"); + CPPUNIT_ASSERT(pXmlRels); + assertXPath(pXmlRels, "/r:Relationships/r:Relationship[@Id='rId1']", "TargetMode", "External"); + assertXPathNoAttribute(pXmlRels, "/r:Relationships/r:Relationship[@Id='rId3']", "TargetMode"); + assertXPath(pXmlRels, "/r:Relationships/r:Relationship[@Id='rId5']", "TargetMode", "External"); + assertXPath(pXmlRels, "/r:Relationships/r:Relationship[@Id='rId1']", "Target", + "file:///C:/TEMP/test.xlsx"); + assertXPath(pXmlRels, "/r:Relationships/r:Relationship[@Id='rId3']", "Target", "#Sheet2!A1"); + assertXPath(pXmlRels, "/r:Relationships/r:Relationship[@Id='rId5']", "Target", + "https://bugs.documentfoundation.org/show_bug.cgi?id=123645"); + + xDocSh->DoClose(); +} + +void ScExportTest2::testTdf125173XLSX() +{ + ScDocShellRef xDocSh = loadDoc(u"text_box_hyperlink.", FORMAT_ODS); + CPPUNIT_ASSERT(xDocSh.is()); + std::shared_ptr<utl::TempFile> pXPathFile + = ScBootstrapFixture::exportTo(&(*xDocSh), FORMAT_XLSX); + + xmlDocUniquePtr pDoc + = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/drawings/drawing1.xml"); + CPPUNIT_ASSERT(pDoc); + assertXPath(pDoc, "/xdr:wsDr/xdr:twoCellAnchor/xdr:sp/xdr:nvSpPr/xdr:cNvPr/a:hlinkClick", 1); + + xmlDocUniquePtr pXmlRels + = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/drawings/_rels/drawing1.xml.rels"); + CPPUNIT_ASSERT(pXmlRels); + assertXPath(pXmlRels, "/r:Relationships/r:Relationship[@Id='rId1']", "Target", + "http://www.google.com/"); + assertXPath(pXmlRels, "/r:Relationships/r:Relationship[@Id='rId1']", "TargetMode", "External"); + + xDocSh->DoClose(); +} + +void ScExportTest2::testTdf79972XLSX() +{ + ScDocShellRef xDocSh = loadDoc(u"tdf79972.", FORMAT_XLSX); + CPPUNIT_ASSERT(xDocSh.is()); + std::shared_ptr<utl::TempFile> pXPathFile + = ScBootstrapFixture::exportTo(&(*xDocSh), FORMAT_XLSX); + + xmlDocUniquePtr pDoc + = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/worksheets/sheet1.xml"); + CPPUNIT_ASSERT(pDoc); + assertXPath(pDoc, "/x:worksheet/x:hyperlinks/x:hyperlink", "ref", "A1"); + + xmlDocUniquePtr pXmlRels + = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/worksheets/_rels/sheet1.xml.rels"); + CPPUNIT_ASSERT(pXmlRels); + assertXPath(pXmlRels, "/r:Relationships/r:Relationship", "Target", + "https://bugs.documentfoundation.org/show_bug.cgi?id=79972"); + assertXPath(pXmlRels, "/r:Relationships/r:Relationship", "TargetMode", "External"); + + xDocSh->DoClose(); +} + +void ScExportTest2::testTdf126024XLSX() +{ + ScDocShellRef xDocSh = loadDoc(u"hyperlink_formula.", FORMAT_XLSX); + CPPUNIT_ASSERT(xDocSh.is()); + std::shared_ptr<utl::TempFile> pXPathFile + = ScBootstrapFixture::exportTo(&(*xDocSh), FORMAT_XLSX); + + xmlDocUniquePtr pDoc + = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/worksheets/sheet1.xml"); + CPPUNIT_ASSERT(pDoc); + assertXPath(pDoc, "/x:worksheet/x:hyperlinks/x:hyperlink", "ref", "A2"); + + xmlDocUniquePtr pXmlRels + = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/worksheets/_rels/sheet1.xml.rels"); + CPPUNIT_ASSERT(pXmlRels); + assertXPath(pXmlRels, "/r:Relationships/r:Relationship", "Target", + "https://bugs.documentfoundation.org/"); + assertXPath(pXmlRels, "/r:Relationships/r:Relationship", "TargetMode", "External"); + + xDocSh->DoClose(); +} + +void ScExportTest2::testTdf126177XLSX() +{ + ScDocShellRef xDocSh = loadDoc(u"hyperlink_export.", FORMAT_XLSX); + CPPUNIT_ASSERT(xDocSh.is()); + std::shared_ptr<utl::TempFile> pXPathFile + = ScBootstrapFixture::exportTo(&(*xDocSh), FORMAT_XLSX); + + xmlDocUniquePtr pDoc + = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/worksheets/sheet1.xml"); + CPPUNIT_ASSERT(pDoc); + assertXPath(pDoc, "/x:worksheet/x:hyperlinks/x:hyperlink", "location", "Munka1!A5"); + + xmlDocUniquePtr pXmlRels + = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/worksheets/_rels/sheet1.xml.rels"); + CPPUNIT_ASSERT(pXmlRels); + OUString aTarget = getXPath(pXmlRels, "/r:Relationships/r:Relationship", "Target"); + CPPUNIT_ASSERT(aTarget.endsWith("test.xlsx")); + assertXPath(pXmlRels, "/r:Relationships/r:Relationship", "TargetMode", "External"); + + xDocSh->DoClose(); +} + +void ScExportTest2::testCommentTextVAlignment() +{ + // Testing comment text alignments. + ScDocShellRef xShell = loadDoc(u"CommentTextVAlign.", FORMAT_ODS); + CPPUNIT_ASSERT(xShell.is()); + + std::shared_ptr<utl::TempFile> pXPathFile + = ScBootstrapFixture::exportTo(&(*xShell), FORMAT_XLSX); + + xmlDocUniquePtr pVmlDrawing + = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/drawings/vmlDrawing1.vml"); + CPPUNIT_ASSERT(pVmlDrawing); + + assertXPathContent(pVmlDrawing, "/xml/v:shape/xx:ClientData/xx:TextVAlign", "Center"); + + xShell->DoClose(); +} + +void ScExportTest2::testCommentTextHAlignment() +{ + // Testing comment text alignments. + ScDocShellRef xShell = loadDoc(u"CommentTextHAlign.", FORMAT_ODS); + CPPUNIT_ASSERT(xShell.is()); + + std::shared_ptr<utl::TempFile> pXPathFile + = ScBootstrapFixture::exportTo(&(*xShell), FORMAT_XLSX); + + xmlDocUniquePtr pVmlDrawing + = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/drawings/vmlDrawing1.vml"); + CPPUNIT_ASSERT(pVmlDrawing); + + assertXPathContent(pVmlDrawing, "/xml/v:shape/xx:ClientData/xx:TextHAlign", "Center"); + + xShell->DoClose(); +} + +void ScExportTest2::testRotatedImageODS() +{ + // Error was, that the length values in shapes were not + // written in the given unit into the file. + css::uno::Reference<css::sheet::XGlobalSheetSettings> xGlobalSheetSettings + = css::sheet::GlobalSheetSettings::create(comphelper::getProcessComponentContext()); + xGlobalSheetSettings->setMetric(static_cast<sal_Int16>(FieldUnit::MM)); + + ScDocShellRef xDocSh = loadDoc(u"tdf103092_RotatedImage.", FORMAT_ODS, true); + CPPUNIT_ASSERT(xDocSh.is()); + + std::shared_ptr<utl::TempFile> pTemp = saveAs(xDocSh.get(), FORMAT_ODS); + CPPUNIT_ASSERT(pTemp); + xmlDocUniquePtr pXmlDoc = XPathHelper::parseExport(pTemp, m_xSFactory, "content.xml"); + CPPUNIT_ASSERT(pXmlDoc); + + const OUString sTransform = getXPath(pXmlDoc, + "/office:document-content/office:body/office:spreadsheet/" + "table:table/table:shapes/draw:frame", + "transform"); + // Attribute transform has the structure skew (...) rotate (...) translate (x y) + // parts are separated by blank + OUString sTranslate(sTransform.copy(sTransform.lastIndexOf('('))); + sTranslate = sTranslate.copy(1, sTranslate.getLength() - 2); // remove '(' and ')' + const OUString sX(sTranslate.getToken(0, ' ')); + const OUString sY(sTranslate.getToken(1, ' ')); + CPPUNIT_ASSERT(sX.endsWith("mm")); + CPPUNIT_ASSERT(sY.endsWith("mm")); + + xDocSh->DoClose(); +} + +void ScExportTest2::testTdf128976() +{ + ScDocShellRef xShell = loadDoc(u"tdf128976.", FORMAT_XLS); + CPPUNIT_ASSERT(xShell.is()); + + ScDocShellRef xDocSh = saveAndReload(xShell.get(), FORMAT_XLS); + xShell->DoClose(); + CPPUNIT_ASSERT(xDocSh.is()); + + ScDocument& rDoc = xDocSh->GetDocument(); + + // Trying to save very small fractional default column width to XLS (where only integer values + // between 0 and 255 are allowed as default) resulted in negative (-1) value after correction, + // and was written as 65535 (invalid default width). As the result, all columns had large width + // when reopened: 28415 (and Excel warned about invalid format). + const sal_uInt16 nColumn0Width = rDoc.GetColWidth(SCCOL(0), SCTAB(0), false); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(45), nColumn0Width); + + xDocSh->DoClose(); +} + +void ScExportTest2::testTdf120502() +{ + // Create an empty worksheet; resize last column on its first sheet; export to XLSX, and check + // that the last exported column number is correct + css::uno::Reference<css::frame::XDesktop2> xDesktop + = css::frame::Desktop::create(comphelper::getProcessComponentContext()); + CPPUNIT_ASSERT(xDesktop); + + css::uno::Sequence<css::beans::PropertyValue> args(1); + args[0].Name = "Hidden"; + args[0].Value <<= true; + + css::uno::Reference<css::lang::XComponent> xComponent + = xDesktop->loadComponentFromURL("private:factory/scalc", "_blank", 0, args); + CPPUNIT_ASSERT(xComponent); + + // Get the document model + SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(xComponent); + CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell); + + ScDocShellRef xShell = dynamic_cast<ScDocShell*>(pFoundShell); + CPPUNIT_ASSERT(xShell); + + ScDocument& rDoc = xShell->GetDocument(); + const SCCOL nMaxCol = rDoc.MaxCol(); // 0-based + + const auto nOldWidth = rDoc.GetColWidth(nMaxCol, 0); + rDoc.SetColWidth(nMaxCol, 0, nOldWidth + 100); + + std::shared_ptr<utl::TempFile> pXPathFile + = ScBootstrapFixture::exportTo(&(*xShell), FORMAT_XLSX); + xShell->DoClose(); + xmlDocUniquePtr pSheet1 + = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/worksheets/sheet1.xml"); + CPPUNIT_ASSERT(pSheet1); + + // This was 1025 when nMaxCol+1 was 1024 + assertXPath(pSheet1, "/x:worksheet/x:cols/x:col", "max", OUString::number(nMaxCol + 1)); +} + +void ScExportTest2::testTdf131372() +{ + ScDocShellRef xShell = loadDoc(u"tdf131372.", FORMAT_ODS); + CPPUNIT_ASSERT(xShell); + + auto pXPathFile = ScBootstrapFixture::exportTo(&(*xShell), FORMAT_XLSX); + + xmlDocUniquePtr pSheet + = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/worksheets/sheet1.xml"); + CPPUNIT_ASSERT(pSheet); + + assertXPathContent(pSheet, "/x:worksheet/x:sheetData/x:row/x:c[1]/x:f", "NA()"); + assertXPathContent(pSheet, "/x:worksheet/x:sheetData/x:row/x:c[2]/x:f", "#N/A"); + + xShell->DoClose(); +} +void ScExportTest2::testTdf81470() +{ + ScDocShellRef xShell = loadDoc(u"tdf81470.", FORMAT_XLS); + CPPUNIT_ASSERT(xShell); + + //without the fix in place, it would have crashed at export time + auto pXPathFile = ScBootstrapFixture::exportTo(&(*xShell), FORMAT_XLSX); + + //also check revisions are exported + xmlDocUniquePtr pHeaders + = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/revisions/revisionHeaders.xml"); + CPPUNIT_ASSERT(pHeaders); + + assertXPath(pHeaders, "/x:headers/x:header[1]", "dateTime", "2014-07-11T13:46:00.000000000Z"); + assertXPath(pHeaders, "/x:headers/x:header[1]", "userName", "Kohei Yoshida"); + assertXPath(pHeaders, "/x:headers/x:header[2]", "dateTime", "2014-07-11T18:38:00.000000000Z"); + assertXPath(pHeaders, "/x:headers/x:header[2]", "userName", "Kohei Yoshida"); + assertXPath(pHeaders, "/x:headers/x:header[3]", "dateTime", "2014-07-11T18:43:00.000000000Z"); + assertXPath(pHeaders, "/x:headers/x:header[3]", "userName", "Kohei Yoshida"); + + xShell->DoClose(); +} + +void ScExportTest2::testTdf122331() +{ + ScDocShellRef xShell = loadDoc(u"tdf122331.", FORMAT_ODS); + CPPUNIT_ASSERT(xShell); + + auto pXPathFile = ScBootstrapFixture::exportTo(&(*xShell), FORMAT_XLSX); + + xmlDocUniquePtr pSheet + = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/worksheets/sheet1.xml"); + CPPUNIT_ASSERT(pSheet); + + assertXPath(pSheet, "/x:worksheet/x:sheetPr", "filterMode", "true"); + assertXPath(pSheet, "/x:worksheet/x:autoFilter", "ref", "A1:B761"); + assertXPath(pSheet, "/x:worksheet/x:autoFilter/x:filterColumn", "colId", "1"); + + xShell->DoClose(); +} + +void ScExportTest2::testTdf83779() +{ + // Roundtripping TRUE/FALSE constants (not functions) must convert them to functions + ScDocShellRef xShell = loadDoc(u"tdf83779.", FORMAT_XLSX); + CPPUNIT_ASSERT(xShell); + + auto pXPathFile = ScBootstrapFixture::exportTo(&(*xShell), FORMAT_XLSX); + + xmlDocUniquePtr pVmlDrawing + = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/worksheets/sheet1.xml"); + CPPUNIT_ASSERT(pVmlDrawing); + + assertXPathContent(pVmlDrawing, "/x:worksheet/x:sheetData/x:row[1]/x:c/x:f", "FALSE()"); + assertXPathContent(pVmlDrawing, "/x:worksheet/x:sheetData/x:row[2]/x:c/x:f", "TRUE()"); + + xShell->DoClose(); +} + +void ScExportTest2::testTdf121716_ExportEvenHeaderFooterXLSX() +{ + // Header and footer on even pages should be exported properly + // If there are separate odd/even header, but only 1 footer for all pages (this is possible only in LibreOffice) + // then the footer will be duplicated to have the same footer separately for even/odd pages + + ScDocShellRef xShell = loadDoc(u"tdf121716_EvenHeaderFooter.", FORMAT_ODS); + CPPUNIT_ASSERT(xShell.is()); + + ScDocShellRef xDocSh = saveAndReload(&(*xShell), FORMAT_XLSX); + CPPUNIT_ASSERT(xDocSh.is()); + + std::shared_ptr<utl::TempFile> pXPathFile + = ScBootstrapFixture::exportTo(&(*xDocSh), FORMAT_XLSX); + xmlDocUniquePtr pDoc + = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/worksheets/sheet1.xml"); + CPPUNIT_ASSERT(pDoc); + + assertXPath(pDoc, "/x:worksheet/x:headerFooter", "differentOddEven", "true"); + assertXPathContent(pDoc, "/x:worksheet/x:headerFooter/x:oddHeader", + "&Lodd/right&Cpage&Rheader"); + assertXPathContent(pDoc, "/x:worksheet/x:headerFooter/x:oddFooter", "&Lboth&C&12page&Rfooter"); + assertXPathContent(pDoc, "/x:worksheet/x:headerFooter/x:evenHeader", + "&Lpage&Cheader&Reven/left"); + assertXPathContent(pDoc, "/x:worksheet/x:headerFooter/x:evenFooter", "&Lboth&C&12page&Rfooter"); + + pDoc = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/worksheets/sheet2.xml"); + CPPUNIT_ASSERT(pDoc); + + assertXPath(pDoc, "/x:worksheet/x:headerFooter", "differentOddEven", "true"); + assertXPathContent(pDoc, "/x:worksheet/x:headerFooter/x:oddHeader", "&Coddh"); + assertXPathContent(pDoc, "/x:worksheet/x:headerFooter/x:oddFooter", "&Coddf"); + assertXPathContent(pDoc, "/x:worksheet/x:headerFooter/x:evenHeader", "&Cevenh"); + assertXPathContent(pDoc, "/x:worksheet/x:headerFooter/x:evenFooter", "&Levenf"); + + xDocSh->DoClose(); +} + +void ScExportTest2::testTdf134459_HeaderFooterColorXLSX() +{ + // Colors in header and footer should be exported, and imported properly + ScDocShellRef xShell = loadDoc(u"tdf134459_HeaderFooterColor.", FORMAT_XLSX); + CPPUNIT_ASSERT(xShell.is()); + + ScDocShellRef xDocSh = saveAndReload(&(*xShell), FORMAT_XLSX); + CPPUNIT_ASSERT(xDocSh.is()); + + xmlDocUniquePtr pDoc = XPathHelper::parseExport2(*this, *xDocSh, m_xSFactory, + "xl/worksheets/sheet1.xml", FORMAT_XLSX); + CPPUNIT_ASSERT(pDoc); + + assertXPathContent(pDoc, "/x:worksheet/x:headerFooter/x:oddHeader", + "&L&Kc06040l&C&K4c3789c&Rr"); + assertXPathContent(pDoc, "/x:worksheet/x:headerFooter/x:oddFooter", + "&Ll&C&K64cf5fc&R&Kcd15aar"); + + xDocSh->DoClose(); +} + +void ScExportTest2::testTdf134817_HeaderFooterTextWith2SectionXLSX() +{ + // Header/footer text with multiple selection should be exported, and imported properly + ScDocShellRef xShell = loadDoc(u"tdf134817_HeaderFooterTextWith2Section.", FORMAT_XLSX); + CPPUNIT_ASSERT(xShell.is()); + + ScDocShellRef xDocSh = saveAndReload(&(*xShell), FORMAT_XLSX); + CPPUNIT_ASSERT(xDocSh.is()); + + xmlDocUniquePtr pDoc = XPathHelper::parseExport2(*this, *xDocSh, m_xSFactory, + "xl/worksheets/sheet1.xml", FORMAT_XLSX); + CPPUNIT_ASSERT(pDoc); + + assertXPathContent(pDoc, "/x:worksheet/x:headerFooter/x:oddHeader", + "&L&\"Abadi,Regular\"&11aaa&\"Bembo,Regular\"&20bbb"); + assertXPathContent(pDoc, "/x:worksheet/x:headerFooter/x:oddFooter", + "&R&\"Cambria,Regular\"&14camb&\"Dante,Regular\"&18dant"); + + xDocSh->DoClose(); +} + +void ScExportTest2::testTdf121718_UseFirstPageNumberXLSX() +{ + // If "First page number" is not checked then useFirstPageNumb, and firstPageNumber should not be exported. + ScDocShellRef xShell = loadDoc(u"tdf121718_UseFirstPageNumber.", FORMAT_ODS); + CPPUNIT_ASSERT(xShell.is()); + + ScDocShellRef xDocSh = saveAndReload(&(*xShell), FORMAT_XLSX); + CPPUNIT_ASSERT(xDocSh.is()); + + std::shared_ptr<utl::TempFile> pXPathFile + = ScBootstrapFixture::exportTo(&(*xDocSh), FORMAT_XLSX); + xmlDocUniquePtr pDoc + = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/worksheets/sheet1.xml"); + CPPUNIT_ASSERT(pDoc); + + assertXPath(pDoc, "/x:worksheet/x:pageSetup", "useFirstPageNumber", "true"); + assertXPath(pDoc, "/x:worksheet/x:pageSetup", "firstPageNumber", "10"); + + pDoc = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/worksheets/sheet2.xml"); + CPPUNIT_ASSERT(pDoc); + + assertXPathNoAttribute(pDoc, "/x:worksheet/x:pageSetup", "useFirstPageNumber"); + assertXPathNoAttribute(pDoc, "/x:worksheet/x:pageSetup", "firstPageNumber"); + + xDocSh->DoClose(); +} + +void ScExportTest2::testHeaderFontStyleXLSX() +{ + ScDocShellRef xShell = loadDoc(u"tdf134826.", FORMAT_XLSX); + CPPUNIT_ASSERT(xShell.is()); + + ScDocument& rDoc = xShell->GetDocument(); + SfxStyleSheetBase* pStyleSheet + = rDoc.GetStyleSheetPool()->Find(rDoc.GetPageStyle(0), SfxStyleFamily::Page); + const SfxItemSet& rItemSet = pStyleSheet->GetItemSet(); + const ScPageHFItem& rHFItem = rItemSet.Get(ATTR_PAGE_HEADERRIGHT); + const EditTextObject* pTextObj = rHFItem.GetLeftArea(); + + std::vector<EECharAttrib> rLst; + + // first line is bold. + pTextObj->GetCharAttribs(0, rLst); + bool bHasBold = std::any_of(rLst.begin(), rLst.end(), [](const EECharAttrib& rAttrib) { + return rAttrib.pAttr->Which() == EE_CHAR_WEIGHT + && static_cast<const SvxWeightItem&>(*rAttrib.pAttr).GetWeight() == WEIGHT_BOLD; + }); + CPPUNIT_ASSERT_MESSAGE("First line should be bold.", bHasBold); + + // second line is italic. + pTextObj->GetCharAttribs(1, rLst); + bool bHasItalic = std::any_of(rLst.begin(), rLst.end(), [](const EECharAttrib& rAttrib) { + return rAttrib.pAttr->Which() == EE_CHAR_ITALIC + && static_cast<const SvxPostureItem&>(*rAttrib.pAttr).GetPosture() == ITALIC_NORMAL; + }); + CPPUNIT_ASSERT_MESSAGE("Second line should be italic.", bHasItalic); + + xShell->DoClose(); +} + +void ScExportTest2::testTdf135828_Shape_Rect() +{ + if (!IsDefaultDPI()) + return; + // tdf#135828 Check that the width and the height of rectangle of the shape is correct. + // tdf#123613 Check the positioning, and allow massive rounding errors because of the back and + // forth conversion between emu and hmm. + ScDocShellRef xShell = loadDoc(u"tdf135828_Shape_Rect.", FORMAT_XLSX); + CPPUNIT_ASSERT(xShell.is()); + + ScDocShellRef xDocSh = saveAndReload(&(*xShell), FORMAT_XLSX); + CPPUNIT_ASSERT(xDocSh.is()); + + std::shared_ptr<utl::TempFile> pXPathFile + = ScBootstrapFixture::exportTo(&(*xDocSh), FORMAT_XLSX); + + xmlDocUniquePtr pDrawing + = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/drawings/drawing1.xml"); + CPPUNIT_ASSERT(pDrawing); + + double nXPosOfTopleft + = getXPath(pDrawing, "/xdr:wsDr/xdr:twoCellAnchor/xdr:sp/xdr:spPr/a:xfrm/a:off", "x") + .toDouble(); + double nYPosOfTopleft + = getXPath(pDrawing, "/xdr:wsDr/xdr:twoCellAnchor/xdr:sp/xdr:spPr/a:xfrm/a:off", "y") + .toDouble(); + double nWidth + = getXPath(pDrawing, "/xdr:wsDr/xdr:twoCellAnchor/xdr:sp/xdr:spPr/a:xfrm/a:ext", "cx") + .toDouble(); + double nHeight + = getXPath(pDrawing, "/xdr:wsDr/xdr:twoCellAnchor/xdr:sp/xdr:spPr/a:xfrm/a:ext", "cy") + .toDouble(); + + CPPUNIT_ASSERT_DOUBLES_EQUAL(854640, nXPosOfTopleft, 10000); + CPPUNIT_ASSERT_DOUBLES_EQUAL(-570600, nYPosOfTopleft, 10000); + CPPUNIT_ASSERT_DOUBLES_EQUAL(294840, nWidth, 10000); + CPPUNIT_ASSERT_DOUBLES_EQUAL(1988280, nHeight, 10000); +} + +void ScExportTest2::testTdf123353() +{ + ScDocShellRef xShell = loadDoc(u"tdf123353.", FORMAT_XLSX); + CPPUNIT_ASSERT(xShell.is()); + + ScDocShellRef xDocSh = saveAndReload(&(*xShell), FORMAT_XLSX); + CPPUNIT_ASSERT(xDocSh.is()); + + std::shared_ptr<utl::TempFile> pXPathFile + = ScBootstrapFixture::exportTo(&(*xDocSh), FORMAT_XLSX); + + xmlDocUniquePtr pDoc + = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/worksheets/sheet1.xml"); + CPPUNIT_ASSERT(pDoc); + + assertXPath(pDoc, "/x:worksheet/x:autoFilter/x:filterColumn/x:filters", "blank", "1"); + + xShell->DoClose(); +} + +void ScExportTest2::testTdf140098() +{ + ScDocShellRef xShell = loadDoc(u"tdf140098.", FORMAT_ODS); + CPPUNIT_ASSERT(xShell.is()); + + ScDocShellRef xDocSh = saveAndReload(&(*xShell), FORMAT_XLSX); + CPPUNIT_ASSERT(xDocSh.is()); + + std::shared_ptr<utl::TempFile> pXPathFile + = ScBootstrapFixture::exportTo(&(*xDocSh), FORMAT_XLSX); + + xmlDocUniquePtr pDoc + = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/worksheets/sheet1.xml"); + CPPUNIT_ASSERT(pDoc); + + assertXPath(pDoc, "/x:worksheet/x:autoFilter/x:filterColumn/x:filters", "blank", "1"); + + xShell->DoClose(); +} + +void ScExportTest2::testTdf133688_precedents() +{ + // tdf#133688 Check that we do not export detective shapes. + ScDocShellRef xShell = loadDoc(u"tdf133688_dont_save_precedents_to_xlsx.", FORMAT_ODS); + CPPUNIT_ASSERT(xShell.is()); + + std::shared_ptr<utl::TempFile> pXPathFile + = ScBootstrapFixture::exportTo(&(*xShell), FORMAT_XLSX); + xmlDocUniquePtr pDrawing + = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/drawings/drawing1.xml"); + CPPUNIT_ASSERT(pDrawing); + + // We do not export any shapes. + assertXPath(pDrawing, "/xdr:wsDr/xdr:twoCellAnchor[1]", 0); +} + +void ScExportTest2::testTdf91251_missingOverflowRoundtrip() +{ + // tdf#91251 check whether textBox overflow property (horzOverflow and vertOverflow) is + // getting preserved after roundtrip + ScDocShellRef xShell = loadDoc(u"tdf91251_missingOverflowRoundtrip.", FORMAT_XLSX); + CPPUNIT_ASSERT(xShell.is()); + + ScDocShellRef xDocSh = saveAndReload(&(*xShell), FORMAT_XLSX); + CPPUNIT_ASSERT(xDocSh.is()); + + std::shared_ptr<utl::TempFile> pXPathFile + = ScBootstrapFixture::exportTo(&(*xDocSh), FORMAT_XLSX); + + xmlDocUniquePtr pDrawing + = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/drawings/drawing1.xml"); + CPPUNIT_ASSERT(pDrawing); + + assertXPath(pDrawing, "/xdr:wsDr/xdr:twoCellAnchor/xdr:sp/xdr:txBody/a:bodyPr", "horzOverflow", + "clip"); + assertXPath(pDrawing, "/xdr:wsDr/xdr:twoCellAnchor/xdr:sp/xdr:txBody/a:bodyPr", "horzOverflow", + "clip"); +} + +void ScExportTest2::testTdf137000_handle_upright() +{ + // tdf#106197 When exporting the "upright" attribute, we must set + // TextPreRotateAngle to 0. + // (Upright is an xml attribute of xdr:txBody/a:bodyPr. It is set when + // in a textbox menu we choose: do not rotate this element.) + ScDocShellRef xShell = loadDoc(u"tdf137000_export_upright.", FORMAT_XLSX); + CPPUNIT_ASSERT(xShell.is()); + + std::shared_ptr<utl::TempFile> pXPathFile + = ScBootstrapFixture::exportTo(&(*xShell), FORMAT_XLSX); + xmlDocUniquePtr pDrawing + = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/drawings/drawing1.xml"); + CPPUNIT_ASSERT(pDrawing); + + assertXPath(pDrawing, "/xdr:wsDr/xdr:twoCellAnchor/xdr:sp/xdr:txBody/a:bodyPr", "rot", + "-5400000"); +} + +void ScExportTest2::testTdf126305_DataValidatyErrorAlert() +{ + ScDocShellRef xShell = loadDoc(u"tdf126305.", FORMAT_ODS); + CPPUNIT_ASSERT(xShell.is()); + + ScDocShellRef xDocSh = saveAndReload(&(*xShell), FORMAT_XLSX); + CPPUNIT_ASSERT(xDocSh.is()); + + std::shared_ptr<utl::TempFile> pXPathFile + = ScBootstrapFixture::exportTo(&(*xDocSh), FORMAT_XLSX); + xmlDocUniquePtr pDoc + = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/worksheets/sheet1.xml"); + CPPUNIT_ASSERT(pDoc); + + assertXPath(pDoc, "/x:worksheet/x:dataValidations/x:dataValidation[1]", "errorStyle", "stop"); + assertXPath(pDoc, "/x:worksheet/x:dataValidations/x:dataValidation[2]", "errorStyle", + "warning"); + assertXPath(pDoc, "/x:worksheet/x:dataValidations/x:dataValidation[3]", "errorStyle", + "information"); + + xDocSh->DoClose(); +} + +void ScExportTest2::testTdf76047_externalLink() +{ + ScDocShellRef pShell = loadDoc(u"tdf76047_externalLink.", FORMAT_XLSX); + CPPUNIT_ASSERT(pShell.is()); + + // load data from external links. (tdf76047_externalLinkSource.ods) + // that file has to be in the same directory as tdf76047_externalLink.xlsx + pShell->ReloadAllLinks(); + ScDocument& rDoc = pShell->GetDocument(); + + // compare the data loaded from external links with the expected result stored in the test file + for (int nCol = 1; nCol <= 5; nCol++) + { + for (int nRow = 3; nRow <= 5; nRow++) + { + OUString aStr1 = rDoc.GetString(ScAddress(nCol, nRow, 0)); + OUString aStr2 = rDoc.GetString(ScAddress(nCol, nRow + 5, 0)); + OUString aStr3 = rDoc.GetString(ScAddress(nCol, nRow + 11, 0)); + + CPPUNIT_ASSERT_EQUAL(aStr1, aStr3); + CPPUNIT_ASSERT_EQUAL(aStr2, aStr3); + } + } +} + +void ScExportTest2::testTdf87973_externalLinkSkipUnuseds() +{ + ScDocShellRef pShell = loadDoc(u"tdf87973_externalLinkSkipUnuseds.", FORMAT_ODS); + CPPUNIT_ASSERT(pShell.is()); + + // try to load data from external link: tdf132105_external.ods + // that file has to be in the same directory as tdf87973_externalLinkSkipUnuseds.ods + pShell->ReloadAllLinks(); + ScDocument& rDoc = pShell->GetDocument(); + + // change external link to: 87973_externalSource.ods + OUString aFormula, aFormula2; + rDoc.GetFormula(3, 1, 0, aFormula); + auto nIdxOfFilename = aFormula.indexOf("tdf132105_external.ods"); + aFormula = aFormula.replaceAt(nIdxOfFilename, 22, "87973_externalSource.ods"); + auto nIdxOfFile = aFormula.indexOf("file"); + + // saveAndReload save the file to a temporary directory + // the link must be changed to point to that directory + utl::TempFile aTempFile; + auto aTempFilename = aTempFile.GetURL(); + auto nIdxOfTmpFile = aTempFilename.lastIndexOf('/'); + aTempFilename = aTempFilename.copy(0, nIdxOfTmpFile + 1); + + aFormula = aFormula.replaceAt(nIdxOfFile, nIdxOfFilename - nIdxOfFile, aTempFilename); + rDoc.SetFormula(ScAddress(3, 1, 0), aFormula, formula::FormulaGrammar::GRAM_NATIVE_UI); + + // tdf#138832: test the same thing with singleref link + rDoc.GetFormula(3, 2, 0, aFormula); + nIdxOfFilename = aFormula.indexOf("tdf132105_external.ods"); + aFormula = aFormula.replaceAt(nIdxOfFilename, 22, "87973_externalSource.ods"); + nIdxOfFile = aFormula.indexOf("file"); + + aFormula = aFormula.replaceAt(nIdxOfFile, nIdxOfFilename - nIdxOfFile, aTempFilename); + rDoc.SetFormula(ScAddress(3, 2, 0), aFormula, formula::FormulaGrammar::GRAM_NATIVE_UI); + + // save and load back + ScDocShellRef pDocSh = saveAndReload(&(*pShell), FORMAT_XLSX); + CPPUNIT_ASSERT(pDocSh.is()); + + // check if the new filename is present in the link (and not replaced by '[2]') + ScDocument& rDoc2 = pDocSh->GetDocument(); + rDoc2.GetFormula(3, 1, 0, aFormula2); + CPPUNIT_ASSERT(aFormula2.indexOf("tdf132105_external.ods") < 0); + CPPUNIT_ASSERT(aFormula2.indexOf("87973_externalSource.ods") >= 0); + rDoc2.GetFormula(3, 2, 0, aFormula2); + CPPUNIT_ASSERT(aFormula2.indexOf("tdf132105_external.ods") < 0); + CPPUNIT_ASSERT(aFormula2.indexOf("87973_externalSource.ods") >= 0); + + pDocSh->DoClose(); +} + +void ScExportTest2::testTdf51022_lostPrintRange() +{ + ScDocShellRef pShell = loadDoc(u"tdf87973_externalLinkSkipUnuseds.", FORMAT_ODS); + CPPUNIT_ASSERT(pShell.is()); + + pShell->ReloadAllLinks(); + ScDocument& rDoc = pShell->GetDocument(); + + //Add print ranges + ScRange aRange1(1, 2, 0, 3, 4, 0); + ScRange aRange2(1, 6, 0, 3, 7, 0); + rDoc.AddPrintRange(0, aRange1); + rDoc.AddPrintRange(0, aRange2); + + // save and load back + ScDocShellRef pDocSh = saveAndReload(&(*pShell), FORMAT_ODS); + CPPUNIT_ASSERT(pDocSh.is()); + + // check if the same print ranges are present + ScDocument& rDoc2 = pDocSh->GetDocument(); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(2), rDoc2.GetPrintRangeCount(0)); + CPPUNIT_ASSERT_EQUAL(aRange1, *rDoc2.GetPrintRange(0, 0)); + CPPUNIT_ASSERT_EQUAL(aRange2, *rDoc2.GetPrintRange(0, 1)); + + pDocSh->DoClose(); +} + +void ScExportTest2::testTdf138741_externalLinkSkipUnusedsCrash() +{ + ScDocShellRef xShell = loadDoc(u"tdf138741_externalLinkSkipUnusedsCrash.", FORMAT_XLSX); + CPPUNIT_ASSERT(xShell); + + //without the fix in place, it would have crashed at export time + ScBootstrapFixture::exportTo(&(*xShell), FORMAT_XLSX); + + xShell->DoClose(); +} + +void ScExportTest2::testTdf138824_linkToParentDirectory() +{ + ScDocShellRef xShell = loadDoc(u"childDir/tdf138824_linkToParentDirectory.", FORMAT_ODS); + CPPUNIT_ASSERT(xShell.is()); + + ScDocument& rDoc = xShell->GetDocument(); + + // saveAndReload save the file to a temporary directory + // the link must be changed to point to that parent directory + utl::TempFile aTempFile; + auto aTempFilename = aTempFile.GetURL(); + auto nIdxOfTmpFile = aTempFilename.lastIndexOf('/'); + nIdxOfTmpFile = aTempFilename.lastIndexOf('/', nIdxOfTmpFile); + aTempFilename = aTempFilename.copy(0, nIdxOfTmpFile + 1); + + // change external link to tmp directory + OUString aFormula; + rDoc.GetFormula(3, 1, 0, aFormula); + auto nIdxOfFilename = aFormula.indexOf("tdf138824_externalSource.ods"); + auto nIdxOfFile = aFormula.indexOf("file"); + + aFormula = aFormula.replaceAt(nIdxOfFile, nIdxOfFilename - nIdxOfFile, aTempFilename); + rDoc.SetFormula(ScAddress(3, 1, 0), aFormula, formula::FormulaGrammar::GRAM_NATIVE_UI); + + ScDocShellRef xDocSh = saveAndReload(&(*xShell), FORMAT_XLSX); + CPPUNIT_ASSERT(xDocSh.is()); + + std::shared_ptr<utl::TempFile> pXPathFile + = ScBootstrapFixture::exportTo(&(*xDocSh), FORMAT_XLSX); + xmlDocUniquePtr pDoc = XPathHelper::parseExport( + pXPathFile, m_xSFactory, "xl/externalLinks/_rels/externalLink1.xml.rels"); + CPPUNIT_ASSERT(pDoc); + + // test also the Linux specific bug tdf#121472 + assertXPath(pDoc, "/r:Relationships/r:Relationship", "Target", + "../tdf138824_externalSource.ods"); + + xDocSh->DoClose(); +} + +void ScExportTest2::testTdf129969() +{ + ScDocShellRef xShell = loadDoc(u"external_hyperlink.", FORMAT_ODS); + CPPUNIT_ASSERT(xShell.is()); + + ScDocShellRef xDocSh = saveAndReload(&(*xShell), FORMAT_XLSX); + CPPUNIT_ASSERT(xDocSh.is()); + ScDocument& rDoc = xDocSh->GetDocument(); + ScAddress aPos(0, 0, 0); + const EditTextObject* pEditText = rDoc.GetEditText(aPos); + const SvxFieldData* pData = pEditText->GetFieldData(0, 0, text::textfield::Type::URL); + const SvxURLField* pURLData = static_cast<const SvxURLField*>(pData); + CPPUNIT_ASSERT(pURLData->GetURL().endsWith("/%23folder/test.ods#Sheet2.B10")); + + xDocSh->DoClose(); +} + +void ScExportTest2::testTdf84874() +{ + ScDocShellRef xShell = loadDoc(u"tdf84874.", FORMAT_ODS); + CPPUNIT_ASSERT(xShell.is()); + + ScDocShellRef xDocSh = saveAndReload(xShell.get(), FORMAT_XLSX); + xShell->DoClose(); + CPPUNIT_ASSERT(xDocSh.is()); + + ScDocument& rDoc = xDocSh->GetDocument(); + + const ScValidationData* pData = rDoc.GetValidationEntry(1); + OUString aTitle, aText; + pData->GetInput(aTitle, aText); + sal_uInt32 nPromptTitleLen = aTitle.getLength(); + sal_uInt32 nPromptTextLen = aText.getLength(); + + CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt32>(255), nPromptTitleLen); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt32>(255), nPromptTextLen); + + ScValidErrorStyle eErrStyle = SC_VALERR_STOP; + pData->GetErrMsg(aTitle, aText, eErrStyle); + sal_uInt32 nErrorTitleLen = aTitle.getLength(); + sal_uInt32 nErrorTextLen = aText.getLength(); + + CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt32>(255), nErrorTitleLen); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt32>(255), nErrorTextLen); + + xDocSh->DoClose(); +} + +void ScExportTest2::testTdf136721_paper_size() +{ + ScDocShellRef xShell = loadDoc(u"tdf136721_letter_sized_paper.", FORMAT_XLSX); + CPPUNIT_ASSERT(xShell.is()); + + std::shared_ptr<utl::TempFile> pXPathFile + = ScBootstrapFixture::exportTo(&(*xShell), FORMAT_XLSX); + xmlDocUniquePtr pDoc + = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/worksheets/sheet1.xml"); + CPPUNIT_ASSERT(pDoc); + + assertXPath(pDoc, "/x:worksheet/x:pageSetup", "paperSize", "70"); +} + +void ScExportTest2::testTdf139258_rotated_image() +{ + // Check that the topleft position of the image is correct. + ScDocShellRef xShell = loadDoc(u"tdf139258_rotated_image.", FORMAT_ODS); + CPPUNIT_ASSERT(xShell.is()); + + std::shared_ptr<utl::TempFile> pXPathFile + = ScBootstrapFixture::exportTo(&(*xShell), FORMAT_XLSX); + + xmlDocUniquePtr pDrawing + = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/drawings/drawing1.xml"); + CPPUNIT_ASSERT(pDrawing); + + assertXPathContent(pDrawing, "/xdr:wsDr/xdr:twoCellAnchor/xdr:from/xdr:col", "1"); + assertXPathContent(pDrawing, "/xdr:wsDr/xdr:twoCellAnchor/xdr:from/xdr:row", "12"); + assertXPathContent(pDrawing, "/xdr:wsDr/xdr:twoCellAnchor/xdr:to/xdr:col", "6"); + assertXPathContent(pDrawing, "/xdr:wsDr/xdr:twoCellAnchor/xdr:to/xdr:row", "25"); +} + +ScDocShellRef ScExportTest2::loadDocAndSetupModelViewController(std::u16string_view rFileName, + sal_Int32 nFormat, bool bReadWrite) +{ + uno::Reference<frame::XDesktop2> xDesktop + = frame::Desktop::create(::comphelper::getProcessComponentContext()); + CPPUNIT_ASSERT(xDesktop.is()); + + // create a frame + Reference<frame::XFrame> xTargetFrame = xDesktop->findFrame("_blank", 0); + CPPUNIT_ASSERT(xTargetFrame.is()); + + // 1. Open the document + ScDocShellRef xDocSh = loadDoc(rFileName, nFormat, bReadWrite); + CPPUNIT_ASSERT_MESSAGE( + OString("Failed to load " + OUStringToOString(rFileName, RTL_TEXTENCODING_UTF8)).getStr(), + xDocSh.is()); + + uno::Reference<frame::XModel2> xModel2 = xDocSh->GetModel(); + CPPUNIT_ASSERT(xModel2.is()); + + Reference<frame::XController2> xController = xModel2->createDefaultViewController(xTargetFrame); + CPPUNIT_ASSERT(xController.is()); + + // introduce model/view/controller to each other + xController->attachModel(xModel2); + xModel2->connectController(xController); + xTargetFrame->setComponent(xController->getComponentWindow(), xController); + xController->attachFrame(xTargetFrame); + xModel2->setCurrentController(xController); + + return xDocSh; +} + +void ScExportTest2::testTdf126541_SheetVisibilityImportXlsx() +{ + // Import an ods file with 'Hide' global grid visibility setting. + ScDocShellRef xShell + = loadDocAndSetupModelViewController(u"tdf126541_GridOffGlobally.", FORMAT_ODS, true); + CPPUNIT_ASSERT(!xShell->GetDocument().GetViewOptions().GetOption(VOPT_GRID)); + + // Importing xlsx file should set the global grid visibility setting to 'Show' + // Sheet based grid line visibility setting should not overwrite the global setting. + xShell = loadDocAndSetupModelViewController(u"tdf126541_GridOff.", FORMAT_XLSX, true); + CPPUNIT_ASSERT(xShell->GetDocument().GetViewOptions().GetOption(VOPT_GRID)); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScExportTest2); + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/qa/unit/subsequent_filters-test.cxx b/sc/qa/unit/subsequent_filters-test.cxx index 0aed0e30c4b2..75ff20e23034 100644 --- a/sc/qa/unit/subsequent_filters-test.cxx +++ b/sc/qa/unit/subsequent_filters-test.cxx @@ -86,8 +86,6 @@ #include "helper/qahelper.hxx" #include "helper/shared_test_impl.hxx" -namespace com::sun::star::frame { class XModel; } - using namespace ::com::sun::star; using namespace ::com::sun::star::uno; @@ -168,7 +166,6 @@ public: void testTdf64401(); void testCondFormatParentXLSX(); void testColorScaleNumWithRefXLSX(); - void testCondFormatXLSB(); void testOrcusODSStyleInterface(); @@ -182,7 +179,6 @@ public: * by one. (fdo#76032) */ void testRowIndex1BasedXLSX(); - void testErrorOnExternalReferences(); //misc tests unrelated to the import filters void testPasswordNew(); @@ -207,62 +203,7 @@ public: void testRowHeightODS(); void testRichTextContentODS(); - void testMiscRowHeights(); - void testOptimalHeightReset(); - void testCustomNumFormatHybridCellODS(); - void testTdf121040(); - void testTdf118086(); - void testTdf118624(); - void testTdf124454(); - - void testPrintRangeODS(); - void testOutlineODS(); - - void testColumnStyleXLSX(); - void testColumnStyleAutoFilterXLSX(); - - void testSharedFormulaHorizontalXLS(); - void testSharedFormulaWrappedRefsXLS(); - void testSharedFormulaBIFF5(); - void testSharedFormulaXLSB(); - void testSharedFormulaXLS(); - void testSharedFormulaColumnLabelsODS(); - void testSharedFormulaColumnRowLabelsODS(); - void testExternalRefCacheXLSX(); - void testExternalRefCacheODS(); - void testHybridSharedStringODS(); - void testCopyMergedNumberFormats(); - void testVBAUserFunctionXLSM(); - void testEmbeddedImageXLS(); - void testTdf84762(); - void testTdf44076(); - void testEditEngStrikeThroughXLSX(); - void testRefStringXLSX(); - void testHiddenSheetsXLSX(); - void testRelFormulaValidationXLS(); - void testTdf130132(); - void testTdf133327(); - void testColumnStyle2XLSX(); - void testAutofilterXLSX(); - - void testBnc762542(); - - void testTdf136364(); - void testTdf103734(); - void testTdf126116(); - void testTdf98844(); - void testTdf100458(); - void testTdf118561(); - void testTdf125099(); - void testTdf134455(); - void testTdf119533(); - void testTdf127982(); - void testTdf109409(); - void testTdf132105(); - void testTdf131424(); - void testTdf100709XLSX(); - void testTdf97598XLSX(); - void testTdf110440XLSX(); + void testTdf122643(); void testTdf132278(); void testTdf130959(); @@ -272,53 +213,6 @@ public: void testTdf139782(); void testTdf129681(); void testTdf111974XLSM(); - void testTdf83672XLSX(); - - void testPageScalingXLSX(); - void testActiveXCheckboxXLSX(); - void testtdf120301_xmlSpaceParsingXLSX(); -#ifdef UNX - void testUnicodeFileNameGnumeric(); -#endif - void testCondFormatFormulaListenerXLSX(); - - void testMergedCellsXLSXML(); - void testBackgroundColorStandardXLSXML(); - void testTdf131536(); - void testTdf130583(); - void testTdf85617(); - void testTdf134234(); - void testTdf42481(); - void testNamedExpressionsXLSXML(); - void testEmptyRowsXLSXML(); - void testBorderDirectionsXLSXML(); - void testBorderColorsXLSXML(); - void testHiddenRowsColumnsXLSXML(); - void testColumnWidthRowHeightXLSXML(); - void testCharacterSetXLSXML(); - void testTdf137091(); - void testTdf62268(); - void testTdf137453(); - void testTdf112780(); - void testTdf72470(); - void testTdf35636(); - void testTdf98481(); - void testTdf115022(); - void testVBAMacroFunctionODS(); - void testAutoheight2Rows(); - void testXLSDefColWidth(); - void testPreviewMissingObjLink(); - void testShapeRotationImport(); - void testShapeDisplacementOnRotationImport(); - void testTextBoxBodyUpright(); - void testTextBoxBodyRotateAngle(); - void testTextLengthDataValidityXLSX(); - void testDeleteCircles(); - void testDrawCircleInMergeCells(); - void testDeleteCirclesInRowAndCol(); - void testTdf129940(); - void testTdf139763ShapeAnchor(); - void testAutofilterNamedRangesXLSX(); CPPUNIT_TEST_SUITE(ScFiltersTest); CPPUNIT_TEST(testCondFormatOperatorsSameRangeXLSX); @@ -389,7 +283,6 @@ public: CPPUNIT_TEST(testTdf64401); CPPUNIT_TEST(testCondFormatParentXLSX); CPPUNIT_TEST(testColorScaleNumWithRefXLSX); - CPPUNIT_TEST(testCondFormatXLSB); CPPUNIT_TEST(testOrcusODSStyleInterface); @@ -411,61 +304,6 @@ public: CPPUNIT_TEST(testPasswordOld); CPPUNIT_TEST(testPasswordNew); - CPPUNIT_TEST(testMiscRowHeights); - CPPUNIT_TEST(testOptimalHeightReset); - CPPUNIT_TEST(testCustomNumFormatHybridCellODS); - CPPUNIT_TEST(testTdf121040); - CPPUNIT_TEST(testTdf118086); - CPPUNIT_TEST(testTdf118624); - CPPUNIT_TEST(testTdf124454); - CPPUNIT_TEST(testPrintRangeODS); - CPPUNIT_TEST(testOutlineODS); - CPPUNIT_TEST(testColumnStyleXLSX); - CPPUNIT_TEST(testColumnStyleAutoFilterXLSX); - CPPUNIT_TEST(testSharedFormulaHorizontalXLS); - CPPUNIT_TEST(testSharedFormulaWrappedRefsXLS); - CPPUNIT_TEST(testSharedFormulaBIFF5); - CPPUNIT_TEST(testSharedFormulaXLSB); - CPPUNIT_TEST(testSharedFormulaXLS); - CPPUNIT_TEST(testSharedFormulaColumnLabelsODS); - CPPUNIT_TEST(testSharedFormulaColumnRowLabelsODS); - CPPUNIT_TEST(testExternalRefCacheXLSX); - CPPUNIT_TEST(testExternalRefCacheODS); - CPPUNIT_TEST(testHybridSharedStringODS); - CPPUNIT_TEST(testCopyMergedNumberFormats); - CPPUNIT_TEST(testVBAUserFunctionXLSM); - CPPUNIT_TEST(testEmbeddedImageXLS); - CPPUNIT_TEST(testErrorOnExternalReferences); - CPPUNIT_TEST(testTdf84762); - CPPUNIT_TEST(testTdf44076); - CPPUNIT_TEST(testEditEngStrikeThroughXLSX); - CPPUNIT_TEST(testRefStringXLSX); - CPPUNIT_TEST(testRelFormulaValidationXLS); - CPPUNIT_TEST(testTdf130132); - CPPUNIT_TEST(testTdf133327); - CPPUNIT_TEST(testColumnStyle2XLSX); - CPPUNIT_TEST(testAutofilterXLSX); - - CPPUNIT_TEST(testBnc762542); - - CPPUNIT_TEST(testHiddenSheetsXLSX); - - CPPUNIT_TEST(testTdf136364); - CPPUNIT_TEST(testTdf103734); - CPPUNIT_TEST(testTdf126116); - CPPUNIT_TEST(testTdf98844); - CPPUNIT_TEST(testTdf100458); - CPPUNIT_TEST(testTdf118561); - CPPUNIT_TEST(testTdf125099); - CPPUNIT_TEST(testTdf134455); - CPPUNIT_TEST(testTdf119533); - CPPUNIT_TEST(testTdf127982); - CPPUNIT_TEST(testTdf109409); - CPPUNIT_TEST(testTdf132105); - CPPUNIT_TEST(testTdf131424); - CPPUNIT_TEST(testTdf100709XLSX); - CPPUNIT_TEST(testTdf97598XLSX); - CPPUNIT_TEST(testTdf110440XLSX); CPPUNIT_TEST(testTdf122643); CPPUNIT_TEST(testTdf132278); CPPUNIT_TEST(testTdf130959); @@ -475,52 +313,6 @@ public: CPPUNIT_TEST(testTdf139782); CPPUNIT_TEST(testTdf129681); CPPUNIT_TEST(testTdf111974XLSM); - CPPUNIT_TEST(testTdf83672XLSX); - - CPPUNIT_TEST(testPageScalingXLSX); - CPPUNIT_TEST(testActiveXCheckboxXLSX); - CPPUNIT_TEST(testtdf120301_xmlSpaceParsingXLSX); -#ifdef UNX - CPPUNIT_TEST(testUnicodeFileNameGnumeric); -#endif - CPPUNIT_TEST(testMergedCellsXLSXML); - CPPUNIT_TEST(testBackgroundColorStandardXLSXML); - CPPUNIT_TEST(testTdf131536); - CPPUNIT_TEST(testTdf130583); - CPPUNIT_TEST(testTdf85617); - CPPUNIT_TEST(testTdf134234); - CPPUNIT_TEST(testTdf42481); - CPPUNIT_TEST(testNamedExpressionsXLSXML); - CPPUNIT_TEST(testEmptyRowsXLSXML); - CPPUNIT_TEST(testBorderDirectionsXLSXML); - CPPUNIT_TEST(testBorderColorsXLSXML); - CPPUNIT_TEST(testHiddenRowsColumnsXLSXML); - CPPUNIT_TEST(testColumnWidthRowHeightXLSXML); - CPPUNIT_TEST(testCharacterSetXLSXML); - CPPUNIT_TEST(testCondFormatFormulaListenerXLSX); - CPPUNIT_TEST(testTdf137091); - CPPUNIT_TEST(testTdf62268); - CPPUNIT_TEST(testTdf137453); - CPPUNIT_TEST(testTdf112780); - CPPUNIT_TEST(testTdf72470); - CPPUNIT_TEST(testTdf35636); - CPPUNIT_TEST(testTdf98481); - CPPUNIT_TEST(testTdf115022); - CPPUNIT_TEST(testVBAMacroFunctionODS); - CPPUNIT_TEST(testAutoheight2Rows); - CPPUNIT_TEST(testXLSDefColWidth); - CPPUNIT_TEST(testPreviewMissingObjLink); - CPPUNIT_TEST(testShapeRotationImport); - CPPUNIT_TEST(testShapeDisplacementOnRotationImport); - CPPUNIT_TEST(testTextBoxBodyUpright); - CPPUNIT_TEST(testTextBoxBodyRotateAngle); - CPPUNIT_TEST(testTextLengthDataValidityXLSX); - CPPUNIT_TEST(testDeleteCircles); - CPPUNIT_TEST(testDrawCircleInMergeCells); - CPPUNIT_TEST(testDeleteCirclesInRowAndCol); - CPPUNIT_TEST(testTdf129940); - CPPUNIT_TEST(testTdf139763ShapeAnchor); - CPPUNIT_TEST(testAutofilterNamedRangesXLSX); CPPUNIT_TEST_SUITE_END(); @@ -3242,917 +3034,19 @@ void ScFiltersTest::testFormulaDependency() xDocSh->DoClose(); } -void ScFiltersTest::testMiscRowHeights() -{ - // FIXME: the DPI check should be removed when either (1) the test is fixed to work with - // non-default DPI; or (2) unit tests on Windows are made to use svp VCL plugin. - if (!IsDefaultDPI()) - return; - - static const TestParam::RowData DfltRowData[] = - { - // check rows at the beginning and end of document - // and make sure they are reported as the default row - // height ( indicated by -1 ) - { 2, 4, 0, -1, 0, false }, - { 1048573, 1048575, 0, -1, 0, false }, - }; - - static const TestParam::RowData MultiLineOptData[] = - { - // Row 0 is 12.63 mm and optimal flag is set => 12.36 mm - { 0, 0, 0, 1236, CHECK_OPTIMAL, true }, - // Row 1 is 11.99 mm and optimal flag is NOT set - { 1, 1, 0, 1199, CHECK_OPTIMAL, false }, - }; - - TestParam aTestValues[] = - { - /* Checks that a document saved to ods with default rows does indeed - have default row heights ( there was a problem where the optimal - height was being calculated after import if no hard height ) - */ - { "alldefaultheights.", FORMAT_ODS, -1, SAL_N_ELEMENTS(DfltRowData), DfltRowData }, - /* Checks the imported height of some multiline input, additionally checks - that the optimal height flag is set ( or not ) - */ - { "multilineoptimal.", FORMAT_ODS, -1, SAL_N_ELEMENTS(MultiLineOptData), MultiLineOptData }, - }; - miscRowHeightsTest( aTestValues, SAL_N_ELEMENTS(aTestValues) ); -} - -// regression test at least fdo#59193 -// what we want to test here is that when cell contents are deleted -// and the optimal flag is set for that row that the row is actually resized - -void ScFiltersTest::testOptimalHeightReset() -{ - // FIXME: the DPI check should be removed when either (1) the test is fixed to work with - // non-default DPI; or (2) unit tests on Windows are made to use svp VCL plugin. - if (!IsDefaultDPI()) - return; - - ScDocShellRef xDocSh = loadDoc(u"multilineoptimal.", FORMAT_ODS, true); - SCTAB nTab = 0; - SCROW nRow = 0; - ScDocument& rDoc = xDocSh->GetDocument(); - // open document in read/write mode ( otherwise optimal height stuff won't - // be triggered ) *and* you can't delete cell contents. - int nHeight = convertTwipToMm100(rDoc.GetRowHeight(nRow, nTab, false)); - CPPUNIT_ASSERT_EQUAL(1236, nHeight); - - ScDocFunc &rFunc = xDocSh->GetDocFunc(); - - // delete content of A1 - ScRange aDelRange(0,0,0,0,0,0); - ScMarkData aMark(rDoc.GetSheetLimits()); - aMark.SetMarkArea(aDelRange); - bool bRet = rFunc.DeleteContents( aMark, InsertDeleteFlags::ALL, false, true ); - CPPUNIT_ASSERT_MESSAGE("DeleteContents failed", bRet); - - // get the new height of A1 - nHeight = convertTwipToMm100(rDoc.GetRowHeight(nRow, nTab, false)); - - // set optimal height for empty row 2 - std::vector<sc::ColRowSpan> aRowArr(1, sc::ColRowSpan(2,2)); - rFunc.SetWidthOrHeight(false, aRowArr, nTab, SC_SIZE_OPTIMAL, 0, true, true); - - // retrieve optimal height - int nOptimalHeight = convertTwipToMm100(rDoc.GetRowHeight(aRowArr[0].mnStart, nTab, false)); - - // check if the new height of A1 ( after delete ) is now the optimal height of an empty cell - CPPUNIT_ASSERT_EQUAL(nOptimalHeight, nHeight ); - xDocSh->DoClose(); -} - -void ScFiltersTest::testCustomNumFormatHybridCellODS() -{ - ScDocShellRef xDocSh = loadDoc(u"custom-numfmt-hybrid-cell.", FORMAT_ODS, false); - ScDocument& rDoc = xDocSh->GetDocument(); - rDoc.SetAutoCalc(true); - - // All of B14, B16 and B18 should be displaying empty strings by virtue - // of the custom number format being set on those cells. - - for (SCROW nRow : {13, 15, 17}) - { - ScAddress aPos(1, nRow, 0); - OUString aStr = rDoc.GetString(aPos); - CPPUNIT_ASSERT(aStr.isEmpty()); - } - - // Now, set value of 1 to B15. This should trigger re-calc on B18 and B18 - // should now show a value of 1. - rDoc.SetValue(ScAddress(1,15,0), 1.0); - - OUString aStr = rDoc.GetString(ScAddress(1,17,0)); - CPPUNIT_ASSERT_EQUAL(OUString("1"), aStr); - - // Make sure the cell doesn't have an error value. - ScFormulaCell* pFC = rDoc.GetFormulaCell(ScAddress(1,17,0)); - CPPUNIT_ASSERT(pFC); - CPPUNIT_ASSERT_EQUAL(FormulaError::NONE, pFC->GetErrCode()); - - xDocSh->DoClose(); -} - -void ScFiltersTest::testTdf121040() -{ - ScDocShellRef xDocSh = loadDoc(u"tdf121040.", FORMAT_ODS); - CPPUNIT_ASSERT_MESSAGE("Failed to load tdf121040.ods", xDocSh.is()); - - const SCTAB nTab = 0; - ScDocument& rDoc = xDocSh->GetDocument(); - - // The first 9 rows should have the same height - const sal_uInt16 nHeight = rDoc.GetRowHeight(0, nTab, false); - for (SCTAB nRow=1; nRow<9; nRow++) - { - CPPUNIT_ASSERT_EQUAL(nHeight, rDoc.GetRowHeight(nRow, nTab, false)); - } - - xDocSh->DoClose(); -} - -void ScFiltersTest::testTdf118086() -{ - ScDocShellRef xDocSh = loadDoc(u"tdf118086.", FORMAT_ODS); - CPPUNIT_ASSERT_MESSAGE("Failed to load tdf118086.ods", xDocSh.is()); - - ScDocument& rDoc = xDocSh->GetDocument(); - - CPPUNIT_ASSERT_EQUAL(sal_uInt16(477), rDoc.GetRowHeight(2, static_cast<SCTAB>(0), false)); - - // Without the fix in place, this test would have failed with - // - Expected: 256 - // - Actual : 477 - CPPUNIT_ASSERT_EQUAL(sal_uInt16(256), rDoc.GetRowHeight(2, static_cast<SCTAB>(1), false)); - CPPUNIT_ASSERT_EQUAL(sal_uInt16(256), rDoc.GetRowHeight(2, static_cast<SCTAB>(2), false)); - - xDocSh->DoClose(); -} - -void ScFiltersTest::testTdf118624() -{ - ScDocShellRef xDocSh = loadDoc(u"tdf118624.", FORMAT_ODS); - CPPUNIT_ASSERT_MESSAGE("Failed to open doc", xDocSh.is()); - - ScDocument& rDoc = xDocSh->GetDocument(); - - CPPUNIT_ASSERT_MESSAGE("RAND() in array/matrix mode shouldn't return the same value", - rDoc.GetString(ScAddress(0,0,0)) != rDoc.GetString(ScAddress(0,1,0))); - - xDocSh->DoClose(); -} - -void ScFiltersTest::testTdf124454() -{ - ScDocShellRef xDocSh = loadDoc(u"tdf124454.", FORMAT_ODS); - CPPUNIT_ASSERT_MESSAGE("Failed to open doc", xDocSh.is()); - - ScDocument& rDoc = xDocSh->GetDocument(); - - CPPUNIT_ASSERT_EQUAL(OUString("1"), rDoc.GetString(ScAddress(1,0,0))); - CPPUNIT_ASSERT_EQUAL(OUString("1"), rDoc.GetString(ScAddress(2,0,0))); - // Without the fix in place, double negation with text in array - // would have returned -1 - CPPUNIT_ASSERT_EQUAL(OUString("1"), rDoc.GetString(ScAddress(3,0,0))); - - xDocSh->DoClose(); -} - -void ScFiltersTest::testPrintRangeODS() -{ - ScDocShellRef xDocSh = loadDoc(u"print-range.", FORMAT_ODS); - ScDocument& rDoc = xDocSh->GetDocument(); - const ScRange* pRange = rDoc.GetRepeatRowRange(0); - CPPUNIT_ASSERT(pRange); - CPPUNIT_ASSERT_EQUAL(ScRange(0,0,0,0,1,0), *pRange); - - pRange = rDoc.GetRepeatRowRange(1); - CPPUNIT_ASSERT(pRange); - CPPUNIT_ASSERT_EQUAL(ScRange(0,2,0,0,4,0), *pRange); - - xDocSh->DoClose(); -} - -void ScFiltersTest::testOutlineODS() -{ - ScDocShellRef xDocSh = loadDoc(u"outline.", FORMAT_ODS); - ScDocument& rDoc = xDocSh->GetDocument(); - - const ScOutlineTable* pTable = rDoc.GetOutlineTable(0); - CPPUNIT_ASSERT(pTable); - - const ScOutlineArray& rArr = pTable->GetRowArray(); - size_t nDepth = rArr.GetDepth(); - CPPUNIT_ASSERT_EQUAL(size_t(4), nDepth); - - for(size_t i = 0; i < nDepth; ++i) - { - CPPUNIT_ASSERT_EQUAL(size_t(1), rArr.GetCount(i)); - } - - struct OutlineData { - SCCOLROW nStart; - SCCOLROW nEnd; - bool bHidden; - bool bVisible; - - size_t nDepth; - size_t nIndex; - }; - - static const OutlineData aRow[] = - { - { 1, 29, false, true, 0, 0 }, - { 2, 26, false, true, 1, 0 }, - { 4, 23, false, true, 2, 0 }, - { 6, 20, true, true, 3, 0 } - }; - - for(size_t i = 0; i < SAL_N_ELEMENTS(aRow); ++i) - { - - const ScOutlineEntry* pEntry = rArr.GetEntry(aRow[i].nDepth, aRow[i].nIndex); - SCCOLROW nStart = pEntry->GetStart(); - CPPUNIT_ASSERT_EQUAL(aRow[i].nStart, nStart); - - SCCOLROW nEnd = pEntry->GetEnd(); - CPPUNIT_ASSERT_EQUAL(aRow[i].nEnd, nEnd); - - bool bHidden = pEntry->IsHidden(); - CPPUNIT_ASSERT_EQUAL(aRow[i].bHidden, bHidden); - - bool bVisible = pEntry->IsVisible(); - CPPUNIT_ASSERT_EQUAL(aRow[i].bVisible, bVisible); - } - - xDocSh->DoClose(); -} - -void ScFiltersTest::testColumnStyleXLSX() -{ - ScDocShellRef xDocSh = loadDoc(u"column-style.", FORMAT_XLSX); - CPPUNIT_ASSERT(xDocSh.is()); - ScDocument& rDoc = xDocSh->GetDocument(); - - const ScPatternAttr* pPattern = rDoc.GetPattern(0,0,0); - CPPUNIT_ASSERT(pPattern); - - const ScProtectionAttr& rAttr = pPattern->GetItem(ATTR_PROTECTION); - CPPUNIT_ASSERT(rAttr.GetProtection()); - - pPattern = rDoc.GetPattern(0,1,0); - CPPUNIT_ASSERT(pPattern); - - const ScProtectionAttr& rAttrNew = pPattern->GetItem(ATTR_PROTECTION); - CPPUNIT_ASSERT(!rAttrNew.GetProtection()); - - xDocSh->DoClose(); -} - -void ScFiltersTest::testColumnStyleAutoFilterXLSX() -{ - ScDocShellRef xDocSh = loadDoc(u"column-style-autofilter.", FORMAT_XLSX); - CPPUNIT_ASSERT(xDocSh.is()); - ScDocument& rDoc = xDocSh->GetDocument(); - - const ScPatternAttr* pPattern = rDoc.GetPattern(0, 10, 18); - CPPUNIT_ASSERT(pPattern); - - const ScMergeFlagAttr& rAttr = pPattern->GetItem(ATTR_MERGE_FLAG); - CPPUNIT_ASSERT(!rAttr.HasAutoFilter()); - - xDocSh->DoClose(); -} - -void ScFiltersTest::testSharedFormulaHorizontalXLS() -{ - ScDocShellRef xDocSh = loadDoc(u"shared-formula/horizontal.", FORMAT_XLS); - CPPUNIT_ASSERT(xDocSh.is()); - ScDocument& rDoc = xDocSh->GetDocument(); - - // Make sure K2:S2 on the 2nd sheet are all formula cells. - ScAddress aPos(0, 1, 1); - for (SCCOL nCol = 10; nCol <= 18; ++nCol) - { - aPos.SetCol(nCol); - CPPUNIT_ASSERT_EQUAL_MESSAGE("Formula cell is expected here.", CELLTYPE_FORMULA, rDoc.GetCellType(aPos)); - } - - // Likewise, B3:J9 all should be formula cells. - for (SCCOL nCol = 1; nCol <= 9; ++nCol) - { - aPos.SetCol(nCol); - for (SCROW nRow = 2; nRow <= 8; ++nRow) - { - aPos.SetRow(nRow); - CPPUNIT_ASSERT_EQUAL_MESSAGE("Formula cell is expected here.", CELLTYPE_FORMULA, rDoc.GetCellType(aPos)); - } - } - - // B2:I2 too. - aPos.SetRow(1); - for (SCCOL nCol = 1; nCol <= 8; ++nCol) - { - aPos.SetCol(nCol); - CPPUNIT_ASSERT_EQUAL_MESSAGE("Formula cell is expected here.", CELLTYPE_FORMULA, rDoc.GetCellType(aPos)); - } - - // J2 has a string of "MW". - aPos.SetCol(9); - CPPUNIT_ASSERT_EQUAL(OUString("MW"), rDoc.GetString(aPos)); - - xDocSh->DoClose(); -} - -void ScFiltersTest::testSharedFormulaWrappedRefsXLS() -{ - ScDocShellRef xDocSh = loadDoc(u"shared-formula/wrapped-refs.", FORMAT_XLS); - CPPUNIT_ASSERT(xDocSh.is()); - ScDocument& rDoc = xDocSh->GetDocument(); - rDoc.CalcAll(); - - // Check the values of H7:H10. - CPPUNIT_ASSERT_EQUAL(7.0, rDoc.GetValue(ScAddress(7,6,0))); - CPPUNIT_ASSERT_EQUAL(8.0, rDoc.GetValue(ScAddress(7,7,0))); - CPPUNIT_ASSERT_EQUAL(9.0, rDoc.GetValue(ScAddress(7,8,0))); - CPPUNIT_ASSERT_EQUAL(10.0, rDoc.GetValue(ScAddress(7,9,0))); - - // EM7:EM10 should reference H7:H10. - CPPUNIT_ASSERT_EQUAL(7.0, rDoc.GetValue(ScAddress(142,6,0))); - CPPUNIT_ASSERT_EQUAL(8.0, rDoc.GetValue(ScAddress(142,7,0))); - CPPUNIT_ASSERT_EQUAL(9.0, rDoc.GetValue(ScAddress(142,8,0))); - CPPUNIT_ASSERT_EQUAL(10.0, rDoc.GetValue(ScAddress(142,9,0))); - - // Make sure EM7:EM10 are grouped. - const ScFormulaCell *pFC = rDoc.GetFormulaCell(ScAddress(142,6,0)); - CPPUNIT_ASSERT(pFC); - CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(6), pFC->GetSharedTopRow()); - CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(4), pFC->GetSharedLength()); - - xDocSh->DoClose(); -} - -void ScFiltersTest::testSharedFormulaBIFF5() -{ - ScDocShellRef xDocSh = loadDoc(u"shared-formula/biff5.", FORMAT_XLS); - CPPUNIT_ASSERT(xDocSh.is()); - ScDocument& rDoc = xDocSh->GetDocument(); - rDoc.CalcAll(); - - // E6:E376 should be all formulas, and they should belong to the same group. - const ScFormulaCell* pFC = rDoc.GetFormulaCell(ScAddress(4,5,0)); - CPPUNIT_ASSERT(pFC); - CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(5), pFC->GetSharedTopRow()); - CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(371), pFC->GetSharedLength()); - - xDocSh->DoClose(); -} - -void ScFiltersTest::testSharedFormulaXLSB() -{ - ScDocShellRef xDocSh = loadDoc(u"shared_formula.", FORMAT_XLSB); - CPPUNIT_ASSERT(xDocSh.is()); - ScDocument& rDoc = xDocSh->GetDocument(); - rDoc.CalcAll(); - - // A1:A30 should be all formulas, and they should belong to the same group. - const ScFormulaCell* pFC = rDoc.GetFormulaCell(ScAddress(0,0,0)); - CPPUNIT_ASSERT(pFC); - CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(0), pFC->GetSharedTopRow()); - CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(30), pFC->GetSharedLength()); - - for(SCROW nRow = 0; nRow < 30; ++nRow) - { - ASSERT_DOUBLES_EQUAL(3.0, rDoc.GetValue(0, nRow, 0)); - } - - xDocSh->DoClose(); -} - -void ScFiltersTest::testSharedFormulaXLS() -{ - { - // fdo#80091 - ScDocShellRef xDocSh = loadDoc(u"shared-formula/relative-refs1.", FORMAT_XLS); - CPPUNIT_ASSERT(xDocSh.is()); - ScDocument& rDoc = xDocSh->GetDocument(); - rDoc.CalcAll(); - - // A1:A30 should be all formulas, and they should belong to the same group. - const ScFormulaCell* pFC = rDoc.GetFormulaCell(ScAddress(0,1,0)); - CPPUNIT_ASSERT(pFC); - CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(1), pFC->GetSharedTopRow()); - CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(29), pFC->GetSharedLength()); - - for(SCROW nRow = 0; nRow < 30; ++nRow) - { - ASSERT_DOUBLES_EQUAL(double(nRow+1), rDoc.GetValue(0, nRow, 0)); - } - - xDocSh->DoClose(); - } - - { - // fdo#84556 and some related tests - ScDocShellRef xDocSh = loadDoc(u"shared-formula/relative-refs2.", FORMAT_XLS); - CPPUNIT_ASSERT(xDocSh.is()); - ScDocument& rDoc = xDocSh->GetDocument(); - rDoc.CalcAll(); - - { - const ScFormulaCell* pFC = rDoc.GetFormulaCell(ScAddress(2,1,0)); - CPPUNIT_ASSERT(pFC); - CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(1), pFC->GetSharedTopRow()); - CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(10), pFC->GetSharedLength()); - - pFC = rDoc.GetFormulaCell(ScAddress(2,10,0)); - CPPUNIT_ASSERT(pFC); - CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(1), pFC->GetSharedTopRow()); - CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(10), pFC->GetSharedLength()); - - OUString aFormula; - rDoc.GetFormula(2, 1, 0, aFormula); - CPPUNIT_ASSERT_EQUAL(OUString("=SUM(B9:D9)"), aFormula); - - rDoc.GetFormula(2, 10, 0, aFormula); - CPPUNIT_ASSERT_EQUAL(OUString("=SUM(B18:D18)"), aFormula); - } - - { - const ScFormulaCell* pFC = rDoc.GetFormulaCell(ScAddress(4,8,0)); - CPPUNIT_ASSERT(pFC); - CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(8), pFC->GetSharedTopRow()); - CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(10), pFC->GetSharedLength()); - - pFC = rDoc.GetFormulaCell(ScAddress(4,17,0)); - CPPUNIT_ASSERT(pFC); - CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(8), pFC->GetSharedTopRow()); - CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(10), pFC->GetSharedLength()); - - OUString aFormula; - rDoc.GetFormula(4, 8, 0, aFormula); - CPPUNIT_ASSERT_EQUAL(OUString("=SUM(G9:EY9)"), aFormula); - - rDoc.GetFormula(4, 17, 0, aFormula); - CPPUNIT_ASSERT_EQUAL(OUString("=SUM(G18:EY18)"), aFormula); - } - - { - const ScFormulaCell* pFC = rDoc.GetFormulaCell(ScAddress(6,15,0)); - CPPUNIT_ASSERT(pFC); - CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(15), pFC->GetSharedTopRow()); - CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(10), pFC->GetSharedLength()); - - pFC = rDoc.GetFormulaCell(ScAddress(6,24,0)); - CPPUNIT_ASSERT(pFC); - CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(15), pFC->GetSharedTopRow()); - CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(10), pFC->GetSharedLength()); - - OUString aFormula; - rDoc.GetFormula(6, 15, 0, aFormula); - CPPUNIT_ASSERT_EQUAL(OUString("=SUM(A16:A40000)"), aFormula); - - rDoc.GetFormula(6, 24, 0, aFormula); - CPPUNIT_ASSERT_EQUAL(OUString("=SUM(A25:A40009)"), aFormula); - } - - xDocSh->DoClose(); - } -} - -void ScFiltersTest::testSharedFormulaColumnLabelsODS() -{ - ScDocShellRef xDocSh = loadDoc(u"shared-formula/column-labels.", FORMAT_ODS); - - CPPUNIT_ASSERT(xDocSh.is()); - ScDocument& rDoc = xDocSh->GetDocument(); - rDoc.CalcAll(); - - CPPUNIT_ASSERT_EQUAL( 5.0, rDoc.GetValue(ScAddress(2,1,0))); - CPPUNIT_ASSERT_EQUAL(15.0, rDoc.GetValue(ScAddress(2,2,0))); - CPPUNIT_ASSERT_EQUAL(30.0, rDoc.GetValue(ScAddress(2,3,0))); - CPPUNIT_ASSERT_EQUAL(28.0, rDoc.GetValue(ScAddress(2,4,0))); - CPPUNIT_ASSERT_EQUAL(48.0, rDoc.GetValue(ScAddress(2,5,0))); - - CPPUNIT_ASSERT_EQUAL( 0.0, rDoc.GetValue(ScAddress(3,1,0))); - CPPUNIT_ASSERT_EQUAL( 50.0, rDoc.GetValue(ScAddress(3,2,0))); - CPPUNIT_ASSERT_EQUAL(144.0, rDoc.GetValue(ScAddress(3,3,0))); - CPPUNIT_ASSERT_EQUAL(147.0, rDoc.GetValue(ScAddress(3,4,0))); - CPPUNIT_ASSERT_EQUAL(320.0, rDoc.GetValue(ScAddress(3,5,0))); - - CPPUNIT_ASSERT_EQUAL(0.0, rDoc.GetValue(ScAddress(4,1,0))); - CPPUNIT_ASSERT_EQUAL(2.0, rDoc.GetValue(ScAddress(4,2,0))); - CPPUNIT_ASSERT_EQUAL(4.0, rDoc.GetValue(ScAddress(4,3,0))); - CPPUNIT_ASSERT_EQUAL(3.0, rDoc.GetValue(ScAddress(4,4,0))); - CPPUNIT_ASSERT_EQUAL(5.0, rDoc.GetValue(ScAddress(4,5,0))); - - xDocSh->DoClose(); -} - -void ScFiltersTest::testSharedFormulaColumnRowLabelsODS() -{ - ScDocShellRef xDocSh = loadDoc(u"shared-formula/column-row-labels.", FORMAT_ODS); - - CPPUNIT_ASSERT(xDocSh.is()); - ScDocument& rDoc = xDocSh->GetDocument(); - rDoc.CalcAll(); - - // Expected output in each of the three ranges. - // - // +---+---+---+ - // | 1 | 4 | 7 | - // +---+---+---+ - // | 2 | 5 | 8 | - // +---+---+---+ - // | 3 | 6 | 9 | - // +---+---+---+ - - auto aCheckFunc = [&](SCCOL nStartCol, SCROW nStartRow) - { - double fExpected = 1.0; - for (SCCOL nCol = 0; nCol <= 2; ++nCol) - { - for (SCROW nRow = 0; nRow <= 2; ++nRow) - { - ScAddress aPos(nStartCol+nCol, nStartRow+nRow, 0); - CPPUNIT_ASSERT_EQUAL(fExpected, rDoc.GetValue(aPos)); - fExpected += 1.0; - } - } - }; - - aCheckFunc(5, 1); // F2:H4 - aCheckFunc(9, 1); // J2:L4 - aCheckFunc(1, 6); // B7:D9 - - xDocSh->DoClose(); -} - -void ScFiltersTest::testExternalRefCacheXLSX() -{ - ScDocShellRef xDocSh = loadDoc(u"external-refs.", FORMAT_XLSX); - CPPUNIT_ASSERT(xDocSh.is()); - ScDocument& rDoc = xDocSh->GetDocument(); - - // These string values are cached external cell values. - CPPUNIT_ASSERT_EQUAL(OUString("Name"), rDoc.GetString(ScAddress(0,0,0))); - CPPUNIT_ASSERT_EQUAL(OUString("Andy"), rDoc.GetString(ScAddress(0,1,0))); - CPPUNIT_ASSERT_EQUAL(OUString("Bruce"), rDoc.GetString(ScAddress(0,2,0))); - CPPUNIT_ASSERT_EQUAL(OUString("Charlie"), rDoc.GetString(ScAddress(0,3,0))); - - xDocSh->DoClose(); -} - -void ScFiltersTest::testExternalRefCacheODS() -{ - ScDocShellRef xDocSh = loadDoc(u"external-ref-cache.", FORMAT_ODS); - - CPPUNIT_ASSERT(xDocSh.is()); - ScDocument& rDoc = xDocSh->GetDocument(); - - // Cells B2:B4 have VLOOKUP with external references which should all show "text". - CPPUNIT_ASSERT_EQUAL(OUString("text"), rDoc.GetString(ScAddress(1,1,0))); - CPPUNIT_ASSERT_EQUAL(OUString("text"), rDoc.GetString(ScAddress(1,2,0))); - CPPUNIT_ASSERT_EQUAL(OUString("text"), rDoc.GetString(ScAddress(1,3,0))); - - // Both cells A6 and A7 should be registered with scExternalRefManager properly - CPPUNIT_ASSERT_EQUAL(true, rDoc.GetExternalRefManager()->hasCellExternalReference(ScAddress(0, 5, 0))); - CPPUNIT_ASSERT_EQUAL(true, rDoc.GetExternalRefManager()->hasCellExternalReference(ScAddress(0, 6, 0))); - - xDocSh->DoClose(); -} - -void ScFiltersTest::testHybridSharedStringODS() -{ - ScDocShellRef xDocSh = loadDoc(u"hybrid-shared-string.", FORMAT_ODS); - - CPPUNIT_ASSERT(xDocSh.is()); - ScDocument& rDoc = xDocSh->GetDocument(); - - // A2 contains formula with MATCH function. The result must be 2, not #N/A! - CPPUNIT_ASSERT_EQUAL(2.0, rDoc.GetValue(ScAddress(0,1,0))); - - xDocSh->DoClose(); -} - -void ScFiltersTest::testCopyMergedNumberFormats() -{ - ScDocShellRef xDocSh = loadDoc(u"copy-merged-number-formats.", FORMAT_ODS); - CPPUNIT_ASSERT(xDocSh.is()); - ScDocument& rDoc = xDocSh->GetDocument(); - - // Cells B1, C1 and D1 are formatted as dates. - OUString aStrB1 = rDoc.GetString(ScAddress(1,0,0)); - OUString aStrC1 = rDoc.GetString(ScAddress(2,0,0)); - OUString aStrD1 = rDoc.GetString(ScAddress(3,0,0)); - - ScDocument aCopyDoc; - aCopyDoc.InsertTab(0, "CopyHere"); - rDoc.CopyStaticToDocument(ScRange(1,0,0,3,0,0), 0, aCopyDoc); - - // Make sure the date formats are copied to the new document. - CPPUNIT_ASSERT_EQUAL(aStrB1, aCopyDoc.GetString(ScAddress(1,0,0))); - CPPUNIT_ASSERT_EQUAL(aStrC1, aCopyDoc.GetString(ScAddress(2,0,0))); - CPPUNIT_ASSERT_EQUAL(aStrD1, aCopyDoc.GetString(ScAddress(3,0,0))); - - xDocSh->DoClose(); -} - -void ScFiltersTest::testVBAUserFunctionXLSM() -{ - ScDocShellRef xDocSh = loadDoc(u"vba-user-function.", FORMAT_XLSM); - CPPUNIT_ASSERT(xDocSh.is()); - ScDocument& rDoc = xDocSh->GetDocument(); - - // A1 contains formula with user-defined function, and the function is defined in VBA. - ScFormulaCell* pFC = rDoc.GetFormulaCell(ScAddress(0,0,0)); - CPPUNIT_ASSERT(pFC); - - sc::CompileFormulaContext aCxt(rDoc); - OUString aFormula = pFC->GetFormula(aCxt); - - CPPUNIT_ASSERT_EQUAL(OUString("=MYFUNC()"), aFormula); - - // Check the formula state after the load. - FormulaError nErrCode = pFC->GetErrCode(); - CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(nErrCode)); - - // Check the result. - CPPUNIT_ASSERT_EQUAL(42.0, rDoc.GetValue(ScAddress(0,0,0))); - - xDocSh->DoClose(); -} - -void ScFiltersTest::testEmbeddedImageXLS() -{ - // The document has one embedded image on the first sheet. Make sure it's - // imported properly. - - ScDocShellRef xDocSh = loadDoc(u"file-with-png-image.", FORMAT_XLS); - CPPUNIT_ASSERT(xDocSh.is()); - ScDocument& rDoc = xDocSh->GetDocument(); - - ScDrawLayer* pDL = rDoc.GetDrawLayer(); - CPPUNIT_ASSERT(pDL); - const SdrPage* pPage = pDL->GetPage(0); - CPPUNIT_ASSERT(pPage); - const SdrObject* pObj = pPage->GetObj(0); - CPPUNIT_ASSERT(pObj); - const SdrGrafObj* pImageObj = dynamic_cast<const SdrGrafObj*>(pObj); - CPPUNIT_ASSERT(pImageObj); - const Graphic& rGrf = pImageObj->GetGraphic(); - BitmapEx aBMP = rGrf.GetBitmapEx(); - CPPUNIT_ASSERT_MESSAGE("Bitmap content should not be empty if the image has been properly imported.", !aBMP.IsEmpty()); - - xDocSh->DoClose(); -} - -void ScFiltersTest::testErrorOnExternalReferences() -{ - ScDocShellRef xDocSh = loadDoc(u"blank.", FORMAT_ODS); - CPPUNIT_ASSERT_MESSAGE("Failed to open empty doc", xDocSh.is()); - - ScDocument& rDoc = xDocSh->GetDocument(); - - // Test tdf#89330 - rDoc.SetString(ScAddress(0,0,0), "='file:///Path/To/FileA.ods'#$Sheet1.A1A"); - - ScFormulaCell* pFC = rDoc.GetFormulaCell(ScAddress(0,0,0)); - CPPUNIT_ASSERT(pFC); - CPPUNIT_ASSERT_EQUAL(int(FormulaError::NoName), static_cast<int>(pFC->GetErrCode())); - - ASSERT_FORMULA_EQUAL(rDoc, ScAddress(0,0,0), "'file:///Path/To/FileA.ods'#$Sheet1.A1A", "Formula changed"); - - xDocSh->DoClose(); -} - -void ScFiltersTest::testTdf84762() -{ - ScDocShellRef xDocSh = loadDoc(u"blank.", FORMAT_ODS); - CPPUNIT_ASSERT_MESSAGE("Failed to open empty doc", xDocSh.is()); - - ScDocument& rDoc = xDocSh->GetDocument(); - - rDoc.SetString(ScAddress(0,0,0), "=RAND()"); - rDoc.SetString(ScAddress(0,1,0), "=RAND()"); - rDoc.SetString(ScAddress(1,0,0), "=RAND()*A1"); - rDoc.SetString(ScAddress(1,1,0), "=RAND()*B1"); - - double nValA1, nValB1, nValA2, nValB2; - - // Without the fix in place, some cells wouldn't have been updated - // after using F9 a few times - for(sal_Int16 i = 0; i < 10; ++i) - { - nValA1 = rDoc.GetValue(0, 0, 0); - nValB1 = rDoc.GetValue(0, 1, 0); - nValA2 = rDoc.GetValue(1, 0, 0); - nValB2 = rDoc.GetValue(1, 1, 0); - - xDocSh->DoRecalc(false); - - CPPUNIT_ASSERT(nValA1 != rDoc.GetValue(0, 0, 0)); - CPPUNIT_ASSERT(nValA2 != rDoc.GetValue(0, 1, 0)); - CPPUNIT_ASSERT(nValB1 != rDoc.GetValue(1, 0, 0)); - CPPUNIT_ASSERT(nValB2 != rDoc.GetValue(1, 1, 0)); - } - - xDocSh->DoClose(); -} - -void ScFiltersTest::testTdf44076() -{ - ScDocShellRef xDocSh = loadDoc(u"blank.", FORMAT_ODS); - CPPUNIT_ASSERT_MESSAGE("Failed to open empty doc", xDocSh.is()); - - ScDocument& rDoc = xDocSh->GetDocument(); +void ScFiltersTest::testTdf122643() { testImportCrash(u"tdf122643.", FORMAT_ODS); } - rDoc.SetString(ScAddress(0,0,0), "=(-8)^(1/3)"); +void ScFiltersTest::testTdf132278() { testImportCrash(u"tdf132278.", FORMAT_ODS); } - CPPUNIT_ASSERT_EQUAL(-2.0, rDoc.GetValue(ScAddress(0,0,0))); +void ScFiltersTest::testTdf130959() { testImportCrash(u"tdf130959.", FORMAT_XLSX); } - xDocSh->DoClose(); -} +void ScFiltersTest::testTdf129410() { testImportCrash(u"tdf129410.", FORMAT_ODS); } -void ScFiltersTest::testEditEngStrikeThroughXLSX() -{ - ScDocShellRef xDocSh = loadDoc(u"strike-through.", FORMAT_XLSX); - CPPUNIT_ASSERT_MESSAGE("Failed to open doc", xDocSh.is()); +void ScFiltersTest::testTdf138507() { testImportCrash(u"tdf138507.", FORMAT_ODS); } - ScDocument& rDoc = xDocSh->GetDocument(); +void ScFiltersTest::testTdf131380() { testImportCrash(u"tdf131380.", FORMAT_XLSX); } - const EditTextObject* pObj = rDoc.GetEditText(ScAddress(0, 0, 0)); - CPPUNIT_ASSERT(pObj); - CPPUNIT_ASSERT_EQUAL(sal_Int32(1), pObj->GetParagraphCount()); - CPPUNIT_ASSERT_EQUAL(OUString("this is strike through this not"), pObj->GetText(0)); - - std::vector<EECharAttrib> aAttribs; - pObj->GetCharAttribs(0, aAttribs); - for (const auto& rAttrib : aAttribs) - { - if (rAttrib.pAttr->Which() == EE_CHAR_STRIKEOUT) - { - const SvxCrossedOutItem& rItem = static_cast<const SvxCrossedOutItem&>(*rAttrib.pAttr); - if (rAttrib.nStart == 0) - { - CPPUNIT_ASSERT(rItem.GetStrikeout() != STRIKEOUT_NONE); - } - else - { - CPPUNIT_ASSERT_EQUAL(STRIKEOUT_NONE, rItem.GetStrikeout()); - } - } - } - - xDocSh->DoClose(); -} - -void ScFiltersTest::testRefStringXLSX() -{ - ScDocShellRef xDocSh = loadDoc(u"ref_string.", FORMAT_XLSX); - CPPUNIT_ASSERT_MESSAGE("Failed to open doc", xDocSh.is()); - - ScDocument& rDoc = xDocSh->GetDocument(); - - double nVal = rDoc.GetValue(2, 2, 0); - ASSERT_DOUBLES_EQUAL(3.0, nVal); - - const ScCalcConfig& rCalcConfig = rDoc.GetCalcConfig(); - CPPUNIT_ASSERT_EQUAL(formula::FormulaGrammar::CONV_XL_A1, rCalcConfig.meStringRefAddressSyntax); - - xDocSh->DoClose(); -} - -void ScFiltersTest::testTdf130132() -{ - ScDocShellRef xDocSh = loadDoc(u"tdf130132.", FORMAT_ODS); - CPPUNIT_ASSERT_MESSAGE("Failed to open doc", xDocSh.is()); - - ScDocument& rDoc = xDocSh->GetDocument(); - const ScPatternAttr* pAttr = rDoc.GetPattern(434, 0, 0); - - { - const SfxPoolItem& rItem = pAttr->GetItem(ATTR_BACKGROUND); - const SvxBrushItem& rBackground = static_cast<const SvxBrushItem&>(rItem); - const Color& rColor = rBackground.GetColor(); - // background colour is yellow - CPPUNIT_ASSERT_EQUAL(Color(255, 255, 0), rColor); - } -} - -void ScFiltersTest::testTdf133327() -{ - ScDocShellRef xDocSh = loadDoc(u"tdf133327.", FORMAT_ODS); - CPPUNIT_ASSERT_MESSAGE("Failed to open doc", xDocSh.is()); - - ScDocument& rDoc = xDocSh->GetDocument(); - - const ScPatternAttr* pAttr = rDoc.GetPattern(250, 1, 0); - - const SfxPoolItem& rItem = pAttr->GetItem(ATTR_BACKGROUND); - const SvxBrushItem& rBackground = static_cast<const SvxBrushItem&>(rItem); - const Color& rColor = rBackground.GetColor(); - - // Without the fix in place, this test would have failed with - // - Expected: Color: R:255 G:255 B: 0 - // - Actual : Color: R:255 G:255 B: 255 - CPPUNIT_ASSERT_EQUAL(Color(255, 255, 0), rColor); -} - -void ScFiltersTest::testColumnStyle2XLSX() -{ - ScDocShellRef xDocSh = loadDoc(u"column_style.", FORMAT_XLSX); - CPPUNIT_ASSERT_MESSAGE("Failed to open doc", xDocSh.is()); - - ScDocument& rDoc = xDocSh->GetDocument(); - const ScPatternAttr* pAttr = rDoc.GetPattern(1, 1, 0); - - { - const SfxPoolItem& rItem = pAttr->GetItem(ATTR_BACKGROUND); - const SvxBrushItem& rBackground = static_cast<const SvxBrushItem&>(rItem); - const Color& rColor = rBackground.GetColor(); - CPPUNIT_ASSERT_EQUAL(Color(255, 51, 51), rColor); - } - - { - const SfxPoolItem& rItem = pAttr->GetItem(ATTR_HOR_JUSTIFY); - const SvxHorJustifyItem& rJustify = static_cast<const SvxHorJustifyItem&>(rItem); - CPPUNIT_ASSERT_EQUAL(SvxCellHorJustify::Center, rJustify.GetValue()); - } - - { - const SfxPoolItem& rItem = pAttr->GetItem(ATTR_FONT_HEIGHT); - const SvxFontHeightItem& rFontHeight = static_cast<const SvxFontHeightItem&>(rItem); - sal_uInt16 nHeight = rFontHeight.GetHeight(); - CPPUNIT_ASSERT_EQUAL(sal_uInt16(240), nHeight); - } - - { - const SfxPoolItem& rItem = pAttr->GetItem(ATTR_FONT); - const SvxFontItem& rFont = static_cast<const SvxFontItem&>(rItem); - OUString aName = rFont.GetFamilyName(); - CPPUNIT_ASSERT_EQUAL(OUString("Linux Biolinum G"), aName); - } - - xDocSh->DoClose(); -} - -void ScFiltersTest::testTdf110440XLSX() -{ - ScDocShellRef xDocSh = loadDoc(u"tdf110440.", FORMAT_XLSX); - CPPUNIT_ASSERT_MESSAGE("Failed to open doc", xDocSh.is()); - - uno::Reference<frame::XModel> xModel = xDocSh->GetModel(); - uno::Reference<sheet::XSpreadsheetDocument> xDoc(xModel, uno::UNO_QUERY_THROW); - uno::Reference<container::XIndexAccess> xIA(xDoc->getSheets(), uno::UNO_QUERY_THROW); - uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(xIA->getByIndex(0), uno::UNO_QUERY_THROW); - xIA.set(xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY_THROW); - uno::Reference<beans::XPropertySet> xShape(xIA->getByIndex(0), uno::UNO_QUERY_THROW); - bool bVisible = true; - xShape->getPropertyValue("Visible") >>= bVisible; - // This failed: group shape's hidden property was lost on import. - CPPUNIT_ASSERT(!bVisible); - - xDocSh->DoClose(); -} - -void ScFiltersTest::testTdf122643() -{ - testImportCrash(u"tdf122643.", FORMAT_ODS); -} - -void ScFiltersTest::testTdf132278() -{ - testImportCrash(u"tdf132278.", FORMAT_ODS); -} - -void ScFiltersTest::testTdf130959() -{ - testImportCrash(u"tdf130959.", FORMAT_XLSX); -} - -void ScFiltersTest::testTdf129410() -{ - testImportCrash(u"tdf129410.", FORMAT_ODS); -} - -void ScFiltersTest::testTdf138507() -{ - testImportCrash(u"tdf138507.", FORMAT_ODS); -} - -void ScFiltersTest::testTdf131380() -{ - testImportCrash(u"tdf131380.", FORMAT_XLSX); -} - -void ScFiltersTest::testTdf139782() -{ - testImportCrash(u"tdf139782.", FORMAT_ODS); -} +void ScFiltersTest::testTdf139782() { testImportCrash(u"tdf139782.", FORMAT_ODS); } void ScFiltersTest::testTdf129681() { @@ -4161,1671 +3055,28 @@ void ScFiltersTest::testTdf129681() ScDocument& rDoc = xDocSh->GetDocument(); - CPPUNIT_ASSERT_EQUAL(OUString("Lamb"), rDoc.GetString(ScAddress(4,2,0))); - CPPUNIT_ASSERT_EQUAL(OUString("Beef"), rDoc.GetString(ScAddress(4,3,0))); - CPPUNIT_ASSERT_EQUAL(OUString("Pork"), rDoc.GetString(ScAddress(4,4,0))); - CPPUNIT_ASSERT_EQUAL(OUString("Goat"), rDoc.GetString(ScAddress(4,5,0))); - CPPUNIT_ASSERT_EQUAL(OUString("Goat"), rDoc.GetString(ScAddress(4,6,0))); - CPPUNIT_ASSERT_EQUAL(OUString("#VALUE!"), rDoc.GetString(ScAddress(4,7,0))); - CPPUNIT_ASSERT_EQUAL(OUString("#VALUE!"), rDoc.GetString(ScAddress(4,8,0))); - CPPUNIT_ASSERT_EQUAL(OUString("Deer"), rDoc.GetString(ScAddress(4,9,0))); - - CPPUNIT_ASSERT_EQUAL(OUString("1"), rDoc.GetString(ScAddress(6,2,0))); - CPPUNIT_ASSERT_EQUAL(OUString("2"), rDoc.GetString(ScAddress(6,3,0))); - CPPUNIT_ASSERT_EQUAL(OUString("3"), rDoc.GetString(ScAddress(6,4,0))); - CPPUNIT_ASSERT_EQUAL(OUString("5"), rDoc.GetString(ScAddress(6,5,0))); - CPPUNIT_ASSERT_EQUAL(OUString("8"), rDoc.GetString(ScAddress(6,6,0))); - CPPUNIT_ASSERT_EQUAL(OUString("#VALUE!"), rDoc.GetString(ScAddress(6,7,0))); - CPPUNIT_ASSERT_EQUAL(OUString("#VALUE!"), rDoc.GetString(ScAddress(6,8,0))); - CPPUNIT_ASSERT_EQUAL(OUString("#VALUE!"), rDoc.GetString(ScAddress(6,9,0))); - - xDocSh->DoClose(); -} - -void ScFiltersTest::testTdf111974XLSM() -{ - testImportCrash(u"tdf111974.", FORMAT_XLSM); -} - -void ScFiltersTest::testBnc762542() -{ - ScDocShellRef xDocSh = loadDoc(u"bnc762542.", FORMAT_XLSX); - CPPUNIT_ASSERT_MESSAGE("Failed to open doc", xDocSh.is()); - - ScDocument& rDoc = xDocSh->GetDocument(); - ScDrawLayer* pDrawLayer = rDoc.GetDrawLayer(); - SdrPage* pPage = pDrawLayer->GetPage(0); - CPPUNIT_ASSERT_MESSAGE("draw page for sheet 1 should exist.", pPage); - - const size_t nCount = pPage->GetObjCount(); - CPPUNIT_ASSERT_EQUAL_MESSAGE("There should be 10 shapes.", static_cast<size_t>(10), nCount); - - // previously, some of the shapes were (incorrectly) rotated by 90 degrees - for (size_t i : { 1, 2, 4, 5, 7, 9 }) - { - SdrObject* pObj = pPage->GetObj(i); - CPPUNIT_ASSERT_MESSAGE("Failed to get drawing object.", pObj); - - tools::Rectangle aRect(pObj->GetCurrentBoundRect()); - CPPUNIT_ASSERT_MESSAGE("Drawing object shouldn't be rotated.", aRect.GetWidth() > aRect.GetHeight()); - } - - xDocSh->DoClose(); -} - -void ScFiltersTest::testHiddenSheetsXLSX() -{ - ScDocShellRef xDocSh = loadDoc(u"hidden_sheets.", FORMAT_XLSX); - CPPUNIT_ASSERT_MESSAGE("Failed to open doc", xDocSh.is()); - - ScDocument& rDoc = xDocSh->GetDocument(); - CPPUNIT_ASSERT_EQUAL_MESSAGE("1st sheet should be hidden", false, rDoc.IsVisible(0)); - CPPUNIT_ASSERT_EQUAL_MESSAGE("2nd sheet should be visible", true, rDoc.IsVisible(1)); - CPPUNIT_ASSERT_EQUAL_MESSAGE("3rd sheet should be hidden", false, rDoc.IsVisible(2)); - - xDocSh->DoClose(); -} - -void ScFiltersTest::testAutofilterXLSX() -{ - ScDocShellRef xDocSh = loadDoc(u"autofilter.", FORMAT_XLSX); - CPPUNIT_ASSERT_MESSAGE("Failed to open doc", xDocSh.is()); - - ScDocument& rDoc = xDocSh->GetDocument(); - const ScDBData* pData = rDoc.GetDBCollection()->GetDBNearCursor(0,0,0); - CPPUNIT_ASSERT(pData); - ScRange aRange; - pData->GetArea(aRange); - CPPUNIT_ASSERT_EQUAL(ScRange(0,0,0,2,4,0), aRange); - - xDocSh->DoClose(); -} - -namespace { - -void checkValidationFormula(const ScAddress& rPos, const ScDocument& rDoc, const OUString& rExpectedFormula) -{ - const SfxUInt32Item* pItem = rDoc.GetAttr(rPos, ATTR_VALIDDATA); - CPPUNIT_ASSERT(pItem); - sal_uLong nKey = pItem->GetValue(); - const ScValidationData* pData = rDoc.GetValidationEntry(nKey); - CPPUNIT_ASSERT(pData); - - OUString aFormula = pData->GetExpression(rPos, 0); - CPPUNIT_ASSERT_EQUAL(rExpectedFormula, aFormula); -} - -} - -void ScFiltersTest::testRelFormulaValidationXLS() -{ - ScDocShellRef xDocSh = loadDoc(u"validation.", FORMAT_XLS); - CPPUNIT_ASSERT_MESSAGE("Failed to open doc", xDocSh.is()); - - ScDocument& rDoc = xDocSh->GetDocument(); - - checkValidationFormula(ScAddress(3, 4, 0), rDoc, "C5"); - checkValidationFormula(ScAddress(5, 8, 0), rDoc, "D7"); - - xDocSh->DoClose(); -} - -void ScFiltersTest::testTdf136364() -{ - ScDocShellRef xDocSh = loadDoc(u"tdf136364.", FORMAT_XLSX); - CPPUNIT_ASSERT_MESSAGE("Failed to open doc", xDocSh.is()); - - ScDocument& rDoc = xDocSh->GetDocument(); - - // Without the fix in place, it would have failed with - // - Expected: =SUM((B2:B3~C4:C5~D6:D7)) - // - Actual : =SUM((B2:B3~C4:C5,D6:D7)) - OUString aFormula; - rDoc.GetFormula(4, 0, 0, aFormula); - CPPUNIT_ASSERT_EQUAL(OUString("=SUM((B2:B3~C4:C5~D6:D7))"), aFormula); - CPPUNIT_ASSERT_EQUAL(27.0, rDoc.GetValue(ScAddress(4,0,0))); - - // - Expected: =SUM((B2~C4~D6)) - // - Actual : =SUM((B2~C4,D6)) - rDoc.GetFormula(4, 1, 0, aFormula); - CPPUNIT_ASSERT_EQUAL(OUString("=SUM((B2~C4~D6))"), aFormula); - CPPUNIT_ASSERT_EQUAL(12.0, rDoc.GetValue(ScAddress(4,1,0))); - - xDocSh->DoClose(); -} - -void ScFiltersTest::testTdf103734() -{ - ScDocShellRef xDocSh = loadDoc(u"tdf103734.", FORMAT_ODS); - CPPUNIT_ASSERT_MESSAGE("Failed to open doc", xDocSh.is()); - ScDocument& rDoc = xDocSh->GetDocument(); - - // Without the fix in place, MAX() would have returned -1.8E+308 - CPPUNIT_ASSERT_EQUAL(OUString("#N/A"), rDoc.GetString(ScAddress(2,0,0))); - - xDocSh->DoClose(); -} - -void ScFiltersTest::testTdf126116() -{ - ScDocShellRef xDocSh = loadDoc(u"tdf126116.", FORMAT_ODS); - CPPUNIT_ASSERT_MESSAGE("Failed to open doc", xDocSh.is()); - ScDocument& rDoc = xDocSh->GetDocument(); - - CPPUNIT_ASSERT_EQUAL(OUString("02/02/21"), rDoc.GetString(ScAddress(0,0,0))); - - rDoc.SetString(ScAddress(0,0,0), "03/03"); - - // Without the fix in place, this test would have failed with - // - Expected: 03/03/21 - // - Actual : 03/03/2021 - CPPUNIT_ASSERT_EQUAL(OUString("03/03/21"), rDoc.GetString(ScAddress(0,0,0))); - - xDocSh->DoClose(); -} - -void ScFiltersTest::testTdf98844() -{ - ScDocShellRef xDocSh = loadDoc(u"tdf98844.", FORMAT_ODS); - CPPUNIT_ASSERT_MESSAGE("Failed to open doc", xDocSh.is()); - ScDocument& rDoc = xDocSh->GetDocument(); - - CPPUNIT_ASSERT_EQUAL(47.6227, rDoc.GetValue(ScAddress(0,7,0))); - CPPUNIT_ASSERT_EQUAL(48.0, rDoc.GetValue(ScAddress(0,8,0))); - - xDocSh->DoHardRecalc(); - - // Without the fix in place, SUM() wouldn't have been updated when - // Precision as shown is enabled - CPPUNIT_ASSERT_EQUAL(48.0, rDoc.GetValue(ScAddress(0,7,0))); - CPPUNIT_ASSERT_EQUAL(48.0, rDoc.GetValue(ScAddress(0,8,0))); - - xDocSh->DoClose(); -} - -void ScFiltersTest::testTdf100458() -{ - ScDocShellRef xDocSh = loadDoc(u"tdf100458_lost_zero_value.", FORMAT_ODS); - CPPUNIT_ASSERT_MESSAGE("Failed to open doc", xDocSh.is()); - ScDocument& rDoc = xDocSh->GetDocument(); - CPPUNIT_ASSERT(rDoc.HasValueData(0, 0, 0)); - CPPUNIT_ASSERT_EQUAL(0.0, rDoc.GetValue(0,0,0)); - CPPUNIT_ASSERT(!rDoc.HasStringData(0, 0, 0)); - xDocSh->DoClose(); -} - -void ScFiltersTest::testTdf118561() -{ - ScDocShellRef xDocSh = loadDoc(u"tdf118561.", FORMAT_ODS); - CPPUNIT_ASSERT_MESSAGE("Failed to open doc", xDocSh.is()); - ScDocument& rDoc = xDocSh->GetDocument(); - - //Without the fix in place, it would have failed with - //- Expected: apple - //- Actual : Err:502 - CPPUNIT_ASSERT_EQUAL(OUString("apple"), rDoc.GetString(ScAddress(1,1,1))); - CPPUNIT_ASSERT_EQUAL(OUString("apple"), rDoc.GetString(ScAddress(2,1,1))); - CPPUNIT_ASSERT_EQUAL(OUString("TRUE"), rDoc.GetString(ScAddress(3,1,1))); - CPPUNIT_ASSERT_EQUAL(OUString("fruits"), rDoc.GetString(ScAddress(4,1,1))); - CPPUNIT_ASSERT_EQUAL(OUString("apple"), rDoc.GetString(ScAddress(5,1,1))); - CPPUNIT_ASSERT_EQUAL(OUString("hat"), rDoc.GetString(ScAddress(6,1,1))); - - xDocSh->DoClose(); -} - -void ScFiltersTest::testTdf125099() -{ - ScDocShellRef xDocSh = loadDoc(u"tdf125099.", FORMAT_ODS); - CPPUNIT_ASSERT_MESSAGE("Failed to open doc", xDocSh.is()); - ScDocument& rDoc = xDocSh->GetDocument(); - - CPPUNIT_ASSERT_EQUAL(OUString("03:53:46"), rDoc.GetString(ScAddress(0,0,0))); - CPPUNIT_ASSERT_EQUAL(OUString("03:23:59"), rDoc.GetString(ScAddress(0,1,0))); - - xDocSh->DoHardRecalc(); - - CPPUNIT_ASSERT_EQUAL(OUString("03:53:46"), rDoc.GetString(ScAddress(0,0,0))); - - // Without the fix in place, this would have failed with - // - Expected: 03:24:00 - // - Actual : 03:23:59 - CPPUNIT_ASSERT_EQUAL(OUString("03:24:00"), rDoc.GetString(ScAddress(0,1,0))); - - xDocSh->DoClose(); -} - -void ScFiltersTest::testTdf134455() -{ - ScDocShellRef xDocSh = loadDoc(u"tdf134455.", FORMAT_XLSX); - CPPUNIT_ASSERT_MESSAGE("Failed to open doc", xDocSh.is()); - ScDocument& rDoc = xDocSh->GetDocument(); - - CPPUNIT_ASSERT_EQUAL(OUString("00:05"), rDoc.GetString(ScAddress(3,4,0))); - CPPUNIT_ASSERT_EQUAL(OUString("00:10"), rDoc.GetString(ScAddress(3,5,0))); - CPPUNIT_ASSERT_EQUAL(OUString("00:59"), rDoc.GetString(ScAddress(3,6,0))); - - // Without the fix in place, TIMEVALUE would have returned Err:502 for values - // greater than 59 - CPPUNIT_ASSERT_EQUAL(OUString("01:05"), rDoc.GetString(ScAddress(3,7,0))); - CPPUNIT_ASSERT_EQUAL(OUString("04:00"), rDoc.GetString(ScAddress(3,8,0))); - - xDocSh->DoClose(); -} - -void ScFiltersTest::testTdf119533() -{ - ScDocShellRef xDocSh = loadDoc(u"tdf119533.", FORMAT_ODS); - CPPUNIT_ASSERT_MESSAGE("Failed to open doc", xDocSh.is()); - ScDocument& rDoc = xDocSh->GetDocument(); - - // Without fix in place, this test would have failed with - // - Expected: 0.5 - // - Actual : 0.483333333333333 - CPPUNIT_ASSERT_EQUAL(OUString("0.5"), rDoc.GetString(ScAddress(4,0,0))); - - // Without fix in place, this test would have failed with - // - Expected: 9.5 - // - Actual : 9.51666666666667 - CPPUNIT_ASSERT_EQUAL(OUString("9.5"), rDoc.GetString(ScAddress(5,0,0))); - - xDocSh->DoClose(); -} - -void ScFiltersTest::testTdf127982() -{ - ScDocShellRef xDocSh = loadDoc(u"tdf127982.", FORMAT_ODS); - CPPUNIT_ASSERT_MESSAGE("Failed to open doc", xDocSh.is()); - ScDocument& rDoc = xDocSh->GetDocument(); - - // Without the fix in place, these cells would be empty - CPPUNIT_ASSERT_EQUAL(OUString("R1"), rDoc.GetString(ScAddress(3,5,0))); - CPPUNIT_ASSERT_EQUAL(OUString("R6"), rDoc.GetString(ScAddress(3,6,0))); - CPPUNIT_ASSERT_EQUAL(OUString("R7"), rDoc.GetString(ScAddress(3,7,0))); - - CPPUNIT_ASSERT_EQUAL(OUString("R1"), rDoc.GetString(ScAddress(4,5,0))); - CPPUNIT_ASSERT_EQUAL(OUString("R6"), rDoc.GetString(ScAddress(4,6,0))); - CPPUNIT_ASSERT_EQUAL(OUString("R7"), rDoc.GetString(ScAddress(4,7,0))); - - // Without the fix in place, these cells would be empty - CPPUNIT_ASSERT_EQUAL(OUString("R1"), rDoc.GetString(ScAddress(4,5,0))); - CPPUNIT_ASSERT_EQUAL(OUString("R6"), rDoc.GetString(ScAddress(4,6,0))); - CPPUNIT_ASSERT_EQUAL(OUString("R7"), rDoc.GetString(ScAddress(4,7,0))); - - xDocSh->DoClose(); -} - -void ScFiltersTest::testTdf109409() -{ - ScDocShellRef xDocSh = loadDoc(u"tdf109409.", FORMAT_ODS); - CPPUNIT_ASSERT_MESSAGE("Failed to open doc", xDocSh.is()); - ScDocument& rDoc = xDocSh->GetDocument(); - - // TEXTJOIN - CPPUNIT_ASSERT_EQUAL(OUString("A1;B1;A2;B2;A3;B3"), rDoc.GetString(ScAddress(3,1,0))); - CPPUNIT_ASSERT_EQUAL(OUString("A1;B1;A2;B2;A3;B3"), rDoc.GetString(ScAddress(3,2,0))); - CPPUNIT_ASSERT_EQUAL(OUString("A1;A2;A3;B1;B2;B3"), rDoc.GetString(ScAddress(3,4,0))); - - // Without the fix in place, it would have failed with - //- Expected: A1;B1;A2;B2;A3;B3 - //- Actual : A1;A2;A3;B1;B2;B3 - CPPUNIT_ASSERT_EQUAL(OUString("A1;B1;A2;B2;A3;B3"), rDoc.GetString(ScAddress(3,5,0))); - - // CONCAT - CPPUNIT_ASSERT_EQUAL(OUString("A1B1A2B2A3B3"), rDoc.GetString(ScAddress(6,1,0))); - CPPUNIT_ASSERT_EQUAL(OUString("A1B1A2B2A3B3"), rDoc.GetString(ScAddress(6,2,0))); - CPPUNIT_ASSERT_EQUAL(OUString("A1A2A3B1B2B3"), rDoc.GetString(ScAddress(6,4,0))); - - // Without the fix in place, it would have failed with - //- Expected: A1B1A2B2A3B3 - //- Actual : A1A2A3B1B2B3 - CPPUNIT_ASSERT_EQUAL(OUString("A1B1A2B2A3B3"), rDoc.GetString(ScAddress(6,5,0))); - - xDocSh->DoClose(); -} - -void ScFiltersTest::testTdf132105() -{ - ScDocShellRef xDocSh = loadDoc(u"tdf132105.", FORMAT_ODS); - CPPUNIT_ASSERT_MESSAGE("Failed to open doc", xDocSh.is()); - ScDocument& rDoc = xDocSh->GetDocument(); - - // MATCH - CPPUNIT_ASSERT_EQUAL(OUString("5"), rDoc.GetString(ScAddress(0,1,0))); - CPPUNIT_ASSERT_EQUAL(OUString("5"), rDoc.GetString(ScAddress(1,1,0))); - - // COUNT - CPPUNIT_ASSERT_EQUAL(OUString("0"), rDoc.GetString(ScAddress(0,2,0))); - CPPUNIT_ASSERT_EQUAL(OUString("20"), rDoc.GetString(ScAddress(1,2,0))); - - // COUNTA - CPPUNIT_ASSERT_EQUAL(OUString("20"), rDoc.GetString(ScAddress(0,3,0))); - CPPUNIT_ASSERT_EQUAL(OUString("20"), rDoc.GetString(ScAddress(1,3,0))); - - // COUNTBLANK - // Without the fix in place, it would have failed with - // - Expected: 0 - //- Actual : Err:504 - CPPUNIT_ASSERT_EQUAL(OUString("0"), rDoc.GetString(ScAddress(0,4,0))); - CPPUNIT_ASSERT_EQUAL(OUString("0"), rDoc.GetString(ScAddress(1,4,0))); - - xDocSh->DoClose(); -} - -void ScFiltersTest::testTdf131424() -{ - ScDocShellRef xDocSh = loadDoc(u"tdf131424.", FORMAT_XLSX); - CPPUNIT_ASSERT_MESSAGE("Failed to open doc", xDocSh.is()); - ScDocument& rDoc = xDocSh->GetDocument(); - - // Without the fix in place, table reference would have failed - CPPUNIT_ASSERT_EQUAL(35.0, rDoc.GetValue(ScAddress(2,1,0))); - CPPUNIT_ASSERT_EQUAL(58.0, rDoc.GetValue(ScAddress(2,2,0))); - CPPUNIT_ASSERT_EQUAL(81.0, rDoc.GetValue(ScAddress(2,3,0))); - CPPUNIT_ASSERT_EQUAL(104.0, rDoc.GetValue(ScAddress(2,4,0))); - - xDocSh->DoClose(); -} - -void ScFiltersTest::testTdf100709XLSX() -{ - ScDocShellRef xDocSh = ScBootstrapFixture::loadDoc(u"tdf100709.", FORMAT_XLSX); - CPPUNIT_ASSERT_MESSAGE("Failed to load tdf100709.xlsx", xDocSh.is()); - - ScDocument& rDoc = xDocSh->GetDocument(); - CPPUNIT_ASSERT_EQUAL_MESSAGE("Cell B52 should not be formatted with a $", OUString("218"), rDoc.GetString(1, 51, 0)); - CPPUNIT_ASSERT_EQUAL_MESSAGE("Cell A75 should not be formatted as a date", OUString("218"), rDoc.GetString(0, 74, 0)); - - xDocSh->DoClose(); -} - -void ScFiltersTest::testTdf97598XLSX() -{ - ScDocShellRef xDocSh = loadDoc(u"tdf97598_scenarios.", FORMAT_XLSX); - CPPUNIT_ASSERT_MESSAGE("Failed to load tdf97598_scenarios.xlsx", xDocSh.is()); - - ScDocument& rDoc = xDocSh->GetDocument(); - OUString aStr = rDoc.GetString(0, 0, 0); // A1 - CPPUNIT_ASSERT_EQUAL(OUString("Cell A1"), aStr); - - xDocSh->DoClose(); -} - -void ScFiltersTest::testTdf83672XLSX() -{ - ScDocShellRef xDocSh = loadDoc(u"tdf83672.", FORMAT_XLSX); - CPPUNIT_ASSERT_MESSAGE("Failed to load tdf83672.xlsx", xDocSh.is()); - uno::Reference< drawing::XDrawPagesSupplier > xDoc( - xDocSh->GetModel(), uno::UNO_QUERY_THROW ); - uno::Reference< drawing::XDrawPage > xPage( - xDoc->getDrawPages()->getByIndex(0), uno::UNO_QUERY_THROW ); - uno::Reference< drawing::XShape > xShape( - xPage->getByIndex(0), uno::UNO_QUERY_THROW ); - uno::Reference< beans::XPropertySet > xShapeProperties( - xShape, uno::UNO_QUERY ); - sal_Int32 nRotate = 0; - xShapeProperties->getPropertyValue("RotateAngle") >>= nRotate; - CPPUNIT_ASSERT(nRotate != 0); - xDocSh->DoClose(); -} - -#ifdef UNX -void ScFiltersTest::testUnicodeFileNameGnumeric() -{ - // Mapping the LO-internal URL - // <file:///.../sc/qa/unit/data/gnumeric/t%C3%A4%C3%9Ft.gnumeric> to the - // repo's file sc/qa/unit/data/gnumeric/t\303\244\303\237t.gnumeric only - // works when the system encoding is UTF-8: - if (osl_getThreadTextEncoding() != RTL_TEXTENCODING_UTF8) { - return; - } - ScDocShellRef xDocSh = loadDoc(u"t\u00E4\u00DFt.", FORMAT_GNUMERIC); - CPPUNIT_ASSERT(xDocSh.is()); - - xDocSh->DoClose(); -} -#endif - -void ScFiltersTest::testMergedCellsXLSXML() -{ - ScDocShellRef xDocSh = loadDoc(u"merged-cells.", FORMAT_XLS_XML); - CPPUNIT_ASSERT_MESSAGE("Failed to load merged-cells.xml", xDocSh.is()); - ScDocument& rDoc = xDocSh->GetDocument(); - - // B1:C1 is merged. - ScRange aMergedRange(1,0,0); // B1 - rDoc.ExtendTotalMerge(aMergedRange); - CPPUNIT_ASSERT_EQUAL(ScRange(1,0,0,2,0,0), aMergedRange); - - // D1:F1 is merged. - aMergedRange = ScRange(3,0,0); // D1 - rDoc.ExtendTotalMerge(aMergedRange); - CPPUNIT_ASSERT_EQUAL(ScRange(3,0,0,5,0,0), aMergedRange); - - // A2:A3 is merged. - aMergedRange = ScRange(0,1,0); // A2 - rDoc.ExtendTotalMerge(aMergedRange); - CPPUNIT_ASSERT_EQUAL(ScRange(0,1,0,0,2,0), aMergedRange); - - // A4:A6 is merged. - aMergedRange = ScRange(0,3,0); // A4 - rDoc.ExtendTotalMerge(aMergedRange); - CPPUNIT_ASSERT_EQUAL(ScRange(0,3,0,0,5,0), aMergedRange); - - // C3:F6 is merged. - aMergedRange = ScRange(2,2,0); // C3 - rDoc.ExtendTotalMerge(aMergedRange); - CPPUNIT_ASSERT_EQUAL(ScRange(2,2,0,5,5,0), aMergedRange); - - xDocSh->DoClose(); -} - -void ScFiltersTest::testBackgroundColorStandardXLSXML() -{ - ScDocShellRef xDocSh = loadDoc(u"background-color-standard.", FORMAT_XLS_XML); - CPPUNIT_ASSERT_MESSAGE("Failed to load background-color-standard.xml", xDocSh.is()); - ScDocument& rDoc = xDocSh->GetDocument(); - - struct Check - { - OUString aCellValue; - Color aFontColor; - Color aBgColor; - }; - - const std::vector<Check> aChecks = - { - { OUString("Background Color"), COL_BLACK, COL_TRANSPARENT }, - { OUString("Dark Red"), COL_WHITE, Color(192, 0, 0) }, - { OUString("Red"), COL_WHITE, Color(255, 0, 0) }, - { OUString("Orange"), COL_WHITE, Color(255, 192, 0) }, - { OUString("Yellow"), COL_WHITE, Color(255, 255, 0) }, - { OUString("Light Green"), COL_WHITE, Color(146, 208, 80) }, - { OUString("Green"), COL_WHITE, Color( 0, 176, 80) }, - { OUString("Light Blue"), COL_WHITE, Color( 0, 176, 240) }, - { OUString("Blue"), COL_WHITE, Color( 0, 112, 192) }, - { OUString("Dark Blue"), COL_WHITE, Color( 0, 32, 96) }, - { OUString("Purple"), COL_WHITE, Color(112, 48, 160) }, - }; - - for (size_t nRow = 0; nRow < aChecks.size(); ++nRow) - { - ScAddress aPos(0, nRow, 0); - OUString aStr = rDoc.GetString(aPos); - CPPUNIT_ASSERT_EQUAL(aChecks[nRow].aCellValue, aStr); - - const ScPatternAttr* pPat = rDoc.GetPattern(aPos); - CPPUNIT_ASSERT(pPat); - - const SvxColorItem& rColor = pPat->GetItem(ATTR_FONT_COLOR); - CPPUNIT_ASSERT_EQUAL(aChecks[nRow].aFontColor, rColor.GetValue()); - - const SvxBrushItem& rBgColor = pPat->GetItem(ATTR_BACKGROUND); - CPPUNIT_ASSERT_EQUAL(aChecks[nRow].aBgColor, rBgColor.GetColor()); - } - - xDocSh->DoClose(); -} - -void ScFiltersTest::testTdf131536() -{ - ScDocShellRef xDocSh = loadDoc(u"tdf131536.", FORMAT_XLSX); - CPPUNIT_ASSERT_MESSAGE("Failed to load the document", xDocSh.is()); - ScDocument& rDoc = xDocSh->GetDocument(); - - ScAddress aPos(3,9,0); - CPPUNIT_ASSERT_EQUAL(1.0, rDoc.GetValue(aPos)); - ASSERT_FORMULA_EQUAL(rDoc, aPos, "IF(D$4=\"-\",\"-\",MID(TEXT(INDEX($Comparison.$I:$J,$Comparison.$A5,$Comparison.D$2),\"\"),2,4)" - "=RIGHT(TEXT(INDEX($Comparison.$L:$Z,$Comparison.$A5,$Comparison.D$4),\"\"),4))", nullptr); - - ScAddress aPos2(4,9,0); - CPPUNIT_ASSERT_EQUAL(1.0, rDoc.GetValue(aPos2)); - ASSERT_FORMULA_EQUAL(rDoc, aPos2, "IF(D$4=\"-\",\"-\",MID(TEXT(INDEX($Comparison.$I:$J,$Comparison.$A5,$Comparison.D$2),\"0\"),2,4)" - "=RIGHT(TEXT(INDEX($Comparison.$L:$Z,$Comparison.$A5,$Comparison.D$4),\"0\"),4))", nullptr); -} - -void ScFiltersTest::testTdf130583() -{ - ScDocShellRef xDocSh = loadDoc(u"tdf130583.", FORMAT_ODS); - CPPUNIT_ASSERT_MESSAGE("Failed to load the document", xDocSh.is()); - ScDocument& rDoc = xDocSh->GetDocument(); - - CPPUNIT_ASSERT_EQUAL(OUString("b"), rDoc.GetString(ScAddress(1,0,0))); - CPPUNIT_ASSERT_EQUAL(OUString("c"), rDoc.GetString(ScAddress(1,1,0))); - CPPUNIT_ASSERT_EQUAL(OUString("a"), rDoc.GetString(ScAddress(1,2,0))); - CPPUNIT_ASSERT_EQUAL(OUString("d"), rDoc.GetString(ScAddress(1,3,0))); - CPPUNIT_ASSERT_EQUAL(OUString("#N/A"), rDoc.GetString(ScAddress(1,4,0))); - - // Without the fix in place, SWITCH would have returned #VALUE! - CPPUNIT_ASSERT_EQUAL(OUString("b"), rDoc.GetString(ScAddress(4,0,0))); - CPPUNIT_ASSERT_EQUAL(OUString("c"), rDoc.GetString(ScAddress(4,1,0))); - CPPUNIT_ASSERT_EQUAL(OUString("a"), rDoc.GetString(ScAddress(4,2,0))); - CPPUNIT_ASSERT_EQUAL(OUString("d"), rDoc.GetString(ScAddress(4,3,0))); - CPPUNIT_ASSERT_EQUAL(OUString("#N/A"), rDoc.GetString(ScAddress(4,4,0))); -} - -void ScFiltersTest::testTdf85617() -{ - ScDocShellRef xDocSh = loadDoc(u"tdf85617.", FORMAT_XLSX); - CPPUNIT_ASSERT_MESSAGE("Failed to load the document", xDocSh.is()); - ScDocument& rDoc = xDocSh->GetDocument(); - - ScAddress aPos(2,2,0); - //Without the fix in place, it would be Err:509 - CPPUNIT_ASSERT_EQUAL(4.5, rDoc.GetValue(aPos)); -} - -void ScFiltersTest::testTdf134234() -{ - ScDocShellRef xDocSh = loadDoc(u"tdf134234.", FORMAT_ODS); - CPPUNIT_ASSERT_MESSAGE("Failed to load the document", xDocSh.is()); - ScDocument& rDoc = xDocSh->GetDocument(); - - CPPUNIT_ASSERT_EQUAL(3.0, rDoc.GetValue(ScAddress(1,0,1))); - - //Without the fix in place, SUMPRODUCT would have returned 0 - CPPUNIT_ASSERT_EQUAL(36.54, rDoc.GetValue(ScAddress(2,0,1))); - CPPUNIT_ASSERT_EQUAL(sal_uInt32(833), static_cast<sal_uInt32>(rDoc.GetValue(ScAddress(3,0,1)))); -} - -void ScFiltersTest::testTdf42481() -{ - ScDocShellRef xDocSh = loadDoc(u"tdf42481.", FORMAT_ODS); - CPPUNIT_ASSERT_MESSAGE("Failed to load the document", xDocSh.is()); - ScDocument& rDoc = xDocSh->GetDocument(); - - CPPUNIT_ASSERT_EQUAL(OUString("#VALUE!"), rDoc.GetString(ScAddress(3,9,0))); - - // Without the fix in place, this test would have failed with - // - Expected: #VALUE! - // - Actual : 14 - CPPUNIT_ASSERT_EQUAL(OUString("#VALUE!"), rDoc.GetString(ScAddress(3,10,0))); - CPPUNIT_ASSERT_EQUAL(OUString("14"), rDoc.GetString(ScAddress(3,11,0))); -} - -void ScFiltersTest::testNamedExpressionsXLSXML() -{ - { - // global named expressions - - ScDocShellRef xDocSh = loadDoc(u"named-exp-global.", FORMAT_XLS_XML); - CPPUNIT_ASSERT_MESSAGE("Failed to load named-exp-global.xml", xDocSh.is()); - ScDocument& rDoc = xDocSh->GetDocument(); - - // A7 - ScAddress aPos(0,6,0); - CPPUNIT_ASSERT_EQUAL(15.0, rDoc.GetValue(aPos)); - ASSERT_FORMULA_EQUAL(rDoc, aPos, "SUM(MyRange)", nullptr); - - // B7 - aPos.IncCol(); - CPPUNIT_ASSERT_EQUAL(55.0, rDoc.GetValue(aPos)); - ASSERT_FORMULA_EQUAL(rDoc, aPos, "SUM(MyRange2)", nullptr); - - const ScRangeData* pRD = rDoc.GetRangeName()->findByUpperName("MYRANGE"); - CPPUNIT_ASSERT(pRD); - pRD = rDoc.GetRangeName()->findByUpperName("MYRANGE2"); - CPPUNIT_ASSERT(pRD); - - xDocSh->DoClose(); - } - - { - // sheet-local named expressions - - ScDocShellRef xDocSh = loadDoc(u"named-exp-local.", FORMAT_XLS_XML); - CPPUNIT_ASSERT_MESSAGE("Failed to load named-exp-local.xml", xDocSh.is()); - ScDocument& rDoc = xDocSh->GetDocument(); - - // A7 on Sheet1 - ScAddress aPos(0,6,0); - CPPUNIT_ASSERT_EQUAL(27.0, rDoc.GetValue(aPos)); - ASSERT_FORMULA_EQUAL(rDoc, aPos, "SUM(MyRange)", nullptr); - - // A7 on Sheet2 - aPos.IncTab(); - CPPUNIT_ASSERT_EQUAL(74.0, rDoc.GetValue(aPos)); - ASSERT_FORMULA_EQUAL(rDoc, aPos, "SUM(MyRange)", nullptr); - - const ScRangeName* pRN = rDoc.GetRangeName(0); - CPPUNIT_ASSERT(pRN); - const ScRangeData* pRD = pRN->findByUpperName("MYRANGE"); - CPPUNIT_ASSERT(pRD); - pRN = rDoc.GetRangeName(1); - CPPUNIT_ASSERT(pRN); - pRD = pRN->findByUpperName("MYRANGE"); - CPPUNIT_ASSERT(pRD); - - xDocSh->DoClose(); - } -} - -void ScFiltersTest::testEmptyRowsXLSXML() -{ - ScDocShellRef xDocSh = loadDoc(u"empty-rows.", FORMAT_XLS_XML); - CPPUNIT_ASSERT_MESSAGE("Failed to load empty-rows.xml", xDocSh.is()); - ScDocument& rDoc = xDocSh->GetDocument(); - - { - // Expected output table content. 0 = empty cell - std::vector<std::vector<const char*>> aOutputCheck = { - { "Top row, followed by 2 empty rows.", nullptr }, - { nullptr, nullptr }, - { nullptr, nullptr }, - { nullptr, "1" }, - { nullptr, "2" }, - { nullptr, "3" }, - { nullptr, "4" }, - { nullptr, "5" }, - { nullptr, "15" }, - }; - - ScRange aDataRange; - aDataRange.Parse("A1:B9", rDoc); - bool bSuccess = checkOutput(&rDoc, aDataRange, aOutputCheck, "Expected output"); - CPPUNIT_ASSERT_MESSAGE("Table output check failed", bSuccess); - } - - ScAddress aPos; - aPos.Parse("B9", rDoc); - ASSERT_FORMULA_EQUAL(rDoc, aPos, "SUM(B4:B8)", nullptr); - - xDocSh->DoClose(); -} - -void ScFiltersTest::testBorderDirectionsXLSXML() -{ - ScDocShellRef xDocSh = loadDoc(u"border-directions.", FORMAT_XLS_XML); - CPPUNIT_ASSERT_MESSAGE("Failed to load border-directions.xml", xDocSh.is()); - ScDocument& rDoc = xDocSh->GetDocument(); - - struct Check - { - ScAddress aPos; - bool bTop; - bool bBottom; - bool bLeft; - bool bRight; - bool bTLtoBR; - bool bTRtoBL; - }; - - std::vector<Check> aChecks = { - { { 1, 1, 0 }, true, false, false, false, false, false }, // B2 - top - { { 1, 3, 0 }, false, false, true, false, false, false }, // B4 - left - { { 1, 5, 0 }, false, false, false, true, false, false }, // B6 - right - { { 1, 7, 0 }, false, true, false, false, false, false }, // B8 - bottom - { { 1, 9, 0 }, false, false, false, false, true, false }, // B10 - tl to br - { { 1, 11, 0 }, false, false, false, false, false, true }, // B12 - tr to bl - { { 1, 13, 0 }, false, false, false, false, true, true }, // B14 - cross-diagonal - }; - - auto funcCheckBorder = []( bool bHasBorder, const editeng::SvxBorderLine* pLine ) -> bool - { - if (bHasBorder) - { - if (!pLine) - { - std::cout << "Border was expected, but not found!" << std::endl; - return false; - } - - if (SvxBorderLineStyle::SOLID != pLine->GetBorderLineStyle()) - { - std::cout << "Border type was expected to be of SOLID, but is not." << std::endl; - return false; - } - - if (COL_BLACK != pLine->GetColor()) - { - std::cout << "Border color was expected to be black, but is not." << std::endl; - return false; - } - } - else - { - if (pLine) - { - std::cout << "Border was not expected, but is found!" << std::endl; - return false; - } - } - - return true; - }; - - for (const Check& c : aChecks) - { - const ScPatternAttr* pPat = rDoc.GetPattern(c.aPos); - CPPUNIT_ASSERT(pPat); - - const SvxBoxItem& rBox = pPat->GetItem(ATTR_BORDER); - - const editeng::SvxBorderLine* pLine = rBox.GetTop(); - CPPUNIT_ASSERT(funcCheckBorder(c.bTop, pLine)); - - pLine = rBox.GetBottom(); - CPPUNIT_ASSERT(funcCheckBorder(c.bBottom, pLine)); - - pLine = rBox.GetLeft(); - CPPUNIT_ASSERT(funcCheckBorder(c.bLeft, pLine)); - - pLine = rBox.GetRight(); - CPPUNIT_ASSERT(funcCheckBorder(c.bRight, pLine)); - - pLine = pPat->GetItem(ATTR_BORDER_TLBR).GetLine(); - CPPUNIT_ASSERT(funcCheckBorder(c.bTLtoBR, pLine)); - - pLine = pPat->GetItem(ATTR_BORDER_BLTR).GetLine(); - CPPUNIT_ASSERT(funcCheckBorder(c.bTRtoBL, pLine)); - } - - xDocSh->DoClose(); -} - -void ScFiltersTest::testBorderColorsXLSXML() -{ - ScDocShellRef xDocSh = loadDoc(u"border-colors.", FORMAT_XLS_XML); - CPPUNIT_ASSERT_MESSAGE("Failed to load border-colors.xml", xDocSh.is()); - ScDocument& rDoc = xDocSh->GetDocument(); - - // B3 - red - const ScPatternAttr* pPat = rDoc.GetPattern(ScAddress(1,2,0)); - CPPUNIT_ASSERT(pPat); - const editeng::SvxBorderLine* pLine = pPat->GetItem(ATTR_BORDER).GetRight(); - CPPUNIT_ASSERT(pLine); - CPPUNIT_ASSERT_EQUAL(SvxBorderLineStyle::SOLID, pLine->GetBorderLineStyle()); - CPPUNIT_ASSERT_EQUAL(Color(255,0,0), pLine->GetColor()); - - // B4 - blue - pPat = rDoc.GetPattern(ScAddress(1,3,0)); - CPPUNIT_ASSERT(pPat); - pLine = pPat->GetItem(ATTR_BORDER).GetRight(); - CPPUNIT_ASSERT(pLine); - CPPUNIT_ASSERT_EQUAL(SvxBorderLineStyle::SOLID, pLine->GetBorderLineStyle()); - CPPUNIT_ASSERT_EQUAL(Color(0,112,192), pLine->GetColor()); - - // B5 - green - pPat = rDoc.GetPattern(ScAddress(1,4,0)); - CPPUNIT_ASSERT(pPat); - pLine = pPat->GetItem(ATTR_BORDER).GetRight(); - CPPUNIT_ASSERT(pLine); - CPPUNIT_ASSERT_EQUAL(SvxBorderLineStyle::SOLID, pLine->GetBorderLineStyle()); - CPPUNIT_ASSERT_EQUAL(Color(0,176,80), pLine->GetColor()); - - // B7 - yellow (left), purple (right), light blue (cross) - pPat = rDoc.GetPattern(ScAddress(1,6,0)); - CPPUNIT_ASSERT(pPat); - - pLine = pPat->GetItem(ATTR_BORDER).GetLeft(); - CPPUNIT_ASSERT(pLine); - CPPUNIT_ASSERT_EQUAL(SvxBorderLineStyle::SOLID, pLine->GetBorderLineStyle()); - CPPUNIT_ASSERT_EQUAL(Color(255,255,0), pLine->GetColor()); // yellow - - pLine = pPat->GetItem(ATTR_BORDER).GetRight(); - CPPUNIT_ASSERT(pLine); - CPPUNIT_ASSERT_EQUAL(SvxBorderLineStyle::SOLID, pLine->GetBorderLineStyle()); - CPPUNIT_ASSERT_EQUAL(Color(112,48,160), pLine->GetColor()); // purple - - pLine = pPat->GetItem(ATTR_BORDER_TLBR).GetLine(); - CPPUNIT_ASSERT(pLine); - CPPUNIT_ASSERT_EQUAL(SvxBorderLineStyle::SOLID, pLine->GetBorderLineStyle()); - CPPUNIT_ASSERT_EQUAL(Color(0,176,240), pLine->GetColor()); // light blue - - pLine = pPat->GetItem(ATTR_BORDER_BLTR).GetLine(); - CPPUNIT_ASSERT(pLine); - CPPUNIT_ASSERT_EQUAL(SvxBorderLineStyle::SOLID, pLine->GetBorderLineStyle()); - CPPUNIT_ASSERT_EQUAL(Color(0,176,240), pLine->GetColor()); // light blue - - xDocSh->DoClose(); -} - -void ScFiltersTest::testHiddenRowsColumnsXLSXML() -{ - ScDocShellRef xDocSh = loadDoc(u"hidden-rows-columns.", FORMAT_XLS_XML); - CPPUNIT_ASSERT_MESSAGE("Failed to load hidden-rows-columns.xml", xDocSh.is()); - ScDocument& rDoc = xDocSh->GetDocument(); - - struct Check - { - SCCOLROW nPos1; - SCCOLROW nPos2; - bool bVisible; - }; - - std::vector<Check> aRowChecks = { - { 0, 0, true }, - { 1, 2, false }, - { 3, 3, true }, - { 4, 4, false }, - { 5, 7, true }, - { 8, 8, false }, - { 9, MAXROW, true }, - }; - - for (const Check& c : aRowChecks) - { - SCROW nRow1 = -1, nRow2 = -1; - bool bVisible = !rDoc.RowHidden(c.nPos1, 0, &nRow1, &nRow2); - CPPUNIT_ASSERT_EQUAL(bVisible, c.bVisible); - CPPUNIT_ASSERT_EQUAL(c.nPos1, nRow1); - CPPUNIT_ASSERT_EQUAL(c.nPos2, nRow2); - } - - std::vector<Check> aColChecks = { - { 0, 1, true }, - { 2, 5, false }, - { 6, 9, true }, - { 10, 10, false }, - { 11, MAXCOL, true }, - }; - - for (const Check& c : aColChecks) - { - SCCOL nCol1 = -1, nCol2 = -1; - bool bVisible = !rDoc.ColHidden(c.nPos1, 1, &nCol1, &nCol2); - CPPUNIT_ASSERT_EQUAL(bVisible, c.bVisible); - CPPUNIT_ASSERT_EQUAL(c.nPos1, SCCOLROW(nCol1)); - CPPUNIT_ASSERT_EQUAL(c.nPos2, SCCOLROW(nCol2)); - } - - xDocSh->DoClose(); -} - -void ScFiltersTest::testColumnWidthRowHeightXLSXML() -{ - ScDocShellRef xDocSh = loadDoc(u"column-width-row-height.", FORMAT_XLS_XML); - CPPUNIT_ASSERT_MESSAGE("Failed to load column-width-row-height.xml", xDocSh.is()); - ScDocument& rDoc = xDocSh->GetDocument(); - - struct RowHeight - { - SCROW nRow1; - SCROW nRow2; - sal_uInt16 nHeight; // in points (1 point == 20 twips) - }; - - std::vector<RowHeight> aRowChecks = { - { 2, 2, 20 }, - { 3, 3, 30 }, - { 4, 4, 40 }, - { 5, 5, 50 }, - { 7, 9, 25 }, - { 12, 13, 35 }, - }; - - for (const RowHeight& rh : aRowChecks) - { - for (SCROW i = rh.nRow1; i <= rh.nRow2; ++i) - { - sal_uInt16 nHeight = rDoc.GetRowHeight(i, 0); - CPPUNIT_ASSERT_EQUAL(sal_uInt16(rh.nHeight*20), nHeight); - } - } - - struct ColWidth - { - SCCOL nCol1; - SCCOL nCol2; - sal_uInt16 nWidth; // in points (1 point == 20 twips - }; - - std::vector<ColWidth> aColChecks = { - { 1, 1, 56 }, - { 2, 2, 83 }, - { 3, 3, 109 }, - { 5, 7, 67 }, - { 10, 11, 119 }, - }; - - for (const ColWidth& cw : aColChecks) - { - for (SCCOL i = cw.nCol1; i <= cw.nCol2; ++i) - { - sal_uInt16 nWidth = rDoc.GetColWidth(i, 0); - CPPUNIT_ASSERT_EQUAL(sal_uInt16(cw.nWidth*20), nWidth); - } - } - - xDocSh->DoClose(); -} - -void ScFiltersTest::testCharacterSetXLSXML() -{ - ScDocShellRef xDocSh = loadDoc(u"character-set.", FORMAT_XLS_XML); - CPPUNIT_ASSERT_MESSAGE("Failed to load column-width-row-height.xml", xDocSh.is()); - ScDocument& rDoc = xDocSh->GetDocument(); - - CPPUNIT_ASSERT_EQUAL(SCTAB(1), rDoc.GetTableCount()); - - OUString aName; - rDoc.GetName(0, aName); - - // Check the sheet name. The values are all Cyrillic letters. - std::vector<sal_Unicode> aBuf = { 0x041b, 0x0438, 0x0441, 0x0442, 0x0031 }; - OUString aExpected(aBuf.data(), aBuf.size()); - CPPUNIT_ASSERT_EQUAL(aExpected, aName); - - // Check the value of I4 - OUString aVal = rDoc.GetString(ScAddress(8,3,0)); - aBuf = { 0x0421, 0x0443, 0x043c, 0x043c, 0x0430 }; - aExpected = OUString(aBuf.data(), aBuf.size()); - CPPUNIT_ASSERT_EQUAL(aExpected, aVal); - - // Check the value of J3 - aVal = rDoc.GetString(ScAddress(9,2,0)); - aBuf = { 0x041e, 0x0441, 0x0442, 0x0430, 0x0442, 0x043e, 0x043a }; - aExpected = OUString(aBuf.data(), aBuf.size()); - CPPUNIT_ASSERT_EQUAL(aExpected, aVal); - - xDocSh->DoClose(); -} - -void ScFiltersTest::testCondFormatXLSB() -{ - ScDocShellRef xDocSh = loadDoc(u"cond_format.", FORMAT_XLSB); - - ScDocument& rDoc = xDocSh->GetDocument(); - ScConditionalFormatList* pList = rDoc.GetCondFormList(0); - CPPUNIT_ASSERT(pList); - - CPPUNIT_ASSERT_EQUAL(size_t(1), pList->size()); - ScConditionalFormat* pFormat = pList->begin()->get(); - CPPUNIT_ASSERT(pFormat); - CPPUNIT_ASSERT_EQUAL(size_t(1), pFormat->size()); - - xDocSh->DoClose(); -} - -void ScFiltersTest::testPageScalingXLSX() -{ - ScDocShellRef xDocSh = loadDoc(u"page_scale.", FORMAT_XLSX); - ScDocument& rDoc = xDocSh->GetDocument(); - - OUString aStyleName = rDoc.GetPageStyle(0); - ScStyleSheetPool* pStylePool = rDoc.GetStyleSheetPool(); - SfxStyleSheetBase* pStyleSheet = pStylePool->Find( aStyleName, SfxStyleFamily::Page ); - CPPUNIT_ASSERT(pStyleSheet); - - SfxItemSet& rSet = pStyleSheet->GetItemSet(); - sal_uInt16 nVal = rSet.Get(ATTR_PAGE_SCALE).GetValue(); - CPPUNIT_ASSERT_EQUAL(sal_uInt16(90), nVal); - - xDocSh->DoClose(); -} - -void ScFiltersTest::testActiveXCheckboxXLSX() -{ - ScDocShellRef xDocSh = loadDoc(u"activex_checkbox.", FORMAT_XLSX); - uno::Reference< frame::XModel > xModel = xDocSh->GetModel(); - uno::Reference< sheet::XSpreadsheetDocument > xDoc(xModel, UNO_QUERY_THROW); - uno::Reference< container::XIndexAccess > xIA(xDoc->getSheets(), UNO_QUERY_THROW); - uno::Reference< drawing::XDrawPageSupplier > xDrawPageSupplier(xIA->getByIndex(0), UNO_QUERY_THROW); - uno::Reference< container::XIndexAccess > xIA_DrawPage(xDrawPageSupplier->getDrawPage(), UNO_QUERY_THROW); - uno::Reference< drawing::XControlShape > xControlShape(xIA_DrawPage->getByIndex(0), UNO_QUERY_THROW); - - // Check control type - uno::Reference<beans::XPropertySet> xPropertySet(xControlShape->getControl(), uno::UNO_QUERY); - uno::Reference<lang::XServiceInfo> xServiceInfo(xPropertySet, uno::UNO_QUERY); - CPPUNIT_ASSERT_EQUAL(true, bool(xServiceInfo->supportsService("com.sun.star.form.component.CheckBox"))); - - // Check custom label - OUString sLabel; - xPropertySet->getPropertyValue("Label") >>= sLabel; - CPPUNIT_ASSERT_EQUAL(OUString("Custom Caption"), sLabel); - - // Check background color (highlight system color) - sal_Int32 nColor; - xPropertySet->getPropertyValue("BackgroundColor") >>= nColor; - CPPUNIT_ASSERT_EQUAL(sal_Int32(0x316AC5), nColor); - - // Check Text color (active border system color) - xPropertySet->getPropertyValue("TextColor") >>= nColor; - CPPUNIT_ASSERT_EQUAL(sal_Int32(0xD4D0C8), nColor); - - // Check state of the checkbox - sal_Int16 nState; - xPropertySet->getPropertyValue("State") >>= nState; - CPPUNIT_ASSERT_EQUAL(sal_Int16(1), nState); - - xDocSh->DoClose(); -} - -void ScFiltersTest::testtdf120301_xmlSpaceParsingXLSX() -{ - ScDocShellRef xDocSh = loadDoc(u"tdf120301_xmlSpaceParsing.", FORMAT_XLSX); - uno::Reference< frame::XModel > xModel = xDocSh->GetModel(); - uno::Reference< sheet::XSpreadsheetDocument > xDoc(xModel, UNO_QUERY_THROW); - uno::Reference< container::XIndexAccess > xIA(xDoc->getSheets(), UNO_QUERY_THROW); - uno::Reference< drawing::XDrawPageSupplier > xDrawPageSupplier( xIA->getByIndex(0), UNO_QUERY_THROW); - uno::Reference< container::XIndexAccess > xIA_DrawPage(xDrawPageSupplier->getDrawPage(), UNO_QUERY_THROW); - - uno::Reference< drawing::XControlShape > xControlShape(xIA_DrawPage->getByIndex(0), UNO_QUERY_THROW); - uno::Reference< beans::XPropertySet > XPropSet( xControlShape->getControl(), uno::UNO_QUERY_THROW ); - OUString sCaption; - XPropSet->getPropertyValue("Label") >>= sCaption; - CPPUNIT_ASSERT_EQUAL(OUString("Check Box 1"), sCaption); - xDocSh->DoClose(); -} - -namespace { - -struct PaintListener : public SfxListener -{ - bool mbCalled = false; - virtual void Notify(SfxBroadcaster& /*rBC*/, const SfxHint& rHint) override - { - const ScPaintHint* pPaintHint = dynamic_cast<const ScPaintHint*>(&rHint); - if (pPaintHint) - { - if (pPaintHint->GetStartCol() <= 0 && pPaintHint->GetEndCol() >= 0 - && pPaintHint->GetStartRow() <= 9 && pPaintHint->GetEndRow() >= 9) - { - mbCalled = true; - } - } - } -}; - -} - -void ScFiltersTest::testCondFormatFormulaListenerXLSX() -{ - ScDocShellRef xDocSh = loadDoc(u"cond_format_formula_listener.", FORMAT_XLSX); - PaintListener aListener; - aListener.StartListening(*xDocSh); - ScDocument& rDoc = xDocSh->GetDocument(); - ScConditionalFormatList* pList = rDoc.GetCondFormList(0); - CPPUNIT_ASSERT(pList); - - CPPUNIT_ASSERT_EQUAL(size_t(1), pList->size()); - ScConditionalFormat* pFormat = pList->begin()->get(); - CPPUNIT_ASSERT(pFormat); - rDoc.SetDocVisible(true); - rDoc.SetValue(0, 0, 0, 2.0); - - CPPUNIT_ASSERT(aListener.mbCalled); - - xDocSh->DoClose(); -} - -void ScFiltersTest::testTdf137091() -{ - // Set the system locale to Turkish - SvtSysLocaleOptions aOptions; - OUString sLocaleConfigString = aOptions.GetLanguageTag().getBcp47(); - aOptions.SetLocaleConfigString("tr-TR"); - aOptions.Commit(); - comphelper::ScopeGuard g([&aOptions, &sLocaleConfigString] { - aOptions.SetLocaleConfigString(sLocaleConfigString); - aOptions.Commit(); - }); - - ScDocShellRef xDocSh = loadDoc(u"tdf137091.", FORMAT_XLSX); - ScDocument& rDoc = xDocSh->GetDocument(); - - // Without the fix in place, this test would have failed with - // - Expected: 28/4 - // - Actual : Err:507 - CPPUNIT_ASSERT_EQUAL(OUString("28/4"), rDoc.GetString(ScAddress(2,1,0))); - xDocSh->DoClose(); -} - -void ScFiltersTest::testTdf62268() -{ - ScDocShellRef xDocSh = loadDoc(u"tdf62268.", FORMAT_ODS); - ScDocument& rDoc = xDocSh->GetDocument(); - int nHeight; - - SCTAB nTab = 0; - nHeight = rDoc.GetRowHeight(0, nTab, false); - CPPUNIT_ASSERT_LESSEQUAL( 3, abs( 256 - nHeight ) ); - nHeight = rDoc.GetRowHeight(1, nTab, false); - CPPUNIT_ASSERT_LESSEQUAL( 19, abs( 1905 - nHeight ) ); - - xDocSh->DoClose(); -} - -void ScFiltersTest::testTdf137453() -{ - ScDocShellRef xDocSh = loadDoc(u"tdf137453.", FORMAT_ODS); - CPPUNIT_ASSERT_MESSAGE("Failed to open doc", xDocSh.is()); - - ScDocument& rDoc = xDocSh->GetDocument(); - - // Without the fix in place, this test would have failed with - // - Expected: 3333333333/100 - // - Actual : -961633963/100 - CPPUNIT_ASSERT_EQUAL(OUString("3333333333/100"), rDoc.GetString(ScAddress(0,0,0))); - - xDocSh->DoClose(); -} - -void ScFiltersTest::testTdf112780() -{ - ScDocShellRef xDocSh = loadDoc(u"tdf112780.", FORMAT_ODS); - CPPUNIT_ASSERT_MESSAGE("Failed to open doc", xDocSh.is()); - - ScDocument& rDoc = xDocSh->GetDocument(); - - // Without the fix in place, this test would have failed with - // - Expected: - // - Actual : #VALUE! - CPPUNIT_ASSERT_EQUAL(OUString(""), rDoc.GetString(ScAddress(3,5,0))); - - OUString aFormula; - rDoc.GetFormula(3, 5, 0, aFormula); - CPPUNIT_ASSERT_EQUAL(OUString("=G6+J6+M6"), aFormula); - - xDocSh->DoClose(); -} - -void ScFiltersTest::testTdf72470() -{ - // Without the fix in place, this test would have hung - - ScDocShellRef xDocSh = loadDoc(u"tdf72470.", FORMAT_XLS); - CPPUNIT_ASSERT_MESSAGE("Failed to open doc", xDocSh.is()); - - ScDocument& rDoc = xDocSh->GetDocument(); - - CPPUNIT_ASSERT_EQUAL(OUString("name"), rDoc.GetString(ScAddress(0,0,0))); - CPPUNIT_ASSERT_EQUAL(OUString(u"أسمي walid"), rDoc.GetString(ScAddress(0,1,0))); - - xDocSh->DoClose(); -} - -void ScFiltersTest::testTdf35636() -{ - ScDocShellRef xDocSh = loadDoc(u"tdf35636.", FORMAT_ODS); - CPPUNIT_ASSERT_MESSAGE("Failed to open doc", xDocSh.is()); - - ScDocument& rDoc = xDocSh->GetDocument(); - - // Without the fix in place, SUMIF would have returned 0.0 - // with empty cells in the criteria - CPPUNIT_ASSERT_EQUAL(50.0, rDoc.GetValue(ScAddress(1,4,0))); - - xDocSh->DoClose(); -} - -void ScFiltersTest::testTdf98481() -{ - ScDocShellRef xDocSh = loadDoc(u"tdf98481.", FORMAT_XLSX); - CPPUNIT_ASSERT_MESSAGE("Failed to open doc", xDocSh.is()); - - ScDocument& rDoc = xDocSh->GetDocument(); - - // Without the fix in place, this test would have failed with - // - Expected: 4 - // - Actual : 0 - CPPUNIT_ASSERT_EQUAL(4.0, rDoc.GetValue(ScAddress(4,1,0))); - CPPUNIT_ASSERT_EQUAL(0.0, rDoc.GetValue(ScAddress(4,2,0))); - CPPUNIT_ASSERT_EQUAL(3.0, rDoc.GetValue(ScAddress(4,3,0))); - CPPUNIT_ASSERT_EQUAL(4.0, rDoc.GetValue(ScAddress(1,4,0))); - CPPUNIT_ASSERT_EQUAL(0.0, rDoc.GetValue(ScAddress(2,4,0))); - CPPUNIT_ASSERT_EQUAL(3.0, rDoc.GetValue(ScAddress(3,4,0))); - - xDocSh->DoClose(); -} - -void ScFiltersTest::testTdf115022() -{ - ScDocShellRef xDocSh = loadDoc(u"tdf115022.", FORMAT_XLSX); - CPPUNIT_ASSERT_MESSAGE("Failed to open doc", xDocSh.is()); - - ScDocument& rDoc = xDocSh->GetDocument(); - - CPPUNIT_ASSERT_EQUAL(6.0, rDoc.GetValue(ScAddress(1,8,0))); - - xDocSh->DoHardRecalc(); - - // Without the fix in place, this test would have failed with - // - Expected: 6 - // - Actual : 21 - CPPUNIT_ASSERT_EQUAL(6.0, rDoc.GetValue(ScAddress(1,8,0))); - - xDocSh->DoClose(); -} - -void ScFiltersTest::testVBAMacroFunctionODS() -{ - ScDocShellRef xDocSh = loadDoc(u"vba_macro_functions.", FORMAT_ODS); - ScDocument& rDoc = xDocSh->GetDocument(); - - OUString aFunction; - rDoc.GetFormula(2, 0, 0, aFunction); - std::cout << aFunction << std::endl; - CPPUNIT_ASSERT_DOUBLES_EQUAL(10.0, rDoc.GetValue(2, 0, 0), 1e-6); - - xDocSh->DoClose(); -} - -void ScFiltersTest::testAutoheight2Rows() -{ - ScDocShellRef xDocSh = loadDoc(u"autoheight2rows.", FORMAT_ODS); - ScDocument& rDoc = xDocSh->GetDocument(); - - SCTAB nTab = 0; - int nHeight1 = rDoc.GetRowHeight(0, nTab, false); - int nHeight2 = rDoc.GetRowHeight(1, nTab, false); - int nHeight4 = rDoc.GetRowHeight(3, nTab, false); - int nHeight5 = rDoc.GetRowHeight(4, nTab, false); - - // We will do relative comparison, because calculated autoheight - // can be different on different platforms - CPPUNIT_ASSERT_MESSAGE("Row #1 and row #4 must have same height after load & auto-adjust", - abs( nHeight1 - nHeight4 ) < 10 ); - CPPUNIT_ASSERT_MESSAGE("Row #2 and row #5 must have same height after load & auto-adjust", - abs( nHeight2 - nHeight5 ) < 10 ); - - xDocSh->DoClose(); -} - -void ScFiltersTest::testXLSDefColWidth() -{ - // XLS has only 256 columns; but on import, we need to set default width to all above that limit - ScDocShellRef xDocSh = loadDoc(u"chartx.", FORMAT_XLS); // just some XLS with narrow columns - ScDocument& rDoc = xDocSh->GetDocument(); - - int nWidth = rDoc.GetColWidth(MAXCOL, 0, false); - // This was 1280 - CPPUNIT_ASSERT_EQUAL(1005, nWidth); - - xDocSh->DoClose(); -} - -void ScFiltersTest::testPreviewMissingObjLink() -{ - ScDocShellRef xDocSh = loadDoc(u"keep-preview-missing-obj-link.", FORMAT_ODS); - CPPUNIT_ASSERT_MESSAGE("Failed to load keep-preview-missing-obj-link.ods.", xDocSh.is()); - - ScDocument& rDoc = xDocSh->GetDocument(); - - // Retrieve the ole object - const SdrOle2Obj* pOleObj = getSingleOleObject(rDoc, 0); - CPPUNIT_ASSERT_MESSAGE("Failed to retrieve an ole object from the 2nd sheet.", pOleObj); - - const Graphic* pGraphic = pOleObj->GetGraphic(); - CPPUNIT_ASSERT_MESSAGE("the ole object links to a missing file, but we should retain its preview", pGraphic); - - xDocSh->DoClose(); -} - -void ScFiltersTest::testShapeRotationImport() -{ - if (!IsDefaultDPI()) - return; - // tdf#83593 Incorrectly calculated bounding rectangles caused shapes to appear as if there - // were extra or missing rotations. Hence, we check the sizes of these rectangles. - ScDocShellRef xDocSh = loadDoc(u"testShapeRotationImport.", FORMAT_XLSX); - CPPUNIT_ASSERT_MESSAGE("Failed to load testShapeRotationImport.xlsx", xDocSh.is()); - uno::Reference< drawing::XDrawPagesSupplier > xDoc(xDocSh->GetModel(), uno::UNO_QUERY_THROW); - uno::Reference< drawing::XDrawPage > xPage(xDoc->getDrawPages()->getByIndex(0), uno::UNO_QUERY_THROW); - - // The expected values are in the map below. Note that some of the angles are outside of the set which contains - // the value of the wrong angles. This is to check the border cases and one value on both sides. - std::map<sal_Int32, std::map<std::string, sal_Int32>> aExpectedValues - { - { 4400, { { "x", 6832 }, { "y", 36893 }, { "width", 8898 }, { "height", 1163 } } }, - { 4500, { { "x", 4490 }, { "y", 36400 }, { "width", 8898 }, { "height", 1163 } } }, - { 4600, { { "x", 1673 }, { "y", 36270 }, { "width", 8862 }, { "height", 1144 } } }, - { 13400, { { "x", 13762 }, { "y", 28403 }, { "width", 8863 }, { "height", 1194 } } }, - { 13500, { { "x", 10817 }, { "y", 27951 }, { "width", 8863 }, { "height", 1170 } } }, - { 13600, { { "x", 8449 }, { "y", 28336 }, { "width", 8897 }, { "height", 1164 } } }, - { 22400, { { "x", 14948 }, { "y", 12978 }, { "width", 8898 }, { "height", 1164 } } }, - { 22500, { { "x", 11765 }, { "y", 12834 }, { "width", 8898 }, { "height", 1164 } } }, - { 22600, { { "x", 8253 }, { "y", 12919 }, { "width", 8863 }, { "height", 1171 } } }, - { 31400, { { "x", 8099 }, { "y", 1160 }, { "width", 9815 }, { "height", 1171 } } }, - { 31500, { { "x", 4427 }, { "y", 1274 }, { "width", 10238 }, { "height", 1171 } } }, - { 31600, { { "x", 1964 }, { "y", 1878 }, { "width", 10307 }, { "height", 1164 } } }, - }; - - for (sal_Int32 ind = 0; ind < 12; ++ind) - { - uno::Reference< drawing::XShape > xShape(xPage->getByIndex(ind), uno::UNO_QUERY_THROW); - - uno::Reference< beans::XPropertySet > xShapeProperties(xShape, uno::UNO_QUERY); - uno::Any nRotProp = xShapeProperties->getPropertyValue("RotateAngle"); - sal_Int32 nRot = nRotProp.get<sal_Int32>(); - - awt::Point aPosition = xShape->getPosition(); - awt::Size aSize = xShape->getSize(); - - CPPUNIT_ASSERT(aExpectedValues.find(nRot) != aExpectedValues.end()); - CPPUNIT_ASSERT_EQUAL(aExpectedValues[nRot]["x"], aPosition.X); - CPPUNIT_ASSERT_EQUAL(aExpectedValues[nRot]["y"], aPosition.Y); - CPPUNIT_ASSERT_EQUAL(aExpectedValues[nRot]["width"], aSize.Width); - CPPUNIT_ASSERT_EQUAL(aExpectedValues[nRot]["height"], aSize.Height); - } -} - -void ScFiltersTest::testShapeDisplacementOnRotationImport() -{ - // tdf#135918 shape is displaced on rotation if it is placed next to the sheets upper/left edges - ScDocShellRef xDocSh = loadDoc(u"testShapeDisplacementOnRotationImport.", FORMAT_XLSX); - CPPUNIT_ASSERT_MESSAGE("Failed to load testShapeDisplacementOnRotationImport.xlsx", xDocSh.is()); - - uno::Reference<drawing::XDrawPagesSupplier> xDoc(xDocSh->GetModel(), uno::UNO_QUERY_THROW); - uno::Reference<drawing::XDrawPage> xPage(xDoc->getDrawPages()->getByIndex(0), uno::UNO_QUERY_THROW); - uno::Reference<drawing::XShape> xShape(xPage->getByIndex(0), uno::UNO_QUERY_THROW); - - uno::Reference<beans::XPropertySet> xShapeProperties(xShape, uno::UNO_QUERY_THROW); - uno::Any aRectProp = xShapeProperties->getPropertyValue("FrameRect"); - awt::Rectangle aRectangle = aRectProp.get<awt::Rectangle>(); - CPPUNIT_ASSERT_EQUAL(sal_Int32(0), aRectangle.X); - CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aRectangle.Y); -} - -void ScFiltersTest::testTextBoxBodyUpright() -{ - // tdf#106197 We should import the "upright" attribute of txBody. - ScDocShellRef xDocSh = loadDoc(u"tdf106197_import_upright.", FORMAT_XLSX); - CPPUNIT_ASSERT_MESSAGE("Failed to load testTextBoxBodyUpright.xlsx", xDocSh.is()); - - uno::Reference<drawing::XDrawPagesSupplier> xDoc(xDocSh->GetModel(), uno::UNO_QUERY_THROW); - uno::Reference<drawing::XDrawPage> xPage(xDoc->getDrawPages()->getByIndex(0), uno::UNO_QUERY_THROW); - uno::Reference<drawing::XShape> xShape(xPage->getByIndex(0), uno::UNO_QUERY_THROW); - uno::Reference<beans::XPropertySet> xShapeProperties(xShape, uno::UNO_QUERY_THROW); - - // Check that we imported "Upright". - bool isUpright = false; - if (xShapeProperties->getPropertySetInfo()->hasPropertyByName("InteropGrabBag")) - { - uno::Sequence<beans::PropertyValue> aGrabBag; - xShapeProperties->getPropertyValue("InteropGrabBag") >>= aGrabBag; - for (auto& aProp : aGrabBag) - { - if (aProp.Name == "Upright") - { - aProp.Value >>= isUpright; - break; - } - } - } - CPPUNIT_ASSERT_EQUAL(true, isUpright); - - // Check the new textRotateAngle. - sal_Int32 nAngle; - uno::Any aGeom = xShapeProperties->getPropertyValue("CustomShapeGeometry"); - auto aGeomSeq = aGeom.get<Sequence<beans::PropertyValue>>(); - for (const auto& aProp : std::as_const(aGeomSeq)) - { - if (aProp.Name == "TextPreRotateAngle") - { - aProp.Value >>= nAngle; - break; - } - } - CPPUNIT_ASSERT_EQUAL(sal_Int32(90), nAngle); -} - -void ScFiltersTest::testTextBoxBodyRotateAngle() -{ - ScDocShellRef xDocSh = loadDoc(u"tdf141644.", FORMAT_XLSX); - CPPUNIT_ASSERT_MESSAGE("Failed to load tdf141644.xlsx", xDocSh.is()); - - uno::Reference<drawing::XDrawPagesSupplier> xDoc(xDocSh->GetModel(), uno::UNO_QUERY_THROW); - uno::Reference<drawing::XDrawPage> xPage(xDoc->getDrawPages()->getByIndex(0), uno::UNO_QUERY_THROW); - uno::Reference<drawing::XShape> xShape(xPage->getByIndex(0), uno::UNO_QUERY_THROW); - uno::Reference<beans::XPropertySet> xShapeProperties(xShape, uno::UNO_QUERY_THROW); - - // Check the new textRotateAngle. - sal_Int32 nAngle; - uno::Any aGeom = xShapeProperties->getPropertyValue("CustomShapeGeometry"); - auto aGeomSeq = aGeom.get<Sequence<beans::PropertyValue>>(); - for (const auto& aProp : std::as_const(aGeomSeq)) - { - if (aProp.Name == "TextPreRotateAngle") - { - aProp.Value >>= nAngle; - break; - } - } - CPPUNIT_ASSERT_EQUAL(sal_Int32(-270), nAngle); -} - -void ScFiltersTest::testTextLengthDataValidityXLSX() -{ - ScDocShellRef xDocSh = loadDoc(u"textLengthDataValidity.", FORMAT_XLSX); - CPPUNIT_ASSERT_MESSAGE("Failed to load textLengthDataValidity.xlsx", xDocSh.is()); - - ScDocument& rDoc = xDocSh->GetDocument(); - - const ScValidationData* pData = rDoc.GetValidationEntry(1); - - ScRefCellValue aCellA1; // A1 = 1234(numeric value) - ScAddress aValBaseAddrA1( 0,0,0 ); - aCellA1.assign(rDoc, aValBaseAddrA1); - bool bValidA1 = pData->IsDataValid(aCellA1, aValBaseAddrA1); - - ScRefCellValue aCellA2; // A2 = 1234(numeric value format as text) - ScAddress aValBaseAddrA2( 0,1,0 ); - aCellA2.assign(rDoc, aValBaseAddrA2); - bool bValidA2 = pData->IsDataValid(aCellA2, aValBaseAddrA2); - - ScRefCellValue aCellA3; // A3 = 1234.00(numeric value) - ScAddress aValBaseAddrA3( 0,2,0 ); - aCellA3.assign(rDoc, aValBaseAddrA3); - bool bValidA3 = pData->IsDataValid(aCellA3, aValBaseAddrA3); - - ScRefCellValue aCellA4; // A4 = 12.3(numeric value) - ScAddress aValBaseAddrA4( 0,3,0 ); - aCellA4.assign(rDoc, aValBaseAddrA4); - bool bValidA4 = pData->IsDataValid(aCellA4, aValBaseAddrA4); + CPPUNIT_ASSERT_EQUAL(OUString("Lamb"), rDoc.GetString(ScAddress(4, 2, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("Beef"), rDoc.GetString(ScAddress(4, 3, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("Pork"), rDoc.GetString(ScAddress(4, 4, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("Goat"), rDoc.GetString(ScAddress(4, 5, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("Goat"), rDoc.GetString(ScAddress(4, 6, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("#VALUE!"), rDoc.GetString(ScAddress(4, 7, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("#VALUE!"), rDoc.GetString(ScAddress(4, 8, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("Deer"), rDoc.GetString(ScAddress(4, 9, 0))); - // True if text length = 4 - CPPUNIT_ASSERT_EQUAL(true, bValidA1); - CPPUNIT_ASSERT_EQUAL(true, bValidA2); - CPPUNIT_ASSERT_EQUAL(true, bValidA3); - CPPUNIT_ASSERT_EQUAL(true, bValidA4); + CPPUNIT_ASSERT_EQUAL(OUString("1"), rDoc.GetString(ScAddress(6, 2, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("2"), rDoc.GetString(ScAddress(6, 3, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("3"), rDoc.GetString(ScAddress(6, 4, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("5"), rDoc.GetString(ScAddress(6, 5, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("8"), rDoc.GetString(ScAddress(6, 6, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("#VALUE!"), rDoc.GetString(ScAddress(6, 7, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("#VALUE!"), rDoc.GetString(ScAddress(6, 8, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("#VALUE!"), rDoc.GetString(ScAddress(6, 9, 0))); xDocSh->DoClose(); } -void ScFiltersTest::testDeleteCircles() -{ - ScDocShellRef xDocSh = loadDoc(u"testDeleteCircles.", FORMAT_XLSX); - CPPUNIT_ASSERT_MESSAGE("Failed to load testDeleteCircles.xlsx", xDocSh.is()); - - ScDocument& rDoc = xDocSh->GetDocument(); - - ScDrawLayer* pDrawLayer = rDoc.GetDrawLayer(); - SdrPage* pPage = pDrawLayer->GetPage(0); - CPPUNIT_ASSERT_MESSAGE("draw page for sheet 1 should exist.", pPage); - - ScRefCellValue aCellA1; // A1 = "Hello" - ScAddress aPosA1(0, 0, 0); - aCellA1.assign(rDoc, aPosA1); - - // Mark invalid value - bool bOverflow; - bool bMarkInvalid = ScDetectiveFunc(rDoc, 0).MarkInvalid(bOverflow); - CPPUNIT_ASSERT_EQUAL(true, bMarkInvalid); - - // There should be a circle object! - CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), pPage->GetObjCount()); - - // The value of A1 change to Hello1. - rDoc.SetString(0, 0, 0, "Hello1"); - - // Check that the data is valid.(True if text length = 6) - const ScValidationData* pData = rDoc.GetValidationEntry(1); - bool bValidA1 = pData->IsDataValid(aCellA1, aPosA1); - // if valid, delete circle. - if (bValidA1) - ScDetectiveFunc(rDoc, 0).DeleteCirclesAt(aPosA1.Col(), aPosA1.Row()); - - // There should not be a circle object! - CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(0), pPage->GetObjCount()); - - xDocSh->DoClose(); -} - -void ScFiltersTest::testDrawCircleInMergeCells() -{ - ScDocShellRef xDocSh = loadDoc(u"testDrawCircleInMergeCells.", FORMAT_XLSX); - CPPUNIT_ASSERT_MESSAGE("Failed to load testDrawCircleInMergeCells.ods", xDocSh.is()); - - ScDocument& rDoc = xDocSh->GetDocument(); - - ScDrawLayer* pDrawLayer = rDoc.GetDrawLayer(); - SdrPage* pPage = pDrawLayer->GetPage(0); - CPPUNIT_ASSERT_MESSAGE("draw page for sheet 1 should exist.", pPage); - - // A1:B2 is merged. - ScRange aMergedRange(0,0,0); - rDoc.ExtendTotalMerge(aMergedRange); - CPPUNIT_ASSERT_EQUAL(ScRange(0,0,0,1,1,0), aMergedRange); - - // Mark invalid value - bool bOverflow; - bool bMarkInvalid = ScDetectiveFunc(rDoc, 0).MarkInvalid(bOverflow); - CPPUNIT_ASSERT_EQUAL(true, bMarkInvalid); - - // There should be a circle object! - CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), pPage->GetObjCount()); - - SdrObject* pObj = pPage->GetObj(0); - tools::Rectangle aRect(pObj->GetLogicRect()); - Point aStartCircle = aRect.TopLeft(); - Point aEndCircle = aRect.BottomRight(); - - tools::Rectangle aCellRect = rDoc.GetMMRect(0,0,1,1,0); - aCellRect.AdjustLeft( -250 ); - aCellRect.AdjustRight(250 ); - aCellRect.AdjustTop( -70 ); - aCellRect.AdjustBottom(70 ); - Point aStartCell = aCellRect.TopLeft(); - Point aEndCell = aCellRect.BottomRight(); - - CPPUNIT_ASSERT_EQUAL(aStartCell.X(), aStartCircle.X()); - CPPUNIT_ASSERT_EQUAL(aEndCell.X(), aEndCircle.X()); - CPPUNIT_ASSERT_EQUAL(aStartCell.Y(), aStartCircle.Y()); - CPPUNIT_ASSERT_EQUAL(aEndCell.Y(), aEndCircle.Y()); - - // Change the height of the first row. (556 ~ 1cm) - rDoc.SetRowHeight(0, 0, 556); - ScDrawObjData* pData = ScDrawLayer::GetObjData(pObj); - pDrawLayer->RecalcPos(pObj,*pData,false,false); - - tools::Rectangle aRecalcRect(pObj->GetLogicRect()); - Point aStartRecalcCircle = aRecalcRect.TopLeft(); - Point aEndRecalcCircle = aRecalcRect.BottomRight(); - - tools::Rectangle aRecalcCellRect = rDoc.GetMMRect(0,0,1,1,0); - aRecalcCellRect.AdjustLeft( -250 ); - aRecalcCellRect.AdjustRight(250 ); - aRecalcCellRect.AdjustTop( -70 ); - aRecalcCellRect.AdjustBottom(70 ); - Point aStartRecalcCell = aRecalcCellRect.TopLeft(); - Point aEndRecalcCell1 = aRecalcCellRect.BottomRight(); - - CPPUNIT_ASSERT_EQUAL(aStartRecalcCell.X(), aStartRecalcCircle.X()); - CPPUNIT_ASSERT_EQUAL(aEndRecalcCell1.X(), aEndRecalcCircle.X()); - CPPUNIT_ASSERT_EQUAL(aStartRecalcCell.Y(), aStartRecalcCircle.Y()); - CPPUNIT_ASSERT_EQUAL(aEndRecalcCell1.Y(), aEndRecalcCircle.Y()); - - xDocSh->DoClose(); -} - -void ScFiltersTest::testDeleteCirclesInRowAndCol() -{ - ScDocShellRef xDocSh = loadDoc(u"deleteCirclesInRowAndCol.", FORMAT_ODS); - CPPUNIT_ASSERT_MESSAGE("Failed to load deleteCirclesInRowAndCol.ods", xDocSh.is()); - - ScDocument& rDoc = xDocSh->GetDocument(); - - ScDrawLayer* pDrawLayer = rDoc.GetDrawLayer(); - SdrPage* pPage = pDrawLayer->GetPage(0); - CPPUNIT_ASSERT_MESSAGE("draw page for sheet 1 should exist.", pPage); - - // There should be 6 circle objects! - CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(6), pPage->GetObjCount()); - - // Delete first row (1023 = MAXCOLS) - pDrawLayer->DeleteObjectsInArea(0,0,0,1023,0,true); - - // There should be 3 circle objects! - CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(3), pPage->GetObjCount()); - - // Delete first col (1048575 = MAXROWS) - pDrawLayer->DeleteObjectsInArea(0,0,0,0,1048575,true); - - // There should not be a circle object! - CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(0), pPage->GetObjCount()); - - xDocSh->DoClose(); -} - -void ScFiltersTest::testTdf129940() -{ - // Test pure span elements inside text:ruby-base - ScDocShellRef xDocSh = loadDoc(u"tdf129940.", FORMAT_ODS); - CPPUNIT_ASSERT_MESSAGE("Failed to load tdf129940.ods", xDocSh.is()); - ScDocument& rDoc = xDocSh->GetDocument(); - // Pure text within text:ruby-base - OUString aStr = rDoc.GetString(ScAddress(0,0,0)); - CPPUNIT_ASSERT_EQUAL(OUString(u"小笠原"), aStr); - aStr = rDoc.GetString(ScAddress(1,0,0)); - CPPUNIT_ASSERT_EQUAL(OUString(u"徳彦"), aStr); - - // Multiple text:span within text:ruby-base - aStr = rDoc.GetString(ScAddress(2,0,0)); - CPPUNIT_ASSERT_EQUAL(OUString(u"注音符號"), aStr); - - xDocSh->DoClose(); -} - -void ScFiltersTest::testTdf139763ShapeAnchor() -{ - ScDocShellRef xDocSh = loadDoc(u"tdf139763ShapeAnchor.", FORMAT_XLSX); - CPPUNIT_ASSERT_MESSAGE("Failed to load cell-anchored-shapes.xlsx", xDocSh.is()); - - // There are two objects on the first sheet, anchored to page by element xdr:absoluteAnchor - // and anchored to cell by element xdr:oneCellAnchor. Error was, that they were imported as - // "anchor to cell (resize with cell". - ScDocument& rDoc = xDocSh->GetDocument(); - - CPPUNIT_ASSERT_MESSAGE("There should be at least one sheet.", rDoc.GetTableCount() > 0); - - ScDrawLayer* pDrawLayer = rDoc.GetDrawLayer(); - SdrPage* pPage = pDrawLayer->GetPage(0); - CPPUNIT_ASSERT_MESSAGE("draw page for sheet 1 should exist.", pPage); - // There should be 2 shapes - CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), pPage->GetObjCount()); - - SdrObject* pObj = pPage->GetObj(0); - CPPUNIT_ASSERT_MESSAGE("Failed to get page anchored object.", pObj); - CPPUNIT_ASSERT_MESSAGE("Shape must be page anchored", !ScDrawLayer::IsCellAnchored(*pObj)); - - pObj = pPage->GetObj(1); - CPPUNIT_ASSERT_MESSAGE("Failed to get cell anchored object.", pObj); - CPPUNIT_ASSERT_MESSAGE("Shape must be anchored to cell.", ScDrawLayer::IsCellAnchored(*pObj)); - CPPUNIT_ASSERT_MESSAGE("Shape must not resize with cell.", !ScDrawLayer::IsResizeWithCell(*pObj)); - - xDocSh->DoClose(); -} - -void ScFiltersTest::testAutofilterNamedRangesXLSX() -{ - ScDocShellRef xDocSh = loadDoc(u"autofilternamedrange.", FORMAT_XLSX); - CPPUNIT_ASSERT_MESSAGE("Failed to load autofilternamedrange.xlsx", xDocSh.is()); - - ScDocument& rDoc = xDocSh->GetDocument(); - const ScDBData* pDBData = rDoc.GetDBCollection()->GetDBNearCursor(0, 0, 0); - CPPUNIT_ASSERT(pDBData); - ScRange aRange; - pDBData->GetArea(aRange); - CPPUNIT_ASSERT_EQUAL(ScRange(0, 0, 0, 0, 3, 0), aRange); - OUString aPosStr; - bool bSheetLocal = false; - // test there is no '_xlnm._FilterDatabase' named range on the filter area - const ScRangeData* pRData = rDoc.GetRangeAtBlock(aRange, aPosStr, &bSheetLocal); - CPPUNIT_ASSERT(!pRData); - CPPUNIT_ASSERT_EQUAL(OUString(), aPosStr); - - xDocSh->DoClose(); -} +void ScFiltersTest::testTdf111974XLSM() { testImportCrash(u"tdf111974.", FORMAT_XLSM); } ScFiltersTest::ScFiltersTest() : ScBootstrapFixture( "sc/qa/unit/data" ) diff --git a/sc/qa/unit/subsequent_filters-test2.cxx b/sc/qa/unit/subsequent_filters-test2.cxx new file mode 100644 index 000000000000..4b4995f9147c --- /dev/null +++ b/sc/qa/unit/subsequent_filters-test2.cxx @@ -0,0 +1,2882 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include <sal/config.h> + +#include <memory> +#include <string_view> + +#include <unotest/filters-test.hxx> +#include <test/bootstrapfixture.hxx> +#include <osl/file.hxx> +#include <config_features.h> + +#include <vcl/svapp.hxx> +#include <sfx2/docfilt.hxx> +#include <sfx2/docfile.hxx> +#include <svl/stritem.hxx> +#include <svl/zformat.hxx> +#include <svx/svdograf.hxx> +#include <svx/svxids.hrc> + +#include <drwlayer.hxx> +#include <svx/svdpage.hxx> +#include <svx/svdoole2.hxx> +#include <editeng/eeitem.hxx> +#include <editeng/wghtitem.hxx> +#include <editeng/postitem.hxx> +#include <editeng/crossedoutitem.hxx> +#include <editeng/udlnitem.hxx> +#include <editeng/editobj.hxx> +#include <editeng/borderline.hxx> +#include <editeng/boxitem.hxx> +#include <editeng/fhgtitem.hxx> +#include <editeng/brushitem.hxx> +#include <editeng/fontitem.hxx> +#include <editeng/flditem.hxx> +#include <editeng/justifyitem.hxx> +#include <editeng/lineitem.hxx> +#include <editeng/colritem.hxx> +#include <dbdata.hxx> +#include <validat.hxx> +#include <formulacell.hxx> +#include <formulaopt.hxx> +#include <userdat.hxx> +#include <stlsheet.hxx> +#include <docfunc.hxx> +#include <markdata.hxx> +#include <colorscale.hxx> +#include <olinetab.hxx> +#include <patattr.hxx> +#include <scitems.hxx> +#include <docsh.hxx> +#include <editutil.hxx> +#include <cellvalue.hxx> +#include <attrib.hxx> +#include <fillinfo.hxx> +#include <scopetools.hxx> +#include <columnspanset.hxx> +#include <tokenstringcontext.hxx> +#include <formula/errorcodes.hxx> +#include <externalrefmgr.hxx> +#include <stlpool.hxx> +#include <hints.hxx> +#include <detfunc.hxx> +#include <cellmergeoption.hxx> +#include <undoblk.hxx> + +#include <orcusfilters.hxx> +#include <filter.hxx> + +#include <com/sun/star/drawing/XDrawPageSupplier.hpp> +#include <com/sun/star/drawing/XControlShape.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/text/textfield/Type.hpp> + +#include <comphelper/scopeguard.hxx> +#include <tools/UnitConversion.hxx> +#include <unotools/syslocaleoptions.hxx> +#include "helper/qahelper.hxx" +#include "helper/shared_test_impl.hxx" + +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; + +class ScFiltersTest2 : public test::FiltersTest, public ScBootstrapFixture +{ +public: + ScFiltersTest2(); + + virtual bool load(const OUString& rFilter, const OUString& rURL, const OUString& rUserData, + SfxFilterFlags nFilterFlags, SotClipboardFormatId nClipboardID, + unsigned int nFilterVersion) override; + + virtual void setUp() override; + virtual void tearDown() override; + + void testMiscRowHeights(); + void testOptimalHeightReset(); + void testCustomNumFormatHybridCellODS(); + void testTdf121040(); + void testTdf118086(); + void testTdf118624(); + void testTdf124454(); + + void testPrintRangeODS(); + void testOutlineODS(); + + void testColumnStyleXLSX(); + void testColumnStyleAutoFilterXLSX(); + + void testSharedFormulaHorizontalXLS(); + void testSharedFormulaWrappedRefsXLS(); + void testSharedFormulaBIFF5(); + void testSharedFormulaXLSB(); + void testSharedFormulaXLS(); + void testSharedFormulaColumnLabelsODS(); + void testSharedFormulaColumnRowLabelsODS(); + void testExternalRefCacheXLSX(); + void testExternalRefCacheODS(); + void testHybridSharedStringODS(); + void testCopyMergedNumberFormats(); + void testVBAUserFunctionXLSM(); + void testEmbeddedImageXLS(); + void testErrorOnExternalReferences(); + void testTdf84762(); + void testTdf44076(); + void testEditEngStrikeThroughXLSX(); + void testRefStringXLSX(); + void testHiddenSheetsXLSX(); + void testRelFormulaValidationXLS(); + void testTdf130132(); + void testTdf133327(); + void testColumnStyle2XLSX(); + void testAutofilterXLSX(); + + void testBnc762542(); + + void testTdf136364(); + void testTdf103734(); + void testTdf126116(); + void testTdf98844(); + void testTdf100458(); + void testTdf118561(); + void testTdf125099(); + void testTdf134455(); + void testTdf119533(); + void testTdf127982(); + void testTdf109409(); + void testTdf132105(); + void testTdf131424(); + void testTdf100709XLSX(); + void testTdf97598XLSX(); + void testTdf110440XLSX(); + void testTdf83672XLSX(); + + void testCondFormatXLSB(); + void testPageScalingXLSX(); + void testActiveXCheckboxXLSX(); + void testtdf120301_xmlSpaceParsingXLSX(); +#ifdef UNX + void testUnicodeFileNameGnumeric(); +#endif + void testCondFormatFormulaListenerXLSX(); + + void testMergedCellsXLSXML(); + void testBackgroundColorStandardXLSXML(); + void testTdf131536(); + void testTdf130583(); + void testTdf85617(); + void testTdf134234(); + void testTdf42481(); + void testNamedExpressionsXLSXML(); + void testEmptyRowsXLSXML(); + void testBorderDirectionsXLSXML(); + void testBorderColorsXLSXML(); + void testHiddenRowsColumnsXLSXML(); + void testColumnWidthRowHeightXLSXML(); + void testCharacterSetXLSXML(); + void testTdf137091(); + void testTdf62268(); + void testTdf137453(); + void testTdf112780(); + void testTdf72470(); + void testTdf35636(); + void testTdf98481(); + void testTdf115022(); + void testVBAMacroFunctionODS(); + void testAutoheight2Rows(); + void testXLSDefColWidth(); + void testPreviewMissingObjLink(); + void testShapeRotationImport(); + void testShapeDisplacementOnRotationImport(); + void testTextBoxBodyUpright(); + void testTextBoxBodyRotateAngle(); + void testTextLengthDataValidityXLSX(); + void testDeleteCircles(); + void testDrawCircleInMergeCells(); + void testDeleteCirclesInRowAndCol(); + void testTdf129940(); + void testTdf139763ShapeAnchor(); + void testAutofilterNamedRangesXLSX(); + + CPPUNIT_TEST_SUITE(ScFiltersTest2); + + CPPUNIT_TEST(testMiscRowHeights); + CPPUNIT_TEST(testOptimalHeightReset); + CPPUNIT_TEST(testCustomNumFormatHybridCellODS); + CPPUNIT_TEST(testTdf121040); + CPPUNIT_TEST(testTdf118086); + CPPUNIT_TEST(testTdf118624); + CPPUNIT_TEST(testTdf124454); + CPPUNIT_TEST(testPrintRangeODS); + CPPUNIT_TEST(testOutlineODS); + CPPUNIT_TEST(testColumnStyleXLSX); + CPPUNIT_TEST(testColumnStyleAutoFilterXLSX); + CPPUNIT_TEST(testSharedFormulaHorizontalXLS); + CPPUNIT_TEST(testSharedFormulaWrappedRefsXLS); + CPPUNIT_TEST(testSharedFormulaBIFF5); + CPPUNIT_TEST(testSharedFormulaXLSB); + CPPUNIT_TEST(testSharedFormulaXLS); + CPPUNIT_TEST(testSharedFormulaColumnLabelsODS); + CPPUNIT_TEST(testSharedFormulaColumnRowLabelsODS); + CPPUNIT_TEST(testExternalRefCacheXLSX); + CPPUNIT_TEST(testExternalRefCacheODS); + CPPUNIT_TEST(testHybridSharedStringODS); + CPPUNIT_TEST(testCopyMergedNumberFormats); + CPPUNIT_TEST(testVBAUserFunctionXLSM); + CPPUNIT_TEST(testEmbeddedImageXLS); + CPPUNIT_TEST(testErrorOnExternalReferences); + CPPUNIT_TEST(testTdf84762); + CPPUNIT_TEST(testTdf44076); + CPPUNIT_TEST(testEditEngStrikeThroughXLSX); + CPPUNIT_TEST(testRefStringXLSX); + CPPUNIT_TEST(testRelFormulaValidationXLS); + CPPUNIT_TEST(testTdf130132); + CPPUNIT_TEST(testTdf133327); + CPPUNIT_TEST(testColumnStyle2XLSX); + CPPUNIT_TEST(testAutofilterXLSX); + + CPPUNIT_TEST(testBnc762542); + + CPPUNIT_TEST(testHiddenSheetsXLSX); + + CPPUNIT_TEST(testTdf136364); + CPPUNIT_TEST(testTdf103734); + CPPUNIT_TEST(testTdf126116); + CPPUNIT_TEST(testTdf98844); + CPPUNIT_TEST(testTdf100458); + CPPUNIT_TEST(testTdf118561); + CPPUNIT_TEST(testTdf125099); + CPPUNIT_TEST(testTdf134455); + CPPUNIT_TEST(testTdf119533); + CPPUNIT_TEST(testTdf127982); + CPPUNIT_TEST(testTdf109409); + CPPUNIT_TEST(testTdf132105); + CPPUNIT_TEST(testTdf131424); + CPPUNIT_TEST(testTdf100709XLSX); + CPPUNIT_TEST(testTdf97598XLSX); + CPPUNIT_TEST(testTdf110440XLSX); + CPPUNIT_TEST(testTdf83672XLSX); + + CPPUNIT_TEST(testCondFormatXLSB); + CPPUNIT_TEST(testPageScalingXLSX); + CPPUNIT_TEST(testActiveXCheckboxXLSX); + CPPUNIT_TEST(testtdf120301_xmlSpaceParsingXLSX); +#ifdef UNX + CPPUNIT_TEST(testUnicodeFileNameGnumeric); +#endif + CPPUNIT_TEST(testMergedCellsXLSXML); + CPPUNIT_TEST(testBackgroundColorStandardXLSXML); + CPPUNIT_TEST(testTdf131536); + CPPUNIT_TEST(testTdf130583); + CPPUNIT_TEST(testTdf85617); + CPPUNIT_TEST(testTdf134234); + CPPUNIT_TEST(testTdf42481); + CPPUNIT_TEST(testNamedExpressionsXLSXML); + CPPUNIT_TEST(testEmptyRowsXLSXML); + CPPUNIT_TEST(testBorderDirectionsXLSXML); + CPPUNIT_TEST(testBorderColorsXLSXML); + CPPUNIT_TEST(testHiddenRowsColumnsXLSXML); + CPPUNIT_TEST(testColumnWidthRowHeightXLSXML); + CPPUNIT_TEST(testCharacterSetXLSXML); + CPPUNIT_TEST(testCondFormatFormulaListenerXLSX); + CPPUNIT_TEST(testTdf137091); + CPPUNIT_TEST(testTdf62268); + CPPUNIT_TEST(testTdf137453); + CPPUNIT_TEST(testTdf112780); + CPPUNIT_TEST(testTdf72470); + CPPUNIT_TEST(testTdf35636); + CPPUNIT_TEST(testTdf98481); + CPPUNIT_TEST(testTdf115022); + CPPUNIT_TEST(testVBAMacroFunctionODS); + CPPUNIT_TEST(testAutoheight2Rows); + CPPUNIT_TEST(testXLSDefColWidth); + CPPUNIT_TEST(testPreviewMissingObjLink); + CPPUNIT_TEST(testShapeRotationImport); + CPPUNIT_TEST(testShapeDisplacementOnRotationImport); + CPPUNIT_TEST(testTextBoxBodyUpright); + CPPUNIT_TEST(testTextBoxBodyRotateAngle); + CPPUNIT_TEST(testTextLengthDataValidityXLSX); + CPPUNIT_TEST(testDeleteCircles); + CPPUNIT_TEST(testDrawCircleInMergeCells); + CPPUNIT_TEST(testDeleteCirclesInRowAndCol); + CPPUNIT_TEST(testTdf129940); + CPPUNIT_TEST(testTdf139763ShapeAnchor); + CPPUNIT_TEST(testAutofilterNamedRangesXLSX); + + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference<uno::XInterface> m_xCalcComponent; +}; + +ScFiltersTest2::ScFiltersTest2() + : ScBootstrapFixture("sc/qa/unit/data") +{ +} + +void ScFiltersTest2::setUp() +{ + test::BootstrapFixture::setUp(); + + // This is a bit of a fudge, we do this to ensure that ScGlobals::ensure, + // which is a private symbol to us, gets called + m_xCalcComponent + = getMultiServiceFactory()->createInstance("com.sun.star.comp.Calc.SpreadsheetDocument"); + CPPUNIT_ASSERT_MESSAGE("no calc component!", m_xCalcComponent.is()); +} + +void ScFiltersTest2::tearDown() +{ + uno::Reference<lang::XComponent>(m_xCalcComponent, UNO_QUERY_THROW)->dispose(); + test::BootstrapFixture::tearDown(); +} + +bool ScFiltersTest2::load(const OUString& rFilter, const OUString& rURL, const OUString& rUserData, + SfxFilterFlags nFilterFlags, SotClipboardFormatId nClipboardID, + unsigned int nFilterVersion) +{ + ScDocShellRef xDocShRef = ScBootstrapFixture::load(rURL, rFilter, rUserData, OUString(), + nFilterFlags, nClipboardID, nFilterVersion); + bool bLoaded = xDocShRef.is(); + //reference counting of ScDocShellRef is very confused. + if (bLoaded) + xDocShRef->DoClose(); + return bLoaded; +} + +void ScFiltersTest2::testMiscRowHeights() +{ + // FIXME: the DPI check should be removed when either (1) the test is fixed to work with + // non-default DPI; or (2) unit tests on Windows are made to use svp VCL plugin. + if (!IsDefaultDPI()) + return; + + static const TestParam::RowData DfltRowData[] = { + // check rows at the beginning and end of document + // and make sure they are reported as the default row + // height ( indicated by -1 ) + { 2, 4, 0, -1, 0, false }, + { 1048573, 1048575, 0, -1, 0, false }, + }; + + static const TestParam::RowData MultiLineOptData[] = { + // Row 0 is 12.63 mm and optimal flag is set => 12.36 mm + { 0, 0, 0, 1236, CHECK_OPTIMAL, true }, + // Row 1 is 11.99 mm and optimal flag is NOT set + { 1, 1, 0, 1199, CHECK_OPTIMAL, false }, + }; + + TestParam aTestValues[] = { + /* Checks that a document saved to ods with default rows does indeed + have default row heights ( there was a problem where the optimal + height was being calculated after import if no hard height ) + */ + { "alldefaultheights.", FORMAT_ODS, -1, SAL_N_ELEMENTS(DfltRowData), DfltRowData }, + /* Checks the imported height of some multiline input, additionally checks + that the optimal height flag is set ( or not ) + */ + { "multilineoptimal.", FORMAT_ODS, -1, SAL_N_ELEMENTS(MultiLineOptData), MultiLineOptData }, + }; + miscRowHeightsTest(aTestValues, SAL_N_ELEMENTS(aTestValues)); +} + +// regression test at least fdo#59193 +// what we want to test here is that when cell contents are deleted +// and the optimal flag is set for that row that the row is actually resized + +void ScFiltersTest2::testOptimalHeightReset() +{ + // FIXME: the DPI check should be removed when either (1) the test is fixed to work with + // non-default DPI; or (2) unit tests on Windows are made to use svp VCL plugin. + if (!IsDefaultDPI()) + return; + + ScDocShellRef xDocSh = loadDoc(u"multilineoptimal.", FORMAT_ODS, true); + SCTAB nTab = 0; + SCROW nRow = 0; + ScDocument& rDoc = xDocSh->GetDocument(); + // open document in read/write mode ( otherwise optimal height stuff won't + // be triggered ) *and* you can't delete cell contents. + int nHeight = convertTwipToMm100(rDoc.GetRowHeight(nRow, nTab, false)); + CPPUNIT_ASSERT_EQUAL(1236, nHeight); + + ScDocFunc& rFunc = xDocSh->GetDocFunc(); + + // delete content of A1 + ScRange aDelRange(0, 0, 0, 0, 0, 0); + ScMarkData aMark(rDoc.GetSheetLimits()); + aMark.SetMarkArea(aDelRange); + bool bRet = rFunc.DeleteContents(aMark, InsertDeleteFlags::ALL, false, true); + CPPUNIT_ASSERT_MESSAGE("DeleteContents failed", bRet); + + // get the new height of A1 + nHeight = convertTwipToMm100(rDoc.GetRowHeight(nRow, nTab, false)); + + // set optimal height for empty row 2 + std::vector<sc::ColRowSpan> aRowArr(1, sc::ColRowSpan(2, 2)); + rFunc.SetWidthOrHeight(false, aRowArr, nTab, SC_SIZE_OPTIMAL, 0, true, true); + + // retrieve optimal height + int nOptimalHeight = convertTwipToMm100(rDoc.GetRowHeight(aRowArr[0].mnStart, nTab, false)); + + // check if the new height of A1 ( after delete ) is now the optimal height of an empty cell + CPPUNIT_ASSERT_EQUAL(nOptimalHeight, nHeight); + xDocSh->DoClose(); +} + +void ScFiltersTest2::testCustomNumFormatHybridCellODS() +{ + ScDocShellRef xDocSh = loadDoc(u"custom-numfmt-hybrid-cell.", FORMAT_ODS, false); + ScDocument& rDoc = xDocSh->GetDocument(); + rDoc.SetAutoCalc(true); + + // All of B14, B16 and B18 should be displaying empty strings by virtue + // of the custom number format being set on those cells. + + for (SCROW nRow : { 13, 15, 17 }) + { + ScAddress aPos(1, nRow, 0); + OUString aStr = rDoc.GetString(aPos); + CPPUNIT_ASSERT(aStr.isEmpty()); + } + + // Now, set value of 1 to B15. This should trigger re-calc on B18 and B18 + // should now show a value of 1. + rDoc.SetValue(ScAddress(1, 15, 0), 1.0); + + OUString aStr = rDoc.GetString(ScAddress(1, 17, 0)); + CPPUNIT_ASSERT_EQUAL(OUString("1"), aStr); + + // Make sure the cell doesn't have an error value. + ScFormulaCell* pFC = rDoc.GetFormulaCell(ScAddress(1, 17, 0)); + CPPUNIT_ASSERT(pFC); + CPPUNIT_ASSERT_EQUAL(FormulaError::NONE, pFC->GetErrCode()); + + xDocSh->DoClose(); +} + +void ScFiltersTest2::testTdf121040() +{ + ScDocShellRef xDocSh = loadDoc(u"tdf121040.", FORMAT_ODS); + CPPUNIT_ASSERT_MESSAGE("Failed to load tdf121040.ods", xDocSh.is()); + + const SCTAB nTab = 0; + ScDocument& rDoc = xDocSh->GetDocument(); + + // The first 9 rows should have the same height + const sal_uInt16 nHeight = rDoc.GetRowHeight(0, nTab, false); + for (SCTAB nRow = 1; nRow < 9; nRow++) + { + CPPUNIT_ASSERT_EQUAL(nHeight, rDoc.GetRowHeight(nRow, nTab, false)); + } + + xDocSh->DoClose(); +} + +void ScFiltersTest2::testTdf118086() +{ + ScDocShellRef xDocSh = loadDoc(u"tdf118086.", FORMAT_ODS); + CPPUNIT_ASSERT_MESSAGE("Failed to load tdf118086.ods", xDocSh.is()); + + ScDocument& rDoc = xDocSh->GetDocument(); + + CPPUNIT_ASSERT_EQUAL(sal_uInt16(477), rDoc.GetRowHeight(2, static_cast<SCTAB>(0), false)); + + // Without the fix in place, this test would have failed with + // - Expected: 256 + // - Actual : 477 + CPPUNIT_ASSERT_EQUAL(sal_uInt16(256), rDoc.GetRowHeight(2, static_cast<SCTAB>(1), false)); + CPPUNIT_ASSERT_EQUAL(sal_uInt16(256), rDoc.GetRowHeight(2, static_cast<SCTAB>(2), false)); + + xDocSh->DoClose(); +} + +void ScFiltersTest2::testTdf118624() +{ + ScDocShellRef xDocSh = loadDoc(u"tdf118624.", FORMAT_ODS); + CPPUNIT_ASSERT_MESSAGE("Failed to open doc", xDocSh.is()); + + ScDocument& rDoc = xDocSh->GetDocument(); + + CPPUNIT_ASSERT_MESSAGE("RAND() in array/matrix mode shouldn't return the same value", + rDoc.GetString(ScAddress(0, 0, 0)) + != rDoc.GetString(ScAddress(0, 1, 0))); + + xDocSh->DoClose(); +} + +void ScFiltersTest2::testTdf124454() +{ + ScDocShellRef xDocSh = loadDoc(u"tdf124454.", FORMAT_ODS); + CPPUNIT_ASSERT_MESSAGE("Failed to open doc", xDocSh.is()); + + ScDocument& rDoc = xDocSh->GetDocument(); + + CPPUNIT_ASSERT_EQUAL(OUString("1"), rDoc.GetString(ScAddress(1, 0, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("1"), rDoc.GetString(ScAddress(2, 0, 0))); + // Without the fix in place, double negation with text in array + // would have returned -1 + CPPUNIT_ASSERT_EQUAL(OUString("1"), rDoc.GetString(ScAddress(3, 0, 0))); + + xDocSh->DoClose(); +} + +void ScFiltersTest2::testPrintRangeODS() +{ + ScDocShellRef xDocSh = loadDoc(u"print-range.", FORMAT_ODS); + ScDocument& rDoc = xDocSh->GetDocument(); + const ScRange* pRange = rDoc.GetRepeatRowRange(0); + CPPUNIT_ASSERT(pRange); + CPPUNIT_ASSERT_EQUAL(ScRange(0, 0, 0, 0, 1, 0), *pRange); + + pRange = rDoc.GetRepeatRowRange(1); + CPPUNIT_ASSERT(pRange); + CPPUNIT_ASSERT_EQUAL(ScRange(0, 2, 0, 0, 4, 0), *pRange); + + xDocSh->DoClose(); +} + +void ScFiltersTest2::testOutlineODS() +{ + ScDocShellRef xDocSh = loadDoc(u"outline.", FORMAT_ODS); + ScDocument& rDoc = xDocSh->GetDocument(); + + const ScOutlineTable* pTable = rDoc.GetOutlineTable(0); + CPPUNIT_ASSERT(pTable); + + const ScOutlineArray& rArr = pTable->GetRowArray(); + size_t nDepth = rArr.GetDepth(); + CPPUNIT_ASSERT_EQUAL(size_t(4), nDepth); + + for (size_t i = 0; i < nDepth; ++i) + { + CPPUNIT_ASSERT_EQUAL(size_t(1), rArr.GetCount(i)); + } + + struct OutlineData + { + SCCOLROW nStart; + SCCOLROW nEnd; + bool bHidden; + bool bVisible; + + size_t nDepth; + size_t nIndex; + }; + + static const OutlineData aRow[] = { { 1, 29, false, true, 0, 0 }, + { 2, 26, false, true, 1, 0 }, + { 4, 23, false, true, 2, 0 }, + { 6, 20, true, true, 3, 0 } }; + + for (size_t i = 0; i < SAL_N_ELEMENTS(aRow); ++i) + { + const ScOutlineEntry* pEntry = rArr.GetEntry(aRow[i].nDepth, aRow[i].nIndex); + SCCOLROW nStart = pEntry->GetStart(); + CPPUNIT_ASSERT_EQUAL(aRow[i].nStart, nStart); + + SCCOLROW nEnd = pEntry->GetEnd(); + CPPUNIT_ASSERT_EQUAL(aRow[i].nEnd, nEnd); + + bool bHidden = pEntry->IsHidden(); + CPPUNIT_ASSERT_EQUAL(aRow[i].bHidden, bHidden); + + bool bVisible = pEntry->IsVisible(); + CPPUNIT_ASSERT_EQUAL(aRow[i].bVisible, bVisible); + } + + xDocSh->DoClose(); +} + +void ScFiltersTest2::testColumnStyleXLSX() +{ + ScDocShellRef xDocSh = loadDoc(u"column-style.", FORMAT_XLSX); + CPPUNIT_ASSERT(xDocSh.is()); + ScDocument& rDoc = xDocSh->GetDocument(); + + const ScPatternAttr* pPattern = rDoc.GetPattern(0, 0, 0); + CPPUNIT_ASSERT(pPattern); + + const ScProtectionAttr& rAttr = pPattern->GetItem(ATTR_PROTECTION); + CPPUNIT_ASSERT(rAttr.GetProtection()); + + pPattern = rDoc.GetPattern(0, 1, 0); + CPPUNIT_ASSERT(pPattern); + + const ScProtectionAttr& rAttrNew = pPattern->GetItem(ATTR_PROTECTION); + CPPUNIT_ASSERT(!rAttrNew.GetProtection()); + + xDocSh->DoClose(); +} + +void ScFiltersTest2::testColumnStyleAutoFilterXLSX() +{ + ScDocShellRef xDocSh = loadDoc(u"column-style-autofilter.", FORMAT_XLSX); + CPPUNIT_ASSERT(xDocSh.is()); + ScDocument& rDoc = xDocSh->GetDocument(); + + const ScPatternAttr* pPattern = rDoc.GetPattern(0, 10, 18); + CPPUNIT_ASSERT(pPattern); + + const ScMergeFlagAttr& rAttr = pPattern->GetItem(ATTR_MERGE_FLAG); + CPPUNIT_ASSERT(!rAttr.HasAutoFilter()); + + xDocSh->DoClose(); +} + +void ScFiltersTest2::testSharedFormulaHorizontalXLS() +{ + ScDocShellRef xDocSh = loadDoc(u"shared-formula/horizontal.", FORMAT_XLS); + CPPUNIT_ASSERT(xDocSh.is()); + ScDocument& rDoc = xDocSh->GetDocument(); + + // Make sure K2:S2 on the 2nd sheet are all formula cells. + ScAddress aPos(0, 1, 1); + for (SCCOL nCol = 10; nCol <= 18; ++nCol) + { + aPos.SetCol(nCol); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Formula cell is expected here.", CELLTYPE_FORMULA, + rDoc.GetCellType(aPos)); + } + + // Likewise, B3:J9 all should be formula cells. + for (SCCOL nCol = 1; nCol <= 9; ++nCol) + { + aPos.SetCol(nCol); + for (SCROW nRow = 2; nRow <= 8; ++nRow) + { + aPos.SetRow(nRow); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Formula cell is expected here.", CELLTYPE_FORMULA, + rDoc.GetCellType(aPos)); + } + } + + // B2:I2 too. + aPos.SetRow(1); + for (SCCOL nCol = 1; nCol <= 8; ++nCol) + { + aPos.SetCol(nCol); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Formula cell is expected here.", CELLTYPE_FORMULA, + rDoc.GetCellType(aPos)); + } + + // J2 has a string of "MW". + aPos.SetCol(9); + CPPUNIT_ASSERT_EQUAL(OUString("MW"), rDoc.GetString(aPos)); + + xDocSh->DoClose(); +} + +void ScFiltersTest2::testSharedFormulaWrappedRefsXLS() +{ + ScDocShellRef xDocSh = loadDoc(u"shared-formula/wrapped-refs.", FORMAT_XLS); + CPPUNIT_ASSERT(xDocSh.is()); + ScDocument& rDoc = xDocSh->GetDocument(); + rDoc.CalcAll(); + + // Check the values of H7:H10. + CPPUNIT_ASSERT_EQUAL(7.0, rDoc.GetValue(ScAddress(7, 6, 0))); + CPPUNIT_ASSERT_EQUAL(8.0, rDoc.GetValue(ScAddress(7, 7, 0))); + CPPUNIT_ASSERT_EQUAL(9.0, rDoc.GetValue(ScAddress(7, 8, 0))); + CPPUNIT_ASSERT_EQUAL(10.0, rDoc.GetValue(ScAddress(7, 9, 0))); + + // EM7:EM10 should reference H7:H10. + CPPUNIT_ASSERT_EQUAL(7.0, rDoc.GetValue(ScAddress(142, 6, 0))); + CPPUNIT_ASSERT_EQUAL(8.0, rDoc.GetValue(ScAddress(142, 7, 0))); + CPPUNIT_ASSERT_EQUAL(9.0, rDoc.GetValue(ScAddress(142, 8, 0))); + CPPUNIT_ASSERT_EQUAL(10.0, rDoc.GetValue(ScAddress(142, 9, 0))); + + // Make sure EM7:EM10 are grouped. + const ScFormulaCell* pFC = rDoc.GetFormulaCell(ScAddress(142, 6, 0)); + CPPUNIT_ASSERT(pFC); + CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(6), pFC->GetSharedTopRow()); + CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(4), pFC->GetSharedLength()); + + xDocSh->DoClose(); +} + +void ScFiltersTest2::testSharedFormulaBIFF5() +{ + ScDocShellRef xDocSh = loadDoc(u"shared-formula/biff5.", FORMAT_XLS); + CPPUNIT_ASSERT(xDocSh.is()); + ScDocument& rDoc = xDocSh->GetDocument(); + rDoc.CalcAll(); + + // E6:E376 should be all formulas, and they should belong to the same group. + const ScFormulaCell* pFC = rDoc.GetFormulaCell(ScAddress(4, 5, 0)); + CPPUNIT_ASSERT(pFC); + CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(5), pFC->GetSharedTopRow()); + CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(371), pFC->GetSharedLength()); + + xDocSh->DoClose(); +} + +void ScFiltersTest2::testSharedFormulaXLSB() +{ + ScDocShellRef xDocSh = loadDoc(u"shared_formula.", FORMAT_XLSB); + CPPUNIT_ASSERT(xDocSh.is()); + ScDocument& rDoc = xDocSh->GetDocument(); + rDoc.CalcAll(); + + // A1:A30 should be all formulas, and they should belong to the same group. + const ScFormulaCell* pFC = rDoc.GetFormulaCell(ScAddress(0, 0, 0)); + CPPUNIT_ASSERT(pFC); + CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(0), pFC->GetSharedTopRow()); + CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(30), pFC->GetSharedLength()); + + for (SCROW nRow = 0; nRow < 30; ++nRow) + { + ASSERT_DOUBLES_EQUAL(3.0, rDoc.GetValue(0, nRow, 0)); + } + + xDocSh->DoClose(); +} + +void ScFiltersTest2::testSharedFormulaXLS() +{ + { + // fdo#80091 + ScDocShellRef xDocSh = loadDoc(u"shared-formula/relative-refs1.", FORMAT_XLS); + CPPUNIT_ASSERT(xDocSh.is()); + ScDocument& rDoc = xDocSh->GetDocument(); + rDoc.CalcAll(); + + // A1:A30 should be all formulas, and they should belong to the same group. + const ScFormulaCell* pFC = rDoc.GetFormulaCell(ScAddress(0, 1, 0)); + CPPUNIT_ASSERT(pFC); + CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(1), pFC->GetSharedTopRow()); + CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(29), pFC->GetSharedLength()); + + for (SCROW nRow = 0; nRow < 30; ++nRow) + { + ASSERT_DOUBLES_EQUAL(double(nRow + 1), rDoc.GetValue(0, nRow, 0)); + } + + xDocSh->DoClose(); + } + + { + // fdo#84556 and some related tests + ScDocShellRef xDocSh = loadDoc(u"shared-formula/relative-refs2.", FORMAT_XLS); + CPPUNIT_ASSERT(xDocSh.is()); + ScDocument& rDoc = xDocSh->GetDocument(); + rDoc.CalcAll(); + + { + const ScFormulaCell* pFC = rDoc.GetFormulaCell(ScAddress(2, 1, 0)); + CPPUNIT_ASSERT(pFC); + CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(1), pFC->GetSharedTopRow()); + CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(10), pFC->GetSharedLength()); + + pFC = rDoc.GetFormulaCell(ScAddress(2, 10, 0)); + CPPUNIT_ASSERT(pFC); + CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(1), pFC->GetSharedTopRow()); + CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(10), pFC->GetSharedLength()); + + OUString aFormula; + rDoc.GetFormula(2, 1, 0, aFormula); + CPPUNIT_ASSERT_EQUAL(OUString("=SUM(B9:D9)"), aFormula); + + rDoc.GetFormula(2, 10, 0, aFormula); + CPPUNIT_ASSERT_EQUAL(OUString("=SUM(B18:D18)"), aFormula); + } + + { + const ScFormulaCell* pFC = rDoc.GetFormulaCell(ScAddress(4, 8, 0)); + CPPUNIT_ASSERT(pFC); + CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(8), pFC->GetSharedTopRow()); + CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(10), pFC->GetSharedLength()); + + pFC = rDoc.GetFormulaCell(ScAddress(4, 17, 0)); + CPPUNIT_ASSERT(pFC); + CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(8), pFC->GetSharedTopRow()); + CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(10), pFC->GetSharedLength()); + + OUString aFormula; + rDoc.GetFormula(4, 8, 0, aFormula); + CPPUNIT_ASSERT_EQUAL(OUString("=SUM(G9:EY9)"), aFormula); + + rDoc.GetFormula(4, 17, 0, aFormula); + CPPUNIT_ASSERT_EQUAL(OUString("=SUM(G18:EY18)"), aFormula); + } + + { + const ScFormulaCell* pFC = rDoc.GetFormulaCell(ScAddress(6, 15, 0)); + CPPUNIT_ASSERT(pFC); + CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(15), pFC->GetSharedTopRow()); + CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(10), pFC->GetSharedLength()); + + pFC = rDoc.GetFormulaCell(ScAddress(6, 24, 0)); + CPPUNIT_ASSERT(pFC); + CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(15), pFC->GetSharedTopRow()); + CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(10), pFC->GetSharedLength()); + + OUString aFormula; + rDoc.GetFormula(6, 15, 0, aFormula); + CPPUNIT_ASSERT_EQUAL(OUString("=SUM(A16:A40000)"), aFormula); + + rDoc.GetFormula(6, 24, 0, aFormula); + CPPUNIT_ASSERT_EQUAL(OUString("=SUM(A25:A40009)"), aFormula); + } + + xDocSh->DoClose(); + } +} + +void ScFiltersTest2::testSharedFormulaColumnLabelsODS() +{ + ScDocShellRef xDocSh = loadDoc(u"shared-formula/column-labels.", FORMAT_ODS); + + CPPUNIT_ASSERT(xDocSh.is()); + ScDocument& rDoc = xDocSh->GetDocument(); + rDoc.CalcAll(); + + CPPUNIT_ASSERT_EQUAL(5.0, rDoc.GetValue(ScAddress(2, 1, 0))); + CPPUNIT_ASSERT_EQUAL(15.0, rDoc.GetValue(ScAddress(2, 2, 0))); + CPPUNIT_ASSERT_EQUAL(30.0, rDoc.GetValue(ScAddress(2, 3, 0))); + CPPUNIT_ASSERT_EQUAL(28.0, rDoc.GetValue(ScAddress(2, 4, 0))); + CPPUNIT_ASSERT_EQUAL(48.0, rDoc.GetValue(ScAddress(2, 5, 0))); + + CPPUNIT_ASSERT_EQUAL(0.0, rDoc.GetValue(ScAddress(3, 1, 0))); + CPPUNIT_ASSERT_EQUAL(50.0, rDoc.GetValue(ScAddress(3, 2, 0))); + CPPUNIT_ASSERT_EQUAL(144.0, rDoc.GetValue(ScAddress(3, 3, 0))); + CPPUNIT_ASSERT_EQUAL(147.0, rDoc.GetValue(ScAddress(3, 4, 0))); + CPPUNIT_ASSERT_EQUAL(320.0, rDoc.GetValue(ScAddress(3, 5, 0))); + + CPPUNIT_ASSERT_EQUAL(0.0, rDoc.GetValue(ScAddress(4, 1, 0))); + CPPUNIT_ASSERT_EQUAL(2.0, rDoc.GetValue(ScAddress(4, 2, 0))); + CPPUNIT_ASSERT_EQUAL(4.0, rDoc.GetValue(ScAddress(4, 3, 0))); + CPPUNIT_ASSERT_EQUAL(3.0, rDoc.GetValue(ScAddress(4, 4, 0))); + CPPUNIT_ASSERT_EQUAL(5.0, rDoc.GetValue(ScAddress(4, 5, 0))); + + xDocSh->DoClose(); +} + +void ScFiltersTest2::testSharedFormulaColumnRowLabelsODS() +{ + ScDocShellRef xDocSh = loadDoc(u"shared-formula/column-row-labels.", FORMAT_ODS); + + CPPUNIT_ASSERT(xDocSh.is()); + ScDocument& rDoc = xDocSh->GetDocument(); + rDoc.CalcAll(); + + // Expected output in each of the three ranges. + // + // +---+---+---+ + // | 1 | 4 | 7 | + // +---+---+---+ + // | 2 | 5 | 8 | + // +---+---+---+ + // | 3 | 6 | 9 | + // +---+---+---+ + + auto aCheckFunc = [&](SCCOL nStartCol, SCROW nStartRow) { + double fExpected = 1.0; + for (SCCOL nCol = 0; nCol <= 2; ++nCol) + { + for (SCROW nRow = 0; nRow <= 2; ++nRow) + { + ScAddress aPos(nStartCol + nCol, nStartRow + nRow, 0); + CPPUNIT_ASSERT_EQUAL(fExpected, rDoc.GetValue(aPos)); + fExpected += 1.0; + } + } + }; + + aCheckFunc(5, 1); // F2:H4 + aCheckFunc(9, 1); // J2:L4 + aCheckFunc(1, 6); // B7:D9 + + xDocSh->DoClose(); +} + +void ScFiltersTest2::testExternalRefCacheXLSX() +{ + ScDocShellRef xDocSh = loadDoc(u"external-refs.", FORMAT_XLSX); + CPPUNIT_ASSERT(xDocSh.is()); + ScDocument& rDoc = xDocSh->GetDocument(); + + // These string values are cached external cell values. + CPPUNIT_ASSERT_EQUAL(OUString("Name"), rDoc.GetString(ScAddress(0, 0, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("Andy"), rDoc.GetString(ScAddress(0, 1, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("Bruce"), rDoc.GetString(ScAddress(0, 2, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("Charlie"), rDoc.GetString(ScAddress(0, 3, 0))); + + xDocSh->DoClose(); +} + +void ScFiltersTest2::testExternalRefCacheODS() +{ + ScDocShellRef xDocSh = loadDoc(u"external-ref-cache.", FORMAT_ODS); + + CPPUNIT_ASSERT(xDocSh.is()); + ScDocument& rDoc = xDocSh->GetDocument(); + + // Cells B2:B4 have VLOOKUP with external references which should all show "text". + CPPUNIT_ASSERT_EQUAL(OUString("text"), rDoc.GetString(ScAddress(1, 1, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("text"), rDoc.GetString(ScAddress(1, 2, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("text"), rDoc.GetString(ScAddress(1, 3, 0))); + + // Both cells A6 and A7 should be registered with scExternalRefManager properly + CPPUNIT_ASSERT_EQUAL( + true, rDoc.GetExternalRefManager()->hasCellExternalReference(ScAddress(0, 5, 0))); + CPPUNIT_ASSERT_EQUAL( + true, rDoc.GetExternalRefManager()->hasCellExternalReference(ScAddress(0, 6, 0))); + + xDocSh->DoClose(); +} + +void ScFiltersTest2::testHybridSharedStringODS() +{ + ScDocShellRef xDocSh = loadDoc(u"hybrid-shared-string.", FORMAT_ODS); + + CPPUNIT_ASSERT(xDocSh.is()); + ScDocument& rDoc = xDocSh->GetDocument(); + + // A2 contains formula with MATCH function. The result must be 2, not #N/A! + CPPUNIT_ASSERT_EQUAL(2.0, rDoc.GetValue(ScAddress(0, 1, 0))); + + xDocSh->DoClose(); +} + +void ScFiltersTest2::testCopyMergedNumberFormats() +{ + ScDocShellRef xDocSh = loadDoc(u"copy-merged-number-formats.", FORMAT_ODS); + CPPUNIT_ASSERT(xDocSh.is()); + ScDocument& rDoc = xDocSh->GetDocument(); + + // Cells B1, C1 and D1 are formatted as dates. + OUString aStrB1 = rDoc.GetString(ScAddress(1, 0, 0)); + OUString aStrC1 = rDoc.GetString(ScAddress(2, 0, 0)); + OUString aStrD1 = rDoc.GetString(ScAddress(3, 0, 0)); + + ScDocument aCopyDoc; + aCopyDoc.InsertTab(0, "CopyHere"); + rDoc.CopyStaticToDocument(ScRange(1, 0, 0, 3, 0, 0), 0, aCopyDoc); + + // Make sure the date formats are copied to the new document. + CPPUNIT_ASSERT_EQUAL(aStrB1, aCopyDoc.GetString(ScAddress(1, 0, 0))); + CPPUNIT_ASSERT_EQUAL(aStrC1, aCopyDoc.GetString(ScAddress(2, 0, 0))); + CPPUNIT_ASSERT_EQUAL(aStrD1, aCopyDoc.GetString(ScAddress(3, 0, 0))); + + xDocSh->DoClose(); +} + +void ScFiltersTest2::testVBAUserFunctionXLSM() +{ + ScDocShellRef xDocSh = loadDoc(u"vba-user-function.", FORMAT_XLSM); + CPPUNIT_ASSERT(xDocSh.is()); + ScDocument& rDoc = xDocSh->GetDocument(); + + // A1 contains formula with user-defined function, and the function is defined in VBA. + ScFormulaCell* pFC = rDoc.GetFormulaCell(ScAddress(0, 0, 0)); + CPPUNIT_ASSERT(pFC); + + sc::CompileFormulaContext aCxt(rDoc); + OUString aFormula = pFC->GetFormula(aCxt); + + CPPUNIT_ASSERT_EQUAL(OUString("=MYFUNC()"), aFormula); + + // Check the formula state after the load. + FormulaError nErrCode = pFC->GetErrCode(); + CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(nErrCode)); + + // Check the result. + CPPUNIT_ASSERT_EQUAL(42.0, rDoc.GetValue(ScAddress(0, 0, 0))); + + xDocSh->DoClose(); +} + +void ScFiltersTest2::testEmbeddedImageXLS() +{ + // The document has one embedded image on the first sheet. Make sure it's + // imported properly. + + ScDocShellRef xDocSh = loadDoc(u"file-with-png-image.", FORMAT_XLS); + CPPUNIT_ASSERT(xDocSh.is()); + ScDocument& rDoc = xDocSh->GetDocument(); + + ScDrawLayer* pDL = rDoc.GetDrawLayer(); + CPPUNIT_ASSERT(pDL); + const SdrPage* pPage = pDL->GetPage(0); + CPPUNIT_ASSERT(pPage); + const SdrObject* pObj = pPage->GetObj(0); + CPPUNIT_ASSERT(pObj); + const SdrGrafObj* pImageObj = dynamic_cast<const SdrGrafObj*>(pObj); + CPPUNIT_ASSERT(pImageObj); + const Graphic& rGrf = pImageObj->GetGraphic(); + BitmapEx aBMP = rGrf.GetBitmapEx(); + CPPUNIT_ASSERT_MESSAGE( + "Bitmap content should not be empty if the image has been properly imported.", + !aBMP.IsEmpty()); + + xDocSh->DoClose(); +} + +void ScFiltersTest2::testErrorOnExternalReferences() +{ + ScDocShellRef xDocSh = loadDoc(u"blank.", FORMAT_ODS); + CPPUNIT_ASSERT_MESSAGE("Failed to open empty doc", xDocSh.is()); + + ScDocument& rDoc = xDocSh->GetDocument(); + + // Test tdf#89330 + rDoc.SetString(ScAddress(0, 0, 0), "='file:///Path/To/FileA.ods'#$Sheet1.A1A"); + + ScFormulaCell* pFC = rDoc.GetFormulaCell(ScAddress(0, 0, 0)); + CPPUNIT_ASSERT(pFC); + CPPUNIT_ASSERT_EQUAL(int(FormulaError::NoName), static_cast<int>(pFC->GetErrCode())); + + ASSERT_FORMULA_EQUAL(rDoc, ScAddress(0, 0, 0), "'file:///Path/To/FileA.ods'#$Sheet1.A1A", + "Formula changed"); + + xDocSh->DoClose(); +} + +void ScFiltersTest2::testTdf84762() +{ + ScDocShellRef xDocSh = loadDoc(u"blank.", FORMAT_ODS); + CPPUNIT_ASSERT_MESSAGE("Failed to open empty doc", xDocSh.is()); + + ScDocument& rDoc = xDocSh->GetDocument(); + + rDoc.SetString(ScAddress(0, 0, 0), "=RAND()"); + rDoc.SetString(ScAddress(0, 1, 0), "=RAND()"); + rDoc.SetString(ScAddress(1, 0, 0), "=RAND()*A1"); + rDoc.SetString(ScAddress(1, 1, 0), "=RAND()*B1"); + + double nValA1, nValB1, nValA2, nValB2; + + // Without the fix in place, some cells wouldn't have been updated + // after using F9 a few times + for (sal_Int16 i = 0; i < 10; ++i) + { + nValA1 = rDoc.GetValue(0, 0, 0); + nValB1 = rDoc.GetValue(0, 1, 0); + nValA2 = rDoc.GetValue(1, 0, 0); + nValB2 = rDoc.GetValue(1, 1, 0); + + xDocSh->DoRecalc(false); + + CPPUNIT_ASSERT(nValA1 != rDoc.GetValue(0, 0, 0)); + CPPUNIT_ASSERT(nValA2 != rDoc.GetValue(0, 1, 0)); + CPPUNIT_ASSERT(nValB1 != rDoc.GetValue(1, 0, 0)); + CPPUNIT_ASSERT(nValB2 != rDoc.GetValue(1, 1, 0)); + } + + xDocSh->DoClose(); +} + +void ScFiltersTest2::testTdf44076() +{ + ScDocShellRef xDocSh = loadDoc(u"blank.", FORMAT_ODS); + CPPUNIT_ASSERT_MESSAGE("Failed to open empty doc", xDocSh.is()); + + ScDocument& rDoc = xDocSh->GetDocument(); + + rDoc.SetString(ScAddress(0, 0, 0), "=(-8)^(1/3)"); + + CPPUNIT_ASSERT_EQUAL(-2.0, rDoc.GetValue(ScAddress(0, 0, 0))); + + xDocSh->DoClose(); +} + +void ScFiltersTest2::testEditEngStrikeThroughXLSX() +{ + ScDocShellRef xDocSh = loadDoc(u"strike-through.", FORMAT_XLSX); + CPPUNIT_ASSERT_MESSAGE("Failed to open doc", xDocSh.is()); + + ScDocument& rDoc = xDocSh->GetDocument(); + + const EditTextObject* pObj = rDoc.GetEditText(ScAddress(0, 0, 0)); + CPPUNIT_ASSERT(pObj); + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), pObj->GetParagraphCount()); + CPPUNIT_ASSERT_EQUAL(OUString("this is strike through this not"), pObj->GetText(0)); + + std::vector<EECharAttrib> aAttribs; + pObj->GetCharAttribs(0, aAttribs); + for (const auto& rAttrib : aAttribs) + { + if (rAttrib.pAttr->Which() == EE_CHAR_STRIKEOUT) + { + const SvxCrossedOutItem& rItem = static_cast<const SvxCrossedOutItem&>(*rAttrib.pAttr); + if (rAttrib.nStart == 0) + { + CPPUNIT_ASSERT(rItem.GetStrikeout() != STRIKEOUT_NONE); + } + else + { + CPPUNIT_ASSERT_EQUAL(STRIKEOUT_NONE, rItem.GetStrikeout()); + } + } + } + + xDocSh->DoClose(); +} + +void ScFiltersTest2::testRefStringXLSX() +{ + ScDocShellRef xDocSh = loadDoc(u"ref_string.", FORMAT_XLSX); + CPPUNIT_ASSERT_MESSAGE("Failed to open doc", xDocSh.is()); + + ScDocument& rDoc = xDocSh->GetDocument(); + + double nVal = rDoc.GetValue(2, 2, 0); + ASSERT_DOUBLES_EQUAL(3.0, nVal); + + const ScCalcConfig& rCalcConfig = rDoc.GetCalcConfig(); + CPPUNIT_ASSERT_EQUAL(formula::FormulaGrammar::CONV_XL_A1, rCalcConfig.meStringRefAddressSyntax); + + xDocSh->DoClose(); +} + +void ScFiltersTest2::testTdf130132() +{ + ScDocShellRef xDocSh = loadDoc(u"tdf130132.", FORMAT_ODS); + CPPUNIT_ASSERT_MESSAGE("Failed to open doc", xDocSh.is()); + + ScDocument& rDoc = xDocSh->GetDocument(); + const ScPatternAttr* pAttr = rDoc.GetPattern(434, 0, 0); + + { + const SfxPoolItem& rItem = pAttr->GetItem(ATTR_BACKGROUND); + const SvxBrushItem& rBackground = static_cast<const SvxBrushItem&>(rItem); + const Color& rColor = rBackground.GetColor(); + // background colour is yellow + CPPUNIT_ASSERT_EQUAL(Color(255, 255, 0), rColor); + } +} + +void ScFiltersTest2::testTdf133327() +{ + ScDocShellRef xDocSh = loadDoc(u"tdf133327.", FORMAT_ODS); + CPPUNIT_ASSERT_MESSAGE("Failed to open doc", xDocSh.is()); + + ScDocument& rDoc = xDocSh->GetDocument(); + + const ScPatternAttr* pAttr = rDoc.GetPattern(250, 1, 0); + + const SfxPoolItem& rItem = pAttr->GetItem(ATTR_BACKGROUND); + const SvxBrushItem& rBackground = static_cast<const SvxBrushItem&>(rItem); + const Color& rColor = rBackground.GetColor(); + + // Without the fix in place, this test would have failed with + // - Expected: Color: R:255 G:255 B: 0 + // - Actual : Color: R:255 G:255 B: 255 + CPPUNIT_ASSERT_EQUAL(Color(255, 255, 0), rColor); +} + +void ScFiltersTest2::testColumnStyle2XLSX() +{ + ScDocShellRef xDocSh = loadDoc(u"column_style.", FORMAT_XLSX); + CPPUNIT_ASSERT_MESSAGE("Failed to open doc", xDocSh.is()); + + ScDocument& rDoc = xDocSh->GetDocument(); + const ScPatternAttr* pAttr = rDoc.GetPattern(1, 1, 0); + + { + const SfxPoolItem& rItem = pAttr->GetItem(ATTR_BACKGROUND); + const SvxBrushItem& rBackground = static_cast<const SvxBrushItem&>(rItem); + const Color& rColor = rBackground.GetColor(); + CPPUNIT_ASSERT_EQUAL(Color(255, 51, 51), rColor); + } + + { + const SfxPoolItem& rItem = pAttr->GetItem(ATTR_HOR_JUSTIFY); + const SvxHorJustifyItem& rJustify = static_cast<const SvxHorJustifyItem&>(rItem); + CPPUNIT_ASSERT_EQUAL(SvxCellHorJustify::Center, rJustify.GetValue()); + } + + { + const SfxPoolItem& rItem = pAttr->GetItem(ATTR_FONT_HEIGHT); + const SvxFontHeightItem& rFontHeight = static_cast<const SvxFontHeightItem&>(rItem); + sal_uInt16 nHeight = rFontHeight.GetHeight(); + CPPUNIT_ASSERT_EQUAL(sal_uInt16(240), nHeight); + } + + { + const SfxPoolItem& rItem = pAttr->GetItem(ATTR_FONT); + const SvxFontItem& rFont = static_cast<const SvxFontItem&>(rItem); + OUString aName = rFont.GetFamilyName(); + CPPUNIT_ASSERT_EQUAL(OUString("Linux Biolinum G"), aName); + } + + xDocSh->DoClose(); +} + +void ScFiltersTest2::testTdf110440XLSX() +{ + ScDocShellRef xDocSh = loadDoc(u"tdf110440.", FORMAT_XLSX); + CPPUNIT_ASSERT_MESSAGE("Failed to open doc", xDocSh.is()); + + uno::Reference<frame::XModel> xModel = xDocSh->GetModel(); + uno::Reference<sheet::XSpreadsheetDocument> xDoc(xModel, uno::UNO_QUERY_THROW); + uno::Reference<container::XIndexAccess> xIA(xDoc->getSheets(), uno::UNO_QUERY_THROW); + uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(xIA->getByIndex(0), + uno::UNO_QUERY_THROW); + xIA.set(xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY_THROW); + uno::Reference<beans::XPropertySet> xShape(xIA->getByIndex(0), uno::UNO_QUERY_THROW); + bool bVisible = true; + xShape->getPropertyValue("Visible") >>= bVisible; + // This failed: group shape's hidden property was lost on import. + CPPUNIT_ASSERT(!bVisible); + + xDocSh->DoClose(); +} + +void ScFiltersTest2::testBnc762542() +{ + ScDocShellRef xDocSh = loadDoc(u"bnc762542.", FORMAT_XLSX); + CPPUNIT_ASSERT_MESSAGE("Failed to open doc", xDocSh.is()); + + ScDocument& rDoc = xDocSh->GetDocument(); + ScDrawLayer* pDrawLayer = rDoc.GetDrawLayer(); + SdrPage* pPage = pDrawLayer->GetPage(0); + CPPUNIT_ASSERT_MESSAGE("draw page for sheet 1 should exist.", pPage); + + const size_t nCount = pPage->GetObjCount(); + CPPUNIT_ASSERT_EQUAL_MESSAGE("There should be 10 shapes.", static_cast<size_t>(10), nCount); + + // previously, some of the shapes were (incorrectly) rotated by 90 degrees + for (size_t i : { 1, 2, 4, 5, 7, 9 }) + { + SdrObject* pObj = pPage->GetObj(i); + CPPUNIT_ASSERT_MESSAGE("Failed to get drawing object.", pObj); + + tools::Rectangle aRect(pObj->GetCurrentBoundRect()); + CPPUNIT_ASSERT_MESSAGE("Drawing object shouldn't be rotated.", + aRect.GetWidth() > aRect.GetHeight()); + } + + xDocSh->DoClose(); +} + +void ScFiltersTest2::testHiddenSheetsXLSX() +{ + ScDocShellRef xDocSh = loadDoc(u"hidden_sheets.", FORMAT_XLSX); + CPPUNIT_ASSERT_MESSAGE("Failed to open doc", xDocSh.is()); + + ScDocument& rDoc = xDocSh->GetDocument(); + CPPUNIT_ASSERT_EQUAL_MESSAGE("1st sheet should be hidden", false, rDoc.IsVisible(0)); + CPPUNIT_ASSERT_EQUAL_MESSAGE("2nd sheet should be visible", true, rDoc.IsVisible(1)); + CPPUNIT_ASSERT_EQUAL_MESSAGE("3rd sheet should be hidden", false, rDoc.IsVisible(2)); + + xDocSh->DoClose(); +} + +void ScFiltersTest2::testAutofilterXLSX() +{ + ScDocShellRef xDocSh = loadDoc(u"autofilter.", FORMAT_XLSX); + CPPUNIT_ASSERT_MESSAGE("Failed to open doc", xDocSh.is()); + + ScDocument& rDoc = xDocSh->GetDocument(); + const ScDBData* pData = rDoc.GetDBCollection()->GetDBNearCursor(0, 0, 0); + CPPUNIT_ASSERT(pData); + ScRange aRange; + pData->GetArea(aRange); + CPPUNIT_ASSERT_EQUAL(ScRange(0, 0, 0, 2, 4, 0), aRange); + + xDocSh->DoClose(); +} + +namespace +{ +void checkValidationFormula(const ScAddress& rPos, const ScDocument& rDoc, + const OUString& rExpectedFormula) +{ + const SfxUInt32Item* pItem = rDoc.GetAttr(rPos, ATTR_VALIDDATA); + CPPUNIT_ASSERT(pItem); + sal_uLong nKey = pItem->GetValue(); + const ScValidationData* pData = rDoc.GetValidationEntry(nKey); + CPPUNIT_ASSERT(pData); + + OUString aFormula = pData->GetExpression(rPos, 0); + CPPUNIT_ASSERT_EQUAL(rExpectedFormula, aFormula); +} +} + +void ScFiltersTest2::testRelFormulaValidationXLS() +{ + ScDocShellRef xDocSh = loadDoc(u"validation.", FORMAT_XLS); + CPPUNIT_ASSERT_MESSAGE("Failed to open doc", xDocSh.is()); + + ScDocument& rDoc = xDocSh->GetDocument(); + + checkValidationFormula(ScAddress(3, 4, 0), rDoc, "C5"); + checkValidationFormula(ScAddress(5, 8, 0), rDoc, "D7"); + + xDocSh->DoClose(); +} + +void ScFiltersTest2::testTdf136364() +{ + ScDocShellRef xDocSh = loadDoc(u"tdf136364.", FORMAT_XLSX); + CPPUNIT_ASSERT_MESSAGE("Failed to open doc", xDocSh.is()); + + ScDocument& rDoc = xDocSh->GetDocument(); + + // Without the fix in place, it would have failed with + // - Expected: =SUM((B2:B3~C4:C5~D6:D7)) + // - Actual : =SUM((B2:B3~C4:C5,D6:D7)) + OUString aFormula; + rDoc.GetFormula(4, 0, 0, aFormula); + CPPUNIT_ASSERT_EQUAL(OUString("=SUM((B2:B3~C4:C5~D6:D7))"), aFormula); + CPPUNIT_ASSERT_EQUAL(27.0, rDoc.GetValue(ScAddress(4, 0, 0))); + + // - Expected: =SUM((B2~C4~D6)) + // - Actual : =SUM((B2~C4,D6)) + rDoc.GetFormula(4, 1, 0, aFormula); + CPPUNIT_ASSERT_EQUAL(OUString("=SUM((B2~C4~D6))"), aFormula); + CPPUNIT_ASSERT_EQUAL(12.0, rDoc.GetValue(ScAddress(4, 1, 0))); + + xDocSh->DoClose(); +} + +void ScFiltersTest2::testTdf103734() +{ + ScDocShellRef xDocSh = loadDoc(u"tdf103734.", FORMAT_ODS); + CPPUNIT_ASSERT_MESSAGE("Failed to open doc", xDocSh.is()); + ScDocument& rDoc = xDocSh->GetDocument(); + + // Without the fix in place, MAX() would have returned -1.8E+308 + CPPUNIT_ASSERT_EQUAL(OUString("#N/A"), rDoc.GetString(ScAddress(2, 0, 0))); + + xDocSh->DoClose(); +} + +void ScFiltersTest2::testTdf126116() +{ + ScDocShellRef xDocSh = loadDoc(u"tdf126116.", FORMAT_ODS); + CPPUNIT_ASSERT_MESSAGE("Failed to open doc", xDocSh.is()); + ScDocument& rDoc = xDocSh->GetDocument(); + + CPPUNIT_ASSERT_EQUAL(OUString("02/02/21"), rDoc.GetString(ScAddress(0, 0, 0))); + + rDoc.SetString(ScAddress(0, 0, 0), "03/03"); + + // Without the fix in place, this test would have failed with + // - Expected: 03/03/21 + // - Actual : 03/03/2021 + CPPUNIT_ASSERT_EQUAL(OUString("03/03/21"), rDoc.GetString(ScAddress(0, 0, 0))); + + xDocSh->DoClose(); +} + +void ScFiltersTest2::testTdf98844() +{ + ScDocShellRef xDocSh = loadDoc(u"tdf98844.", FORMAT_ODS); + CPPUNIT_ASSERT_MESSAGE("Failed to open doc", xDocSh.is()); + ScDocument& rDoc = xDocSh->GetDocument(); + + CPPUNIT_ASSERT_EQUAL(47.6227, rDoc.GetValue(ScAddress(0, 7, 0))); + CPPUNIT_ASSERT_EQUAL(48.0, rDoc.GetValue(ScAddress(0, 8, 0))); + + xDocSh->DoHardRecalc(); + + // Without the fix in place, SUM() wouldn't have been updated when + // Precision as shown is enabled + CPPUNIT_ASSERT_EQUAL(48.0, rDoc.GetValue(ScAddress(0, 7, 0))); + CPPUNIT_ASSERT_EQUAL(48.0, rDoc.GetValue(ScAddress(0, 8, 0))); + + xDocSh->DoClose(); +} + +void ScFiltersTest2::testTdf100458() +{ + ScDocShellRef xDocSh = loadDoc(u"tdf100458_lost_zero_value.", FORMAT_ODS); + CPPUNIT_ASSERT_MESSAGE("Failed to open doc", xDocSh.is()); + ScDocument& rDoc = xDocSh->GetDocument(); + CPPUNIT_ASSERT(rDoc.HasValueData(0, 0, 0)); + CPPUNIT_ASSERT_EQUAL(0.0, rDoc.GetValue(0, 0, 0)); + CPPUNIT_ASSERT(!rDoc.HasStringData(0, 0, 0)); + xDocSh->DoClose(); +} + +void ScFiltersTest2::testTdf118561() +{ + ScDocShellRef xDocSh = loadDoc(u"tdf118561.", FORMAT_ODS); + CPPUNIT_ASSERT_MESSAGE("Failed to open doc", xDocSh.is()); + ScDocument& rDoc = xDocSh->GetDocument(); + + //Without the fix in place, it would have failed with + //- Expected: apple + //- Actual : Err:502 + CPPUNIT_ASSERT_EQUAL(OUString("apple"), rDoc.GetString(ScAddress(1, 1, 1))); + CPPUNIT_ASSERT_EQUAL(OUString("apple"), rDoc.GetString(ScAddress(2, 1, 1))); + CPPUNIT_ASSERT_EQUAL(OUString("TRUE"), rDoc.GetString(ScAddress(3, 1, 1))); + CPPUNIT_ASSERT_EQUAL(OUString("fruits"), rDoc.GetString(ScAddress(4, 1, 1))); + CPPUNIT_ASSERT_EQUAL(OUString("apple"), rDoc.GetString(ScAddress(5, 1, 1))); + CPPUNIT_ASSERT_EQUAL(OUString("hat"), rDoc.GetString(ScAddress(6, 1, 1))); + + xDocSh->DoClose(); +} + +void ScFiltersTest2::testTdf125099() +{ + ScDocShellRef xDocSh = loadDoc(u"tdf125099.", FORMAT_ODS); + CPPUNIT_ASSERT_MESSAGE("Failed to open doc", xDocSh.is()); + ScDocument& rDoc = xDocSh->GetDocument(); + + CPPUNIT_ASSERT_EQUAL(OUString("03:53:46"), rDoc.GetString(ScAddress(0, 0, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("03:23:59"), rDoc.GetString(ScAddress(0, 1, 0))); + + xDocSh->DoHardRecalc(); + + CPPUNIT_ASSERT_EQUAL(OUString("03:53:46"), rDoc.GetString(ScAddress(0, 0, 0))); + + // Without the fix in place, this would have failed with + // - Expected: 03:24:00 + // - Actual : 03:23:59 + CPPUNIT_ASSERT_EQUAL(OUString("03:24:00"), rDoc.GetString(ScAddress(0, 1, 0))); + + xDocSh->DoClose(); +} + +void ScFiltersTest2::testTdf134455() +{ + ScDocShellRef xDocSh = loadDoc(u"tdf134455.", FORMAT_XLSX); + CPPUNIT_ASSERT_MESSAGE("Failed to open doc", xDocSh.is()); + ScDocument& rDoc = xDocSh->GetDocument(); + + CPPUNIT_ASSERT_EQUAL(OUString("00:05"), rDoc.GetString(ScAddress(3, 4, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("00:10"), rDoc.GetString(ScAddress(3, 5, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("00:59"), rDoc.GetString(ScAddress(3, 6, 0))); + + // Without the fix in place, TIMEVALUE would have returned Err:502 for values + // greater than 59 + CPPUNIT_ASSERT_EQUAL(OUString("01:05"), rDoc.GetString(ScAddress(3, 7, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("04:00"), rDoc.GetString(ScAddress(3, 8, 0))); + + xDocSh->DoClose(); +} + +void ScFiltersTest2::testTdf119533() +{ + ScDocShellRef xDocSh = loadDoc(u"tdf119533.", FORMAT_ODS); + CPPUNIT_ASSERT_MESSAGE("Failed to open doc", xDocSh.is()); + ScDocument& rDoc = xDocSh->GetDocument(); + + // Without fix in place, this test would have failed with + // - Expected: 0.5 + // - Actual : 0.483333333333333 + CPPUNIT_ASSERT_EQUAL(OUString("0.5"), rDoc.GetString(ScAddress(4, 0, 0))); + + // Without fix in place, this test would have failed with + // - Expected: 9.5 + // - Actual : 9.51666666666667 + CPPUNIT_ASSERT_EQUAL(OUString("9.5"), rDoc.GetString(ScAddress(5, 0, 0))); + + xDocSh->DoClose(); +} + +void ScFiltersTest2::testTdf127982() +{ + ScDocShellRef xDocSh = loadDoc(u"tdf127982.", FORMAT_ODS); + CPPUNIT_ASSERT_MESSAGE("Failed to open doc", xDocSh.is()); + ScDocument& rDoc = xDocSh->GetDocument(); + + // Without the fix in place, these cells would be empty + CPPUNIT_ASSERT_EQUAL(OUString("R1"), rDoc.GetString(ScAddress(3, 5, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("R6"), rDoc.GetString(ScAddress(3, 6, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("R7"), rDoc.GetString(ScAddress(3, 7, 0))); + + CPPUNIT_ASSERT_EQUAL(OUString("R1"), rDoc.GetString(ScAddress(4, 5, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("R6"), rDoc.GetString(ScAddress(4, 6, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("R7"), rDoc.GetString(ScAddress(4, 7, 0))); + + // Without the fix in place, these cells would be empty + CPPUNIT_ASSERT_EQUAL(OUString("R1"), rDoc.GetString(ScAddress(4, 5, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("R6"), rDoc.GetString(ScAddress(4, 6, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("R7"), rDoc.GetString(ScAddress(4, 7, 0))); + + xDocSh->DoClose(); +} + +void ScFiltersTest2::testTdf109409() +{ + ScDocShellRef xDocSh = loadDoc(u"tdf109409.", FORMAT_ODS); + CPPUNIT_ASSERT_MESSAGE("Failed to open doc", xDocSh.is()); + ScDocument& rDoc = xDocSh->GetDocument(); + + // TEXTJOIN + CPPUNIT_ASSERT_EQUAL(OUString("A1;B1;A2;B2;A3;B3"), rDoc.GetString(ScAddress(3, 1, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("A1;B1;A2;B2;A3;B3"), rDoc.GetString(ScAddress(3, 2, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("A1;A2;A3;B1;B2;B3"), rDoc.GetString(ScAddress(3, 4, 0))); + + // Without the fix in place, it would have failed with + //- Expected: A1;B1;A2;B2;A3;B3 + //- Actual : A1;A2;A3;B1;B2;B3 + CPPUNIT_ASSERT_EQUAL(OUString("A1;B1;A2;B2;A3;B3"), rDoc.GetString(ScAddress(3, 5, 0))); + + // CONCAT + CPPUNIT_ASSERT_EQUAL(OUString("A1B1A2B2A3B3"), rDoc.GetString(ScAddress(6, 1, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("A1B1A2B2A3B3"), rDoc.GetString(ScAddress(6, 2, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("A1A2A3B1B2B3"), rDoc.GetString(ScAddress(6, 4, 0))); + + // Without the fix in place, it would have failed with + //- Expected: A1B1A2B2A3B3 + //- Actual : A1A2A3B1B2B3 + CPPUNIT_ASSERT_EQUAL(OUString("A1B1A2B2A3B3"), rDoc.GetString(ScAddress(6, 5, 0))); + + xDocSh->DoClose(); +} + +void ScFiltersTest2::testTdf132105() +{ + ScDocShellRef xDocSh = loadDoc(u"tdf132105.", FORMAT_ODS); + CPPUNIT_ASSERT_MESSAGE("Failed to open doc", xDocSh.is()); + ScDocument& rDoc = xDocSh->GetDocument(); + + // MATCH + CPPUNIT_ASSERT_EQUAL(OUString("5"), rDoc.GetString(ScAddress(0, 1, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("5"), rDoc.GetString(ScAddress(1, 1, 0))); + + // COUNT + CPPUNIT_ASSERT_EQUAL(OUString("0"), rDoc.GetString(ScAddress(0, 2, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("20"), rDoc.GetString(ScAddress(1, 2, 0))); + + // COUNTA + CPPUNIT_ASSERT_EQUAL(OUString("20"), rDoc.GetString(ScAddress(0, 3, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("20"), rDoc.GetString(ScAddress(1, 3, 0))); + + // COUNTBLANK + // Without the fix in place, it would have failed with + // - Expected: 0 + //- Actual : Err:504 + CPPUNIT_ASSERT_EQUAL(OUString("0"), rDoc.GetString(ScAddress(0, 4, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("0"), rDoc.GetString(ScAddress(1, 4, 0))); + + xDocSh->DoClose(); +} + +void ScFiltersTest2::testTdf131424() +{ + ScDocShellRef xDocSh = loadDoc(u"tdf131424.", FORMAT_XLSX); + CPPUNIT_ASSERT_MESSAGE("Failed to open doc", xDocSh.is()); + ScDocument& rDoc = xDocSh->GetDocument(); + + // Without the fix in place, table reference would have failed + CPPUNIT_ASSERT_EQUAL(35.0, rDoc.GetValue(ScAddress(2, 1, 0))); + CPPUNIT_ASSERT_EQUAL(58.0, rDoc.GetValue(ScAddress(2, 2, 0))); + CPPUNIT_ASSERT_EQUAL(81.0, rDoc.GetValue(ScAddress(2, 3, 0))); + CPPUNIT_ASSERT_EQUAL(104.0, rDoc.GetValue(ScAddress(2, 4, 0))); + + xDocSh->DoClose(); +} + +void ScFiltersTest2::testTdf100709XLSX() +{ + ScDocShellRef xDocSh = ScBootstrapFixture::loadDoc(u"tdf100709.", FORMAT_XLSX); + CPPUNIT_ASSERT_MESSAGE("Failed to load tdf100709.xlsx", xDocSh.is()); + + ScDocument& rDoc = xDocSh->GetDocument(); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Cell B52 should not be formatted with a $", OUString("218"), + rDoc.GetString(1, 51, 0)); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Cell A75 should not be formatted as a date", OUString("218"), + rDoc.GetString(0, 74, 0)); + + xDocSh->DoClose(); +} + +void ScFiltersTest2::testTdf97598XLSX() +{ + ScDocShellRef xDocSh = loadDoc(u"tdf97598_scenarios.", FORMAT_XLSX); + CPPUNIT_ASSERT_MESSAGE("Failed to load tdf97598_scenarios.xlsx", xDocSh.is()); + + ScDocument& rDoc = xDocSh->GetDocument(); + OUString aStr = rDoc.GetString(0, 0, 0); // A1 + CPPUNIT_ASSERT_EQUAL(OUString("Cell A1"), aStr); + + xDocSh->DoClose(); +} + +void ScFiltersTest2::testTdf83672XLSX() +{ + ScDocShellRef xDocSh = loadDoc(u"tdf83672.", FORMAT_XLSX); + CPPUNIT_ASSERT_MESSAGE("Failed to load tdf83672.xlsx", xDocSh.is()); + uno::Reference<drawing::XDrawPagesSupplier> xDoc(xDocSh->GetModel(), uno::UNO_QUERY_THROW); + uno::Reference<drawing::XDrawPage> xPage(xDoc->getDrawPages()->getByIndex(0), + uno::UNO_QUERY_THROW); + uno::Reference<drawing::XShape> xShape(xPage->getByIndex(0), uno::UNO_QUERY_THROW); + uno::Reference<beans::XPropertySet> xShapeProperties(xShape, uno::UNO_QUERY); + sal_Int32 nRotate = 0; + xShapeProperties->getPropertyValue("RotateAngle") >>= nRotate; + CPPUNIT_ASSERT(nRotate != 0); + xDocSh->DoClose(); +} + +#ifdef UNX +void ScFiltersTest2::testUnicodeFileNameGnumeric() +{ + // Mapping the LO-internal URL + // <file:///.../sc/qa/unit/data/gnumeric/t%C3%A4%C3%9Ft.gnumeric> to the + // repo's file sc/qa/unit/data/gnumeric/t\303\244\303\237t.gnumeric only + // works when the system encoding is UTF-8: + if (osl_getThreadTextEncoding() != RTL_TEXTENCODING_UTF8) + { + return; + } + ScDocShellRef xDocSh = loadDoc(u"t\u00E4\u00DFt.", FORMAT_GNUMERIC); + CPPUNIT_ASSERT(xDocSh.is()); + + xDocSh->DoClose(); +} +#endif + +void ScFiltersTest2::testMergedCellsXLSXML() +{ + ScDocShellRef xDocSh = loadDoc(u"merged-cells.", FORMAT_XLS_XML); + CPPUNIT_ASSERT_MESSAGE("Failed to load merged-cells.xml", xDocSh.is()); + ScDocument& rDoc = xDocSh->GetDocument(); + + // B1:C1 is merged. + ScRange aMergedRange(1, 0, 0); // B1 + rDoc.ExtendTotalMerge(aMergedRange); + CPPUNIT_ASSERT_EQUAL(ScRange(1, 0, 0, 2, 0, 0), aMergedRange); + + // D1:F1 is merged. + aMergedRange = ScRange(3, 0, 0); // D1 + rDoc.ExtendTotalMerge(aMergedRange); + CPPUNIT_ASSERT_EQUAL(ScRange(3, 0, 0, 5, 0, 0), aMergedRange); + + // A2:A3 is merged. + aMergedRange = ScRange(0, 1, 0); // A2 + rDoc.ExtendTotalMerge(aMergedRange); + CPPUNIT_ASSERT_EQUAL(ScRange(0, 1, 0, 0, 2, 0), aMergedRange); + + // A4:A6 is merged. + aMergedRange = ScRange(0, 3, 0); // A4 + rDoc.ExtendTotalMerge(aMergedRange); + CPPUNIT_ASSERT_EQUAL(ScRange(0, 3, 0, 0, 5, 0), aMergedRange); + + // C3:F6 is merged. + aMergedRange = ScRange(2, 2, 0); // C3 + rDoc.ExtendTotalMerge(aMergedRange); + CPPUNIT_ASSERT_EQUAL(ScRange(2, 2, 0, 5, 5, 0), aMergedRange); + + xDocSh->DoClose(); +} + +void ScFiltersTest2::testBackgroundColorStandardXLSXML() +{ + ScDocShellRef xDocSh = loadDoc(u"background-color-standard.", FORMAT_XLS_XML); + CPPUNIT_ASSERT_MESSAGE("Failed to load background-color-standard.xml", xDocSh.is()); + ScDocument& rDoc = xDocSh->GetDocument(); + + struct Check + { + OUString aCellValue; + Color aFontColor; + Color aBgColor; + }; + + const std::vector<Check> aChecks = { + { OUString("Background Color"), COL_BLACK, COL_TRANSPARENT }, + { OUString("Dark Red"), COL_WHITE, Color(192, 0, 0) }, + { OUString("Red"), COL_WHITE, Color(255, 0, 0) }, + { OUString("Orange"), COL_WHITE, Color(255, 192, 0) }, + { OUString("Yellow"), COL_WHITE, Color(255, 255, 0) }, + { OUString("Light Green"), COL_WHITE, Color(146, 208, 80) }, + { OUString("Green"), COL_WHITE, Color(0, 176, 80) }, + { OUString("Light Blue"), COL_WHITE, Color(0, 176, 240) }, + { OUString("Blue"), COL_WHITE, Color(0, 112, 192) }, + { OUString("Dark Blue"), COL_WHITE, Color(0, 32, 96) }, + { OUString("Purple"), COL_WHITE, Color(112, 48, 160) }, + }; + + for (size_t nRow = 0; nRow < aChecks.size(); ++nRow) + { + ScAddress aPos(0, nRow, 0); + OUString aStr = rDoc.GetString(aPos); + CPPUNIT_ASSERT_EQUAL(aChecks[nRow].aCellValue, aStr); + + const ScPatternAttr* pPat = rDoc.GetPattern(aPos); + CPPUNIT_ASSERT(pPat); + + const SvxColorItem& rColor = pPat->GetItem(ATTR_FONT_COLOR); + CPPUNIT_ASSERT_EQUAL(aChecks[nRow].aFontColor, rColor.GetValue()); + + const SvxBrushItem& rBgColor = pPat->GetItem(ATTR_BACKGROUND); + CPPUNIT_ASSERT_EQUAL(aChecks[nRow].aBgColor, rBgColor.GetColor()); + } + + xDocSh->DoClose(); +} + +void ScFiltersTest2::testTdf131536() +{ + ScDocShellRef xDocSh = loadDoc(u"tdf131536.", FORMAT_XLSX); + CPPUNIT_ASSERT_MESSAGE("Failed to load the document", xDocSh.is()); + ScDocument& rDoc = xDocSh->GetDocument(); + + ScAddress aPos(3, 9, 0); + CPPUNIT_ASSERT_EQUAL(1.0, rDoc.GetValue(aPos)); + ASSERT_FORMULA_EQUAL( + rDoc, aPos, + "IF(D$4=\"-\",\"-\",MID(TEXT(INDEX($Comparison.$I:$J,$Comparison.$A5,$Comparison.D$2),\"\")" + ",2,4)" + "=RIGHT(TEXT(INDEX($Comparison.$L:$Z,$Comparison.$A5,$Comparison.D$4),\"\"),4))", + nullptr); + + ScAddress aPos2(4, 9, 0); + CPPUNIT_ASSERT_EQUAL(1.0, rDoc.GetValue(aPos2)); + ASSERT_FORMULA_EQUAL( + rDoc, aPos2, + "IF(D$4=\"-\",\"-\",MID(TEXT(INDEX($Comparison.$I:$J,$Comparison.$A5,$Comparison.D$2)," + "\"0\"),2,4)" + "=RIGHT(TEXT(INDEX($Comparison.$L:$Z,$Comparison.$A5,$Comparison.D$4),\"0\"),4))", + nullptr); +} + +void ScFiltersTest2::testTdf130583() +{ + ScDocShellRef xDocSh = loadDoc(u"tdf130583.", FORMAT_ODS); + CPPUNIT_ASSERT_MESSAGE("Failed to load the document", xDocSh.is()); + ScDocument& rDoc = xDocSh->GetDocument(); + + CPPUNIT_ASSERT_EQUAL(OUString("b"), rDoc.GetString(ScAddress(1, 0, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("c"), rDoc.GetString(ScAddress(1, 1, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("a"), rDoc.GetString(ScAddress(1, 2, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("d"), rDoc.GetString(ScAddress(1, 3, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("#N/A"), rDoc.GetString(ScAddress(1, 4, 0))); + + // Without the fix in place, SWITCH would have returned #VALUE! + CPPUNIT_ASSERT_EQUAL(OUString("b"), rDoc.GetString(ScAddress(4, 0, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("c"), rDoc.GetString(ScAddress(4, 1, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("a"), rDoc.GetString(ScAddress(4, 2, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("d"), rDoc.GetString(ScAddress(4, 3, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("#N/A"), rDoc.GetString(ScAddress(4, 4, 0))); +} + +void ScFiltersTest2::testTdf85617() +{ + ScDocShellRef xDocSh = loadDoc(u"tdf85617.", FORMAT_XLSX); + CPPUNIT_ASSERT_MESSAGE("Failed to load the document", xDocSh.is()); + ScDocument& rDoc = xDocSh->GetDocument(); + + ScAddress aPos(2, 2, 0); + //Without the fix in place, it would be Err:509 + CPPUNIT_ASSERT_EQUAL(4.5, rDoc.GetValue(aPos)); +} + +void ScFiltersTest2::testTdf134234() +{ + ScDocShellRef xDocSh = loadDoc(u"tdf134234.", FORMAT_ODS); + CPPUNIT_ASSERT_MESSAGE("Failed to load the document", xDocSh.is()); + ScDocument& rDoc = xDocSh->GetDocument(); + + CPPUNIT_ASSERT_EQUAL(3.0, rDoc.GetValue(ScAddress(1, 0, 1))); + + //Without the fix in place, SUMPRODUCT would have returned 0 + CPPUNIT_ASSERT_EQUAL(36.54, rDoc.GetValue(ScAddress(2, 0, 1))); + CPPUNIT_ASSERT_EQUAL(sal_uInt32(833), + static_cast<sal_uInt32>(rDoc.GetValue(ScAddress(3, 0, 1)))); +} + +void ScFiltersTest2::testTdf42481() +{ + ScDocShellRef xDocSh = loadDoc(u"tdf42481.", FORMAT_ODS); + CPPUNIT_ASSERT_MESSAGE("Failed to load the document", xDocSh.is()); + ScDocument& rDoc = xDocSh->GetDocument(); + + CPPUNIT_ASSERT_EQUAL(OUString("#VALUE!"), rDoc.GetString(ScAddress(3, 9, 0))); + + // Without the fix in place, this test would have failed with + // - Expected: #VALUE! + // - Actual : 14 + CPPUNIT_ASSERT_EQUAL(OUString("#VALUE!"), rDoc.GetString(ScAddress(3, 10, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("14"), rDoc.GetString(ScAddress(3, 11, 0))); +} + +void ScFiltersTest2::testNamedExpressionsXLSXML() +{ + { + // global named expressions + + ScDocShellRef xDocSh = loadDoc(u"named-exp-global.", FORMAT_XLS_XML); + CPPUNIT_ASSERT_MESSAGE("Failed to load named-exp-global.xml", xDocSh.is()); + ScDocument& rDoc = xDocSh->GetDocument(); + + // A7 + ScAddress aPos(0, 6, 0); + CPPUNIT_ASSERT_EQUAL(15.0, rDoc.GetValue(aPos)); + ASSERT_FORMULA_EQUAL(rDoc, aPos, "SUM(MyRange)", nullptr); + + // B7 + aPos.IncCol(); + CPPUNIT_ASSERT_EQUAL(55.0, rDoc.GetValue(aPos)); + ASSERT_FORMULA_EQUAL(rDoc, aPos, "SUM(MyRange2)", nullptr); + + const ScRangeData* pRD = rDoc.GetRangeName()->findByUpperName("MYRANGE"); + CPPUNIT_ASSERT(pRD); + pRD = rDoc.GetRangeName()->findByUpperName("MYRANGE2"); + CPPUNIT_ASSERT(pRD); + + xDocSh->DoClose(); + } + + { + // sheet-local named expressions + + ScDocShellRef xDocSh = loadDoc(u"named-exp-local.", FORMAT_XLS_XML); + CPPUNIT_ASSERT_MESSAGE("Failed to load named-exp-local.xml", xDocSh.is()); + ScDocument& rDoc = xDocSh->GetDocument(); + + // A7 on Sheet1 + ScAddress aPos(0, 6, 0); + CPPUNIT_ASSERT_EQUAL(27.0, rDoc.GetValue(aPos)); + ASSERT_FORMULA_EQUAL(rDoc, aPos, "SUM(MyRange)", nullptr); + + // A7 on Sheet2 + aPos.IncTab(); + CPPUNIT_ASSERT_EQUAL(74.0, rDoc.GetValue(aPos)); + ASSERT_FORMULA_EQUAL(rDoc, aPos, "SUM(MyRange)", nullptr); + + const ScRangeName* pRN = rDoc.GetRangeName(0); + CPPUNIT_ASSERT(pRN); + const ScRangeData* pRD = pRN->findByUpperName("MYRANGE"); + CPPUNIT_ASSERT(pRD); + pRN = rDoc.GetRangeName(1); + CPPUNIT_ASSERT(pRN); + pRD = pRN->findByUpperName("MYRANGE"); + CPPUNIT_ASSERT(pRD); + + xDocSh->DoClose(); + } +} + +void ScFiltersTest2::testEmptyRowsXLSXML() +{ + ScDocShellRef xDocSh = loadDoc(u"empty-rows.", FORMAT_XLS_XML); + CPPUNIT_ASSERT_MESSAGE("Failed to load empty-rows.xml", xDocSh.is()); + ScDocument& rDoc = xDocSh->GetDocument(); + + { + // Expected output table content. 0 = empty cell + std::vector<std::vector<const char*>> aOutputCheck = { + { "Top row, followed by 2 empty rows.", nullptr }, + { nullptr, nullptr }, + { nullptr, nullptr }, + { nullptr, "1" }, + { nullptr, "2" }, + { nullptr, "3" }, + { nullptr, "4" }, + { nullptr, "5" }, + { nullptr, "15" }, + }; + + ScRange aDataRange; + aDataRange.Parse("A1:B9", rDoc); + bool bSuccess = checkOutput(&rDoc, aDataRange, aOutputCheck, "Expected output"); + CPPUNIT_ASSERT_MESSAGE("Table output check failed", bSuccess); + } + + ScAddress aPos; + aPos.Parse("B9", rDoc); + ASSERT_FORMULA_EQUAL(rDoc, aPos, "SUM(B4:B8)", nullptr); + + xDocSh->DoClose(); +} + +void ScFiltersTest2::testBorderDirectionsXLSXML() +{ + ScDocShellRef xDocSh = loadDoc(u"border-directions.", FORMAT_XLS_XML); + CPPUNIT_ASSERT_MESSAGE("Failed to load border-directions.xml", xDocSh.is()); + ScDocument& rDoc = xDocSh->GetDocument(); + + struct Check + { + ScAddress aPos; + bool bTop; + bool bBottom; + bool bLeft; + bool bRight; + bool bTLtoBR; + bool bTRtoBL; + }; + + std::vector<Check> aChecks = { + { { 1, 1, 0 }, true, false, false, false, false, false }, // B2 - top + { { 1, 3, 0 }, false, false, true, false, false, false }, // B4 - left + { { 1, 5, 0 }, false, false, false, true, false, false }, // B6 - right + { { 1, 7, 0 }, false, true, false, false, false, false }, // B8 - bottom + { { 1, 9, 0 }, false, false, false, false, true, false }, // B10 - tl to br + { { 1, 11, 0 }, false, false, false, false, false, true }, // B12 - tr to bl + { { 1, 13, 0 }, false, false, false, false, true, true }, // B14 - cross-diagonal + }; + + auto funcCheckBorder = [](bool bHasBorder, const editeng::SvxBorderLine* pLine) -> bool { + if (bHasBorder) + { + if (!pLine) + { + std::cout << "Border was expected, but not found!" << std::endl; + return false; + } + + if (SvxBorderLineStyle::SOLID != pLine->GetBorderLineStyle()) + { + std::cout << "Border type was expected to be of SOLID, but is not." << std::endl; + return false; + } + + if (COL_BLACK != pLine->GetColor()) + { + std::cout << "Border color was expected to be black, but is not." << std::endl; + return false; + } + } + else + { + if (pLine) + { + std::cout << "Border was not expected, but is found!" << std::endl; + return false; + } + } + + return true; + }; + + for (const Check& c : aChecks) + { + const ScPatternAttr* pPat = rDoc.GetPattern(c.aPos); + CPPUNIT_ASSERT(pPat); + + const SvxBoxItem& rBox = pPat->GetItem(ATTR_BORDER); + + const editeng::SvxBorderLine* pLine = rBox.GetTop(); + CPPUNIT_ASSERT(funcCheckBorder(c.bTop, pLine)); + + pLine = rBox.GetBottom(); + CPPUNIT_ASSERT(funcCheckBorder(c.bBottom, pLine)); + + pLine = rBox.GetLeft(); + CPPUNIT_ASSERT(funcCheckBorder(c.bLeft, pLine)); + + pLine = rBox.GetRight(); + CPPUNIT_ASSERT(funcCheckBorder(c.bRight, pLine)); + + pLine = pPat->GetItem(ATTR_BORDER_TLBR).GetLine(); + CPPUNIT_ASSERT(funcCheckBorder(c.bTLtoBR, pLine)); + + pLine = pPat->GetItem(ATTR_BORDER_BLTR).GetLine(); + CPPUNIT_ASSERT(funcCheckBorder(c.bTRtoBL, pLine)); + } + + xDocSh->DoClose(); +} + +void ScFiltersTest2::testBorderColorsXLSXML() +{ + ScDocShellRef xDocSh = loadDoc(u"border-colors.", FORMAT_XLS_XML); + CPPUNIT_ASSERT_MESSAGE("Failed to load border-colors.xml", xDocSh.is()); + ScDocument& rDoc = xDocSh->GetDocument(); + + // B3 - red + const ScPatternAttr* pPat = rDoc.GetPattern(ScAddress(1, 2, 0)); + CPPUNIT_ASSERT(pPat); + const editeng::SvxBorderLine* pLine = pPat->GetItem(ATTR_BORDER).GetRight(); + CPPUNIT_ASSERT(pLine); + CPPUNIT_ASSERT_EQUAL(SvxBorderLineStyle::SOLID, pLine->GetBorderLineStyle()); + CPPUNIT_ASSERT_EQUAL(Color(255, 0, 0), pLine->GetColor()); + + // B4 - blue + pPat = rDoc.GetPattern(ScAddress(1, 3, 0)); + CPPUNIT_ASSERT(pPat); + pLine = pPat->GetItem(ATTR_BORDER).GetRight(); + CPPUNIT_ASSERT(pLine); + CPPUNIT_ASSERT_EQUAL(SvxBorderLineStyle::SOLID, pLine->GetBorderLineStyle()); + CPPUNIT_ASSERT_EQUAL(Color(0, 112, 192), pLine->GetColor()); + + // B5 - green + pPat = rDoc.GetPattern(ScAddress(1, 4, 0)); + CPPUNIT_ASSERT(pPat); + pLine = pPat->GetItem(ATTR_BORDER).GetRight(); + CPPUNIT_ASSERT(pLine); + CPPUNIT_ASSERT_EQUAL(SvxBorderLineStyle::SOLID, pLine->GetBorderLineStyle()); + CPPUNIT_ASSERT_EQUAL(Color(0, 176, 80), pLine->GetColor()); + + // B7 - yellow (left), purple (right), light blue (cross) + pPat = rDoc.GetPattern(ScAddress(1, 6, 0)); + CPPUNIT_ASSERT(pPat); + + pLine = pPat->GetItem(ATTR_BORDER).GetLeft(); + CPPUNIT_ASSERT(pLine); + CPPUNIT_ASSERT_EQUAL(SvxBorderLineStyle::SOLID, pLine->GetBorderLineStyle()); + CPPUNIT_ASSERT_EQUAL(Color(255, 255, 0), pLine->GetColor()); // yellow + + pLine = pPat->GetItem(ATTR_BORDER).GetRight(); + CPPUNIT_ASSERT(pLine); + CPPUNIT_ASSERT_EQUAL(SvxBorderLineStyle::SOLID, pLine->GetBorderLineStyle()); + CPPUNIT_ASSERT_EQUAL(Color(112, 48, 160), pLine->GetColor()); // purple + + pLine = pPat->GetItem(ATTR_BORDER_TLBR).GetLine(); + CPPUNIT_ASSERT(pLine); + CPPUNIT_ASSERT_EQUAL(SvxBorderLineStyle::SOLID, pLine->GetBorderLineStyle()); + CPPUNIT_ASSERT_EQUAL(Color(0, 176, 240), pLine->GetColor()); // light blue + + pLine = pPat->GetItem(ATTR_BORDER_BLTR).GetLine(); + CPPUNIT_ASSERT(pLine); + CPPUNIT_ASSERT_EQUAL(SvxBorderLineStyle::SOLID, pLine->GetBorderLineStyle()); + CPPUNIT_ASSERT_EQUAL(Color(0, 176, 240), pLine->GetColor()); // light blue + + xDocSh->DoClose(); +} + +void ScFiltersTest2::testHiddenRowsColumnsXLSXML() +{ + ScDocShellRef xDocSh = loadDoc(u"hidden-rows-columns.", FORMAT_XLS_XML); + CPPUNIT_ASSERT_MESSAGE("Failed to load hidden-rows-columns.xml", xDocSh.is()); + ScDocument& rDoc = xDocSh->GetDocument(); + + struct Check + { + SCCOLROW nPos1; + SCCOLROW nPos2; + bool bVisible; + }; + + std::vector<Check> aRowChecks = { + { 0, 0, true }, { 1, 2, false }, { 3, 3, true }, { 4, 4, false }, + { 5, 7, true }, { 8, 8, false }, { 9, MAXROW, true }, + }; + + for (const Check& c : aRowChecks) + { + SCROW nRow1 = -1, nRow2 = -1; + bool bVisible = !rDoc.RowHidden(c.nPos1, 0, &nRow1, &nRow2); + CPPUNIT_ASSERT_EQUAL(bVisible, c.bVisible); + CPPUNIT_ASSERT_EQUAL(c.nPos1, nRow1); + CPPUNIT_ASSERT_EQUAL(c.nPos2, nRow2); + } + + std::vector<Check> aColChecks = { + { 0, 1, true }, { 2, 5, false }, { 6, 9, true }, { 10, 10, false }, { 11, MAXCOL, true }, + }; + + for (const Check& c : aColChecks) + { + SCCOL nCol1 = -1, nCol2 = -1; + bool bVisible = !rDoc.ColHidden(c.nPos1, 1, &nCol1, &nCol2); + CPPUNIT_ASSERT_EQUAL(bVisible, c.bVisible); + CPPUNIT_ASSERT_EQUAL(c.nPos1, SCCOLROW(nCol1)); + CPPUNIT_ASSERT_EQUAL(c.nPos2, SCCOLROW(nCol2)); + } + + xDocSh->DoClose(); +} + +void ScFiltersTest2::testColumnWidthRowHeightXLSXML() +{ + ScDocShellRef xDocSh = loadDoc(u"column-width-row-height.", FORMAT_XLS_XML); + CPPUNIT_ASSERT_MESSAGE("Failed to load column-width-row-height.xml", xDocSh.is()); + ScDocument& rDoc = xDocSh->GetDocument(); + + struct RowHeight + { + SCROW nRow1; + SCROW nRow2; + sal_uInt16 nHeight; // in points (1 point == 20 twips) + }; + + std::vector<RowHeight> aRowChecks = { + { 2, 2, 20 }, { 3, 3, 30 }, { 4, 4, 40 }, { 5, 5, 50 }, { 7, 9, 25 }, { 12, 13, 35 }, + }; + + for (const RowHeight& rh : aRowChecks) + { + for (SCROW i = rh.nRow1; i <= rh.nRow2; ++i) + { + sal_uInt16 nHeight = rDoc.GetRowHeight(i, 0); + CPPUNIT_ASSERT_EQUAL(sal_uInt16(rh.nHeight * 20), nHeight); + } + } + + struct ColWidth + { + SCCOL nCol1; + SCCOL nCol2; + sal_uInt16 nWidth; // in points (1 point == 20 twips + }; + + std::vector<ColWidth> aColChecks = { + { 1, 1, 56 }, { 2, 2, 83 }, { 3, 3, 109 }, { 5, 7, 67 }, { 10, 11, 119 }, + }; + + for (const ColWidth& cw : aColChecks) + { + for (SCCOL i = cw.nCol1; i <= cw.nCol2; ++i) + { + sal_uInt16 nWidth = rDoc.GetColWidth(i, 0); + CPPUNIT_ASSERT_EQUAL(sal_uInt16(cw.nWidth * 20), nWidth); + } + } + + xDocSh->DoClose(); +} + +void ScFiltersTest2::testCharacterSetXLSXML() +{ + ScDocShellRef xDocSh = loadDoc(u"character-set.", FORMAT_XLS_XML); + CPPUNIT_ASSERT_MESSAGE("Failed to load column-width-row-height.xml", xDocSh.is()); + ScDocument& rDoc = xDocSh->GetDocument(); + + CPPUNIT_ASSERT_EQUAL(SCTAB(1), rDoc.GetTableCount()); + + OUString aName; + rDoc.GetName(0, aName); + + // Check the sheet name. The values are all Cyrillic letters. + std::vector<sal_Unicode> aBuf = { 0x041b, 0x0438, 0x0441, 0x0442, 0x0031 }; + OUString aExpected(aBuf.data(), aBuf.size()); + CPPUNIT_ASSERT_EQUAL(aExpected, aName); + + // Check the value of I4 + OUString aVal = rDoc.GetString(ScAddress(8, 3, 0)); + aBuf = { 0x0421, 0x0443, 0x043c, 0x043c, 0x0430 }; + aExpected = OUString(aBuf.data(), aBuf.size()); + CPPUNIT_ASSERT_EQUAL(aExpected, aVal); + + // Check the value of J3 + aVal = rDoc.GetString(ScAddress(9, 2, 0)); + aBuf = { 0x041e, 0x0441, 0x0442, 0x0430, 0x0442, 0x043e, 0x043a }; + aExpected = OUString(aBuf.data(), aBuf.size()); + CPPUNIT_ASSERT_EQUAL(aExpected, aVal); + + xDocSh->DoClose(); +} + +void ScFiltersTest2::testCondFormatXLSB() +{ + ScDocShellRef xDocSh = loadDoc(u"cond_format.", FORMAT_XLSB); + + ScDocument& rDoc = xDocSh->GetDocument(); + ScConditionalFormatList* pList = rDoc.GetCondFormList(0); + CPPUNIT_ASSERT(pList); + + CPPUNIT_ASSERT_EQUAL(size_t(1), pList->size()); + ScConditionalFormat* pFormat = pList->begin()->get(); + CPPUNIT_ASSERT(pFormat); + CPPUNIT_ASSERT_EQUAL(size_t(1), pFormat->size()); + + xDocSh->DoClose(); +} + +void ScFiltersTest2::testPageScalingXLSX() +{ + ScDocShellRef xDocSh = loadDoc(u"page_scale.", FORMAT_XLSX); + ScDocument& rDoc = xDocSh->GetDocument(); + + OUString aStyleName = rDoc.GetPageStyle(0); + ScStyleSheetPool* pStylePool = rDoc.GetStyleSheetPool(); + SfxStyleSheetBase* pStyleSheet = pStylePool->Find(aStyleName, SfxStyleFamily::Page); + CPPUNIT_ASSERT(pStyleSheet); + + SfxItemSet& rSet = pStyleSheet->GetItemSet(); + sal_uInt16 nVal = rSet.Get(ATTR_PAGE_SCALE).GetValue(); + CPPUNIT_ASSERT_EQUAL(sal_uInt16(90), nVal); + + xDocSh->DoClose(); +} + +void ScFiltersTest2::testActiveXCheckboxXLSX() +{ + ScDocShellRef xDocSh = loadDoc(u"activex_checkbox.", FORMAT_XLSX); + uno::Reference<frame::XModel> xModel = xDocSh->GetModel(); + uno::Reference<sheet::XSpreadsheetDocument> xDoc(xModel, UNO_QUERY_THROW); + uno::Reference<container::XIndexAccess> xIA(xDoc->getSheets(), UNO_QUERY_THROW); + uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(xIA->getByIndex(0), + UNO_QUERY_THROW); + uno::Reference<container::XIndexAccess> xIA_DrawPage(xDrawPageSupplier->getDrawPage(), + UNO_QUERY_THROW); + uno::Reference<drawing::XControlShape> xControlShape(xIA_DrawPage->getByIndex(0), + UNO_QUERY_THROW); + + // Check control type + uno::Reference<beans::XPropertySet> xPropertySet(xControlShape->getControl(), uno::UNO_QUERY); + uno::Reference<lang::XServiceInfo> xServiceInfo(xPropertySet, uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL( + true, bool(xServiceInfo->supportsService("com.sun.star.form.component.CheckBox"))); + + // Check custom label + OUString sLabel; + xPropertySet->getPropertyValue("Label") >>= sLabel; + CPPUNIT_ASSERT_EQUAL(OUString("Custom Caption"), sLabel); + + // Check background color (highlight system color) + sal_Int32 nColor; + xPropertySet->getPropertyValue("BackgroundColor") >>= nColor; + CPPUNIT_ASSERT_EQUAL(sal_Int32(0x316AC5), nColor); + + // Check Text color (active border system color) + xPropertySet->getPropertyValue("TextColor") >>= nColor; + CPPUNIT_ASSERT_EQUAL(sal_Int32(0xD4D0C8), nColor); + + // Check state of the checkbox + sal_Int16 nState; + xPropertySet->getPropertyValue("State") >>= nState; + CPPUNIT_ASSERT_EQUAL(sal_Int16(1), nState); + + xDocSh->DoClose(); +} + +void ScFiltersTest2::testtdf120301_xmlSpaceParsingXLSX() +{ + ScDocShellRef xDocSh = loadDoc(u"tdf120301_xmlSpaceParsing.", FORMAT_XLSX); + uno::Reference<frame::XModel> xModel = xDocSh->GetModel(); + uno::Reference<sheet::XSpreadsheetDocument> xDoc(xModel, UNO_QUERY_THROW); + uno::Reference<container::XIndexAccess> xIA(xDoc->getSheets(), UNO_QUERY_THROW); + uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(xIA->getByIndex(0), + UNO_QUERY_THROW); + uno::Reference<container::XIndexAccess> xIA_DrawPage(xDrawPageSupplier->getDrawPage(), + UNO_QUERY_THROW); + + uno::Reference<drawing::XControlShape> xControlShape(xIA_DrawPage->getByIndex(0), + UNO_QUERY_THROW); + uno::Reference<beans::XPropertySet> XPropSet(xControlShape->getControl(), uno::UNO_QUERY_THROW); + OUString sCaption; + XPropSet->getPropertyValue("Label") >>= sCaption; + CPPUNIT_ASSERT_EQUAL(OUString("Check Box 1"), sCaption); + xDocSh->DoClose(); +} + +namespace +{ +struct PaintListener : public SfxListener +{ + bool mbCalled = false; + virtual void Notify(SfxBroadcaster& /*rBC*/, const SfxHint& rHint) override + { + const ScPaintHint* pPaintHint = dynamic_cast<const ScPaintHint*>(&rHint); + if (pPaintHint) + { + if (pPaintHint->GetStartCol() <= 0 && pPaintHint->GetEndCol() >= 0 + && pPaintHint->GetStartRow() <= 9 && pPaintHint->GetEndRow() >= 9) + { + mbCalled = true; + } + } + } +}; +} + +void ScFiltersTest2::testCondFormatFormulaListenerXLSX() +{ + ScDocShellRef xDocSh = loadDoc(u"cond_format_formula_listener.", FORMAT_XLSX); + PaintListener aListener; + aListener.StartListening(*xDocSh); + ScDocument& rDoc = xDocSh->GetDocument(); + ScConditionalFormatList* pList = rDoc.GetCondFormList(0); + CPPUNIT_ASSERT(pList); + + CPPUNIT_ASSERT_EQUAL(size_t(1), pList->size()); + ScConditionalFormat* pFormat = pList->begin()->get(); + CPPUNIT_ASSERT(pFormat); + rDoc.SetDocVisible(true); + rDoc.SetValue(0, 0, 0, 2.0); + + CPPUNIT_ASSERT(aListener.mbCalled); + + xDocSh->DoClose(); +} + +void ScFiltersTest2::testTdf137091() +{ + // Set the system locale to Turkish + SvtSysLocaleOptions aOptions; + OUString sLocaleConfigString = aOptions.GetLanguageTag().getBcp47(); + aOptions.SetLocaleConfigString("tr-TR"); + aOptions.Commit(); + comphelper::ScopeGuard g([&aOptions, &sLocaleConfigString] { + aOptions.SetLocaleConfigString(sLocaleConfigString); + aOptions.Commit(); + }); + + ScDocShellRef xDocSh = loadDoc(u"tdf137091.", FORMAT_XLSX); + ScDocument& rDoc = xDocSh->GetDocument(); + + // Without the fix in place, this test would have failed with + // - Expected: 28/4 + // - Actual : Err:507 + CPPUNIT_ASSERT_EQUAL(OUString("28/4"), rDoc.GetString(ScAddress(2, 1, 0))); + xDocSh->DoClose(); +} + +void ScFiltersTest2::testTdf62268() +{ + ScDocShellRef xDocSh = loadDoc(u"tdf62268.", FORMAT_ODS); + ScDocument& rDoc = xDocSh->GetDocument(); + int nHeight; + + SCTAB nTab = 0; + nHeight = rDoc.GetRowHeight(0, nTab, false); + CPPUNIT_ASSERT_LESSEQUAL(3, abs(256 - nHeight)); + nHeight = rDoc.GetRowHeight(1, nTab, false); + CPPUNIT_ASSERT_LESSEQUAL(19, abs(1905 - nHeight)); + + xDocSh->DoClose(); +} + +void ScFiltersTest2::testTdf137453() +{ + ScDocShellRef xDocSh = loadDoc(u"tdf137453.", FORMAT_ODS); + CPPUNIT_ASSERT_MESSAGE("Failed to open doc", xDocSh.is()); + + ScDocument& rDoc = xDocSh->GetDocument(); + + // Without the fix in place, this test would have failed with + // - Expected: 3333333333/100 + // - Actual : -961633963/100 + CPPUNIT_ASSERT_EQUAL(OUString("3333333333/100"), rDoc.GetString(ScAddress(0, 0, 0))); + + xDocSh->DoClose(); +} + +void ScFiltersTest2::testTdf112780() +{ + ScDocShellRef xDocSh = loadDoc(u"tdf112780.", FORMAT_ODS); + CPPUNIT_ASSERT_MESSAGE("Failed to open doc", xDocSh.is()); + + ScDocument& rDoc = xDocSh->GetDocument(); + + // Without the fix in place, this test would have failed with + // - Expected: + // - Actual : #VALUE! + CPPUNIT_ASSERT_EQUAL(OUString(""), rDoc.GetString(ScAddress(3, 5, 0))); + + OUString aFormula; + rDoc.GetFormula(3, 5, 0, aFormula); + CPPUNIT_ASSERT_EQUAL(OUString("=G6+J6+M6"), aFormula); + + xDocSh->DoClose(); +} + +void ScFiltersTest2::testTdf72470() +{ + // Without the fix in place, this test would have hung + + ScDocShellRef xDocSh = loadDoc(u"tdf72470.", FORMAT_XLS); + CPPUNIT_ASSERT_MESSAGE("Failed to open doc", xDocSh.is()); + + ScDocument& rDoc = xDocSh->GetDocument(); + + CPPUNIT_ASSERT_EQUAL(OUString("name"), rDoc.GetString(ScAddress(0, 0, 0))); + CPPUNIT_ASSERT_EQUAL(OUString(u"أسمي walid"), rDoc.GetString(ScAddress(0, 1, 0))); + + xDocSh->DoClose(); +} + +void ScFiltersTest2::testTdf35636() +{ + ScDocShellRef xDocSh = loadDoc(u"tdf35636.", FORMAT_ODS); + CPPUNIT_ASSERT_MESSAGE("Failed to open doc", xDocSh.is()); + + ScDocument& rDoc = xDocSh->GetDocument(); + + // Without the fix in place, SUMIF would have returned 0.0 + // with empty cells in the criteria + CPPUNIT_ASSERT_EQUAL(50.0, rDoc.GetValue(ScAddress(1, 4, 0))); + + xDocSh->DoClose(); +} + +void ScFiltersTest2::testTdf98481() +{ + ScDocShellRef xDocSh = loadDoc(u"tdf98481.", FORMAT_XLSX); + CPPUNIT_ASSERT_MESSAGE("Failed to open doc", xDocSh.is()); + + ScDocument& rDoc = xDocSh->GetDocument(); + + // Without the fix in place, this test would have failed with + // - Expected: 4 + // - Actual : 0 + CPPUNIT_ASSERT_EQUAL(4.0, rDoc.GetValue(ScAddress(4, 1, 0))); + CPPUNIT_ASSERT_EQUAL(0.0, rDoc.GetValue(ScAddress(4, 2, 0))); + CPPUNIT_ASSERT_EQUAL(3.0, rDoc.GetValue(ScAddress(4, 3, 0))); + CPPUNIT_ASSERT_EQUAL(4.0, rDoc.GetValue(ScAddress(1, 4, 0))); + CPPUNIT_ASSERT_EQUAL(0.0, rDoc.GetValue(ScAddress(2, 4, 0))); + CPPUNIT_ASSERT_EQUAL(3.0, rDoc.GetValue(ScAddress(3, 4, 0))); + + xDocSh->DoClose(); +} + +void ScFiltersTest2::testTdf115022() +{ + ScDocShellRef xDocSh = loadDoc(u"tdf115022.", FORMAT_XLSX); + CPPUNIT_ASSERT_MESSAGE("Failed to open doc", xDocSh.is()); + + ScDocument& rDoc = xDocSh->GetDocument(); + + CPPUNIT_ASSERT_EQUAL(6.0, rDoc.GetValue(ScAddress(1, 8, 0))); + + xDocSh->DoHardRecalc(); + + // Without the fix in place, this test would have failed with + // - Expected: 6 + // - Actual : 21 + CPPUNIT_ASSERT_EQUAL(6.0, rDoc.GetValue(ScAddress(1, 8, 0))); + + xDocSh->DoClose(); +} + +void ScFiltersTest2::testVBAMacroFunctionODS() +{ + ScDocShellRef xDocSh = loadDoc(u"vba_macro_functions.", FORMAT_ODS); + ScDocument& rDoc = xDocSh->GetDocument(); + + OUString aFunction; + rDoc.GetFormula(2, 0, 0, aFunction); + std::cout << aFunction << std::endl; + CPPUNIT_ASSERT_DOUBLES_EQUAL(10.0, rDoc.GetValue(2, 0, 0), 1e-6); + + xDocSh->DoClose(); +} + +void ScFiltersTest2::testAutoheight2Rows() +{ + ScDocShellRef xDocSh = loadDoc(u"autoheight2rows.", FORMAT_ODS); + ScDocument& rDoc = xDocSh->GetDocument(); + + SCTAB nTab = 0; + int nHeight1 = rDoc.GetRowHeight(0, nTab, false); + int nHeight2 = rDoc.GetRowHeight(1, nTab, false); + int nHeight4 = rDoc.GetRowHeight(3, nTab, false); + int nHeight5 = rDoc.GetRowHeight(4, nTab, false); + + // We will do relative comparison, because calculated autoheight + // can be different on different platforms + CPPUNIT_ASSERT_MESSAGE("Row #1 and row #4 must have same height after load & auto-adjust", + abs(nHeight1 - nHeight4) < 10); + CPPUNIT_ASSERT_MESSAGE("Row #2 and row #5 must have same height after load & auto-adjust", + abs(nHeight2 - nHeight5) < 10); + + xDocSh->DoClose(); +} + +void ScFiltersTest2::testXLSDefColWidth() +{ + // XLS has only 256 columns; but on import, we need to set default width to all above that limit + ScDocShellRef xDocSh = loadDoc(u"chartx.", FORMAT_XLS); // just some XLS with narrow columns + ScDocument& rDoc = xDocSh->GetDocument(); + + int nWidth = rDoc.GetColWidth(MAXCOL, 0, false); + // This was 1280 + CPPUNIT_ASSERT_EQUAL(1005, nWidth); + + xDocSh->DoClose(); +} + +void ScFiltersTest2::testPreviewMissingObjLink() +{ + ScDocShellRef xDocSh = loadDoc(u"keep-preview-missing-obj-link.", FORMAT_ODS); + CPPUNIT_ASSERT_MESSAGE("Failed to load keep-preview-missing-obj-link.ods.", xDocSh.is()); + + ScDocument& rDoc = xDocSh->GetDocument(); + + // Retrieve the ole object + const SdrOle2Obj* pOleObj = getSingleOleObject(rDoc, 0); + CPPUNIT_ASSERT_MESSAGE("Failed to retrieve an ole object from the 2nd sheet.", pOleObj); + + const Graphic* pGraphic = pOleObj->GetGraphic(); + CPPUNIT_ASSERT_MESSAGE( + "the ole object links to a missing file, but we should retain its preview", pGraphic); + + xDocSh->DoClose(); +} + +void ScFiltersTest2::testShapeRotationImport() +{ + if (!IsDefaultDPI()) + return; + // tdf#83593 Incorrectly calculated bounding rectangles caused shapes to appear as if there + // were extra or missing rotations. Hence, we check the sizes of these rectangles. + ScDocShellRef xDocSh = loadDoc(u"testShapeRotationImport.", FORMAT_XLSX); + CPPUNIT_ASSERT_MESSAGE("Failed to load testShapeRotationImport.xlsx", xDocSh.is()); + uno::Reference<drawing::XDrawPagesSupplier> xDoc(xDocSh->GetModel(), uno::UNO_QUERY_THROW); + uno::Reference<drawing::XDrawPage> xPage(xDoc->getDrawPages()->getByIndex(0), + uno::UNO_QUERY_THROW); + + // The expected values are in the map below. Note that some of the angles are outside of the set which contains + // the value of the wrong angles. This is to check the border cases and one value on both sides. + std::map<sal_Int32, std::map<std::string, sal_Int32>> aExpectedValues{ + { 4400, { { "x", 6832 }, { "y", 36893 }, { "width", 8898 }, { "height", 1163 } } }, + { 4500, { { "x", 4490 }, { "y", 36400 }, { "width", 8898 }, { "height", 1163 } } }, + { 4600, { { "x", 1673 }, { "y", 36270 }, { "width", 8862 }, { "height", 1144 } } }, + { 13400, { { "x", 13762 }, { "y", 28403 }, { "width", 8863 }, { "height", 1194 } } }, + { 13500, { { "x", 10817 }, { "y", 27951 }, { "width", 8863 }, { "height", 1170 } } }, + { 13600, { { "x", 8449 }, { "y", 28336 }, { "width", 8897 }, { "height", 1164 } } }, + { 22400, { { "x", 14948 }, { "y", 12978 }, { "width", 8898 }, { "height", 1164 } } }, + { 22500, { { "x", 11765 }, { "y", 12834 }, { "width", 8898 }, { "height", 1164 } } }, + { 22600, { { "x", 8253 }, { "y", 12919 }, { "width", 8863 }, { "height", 1171 } } }, + { 31400, { { "x", 8099 }, { "y", 1160 }, { "width", 9815 }, { "height", 1171 } } }, + { 31500, { { "x", 4427 }, { "y", 1274 }, { "width", 10238 }, { "height", 1171 } } }, + { 31600, { { "x", 1964 }, { "y", 1878 }, { "width", 10307 }, { "height", 1164 } } }, + }; + + for (sal_Int32 ind = 0; ind < 12; ++ind) + { + uno::Reference<drawing::XShape> xShape(xPage->getByIndex(ind), uno::UNO_QUERY_THROW); + + uno::Reference<beans::XPropertySet> xShapeProperties(xShape, uno::UNO_QUERY); + uno::Any nRotProp = xShapeProperties->getPropertyValue("RotateAngle"); + sal_Int32 nRot = nRotProp.get<sal_Int32>(); + + awt::Point aPosition = xShape->getPosition(); + awt::Size aSize = xShape->getSize(); + + CPPUNIT_ASSERT(aExpectedValues.find(nRot) != aExpectedValues.end()); + CPPUNIT_ASSERT_EQUAL(aExpectedValues[nRot]["x"], aPosition.X); + CPPUNIT_ASSERT_EQUAL(aExpectedValues[nRot]["y"], aPosition.Y); + CPPUNIT_ASSERT_EQUAL(aExpectedValues[nRot]["width"], aSize.Width); + CPPUNIT_ASSERT_EQUAL(aExpectedValues[nRot]["height"], aSize.Height); + } +} + +void ScFiltersTest2::testShapeDisplacementOnRotationImport() +{ + // tdf#135918 shape is displaced on rotation if it is placed next to the sheets upper/left edges + ScDocShellRef xDocSh = loadDoc(u"testShapeDisplacementOnRotationImport.", FORMAT_XLSX); + CPPUNIT_ASSERT_MESSAGE("Failed to load testShapeDisplacementOnRotationImport.xlsx", + xDocSh.is()); + + uno::Reference<drawing::XDrawPagesSupplier> xDoc(xDocSh->GetModel(), uno::UNO_QUERY_THROW); + uno::Reference<drawing::XDrawPage> xPage(xDoc->getDrawPages()->getByIndex(0), + uno::UNO_QUERY_THROW); + uno::Reference<drawing::XShape> xShape(xPage->getByIndex(0), uno::UNO_QUERY_THROW); + + uno::Reference<beans::XPropertySet> xShapeProperties(xShape, uno::UNO_QUERY_THROW); + uno::Any aRectProp = xShapeProperties->getPropertyValue("FrameRect"); + awt::Rectangle aRectangle = aRectProp.get<awt::Rectangle>(); + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), aRectangle.X); + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aRectangle.Y); +} + +void ScFiltersTest2::testTextBoxBodyUpright() +{ + // tdf#106197 We should import the "upright" attribute of txBody. + ScDocShellRef xDocSh = loadDoc(u"tdf106197_import_upright.", FORMAT_XLSX); + CPPUNIT_ASSERT_MESSAGE("Failed to load testTextBoxBodyUpright.xlsx", xDocSh.is()); + + uno::Reference<drawing::XDrawPagesSupplier> xDoc(xDocSh->GetModel(), uno::UNO_QUERY_THROW); + uno::Reference<drawing::XDrawPage> xPage(xDoc->getDrawPages()->getByIndex(0), + uno::UNO_QUERY_THROW); + uno::Reference<drawing::XShape> xShape(xPage->getByIndex(0), uno::UNO_QUERY_THROW); + uno::Reference<beans::XPropertySet> xShapeProperties(xShape, uno::UNO_QUERY_THROW); + + // Check that we imported "Upright". + bool isUpright = false; + if (xShapeProperties->getPropertySetInfo()->hasPropertyByName("InteropGrabBag")) + { + uno::Sequence<beans::PropertyValue> aGrabBag; + xShapeProperties->getPropertyValue("InteropGrabBag") >>= aGrabBag; + for (auto& aProp : aGrabBag) + { + if (aProp.Name == "Upright") + { + aProp.Value >>= isUpright; + break; + } + } + } + CPPUNIT_ASSERT_EQUAL(true, isUpright); + + // Check the new textRotateAngle. + sal_Int32 nAngle; + uno::Any aGeom = xShapeProperties->getPropertyValue("CustomShapeGeometry"); + auto aGeomSeq = aGeom.get<Sequence<beans::PropertyValue>>(); + for (const auto& aProp : std::as_const(aGeomSeq)) + { + if (aProp.Name == "TextPreRotateAngle") + { + aProp.Value >>= nAngle; + break; + } + } + CPPUNIT_ASSERT_EQUAL(sal_Int32(90), nAngle); +} + +void ScFiltersTest2::testTextBoxBodyRotateAngle() +{ + ScDocShellRef xDocSh = loadDoc(u"tdf141644.", FORMAT_XLSX); + CPPUNIT_ASSERT_MESSAGE("Failed to load tdf141644.xlsx", xDocSh.is()); + + uno::Reference<drawing::XDrawPagesSupplier> xDoc(xDocSh->GetModel(), uno::UNO_QUERY_THROW); + uno::Reference<drawing::XDrawPage> xPage(xDoc->getDrawPages()->getByIndex(0), + uno::UNO_QUERY_THROW); + uno::Reference<drawing::XShape> xShape(xPage->getByIndex(0), uno::UNO_QUERY_THROW); + uno::Reference<beans::XPropertySet> xShapeProperties(xShape, uno::UNO_QUERY_THROW); + + // Check the new textRotateAngle. + sal_Int32 nAngle; + uno::Any aGeom = xShapeProperties->getPropertyValue("CustomShapeGeometry"); + auto aGeomSeq = aGeom.get<Sequence<beans::PropertyValue>>(); + for (const auto& aProp : std::as_const(aGeomSeq)) + { + if (aProp.Name == "TextPreRotateAngle") + { + aProp.Value >>= nAngle; + break; + } + } + CPPUNIT_ASSERT_EQUAL(sal_Int32(-270), nAngle); +} + +void ScFiltersTest2::testTextLengthDataValidityXLSX() +{ + ScDocShellRef xDocSh = loadDoc(u"textLengthDataValidity.", FORMAT_XLSX); + CPPUNIT_ASSERT_MESSAGE("Failed to load textLengthDataValidity.xlsx", xDocSh.is()); + + ScDocument& rDoc = xDocSh->GetDocument(); + + const ScValidationData* pData = rDoc.GetValidationEntry(1); + + ScRefCellValue aCellA1; // A1 = 1234(numeric value) + ScAddress aValBaseAddrA1(0, 0, 0); + aCellA1.assign(rDoc, aValBaseAddrA1); + bool bValidA1 = pData->IsDataValid(aCellA1, aValBaseAddrA1); + + ScRefCellValue aCellA2; // A2 = 1234(numeric value format as text) + ScAddress aValBaseAddrA2(0, 1, 0); + aCellA2.assign(rDoc, aValBaseAddrA2); + bool bValidA2 = pData->IsDataValid(aCellA2, aValBaseAddrA2); + + ScRefCellValue aCellA3; // A3 = 1234.00(numeric value) + ScAddress aValBaseAddrA3(0, 2, 0); + aCellA3.assign(rDoc, aValBaseAddrA3); + bool bValidA3 = pData->IsDataValid(aCellA3, aValBaseAddrA3); + + ScRefCellValue aCellA4; // A4 = 12.3(numeric value) + ScAddress aValBaseAddrA4(0, 3, 0); + aCellA4.assign(rDoc, aValBaseAddrA4); + bool bValidA4 = pData->IsDataValid(aCellA4, aValBaseAddrA4); + + // True if text length = 4 + CPPUNIT_ASSERT_EQUAL(true, bValidA1); + CPPUNIT_ASSERT_EQUAL(true, bValidA2); + CPPUNIT_ASSERT_EQUAL(true, bValidA3); + CPPUNIT_ASSERT_EQUAL(true, bValidA4); + + xDocSh->DoClose(); +} + +void ScFiltersTest2::testDeleteCircles() +{ + ScDocShellRef xDocSh = loadDoc(u"testDeleteCircles.", FORMAT_XLSX); + CPPUNIT_ASSERT_MESSAGE("Failed to load testDeleteCircles.xlsx", xDocSh.is()); + + ScDocument& rDoc = xDocSh->GetDocument(); + + ScDrawLayer* pDrawLayer = rDoc.GetDrawLayer(); + SdrPage* pPage = pDrawLayer->GetPage(0); + CPPUNIT_ASSERT_MESSAGE("draw page for sheet 1 should exist.", pPage); + + ScRefCellValue aCellA1; // A1 = "Hello" + ScAddress aPosA1(0, 0, 0); + aCellA1.assign(rDoc, aPosA1); + + // Mark invalid value + bool bOverflow; + bool bMarkInvalid = ScDetectiveFunc(rDoc, 0).MarkInvalid(bOverflow); + CPPUNIT_ASSERT_EQUAL(true, bMarkInvalid); + + // There should be a circle object! + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), pPage->GetObjCount()); + + // The value of A1 change to Hello1. + rDoc.SetString(0, 0, 0, "Hello1"); + + // Check that the data is valid.(True if text length = 6) + const ScValidationData* pData = rDoc.GetValidationEntry(1); + bool bValidA1 = pData->IsDataValid(aCellA1, aPosA1); + // if valid, delete circle. + if (bValidA1) + ScDetectiveFunc(rDoc, 0).DeleteCirclesAt(aPosA1.Col(), aPosA1.Row()); + + // There should not be a circle object! + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(0), pPage->GetObjCount()); + + xDocSh->DoClose(); +} + +void ScFiltersTest2::testDrawCircleInMergeCells() +{ + ScDocShellRef xDocSh = loadDoc(u"testDrawCircleInMergeCells.", FORMAT_XLSX); + CPPUNIT_ASSERT_MESSAGE("Failed to load testDrawCircleInMergeCells.ods", xDocSh.is()); + + ScDocument& rDoc = xDocSh->GetDocument(); + + ScDrawLayer* pDrawLayer = rDoc.GetDrawLayer(); + SdrPage* pPage = pDrawLayer->GetPage(0); + CPPUNIT_ASSERT_MESSAGE("draw page for sheet 1 should exist.", pPage); + + // A1:B2 is merged. + ScRange aMergedRange(0, 0, 0); + rDoc.ExtendTotalMerge(aMergedRange); + CPPUNIT_ASSERT_EQUAL(ScRange(0, 0, 0, 1, 1, 0), aMergedRange); + + // Mark invalid value + bool bOverflow; + bool bMarkInvalid = ScDetectiveFunc(rDoc, 0).MarkInvalid(bOverflow); + CPPUNIT_ASSERT_EQUAL(true, bMarkInvalid); + + // There should be a circle object! + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), pPage->GetObjCount()); + + SdrObject* pObj = pPage->GetObj(0); + tools::Rectangle aRect(pObj->GetLogicRect()); + Point aStartCircle = aRect.TopLeft(); + Point aEndCircle = aRect.BottomRight(); + + tools::Rectangle aCellRect = rDoc.GetMMRect(0, 0, 1, 1, 0); + aCellRect.AdjustLeft(-250); + aCellRect.AdjustRight(250); + aCellRect.AdjustTop(-70); + aCellRect.AdjustBottom(70); + Point aStartCell = aCellRect.TopLeft(); + Point aEndCell = aCellRect.BottomRight(); + + CPPUNIT_ASSERT_EQUAL(aStartCell.X(), aStartCircle.X()); + CPPUNIT_ASSERT_EQUAL(aEndCell.X(), aEndCircle.X()); + CPPUNIT_ASSERT_EQUAL(aStartCell.Y(), aStartCircle.Y()); + CPPUNIT_ASSERT_EQUAL(aEndCell.Y(), aEndCircle.Y()); + + // Change the height of the first row. (556 ~ 1cm) + rDoc.SetRowHeight(0, 0, 556); + ScDrawObjData* pData = ScDrawLayer::GetObjData(pObj); + pDrawLayer->RecalcPos(pObj, *pData, false, false); + + tools::Rectangle aRecalcRect(pObj->GetLogicRect()); + Point aStartRecalcCircle = aRecalcRect.TopLeft(); + Point aEndRecalcCircle = aRecalcRect.BottomRight(); + + tools::Rectangle aRecalcCellRect = rDoc.GetMMRect(0, 0, 1, 1, 0); + aRecalcCellRect.AdjustLeft(-250); + aRecalcCellRect.AdjustRight(250); + aRecalcCellRect.AdjustTop(-70); + aRecalcCellRect.AdjustBottom(70); + Point aStartRecalcCell = aRecalcCellRect.TopLeft(); + Point aEndRecalcCell1 = aRecalcCellRect.BottomRight(); + + CPPUNIT_ASSERT_EQUAL(aStartRecalcCell.X(), aStartRecalcCircle.X()); + CPPUNIT_ASSERT_EQUAL(aEndRecalcCell1.X(), aEndRecalcCircle.X()); + CPPUNIT_ASSERT_EQUAL(aStartRecalcCell.Y(), aStartRecalcCircle.Y()); + CPPUNIT_ASSERT_EQUAL(aEndRecalcCell1.Y(), aEndRecalcCircle.Y()); + + xDocSh->DoClose(); +} + +void ScFiltersTest2::testDeleteCirclesInRowAndCol() +{ + ScDocShellRef xDocSh = loadDoc(u"deleteCirclesInRowAndCol.", FORMAT_ODS); + CPPUNIT_ASSERT_MESSAGE("Failed to load deleteCirclesInRowAndCol.ods", xDocSh.is()); + + ScDocument& rDoc = xDocSh->GetDocument(); + + ScDrawLayer* pDrawLayer = rDoc.GetDrawLayer(); + SdrPage* pPage = pDrawLayer->GetPage(0); + CPPUNIT_ASSERT_MESSAGE("draw page for sheet 1 should exist.", pPage); + + // There should be 6 circle objects! + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(6), pPage->GetObjCount()); + + // Delete first row (1023 = MAXCOLS) + pDrawLayer->DeleteObjectsInArea(0, 0, 0, 1023, 0, true); + + // There should be 3 circle objects! + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(3), pPage->GetObjCount()); + + // Delete first col (1048575 = MAXROWS) + pDrawLayer->DeleteObjectsInArea(0, 0, 0, 0, 1048575, true); + + // There should not be a circle object! + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(0), pPage->GetObjCount()); + + xDocSh->DoClose(); +} + +void ScFiltersTest2::testTdf129940() +{ + // Test pure span elements inside text:ruby-base + ScDocShellRef xDocSh = loadDoc(u"tdf129940.", FORMAT_ODS); + CPPUNIT_ASSERT_MESSAGE("Failed to load tdf129940.ods", xDocSh.is()); + ScDocument& rDoc = xDocSh->GetDocument(); + // Pure text within text:ruby-base + OUString aStr = rDoc.GetString(ScAddress(0, 0, 0)); + CPPUNIT_ASSERT_EQUAL(OUString(u"小笠原"), aStr); + aStr = rDoc.GetString(ScAddress(1, 0, 0)); + CPPUNIT_ASSERT_EQUAL(OUString(u"徳彦"), aStr); + + // Multiple text:span within text:ruby-base + aStr = rDoc.GetString(ScAddress(2, 0, 0)); + CPPUNIT_ASSERT_EQUAL(OUString(u"注音符號"), aStr); + + xDocSh->DoClose(); +} + +void ScFiltersTest2::testTdf139763ShapeAnchor() +{ + ScDocShellRef xDocSh = loadDoc(u"tdf139763ShapeAnchor.", FORMAT_XLSX); + CPPUNIT_ASSERT_MESSAGE("Failed to load cell-anchored-shapes.xlsx", xDocSh.is()); + + // There are two objects on the first sheet, anchored to page by element xdr:absoluteAnchor + // and anchored to cell by element xdr:oneCellAnchor. Error was, that they were imported as + // "anchor to cell (resize with cell". + ScDocument& rDoc = xDocSh->GetDocument(); + + CPPUNIT_ASSERT_MESSAGE("There should be at least one sheet.", rDoc.GetTableCount() > 0); + + ScDrawLayer* pDrawLayer = rDoc.GetDrawLayer(); + SdrPage* pPage = pDrawLayer->GetPage(0); + CPPUNIT_ASSERT_MESSAGE("draw page for sheet 1 should exist.", pPage); + // There should be 2 shapes + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), pPage->GetObjCount()); + + SdrObject* pObj = pPage->GetObj(0); + CPPUNIT_ASSERT_MESSAGE("Failed to get page anchored object.", pObj); + CPPUNIT_ASSERT_MESSAGE("Shape must be page anchored", !ScDrawLayer::IsCellAnchored(*pObj)); + + pObj = pPage->GetObj(1); + CPPUNIT_ASSERT_MESSAGE("Failed to get cell anchored object.", pObj); + CPPUNIT_ASSERT_MESSAGE("Shape must be anchored to cell.", ScDrawLayer::IsCellAnchored(*pObj)); + CPPUNIT_ASSERT_MESSAGE("Shape must not resize with cell.", + !ScDrawLayer::IsResizeWithCell(*pObj)); + + xDocSh->DoClose(); +} + +void ScFiltersTest2::testAutofilterNamedRangesXLSX() +{ + ScDocShellRef xDocSh = loadDoc(u"autofilternamedrange.", FORMAT_XLSX); + CPPUNIT_ASSERT_MESSAGE("Failed to load autofilternamedrange.xlsx", xDocSh.is()); + + ScDocument& rDoc = xDocSh->GetDocument(); + const ScDBData* pDBData = rDoc.GetDBCollection()->GetDBNearCursor(0, 0, 0); + CPPUNIT_ASSERT(pDBData); + ScRange aRange; + pDBData->GetArea(aRange); + CPPUNIT_ASSERT_EQUAL(ScRange(0, 0, 0, 0, 3, 0), aRange); + OUString aPosStr; + bool bSheetLocal = false; + // test there is no '_xlnm._FilterDatabase' named range on the filter area + const ScRangeData* pRData = rDoc.GetRangeAtBlock(aRange, aPosStr, &bSheetLocal); + CPPUNIT_ASSERT(!pRData); + CPPUNIT_ASSERT_EQUAL(OUString(), aPosStr); + + xDocSh->DoClose(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScFiltersTest2); + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/CppunitTest_sc_subsequent_export_test.mk b/sc/subsequent_setup.mk index 9d5fb86cb56e..355d0ca7435a 100644 --- a/sc/CppunitTest_sc_subsequent_export_test.mk +++ b/sc/subsequent_setup.mk @@ -7,21 +7,24 @@ # file, You can obtain one at http://mozilla.org/MPL/2.0/. # -$(eval $(call gb_CppunitTest_CppunitTest,sc_subsequent_export_test)) +# template for subsequent tests +define sc_subsequent_test -$(eval $(call gb_CppunitTest_use_common_precompiled_header,sc_subsequent_export_test)) +$(eval $(call gb_CppunitTest_CppunitTest,sc_subsequent_$(1))) -$(eval $(call gb_CppunitTest_add_exception_objects,sc_subsequent_export_test, \ - sc/qa/unit/subsequent_export-test \ +$(eval $(call gb_CppunitTest_use_common_precompiled_header,sc_subsequent_$(1))) + +$(eval $(call gb_CppunitTest_add_exception_objects,sc_subsequent_$(1), \ + sc/qa/unit/subsequent_$(1) \ )) -$(eval $(call gb_CppunitTest_use_externals,sc_subsequent_export_test, \ +$(eval $(call gb_CppunitTest_use_externals,sc_subsequent_$(1), \ boost_headers \ mdds_headers \ libxml2 \ )) -$(eval $(call gb_CppunitTest_use_libraries,sc_subsequent_export_test, \ +$(eval $(call gb_CppunitTest_use_libraries,sc_subsequent_$(1), \ basegfx \ comphelper \ cppu \ @@ -54,22 +57,24 @@ $(eval $(call gb_CppunitTest_use_libraries,sc_subsequent_export_test, \ xo \ )) -$(eval $(call gb_CppunitTest_set_include,sc_subsequent_export_test,\ +$(eval $(call gb_CppunitTest_set_include,sc_subsequent_$(1),\ -I$(SRCDIR)/sc/source/ui/inc \ -I$(SRCDIR)/sc/inc \ $$(INCLUDE) \ )) -$(eval $(call gb_CppunitTest_use_api,sc_subsequent_export_test,\ +$(eval $(call gb_CppunitTest_use_api,sc_subsequent_$(1),\ udkapi \ offapi \ oovbaapi \ )) -$(eval $(call gb_CppunitTest_use_ure,sc_subsequent_export_test)) -$(eval $(call gb_CppunitTest_use_vcl,sc_subsequent_export_test)) +$(eval $(call gb_CppunitTest_use_ure,sc_subsequent_$(1))) +$(eval $(call gb_CppunitTest_use_vcl,sc_subsequent_$(1))) -$(eval $(call gb_CppunitTest_use_components,sc_subsequent_export_test,\ +$(eval $(call gb_CppunitTest_use_components,sc_subsequent_$(1),\ + basic/util/sb \ + basctl/util/basctl \ chart2/source/chartcore \ chart2/source/controller/chartcontroller \ comphelper/util/comphelp \ @@ -93,6 +98,7 @@ $(eval $(call gb_CppunitTest_use_components,sc_subsequent_export_test,\ scaddins/source/datefunc/date \ sc/util/sc \ sc/util/scfilt \ + sc/util/vbaobj \ sfx2/util/sfx \ sot/util/sot \ svl/util/svl \ @@ -112,20 +118,22 @@ $(eval $(call gb_CppunitTest_use_components,sc_subsequent_export_test,\ emfio/emfio \ )) -$(eval $(call gb_CppunitTest_use_components,sc_subsequent_export_test,\ +$(eval $(call gb_CppunitTest_use_components,sc_subsequent_$(1),\ xmlsecurity/util/xsec_xmlsec \ )) -$(eval $(call gb_CppunitTest_use_custom_headers,sc_subsequent_export_test,\ +$(eval $(call gb_CppunitTest_use_custom_headers,sc_subsequent_$(1),\ officecfg/registry \ )) -$(eval $(call gb_CppunitTest_use_configuration,sc_subsequent_export_test)) +$(eval $(call gb_CppunitTest_use_configuration,sc_subsequent_$(1))) -$(eval $(call gb_CppunitTest_use_packages,sc_subsequent_export_test, \ +$(eval $(call gb_CppunitTest_use_packages,sc_subsequent_$(1), \ oox_generated \ )) -$(eval $(call gb_CppunitTest_use_more_fonts,sc_subsequent_export_test)) +$(eval $(call gb_CppunitTest_use_more_fonts,sc_subsequent_$(1))) + +endef # vim: set noet sw=4 ts=4: |