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

Kohei Yoshida kohei.yoshida at collabora.com
Thu Feb 9 14:06:06 UTC 2017


 sc/qa/unit/ucalc.hxx         |    2 +
 sc/qa/unit/ucalc_formula.cxx |   46 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 48 insertions(+)

New commits:
commit 99d35740a1dfa580986b02cacbe7854caa998708
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date:   Wed Feb 8 23:18:10 2017 -0500

    tdf#103890: Add unit test for this.
    
    Change-Id: I93a17f90b7e6ff9aa5133401b2630d4b4e0cced5
    Reviewed-on: https://gerrit.libreoffice.org/34050
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Kohei Yoshida <libreoffice at kohei.us>

diff --git a/sc/qa/unit/ucalc.hxx b/sc/qa/unit/ucalc.hxx
index 9852426..fc956db 100644
--- a/sc/qa/unit/ucalc.hxx
+++ b/sc/qa/unit/ucalc.hxx
@@ -151,6 +151,7 @@ public:
     void testFormulaRefUpdateNameCopySheetCheckTab( SCTAB Tab, bool bCheckNames );
     void testFormulaRefUpdateNameDelete();
     void testFormulaRefUpdateValidity();
+    void testTokenArrayRefUpdateMove();
     void testMultipleOperations();
     void testFuncCOLUMN();
     void testFuncCOUNT();
@@ -528,6 +529,7 @@ public:
     CPPUNIT_TEST(testFormulaRefUpdateNameCopySheet);
     CPPUNIT_TEST(testFormulaRefUpdateNameDelete);
     CPPUNIT_TEST(testFormulaRefUpdateValidity);
+    CPPUNIT_TEST(testTokenArrayRefUpdateMove);
     CPPUNIT_TEST(testMultipleOperations);
     CPPUNIT_TEST(testFuncCOLUMN);
     CPPUNIT_TEST(testFuncCOUNT);
diff --git a/sc/qa/unit/ucalc_formula.cxx b/sc/qa/unit/ucalc_formula.cxx
index 8b862bd..3dfe0c7 100644
--- a/sc/qa/unit/ucalc_formula.cxx
+++ b/sc/qa/unit/ucalc_formula.cxx
@@ -23,6 +23,7 @@
 #include "docfunc.hxx"
 #include "paramisc.hxx"
 #include "tokenstringcontext.hxx"
+#include <refupdatecontext.hxx>
 #include "dbdata.hxx"
 #include "scmatrix.hxx"
 #include <validat.hxx>
@@ -3330,6 +3331,51 @@ void Test::testFormulaRefUpdateValidity()
     m_pDoc->DeleteTab(0);
 }
 
+void Test::testTokenArrayRefUpdateMove()
+{
+    m_pDoc->InsertTab(0, "Sheet1");
+    m_pDoc->InsertTab(1, "Sheet2");
+
+    ScAddress aPos(0,0,0); // A1
+
+    sc::TokenStringContext aCxt(m_pDoc, m_pDoc->GetGrammar());
+
+    // Emulate cell movement from Sheet1.C3 to Sheet2.C3.
+    sc::RefUpdateContext aRefCxt(*m_pDoc);
+    aRefCxt.meMode = URM_MOVE;
+    aRefCxt.maRange = ScAddress(2,2,1); // C3 on Sheet2.
+    aRefCxt.mnTabDelta = -1;
+
+    std::vector<OUString> aTests = {
+        "B1*C1",
+        "SUM(B1:C1)"
+    };
+
+    // Since C3 is not referenced in any of the above formulas, moving C3 from
+    // Sheet1 to Sheet2 should NOT change the displayed formula string at all.
+
+    for (const OUString& aTest : aTests)
+    {
+        ScCompiler aComp(m_pDoc, aPos);
+        aComp.SetGrammar(m_pDoc->GetGrammar());
+        std::unique_ptr<ScTokenArray> pArray(aComp.CompileString(aTest));
+
+        OUString aStr = pArray->CreateString(aCxt, aPos);
+
+        CPPUNIT_ASSERT_EQUAL(aTest, aStr);
+
+        // This formula cell isn't moving its position. The displayed formula
+        // string should not change.
+        pArray->AdjustReferenceOnMove(aRefCxt, aPos, aPos);
+
+        aStr = pArray->CreateString(aCxt, aPos);
+        CPPUNIT_ASSERT_EQUAL(aTest, aStr);
+    }
+
+    m_pDoc->DeleteTab(1);
+    m_pDoc->DeleteTab(0);
+}
+
 void Test::testMultipleOperations()
 {
     m_pDoc->InsertTab(0, "MultiOp");


More information about the Libreoffice-commits mailing list