diff options
author | Kohei Yoshida <kohei.yoshida@collabora.com> | 2017-02-08 23:18:10 -0500 |
---|---|---|
committer | Kohei Yoshida <libreoffice@kohei.us> | 2017-02-09 14:05:43 +0000 |
commit | 99d35740a1dfa580986b02cacbe7854caa998708 (patch) | |
tree | 6b0e140f4caa5f85b748ab77e1b9dc897294cfe7 | |
parent | bf8d4fb60da5e583b3a90639af45b901e19cb5aa (diff) |
tdf#103890: Add unit test for this.
Change-Id: I93a17f90b7e6ff9aa5133401b2630d4b4e0cced5
Reviewed-on: https://gerrit.libreoffice.org/34050
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Kohei Yoshida <libreoffice@kohei.us>
-rw-r--r-- | sc/qa/unit/ucalc.hxx | 2 | ||||
-rw-r--r-- | sc/qa/unit/ucalc_formula.cxx | 46 |
2 files changed, 48 insertions, 0 deletions
diff --git a/sc/qa/unit/ucalc.hxx b/sc/qa/unit/ucalc.hxx index 98524267a47e..fc956db49113 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 8b862bd551a8..3dfe0c72df99 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"); |