sc/qa/unit/ucalc.hxx | 2 + sc/qa/unit/ucalc_sharedformula.cxx | 53 ++++++++++++++++++++++++++++++++++++ sc/source/core/data/formulacell.cxx | 5 ++- 3 files changed, 59 insertions(+), 1 deletion(-)
New commits: commit f4710e167ded0e6a378f1bfb01ef842b726b0aac Author: Kohei Yoshida <libreoff...@kohei.us> Date: Sat Sep 7 16:32:49 2013 -0400 Fix incorrect reference update on shared formulas. The start position of a shared formula group is used to prevent non-top cells of the group from being updated. Updating it at the top cell may cause non-top cells to perform reference update which they never should. Change-Id: I4f067d4d717b756fc89cb823f3ce3e630dac756e diff --git a/sc/qa/unit/ucalc.hxx b/sc/qa/unit/ucalc.hxx index 9ad69b6..e97bb8d 100644 --- a/sc/qa/unit/ucalc.hxx +++ b/sc/qa/unit/ucalc.hxx @@ -220,6 +220,7 @@ public: void testSearchCells(); void testSharedFormulas(); void testSharedFormulasRefUpdate(); + void testSharedFormulasRefUpdateRange(); void testSharedFormulasCopyPaste(); void testFormulaPosition(); @@ -350,6 +351,7 @@ public: CPPUNIT_TEST(testSearchCells); CPPUNIT_TEST(testSharedFormulas); CPPUNIT_TEST(testSharedFormulasRefUpdate); + CPPUNIT_TEST(testSharedFormulasRefUpdateRange); CPPUNIT_TEST(testSharedFormulasCopyPaste); CPPUNIT_TEST(testFormulaPosition); CPPUNIT_TEST(testJumpToPrecedentsDependents); diff --git a/sc/qa/unit/ucalc_sharedformula.cxx b/sc/qa/unit/ucalc_sharedformula.cxx index 1ecff32..00378dd 100644 --- a/sc/qa/unit/ucalc_sharedformula.cxx +++ b/sc/qa/unit/ucalc_sharedformula.cxx @@ -391,6 +391,59 @@ void Test::testSharedFormulasRefUpdate() m_pDoc->DeleteTab(0); } +void Test::testSharedFormulasRefUpdateRange() +{ + m_pDoc->InsertTab(0, "Test"); + + // Insert values to A3:A5. + m_pDoc->SetValue(ScAddress(0,2,0), 1); + m_pDoc->SetValue(ScAddress(0,3,0), 2); + m_pDoc->SetValue(ScAddress(0,4,0), 3); + + // Insert formulas to B3:B5. + m_pDoc->SetString(ScAddress(1,2,0), "=SUM($A$3:$A$5)"); + m_pDoc->SetString(ScAddress(1,3,0), "=SUM($A$3:$A$5)"); + m_pDoc->SetString(ScAddress(1,4,0), "=SUM($A$3:$A$5)"); + + if (!checkFormula(*m_pDoc, ScAddress(1,2,0), "SUM($A$3:$A$5)")) + CPPUNIT_FAIL("Wrong formula"); + if (!checkFormula(*m_pDoc, ScAddress(1,3,0), "SUM($A$3:$A$5)")) + CPPUNIT_FAIL("Wrong formula"); + if (!checkFormula(*m_pDoc, ScAddress(1,4,0), "SUM($A$3:$A$5)")) + CPPUNIT_FAIL("Wrong formula"); + + // B3:B5 should be shared. + const ScFormulaCell* pFC = m_pDoc->GetFormulaCell(ScAddress(1,2,0)); + CPPUNIT_ASSERT_MESSAGE("B3 should be shared.", pFC && pFC->IsShared()); + pFC = m_pDoc->GetFormulaCell(ScAddress(1,3,0)); + CPPUNIT_ASSERT_MESSAGE("B4 should be shared.", pFC && pFC->IsShared()); + pFC = m_pDoc->GetFormulaCell(ScAddress(1,4,0)); + CPPUNIT_ASSERT_MESSAGE("B3 should be shared.", pFC && pFC->IsShared()); + + // Insert 2 rows at row 1. + m_pDoc->InsertRow(ScRange(0,0,0,MAXCOL,1,0)); + + // B5:B7 should be shared. + pFC = m_pDoc->GetFormulaCell(ScAddress(1,4,0)); + CPPUNIT_ASSERT_MESSAGE("B5 should be shared.", pFC && pFC->IsShared()); + pFC = m_pDoc->GetFormulaCell(ScAddress(1,5,0)); + CPPUNIT_ASSERT_MESSAGE("B6 should be shared.", pFC && pFC->IsShared()); + pFC = m_pDoc->GetFormulaCell(ScAddress(1,6,0)); + CPPUNIT_ASSERT_MESSAGE("B7 should be shared.", pFC && pFC->IsShared()); + + CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(4), pFC->GetSharedTopRow()); + CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(3), pFC->GetSharedLength()); + + if (!checkFormula(*m_pDoc, ScAddress(1,4,0), "SUM($A$5:$A$7)")) + CPPUNIT_FAIL("Wrong formula"); + if (!checkFormula(*m_pDoc, ScAddress(1,5,0), "SUM($A$5:$A$7)")) + CPPUNIT_FAIL("Wrong formula"); + if (!checkFormula(*m_pDoc, ScAddress(1,6,0), "SUM($A$5:$A$7)")) + CPPUNIT_FAIL("Wrong formula"); + + m_pDoc->DeleteTab(0); +} + void Test::testSharedFormulasCopyPaste() { m_pDoc->InsertTab(0, "Test"); diff --git a/sc/source/core/data/formulacell.cxx b/sc/source/core/data/formulacell.cxx index 143351e8..0f248a2 100644 --- a/sc/source/core/data/formulacell.cxx +++ b/sc/source/core/data/formulacell.cxx @@ -2186,7 +2186,10 @@ bool ScFormulaCell::UpdatePosOnShift( const sc::RefUpdateContext& rCxt ) // This formula cell itself is being shifted during cell range // insertion or deletion. Update its position. - if (mxGroup && mxGroup->mnStart == aPos.Row()) + + if (mxGroup && (mxGroup->mnStart+mxGroup->mnLength-1) == aPos.Row()) + // For a shared formula cell, update its group start position only + // when it's the last cell of the group. mxGroup->mnStart += rCxt.mnRowDelta; aPos.Move(rCxt.mnColDelta, rCxt.mnRowDelta, rCxt.mnTabDelta); _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits