summaryrefslogtreecommitdiff
path: root/sc/qa/unit
diff options
context:
space:
mode:
authorKohei Yoshida <kohei.yoshida@collabora.com>2014-07-30 12:35:26 -0400
committerKohei Yoshida <kohei.yoshida@collabora.com>2014-07-31 09:05:18 -0400
commit85f8f8f8589af3c404339c0f78021a7fe21cdfcd (patch)
treedfcfbe5fb0ed4a59cb741e40b559277c12701f08 /sc/qa/unit
parent6a2ea81ca1622d2c2ad55bea8ddc28167fcc2794 (diff)
fdo#78555: Write test for this first.
Change-Id: I01f7ca80d8d2ac4c3b5f262625cc54a27cf4327a
Diffstat (limited to 'sc/qa/unit')
-rw-r--r--sc/qa/unit/ucalc.hxx2
-rw-r--r--sc/qa/unit/ucalc_sharedformula.cxx68
2 files changed, 70 insertions, 0 deletions
diff --git a/sc/qa/unit/ucalc.hxx b/sc/qa/unit/ucalc.hxx
index b067a22b732d..e4a6b8c0b000 100644
--- a/sc/qa/unit/ucalc.hxx
+++ b/sc/qa/unit/ucalc.hxx
@@ -290,6 +290,7 @@ public:
void testSharedFormulas();
void testSharedFormulasRefUpdate();
void testSharedFormulasRefUpdateMove();
+ void testSharedFormulasRefUpdateMove2();
void testSharedFormulasRefUpdateRange();
void testSharedFormulasRefUpdateExternal();
void testSharedFormulasInsertRow();
@@ -499,6 +500,7 @@ public:
CPPUNIT_TEST(testSharedFormulas);
CPPUNIT_TEST(testSharedFormulasRefUpdate);
CPPUNIT_TEST(testSharedFormulasRefUpdateMove);
+ CPPUNIT_TEST(testSharedFormulasRefUpdateMove2);
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 5fa1dfad862c..8c49076b2601 100644
--- a/sc/qa/unit/ucalc_sharedformula.cxx
+++ b/sc/qa/unit/ucalc_sharedformula.cxx
@@ -459,6 +459,74 @@ void Test::testSharedFormulasRefUpdateMove()
m_pDoc->DeleteTab(0);
}
+void Test::testSharedFormulasRefUpdateMove2()
+{
+ sc::AutoCalcSwitch aACSwitch(*m_pDoc, false); // turn auto calc off this time.
+ FormulaGrammarSwitch aFGSwitch(m_pDoc, formula::FormulaGrammar::GRAM_ENGLISH_XL_R1C1);
+
+ m_pDoc->InsertTab(0, "Test");
+
+ // Set values in B2:B3, and E2:E3.
+ for (SCROW i = 1; i <= 2; ++i)
+ {
+ m_pDoc->SetValue(ScAddress(1,i,0), i);
+ m_pDoc->SetValue(ScAddress(4,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(1.0, m_pDoc->GetValue(ScAddress(4,1,0)));
+ CPPUNIT_ASSERT_EQUAL(2.0, m_pDoc->GetValue(ScAddress(4,2,0)));
+
+ // Set formulas in C2:C3 that reference B2:B4 individually, and F2:F3 to E2:E3.
+ for (SCROW i = 1; i <= 2; ++i)
+ {
+ m_pDoc->SetString(ScAddress(2,i,0), "=RC[-1]");
+ m_pDoc->SetString(ScAddress(5,i,0), "=RC[-1]");
+ }
+
+ m_pDoc->CalcFormulaTree(); // calculate manually.
+
+ // 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(1.0, m_pDoc->GetValue(ScAddress(5,1,0)));
+ CPPUNIT_ASSERT_EQUAL(2.0, m_pDoc->GetValue(ScAddress(5,2,0)));
+
+ // Move B2:C3 to C3:D4.
+ bool bMoved = getDocShell().GetDocFunc().MoveBlock(
+ ScRange(1,1,0,2,2,0), ScAddress(2,2,0), true, true, false, true);
+ CPPUNIT_ASSERT(bMoved);
+
+ // Make sure the range has been moved.
+ CPPUNIT_ASSERT_EQUAL(1.0, m_pDoc->GetValue(ScAddress(2,2,0)));
+ CPPUNIT_ASSERT_EQUAL(2.0, m_pDoc->GetValue(ScAddress(2,3,0)));
+
+ // The formula cells should retain their results even with auto calc off
+ // and without recalculation.
+ CPPUNIT_ASSERT_EQUAL(1.0, m_pDoc->GetValue(ScAddress(3,2,0)));
+ CPPUNIT_ASSERT_EQUAL(2.0, m_pDoc->GetValue(ScAddress(3,3,0)));
+
+ // And these formulas in F2:F3 are unaffected, therefore should not change.
+ CPPUNIT_ASSERT_EQUAL(1.0, m_pDoc->GetValue(ScAddress(5,1,0)));
+ CPPUNIT_ASSERT_EQUAL(2.0, m_pDoc->GetValue(ScAddress(5,2,0)));
+
+ SfxUndoManager* pUndoMgr = m_pDoc->GetUndoManager();
+ CPPUNIT_ASSERT(pUndoMgr);
+
+ // Undo the move.
+ pUndoMgr->Undo();
+
+ // Check the formula results. The results should still be intact.
+ 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(1.0, m_pDoc->GetValue(ScAddress(5,1,0)));
+ CPPUNIT_ASSERT_EQUAL(2.0, m_pDoc->GetValue(ScAddress(5,2,0)));
+
+ m_pDoc->DeleteTab(0);
+}
+
void Test::testSharedFormulasRefUpdateRange()
{
m_pDoc->InsertTab(0, "Test");