[Libreoffice-commits] core.git: sc/CppunitTest_sc_uicalc.mk sc/qa

Xisco Fauli (via logerrit) logerrit at kemper.freedesktop.org
Tue Feb 2 23:10:06 UTC 2021


 sc/CppunitTest_sc_uicalc.mk          |    1 
 sc/qa/unit/uicalc/data/tdf100582.xls |binary
 sc/qa/unit/uicalc/uicalc.cxx         |   72 +++++++++++++++++++++++++++++++++++
 3 files changed, 73 insertions(+)

New commits:
commit 8c355246fdfb3fa021d213d65f8fb24dc01843ee
Author:     Xisco Fauli <xiscofauli at libreoffice.org>
AuthorDate: Tue Feb 2 22:02:41 2021 +0100
Commit:     Xisco Fauli <xiscofauli at libreoffice.org>
CommitDate: Wed Feb 3 00:09:17 2021 +0100

    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 at libreoffice.org>

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
new file mode 100644
index 000000000000..24886a2fe605
Binary files /dev/null and b/sc/qa/unit/uicalc/data/tdf100582.xls differ
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");


More information about the Libreoffice-commits mailing list