sc/qa/unit/uicalc/data/tdf145640.ods |binary
 sc/qa/unit/uicalc/uicalc.cxx         |   36 +++++++++++++++++++++++++++++++++++
 2 files changed, 36 insertions(+)

New commits:
commit 499b6d679866a952e40e16ce16f997ecb5ec5853
Author:     Xisco Fauli <xiscofa...@libreoffice.org>
AuthorDate: Mon Nov 15 13:26:58 2021 +0100
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Mon Nov 15 16:42:12 2021 +0100

    tdf#145640: sc_uicalc: Add unittest
    
    Change-Id: Iba1723704b3fafdd52e32ae0f5f2cc986ba2ba16
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/125245
    Tested-by: Jenkins
    Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org>

diff --git a/sc/qa/unit/uicalc/data/tdf145640.ods 
b/sc/qa/unit/uicalc/data/tdf145640.ods
new file mode 100644
index 000000000000..34b501792723
Binary files /dev/null and b/sc/qa/unit/uicalc/data/tdf145640.ods differ
diff --git a/sc/qa/unit/uicalc/uicalc.cxx b/sc/qa/unit/uicalc/uicalc.cxx
index a06dd66b5117..72b1c6ea1c7b 100644
--- a/sc/qa/unit/uicalc/uicalc.cxx
+++ b/sc/qa/unit/uicalc/uicalc.cxx
@@ -355,6 +355,42 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf100582)
     pMod->SetInputOptions(aInputOption);
 }
 
+CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf145640)
+{
+    ScModelObj* pModelObj = createDoc("tdf145640.ods");
+    ScDocument* pDoc = pModelObj->GetDocument();
+    CPPUNIT_ASSERT(pDoc);
+
+    // Enable sorting with update reference
+    ScModule* pMod = SC_MOD();
+    ScInputOptions aInputOption = pMod->GetInputOptions();
+    bool bOldStatus = aInputOption.GetSortRefUpdate();
+    aInputOption.SetSortRefUpdate(true);
+    pMod->SetInputOptions(aInputOption);
+
+    goToCell("A2:F17");
+
+    dispatchCommand(mxComponent, ".uno:SortDescending", {});
+    Scheduler::ProcessEventsToIdle();
+
+    CPPUNIT_ASSERT_EQUAL(OUString("=SUM(A15:B15:C15:D15:E15:F15)"), 
pDoc->GetFormula(6, 3, 0));
+
+    // Without the fix in place, this test would have failed with
+    // - Expected: 10
+    // - Actual  : 0
+    CPPUNIT_ASSERT_EQUAL(10.0, pDoc->GetValue(ScAddress(6, 3, 0)));
+
+    dispatchCommand(mxComponent, ".uno:Undo", {});
+    Scheduler::ProcessEventsToIdle();
+
+    CPPUNIT_ASSERT_EQUAL(OUString("=SUM(A4:B4:C4:D4:E4:F4)"), 
pDoc->GetFormula(6, 3, 0));
+    CPPUNIT_ASSERT_EQUAL(10.0, pDoc->GetValue(ScAddress(6, 3, 0)));
+
+    // Restore previous status
+    aInputOption.SetSortRefUpdate(bOldStatus);
+    pMod->SetInputOptions(aInputOption);
+}
+
 CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf97215)
 {
     ScModelObj* pModelObj = createDoc("tdf97215.ods");

Reply via email to