summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKohei Yoshida <kohei.yoshida@collabora.com>2014-03-21 20:42:47 -0400
committerKohei Yoshida <kohei.yoshida@collabora.com>2014-03-22 09:51:41 -0400
commitc78d1bb2cd98aeac64402caf7baa40cbe4cca6f9 (patch)
treea1c6afb5789ef5e13be4aced7430d3401b5c9141
parent802b6aaed855376b24d09acd5aa91abf80a9f71a (diff)
fdo#76470: Write unit test for this first.
Change-Id: Iaf609b509165405c1a471dd8556c30dc019922da
-rw-r--r--sc/qa/unit/ucalc.hxx2
-rw-r--r--sc/qa/unit/ucalc_sharedformula.cxx106
2 files changed, 108 insertions, 0 deletions
diff --git a/sc/qa/unit/ucalc.hxx b/sc/qa/unit/ucalc.hxx
index 81e915f44892..39b40d162537 100644
--- a/sc/qa/unit/ucalc.hxx
+++ b/sc/qa/unit/ucalc.hxx
@@ -265,6 +265,7 @@ public:
void testSharedFormulasRefUpdate();
void testSharedFormulasRefUpdateRange();
void testSharedFormulasRefUpdateExternal();
+ void testSharedFormulasInsertRow();
void testSharedFormulasDeleteRows();
void testSharedFormulasDeleteColumns();
void testSharedFormulasRefUpdateMoveSheets();
@@ -442,6 +443,7 @@ public:
CPPUNIT_TEST(testSharedFormulasRefUpdate);
CPPUNIT_TEST(testSharedFormulasRefUpdateRange);
CPPUNIT_TEST(testSharedFormulasRefUpdateExternal);
+ CPPUNIT_TEST(testSharedFormulasInsertRow);
CPPUNIT_TEST(testSharedFormulasDeleteRows);
CPPUNIT_TEST(testSharedFormulasDeleteColumns);
CPPUNIT_TEST(testSharedFormulasRefUpdateMoveSheets);
diff --git a/sc/qa/unit/ucalc_sharedformula.cxx b/sc/qa/unit/ucalc_sharedformula.cxx
index eb7b5984d3b1..b95a673d0c92 100644
--- a/sc/qa/unit/ucalc_sharedformula.cxx
+++ b/sc/qa/unit/ucalc_sharedformula.cxx
@@ -536,6 +536,112 @@ void Test::testSharedFormulasRefUpdateExternal()
m_pDoc->DeleteTab(0);
}
+void Test::testSharedFormulasInsertRow()
+{
+ struct
+ {
+ bool checkContent( ScDocument* pDoc )
+ {
+ // B1:B2 and B4:B5 should point to $A$5.
+ SCROW pRows[] = { 0, 1, 3, 4 };
+ for (size_t i = 0, n = SAL_N_ELEMENTS(pRows); i < n; ++i)
+ {
+ ScAddress aPos(1, pRows[i], 0);
+ if (!checkFormula(*pDoc, aPos, "$A$5"))
+ {
+ cerr << "Wrong formula!" << endl;
+ return false;
+ }
+ }
+
+ // B1:B2 should be grouped.
+ ScFormulaCell* pFC = pDoc->GetFormulaCell(ScAddress(1,0,0));
+ if (!pFC || pFC->GetSharedTopRow() != 0 || pFC->GetSharedLength() != 2)
+ {
+ cerr << "B1:B2 should be grouped." << endl;
+ return false;
+ }
+
+ // B4:B5 should be grouped.
+ pFC = pDoc->GetFormulaCell(ScAddress(1,3,0));
+ if (!pFC || pFC->GetSharedTopRow() != 3 || pFC->GetSharedLength() != 2)
+ {
+ cerr << "B4:B5 should be grouped." << endl;
+ return false;
+ }
+
+ return true;
+ }
+
+ bool checkContentUndo( ScDocument* pDoc )
+ {
+ for (SCROW i = 0; i <= 3; ++i)
+ {
+ ScAddress aPos(1,i,0);
+ if (!checkFormula(*pDoc, aPos, "$A$4"))
+ {
+ cerr << "Wrong formula!" << endl;
+ return false;
+ }
+ }
+
+ // Ensure that B5 is empty.
+ if (pDoc->GetCellType(ScAddress(1,4,0)) != CELLTYPE_NONE)
+ {
+ cerr << "B5 should be empty." << endl;
+ return false;
+ }
+
+ // B1:B4 should be grouped.
+ ScFormulaCell* pFC = pDoc->GetFormulaCell(ScAddress(1,0,0));
+ if (!pFC || pFC->GetSharedTopRow() != 0 || pFC->GetSharedLength() != 4)
+ {
+ cerr << "B1:B4 should be grouped." << endl;
+ return false;
+ }
+
+ return true;
+ }
+
+ } aCheck;
+
+ sc::AutoCalcSwitch aACSwitch(*m_pDoc, true); // turn on auto calc.
+ m_pDoc->InsertTab(0, "Test");
+
+ // Scenario inspired by fdo#76470.
+
+ // Set value to A4.
+ m_pDoc->SetValue(ScAddress(0,3,0), 4.0);
+
+ // Set formula cells in B1:B4 all referencing A4 as absolute reference.
+ for (SCROW i = 0; i <= 3; ++i)
+ m_pDoc->SetString(ScAddress(1,i,0), "=$A$4");
+
+ // Insert a new row at row 3.
+ ScDocFunc& rFunc = getDocShell().GetDocFunc();
+ ScMarkData aMark;
+ aMark.SelectOneTable(0);
+ rFunc.InsertCells(ScRange(0,2,0,MAXCOL,2,0), &aMark, INS_INSROWS, true, true, false);
+
+ bool bResult = aCheck.checkContent(m_pDoc);
+ CPPUNIT_ASSERT_MESSAGE("Failed on the initial content check.", bResult);
+
+ // Undo and check its result.
+ SfxUndoManager* pUndoMgr = m_pDoc->GetUndoManager();
+ CPPUNIT_ASSERT(pUndoMgr);
+ pUndoMgr->Undo();
+
+ bResult = aCheck.checkContentUndo(m_pDoc);
+ CPPUNIT_ASSERT_MESSAGE("Failed on the content check after undo.", bResult);
+
+ // Redo and check its result.
+ pUndoMgr->Redo();
+ bResult = aCheck.checkContent(m_pDoc);
+ CPPUNIT_ASSERT_MESSAGE("Failed on the content check after redo.", bResult);
+
+ m_pDoc->DeleteTab(0);
+}
+
void Test::testSharedFormulasDeleteRows()
{
m_pDoc->InsertTab(0, "Test");