Kaydet (Commit) f4710e16 authored tarafından Kohei Yoshida's avatar Kohei Yoshida

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
üst 405a9346
...@@ -220,6 +220,7 @@ public: ...@@ -220,6 +220,7 @@ public:
void testSearchCells(); void testSearchCells();
void testSharedFormulas(); void testSharedFormulas();
void testSharedFormulasRefUpdate(); void testSharedFormulasRefUpdate();
void testSharedFormulasRefUpdateRange();
void testSharedFormulasCopyPaste(); void testSharedFormulasCopyPaste();
void testFormulaPosition(); void testFormulaPosition();
...@@ -350,6 +351,7 @@ public: ...@@ -350,6 +351,7 @@ public:
CPPUNIT_TEST(testSearchCells); CPPUNIT_TEST(testSearchCells);
CPPUNIT_TEST(testSharedFormulas); CPPUNIT_TEST(testSharedFormulas);
CPPUNIT_TEST(testSharedFormulasRefUpdate); CPPUNIT_TEST(testSharedFormulasRefUpdate);
CPPUNIT_TEST(testSharedFormulasRefUpdateRange);
CPPUNIT_TEST(testSharedFormulasCopyPaste); CPPUNIT_TEST(testSharedFormulasCopyPaste);
CPPUNIT_TEST(testFormulaPosition); CPPUNIT_TEST(testFormulaPosition);
CPPUNIT_TEST(testJumpToPrecedentsDependents); CPPUNIT_TEST(testJumpToPrecedentsDependents);
......
...@@ -391,6 +391,59 @@ void Test::testSharedFormulasRefUpdate() ...@@ -391,6 +391,59 @@ void Test::testSharedFormulasRefUpdate()
m_pDoc->DeleteTab(0); 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() void Test::testSharedFormulasCopyPaste()
{ {
m_pDoc->InsertTab(0, "Test"); m_pDoc->InsertTab(0, "Test");
......
...@@ -2186,7 +2186,10 @@ bool ScFormulaCell::UpdatePosOnShift( const sc::RefUpdateContext& rCxt ) ...@@ -2186,7 +2186,10 @@ bool ScFormulaCell::UpdatePosOnShift( const sc::RefUpdateContext& rCxt )
// This formula cell itself is being shifted during cell range // This formula cell itself is being shifted during cell range
// insertion or deletion. Update its position. // 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; mxGroup->mnStart += rCxt.mnRowDelta;
aPos.Move(rCxt.mnColDelta, rCxt.mnRowDelta, rCxt.mnTabDelta); aPos.Move(rCxt.mnColDelta, rCxt.mnRowDelta, rCxt.mnTabDelta);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment