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

Kohei Yoshida kohei.yoshida at collabora.com
Thu Jan 16 11:36:46 PST 2014


 sc/qa/unit/helper/qahelper.cxx      |    2 
 sc/qa/unit/ucalc.hxx                |    2 
 sc/qa/unit/ucalc_sharedformula.cxx  |   81 ++++++++++++++++++++++++++++++++++++
 sc/source/core/data/formulacell.cxx |   17 +++++++
 4 files changed, 101 insertions(+), 1 deletion(-)

New commits:
commit 8c3b6b34cea6212f4f3f266cc92e76de97d0aa55
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date:   Thu Jan 16 12:50:48 2014 -0500

    fdo#73655: Write unit test for this.
    
    Change-Id: I0409e3c482d8a833672f41b1398333e5181847af

diff --git a/sc/qa/unit/helper/qahelper.cxx b/sc/qa/unit/helper/qahelper.cxx
index 7666c34..773b779 100644
--- a/sc/qa/unit/helper/qahelper.cxx
+++ b/sc/qa/unit/helper/qahelper.cxx
@@ -420,7 +420,7 @@ bool checkFormula(ScDocument& rDoc, const ScAddress& rPos, const char* pExpected
         return false;
     }
 
-    OUString aFormula = toString(rDoc, rPos, *pCode);
+    OUString aFormula = toString(rDoc, rPos, *pCode, rDoc.GetGrammar());
     if (aFormula != OUString::createFromAscii(pExpected))
     {
         cerr << "Formula '" << pExpected << "' expected, but '" << aFormula << "' found" << endl;
diff --git a/sc/qa/unit/ucalc.hxx b/sc/qa/unit/ucalc.hxx
index 1f6f202..1dbfbbc 100644
--- a/sc/qa/unit/ucalc.hxx
+++ b/sc/qa/unit/ucalc.hxx
@@ -246,6 +246,7 @@ public:
     void testSharedFormulasRefUpdate();
     void testSharedFormulasRefUpdateRange();
     void testSharedFormulasDeleteRows();
+    void testSharedFormulasRefUpdateMoveSheets();
     void testSharedFormulasCopyPaste();
     void testFormulaPosition();
 
@@ -396,6 +397,7 @@ public:
     CPPUNIT_TEST(testSharedFormulasRefUpdate);
     CPPUNIT_TEST(testSharedFormulasRefUpdateRange);
     CPPUNIT_TEST(testSharedFormulasDeleteRows);
+    CPPUNIT_TEST(testSharedFormulasRefUpdateMoveSheets);
     CPPUNIT_TEST(testSharedFormulasCopyPaste);
     CPPUNIT_TEST(testFormulaPosition);
     CPPUNIT_TEST(testJumpToPrecedentsDependents);
diff --git a/sc/qa/unit/ucalc_sharedformula.cxx b/sc/qa/unit/ucalc_sharedformula.cxx
index b1bdea2..b4ce117 100644
--- a/sc/qa/unit/ucalc_sharedformula.cxx
+++ b/sc/qa/unit/ucalc_sharedformula.cxx
@@ -515,7 +515,88 @@ void Test::testSharedFormulasDeleteRows()
     CPPUNIT_ASSERT_MESSAGE("1,6 must be a shared formula cell.", pFC && pFC->IsShared());
     CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(6), pFC->GetSharedTopRow());
     CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(8), pFC->GetSharedLength());
+}
+
+void Test::testSharedFormulasRefUpdateMoveSheets()
+{
+    m_pDoc->InsertTab(0, "Sheet1");
+    m_pDoc->InsertTab(1, "Sheet2");
+    m_pDoc->InsertTab(2, "Sheet3");
+
+    sc::AutoCalcSwitch aACSwitch(*m_pDoc, true); // make sure auto calc is on.
+
+    // Switch to R1C1 for ease of repeated formula insertions.
+    FormulaGrammarSwitch aFGSwitch(m_pDoc, formula::FormulaGrammar::GRAM_ENGLISH_XL_R1C1);
+
+    // Fill numbers in A1:A8 on Sheet2.
+    for (SCROW i = 0; i <= 7; ++i)
+        m_pDoc->SetValue(ScAddress(0,i,1), i+1);
+
+    // Fill formula cells A1:A8 on Sheet1, to refer to the same cell address on Sheet2.
+    for (SCROW i = 0; i <= 7; ++i)
+        m_pDoc->SetString(ScAddress(0,i,0), "=Sheet2!RC");
+
+    // Check the results.
+    for (SCROW i = 0; i <= 7; ++i)
+        CPPUNIT_ASSERT_EQUAL(static_cast<double>(i+1), m_pDoc->GetValue(ScAddress(0,i,0)));
+
+    // Move Sheet3 to the leftmost position before Sheet1.
+    m_pDoc->MoveTab(2, 0);
+
+    // Check sheet names.
+    std::vector<OUString> aTabNames = m_pDoc->GetAllTableNames();
+    CPPUNIT_ASSERT_MESSAGE("There should be at least 3 sheets.", aTabNames.size() >= 3);
+    CPPUNIT_ASSERT_EQUAL(OUString("Sheet3"), aTabNames[0]);
+    CPPUNIT_ASSERT_EQUAL(OUString("Sheet1"), aTabNames[1]);
+    CPPUNIT_ASSERT_EQUAL(OUString("Sheet2"), aTabNames[2]);
+
+    // Check the results again on Sheet1.
+    for (SCROW i = 0; i <= 7; ++i)
+    {
+        CPPUNIT_ASSERT_EQUAL(static_cast<double>(i+1), m_pDoc->GetValue(ScAddress(0,i,1)));
+        if (!checkFormula(*m_pDoc, ScAddress(0,i,1), "Sheet2!RC"))
+            CPPUNIT_FAIL("Wrong formula expression.");
+    }
+
+    // Insert a new sheet at the left end.
+    m_pDoc->InsertTab(0, "Sheet4");
+
+    // Check sheet names.
+    aTabNames = m_pDoc->GetAllTableNames();
+    CPPUNIT_ASSERT_MESSAGE("There should be at least 4 sheets.", aTabNames.size() >= 4);
+    CPPUNIT_ASSERT_EQUAL(OUString("Sheet4"), aTabNames[0]);
+    CPPUNIT_ASSERT_EQUAL(OUString("Sheet3"), aTabNames[1]);
+    CPPUNIT_ASSERT_EQUAL(OUString("Sheet1"), aTabNames[2]);
+    CPPUNIT_ASSERT_EQUAL(OUString("Sheet2"), aTabNames[3]);
+
+    // Check the results again on Sheet1.
+    for (SCROW i = 0; i <= 7; ++i)
+    {
+        CPPUNIT_ASSERT_EQUAL(static_cast<double>(i+1), m_pDoc->GetValue(ScAddress(0,i,2)));
+        if (!checkFormula(*m_pDoc, ScAddress(0,i,2), "Sheet2!RC"))
+            CPPUNIT_FAIL("Wrong formula expression.");
+    }
+
+    // Delete Sheet4.
+    m_pDoc->DeleteTab(0);
+
+    // Check sheet names.
+    aTabNames = m_pDoc->GetAllTableNames();
+    CPPUNIT_ASSERT_MESSAGE("There should be at least 3 sheets.", aTabNames.size() >= 3);
+    CPPUNIT_ASSERT_EQUAL(OUString("Sheet3"), aTabNames[0]);
+    CPPUNIT_ASSERT_EQUAL(OUString("Sheet1"), aTabNames[1]);
+    CPPUNIT_ASSERT_EQUAL(OUString("Sheet2"), aTabNames[2]);
+
+    // Check the results again on Sheet1.
+    for (SCROW i = 0; i <= 7; ++i)
+    {
+        CPPUNIT_ASSERT_EQUAL(static_cast<double>(i+1), m_pDoc->GetValue(ScAddress(0,i,1)));
+        if (!checkFormula(*m_pDoc, ScAddress(0,i,1), "Sheet2!RC"))
+            CPPUNIT_FAIL("Wrong formula expression.");
+    }
 
+    m_pDoc->DeleteTab(2);
+    m_pDoc->DeleteTab(1);
     m_pDoc->DeleteTab(0);
 }
 
commit 982a03d4e2baf4ca7e78c79014389d9b23e200d1
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date:   Thu Jan 16 12:49:14 2014 -0500

    fdo#73655: Don't adjust formula tokens on non-top shared formula cells.
    
    Only adjust tokens for non-shared formula cells and shared formuls cells
    that are the top of their respective shared groups.
    
    Change-Id: I9cd57653602c97504a802001947a28c4d03368a5

diff --git a/sc/source/core/data/formulacell.cxx b/sc/source/core/data/formulacell.cxx
index 4837e3c..14ccad4 100644
--- a/sc/source/core/data/formulacell.cxx
+++ b/sc/source/core/data/formulacell.cxx
@@ -2799,6 +2799,8 @@ bool ScFormulaCell::UpdateReference(
 
 void ScFormulaCell::UpdateInsertTab( sc::RefUpdateInsertTabContext& rCxt )
 {
+    // Adjust tokens only when it's not grouped or grouped top cell.
+    bool bAdjustCode = !mxGroup || mxGroup->mpTopCell == this;
     bool bPosChanged = (rCxt.mnInsertPos <= aPos.Tab());
     pCode->Reset();
     if (pDocument->IsClipOrUndo() || !pCode->GetNextReferenceRPN())
@@ -2815,6 +2817,9 @@ void ScFormulaCell::UpdateInsertTab( sc::RefUpdateInsertTabContext& rCxt )
     if (bPosChanged)
         aPos.IncTab(rCxt.mnSheets);
 
+    if (!bAdjustCode)
+        return;
+
     sc::RefUpdateResult aRes = pCode->AdjustReferenceOnInsertedTab(rCxt, aOldPos);
     if (aRes.mbNameModified)
         // Re-compile after new sheet(s) have been inserted.
@@ -2825,6 +2830,8 @@ void ScFormulaCell::UpdateInsertTab( sc::RefUpdateInsertTabContext& rCxt )
 
 bool ScFormulaCell::UpdateDeleteTab( sc::RefUpdateDeleteTabContext& rCxt )
 {
+    // Adjust tokens only when it's not grouped or grouped top cell.
+    bool bAdjustCode = !mxGroup || mxGroup->mpTopCell == this;
     bool bPosChanged = (aPos.Tab() >= rCxt.mnDeletePos + rCxt.mnSheets);
     pCode->Reset();
     if (pDocument->IsClipOrUndo() || !pCode->GetNextReferenceRPN())
@@ -2840,6 +2847,9 @@ bool ScFormulaCell::UpdateDeleteTab( sc::RefUpdateDeleteTabContext& rCxt )
     if (bPosChanged)
         aPos.IncTab(-1*rCxt.mnSheets);
 
+    if (!bAdjustCode)
+        return false;
+
     sc::RefUpdateResult aRes = pCode->AdjustReferenceOnDeletedTab(rCxt, aOldPos);
     if (aRes.mbNameModified)
         // Re-compile after sheet(s) have been deleted.
@@ -2850,6 +2860,9 @@ bool ScFormulaCell::UpdateDeleteTab( sc::RefUpdateDeleteTabContext& rCxt )
 
 void ScFormulaCell::UpdateMoveTab( sc::RefUpdateMoveTabContext& rCxt, SCTAB nTabNo )
 {
+    // Adjust tokens only when it's not grouped or grouped top cell.
+    bool bAdjustCode = !mxGroup || mxGroup->mpTopCell == this;
+
     pCode->Reset();
     if (!pCode->GetNextReferenceRPN() || pDocument->IsClipOrUndo())
     {
@@ -2863,6 +2876,10 @@ void ScFormulaCell::UpdateMoveTab( sc::RefUpdateMoveTabContext& rCxt, SCTAB nTab
     aPos.SetTab(nTabNo);
 
     // no StartListeningTo because pTab[nTab] not yet correct!
+
+    if (!bAdjustCode)
+        return;
+
     sc::RefUpdateResult aRes = pCode->AdjustReferenceOnMovedTab(rCxt, aOldPos);
     if (aRes.mbNameModified)
         // Re-compile after sheet(s) have been deleted.


More information about the Libreoffice-commits mailing list