diff options
author | Xisco Fauli <xiscofauli@libreoffice.org> | 2021-02-02 22:02:41 +0100 |
---|---|---|
committer | Xisco Fauli <xiscofauli@libreoffice.org> | 2021-02-03 00:09:17 +0100 |
commit | 8c355246fdfb3fa021d213d65f8fb24dc01843ee (patch) | |
tree | 6d9f199788dfa235bc4645b227a6195a00229a3d | |
parent | 65129e0bc5abfe7afc612eb46f1434e627265a7d (diff) |
tdf#100582: sc_uicalc: Add unittest
Change-Id: Icad48707d4806cb1fbc2de160059c199fceeda78
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/110334
Tested-by: Jenkins
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
-rw-r--r-- | sc/CppunitTest_sc_uicalc.mk | 1 | ||||
-rw-r--r-- | sc/qa/unit/uicalc/data/tdf100582.xls | bin | 0 -> 9216 bytes | |||
-rw-r--r-- | sc/qa/unit/uicalc/uicalc.cxx | 72 |
3 files changed, 73 insertions, 0 deletions
diff --git a/sc/CppunitTest_sc_uicalc.mk b/sc/CppunitTest_sc_uicalc.mk index 4c1f99d87ddd..82bfb875b05e 100644 --- a/sc/CppunitTest_sc_uicalc.mk +++ b/sc/CppunitTest_sc_uicalc.mk @@ -27,6 +27,7 @@ $(eval $(call gb_CppunitTest_use_libraries,sc_uicalc, \ test \ tl \ unotest \ + utl \ vcl \ )) diff --git a/sc/qa/unit/uicalc/data/tdf100582.xls b/sc/qa/unit/uicalc/data/tdf100582.xls Binary files differnew file mode 100644 index 000000000000..24886a2fe605 --- /dev/null +++ b/sc/qa/unit/uicalc/data/tdf100582.xls diff --git a/sc/qa/unit/uicalc/uicalc.cxx b/sc/qa/unit/uicalc/uicalc.cxx index 5c42f7c61db4..bb038104a60f 100644 --- a/sc/qa/unit/uicalc/uicalc.cxx +++ b/sc/qa/unit/uicalc/uicalc.cxx @@ -11,6 +11,7 @@ #include <unotest/macros_test.hxx> #include <LibreOfficeKit/LibreOfficeKitEnums.h> #include <svx/svdpage.hxx> +#include <unotools/tempfile.hxx> #include <vcl/keycodes.hxx> #include <vcl/scheduler.hxx> @@ -39,6 +40,8 @@ public: virtual void tearDown() override; ScModelObj* createDoc(const char* pName); + ScModelObj* saveAndReload(css::uno::Reference<css::lang::XComponent>& xComponent, + const OUString& rFilter); void goToCell(const OUString& rCell); void insertStringToCell(ScModelObj& rModelObj, const OUString& rCell, const std::string& rStr, bool bIsArray = false); @@ -140,6 +143,75 @@ ScModelObj* ScUiCalcTest::createDoc(const char* pName) return pModelObj; } +ScModelObj* ScUiCalcTest::saveAndReload(css::uno::Reference<css::lang::XComponent>& xComponent, + const OUString& rFilter) +{ + utl::TempFile aTempFile; + aTempFile.EnableKillingFile(); + css::uno::Sequence<css::beans::PropertyValue> aArgs(1); + aArgs[0].Name = "FilterName"; + aArgs[0].Value <<= rFilter; + css::uno::Reference<css::frame::XStorable> xStorable(xComponent, css::uno::UNO_QUERY_THROW); + xStorable->storeAsURL(aTempFile.GetURL(), aArgs); + css::uno::Reference<css::util::XCloseable> xCloseable(xComponent, css::uno::UNO_QUERY_THROW); + xCloseable->close(true); + + mxComponent = loadFromDesktop(aTempFile.GetURL(), "com.sun.star.sheet.SpreadsheetDocument"); + + ScModelObj* pModelObj = dynamic_cast<ScModelObj*>(mxComponent.get()); + CPPUNIT_ASSERT(pModelObj); + return pModelObj; +} + +CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf100582) +{ + ScModelObj* pModelObj = createDoc("tdf100582.xls"); + ScDocument* pDoc = pModelObj->GetDocument(); + CPPUNIT_ASSERT(pDoc); + + // Disable replace cell warning + ScModule* pMod = SC_MOD(); + ScInputOptions aInputOption = pMod->GetInputOptions(); + bool bOldStatus = aInputOption.GetReplaceCellsWarn(); + aInputOption.SetReplaceCellsWarn(false); + pMod->SetInputOptions(aInputOption); + + goToCell("C10"); + + ScDocument aClipDoc(SCDOCMODE_CLIP); + ScDocShell::GetViewData()->GetView()->CopyToClip(&aClipDoc, false, false, false, false); + Scheduler::ProcessEventsToIdle(); + + goToCell("C10:H14"); + + ScDocShell::GetViewData()->GetView()->PasteFromClip(InsertDeleteFlags::ALL, &aClipDoc); + Scheduler::ProcessEventsToIdle(); + + pModelObj = saveAndReload(mxComponent, "MS Excel 97"); + pDoc = pModelObj->GetDocument(); + CPPUNIT_ASSERT(pDoc); + + OUString aFormula; + pDoc->GetFormula(3, 10, 0, aFormula); + + // Without the fix in place, this test would have failed with + // - Expected: {=SUM(($B$3:$B$7=$B11)*(D$3:D$7))} + //- Actual : + CPPUNIT_ASSERT_EQUAL(OUString("{=SUM(($B$3:$B$7=$B11)*(D$3:D$7))}"), aFormula); + pDoc->GetFormula(4, 10, 0, aFormula); + CPPUNIT_ASSERT_EQUAL(OUString("{=SUM(($B$3:$B$7=$B11)*(E$3:E$7))}"), aFormula); + pDoc->GetFormula(5, 10, 0, aFormula); + CPPUNIT_ASSERT_EQUAL(OUString("{=SUM(($B$3:$B$7=$B11)*(F$3:F$7))}"), aFormula); + pDoc->GetFormula(6, 10, 0, aFormula); + CPPUNIT_ASSERT_EQUAL(OUString("{=SUM(($B$3:$B$7=$B11)*(G$3:G$7))}"), aFormula); + pDoc->GetFormula(7, 10, 0, aFormula); + CPPUNIT_ASSERT_EQUAL(OUString("{=SUM(($B$3:$B$7=$B11)*(H$3:H$7))}"), aFormula); + + // Restore previous status + aInputOption.SetReplaceCellsWarn(bOldStatus); + pMod->SetInputOptions(aInputOption); +} + CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf97215) { ScModelObj* pModelObj = createDoc("tdf97215.ods"); |