diff options
author | Kohei Yoshida <kohei.yoshida@collabora.com> | 2014-05-06 15:23:57 -0400 |
---|---|---|
committer | Kohei Yoshida <kohei.yoshida@collabora.com> | 2014-05-06 15:26:02 -0400 |
commit | 48631bde1ccdbd618e5892b7050822b61b843332 (patch) | |
tree | 3a29565b9850aefc5b01194fcd90aa77c759f917 | |
parent | 166c282e98ded4822425e034b1002d7fe447f405 (diff) |
fdo#77647: Test for reference adjustment on column insertion.
Change-Id: Ic95ff3892efbfc003ae9976b4fba4129de11bbef
-rw-r--r-- | sc/qa/unit/ucalc.cxx | 9 | ||||
-rw-r--r-- | sc/qa/unit/ucalc.hxx | 8 | ||||
-rw-r--r-- | sc/qa/unit/ucalc_formula.cxx | 52 |
3 files changed, 53 insertions, 16 deletions
diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx index 97e652126820..d764673ebba5 100644 --- a/sc/qa/unit/ucalc.cxx +++ b/sc/qa/unit/ucalc.cxx @@ -62,6 +62,7 @@ #include <patattr.hxx> #include <docpool.hxx> #include <globalnames.hxx> +#include <inputopt.hxx> #include "formula/IFunctionDescription.hxx" @@ -6139,6 +6140,14 @@ ScUndoPaste* Test::createUndoPaste(ScDocShell& rDocSh, const ScRange& rRange, Sc &rDocSh, rRange, aMarkData, pUndoDoc, NULL, IDF_ALL, pRefUndoData, false); } +void Test::setExpandRefs(bool bExpand) +{ + ScModule* pMod = SC_MOD(); + ScInputOptions aOpt = pMod->GetInputOptions(); + aOpt.SetExpandRefs(bExpand); + pMod->SetInputOptions(aOpt); +} + CPPUNIT_TEST_SUITE_REGISTRATION(Test); CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/sc/qa/unit/ucalc.hxx b/sc/qa/unit/ucalc.hxx index f812630558f4..dbe84e71b28d 100644 --- a/sc/qa/unit/ucalc.hxx +++ b/sc/qa/unit/ucalc.hxx @@ -47,6 +47,12 @@ public: static void pasteFromClip(ScDocument* pDestDoc, const ScRange& rDestRange, ScDocument* pClipDoc); static ScUndoPaste* createUndoPaste(ScDocShell& rDocSh, const ScRange& rRange, ScDocument* pUndoDoc); + /** + * Enable or disable expand reference options which controls how + * references in formula are expanded when inserting rows or columns. + */ + static void setExpandRefs(bool bExpand); + template<size_t _Size> static ScRange insertRangeData(ScDocument* pDoc, const ScAddress& rPos, const char* aData[][_Size], size_t nRowCount) { @@ -119,6 +125,7 @@ public: void testFormulaRefUpdateRange(); void testFormulaRefUpdateSheets(); void testFormulaRefUpdateInsertRows(); + void testFormulaRefUpdateInsertColumns(); void testFormulaRefUpdateMove(); void testFormulaRefUpdateMoveUndo(); void testFormulaRefUpdateNamedExpression(); @@ -375,6 +382,7 @@ public: CPPUNIT_TEST(testFormulaRefUpdateRange); CPPUNIT_TEST(testFormulaRefUpdateSheets); CPPUNIT_TEST(testFormulaRefUpdateInsertRows); + CPPUNIT_TEST(testFormulaRefUpdateInsertColumns); CPPUNIT_TEST(testFormulaRefUpdateMove); CPPUNIT_TEST(testFormulaRefUpdateMoveUndo); CPPUNIT_TEST(testFormulaRefUpdateNamedExpression); diff --git a/sc/qa/unit/ucalc_formula.cxx b/sc/qa/unit/ucalc_formula.cxx index efe73a0f3e61..3f75db8389d2 100644 --- a/sc/qa/unit/ucalc_formula.cxx +++ b/sc/qa/unit/ucalc_formula.cxx @@ -17,7 +17,6 @@ #include "scopetools.hxx" #include "formulacell.hxx" #include "formulagroup.hxx" -#include "inputopt.hxx" #include "scmod.hxx" #include "docsh.hxx" #include "docfunc.hxx" @@ -1036,10 +1035,7 @@ void Test::testFormulaRefUpdateRange() sc::AutoCalcSwitch aACSwitch(*m_pDoc, true); // turn auto calc on. - ScModule* pMod = SC_MOD(); - ScInputOptions aOpt = pMod->GetInputOptions(); - aOpt.SetExpandRefs(false); - pMod->SetInputOptions(aOpt); + setExpandRefs(false); // Set values to B2:C5. m_pDoc->SetValue(ScAddress(1,1,0), 1); @@ -1166,7 +1162,7 @@ void Test::testFormulaRefUpdateRange() clearRange(m_pDoc, ScRange(0,0,0,20,20,0)); // Disable expansion of range reference on insertion in adjacent areas. - m_pDoc->SetExpandRefs(false); + setExpandRefs(false); // Fill C2:D3 with values. m_pDoc->SetValue(ScAddress(2,1,0), 1); @@ -1251,8 +1247,7 @@ void Test::testFormulaRefUpdateRange() clearRange(m_pDoc, ScRange(0,0,0,20,20,0)); // Turn edge expansion on. - aOpt.SetExpandRefs(true); - pMod->SetInputOptions(aOpt); + setExpandRefs(true); // Fill C6:D7 with values. m_pDoc->SetValue(ScAddress(2,5,0), 1); @@ -1479,10 +1474,7 @@ void Test::testFormulaRefUpdateSheets() void Test::testFormulaRefUpdateInsertRows() { - ScModule* pMod = SC_MOD(); - ScInputOptions aOpt = pMod->GetInputOptions(); - aOpt.SetExpandRefs(false); - pMod->SetInputOptions(aOpt); + setExpandRefs(false); sc::AutoCalcSwitch aACSwitch(*m_pDoc, true); // turn auto calc on. m_pDoc->InsertTab(0, "Formula"); @@ -1537,6 +1529,37 @@ void Test::testFormulaRefUpdateInsertRows() m_pDoc->DeleteTab(0); } +void Test::testFormulaRefUpdateInsertColumns() +{ + sc::AutoCalcSwitch aACSwitch(*m_pDoc, true); // turn auto calc on. + setExpandRefs(false); + + m_pDoc->InsertTab(0, "Formula"); + + // Set values in B1:B3. + m_pDoc->SetValue(ScAddress(1,0,0), 1.0); + m_pDoc->SetValue(ScAddress(1,1,0), 2.0); + m_pDoc->SetValue(ScAddress(1,2,0), 3.0); + + // Reference them in B4. + m_pDoc->SetString(ScAddress(1,3,0), "=SUM(B1:B3)"); + CPPUNIT_ASSERT_EQUAL(6.0, m_pDoc->GetValue(ScAddress(1,3,0))); + + // Inert columns over A:B. + ScMarkData aMark; + aMark.SelectOneTable(0); + ScDocFunc& rFunc = getDocShell().GetDocFunc(); + rFunc.InsertCells(ScRange(0,0,0,1,MAXROW,0), &aMark, INS_INSCOLS, false, true, false); + + // Now, the original column B has moved to column D. + if (!checkFormula(*m_pDoc, ScAddress(3,3,0), "SUM(D1:D3)")) + CPPUNIT_FAIL("Wrong formula in D4 after column insertion."); + + CPPUNIT_ASSERT_EQUAL(6.0, m_pDoc->GetValue(ScAddress(3,3,0))); + + m_pDoc->DeleteTab(0); +} + void Test::testFormulaRefUpdateMove() { m_pDoc->InsertTab(0, "Sheet1"); @@ -1982,10 +2005,7 @@ void Test::testFormulaRefUpdateNamedExpressionMove() void Test::testFormulaRefUpdateNamedExpressionExpandRef() { - ScModule* pMod = SC_MOD(); - ScInputOptions aOpt = pMod->GetInputOptions(); - aOpt.SetExpandRefs(true); // turn on automatic range expansion. - pMod->SetInputOptions(aOpt); + setExpandRefs(true); sc::AutoCalcSwitch aACSwitch(*m_pDoc, true); // turn auto calc on. |