diff options
author | Kohei Yoshida <kohei.yoshida@collabora.com> | 2014-04-25 00:53:59 -0400 |
---|---|---|
committer | Kohei Yoshida <kohei.yoshida@collabora.com> | 2014-04-25 00:58:14 -0400 |
commit | 7608bf4660d11ccda56cb7c3edad4d78d3610139 (patch) | |
tree | 68b64ee29aa93921b51208d2dde2121aab464b0c | |
parent | 36e0d770928f71c932db5dea9f04645f65222ea6 (diff) |
fdo#77728: Add test case for named range expansion and formula update.
Change-Id: Ia900ae5f1091ac220c4e08b667920affa2546261
-rw-r--r-- | sc/qa/unit/ucalc_formula.cxx | 49 |
1 files changed, 47 insertions, 2 deletions
diff --git a/sc/qa/unit/ucalc_formula.cxx b/sc/qa/unit/ucalc_formula.cxx index e3283dbcb5d9..9776715d3ba6 100644 --- a/sc/qa/unit/ucalc_formula.cxx +++ b/sc/qa/unit/ucalc_formula.cxx @@ -1900,11 +1900,11 @@ void Test::testFormulaRefUpdateNamedExpressionMove() void Test::testFormulaRefUpdateNamedExpressionExpandRef() { + sc::AutoCalcSwitch aACSwitch(*m_pDoc, true); // turn auto calc on. + m_pDoc->InsertTab(0, "Test"); m_pDoc->SetExpandRefs(true); // turn on automatic range expansion. - sc::AutoCalcSwitch aACSwitch(*m_pDoc, true); // turn auto calc on. - bool bInserted = m_pDoc->InsertNewRangeName("MyRange", ScAddress(0,0,0), "$A$1:$A$3"); CPPUNIT_ASSERT(bInserted); @@ -1957,6 +1957,51 @@ void Test::testFormulaRefUpdateNamedExpressionExpandRef() pName->GetSymbol(aSymbol, m_pDoc->GetGrammar()); CPPUNIT_ASSERT_EQUAL(OUString("$B$4:$B$9"), aSymbol); + // Clear the document and start over. + m_pDoc->GetRangeName()->clear(); + clearSheet(m_pDoc, 0); + + // Set values to A1:A3. + m_pDoc->SetValue(ScAddress(0,0,0), 1.0); + m_pDoc->SetValue(ScAddress(0,1,0), 2.0); + m_pDoc->SetValue(ScAddress(0,2,0), 3.0); + + // Name A1:A3 'MyData'. + bInserted = m_pDoc->InsertNewRangeName("MyData", ScAddress(0,0,0), "$A$1:$A$3"); + CPPUNIT_ASSERT(bInserted); + + // Set formulas to C1:C2 and E1. + m_pDoc->SetString(ScAddress(2,0,0), "=SUM(MyData)"); + m_pDoc->SetString(ScAddress(2,1,0), "=SUM(MyData)"); + m_pDoc->SetString(ScAddress(4,0,0), "=SUM(MyData)"); + + // C1:C2 should be shared. + const ScFormulaCell* pFC = m_pDoc->GetFormulaCell(ScAddress(2,0,0)); + CPPUNIT_ASSERT(pFC); + CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(0), pFC->GetSharedTopRow()); + CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(2), pFC->GetSharedLength()); + + // E1 should not be shared. + pFC = m_pDoc->GetFormulaCell(ScAddress(4,0,0)); + CPPUNIT_ASSERT(pFC); + CPPUNIT_ASSERT(!pFC->IsShared()); + + // Check the results. + CPPUNIT_ASSERT_EQUAL(6.0, m_pDoc->GetValue(ScAddress(2,0,0))); + CPPUNIT_ASSERT_EQUAL(6.0, m_pDoc->GetValue(ScAddress(2,1,0))); + CPPUNIT_ASSERT_EQUAL(6.0, m_pDoc->GetValue(ScAddress(4,0,0))); + + // Insert a new row at row 3. This should expand MyData to A1:A4. + rFunc.InsertCells(ScRange(0,2,0,MAXCOL,2,0), &aMark, INS_INSROWS, false, true, false); + + // Set new value to A3. + m_pDoc->SetValue(ScAddress(0,2,0), 4.0); + + // Check the results again. + CPPUNIT_ASSERT_EQUAL(10.0, m_pDoc->GetValue(ScAddress(2,0,0))); + CPPUNIT_ASSERT_EQUAL(10.0, m_pDoc->GetValue(ScAddress(2,1,0))); + CPPUNIT_ASSERT_EQUAL(10.0, m_pDoc->GetValue(ScAddress(4,0,0))); + m_pDoc->DeleteTab(0); } |