From 78eeb30220b478a5040c60d2c8eee8b1f3d1c7dd Mon Sep 17 00:00:00 2001 From: Xisco Fauli Date: Tue, 28 Feb 2023 15:48:33 +0100 Subject: [PATCH] CppunitTest_sc_subsequent_filters_test2: split into two it already has 115 tests Change-Id: I043d000b8782bae66bdd958c0273f8c5ea622a60 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/148009 Tested-by: Jenkins Reviewed-by: Xisco Fauli --- sc/CppunitTest_sc_subsequent_filters_test3.mk | 12 + sc/Module_sc.mk | 1 + sc/qa/unit/subsequent_filters_test2.cxx | 1273 ---------------- sc/qa/unit/subsequent_filters_test3.cxx | 1319 +++++++++++++++++ 4 files changed, 1332 insertions(+), 1273 deletions(-) create mode 100644 sc/CppunitTest_sc_subsequent_filters_test3.mk create mode 100644 sc/qa/unit/subsequent_filters_test3.cxx diff --git a/sc/CppunitTest_sc_subsequent_filters_test3.mk b/sc/CppunitTest_sc_subsequent_filters_test3.mk new file mode 100644 index 000000000000..edcccf56a71f --- /dev/null +++ b/sc/CppunitTest_sc_subsequent_filters_test3.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_test3)) + +# vim: set noet sw=4 ts=4: diff --git a/sc/Module_sc.mk b/sc/Module_sc.mk index 8e0644f73940..ffbe0dafb6c4 100644 --- a/sc/Module_sc.mk +++ b/sc/Module_sc.mk @@ -84,6 +84,7 @@ $(eval $(call gb_Module_add_slowcheck_targets,sc, \ CppunitTest_sc_sparkline_test \ CppunitTest_sc_subsequent_filters_test \ CppunitTest_sc_subsequent_filters_test2 \ + CppunitTest_sc_subsequent_filters_test3 \ CppunitTest_sc_subsequent_export_test \ CppunitTest_sc_subsequent_export_test2 \ CppunitTest_sc_uicalc \ diff --git a/sc/qa/unit/subsequent_filters_test2.cxx b/sc/qa/unit/subsequent_filters_test2.cxx index d63298852b6a..cd5f073f46c4 100644 --- a/sc/qa/unit/subsequent_filters_test2.cxx +++ b/sc/qa/unit/subsequent_filters_test2.cxx @@ -12,13 +12,11 @@ #include #include -#include #include #include #include #include -#include #include #include #include @@ -33,34 +31,22 @@ #include #include #include -#include #include #include -#include #include #include -#include #include #include #include #include -#include -#include -#include -#include #include -#include #include #include -#include -#include #include #include -#include #include "helper/qahelper.hxx" -#include using namespace ::com::sun::star; using namespace ::com::sun::star::uno; @@ -1579,1265 +1565,6 @@ CPPUNIT_TEST_FIXTURE(ScFiltersTest2, testBorderDirectionsXLSXML) } } -CPPUNIT_TEST_FIXTURE(ScFiltersTest2, testBorderColorsXLSXML) -{ - createScDoc("xml/border-colors.xml"); - ScDocument* pDoc = getScDoc(); - - // B3 - red - const ScPatternAttr* pPat = pDoc->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 = pDoc->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 = pDoc->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 = pDoc->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 -} - -CPPUNIT_TEST_FIXTURE(ScFiltersTest2, testHiddenRowsColumnsXLSXML) -{ - createScDoc("xml/hidden-rows-columns.xml"); - ScDocument* pDoc = getScDoc(); - - struct Check - { - SCCOLROW nPos1; - SCCOLROW nPos2; - bool bVisible; - }; - - std::vector aRowChecks = { - { 0, 0, true }, - { 1, 2, false }, - { 3, 3, true }, - { 4, 4, false }, - { 5, 7, true }, - { 8, 8, false }, - { 9, pDoc->MaxRow(), true }, - }; - - for (const Check& c : aRowChecks) - { - SCROW nRow1 = -1, nRow2 = -1; - bool bVisible = !pDoc->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 aColChecks = { - { 0, 1, true }, - { 2, 5, false }, - { 6, 9, true }, - { 10, 10, false }, - { 11, pDoc->MaxCol(), true }, - }; - - for (const Check& c : aColChecks) - { - SCCOL nCol1 = -1, nCol2 = -1; - bool bVisible = !pDoc->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)); - } -} - -CPPUNIT_TEST_FIXTURE(ScFiltersTest2, testColumnWidthRowHeightXLSXML) -{ - createScDoc("xml/column-width-row-height.xml"); - ScDocument* pDoc = getScDoc(); - - struct RowHeight - { - SCROW nRow1; - SCROW nRow2; - sal_uInt16 nHeight; // in points (1 point == 20 twips) - }; - - std::vector 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 = pDoc->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 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 = pDoc->GetColWidth(i, 0); - CPPUNIT_ASSERT_EQUAL(sal_uInt16(cw.nWidth * 20), nWidth); - } - } -} - -CPPUNIT_TEST_FIXTURE(ScFiltersTest2, testCharacterSetXLSXML) -{ - createScDoc("xml/character-set.xml"); - ScDocument* pDoc = getScDoc(); - - CPPUNIT_ASSERT_EQUAL(SCTAB(1), pDoc->GetTableCount()); - - OUString aName; - pDoc->GetName(0, aName); - - // Check the sheet name. The values are all Cyrillic letters. - std::vector aBuf = { 0x041b, 0x0438, 0x0441, 0x0442, 0x0031 }; - OUString aExpected(aBuf.data(), aBuf.size()); - CPPUNIT_ASSERT_EQUAL(aExpected, aName); - - // Check the value of I4 - OUString aVal = pDoc->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 = pDoc->GetString(ScAddress(9, 2, 0)); - aBuf = { 0x041e, 0x0441, 0x0442, 0x0430, 0x0442, 0x043e, 0x043a }; - aExpected = OUString(aBuf.data(), aBuf.size()); - CPPUNIT_ASSERT_EQUAL(aExpected, aVal); -} - -CPPUNIT_TEST_FIXTURE(ScFiltersTest2, testWrapAndShrinkXLSXML) -{ - createScDoc("xml/wrap-and-shrink.xml"); - ScDocument* pDoc = getScDoc(); - - CPPUNIT_ASSERT_EQUAL(SCTAB(1), pDoc->GetTableCount()); - - struct Check - { - SCCOL nCol; - SCROW nRow; - - bool bWrapText; - bool bShrinkToFit; - }; - - constexpr Check aChecks[] = { - { 1, 0, false, false }, - { 1, 1, true, false }, - { 1, 2, false, true }, - }; - - for (const auto& rC : aChecks) - { - const ScLineBreakCell* pLB = pDoc->GetAttr(rC.nCol, rC.nRow, 0, ATTR_LINEBREAK); - CPPUNIT_ASSERT_EQUAL(pLB->GetValue(), rC.bWrapText); - - const ScShrinkToFitCell* pSTF = pDoc->GetAttr(rC.nCol, rC.nRow, 0, ATTR_SHRINKTOFIT); - CPPUNIT_ASSERT_EQUAL(pSTF->GetValue(), rC.bShrinkToFit); - } -} - -CPPUNIT_TEST_FIXTURE(ScFiltersTest2, testCondFormatXLSB) -{ - createScDoc("xlsb/cond_format.xlsb"); - - ScDocument* pDoc = getScDoc(); - ScConditionalFormatList* pList = pDoc->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()); -} - -CPPUNIT_TEST_FIXTURE(ScFiltersTest2, testPageScalingXLSX) -{ - createScDoc("xlsx/page_scale.xlsx"); - ScDocument* pDoc = getScDoc(); - - OUString aStyleName = pDoc->GetPageStyle(0); - ScStyleSheetPool* pStylePool = pDoc->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); -} - -CPPUNIT_TEST_FIXTURE(ScFiltersTest2, testActiveXCheckboxXLSX) -{ - createScDoc("xlsx/activex_checkbox.xlsx"); - uno::Reference xDoc(mxComponent, UNO_QUERY_THROW); - uno::Reference xIA(xDoc->getSheets(), UNO_QUERY_THROW); - uno::Reference xDrawPageSupplier(xIA->getByIndex(0), - UNO_QUERY_THROW); - uno::Reference xIA_DrawPage(xDrawPageSupplier->getDrawPage(), - UNO_QUERY_THROW); - uno::Reference xControlShape(xIA_DrawPage->getByIndex(0), - UNO_QUERY_THROW); - - // Check control type - uno::Reference xPropertySet(xControlShape->getControl(), uno::UNO_QUERY); - uno::Reference 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) - Color nColor; - xPropertySet->getPropertyValue("BackgroundColor") >>= nColor; - CPPUNIT_ASSERT_EQUAL(Color(0x316AC5), nColor); - - // Check Text color (active border system color) - xPropertySet->getPropertyValue("TextColor") >>= nColor; - CPPUNIT_ASSERT_EQUAL(Color(0xD4D0C8), nColor); - - // Check state of the checkbox - sal_Int16 nState; - xPropertySet->getPropertyValue("State") >>= nState; - CPPUNIT_ASSERT_EQUAL(sal_Int16(1), nState); -} - -CPPUNIT_TEST_FIXTURE(ScFiltersTest2, testTdf60673) -{ - createScDoc("xlsx/tdf60673.xlsx"); - uno::Reference xDoc(mxComponent, UNO_QUERY_THROW); - uno::Reference xIA(xDoc->getSheets(), UNO_QUERY_THROW); - uno::Reference xDrawPageSupplier(xIA->getByIndex(0), - UNO_QUERY_THROW); - uno::Reference xIA_DrawPage(xDrawPageSupplier->getDrawPage(), - UNO_QUERY_THROW); - uno::Reference xControlShape(xIA_DrawPage->getByIndex(0), - UNO_QUERY_THROW); - - uno::Reference xPropertySet(xControlShape->getControl(), uno::UNO_QUERY); - - OUString sLabel; - xPropertySet->getPropertyValue("Label") >>= sLabel; - - // Without the fix in place, this test would have failed with - // - Expected: PL: ĄŚŻŹĆŃŁÓĘ - // - Actual : PL: - CPPUNIT_ASSERT_EQUAL(OUString(u"PL: ĄŚŻŹĆŃŁÓĘ"), sLabel); -} - -CPPUNIT_TEST_FIXTURE(ScFiltersTest2, testtdf120301_xmlSpaceParsingXLSX) -{ - createScDoc("xlsx/tdf120301_xmlSpaceParsing.xlsx"); - uno::Reference xDoc(mxComponent, UNO_QUERY_THROW); - uno::Reference xIA(xDoc->getSheets(), UNO_QUERY_THROW); - uno::Reference xDrawPageSupplier(xIA->getByIndex(0), - UNO_QUERY_THROW); - uno::Reference xIA_DrawPage(xDrawPageSupplier->getDrawPage(), - UNO_QUERY_THROW); - - uno::Reference xControlShape(xIA_DrawPage->getByIndex(0), - UNO_QUERY_THROW); - uno::Reference XPropSet(xControlShape->getControl(), uno::UNO_QUERY_THROW); - OUString sCaption; - XPropSet->getPropertyValue("Label") >>= sCaption; - CPPUNIT_ASSERT_EQUAL(OUString("Check Box 1"), sCaption); -} - -namespace -{ -struct PaintListener : public SfxListener -{ - bool mbCalled = false; - virtual void Notify(SfxBroadcaster& /*rBC*/, const SfxHint& rHint) override - { - const ScPaintHint* pPaintHint = dynamic_cast(&rHint); - if (pPaintHint) - { - if (pPaintHint->GetStartCol() <= 0 && pPaintHint->GetEndCol() >= 0 - && pPaintHint->GetStartRow() <= 9 && pPaintHint->GetEndRow() >= 9) - { - mbCalled = true; - } - } - } -}; -} - -CPPUNIT_TEST_FIXTURE(ScFiltersTest2, testCondFormatFormulaListenerXLSX) -{ - createScDoc("xlsx/cond_format_formula_listener.xlsx"); - ScDocShell* pDocSh = getScDocShell(); - PaintListener aListener; - aListener.StartListening(*pDocSh); - ScDocument* pDoc = getScDoc(); - ScConditionalFormatList* pList = pDoc->GetCondFormList(0); - CPPUNIT_ASSERT(pList); - - CPPUNIT_ASSERT_EQUAL(size_t(1), pList->size()); - ScConditionalFormat* pFormat = pList->begin()->get(); - CPPUNIT_ASSERT(pFormat); - pDoc->SetDocVisible(true); - pDoc->SetValue(0, 0, 0, 2.0); - - CPPUNIT_ASSERT(aListener.mbCalled); -} - -CPPUNIT_TEST_FIXTURE(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(); - }); - - createScDoc("xlsx/tdf137091.xlsx"); - ScDocument* pDoc = getScDoc(); - - // Without the fix in place, this test would have failed with - // - Expected: 28/4 - // - Actual : Err:507 - CPPUNIT_ASSERT_EQUAL(OUString("28/4"), pDoc->GetString(ScAddress(2, 1, 0))); -} - -CPPUNIT_TEST_FIXTURE(ScFiltersTest2, testTdf141495) -{ - // 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(); - }); - - createScDoc("xlsx/tdf141495.xlsx"); - ScDocument* pDoc = getScDoc(); - - ScDocShell* pDocSh = getScDocShell(); - pDocSh->DoHardRecalc(); - - // Without the fix in place, this test would have failed with - // - Expected: 44926 - // - Actual : #ADDIN? - CPPUNIT_ASSERT_EQUAL(OUString("44926"), pDoc->GetString(ScAddress(11, 6, 0))); -} - -CPPUNIT_TEST_FIXTURE(ScFiltersTest2, testTdf70455) -{ - createScDoc("xlsx/tdf70455.xlsx"); - ScDocument* pDoc = getScDoc(); - - // Without the fix in place, this test would have failed with - // - Expected: €780.00 - // - Actual : Err:509 - CPPUNIT_ASSERT_EQUAL(OUString(u"€780.00"), pDoc->GetString(ScAddress(7, 7, 0))); -} - -CPPUNIT_TEST_FIXTURE(ScFiltersTest2, testTdf62268) -{ - createScDoc("ods/tdf62268.ods"); - ScDocument* pDoc = getScDoc(); - int nHeight; - - SCTAB nTab = 0; - nHeight = pDoc->GetRowHeight(0, nTab, false); - CPPUNIT_ASSERT_LESSEQUAL(3, abs(256 - nHeight)); - nHeight = pDoc->GetRowHeight(1, nTab, false); - CPPUNIT_ASSERT_LESSEQUAL(19, abs(1905 - nHeight)); -} - -CPPUNIT_TEST_FIXTURE(ScFiltersTest2, testTdf137453) -{ - createScDoc("ods/tdf137453.ods"); - - ScDocument* pDoc = getScDoc(); - - // Without the fix in place, this test would have failed with - // - Expected: 3333333333/100 - // - Actual : -961633963/100 - CPPUNIT_ASSERT_EQUAL(OUString("3333333333/100"), pDoc->GetString(ScAddress(0, 0, 0))); -} - -CPPUNIT_TEST_FIXTURE(ScFiltersTest2, testTdf112780) -{ - createScDoc("ods/tdf112780.ods"); - - ScDocument* pDoc = getScDoc(); - - // Without the fix in place, this test would have failed with - // - Expected: - // - Actual : #VALUE! - CPPUNIT_ASSERT_EQUAL(OUString(""), pDoc->GetString(ScAddress(3, 5, 0))); - - OUString aFormula = pDoc->GetFormula(3, 5, 0); - CPPUNIT_ASSERT_EQUAL(OUString("=G6+J6+M6"), aFormula); -} - -CPPUNIT_TEST_FIXTURE(ScFiltersTest2, testTdf72470) -{ - // Without the fix in place, this test would have hung - - createScDoc("xls/tdf72470.xls"); - - ScDocument* pDoc = getScDoc(); - - CPPUNIT_ASSERT_EQUAL(OUString("name"), pDoc->GetString(ScAddress(0, 0, 0))); - CPPUNIT_ASSERT_EQUAL(OUString(u"أسمي walid"), pDoc->GetString(ScAddress(0, 1, 0))); -} - -CPPUNIT_TEST_FIXTURE(ScFiltersTest2, testTdf35636) -{ - createScDoc("ods/tdf35636.ods"); - - ScDocument* pDoc = getScDoc(); - - // Without the fix in place, SUMIF would have returned 0.0 - // with empty cells in the criteria - CPPUNIT_ASSERT_EQUAL(50.0, pDoc->GetValue(ScAddress(1, 4, 0))); -} - -CPPUNIT_TEST_FIXTURE(ScFiltersTest2, testTdf98481) -{ - createScDoc("xlsx/tdf98481.xlsx"); - - ScDocument* pDoc = getScDoc(); - - // Without the fix in place, this test would have failed with - // - Expected: 4 - // - Actual : 0 - CPPUNIT_ASSERT_EQUAL(4.0, pDoc->GetValue(ScAddress(4, 1, 0))); - CPPUNIT_ASSERT_EQUAL(0.0, pDoc->GetValue(ScAddress(4, 2, 0))); - CPPUNIT_ASSERT_EQUAL(3.0, pDoc->GetValue(ScAddress(4, 3, 0))); - CPPUNIT_ASSERT_EQUAL(4.0, pDoc->GetValue(ScAddress(1, 4, 0))); - CPPUNIT_ASSERT_EQUAL(0.0, pDoc->GetValue(ScAddress(2, 4, 0))); - CPPUNIT_ASSERT_EQUAL(3.0, pDoc->GetValue(ScAddress(3, 4, 0))); -} - -CPPUNIT_TEST_FIXTURE(ScFiltersTest2, testTdf115022) -{ - createScDoc("xlsx/tdf115022.xlsx"); - - ScDocument* pDoc = getScDoc(); - - CPPUNIT_ASSERT_EQUAL(6.0, pDoc->GetValue(ScAddress(1, 8, 0))); - - ScDocShell* pDocSh = getScDocShell(); - pDocSh->DoHardRecalc(); - - // Without the fix in place, this test would have failed with - // - Expected: 6 - // - Actual : 21 - CPPUNIT_ASSERT_EQUAL(6.0, pDoc->GetValue(ScAddress(1, 8, 0))); -} - -CPPUNIT_TEST_FIXTURE(ScFiltersTest2, testVBAMacroFunctionODS) -{ - createScDoc("ods/vba_macro_functions.ods"); - ScDocument* pDoc = getScDoc(); - - OUString aFunction = pDoc->GetFormula(2, 0, 0); - std::cout << aFunction << std::endl; - CPPUNIT_ASSERT_DOUBLES_EQUAL(10.0, pDoc->GetValue(2, 0, 0), 1e-6); -} - -CPPUNIT_TEST_FIXTURE(ScFiltersTest2, testAutoheight2Rows) -{ - createScDoc("ods/autoheight2rows.ods"); - ScDocument* pDoc = getScDoc(); - - SCTAB nTab = 0; - int nHeight1 = pDoc->GetRowHeight(0, nTab, false); - int nHeight2 = pDoc->GetRowHeight(1, nTab, false); - int nHeight4 = pDoc->GetRowHeight(3, nTab, false); - int nHeight5 = pDoc->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); -} - -CPPUNIT_TEST_FIXTURE(ScFiltersTest2, testXLSDefColWidth) -{ - // XLS has only 256 columns; but on import, we need to set default width to all above that limit - createScDoc("xls/chartx.xls"); - ScDocument* pDoc = getScDoc(); - - int nWidth = pDoc->GetColWidth(pDoc->MaxCol(), 0, false); - // This was 1280 - CPPUNIT_ASSERT_EQUAL(1005, nWidth); -} - -CPPUNIT_TEST_FIXTURE(ScFiltersTest2, testTdf148423) -{ - createScDoc("csv/tdf148423.csv"); - ScDocument* pDoc = getScDoc(); - - int nWidth = pDoc->GetColWidth(0, 0, false); - - // Without the fix in place, this test would have failed with - // - Expected: 32880 - // - Actual : 112 - CPPUNIT_ASSERT_EQUAL(32880, nWidth); -} - -CPPUNIT_TEST_FIXTURE(ScFiltersTest2, testTdf152053) -{ - createScDoc("csv/tdf152053.csv"); - ScDocument* pDoc = getScDoc(); - - int nWidth = pDoc->GetColWidth(0, 0, false); - - // Without the fix in place, this test would have failed with - // - Expected: 1162 - // - Actual : 715 - // tolerance is for windows machines with non-default DPI - CPPUNIT_ASSERT_DOUBLES_EQUAL(1162, nWidth, 10); -} - -CPPUNIT_TEST_FIXTURE(ScFiltersTest2, testPreviewMissingObjLink) -{ - createScDoc("ods/keep-preview-missing-obj-link.ods"); - - ScDocument* pDoc = getScDoc(); - - // Retrieve the ole object - const SdrOle2Obj* pOleObj = getSingleOleObject(*pDoc, 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); -} - -CPPUNIT_TEST_FIXTURE(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. - createScDoc("xlsx/testShapeRotationImport.xlsx"); - uno::Reference xDoc(mxComponent, uno::UNO_QUERY_THROW); - uno::Reference 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> aExpectedValues{ - { 4400, { { "x", 6826 }, { "y", 36891 }, { "width", 8889 }, { "height", 1163 } } }, - { 4500, { { "x", 4485 }, { "y", 36397 }, { "width", 8889 }, { "height", 1164 } } }, - { 4600, { { "x", 1669 }, { "y", 36272 }, { "width", 8863 }, { "height", 1142 } } }, - { 13400, { { "x", 13752 }, { "y", 28403 }, { "width", 8863 }, { "height", 1194 } } }, - { 13500, { { "x", 10810 }, { "y", 27951 }, { "width", 8863 }, { "height", 1168 } } }, - { 13600, { { "x", 8442 }, { "y", 28334 }, { "width", 8889 }, { "height", 1163 } } }, - { 22400, { { "x", 14934 }, { "y", 12981 }, { "width", 8889 }, { "height", 1163 } } }, - { 22500, { { "x", 11754 }, { "y", 12837 }, { "width", 8889 }, { "height", 1163 } } }, - { 22600, { { "x", 8248 }, { "y", 12919 }, { "width", 8862 }, { "height", 1169 } } }, - { 31400, { { "x", 8089 }, { "y", 1160 }, { "width", 9815 }, { "height", 1171 } } }, - { 31500, { { "x", 4421 }, { "y", 1274 }, { "width", 10238 }, { "height", 1171 } } }, - { 31600, { { "x", 1963 }, { "y", 1882 }, { "width", 10297 }, { "height", 1163 } } }, - }; - - for (sal_Int32 ind = 0; ind < 12; ++ind) - { - uno::Reference xShape(xPage->getByIndex(ind), uno::UNO_QUERY_THROW); - - uno::Reference xShapeProperties(xShape, uno::UNO_QUERY); - uno::Any nRotProp = xShapeProperties->getPropertyValue("RotateAngle"); - sal_Int32 nRot = nRotProp.get(); - const OString sNote = "RotateAngle = " + OString::number(nRot); - - awt::Point aPosition = xShape->getPosition(); - awt::Size aSize = xShape->getSize(); - - CPPUNIT_ASSERT_MESSAGE(sNote.getStr(), aExpectedValues.find(nRot) != aExpectedValues.end()); - CPPUNIT_ASSERT_EQUAL_MESSAGE(sNote.getStr(), aExpectedValues[nRot]["x"], aPosition.X); - CPPUNIT_ASSERT_EQUAL_MESSAGE(sNote.getStr(), aExpectedValues[nRot]["y"], aPosition.Y); - CPPUNIT_ASSERT_EQUAL_MESSAGE(sNote.getStr(), aExpectedValues[nRot]["width"], aSize.Width); - CPPUNIT_ASSERT_EQUAL_MESSAGE(sNote.getStr(), aExpectedValues[nRot]["height"], aSize.Height); - } -} - -CPPUNIT_TEST_FIXTURE(ScFiltersTest2, testShapeDisplacementOnRotationImport) -{ - // tdf#135918 shape is displaced on rotation if it is placed next to the sheets upper/left edges - createScDoc("xlsx/testShapeDisplacementOnRotationImport.xlsx"); - - uno::Reference xDoc(mxComponent, uno::UNO_QUERY_THROW); - uno::Reference xPage(xDoc->getDrawPages()->getByIndex(0), - uno::UNO_QUERY_THROW); - uno::Reference xShape(xPage->getByIndex(0), uno::UNO_QUERY_THROW); - - uno::Reference xShapeProperties(xShape, uno::UNO_QUERY_THROW); - uno::Any aRectProp = xShapeProperties->getPropertyValue("FrameRect"); - awt::Rectangle aRectangle = aRectProp.get(); - CPPUNIT_ASSERT_EQUAL(sal_Int32(0), aRectangle.X); - CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aRectangle.Y); -} - -CPPUNIT_TEST_FIXTURE(ScFiltersTest2, testTextBoxBodyUpright) -{ - // tdf#106197 We should import the "upright" attribute of txBody. - createScDoc("xlsx/tdf106197_import_upright.xlsx"); - - uno::Reference xDoc(mxComponent, uno::UNO_QUERY_THROW); - uno::Reference xPage(xDoc->getDrawPages()->getByIndex(0), - uno::UNO_QUERY_THROW); - uno::Reference xShape(xPage->getByIndex(0), uno::UNO_QUERY_THROW); - uno::Reference xShapeProperties(xShape, uno::UNO_QUERY_THROW); - - // Check that we imported "Upright". - bool isUpright = false; - if (xShapeProperties->getPropertySetInfo()->hasPropertyByName("InteropGrabBag")) - { - uno::Sequence aGrabBag; - xShapeProperties->getPropertyValue("InteropGrabBag") >>= aGrabBag; - for (auto& aProp : std::as_const(aGrabBag)) - { - if (aProp.Name == "Upright") - { - aProp.Value >>= isUpright; - break; - } - } - } - CPPUNIT_ASSERT_EQUAL(true, isUpright); - - // Check the TextPreRotateAngle has the compensation for the additional 90deg area rotation, - // which is added in Shape::createAndInsert to get the same rendering as in MS Office. - sal_Int32 nAngle; - uno::Any aGeom = xShapeProperties->getPropertyValue("CustomShapeGeometry"); - auto aGeomSeq = aGeom.get>(); - for (const auto& aProp : std::as_const(aGeomSeq)) - { - if (aProp.Name == "TextPreRotateAngle") - { - aProp.Value >>= nAngle; - break; - } - } - CPPUNIT_ASSERT_EQUAL(sal_Int32(90), nAngle); -} - -CPPUNIT_TEST_FIXTURE(ScFiltersTest2, testTextBoxBodyRotateAngle) -{ - createScDoc("xlsx/tdf141644.xlsx"); - - uno::Reference xDoc(mxComponent, uno::UNO_QUERY_THROW); - uno::Reference xPage(xDoc->getDrawPages()->getByIndex(0), - uno::UNO_QUERY_THROW); - uno::Reference xShape(xPage->getByIndex(0), uno::UNO_QUERY_THROW); - uno::Reference xShapeProperties(xShape, uno::UNO_QUERY_THROW); - - // Check the text direction. - sal_Int16 eWritingMode = text::WritingMode2::LR_TB; - if (xShapeProperties->getPropertySetInfo()->hasPropertyByName("WritingMode")) - xShapeProperties->getPropertyValue("WritingMode") >>= eWritingMode; - CPPUNIT_ASSERT_EQUAL(sal_Int16(text::WritingMode2::BT_LR), eWritingMode); -} - -CPPUNIT_TEST_FIXTURE(ScFiltersTest2, testTextLengthDataValidityXLSX) -{ - createScDoc("xlsx/textLengthDataValidity.xlsx"); - - ScDocument* pDoc = getScDoc(); - - const ScValidationData* pData = pDoc->GetValidationEntry(1); - - ScRefCellValue aCellA1; // A1 = 1234(numeric value) - ScAddress aValBaseAddrA1(0, 0, 0); - aCellA1.assign(*pDoc, aValBaseAddrA1); - bool bValidA1 = pData->IsDataValid(aCellA1, aValBaseAddrA1); - - ScRefCellValue aCellA2; // A2 = 1234(numeric value format as text) - ScAddress aValBaseAddrA2(0, 1, 0); - aCellA2.assign(*pDoc, aValBaseAddrA2); - bool bValidA2 = pData->IsDataValid(aCellA2, aValBaseAddrA2); - - ScRefCellValue aCellA3; // A3 = 1234.00(numeric value) - ScAddress aValBaseAddrA3(0, 2, 0); - aCellA3.assign(*pDoc, aValBaseAddrA3); - bool bValidA3 = pData->IsDataValid(aCellA3, aValBaseAddrA3); - - ScRefCellValue aCellA4; // A4 = 12.3(numeric value) - ScAddress aValBaseAddrA4(0, 3, 0); - aCellA4.assign(*pDoc, 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); -} - -CPPUNIT_TEST_FIXTURE(ScFiltersTest2, testDeleteCircles) -{ - createScDoc("xlsx/testDeleteCircles.xlsx"); - - ScDocument* pDoc = getScDoc(); - - ScDrawLayer* pDrawLayer = pDoc->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(*pDoc, aPosA1); - - // Mark invalid value - bool bOverflow; - bool bMarkInvalid = ScDetectiveFunc(*pDoc, 0).MarkInvalid(bOverflow); - CPPUNIT_ASSERT_EQUAL(true, bMarkInvalid); - - // There should be a circle object! - CPPUNIT_ASSERT_EQUAL(static_cast(1), pPage->GetObjCount()); - - // The value of A1 change to Hello1. - pDoc->SetString(0, 0, 0, "Hello1"); - - // Check that the data is valid.(True if text length = 6) - const ScValidationData* pData = pDoc->GetValidationEntry(1); - bool bValidA1 = pData->IsDataValid(aCellA1, aPosA1); - // if valid, delete circle. - if (bValidA1) - ScDetectiveFunc(*pDoc, 0).DeleteCirclesAt(aPosA1.Col(), aPosA1.Row()); - - // There should not be a circle object! - CPPUNIT_ASSERT_EQUAL(static_cast(0), pPage->GetObjCount()); -} - -CPPUNIT_TEST_FIXTURE(ScFiltersTest2, testDrawCircleInMergeCells) -{ - createScDoc("xlsx/testDrawCircleInMergeCells.xlsx"); - - ScDocument* pDoc = getScDoc(); - - ScDrawLayer* pDrawLayer = pDoc->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); - pDoc->ExtendTotalMerge(aMergedRange); - CPPUNIT_ASSERT_EQUAL(ScRange(0, 0, 0, 1, 1, 0), aMergedRange); - - // Mark invalid value - bool bOverflow; - bool bMarkInvalid = ScDetectiveFunc(*pDoc, 0).MarkInvalid(bOverflow); - CPPUNIT_ASSERT_EQUAL(true, bMarkInvalid); - - // There should be a circle object! - CPPUNIT_ASSERT_EQUAL(static_cast(1), pPage->GetObjCount()); - - SdrObject* pObj = pPage->GetObj(0); - tools::Rectangle aRect(pObj->GetLogicRect()); - Point aStartCircle = aRect.TopLeft(); - Point aEndCircle = aRect.BottomRight(); - - tools::Rectangle aCellRect = pDoc->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) - pDoc->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 = pDoc->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()); -} - -CPPUNIT_TEST_FIXTURE(ScFiltersTest2, testDeleteCirclesInRowAndCol) -{ - createScDoc("ods/deleteCirclesInRowAndCol.ods"); - - ScDocument* pDoc = getScDoc(); - - ScDrawLayer* pDrawLayer = pDoc->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(6), pPage->GetObjCount()); - - // Delete first row. - pDrawLayer->DeleteObjectsInArea(0, 0, 0, pDoc->MaxCol(), 0, true); - - // There should be 3 circle objects! - CPPUNIT_ASSERT_EQUAL(static_cast(3), pPage->GetObjCount()); - - // Delete first col. - pDrawLayer->DeleteObjectsInArea(0, 0, 0, 0, pDoc->MaxRow(), true); - - // There should not be a circle object! - CPPUNIT_ASSERT_EQUAL(static_cast(0), pPage->GetObjCount()); -} - -CPPUNIT_TEST_FIXTURE(ScFiltersTest2, testTdf129940) -{ - // Test pure span elements inside text:ruby-base - createScDoc("ods/tdf129940.ods"); - ScDocument* pDoc = getScDoc(); - // Pure text within text:ruby-base - OUString aStr = pDoc->GetString(ScAddress(0, 0, 0)); - CPPUNIT_ASSERT_EQUAL(OUString(u"小笠原"), aStr); - aStr = pDoc->GetString(ScAddress(1, 0, 0)); - CPPUNIT_ASSERT_EQUAL(OUString(u"徳彦"), aStr); - - // Multiple text:span within text:ruby-base - aStr = pDoc->GetString(ScAddress(2, 0, 0)); - CPPUNIT_ASSERT_EQUAL(OUString(u"注音符號"), aStr); -} - -CPPUNIT_TEST_FIXTURE(ScFiltersTest2, testTdf119190) -{ - createScDoc("xlsx/tdf119190.xlsx"); - ScDocument* pDoc = getScDoc(); - - // Without the fix in place, this test would have failed here - CPPUNIT_ASSERT(pDoc->HasNote(ScAddress(2, 0, 0))); - - ScPostIt* pNote = pDoc->GetNote(ScAddress(2, 0, 0)); - CPPUNIT_ASSERT(pNote); - CPPUNIT_ASSERT_EQUAL(true, pNote->IsCaptionShown()); -} - -CPPUNIT_TEST_FIXTURE(ScFiltersTest2, testTdf139612) -{ - createScDoc("ods/tdf139612.ods"); - ScDocument* pDoc = getScDoc(); - - ScDocShell* pDocSh = getScDocShell(); - pDocSh->DoHardRecalc(); - - // Without the fix in place, this test would have failed with - // - Expected: 1 - // - Actual : 0 - CPPUNIT_ASSERT_EQUAL(1.0, pDoc->GetValue(ScAddress(1, 15, 0))); -} - -CPPUNIT_TEST_FIXTURE(ScFiltersTest2, testTdf144740) -{ - createScDoc("ods/tdf144740.ods"); - ScDocument* pDoc = getScDoc(); - - // Without the fix in place, this test would have failed with - // - Expected: 1 - // - Actual : 2 - CPPUNIT_ASSERT_EQUAL(1.0, pDoc->GetValue(ScAddress(1, 0, 0))); -} - -CPPUNIT_TEST_FIXTURE(ScFiltersTest2, testTdf146722) -{ - createScDoc("ods/tdf146722.ods"); - ScDocument* pDoc = getScDoc(); - - // Without the fix in place, this test would have failed with - // - Expected: 3 - // - Actual : 0 - CPPUNIT_ASSERT_EQUAL(3.0, pDoc->GetValue(ScAddress(1, 2, 0))); -} - -CPPUNIT_TEST_FIXTURE(ScFiltersTest2, testTdf147014) -{ - createScDoc("xlsx/tdf147014.xlsx"); - uno::Reference xDoc(mxComponent, uno::UNO_QUERY_THROW); - uno::Reference xIA(xDoc->getSheets(), uno::UNO_QUERY_THROW); - uno::Reference xDrawPageSupplier(xIA->getByIndex(0), - uno::UNO_QUERY_THROW); - xIA.set(xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY_THROW); - // The sheet has a single shape, without the fix it was not imported, except in 32-bit builds - CPPUNIT_ASSERT_EQUAL_MESSAGE("Shape not imported", static_cast(1), xIA->getCount()); -} - -CPPUNIT_TEST_FIXTURE(ScFiltersTest2, testTdf139763ShapeAnchor) -{ - createScDoc("xlsx/tdf139763ShapeAnchor.xlsx"); - - // 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* pDoc = getScDoc(); - - CPPUNIT_ASSERT_MESSAGE("There should be at least one sheet.", pDoc->GetTableCount() > 0); - - ScDrawLayer* pDrawLayer = pDoc->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(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)); -} - -CPPUNIT_TEST_FIXTURE(ScFiltersTest2, testAutofilterNamedRangesXLSX) -{ - createScDoc("xlsx/autofilternamedrange.xlsx"); - - ScDocument* pDoc = getScDoc(); - const ScDBData* pDBData = pDoc->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 = pDoc->GetRangeAtBlock(aRange, aPosStr, &bSheetLocal); - CPPUNIT_ASSERT(!pRData); - CPPUNIT_ASSERT_EQUAL(OUString(), aPosStr); -} - -CPPUNIT_TEST_FIXTURE(ScFiltersTest2, testInvalidBareBiff5) -{ - createScDoc("xls/tdf144732.xls"); - ScDocument* pDoc = getScDoc(); - pDoc->CalcAll(); - - // Check that we import the contents from such file, as Excel does - CPPUNIT_ASSERT_EQUAL(SCTAB(1), pDoc->GetTableCount()); - - // Row 1 - ScAddress aPos(0, 0, 0); - CPPUNIT_ASSERT_EQUAL(CELLTYPE_VALUE, pDoc->GetCellType(aPos)); - CPPUNIT_ASSERT_EQUAL(1.0, pDoc->GetValue(aPos)); - aPos.IncCol(); - CPPUNIT_ASSERT_EQUAL(CELLTYPE_VALUE, pDoc->GetCellType(aPos)); - CPPUNIT_ASSERT_EQUAL(2.0, pDoc->GetValue(aPos)); - aPos.IncCol(); - CPPUNIT_ASSERT_EQUAL(CELLTYPE_VALUE, pDoc->GetCellType(aPos)); - CPPUNIT_ASSERT_EQUAL(3.0, pDoc->GetValue(aPos)); - aPos.IncCol(); - CPPUNIT_ASSERT_EQUAL(OUString(), pDoc->GetString(aPos)); - - // Row 2 - aPos = ScAddress(0, 1, 0); - CPPUNIT_ASSERT_EQUAL(CELLTYPE_FORMULA, pDoc->GetCellType(aPos)); - OUString sFormula = pDoc->GetFormula(aPos.Col(), aPos.Row(), aPos.Tab()); - CPPUNIT_ASSERT_EQUAL(OUString("=TRUE()"), sFormula); - CPPUNIT_ASSERT_EQUAL(1.0, pDoc->GetValue(aPos)); - aPos.IncCol(); - CPPUNIT_ASSERT_EQUAL(CELLTYPE_FORMULA, pDoc->GetCellType(aPos)); - sFormula = pDoc->GetFormula(aPos.Col(), aPos.Row(), aPos.Tab()); - CPPUNIT_ASSERT_EQUAL(OUString("=FALSE()"), sFormula); - CPPUNIT_ASSERT_EQUAL(0.0, pDoc->GetValue(aPos)); - aPos.IncCol(); - CPPUNIT_ASSERT_EQUAL(CELLTYPE_NONE, pDoc->GetCellType(aPos)); - CPPUNIT_ASSERT_EQUAL(OUString(), pDoc->GetString(aPos)); - aPos.IncCol(); - CPPUNIT_ASSERT_EQUAL(CELLTYPE_STRING, pDoc->GetCellType(aPos)); - CPPUNIT_ASSERT_EQUAL(OUString(u"sheetjs"), pDoc->GetString(aPos)); - - // Row 3 - aPos = ScAddress(0, 2, 0); - CPPUNIT_ASSERT_EQUAL(CELLTYPE_STRING, pDoc->GetCellType(aPos)); - CPPUNIT_ASSERT_EQUAL(OUString(u"foo bar"), pDoc->GetString(aPos)); - aPos.IncCol(); - CPPUNIT_ASSERT_EQUAL(CELLTYPE_STRING, pDoc->GetCellType(aPos)); - CPPUNIT_ASSERT_EQUAL(OUString(u"baz"), pDoc->GetString(aPos)); - aPos.IncCol(); - CPPUNIT_ASSERT_EQUAL(CELLTYPE_VALUE, pDoc->GetCellType(aPos)); - CPPUNIT_ASSERT_EQUAL(41689.4375, pDoc->GetValue(aPos)); - aPos.IncCol(); - CPPUNIT_ASSERT_EQUAL(CELLTYPE_STRING, pDoc->GetCellType(aPos)); - CPPUNIT_ASSERT_EQUAL(OUString(u"0.3"), pDoc->GetString(aPos)); - - // Row 4 - aPos = ScAddress(0, 3, 0); - CPPUNIT_ASSERT_EQUAL(CELLTYPE_STRING, pDoc->GetCellType(aPos)); - CPPUNIT_ASSERT_EQUAL(OUString(u"baz"), pDoc->GetString(aPos)); - aPos.IncCol(); - CPPUNIT_ASSERT_EQUAL(CELLTYPE_NONE, pDoc->GetCellType(aPos)); - CPPUNIT_ASSERT_EQUAL(OUString(), pDoc->GetString(aPos)); - aPos.IncCol(); - CPPUNIT_ASSERT_EQUAL(CELLTYPE_STRING, pDoc->GetCellType(aPos)); - CPPUNIT_ASSERT_EQUAL(OUString(u"_"), pDoc->GetString(aPos)); - aPos.IncCol(); - CPPUNIT_ASSERT_EQUAL(CELLTYPE_VALUE, pDoc->GetCellType(aPos)); - CPPUNIT_ASSERT_EQUAL(3.14159, pDoc->GetValue(aPos)); - - // Row 5 - aPos = ScAddress(0, 4, 0); - CPPUNIT_ASSERT_EQUAL(CELLTYPE_STRING, pDoc->GetCellType(aPos)); - CPPUNIT_ASSERT_EQUAL(OUString(u"hidden"), pDoc->GetString(aPos)); - aPos.IncCol(); - CPPUNIT_ASSERT_EQUAL(CELLTYPE_NONE, pDoc->GetCellType(aPos)); - CPPUNIT_ASSERT_EQUAL(OUString(), pDoc->GetString(aPos)); - aPos.IncCol(); - CPPUNIT_ASSERT_EQUAL(CELLTYPE_NONE, pDoc->GetCellType(aPos)); - CPPUNIT_ASSERT_EQUAL(OUString(), pDoc->GetString(aPos)); - aPos.IncCol(); - CPPUNIT_ASSERT_EQUAL(CELLTYPE_NONE, pDoc->GetCellType(aPos)); - CPPUNIT_ASSERT_EQUAL(OUString(), pDoc->GetString(aPos)); - - // Row 6 - aPos = ScAddress(0, 5, 0); - CPPUNIT_ASSERT_EQUAL(CELLTYPE_STRING, pDoc->GetCellType(aPos)); - CPPUNIT_ASSERT_EQUAL(OUString(u"visible"), pDoc->GetString(aPos)); - aPos.IncCol(); - CPPUNIT_ASSERT_EQUAL(CELLTYPE_NONE, pDoc->GetCellType(aPos)); - CPPUNIT_ASSERT_EQUAL(OUString(), pDoc->GetString(aPos)); - aPos.IncCol(); - CPPUNIT_ASSERT_EQUAL(CELLTYPE_NONE, pDoc->GetCellType(aPos)); - CPPUNIT_ASSERT_EQUAL(OUString(), pDoc->GetString(aPos)); - aPos.IncCol(); - CPPUNIT_ASSERT_EQUAL(CELLTYPE_NONE, pDoc->GetCellType(aPos)); - CPPUNIT_ASSERT_EQUAL(OUString(), pDoc->GetString(aPos)); -} - -CPPUNIT_TEST_FIXTURE(ScFiltersTest2, testTooManyColsRows) -{ - // The intentionally doc has cells beyond our MAXROW/MAXCOL, so there - // should be a warning on load. - createScDoc("ods/too-many-cols-rows.ods", /*pPassword*/ nullptr, /*bCheckWarningError*/ false); - - ScDocShell* pDocSh = getScDocShell(); - SfxMedium* pMedium = pDocSh->GetMedium(); - - CPPUNIT_ASSERT(pMedium->GetWarningError() == SCWARN_IMPORT_ROW_OVERFLOW - || pMedium->GetWarningError() == SCWARN_IMPORT_COLUMN_OVERFLOW); - - createScDoc("xlsx/too-many-cols-rows.xlsx", /*pPassword*/ nullptr, - /*bCheckWarningError*/ false); - - pDocSh = getScDocShell(); - pMedium = pDocSh->GetMedium(); - - CPPUNIT_ASSERT(pMedium->GetWarningError() == SCWARN_IMPORT_ROW_OVERFLOW - || pMedium->GetWarningError() == SCWARN_IMPORT_COLUMN_OVERFLOW); -} - -CPPUNIT_TEST_FIXTURE(ScFiltersTest2, testTdf83671_SmartArt_import) -{ - // The example doc contains a diagram (SmartArt). Such should be imported as group object. - // Error was, that the background shape had size zero and the diagram shapes where missing. - - // Make sure SmartArt is loaded as group shape - bool bUseGroup = officecfg::Office::Common::Filter::Microsoft::Import::SmartArtToShapes::get(); - if (!bUseGroup) - { - std::shared_ptr pChange( - comphelper::ConfigurationChanges::create()); - officecfg::Office::Common::Filter::Microsoft::Import::SmartArtToShapes::set(true, pChange); - pChange->commit(); - } - - // Get document and shape - createScDoc("xlsx/tdf83671_SmartArt_import.xlsx"); - ScDocument* pDoc = getScDoc(); - ScDrawLayer* pDrawLayer = pDoc->GetDrawLayer(); - SdrPage* pPage = pDrawLayer->GetPage(0); - SdrObject* pObj = pPage->GetObj(0); - - // Check that it is a group shape with 4 children - CPPUNIT_ASSERT(pObj->IsGroupObject()); - SdrObjList* pChildren = pObj->getChildrenOfSdrObject(); - CPPUNIT_ASSERT_EQUAL(size_t(4), pChildren->GetObjCount()); - - // The background shape should have about 60mm x 42mm size. - // Without fix its size was zero. - tools::Rectangle aBackground = pChildren->GetObj(0)->GetLogicRect(); - CPPUNIT_ASSERT_DOUBLES_EQUAL(sal_Int32(6000), aBackground.getOpenWidth(), 10); - CPPUNIT_ASSERT_DOUBLES_EQUAL(sal_Int32(4200), aBackground.getOpenHeight(), 10); - - if (!bUseGroup) - { - std::shared_ptr pChange( - comphelper::ConfigurationChanges::create()); - officecfg::Office::Common::Filter::Microsoft::Import::SmartArtToShapes::set(false, pChange); - pChange->commit(); - } -} - -CPPUNIT_TEST_FIXTURE(ScFiltersTest2, testTdf83671_SmartArt_import2) -{ - // The example doc contains a diagram (SmartArt). Such should be imported as group object. - // With conversion enabled, the group contains only a graphic. Error was, that the shape - // had size 100x100 Hmm and position 0|0. - - // Make sure SmartArt is loaded with converting to metafile - bool bUseGroup = officecfg::Office::Common::Filter::Microsoft::Import::SmartArtToShapes::get(); - if (bUseGroup) - { - std::shared_ptr pChange( - comphelper::ConfigurationChanges::create()); - officecfg::Office::Common::Filter::Microsoft::Import::SmartArtToShapes::set(false, pChange); - pChange->commit(); - } - - // Get document and shape - createScDoc("xlsx/tdf83671_SmartArt_import.xlsx"); - ScDocument* pDoc = getScDoc(); - ScDrawLayer* pDrawLayer = pDoc->GetDrawLayer(); - SdrPage* pPage = pDrawLayer->GetPage(0); - SdrObject* pObj = pPage->GetObj(0); - - // Check that it is a group shape with 1 child - CPPUNIT_ASSERT(pObj->IsGroupObject()); - SdrObjList* pChildren = pObj->getChildrenOfSdrObject(); - CPPUNIT_ASSERT_EQUAL(size_t(1), pChildren->GetObjCount()); - - // The child shape should have about 60mm x 42mm size and position 1164|1270. - // Without fix its size was 100x100 and position 0|0. - tools::Rectangle aBackground = pChildren->GetObj(0)->GetLogicRect(); - CPPUNIT_ASSERT_DOUBLES_EQUAL(sal_Int32(6000), aBackground.getOpenWidth(), 10); - CPPUNIT_ASSERT_DOUBLES_EQUAL(sal_Int32(4200), aBackground.getOpenHeight(), 10); - CPPUNIT_ASSERT_EQUAL(Point(1164, 1270), aBackground.GetPos()); - - if (bUseGroup) - { - std::shared_ptr pChange( - comphelper::ConfigurationChanges::create()); - officecfg::Office::Common::Filter::Microsoft::Import::SmartArtToShapes::set(true, pChange); - pChange->commit(); - } -} - -CPPUNIT_TEST_FIXTURE(ScFiltersTest2, testTdf151818_SmartArtFontColor) -{ - // The document contains a SmartArt where the color for the texts in the shapes is given by - // the theme. - // Error was, that the theme was not considered and therefore the text was white. - - // Make sure it is not loaded as metafile but with single shapes. - bool bUseGroup = officecfg::Office::Common::Filter::Microsoft::Import::SmartArtToShapes::get(); - if (!bUseGroup) - { - std::shared_ptr pChange( - comphelper::ConfigurationChanges::create()); - officecfg::Office::Common::Filter::Microsoft::Import::SmartArtToShapes::set(true, pChange); - pChange->commit(); - } - - // Get document and shape in SmartArt object - createScDoc("xlsx/tdf151818_SmartartThemeFontColor.xlsx"); - uno::Reference xDoc(mxComponent, uno::UNO_QUERY_THROW); - uno::Reference xPage(xDoc->getDrawPages()->getByIndex(0), - uno::UNO_QUERY_THROW); - uno::Reference xSmartArt(xPage->getByIndex(0), uno::UNO_QUERY_THROW); - // shape 0 is the background shape without text - uno::Reference xShape(xSmartArt->getByIndex(1), uno::UNO_QUERY); - - // text color - uno::Reference xText(xShape->getText(), uno::UNO_QUERY); - uno::Reference xPara(xText->createEnumeration()->nextElement(), - uno::UNO_QUERY); - uno::Reference xPortion(xPara->createEnumeration()->nextElement(), - uno::UNO_QUERY); - sal_Int32 nActualColor{ 0 }; - xPortion->getPropertyValue("CharColor") >>= nActualColor; - // Without fix the test would have failed with: - // - Expected: 4478058 (0x44546A) - // - Actual : 16777215 (0xFFFFFF), that is text was white - CPPUNIT_ASSERT_EQUAL(sal_Int32(0x44546A), nActualColor); - - // clrScheme. For map between name in xlsx and index from CharColorTheme see - // oox::drawingml::Color::getSchemeColorIndex() - // Without fix the color scheme was "lt1" (1) but should be "dk2" (2). - CPPUNIT_ASSERT_EQUAL(sal_Int16(2), - xPortion->getPropertyValue("CharColorTheme").get()); - - if (!bUseGroup) - { - std::shared_ptr pChange( - comphelper::ConfigurationChanges::create()); - officecfg::Office::Common::Filter::Microsoft::Import::SmartArtToShapes::set(false, pChange); - pChange->commit(); - } -} - CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/qa/unit/subsequent_filters_test3.cxx b/sc/qa/unit/subsequent_filters_test3.cxx new file mode 100644 index 000000000000..5e2683fe875b --- /dev/null +++ b/sc/qa/unit/subsequent_filters_test3.cxx @@ -0,0 +1,1319 @@ +/* -*- 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 + +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include +#include +#include "helper/qahelper.hxx" +#include + +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; + +class ScFiltersTest3 : public ScModelTestBase +{ +public: + ScFiltersTest3(); +}; + +ScFiltersTest3::ScFiltersTest3() + : ScModelTestBase("sc/qa/unit/data") +{ +} + +CPPUNIT_TEST_FIXTURE(ScFiltersTest3, testBorderColorsXLSXML) +{ + createScDoc("xml/border-colors.xml"); + ScDocument* pDoc = getScDoc(); + + // B3 - red + const ScPatternAttr* pPat = pDoc->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 = pDoc->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 = pDoc->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 = pDoc->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 +} + +CPPUNIT_TEST_FIXTURE(ScFiltersTest3, testHiddenRowsColumnsXLSXML) +{ + createScDoc("xml/hidden-rows-columns.xml"); + ScDocument* pDoc = getScDoc(); + + struct Check + { + SCCOLROW nPos1; + SCCOLROW nPos2; + bool bVisible; + }; + + std::vector aRowChecks = { + { 0, 0, true }, + { 1, 2, false }, + { 3, 3, true }, + { 4, 4, false }, + { 5, 7, true }, + { 8, 8, false }, + { 9, pDoc->MaxRow(), true }, + }; + + for (const Check& c : aRowChecks) + { + SCROW nRow1 = -1, nRow2 = -1; + bool bVisible = !pDoc->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 aColChecks = { + { 0, 1, true }, + { 2, 5, false }, + { 6, 9, true }, + { 10, 10, false }, + { 11, pDoc->MaxCol(), true }, + }; + + for (const Check& c : aColChecks) + { + SCCOL nCol1 = -1, nCol2 = -1; + bool bVisible = !pDoc->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)); + } +} + +CPPUNIT_TEST_FIXTURE(ScFiltersTest3, testColumnWidthRowHeightXLSXML) +{ + createScDoc("xml/column-width-row-height.xml"); + ScDocument* pDoc = getScDoc(); + + struct RowHeight + { + SCROW nRow1; + SCROW nRow2; + sal_uInt16 nHeight; // in points (1 point == 20 twips) + }; + + std::vector 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 = pDoc->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 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 = pDoc->GetColWidth(i, 0); + CPPUNIT_ASSERT_EQUAL(sal_uInt16(cw.nWidth * 20), nWidth); + } + } +} + +CPPUNIT_TEST_FIXTURE(ScFiltersTest3, testCharacterSetXLSXML) +{ + createScDoc("xml/character-set.xml"); + ScDocument* pDoc = getScDoc(); + + CPPUNIT_ASSERT_EQUAL(SCTAB(1), pDoc->GetTableCount()); + + OUString aName; + pDoc->GetName(0, aName); + + // Check the sheet name. The values are all Cyrillic letters. + std::vector aBuf = { 0x041b, 0x0438, 0x0441, 0x0442, 0x0031 }; + OUString aExpected(aBuf.data(), aBuf.size()); + CPPUNIT_ASSERT_EQUAL(aExpected, aName); + + // Check the value of I4 + OUString aVal = pDoc->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 = pDoc->GetString(ScAddress(9, 2, 0)); + aBuf = { 0x041e, 0x0441, 0x0442, 0x0430, 0x0442, 0x043e, 0x043a }; + aExpected = OUString(aBuf.data(), aBuf.size()); + CPPUNIT_ASSERT_EQUAL(aExpected, aVal); +} + +CPPUNIT_TEST_FIXTURE(ScFiltersTest3, testWrapAndShrinkXLSXML) +{ + createScDoc("xml/wrap-and-shrink.xml"); + ScDocument* pDoc = getScDoc(); + + CPPUNIT_ASSERT_EQUAL(SCTAB(1), pDoc->GetTableCount()); + + struct Check + { + SCCOL nCol; + SCROW nRow; + + bool bWrapText; + bool bShrinkToFit; + }; + + constexpr Check aChecks[] = { + { 1, 0, false, false }, + { 1, 1, true, false }, + { 1, 2, false, true }, + }; + + for (const auto& rC : aChecks) + { + const ScLineBreakCell* pLB = pDoc->GetAttr(rC.nCol, rC.nRow, 0, ATTR_LINEBREAK); + CPPUNIT_ASSERT_EQUAL(pLB->GetValue(), rC.bWrapText); + + const ScShrinkToFitCell* pSTF = pDoc->GetAttr(rC.nCol, rC.nRow, 0, ATTR_SHRINKTOFIT); + CPPUNIT_ASSERT_EQUAL(pSTF->GetValue(), rC.bShrinkToFit); + } +} + +CPPUNIT_TEST_FIXTURE(ScFiltersTest3, testCondFormatXLSB) +{ + createScDoc("xlsb/cond_format.xlsb"); + + ScDocument* pDoc = getScDoc(); + ScConditionalFormatList* pList = pDoc->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()); +} + +CPPUNIT_TEST_FIXTURE(ScFiltersTest3, testPageScalingXLSX) +{ + createScDoc("xlsx/page_scale.xlsx"); + ScDocument* pDoc = getScDoc(); + + OUString aStyleName = pDoc->GetPageStyle(0); + ScStyleSheetPool* pStylePool = pDoc->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); +} + +CPPUNIT_TEST_FIXTURE(ScFiltersTest3, testActiveXCheckboxXLSX) +{ + createScDoc("xlsx/activex_checkbox.xlsx"); + uno::Reference xDoc(mxComponent, UNO_QUERY_THROW); + uno::Reference xIA(xDoc->getSheets(), UNO_QUERY_THROW); + uno::Reference xDrawPageSupplier(xIA->getByIndex(0), + UNO_QUERY_THROW); + uno::Reference xIA_DrawPage(xDrawPageSupplier->getDrawPage(), + UNO_QUERY_THROW); + uno::Reference xControlShape(xIA_DrawPage->getByIndex(0), + UNO_QUERY_THROW); + + // Check control type + uno::Reference xPropertySet(xControlShape->getControl(), uno::UNO_QUERY); + uno::Reference 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) + Color nColor; + xPropertySet->getPropertyValue("BackgroundColor") >>= nColor; + CPPUNIT_ASSERT_EQUAL(Color(0x316AC5), nColor); + + // Check Text color (active border system color) + xPropertySet->getPropertyValue("TextColor") >>= nColor; + CPPUNIT_ASSERT_EQUAL(Color(0xD4D0C8), nColor); + + // Check state of the checkbox + sal_Int16 nState; + xPropertySet->getPropertyValue("State") >>= nState; + CPPUNIT_ASSERT_EQUAL(sal_Int16(1), nState); +} + +CPPUNIT_TEST_FIXTURE(ScFiltersTest3, testTdf60673) +{ + createScDoc("xlsx/tdf60673.xlsx"); + uno::Reference xDoc(mxComponent, UNO_QUERY_THROW); + uno::Reference xIA(xDoc->getSheets(), UNO_QUERY_THROW); + uno::Reference xDrawPageSupplier(xIA->getByIndex(0), + UNO_QUERY_THROW); + uno::Reference xIA_DrawPage(xDrawPageSupplier->getDrawPage(), + UNO_QUERY_THROW); + uno::Reference xControlShape(xIA_DrawPage->getByIndex(0), + UNO_QUERY_THROW); + + uno::Reference xPropertySet(xControlShape->getControl(), uno::UNO_QUERY); + + OUString sLabel; + xPropertySet->getPropertyValue("Label") >>= sLabel; + + // Without the fix in place, this test would have failed with + // - Expected: PL: ĄŚŻŹĆŃŁÓĘ + // - Actual : PL: + CPPUNIT_ASSERT_EQUAL(OUString(u"PL: ĄŚŻŹĆŃŁÓĘ"), sLabel); +} + +CPPUNIT_TEST_FIXTURE(ScFiltersTest3, testtdf120301_xmlSpaceParsingXLSX) +{ + createScDoc("xlsx/tdf120301_xmlSpaceParsing.xlsx"); + uno::Reference xDoc(mxComponent, UNO_QUERY_THROW); + uno::Reference xIA(xDoc->getSheets(), UNO_QUERY_THROW); + uno::Reference xDrawPageSupplier(xIA->getByIndex(0), + UNO_QUERY_THROW); + uno::Reference xIA_DrawPage(xDrawPageSupplier->getDrawPage(), + UNO_QUERY_THROW); + + uno::Reference xControlShape(xIA_DrawPage->getByIndex(0), + UNO_QUERY_THROW); + uno::Reference XPropSet(xControlShape->getControl(), uno::UNO_QUERY_THROW); + OUString sCaption; + XPropSet->getPropertyValue("Label") >>= sCaption; + CPPUNIT_ASSERT_EQUAL(OUString("Check Box 1"), sCaption); +} + +namespace +{ +struct PaintListener : public SfxListener +{ + bool mbCalled = false; + virtual void Notify(SfxBroadcaster& /*rBC*/, const SfxHint& rHint) override + { + const ScPaintHint* pPaintHint = dynamic_cast(&rHint); + if (pPaintHint) + { + if (pPaintHint->GetStartCol() <= 0 && pPaintHint->GetEndCol() >= 0 + && pPaintHint->GetStartRow() <= 9 && pPaintHint->GetEndRow() >= 9) + { + mbCalled = true; + } + } + } +}; +} + +CPPUNIT_TEST_FIXTURE(ScFiltersTest3, testCondFormatFormulaListenerXLSX) +{ + createScDoc("xlsx/cond_format_formula_listener.xlsx"); + ScDocShell* pDocSh = getScDocShell(); + PaintListener aListener; + aListener.StartListening(*pDocSh); + ScDocument* pDoc = getScDoc(); + ScConditionalFormatList* pList = pDoc->GetCondFormList(0); + CPPUNIT_ASSERT(pList); + + CPPUNIT_ASSERT_EQUAL(size_t(1), pList->size()); + ScConditionalFormat* pFormat = pList->begin()->get(); + CPPUNIT_ASSERT(pFormat); + pDoc->SetDocVisible(true); + pDoc->SetValue(0, 0, 0, 2.0); + + CPPUNIT_ASSERT(aListener.mbCalled); +} + +CPPUNIT_TEST_FIXTURE(ScFiltersTest3, 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(); + }); + + createScDoc("xlsx/tdf137091.xlsx"); + ScDocument* pDoc = getScDoc(); + + // Without the fix in place, this test would have failed with + // - Expected: 28/4 + // - Actual : Err:507 + CPPUNIT_ASSERT_EQUAL(OUString("28/4"), pDoc->GetString(ScAddress(2, 1, 0))); +} + +CPPUNIT_TEST_FIXTURE(ScFiltersTest3, testTdf141495) +{ + // 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(); + }); + + createScDoc("xlsx/tdf141495.xlsx"); + ScDocument* pDoc = getScDoc(); + + ScDocShell* pDocSh = getScDocShell(); + pDocSh->DoHardRecalc(); + + // Without the fix in place, this test would have failed with + // - Expected: 44926 + // - Actual : #ADDIN? + CPPUNIT_ASSERT_EQUAL(OUString("44926"), pDoc->GetString(ScAddress(11, 6, 0))); +} + +CPPUNIT_TEST_FIXTURE(ScFiltersTest3, testTdf70455) +{ + createScDoc("xlsx/tdf70455.xlsx"); + ScDocument* pDoc = getScDoc(); + + // Without the fix in place, this test would have failed with + // - Expected: €780.00 + // - Actual : Err:509 + CPPUNIT_ASSERT_EQUAL(OUString(u"€780.00"), pDoc->GetString(ScAddress(7, 7, 0))); +} + +CPPUNIT_TEST_FIXTURE(ScFiltersTest3, testTdf62268) +{ + createScDoc("ods/tdf62268.ods"); + ScDocument* pDoc = getScDoc(); + int nHeight; + + SCTAB nTab = 0; + nHeight = pDoc->GetRowHeight(0, nTab, false); + CPPUNIT_ASSERT_LESSEQUAL(3, abs(256 - nHeight)); + nHeight = pDoc->GetRowHeight(1, nTab, false); + CPPUNIT_ASSERT_LESSEQUAL(19, abs(1905 - nHeight)); +} + +CPPUNIT_TEST_FIXTURE(ScFiltersTest3, testTdf137453) +{ + createScDoc("ods/tdf137453.ods"); + + ScDocument* pDoc = getScDoc(); + + // Without the fix in place, this test would have failed with + // - Expected: 3333333333/100 + // - Actual : -961633963/100 + CPPUNIT_ASSERT_EQUAL(OUString("3333333333/100"), pDoc->GetString(ScAddress(0, 0, 0))); +} + +CPPUNIT_TEST_FIXTURE(ScFiltersTest3, testTdf112780) +{ + createScDoc("ods/tdf112780.ods"); + + ScDocument* pDoc = getScDoc(); + + // Without the fix in place, this test would have failed with + // - Expected: + // - Actual : #VALUE! + CPPUNIT_ASSERT_EQUAL(OUString(""), pDoc->GetString(ScAddress(3, 5, 0))); + + OUString aFormula = pDoc->GetFormula(3, 5, 0); + CPPUNIT_ASSERT_EQUAL(OUString("=G6+J6+M6"), aFormula); +} + +CPPUNIT_TEST_FIXTURE(ScFiltersTest3, testTdf72470) +{ + // Without the fix in place, this test would have hung + + createScDoc("xls/tdf72470.xls"); + + ScDocument* pDoc = getScDoc(); + + CPPUNIT_ASSERT_EQUAL(OUString("name"), pDoc->GetString(ScAddress(0, 0, 0))); + CPPUNIT_ASSERT_EQUAL(OUString(u"أسمي walid"), pDoc->GetString(ScAddress(0, 1, 0))); +} + +CPPUNIT_TEST_FIXTURE(ScFiltersTest3, testTdf35636) +{ + createScDoc("ods/tdf35636.ods"); + + ScDocument* pDoc = getScDoc(); + + // Without the fix in place, SUMIF would have returned 0.0 + // with empty cells in the criteria + CPPUNIT_ASSERT_EQUAL(50.0, pDoc->GetValue(ScAddress(1, 4, 0))); +} + +CPPUNIT_TEST_FIXTURE(ScFiltersTest3, testTdf98481) +{ + createScDoc("xlsx/tdf98481.xlsx"); + + ScDocument* pDoc = getScDoc(); + + // Without the fix in place, this test would have failed with + // - Expected: 4 + // - Actual : 0 + CPPUNIT_ASSERT_EQUAL(4.0, pDoc->GetValue(ScAddress(4, 1, 0))); + CPPUNIT_ASSERT_EQUAL(0.0, pDoc->GetValue(ScAddress(4, 2, 0))); + CPPUNIT_ASSERT_EQUAL(3.0, pDoc->GetValue(ScAddress(4, 3, 0))); + CPPUNIT_ASSERT_EQUAL(4.0, pDoc->GetValue(ScAddress(1, 4, 0))); + CPPUNIT_ASSERT_EQUAL(0.0, pDoc->GetValue(ScAddress(2, 4, 0))); + CPPUNIT_ASSERT_EQUAL(3.0, pDoc->GetValue(ScAddress(3, 4, 0))); +} + +CPPUNIT_TEST_FIXTURE(ScFiltersTest3, testTdf115022) +{ + createScDoc("xlsx/tdf115022.xlsx"); + + ScDocument* pDoc = getScDoc(); + + CPPUNIT_ASSERT_EQUAL(6.0, pDoc->GetValue(ScAddress(1, 8, 0))); + + ScDocShell* pDocSh = getScDocShell(); + pDocSh->DoHardRecalc(); + + // Without the fix in place, this test would have failed with + // - Expected: 6 + // - Actual : 21 + CPPUNIT_ASSERT_EQUAL(6.0, pDoc->GetValue(ScAddress(1, 8, 0))); +} + +CPPUNIT_TEST_FIXTURE(ScFiltersTest3, testVBAMacroFunctionODS) +{ + createScDoc("ods/vba_macro_functions.ods"); + ScDocument* pDoc = getScDoc(); + + OUString aFunction = pDoc->GetFormula(2, 0, 0); + std::cout << aFunction << std::endl; + CPPUNIT_ASSERT_DOUBLES_EQUAL(10.0, pDoc->GetValue(2, 0, 0), 1e-6); +} + +CPPUNIT_TEST_FIXTURE(ScFiltersTest3, testAutoheight2Rows) +{ + createScDoc("ods/autoheight2rows.ods"); + ScDocument* pDoc = getScDoc(); + + SCTAB nTab = 0; + int nHeight1 = pDoc->GetRowHeight(0, nTab, false); + int nHeight2 = pDoc->GetRowHeight(1, nTab, false); + int nHeight4 = pDoc->GetRowHeight(3, nTab, false); + int nHeight5 = pDoc->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); +} + +CPPUNIT_TEST_FIXTURE(ScFiltersTest3, testXLSDefColWidth) +{ + // XLS has only 256 columns; but on import, we need to set default width to all above that limit + createScDoc("xls/chartx.xls"); + ScDocument* pDoc = getScDoc(); + + int nWidth = pDoc->GetColWidth(pDoc->MaxCol(), 0, false); + // This was 1280 + CPPUNIT_ASSERT_EQUAL(1005, nWidth); +} + +CPPUNIT_TEST_FIXTURE(ScFiltersTest3, testTdf148423) +{ + createScDoc("csv/tdf148423.csv"); + ScDocument* pDoc = getScDoc(); + + int nWidth = pDoc->GetColWidth(0, 0, false); + + // Without the fix in place, this test would have failed with + // - Expected: 32880 + // - Actual : 112 + CPPUNIT_ASSERT_EQUAL(32880, nWidth); +} + +CPPUNIT_TEST_FIXTURE(ScFiltersTest3, testTdf152053) +{ + createScDoc("csv/tdf152053.csv"); + ScDocument* pDoc = getScDoc(); + + int nWidth = pDoc->GetColWidth(0, 0, false); + + // Without the fix in place, this test would have failed with + // - Expected: 1162 + // - Actual : 715 + // tolerance is for windows machines with non-default DPI + CPPUNIT_ASSERT_DOUBLES_EQUAL(1162, nWidth, 10); +} + +CPPUNIT_TEST_FIXTURE(ScFiltersTest3, testPreviewMissingObjLink) +{ + createScDoc("ods/keep-preview-missing-obj-link.ods"); + + ScDocument* pDoc = getScDoc(); + + // Retrieve the ole object + const SdrOle2Obj* pOleObj = getSingleOleObject(*pDoc, 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); +} + +CPPUNIT_TEST_FIXTURE(ScFiltersTest3, 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. + createScDoc("xlsx/testShapeRotationImport.xlsx"); + uno::Reference xDoc(mxComponent, uno::UNO_QUERY_THROW); + uno::Reference 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> aExpectedValues{ + { 4400, { { "x", 6826 }, { "y", 36891 }, { "width", 8889 }, { "height", 1163 } } }, + { 4500, { { "x", 4485 }, { "y", 36397 }, { "width", 8889 }, { "height", 1164 } } }, + { 4600, { { "x", 1669 }, { "y", 36272 }, { "width", 8863 }, { "height", 1142 } } }, + { 13400, { { "x", 13752 }, { "y", 28403 }, { "width", 8863 }, { "height", 1194 } } }, + { 13500, { { "x", 10810 }, { "y", 27951 }, { "width", 8863 }, { "height", 1168 } } }, + { 13600, { { "x", 8442 }, { "y", 28334 }, { "width", 8889 }, { "height", 1163 } } }, + { 22400, { { "x", 14934 }, { "y", 12981 }, { "width", 8889 }, { "height", 1163 } } }, + { 22500, { { "x", 11754 }, { "y", 12837 }, { "width", 8889 }, { "height", 1163 } } }, + { 22600, { { "x", 8248 }, { "y", 12919 }, { "width", 8862 }, { "height", 1169 } } }, + { 31400, { { "x", 8089 }, { "y", 1160 }, { "width", 9815 }, { "height", 1171 } } }, + { 31500, { { "x", 4421 }, { "y", 1274 }, { "width", 10238 }, { "height", 1171 } } }, + { 31600, { { "x", 1963 }, { "y", 1882 }, { "width", 10297 }, { "height", 1163 } } }, + }; + + for (sal_Int32 ind = 0; ind < 12; ++ind) + { + uno::Reference xShape(xPage->getByIndex(ind), uno::UNO_QUERY_THROW); + + uno::Reference xShapeProperties(xShape, uno::UNO_QUERY); + uno::Any nRotProp = xShapeProperties->getPropertyValue("RotateAngle"); + sal_Int32 nRot = nRotProp.get(); + const OString sNote = "RotateAngle = " + OString::number(nRot); + + awt::Point aPosition = xShape->getPosition(); + awt::Size aSize = xShape->getSize(); + + CPPUNIT_ASSERT_MESSAGE(sNote.getStr(), aExpectedValues.find(nRot) != aExpectedValues.end()); + CPPUNIT_ASSERT_EQUAL_MESSAGE(sNote.getStr(), aExpectedValues[nRot]["x"], aPosition.X); + CPPUNIT_ASSERT_EQUAL_MESSAGE(sNote.getStr(), aExpectedValues[nRot]["y"], aPosition.Y); + CPPUNIT_ASSERT_EQUAL_MESSAGE(sNote.getStr(), aExpectedValues[nRot]["width"], aSize.Width); + CPPUNIT_ASSERT_EQUAL_MESSAGE(sNote.getStr(), aExpectedValues[nRot]["height"], aSize.Height); + } +} + +CPPUNIT_TEST_FIXTURE(ScFiltersTest3, testShapeDisplacementOnRotationImport) +{ + // tdf#135918 shape is displaced on rotation if it is placed next to the sheets upper/left edges + createScDoc("xlsx/testShapeDisplacementOnRotationImport.xlsx"); + + uno::Reference xDoc(mxComponent, uno::UNO_QUERY_THROW); + uno::Reference xPage(xDoc->getDrawPages()->getByIndex(0), + uno::UNO_QUERY_THROW); + uno::Reference xShape(xPage->getByIndex(0), uno::UNO_QUERY_THROW); + + uno::Reference xShapeProperties(xShape, uno::UNO_QUERY_THROW); + uno::Any aRectProp = xShapeProperties->getPropertyValue("FrameRect"); + awt::Rectangle aRectangle = aRectProp.get(); + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), aRectangle.X); + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aRectangle.Y); +} + +CPPUNIT_TEST_FIXTURE(ScFiltersTest3, testTextBoxBodyUpright) +{ + // tdf#106197 We should import the "upright" attribute of txBody. + createScDoc("xlsx/tdf106197_import_upright.xlsx"); + + uno::Reference xDoc(mxComponent, uno::UNO_QUERY_THROW); + uno::Reference xPage(xDoc->getDrawPages()->getByIndex(0), + uno::UNO_QUERY_THROW); + uno::Reference xShape(xPage->getByIndex(0), uno::UNO_QUERY_THROW); + uno::Reference xShapeProperties(xShape, uno::UNO_QUERY_THROW); + + // Check that we imported "Upright". + bool isUpright = false; + if (xShapeProperties->getPropertySetInfo()->hasPropertyByName("InteropGrabBag")) + { + uno::Sequence aGrabBag; + xShapeProperties->getPropertyValue("InteropGrabBag") >>= aGrabBag; + for (auto& aProp : std::as_const(aGrabBag)) + { + if (aProp.Name == "Upright") + { + aProp.Value >>= isUpright; + break; + } + } + } + CPPUNIT_ASSERT_EQUAL(true, isUpright); + + // Check the TextPreRotateAngle has the compensation for the additional 90deg area rotation, + // which is added in Shape::createAndInsert to get the same rendering as in MS Office. + sal_Int32 nAngle; + uno::Any aGeom = xShapeProperties->getPropertyValue("CustomShapeGeometry"); + auto aGeomSeq = aGeom.get>(); + for (const auto& aProp : std::as_const(aGeomSeq)) + { + if (aProp.Name == "TextPreRotateAngle") + { + aProp.Value >>= nAngle; + break; + } + } + CPPUNIT_ASSERT_EQUAL(sal_Int32(90), nAngle); +} + +CPPUNIT_TEST_FIXTURE(ScFiltersTest3, testTextBoxBodyRotateAngle) +{ + createScDoc("xlsx/tdf141644.xlsx"); + + uno::Reference xDoc(mxComponent, uno::UNO_QUERY_THROW); + uno::Reference xPage(xDoc->getDrawPages()->getByIndex(0), + uno::UNO_QUERY_THROW); + uno::Reference xShape(xPage->getByIndex(0), uno::UNO_QUERY_THROW); + uno::Reference xShapeProperties(xShape, uno::UNO_QUERY_THROW); + + // Check the text direction. + sal_Int16 eWritingMode = text::WritingMode2::LR_TB; + if (xShapeProperties->getPropertySetInfo()->hasPropertyByName("WritingMode")) + xShapeProperties->getPropertyValue("WritingMode") >>= eWritingMode; + CPPUNIT_ASSERT_EQUAL(sal_Int16(text::WritingMode2::BT_LR), eWritingMode); +} + +CPPUNIT_TEST_FIXTURE(ScFiltersTest3, testTextLengthDataValidityXLSX) +{ + createScDoc("xlsx/textLengthDataValidity.xlsx"); + + ScDocument* pDoc = getScDoc(); + + const ScValidationData* pData = pDoc->GetValidationEntry(1); + + ScRefCellValue aCellA1; // A1 = 1234(numeric value) + ScAddress aValBaseAddrA1(0, 0, 0); + aCellA1.assign(*pDoc, aValBaseAddrA1); + bool bValidA1 = pData->IsDataValid(aCellA1, aValBaseAddrA1); + + ScRefCellValue aCellA2; // A2 = 1234(numeric value format as text) + ScAddress aValBaseAddrA2(0, 1, 0); + aCellA2.assign(*pDoc, aValBaseAddrA2); + bool bValidA2 = pData->IsDataValid(aCellA2, aValBaseAddrA2); + + ScRefCellValue aCellA3; // A3 = 1234.00(numeric value) + ScAddress aValBaseAddrA3(0, 2, 0); + aCellA3.assign(*pDoc, aValBaseAddrA3); + bool bValidA3 = pData->IsDataValid(aCellA3, aValBaseAddrA3); + + ScRefCellValue aCellA4; // A4 = 12.3(numeric value) + ScAddress aValBaseAddrA4(0, 3, 0); + aCellA4.assign(*pDoc, 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); +} + +CPPUNIT_TEST_FIXTURE(ScFiltersTest3, testDeleteCircles) +{ + createScDoc("xlsx/testDeleteCircles.xlsx"); + + ScDocument* pDoc = getScDoc(); + + ScDrawLayer* pDrawLayer = pDoc->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(*pDoc, aPosA1); + + // Mark invalid value + bool bOverflow; + bool bMarkInvalid = ScDetectiveFunc(*pDoc, 0).MarkInvalid(bOverflow); + CPPUNIT_ASSERT_EQUAL(true, bMarkInvalid); + + // There should be a circle object! + CPPUNIT_ASSERT_EQUAL(static_cast(1), pPage->GetObjCount()); + + // The value of A1 change to Hello1. + pDoc->SetString(0, 0, 0, "Hello1"); + + // Check that the data is valid.(True if text length = 6) + const ScValidationData* pData = pDoc->GetValidationEntry(1); + bool bValidA1 = pData->IsDataValid(aCellA1, aPosA1); + // if valid, delete circle. + if (bValidA1) + ScDetectiveFunc(*pDoc, 0).DeleteCirclesAt(aPosA1.Col(), aPosA1.Row()); + + // There should not be a circle object! + CPPUNIT_ASSERT_EQUAL(static_cast(0), pPage->GetObjCount()); +} + +CPPUNIT_TEST_FIXTURE(ScFiltersTest3, testDrawCircleInMergeCells) +{ + createScDoc("xlsx/testDrawCircleInMergeCells.xlsx"); + + ScDocument* pDoc = getScDoc(); + + ScDrawLayer* pDrawLayer = pDoc->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); + pDoc->ExtendTotalMerge(aMergedRange); + CPPUNIT_ASSERT_EQUAL(ScRange(0, 0, 0, 1, 1, 0), aMergedRange); + + // Mark invalid value + bool bOverflow; + bool bMarkInvalid = ScDetectiveFunc(*pDoc, 0).MarkInvalid(bOverflow); + CPPUNIT_ASSERT_EQUAL(true, bMarkInvalid); + + // There should be a circle object! + CPPUNIT_ASSERT_EQUAL(static_cast(1), pPage->GetObjCount()); + + SdrObject* pObj = pPage->GetObj(0); + tools::Rectangle aRect(pObj->GetLogicRect()); + Point aStartCircle = aRect.TopLeft(); + Point aEndCircle = aRect.BottomRight(); + + tools::Rectangle aCellRect = pDoc->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) + pDoc->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 = pDoc->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()); +} + +CPPUNIT_TEST_FIXTURE(ScFiltersTest3, testDeleteCirclesInRowAndCol) +{ + createScDoc("ods/deleteCirclesInRowAndCol.ods"); + + ScDocument* pDoc = getScDoc(); + + ScDrawLayer* pDrawLayer = pDoc->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(6), pPage->GetObjCount()); + + // Delete first row. + pDrawLayer->DeleteObjectsInArea(0, 0, 0, pDoc->MaxCol(), 0, true); + + // There should be 3 circle objects! + CPPUNIT_ASSERT_EQUAL(static_cast(3), pPage->GetObjCount()); + + // Delete first col. + pDrawLayer->DeleteObjectsInArea(0, 0, 0, 0, pDoc->MaxRow(), true); + + // There should not be a circle object! + CPPUNIT_ASSERT_EQUAL(static_cast(0), pPage->GetObjCount()); +} + +CPPUNIT_TEST_FIXTURE(ScFiltersTest3, testTdf129940) +{ + // Test pure span elements inside text:ruby-base + createScDoc("ods/tdf129940.ods"); + ScDocument* pDoc = getScDoc(); + // Pure text within text:ruby-base + OUString aStr = pDoc->GetString(ScAddress(0, 0, 0)); + CPPUNIT_ASSERT_EQUAL(OUString(u"小笠原"), aStr); + aStr = pDoc->GetString(ScAddress(1, 0, 0)); + CPPUNIT_ASSERT_EQUAL(OUString(u"徳彦"), aStr); + + // Multiple text:span within text:ruby-base + aStr = pDoc->GetString(ScAddress(2, 0, 0)); + CPPUNIT_ASSERT_EQUAL(OUString(u"注音符號"), aStr); +} + +CPPUNIT_TEST_FIXTURE(ScFiltersTest3, testTdf119190) +{ + createScDoc("xlsx/tdf119190.xlsx"); + ScDocument* pDoc = getScDoc(); + + // Without the fix in place, this test would have failed here + CPPUNIT_ASSERT(pDoc->HasNote(ScAddress(2, 0, 0))); + + ScPostIt* pNote = pDoc->GetNote(ScAddress(2, 0, 0)); + CPPUNIT_ASSERT(pNote); + CPPUNIT_ASSERT_EQUAL(true, pNote->IsCaptionShown()); +} + +CPPUNIT_TEST_FIXTURE(ScFiltersTest3, testTdf139612) +{ + createScDoc("ods/tdf139612.ods"); + ScDocument* pDoc = getScDoc(); + + ScDocShell* pDocSh = getScDocShell(); + pDocSh->DoHardRecalc(); + + // Without the fix in place, this test would have failed with + // - Expected: 1 + // - Actual : 0 + CPPUNIT_ASSERT_EQUAL(1.0, pDoc->GetValue(ScAddress(1, 15, 0))); +} + +CPPUNIT_TEST_FIXTURE(ScFiltersTest3, testTdf144740) +{ + createScDoc("ods/tdf144740.ods"); + ScDocument* pDoc = getScDoc(); + + // Without the fix in place, this test would have failed with + // - Expected: 1 + // - Actual : 2 + CPPUNIT_ASSERT_EQUAL(1.0, pDoc->GetValue(ScAddress(1, 0, 0))); +} + +CPPUNIT_TEST_FIXTURE(ScFiltersTest3, testTdf146722) +{ + createScDoc("ods/tdf146722.ods"); + ScDocument* pDoc = getScDoc(); + + // Without the fix in place, this test would have failed with + // - Expected: 3 + // - Actual : 0 + CPPUNIT_ASSERT_EQUAL(3.0, pDoc->GetValue(ScAddress(1, 2, 0))); +} + +CPPUNIT_TEST_FIXTURE(ScFiltersTest3, testTdf147014) +{ + createScDoc("xlsx/tdf147014.xlsx"); + uno::Reference xDoc(mxComponent, uno::UNO_QUERY_THROW); + uno::Reference xIA(xDoc->getSheets(), uno::UNO_QUERY_THROW); + uno::Reference xDrawPageSupplier(xIA->getByIndex(0), + uno::UNO_QUERY_THROW); + xIA.set(xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY_THROW); + // The sheet has a single shape, without the fix it was not imported, except in 32-bit builds + CPPUNIT_ASSERT_EQUAL_MESSAGE("Shape not imported", static_cast(1), xIA->getCount()); +} + +CPPUNIT_TEST_FIXTURE(ScFiltersTest3, testTdf139763ShapeAnchor) +{ + createScDoc("xlsx/tdf139763ShapeAnchor.xlsx"); + + // 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* pDoc = getScDoc(); + + CPPUNIT_ASSERT_MESSAGE("There should be at least one sheet.", pDoc->GetTableCount() > 0); + + ScDrawLayer* pDrawLayer = pDoc->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(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)); +} + +CPPUNIT_TEST_FIXTURE(ScFiltersTest3, testAutofilterNamedRangesXLSX) +{ + createScDoc("xlsx/autofilternamedrange.xlsx"); + + ScDocument* pDoc = getScDoc(); + const ScDBData* pDBData = pDoc->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 = pDoc->GetRangeAtBlock(aRange, aPosStr, &bSheetLocal); + CPPUNIT_ASSERT(!pRData); + CPPUNIT_ASSERT_EQUAL(OUString(), aPosStr); +} + +CPPUNIT_TEST_FIXTURE(ScFiltersTest3, testInvalidBareBiff5) +{ + createScDoc("xls/tdf144732.xls"); + ScDocument* pDoc = getScDoc(); + pDoc->CalcAll(); + + // Check that we import the contents from such file, as Excel does + CPPUNIT_ASSERT_EQUAL(SCTAB(1), pDoc->GetTableCount()); + + // Row 1 + ScAddress aPos(0, 0, 0); + CPPUNIT_ASSERT_EQUAL(CELLTYPE_VALUE, pDoc->GetCellType(aPos)); + CPPUNIT_ASSERT_EQUAL(1.0, pDoc->GetValue(aPos)); + aPos.IncCol(); + CPPUNIT_ASSERT_EQUAL(CELLTYPE_VALUE, pDoc->GetCellType(aPos)); + CPPUNIT_ASSERT_EQUAL(2.0, pDoc->GetValue(aPos)); + aPos.IncCol(); + CPPUNIT_ASSERT_EQUAL(CELLTYPE_VALUE, pDoc->GetCellType(aPos)); + CPPUNIT_ASSERT_EQUAL(3.0, pDoc->GetValue(aPos)); + aPos.IncCol(); + CPPUNIT_ASSERT_EQUAL(OUString(), pDoc->GetString(aPos)); + + // Row 2 + aPos = ScAddress(0, 1, 0); + CPPUNIT_ASSERT_EQUAL(CELLTYPE_FORMULA, pDoc->GetCellType(aPos)); + OUString sFormula = pDoc->GetFormula(aPos.Col(), aPos.Row(), aPos.Tab()); + CPPUNIT_ASSERT_EQUAL(OUString("=TRUE()"), sFormula); + CPPUNIT_ASSERT_EQUAL(1.0, pDoc->GetValue(aPos)); + aPos.IncCol(); + CPPUNIT_ASSERT_EQUAL(CELLTYPE_FORMULA, pDoc->GetCellType(aPos)); + sFormula = pDoc->GetFormula(aPos.Col(), aPos.Row(), aPos.Tab()); + CPPUNIT_ASSERT_EQUAL(OUString("=FALSE()"), sFormula); + CPPUNIT_ASSERT_EQUAL(0.0, pDoc->GetValue(aPos)); + aPos.IncCol(); + CPPUNIT_ASSERT_EQUAL(CELLTYPE_NONE, pDoc->GetCellType(aPos)); + CPPUNIT_ASSERT_EQUAL(OUString(), pDoc->GetString(aPos)); + aPos.IncCol(); + CPPUNIT_ASSERT_EQUAL(CELLTYPE_STRING, pDoc->GetCellType(aPos)); + CPPUNIT_ASSERT_EQUAL(OUString(u"sheetjs"), pDoc->GetString(aPos)); + + // Row 3 + aPos = ScAddress(0, 2, 0); + CPPUNIT_ASSERT_EQUAL(CELLTYPE_STRING, pDoc->GetCellType(aPos)); + CPPUNIT_ASSERT_EQUAL(OUString(u"foo bar"), pDoc->GetString(aPos)); + aPos.IncCol(); + CPPUNIT_ASSERT_EQUAL(CELLTYPE_STRING, pDoc->GetCellType(aPos)); + CPPUNIT_ASSERT_EQUAL(OUString(u"baz"), pDoc->GetString(aPos)); + aPos.IncCol(); + CPPUNIT_ASSERT_EQUAL(CELLTYPE_VALUE, pDoc->GetCellType(aPos)); + CPPUNIT_ASSERT_EQUAL(41689.4375, pDoc->GetValue(aPos)); + aPos.IncCol(); + CPPUNIT_ASSERT_EQUAL(CELLTYPE_STRING, pDoc->GetCellType(aPos)); + CPPUNIT_ASSERT_EQUAL(OUString(u"0.3"), pDoc->GetString(aPos)); + + // Row 4 + aPos = ScAddress(0, 3, 0); + CPPUNIT_ASSERT_EQUAL(CELLTYPE_STRING, pDoc->GetCellType(aPos)); + CPPUNIT_ASSERT_EQUAL(OUString(u"baz"), pDoc->GetString(aPos)); + aPos.IncCol(); + CPPUNIT_ASSERT_EQUAL(CELLTYPE_NONE, pDoc->GetCellType(aPos)); + CPPUNIT_ASSERT_EQUAL(OUString(), pDoc->GetString(aPos)); + aPos.IncCol(); + CPPUNIT_ASSERT_EQUAL(CELLTYPE_STRING, pDoc->GetCellType(aPos)); + CPPUNIT_ASSERT_EQUAL(OUString(u"_"), pDoc->GetString(aPos)); + aPos.IncCol(); + CPPUNIT_ASSERT_EQUAL(CELLTYPE_VALUE, pDoc->GetCellType(aPos)); + CPPUNIT_ASSERT_EQUAL(3.14159, pDoc->GetValue(aPos)); + + // Row 5 + aPos = ScAddress(0, 4, 0); + CPPUNIT_ASSERT_EQUAL(CELLTYPE_STRING, pDoc->GetCellType(aPos)); + CPPUNIT_ASSERT_EQUAL(OUString(u"hidden"), pDoc->GetString(aPos)); + aPos.IncCol(); + CPPUNIT_ASSERT_EQUAL(CELLTYPE_NONE, pDoc->GetCellType(aPos)); + CPPUNIT_ASSERT_EQUAL(OUString(), pDoc->GetString(aPos)); + aPos.IncCol(); + CPPUNIT_ASSERT_EQUAL(CELLTYPE_NONE, pDoc->GetCellType(aPos)); + CPPUNIT_ASSERT_EQUAL(OUString(), pDoc->GetString(aPos)); + aPos.IncCol(); + CPPUNIT_ASSERT_EQUAL(CELLTYPE_NONE, pDoc->GetCellType(aPos)); + CPPUNIT_ASSERT_EQUAL(OUString(), pDoc->GetString(aPos)); + + // Row 6 + aPos = ScAddress(0, 5, 0); + CPPUNIT_ASSERT_EQUAL(CELLTYPE_STRING, pDoc->GetCellType(aPos)); + CPPUNIT_ASSERT_EQUAL(OUString(u"visible"), pDoc->GetString(aPos)); + aPos.IncCol(); + CPPUNIT_ASSERT_EQUAL(CELLTYPE_NONE, pDoc->GetCellType(aPos)); + CPPUNIT_ASSERT_EQUAL(OUString(), pDoc->GetString(aPos)); + aPos.IncCol(); + CPPUNIT_ASSERT_EQUAL(CELLTYPE_NONE, pDoc->GetCellType(aPos)); + CPPUNIT_ASSERT_EQUAL(OUString(), pDoc->GetString(aPos)); + aPos.IncCol(); + CPPUNIT_ASSERT_EQUAL(CELLTYPE_NONE, pDoc->GetCellType(aPos)); + CPPUNIT_ASSERT_EQUAL(OUString(), pDoc->GetString(aPos)); +} + +CPPUNIT_TEST_FIXTURE(ScFiltersTest3, testTooManyColsRows) +{ + // The intentionally doc has cells beyond our MAXROW/MAXCOL, so there + // should be a warning on load. + createScDoc("ods/too-many-cols-rows.ods", /*pPassword*/ nullptr, /*bCheckWarningError*/ false); + + ScDocShell* pDocSh = getScDocShell(); + SfxMedium* pMedium = pDocSh->GetMedium(); + + CPPUNIT_ASSERT(pMedium->GetWarningError() == SCWARN_IMPORT_ROW_OVERFLOW + || pMedium->GetWarningError() == SCWARN_IMPORT_COLUMN_OVERFLOW); + + createScDoc("xlsx/too-many-cols-rows.xlsx", /*pPassword*/ nullptr, + /*bCheckWarningError*/ false); + + pDocSh = getScDocShell(); + pMedium = pDocSh->GetMedium(); + + CPPUNIT_ASSERT(pMedium->GetWarningError() == SCWARN_IMPORT_ROW_OVERFLOW + || pMedium->GetWarningError() == SCWARN_IMPORT_COLUMN_OVERFLOW); +} + +CPPUNIT_TEST_FIXTURE(ScFiltersTest3, testTdf83671_SmartArt_import) +{ + // The example doc contains a diagram (SmartArt). Such should be imported as group object. + // Error was, that the background shape had size zero and the diagram shapes where missing. + + // Make sure SmartArt is loaded as group shape + bool bUseGroup = officecfg::Office::Common::Filter::Microsoft::Import::SmartArtToShapes::get(); + if (!bUseGroup) + { + std::shared_ptr pChange( + comphelper::ConfigurationChanges::create()); + officecfg::Office::Common::Filter::Microsoft::Import::SmartArtToShapes::set(true, pChange); + pChange->commit(); + } + + // Get document and shape + createScDoc("xlsx/tdf83671_SmartArt_import.xlsx"); + ScDocument* pDoc = getScDoc(); + ScDrawLayer* pDrawLayer = pDoc->GetDrawLayer(); + SdrPage* pPage = pDrawLayer->GetPage(0); + SdrObject* pObj = pPage->GetObj(0); + + // Check that it is a group shape with 4 children + CPPUNIT_ASSERT(pObj->IsGroupObject()); + SdrObjList* pChildren = pObj->getChildrenOfSdrObject(); + CPPUNIT_ASSERT_EQUAL(size_t(4), pChildren->GetObjCount()); + + // The background shape should have about 60mm x 42mm size. + // Without fix its size was zero. + tools::Rectangle aBackground = pChildren->GetObj(0)->GetLogicRect(); + CPPUNIT_ASSERT_DOUBLES_EQUAL(sal_Int32(6000), aBackground.getOpenWidth(), 10); + CPPUNIT_ASSERT_DOUBLES_EQUAL(sal_Int32(4200), aBackground.getOpenHeight(), 10); + + if (!bUseGroup) + { + std::shared_ptr pChange( + comphelper::ConfigurationChanges::create()); + officecfg::Office::Common::Filter::Microsoft::Import::SmartArtToShapes::set(false, pChange); + pChange->commit(); + } +} + +CPPUNIT_TEST_FIXTURE(ScFiltersTest3, testTdf83671_SmartArt_import2) +{ + // The example doc contains a diagram (SmartArt). Such should be imported as group object. + // With conversion enabled, the group contains only a graphic. Error was, that the shape + // had size 100x100 Hmm and position 0|0. + + // Make sure SmartArt is loaded with converting to metafile + bool bUseGroup = officecfg::Office::Common::Filter::Microsoft::Import::SmartArtToShapes::get(); + if (bUseGroup) + { + std::shared_ptr pChange( + comphelper::ConfigurationChanges::create()); + officecfg::Office::Common::Filter::Microsoft::Import::SmartArtToShapes::set(false, pChange); + pChange->commit(); + } + + // Get document and shape + createScDoc("xlsx/tdf83671_SmartArt_import.xlsx"); + ScDocument* pDoc = getScDoc(); + ScDrawLayer* pDrawLayer = pDoc->GetDrawLayer(); + SdrPage* pPage = pDrawLayer->GetPage(0); + SdrObject* pObj = pPage->GetObj(0); + + // Check that it is a group shape with 1 child + CPPUNIT_ASSERT(pObj->IsGroupObject()); + SdrObjList* pChildren = pObj->getChildrenOfSdrObject(); + CPPUNIT_ASSERT_EQUAL(size_t(1), pChildren->GetObjCount()); + + // The child shape should have about 60mm x 42mm size and position 1164|1270. + // Without fix its size was 100x100 and position 0|0. + tools::Rectangle aBackground = pChildren->GetObj(0)->GetLogicRect(); + CPPUNIT_ASSERT_DOUBLES_EQUAL(sal_Int32(6000), aBackground.getOpenWidth(), 10); + CPPUNIT_ASSERT_DOUBLES_EQUAL(sal_Int32(4200), aBackground.getOpenHeight(), 10); + CPPUNIT_ASSERT_EQUAL(Point(1164, 1270), aBackground.GetPos()); + + if (bUseGroup) + { + std::shared_ptr pChange( + comphelper::ConfigurationChanges::create()); + officecfg::Office::Common::Filter::Microsoft::Import::SmartArtToShapes::set(true, pChange); + pChange->commit(); + } +} + +CPPUNIT_TEST_FIXTURE(ScFiltersTest3, testTdf151818_SmartArtFontColor) +{ + // The document contains a SmartArt where the color for the texts in the shapes is given by + // the theme. + // Error was, that the theme was not considered and therefore the text was white. + + // Make sure it is not loaded as metafile but with single shapes. + bool bUseGroup = officecfg::Office::Common::Filter::Microsoft::Import::SmartArtToShapes::get(); + if (!bUseGroup) + { + std::shared_ptr pChange( + comphelper::ConfigurationChanges::create()); + officecfg::Office::Common::Filter::Microsoft::Import::SmartArtToShapes::set(true, pChange); + pChange->commit(); + } + + // Get document and shape in SmartArt object + createScDoc("xlsx/tdf151818_SmartartThemeFontColor.xlsx"); + uno::Reference xDoc(mxComponent, uno::UNO_QUERY_THROW); + uno::Reference xPage(xDoc->getDrawPages()->getByIndex(0), + uno::UNO_QUERY_THROW); + uno::Reference xSmartArt(xPage->getByIndex(0), uno::UNO_QUERY_THROW); + // shape 0 is the background shape without text + uno::Reference xShape(xSmartArt->getByIndex(1), uno::UNO_QUERY); + + // text color + uno::Reference xText(xShape->getText(), uno::UNO_QUERY); + uno::Reference xPara(xText->createEnumeration()->nextElement(), + uno::UNO_QUERY); + uno::Reference xPortion(xPara->createEnumeration()->nextElement(), + uno::UNO_QUERY); + sal_Int32 nActualColor{ 0 }; + xPortion->getPropertyValue("CharColor") >>= nActualColor; + // Without fix the test would have failed with: + // - Expected: 4478058 (0x44546A) + // - Actual : 16777215 (0xFFFFFF), that is text was white + CPPUNIT_ASSERT_EQUAL(sal_Int32(0x44546A), nActualColor); + + // clrScheme. For map between name in xlsx and index from CharColorTheme see + // oox::drawingml::Color::getSchemeColorIndex() + // Without fix the color scheme was "lt1" (1) but should be "dk2" (2). + CPPUNIT_ASSERT_EQUAL(sal_Int16(2), + xPortion->getPropertyValue("CharColorTheme").get()); + + if (!bUseGroup) + { + std::shared_ptr pChange( + comphelper::ConfigurationChanges::create()); + officecfg::Office::Common::Filter::Microsoft::Import::SmartArtToShapes::set(false, pChange); + pChange->commit(); + } +} + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */