summaryrefslogtreecommitdiff
path: root/sc/qa/unit
diff options
context:
space:
mode:
authorKohei Yoshida <kohei.yoshida@collabora.com>2014-07-30 10:04:17 -0400
committerKohei Yoshida <kohei.yoshida@collabora.com>2014-07-30 11:04:49 -0400
commitd0125712494ac0be512aa5e3fd7315e0cab2b323 (patch)
tree5d51e44343d7f45ab491f849598395a65329119a /sc/qa/unit
parentff209b1446c7923c9e8675611a392c9d280d1440 (diff)
fdo#80501: Write test for this first.
Change-Id: I43c0018f445394387ef28590b56ca38344e61c11
Diffstat (limited to 'sc/qa/unit')
-rw-r--r--sc/qa/unit/ucalc.hxx2
-rw-r--r--sc/qa/unit/ucalc_sharedformula.cxx56
2 files changed, 58 insertions, 0 deletions
diff --git a/sc/qa/unit/ucalc.hxx b/sc/qa/unit/ucalc.hxx
index 471cf823acef..b067a22b732d 100644
--- a/sc/qa/unit/ucalc.hxx
+++ b/sc/qa/unit/ucalc.hxx
@@ -289,6 +289,7 @@ public:
void testSearchCells();
void testSharedFormulas();
void testSharedFormulasRefUpdate();
+ void testSharedFormulasRefUpdateMove();
void testSharedFormulasRefUpdateRange();
void testSharedFormulasRefUpdateExternal();
void testSharedFormulasInsertRow();
@@ -497,6 +498,7 @@ public:
CPPUNIT_TEST(testSearchCells);
CPPUNIT_TEST(testSharedFormulas);
CPPUNIT_TEST(testSharedFormulasRefUpdate);
+ CPPUNIT_TEST(testSharedFormulasRefUpdateMove);
CPPUNIT_TEST(testSharedFormulasRefUpdateRange);
CPPUNIT_TEST(testSharedFormulasRefUpdateExternal);
CPPUNIT_TEST(testSharedFormulasInsertRow);
diff --git a/sc/qa/unit/ucalc_sharedformula.cxx b/sc/qa/unit/ucalc_sharedformula.cxx
index b4babd666958..5fa1dfad862c 100644
--- a/sc/qa/unit/ucalc_sharedformula.cxx
+++ b/sc/qa/unit/ucalc_sharedformula.cxx
@@ -403,6 +403,62 @@ void Test::testSharedFormulasRefUpdate()
m_pDoc->DeleteTab(0);
}
+void Test::testSharedFormulasRefUpdateMove()
+{
+ sc::AutoCalcSwitch aACSwitch(*m_pDoc, true); // turn on auto calc.
+ FormulaGrammarSwitch aFGSwitch(m_pDoc, formula::FormulaGrammar::GRAM_ENGLISH_XL_R1C1);
+
+ m_pDoc->InsertTab(0, "Test");
+
+ // Set values in B2:B4.
+ for (SCROW i = 1; i <= 3; ++i)
+ m_pDoc->SetValue(ScAddress(1,i,0), i);
+
+ // Make sure the values are really there.
+ CPPUNIT_ASSERT_EQUAL(1.0, m_pDoc->GetValue(ScAddress(1,1,0)));
+ CPPUNIT_ASSERT_EQUAL(2.0, m_pDoc->GetValue(ScAddress(1,2,0)));
+ CPPUNIT_ASSERT_EQUAL(3.0, m_pDoc->GetValue(ScAddress(1,3,0)));
+
+ // Set formulas in C2:C4 that reference B2:B4 individually.
+ for (SCROW i = 1; i <= 3; ++i)
+ m_pDoc->SetString(ScAddress(2,i,0), "=RC[-1]");
+
+ // Check the formula results.
+ CPPUNIT_ASSERT_EQUAL(1.0, m_pDoc->GetValue(ScAddress(2,1,0)));
+ CPPUNIT_ASSERT_EQUAL(2.0, m_pDoc->GetValue(ScAddress(2,2,0)));
+ CPPUNIT_ASSERT_EQUAL(3.0, m_pDoc->GetValue(ScAddress(2,3,0)));
+
+ // Move B2:B4 to B1:B3.
+ bool bMoved = getDocShell().GetDocFunc().MoveBlock(ScRange(1,1,0,1,3,0), ScAddress(1,0,0), true, true, false, true);
+ CPPUNIT_ASSERT(bMoved);
+
+ // Make sure the values have been moved for real.
+ CPPUNIT_ASSERT_EQUAL(1.0, m_pDoc->GetValue(ScAddress(1,0,0)));
+ CPPUNIT_ASSERT_EQUAL(2.0, m_pDoc->GetValue(ScAddress(1,1,0)));
+ CPPUNIT_ASSERT_EQUAL(3.0, m_pDoc->GetValue(ScAddress(1,2,0)));
+
+ // The formulas should have been adjusted for the move.
+ CPPUNIT_ASSERT(checkFormula(*m_pDoc, ScAddress(2,1,0), "R[-1]C[-1]"));
+ CPPUNIT_ASSERT(checkFormula(*m_pDoc, ScAddress(2,2,0), "R[-1]C[-1]"));
+ CPPUNIT_ASSERT(checkFormula(*m_pDoc, ScAddress(2,3,0), "R[-1]C[-1]"));
+
+ SfxUndoManager* pUndoMgr = m_pDoc->GetUndoManager();
+ CPPUNIT_ASSERT(pUndoMgr);
+ pUndoMgr->Undo();
+
+ // The values should have moved back.
+ CPPUNIT_ASSERT_EQUAL(1.0, m_pDoc->GetValue(ScAddress(1,1,0)));
+ CPPUNIT_ASSERT_EQUAL(2.0, m_pDoc->GetValue(ScAddress(1,2,0)));
+ CPPUNIT_ASSERT_EQUAL(3.0, m_pDoc->GetValue(ScAddress(1,3,0)));
+
+ // And the formulas should have been re-adjusted to their original references.
+ CPPUNIT_ASSERT(checkFormula(*m_pDoc, ScAddress(2,1,0), "RC[-1]"));
+ CPPUNIT_ASSERT(checkFormula(*m_pDoc, ScAddress(2,2,0), "RC[-1]"));
+ CPPUNIT_ASSERT(checkFormula(*m_pDoc, ScAddress(2,3,0), "RC[-1]"));
+
+ m_pDoc->DeleteTab(0);
+}
+
void Test::testSharedFormulasRefUpdateRange()
{
m_pDoc->InsertTab(0, "Test");