diff options
author | Kohei Yoshida <libreoffice@kohei.us> | 2013-09-07 16:32:49 -0400 |
---|---|---|
committer | Kohei Yoshida <libreoffice@kohei.us> | 2013-09-07 16:38:24 -0400 |
commit | f4710e167ded0e6a378f1bfb01ef842b726b0aac (patch) | |
tree | bbb8fe4f38bcf1be19e9c438e4941af1bee80636 /sc/qa | |
parent | 405a9346efa8dbed3d36ad96dc373a97e4e99d92 (diff) |
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
Diffstat (limited to 'sc/qa')
-rw-r--r-- | sc/qa/unit/ucalc.hxx | 2 | ||||
-rw-r--r-- | sc/qa/unit/ucalc_sharedformula.cxx | 53 |
2 files changed, 55 insertions, 0 deletions
diff --git a/sc/qa/unit/ucalc.hxx b/sc/qa/unit/ucalc.hxx index 9ad69b663701..e97bb8df24e7 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 1ecff32fb098..00378ddb2155 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"); |