[Libreoffice-commits] core.git: 2 commits - sc/qa sc/source

Kohei Yoshida kohei.yoshida at collabora.com
Sun Oct 26 14:46:18 PDT 2014


 sc/qa/unit/ucalc.hxx           |    2 
 sc/qa/unit/ucalc_sort.cxx      |  108 +++++++++++++++++++++++++++++++++++++++++
 sc/source/core/data/table3.cxx |    7 +-
 sc/source/ui/undo/undosort.cxx |    3 -
 4 files changed, 116 insertions(+), 4 deletions(-)

New commits:
commit ae5ac4807cab26de2a149162576d2ef927cc8326
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date:   Sun Oct 26 14:43:47 2014 -0700

    fdo#85215: Write test for this.
    
    Change-Id: Ibe959201541ce6ad84540eba93ac9235dca91f40

diff --git a/sc/qa/unit/ucalc.hxx b/sc/qa/unit/ucalc.hxx
index 472779c..9eaa709 100644
--- a/sc/qa/unit/ucalc.hxx
+++ b/sc/qa/unit/ucalc.hxx
@@ -364,6 +364,7 @@ public:
     void testSortRefUpdate3();
     void testSortRefUpdate4();
     void testSortRefUpdate5();
+    void testSortRefUpdate6();
     void testSortOutOfPlaceResult();
     void testSortPartialFormulaGroup();
 
@@ -555,6 +556,7 @@ public:
     CPPUNIT_TEST(testSortRefUpdate3);
     CPPUNIT_TEST(testSortRefUpdate4);
     CPPUNIT_TEST(testSortRefUpdate5);
+    CPPUNIT_TEST(testSortRefUpdate6);
     CPPUNIT_TEST(testSortOutOfPlaceResult);
     CPPUNIT_TEST(testSortPartialFormulaGroup);
     CPPUNIT_TEST(testShiftCells);
diff --git a/sc/qa/unit/ucalc_sort.cxx b/sc/qa/unit/ucalc_sort.cxx
index ce6b9b3..d0997c3 100644
--- a/sc/qa/unit/ucalc_sort.cxx
+++ b/sc/qa/unit/ucalc_sort.cxx
@@ -1329,6 +1329,114 @@ void Test::testSortRefUpdate5()
     m_pDoc->DeleteTab(0);
 }
 
+void Test::testSortRefUpdate6()
+{
+    SortRefNoUpdateSetter aUpdateSet;
+
+    sc::AutoCalcSwitch aACSwitch(*m_pDoc, true); // turn auto calc on.
+    m_pDoc->InsertTab(0, "Sort");
+
+    const char* aData[][3] = {
+        { "Order", "Value", "1" },
+        { "9", "1", "=C1+B2" },
+        { "1", "2", "=C2+B3" },
+        { "8", "3", "=C3+B4" },
+    };
+
+    ScAddress aPos(0,0,0);
+    ScRange aDataRange = insertRangeData(m_pDoc, aPos, aData, SAL_N_ELEMENTS(aData));
+    CPPUNIT_ASSERT(aDataRange.aStart == aPos);
+
+    {
+        // Expected output table content.  0 = empty cell
+        const char* aOutputCheck[][3] = {
+            { "Order", "Value", "1" },
+            { "9", "1", "2" },
+            { "1", "2", "4" },
+            { "8", "3", "7" },
+        };
+
+        bool bSuccess = checkOutput<3>(m_pDoc, aDataRange, aOutputCheck, "Initial value");
+        CPPUNIT_ASSERT_MESSAGE("Table output check failed", bSuccess);
+    }
+
+    ScDBDocFunc aFunc(getDocShell());
+
+    // Sort A1:C4.
+    m_pDoc->SetAnonymousDBData(
+        0, new ScDBData(STR_DB_LOCAL_NONAME, 0, 0, 0, 2, 3));
+
+    // Sort A1:A6 by column A (with a row header).
+    ScSortParam aSortData;
+    aSortData.nCol1 = 0;
+    aSortData.nCol2 = 2;
+    aSortData.nRow1 = 0;
+    aSortData.nRow2 = 3;
+    aSortData.bHasHeader = true;
+    aSortData.maKeyState[0].bDoSort = true;
+    aSortData.maKeyState[0].nField = 0;
+    aSortData.maKeyState[0].bAscending = true;
+    bool bSorted = aFunc.Sort(0, aSortData, true, true, true);
+    CPPUNIT_ASSERT(bSorted);
+
+    {
+        // Expected output table content.  0 = empty cell
+        const char* aOutputCheck[][3] = {
+            { "Order", "Value", "1" },
+            { "1", "2", "3" },
+            { "8", "3", "6" },
+            { "9", "1", "7" },
+        };
+
+        bool bSuccess = checkOutput<3>(m_pDoc, aDataRange, aOutputCheck, "Sorted without reference update");
+        CPPUNIT_ASSERT_MESSAGE("Table output check failed", bSuccess);
+    }
+
+    // Make sure that the formulas in C2:C4 are not adjusted.
+    if (!checkFormula(*m_pDoc, ScAddress(2,1,0), "C1+B2"))
+        CPPUNIT_FAIL("Wrong formula!");
+    if (!checkFormula(*m_pDoc, ScAddress(2,2,0), "C2+B3"))
+        CPPUNIT_FAIL("Wrong formula!");
+    if (!checkFormula(*m_pDoc, ScAddress(2,3,0), "C3+B4"))
+        CPPUNIT_FAIL("Wrong formula!");
+
+    // Undo and check.
+    SfxUndoManager* pUndoMgr = m_pDoc->GetUndoManager();
+    CPPUNIT_ASSERT(pUndoMgr);
+
+    pUndoMgr->Undo();
+
+    {
+        // Expected output table content.  0 = empty cell
+        const char* aOutputCheck[][3] = {
+            { "Order", "Value", "1" },
+            { "9", "1", "2" },
+            { "1", "2", "4" },
+            { "8", "3", "7" },
+        };
+
+        bool bSuccess = checkOutput<3>(m_pDoc, aDataRange, aOutputCheck, "After undo");
+        CPPUNIT_ASSERT_MESSAGE("Table output check failed", bSuccess);
+    }
+
+    // Redo and check.
+    pUndoMgr->Redo();
+    {
+        // Expected output table content.  0 = empty cell
+        const char* aOutputCheck[][3] = {
+            { "Order", "Value", "1" },
+            { "1", "2", "3" },
+            { "8", "3", "6" },
+            { "9", "1", "7" },
+        };
+
+        bool bSuccess = checkOutput<3>(m_pDoc, aDataRange, aOutputCheck, "Sorted without reference update");
+        CPPUNIT_ASSERT_MESSAGE("Table output check failed", bSuccess);
+    }
+
+    m_pDoc->DeleteTab(0);
+}
+
 void Test::testSortOutOfPlaceResult()
 {
     m_pDoc->InsertTab(0, "Sort");
commit 10fc138307afb4b39baddb0d56eb8e986e5d29ea
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date:   Sun Oct 26 14:43:14 2014 -0700

    fdo#85215: Don't adjust references wrt cell position when disabled.
    
    Change-Id: Ie1a12cc189bcb66fad59ea9901ac0dc95bb68788

diff --git a/sc/source/core/data/table3.cxx b/sc/source/core/data/table3.cxx
index e41458b..3e8250a 100644
--- a/sc/source/core/data/table3.cxx
+++ b/sc/source/core/data/table3.cxx
@@ -854,8 +854,11 @@ void ScTable::SortReorderByRow(
                     ScAddress aOldPos = rCell.maCell.mpFormula->aPos;
 
                     ScFormulaCell* pNew = rCell.maCell.mpFormula->Clone( aCellPos, SC_CLONECELL_DEFAULT);
-                    pNew->CopyAllBroadcasters(*rCell.maCell.mpFormula);
-                    pNew->GetCode()->AdjustReferenceOnMovedOrigin(aOldPos, aCellPos);
+                    if (pArray->IsUpdateRefs())
+                    {
+                        pNew->CopyAllBroadcasters(*rCell.maCell.mpFormula);
+                        pNew->GetCode()->AdjustReferenceOnMovedOrigin(aOldPos, aCellPos);
+                    }
 
                     rCellStore.push_back(pNew);
                 }
diff --git a/sc/source/ui/undo/undosort.cxx b/sc/source/ui/undo/undosort.cxx
index fbd10ae..ead54d4 100644
--- a/sc/source/ui/undo/undosort.cxx
+++ b/sc/source/ui/undo/undosort.cxx
@@ -46,8 +46,7 @@ void UndoSort::Execute( bool bUndo )
 
     ScUndoUtil::MarkSimpleBlock(pDocShell, maParam.maSortRange);
 
-    pDocShell->PostPaint(maParam.maSortRange, PAINT_GRID);
-    pDocShell->PostDataChanged();
+    rDoc.SetDirty(maParam.maSortRange);
     if (!aParam.mbUpdateRefs)
         rDoc.BroadcastCells(aParam.maSortRange, SC_HINT_DATACHANGED);
 }


More information about the Libreoffice-commits mailing list