diff options
author | Kohei Yoshida <kohei.yoshida@collabora.com> | 2014-03-25 22:33:03 -0400 |
---|---|---|
committer | Kohei Yoshida <kohei.yoshida@collabora.com> | 2014-03-25 22:37:10 -0400 |
commit | 3edc49d11765372fa54c52b71b49bf52675f4dda (patch) | |
tree | c69dfc77e56dd37bb599464cac84aed0c91fa1e5 /sc | |
parent | 8bf22e7fe67b3321e2b2dcc8fb98882ef0eef4ca (diff) |
fdo#74322: Write unit test for this first.
Change-Id: If16a93ee371e9a4e0d0992fd0a62a4623fc284ab
Diffstat (limited to 'sc')
-rw-r--r-- | sc/qa/unit/ucalc.hxx | 2 | ||||
-rw-r--r-- | sc/qa/unit/ucalc_formula.cxx | 80 |
2 files changed, 82 insertions, 0 deletions
diff --git a/sc/qa/unit/ucalc.hxx b/sc/qa/unit/ucalc.hxx index 7c1c67ce2c4d..9579918a2e8b 100644 --- a/sc/qa/unit/ucalc.hxx +++ b/sc/qa/unit/ucalc.hxx @@ -121,6 +121,7 @@ public: void testFormulaRefUpdateMove(); void testFormulaRefUpdateMoveUndo(); void testFormulaRefUpdateNamedExpression(); + void testFormulaRefUpdateNamedExpressionMove(); void testFormulaRefUpdateNamedExpressionExpandRef(); void testMultipleOperations(); void testFuncCOLUMN(); @@ -367,6 +368,7 @@ public: CPPUNIT_TEST(testFormulaRefUpdateMove); CPPUNIT_TEST(testFormulaRefUpdateMoveUndo); CPPUNIT_TEST(testFormulaRefUpdateNamedExpression); + CPPUNIT_TEST(testFormulaRefUpdateNamedExpressionMove); CPPUNIT_TEST(testFormulaRefUpdateNamedExpressionExpandRef); CPPUNIT_TEST(testMultipleOperations); CPPUNIT_TEST(testFuncCOLUMN); diff --git a/sc/qa/unit/ucalc_formula.cxx b/sc/qa/unit/ucalc_formula.cxx index 718ece72bbf4..4544ac6eb8e7 100644 --- a/sc/qa/unit/ucalc_formula.cxx +++ b/sc/qa/unit/ucalc_formula.cxx @@ -1818,6 +1818,86 @@ void Test::testFormulaRefUpdateNamedExpression() m_pDoc->DeleteTab(0); } +void Test::testFormulaRefUpdateNamedExpressionMove() +{ + sc::AutoCalcSwitch aACSwitch(*m_pDoc, true); // turn auto calc on. + + m_pDoc->InsertTab(0, "Test"); + + // Set values to B2:B4. + m_pDoc->SetValue(ScAddress(1,1,0), 1.0); + m_pDoc->SetValue(ScAddress(1,2,0), 2.0); + m_pDoc->SetValue(ScAddress(1,3,0), 3.0); + + // Set named range for B2:B4. + bool bInserted = m_pDoc->InsertNewRangeName("MyRange", ScAddress(0,0,0), "$Test.$B$2:$B$4"); + CPPUNIT_ASSERT(bInserted); + + // Set formula in A10. + m_pDoc->SetString(ScAddress(0,9,0), "=SUM(MyRange)"); + CPPUNIT_ASSERT_EQUAL(6.0, m_pDoc->GetValue(ScAddress(0,9,0))); + + ScRangeData* pData = m_pDoc->GetRangeName()->findByUpperName("MYRANGE"); + CPPUNIT_ASSERT(pData); + OUString aSymbol; + pData->GetSymbol(aSymbol, m_pDoc->GetGrammar()); + CPPUNIT_ASSERT_EQUAL(OUString("$Test.$B$2:$B$4"), aSymbol); + + // Move B2:B4 to D3. + ScDocFunc& rFunc = getDocShell().GetDocFunc(); + bool bMoved = rFunc.MoveBlock(ScRange(1,1,0,1,3,0), ScAddress(3,2,0), true, true, false, true); + CPPUNIT_ASSERT(bMoved); + + // The named range should have moved as well. + pData->GetSymbol(aSymbol, m_pDoc->GetGrammar()); + CPPUNIT_ASSERT_EQUAL(OUString("$Test.$D$3:$D$5"), aSymbol); + + // The value of A10 should remain unchanged. + CPPUNIT_ASSERT_EQUAL(6.0, m_pDoc->GetValue(ScAddress(0,9,0))); + + SfxUndoManager* pUndoMgr = m_pDoc->GetUndoManager(); + CPPUNIT_ASSERT(pUndoMgr); + + // Undo and check. + pUndoMgr->Undo(); + + pData = m_pDoc->GetRangeName()->findByUpperName("MYRANGE"); + CPPUNIT_ASSERT(pData); + pData->GetSymbol(aSymbol, m_pDoc->GetGrammar()); + CPPUNIT_ASSERT_EQUAL(OUString("$Test.$B$2:$B$4"), aSymbol); + CPPUNIT_ASSERT_EQUAL(6.0, m_pDoc->GetValue(ScAddress(0,9,0))); + + // Redo and check. + pUndoMgr->Redo(); + + pData = m_pDoc->GetRangeName()->findByUpperName("MYRANGE"); + CPPUNIT_ASSERT(pData); + pData->GetSymbol(aSymbol, m_pDoc->GetGrammar()); + CPPUNIT_ASSERT_EQUAL(OUString("$Test.$D$3:$D$5"), aSymbol); + CPPUNIT_ASSERT_EQUAL(6.0, m_pDoc->GetValue(ScAddress(0,9,0))); + + // Undo again to bring it back to the initial condition, and clear the undo buffer. + pUndoMgr->Undo(); + pUndoMgr->Clear(); + + // Add an identical formula to A11 and make a formula group over A10:A11. + m_pDoc->SetString(ScAddress(0,10,0), "=SUM(MyRange)"); + ScFormulaCell* pFC = m_pDoc->GetFormulaCell(ScAddress(0,9,0)); + CPPUNIT_ASSERT(pFC); + CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(9), pFC->GetSharedTopRow()); + CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(2), pFC->GetSharedLength()); + + // Move B2:B4 to D3 again. + bMoved = rFunc.MoveBlock(ScRange(1,1,0,1,3,0), ScAddress(3,2,0), true, true, false, true); + CPPUNIT_ASSERT(bMoved); + + // Values of A10 and A11 should remain the same. + CPPUNIT_ASSERT_EQUAL(6.0, m_pDoc->GetValue(ScAddress(0,9,0))); + CPPUNIT_ASSERT_EQUAL(6.0, m_pDoc->GetValue(ScAddress(0,10,0))); + + m_pDoc->DeleteTab(0); +} + void Test::testFormulaRefUpdateNamedExpressionExpandRef() { m_pDoc->InsertTab(0, "Test"); |