diff options
author | Kohei Yoshida <kohei.yoshida@collabora.com> | 2014-03-12 17:39:38 -0400 |
---|---|---|
committer | Kohei Yoshida <kohei.yoshida@collabora.com> | 2014-03-12 22:00:06 -0400 |
commit | c9058f25e97b58a05eb25b7b769f6406423186b6 (patch) | |
tree | 6a1b6568a581c186de40a22a928d9597ed5c322f /sc/qa | |
parent | b749a589bb2e111546fc9e4b4dd32791e424a37b (diff) |
fdo#75977: Write test for this.
Change-Id: I96bd008759a2a06ffeea46f2b25b847bc895e9eb
Diffstat (limited to 'sc/qa')
-rw-r--r-- | sc/qa/unit/ucalc.hxx | 2 | ||||
-rw-r--r-- | sc/qa/unit/ucalc_sharedformula.cxx | 59 |
2 files changed, 61 insertions, 0 deletions
diff --git a/sc/qa/unit/ucalc.hxx b/sc/qa/unit/ucalc.hxx index 58dc0838317b..d17c8f54fca9 100644 --- a/sc/qa/unit/ucalc.hxx +++ b/sc/qa/unit/ucalc.hxx @@ -267,6 +267,7 @@ public: void testSharedFormulasDeleteColumns(); void testSharedFormulasRefUpdateMoveSheets(); void testSharedFormulasRefUpdateCopySheets(); + void testSharedFormulasRefUpdateDeleteSheets(); void testSharedFormulasCopyPaste(); void testSharedFormulaInsertColumn(); void testSharedFormulaMoveBlock(); @@ -441,6 +442,7 @@ public: CPPUNIT_TEST(testSharedFormulasDeleteColumns); CPPUNIT_TEST(testSharedFormulasRefUpdateMoveSheets); CPPUNIT_TEST(testSharedFormulasRefUpdateCopySheets); + CPPUNIT_TEST(testSharedFormulasRefUpdateDeleteSheets); CPPUNIT_TEST(testSharedFormulasCopyPaste); CPPUNIT_TEST(testSharedFormulaInsertColumn); CPPUNIT_TEST(testSharedFormulaMoveBlock); diff --git a/sc/qa/unit/ucalc_sharedformula.cxx b/sc/qa/unit/ucalc_sharedformula.cxx index 98d087dc82cd..eb7b5984d3b1 100644 --- a/sc/qa/unit/ucalc_sharedformula.cxx +++ b/sc/qa/unit/ucalc_sharedformula.cxx @@ -819,6 +819,65 @@ void Test::testSharedFormulasRefUpdateCopySheets() m_pDoc->DeleteTab(0); } +void Test::testSharedFormulasRefUpdateDeleteSheets() +{ + sc::AutoCalcSwitch aACSwitch(*m_pDoc, true); // make sure auto calc is on. + + m_pDoc->InsertTab(0, "Sheet1"); + m_pDoc->InsertTab(1, "Sheet2"); + + // Set values to B2:B4 on Sheet2. + m_pDoc->SetValue(ScAddress(1,1,1), 1.0); + m_pDoc->SetValue(ScAddress(1,2,1), 2.0); + m_pDoc->SetValue(ScAddress(1,3,1), 3.0); + + // Set formulas in A1:A3 on Sheet1 that reference B2:B4 on Sheet2. + m_pDoc->SetString(ScAddress(0,0,0), "=Sheet2.B2"); + m_pDoc->SetString(ScAddress(0,1,0), "=Sheet2.B3"); + m_pDoc->SetString(ScAddress(0,2,0), "=Sheet2.B4"); + + // Check the formula results. + CPPUNIT_ASSERT_EQUAL(1.0, m_pDoc->GetValue(ScAddress(0,0,0))); + CPPUNIT_ASSERT_EQUAL(2.0, m_pDoc->GetValue(ScAddress(0,1,0))); + CPPUNIT_ASSERT_EQUAL(3.0, m_pDoc->GetValue(ScAddress(0,2,0))); + + if (!checkFormula(*m_pDoc, ScAddress(0,0,0), "Sheet2.B2")) + CPPUNIT_FAIL("Wrong formula"); + if (!checkFormula(*m_pDoc, ScAddress(0,1,0), "Sheet2.B3")) + CPPUNIT_FAIL("Wrong formula"); + if (!checkFormula(*m_pDoc, ScAddress(0,2,0), "Sheet2.B4")) + CPPUNIT_FAIL("Wrong formula"); + + // Delete Sheet2. + ScDocFunc& rFunc = getDocShell().GetDocFunc(); + rFunc.DeleteTable(1, true, true); + + if (!checkFormula(*m_pDoc, ScAddress(0,0,0), "#REF!.B2")) + CPPUNIT_FAIL("Wrong formula"); + if (!checkFormula(*m_pDoc, ScAddress(0,1,0), "#REF!.B3")) + CPPUNIT_FAIL("Wrong formula"); + if (!checkFormula(*m_pDoc, ScAddress(0,2,0), "#REF!.B4")) + CPPUNIT_FAIL("Wrong formula"); + + // Undo the deletion and make sure the formulas are back to the way they were. + SfxUndoManager* pUndoMgr = m_pDoc->GetUndoManager(); + CPPUNIT_ASSERT(pUndoMgr); + pUndoMgr->Undo(); + + if (!checkFormula(*m_pDoc, ScAddress(0,0,0), "Sheet2.B2")) + CPPUNIT_FAIL("Wrong formula"); + if (!checkFormula(*m_pDoc, ScAddress(0,1,0), "Sheet2.B3")) + CPPUNIT_FAIL("Wrong formula"); + if (!checkFormula(*m_pDoc, ScAddress(0,2,0), "Sheet2.B4")) + CPPUNIT_FAIL("Wrong formula"); + + // TODO: We can't test redo yet as ScUndoDeleteTab::Redo() relies on + // view shell to do its thing. + + m_pDoc->DeleteTab(1); + m_pDoc->DeleteTab(0); +} + void Test::testSharedFormulasCopyPaste() { m_pDoc->InsertTab(0, "Test"); |