summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKohei Yoshida <kohei.yoshida@collabora.com>2014-07-28 19:16:12 -0400
committerKohei Yoshida <kohei.yoshida@collabora.com>2014-07-28 22:08:22 -0400
commita0b9200eed928ac81d798bd59aed69ed6d470bac (patch)
tree9121c7b801ae00cd3189e0dd4dc9e47f6b35aec5
parentab409bf7fbe8a9af75fdd253a760ffbaf92a8376 (diff)
fdo#79578: Write test for this first.
Change-Id: I46ccf0954f9397779244132488d93f3162cf04d6
-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 3197990d9281..880fde6919f1 100644
--- a/sc/qa/unit/ucalc.hxx
+++ b/sc/qa/unit/ucalc.hxx
@@ -299,6 +299,7 @@ public:
void testSharedFormulaInsertColumn();
void testSharedFormulaMoveBlock();
void testSharedFormulaUpdateOnNamedRangeChange();
+ void testSharedFormulaUpdateOnDBChange();
void testFormulaPosition();
void testMixData();
@@ -503,6 +504,7 @@ public:
CPPUNIT_TEST(testSharedFormulasCopyPaste);
CPPUNIT_TEST(testSharedFormulaInsertColumn);
CPPUNIT_TEST(testSharedFormulaUpdateOnNamedRangeChange);
+ CPPUNIT_TEST(testSharedFormulaUpdateOnDBChange);
CPPUNIT_TEST(testFormulaPosition);
CPPUNIT_TEST(testMixData);
CPPUNIT_TEST(testJumpToPrecedentsDependents);
diff --git a/sc/qa/unit/ucalc_sharedformula.cxx b/sc/qa/unit/ucalc_sharedformula.cxx
index 06c09b05c929..b4babd666958 100644
--- a/sc/qa/unit/ucalc_sharedformula.cxx
+++ b/sc/qa/unit/ucalc_sharedformula.cxx
@@ -16,9 +16,11 @@
#include "undoblk.hxx"
#include "scopetools.hxx"
#include <docfunc.hxx>
+#include <dbdocfun.hxx>
#include <tokenarray.hxx>
#include <tokenstringcontext.hxx>
#include <globalnames.hxx>
+#include <dbdata.hxx>
#include <svl/sharedstring.hxx>
@@ -1307,4 +1309,70 @@ void Test::testSharedFormulaUpdateOnNamedRangeChange()
m_pDoc->DeleteTab(0);
}
+void Test::testSharedFormulaUpdateOnDBChange()
+{
+ sc::AutoCalcSwitch aACSwitch(*m_pDoc, true); // turn on auto calc.
+
+ m_pDoc->InsertTab(0, "RangeTest");
+
+ // Put 1, 2, 3, 4 in A1:A4.
+ for (SCROW i = 0; i <= 3; ++i)
+ m_pDoc->SetValue(ScAddress(0,i,0), (i+1));
+
+ ScDBCollection* pDBs = m_pDoc->GetDBCollection();
+ CPPUNIT_ASSERT_MESSAGE("Failed to fetch DB collection object.", pDBs);
+
+ // Define database range 'MyRange' for A1:A2.
+ ScDBData* pData = new ScDBData("MyRange", 0, 0, 0, 0, 1);
+ bool bInserted = pDBs->getNamedDBs().insert(pData);
+ CPPUNIT_ASSERT_MESSAGE("Failed to insert a new database range.", bInserted);
+
+ // Insert in C2:C4 a group of formula cells that reference MyRange.
+ for (SCROW i = 1; i <= 3; ++i)
+ m_pDoc->SetString(ScAddress(2,i,0), "=SUM(MyRange)");
+
+ // Make sure C2:C4 is a formula group.
+ const ScFormulaCell* pFC = m_pDoc->GetFormulaCell(ScAddress(2,1,0));
+ CPPUNIT_ASSERT(pFC);
+ CPPUNIT_ASSERT(pFC->IsSharedTop());
+ CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(3), pFC->GetSharedLength());
+
+ // Check the initial formula results.
+ CPPUNIT_ASSERT_EQUAL(3.0, m_pDoc->GetValue(ScAddress(2,1,0)));
+ CPPUNIT_ASSERT_EQUAL(3.0, m_pDoc->GetValue(ScAddress(2,2,0)));
+ CPPUNIT_ASSERT_EQUAL(3.0, m_pDoc->GetValue(ScAddress(2,3,0)));
+
+ ScDBDocFunc aFunc(getDocShell());
+
+ // Change the range referenced by MyRange to A1:A4.
+ ScDBCollection aNewDBs(m_pDoc);
+ bInserted = aNewDBs.getNamedDBs().insert(new ScDBData("MyRange", 0, 0, 0, 0, 3));
+ CPPUNIT_ASSERT_MESSAGE("Failed to insert a new database range.", bInserted);
+
+ std::vector<ScRange> aDeleted;
+ aFunc.ModifyAllDBData(aNewDBs, aDeleted);
+
+ // Check the updated formula results.
+ CPPUNIT_ASSERT_EQUAL(10.0, m_pDoc->GetValue(ScAddress(2,1,0)));
+ CPPUNIT_ASSERT_EQUAL(10.0, m_pDoc->GetValue(ScAddress(2,2,0)));
+ CPPUNIT_ASSERT_EQUAL(10.0, m_pDoc->GetValue(ScAddress(2,3,0)));
+
+ SfxUndoManager* pUndoMgr = m_pDoc->GetUndoManager();
+ CPPUNIT_ASSERT(pUndoMgr);
+
+ // Undo and check the results.
+ pUndoMgr->Undo();
+ CPPUNIT_ASSERT_EQUAL(3.0, m_pDoc->GetValue(ScAddress(2,1,0)));
+ CPPUNIT_ASSERT_EQUAL(3.0, m_pDoc->GetValue(ScAddress(2,2,0)));
+ CPPUNIT_ASSERT_EQUAL(3.0, m_pDoc->GetValue(ScAddress(2,3,0)));
+
+ // Redo and check the results.
+ pUndoMgr->Redo();
+ CPPUNIT_ASSERT_EQUAL(10.0, m_pDoc->GetValue(ScAddress(2,1,0)));
+ CPPUNIT_ASSERT_EQUAL(10.0, m_pDoc->GetValue(ScAddress(2,2,0)));
+ CPPUNIT_ASSERT_EQUAL(10.0, m_pDoc->GetValue(ScAddress(2,3,0)));
+
+ m_pDoc->DeleteTab(0);
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */