diff options
author | Kohei Yoshida <kohei.yoshida@gmail.com> | 2013-07-29 14:47:07 -0400 |
---|---|---|
committer | Kohei Yoshida <kohei.yoshida@gmail.com> | 2013-07-30 23:50:00 -0400 |
commit | f77c9d5b3cb65d9c2e2417f60bec1113feac50e1 (patch) | |
tree | 9654e02707830fc937fa5bedebf1d6ac3f9ae25f /sc/qa/unit | |
parent | 35d11d2b1e53d07833bc90242ac82f3a00587d41 (diff) |
First cut on re-working reference update in named expressions.
It's not perfect yet.
Change-Id: Iebe7a88e419365b053765685bb769427f569070d
Diffstat (limited to 'sc/qa/unit')
-rw-r--r-- | sc/qa/unit/ucalc.hxx | 2 | ||||
-rw-r--r-- | sc/qa/unit/ucalc_formula.cxx | 56 |
2 files changed, 58 insertions, 0 deletions
diff --git a/sc/qa/unit/ucalc.hxx b/sc/qa/unit/ucalc.hxx index 5a1d0aea89e9..241331791c5a 100644 --- a/sc/qa/unit/ucalc.hxx +++ b/sc/qa/unit/ucalc.hxx @@ -90,6 +90,7 @@ public: void testFormulaRefUpdateRange(); void testFormulaRefUpdateSheets(); void testFormulaRefUpdateMove(); + void testFormulaRefUpdateNamedExpression(); void testFuncCOLUMN(); void testFuncROW(); void testFuncSUM(); @@ -282,6 +283,7 @@ public: CPPUNIT_TEST(testFormulaRefUpdateRange); CPPUNIT_TEST(testFormulaRefUpdateSheets); CPPUNIT_TEST(testFormulaRefUpdateMove); + CPPUNIT_TEST(testFormulaRefUpdateNamedExpression); CPPUNIT_TEST(testFuncCOLUMN); CPPUNIT_TEST(testFuncROW); CPPUNIT_TEST(testFuncSUM); diff --git a/sc/qa/unit/ucalc_formula.cxx b/sc/qa/unit/ucalc_formula.cxx index def390273859..68c0f07ae3cb 100644 --- a/sc/qa/unit/ucalc_formula.cxx +++ b/sc/qa/unit/ucalc_formula.cxx @@ -964,6 +964,62 @@ void Test::testFormulaRefUpdateMove() m_pDoc->DeleteTab(0); } +void Test::testFormulaRefUpdateNamedExpression() +{ + m_pDoc->InsertTab(0, "Formula"); + + sc::AutoCalcSwitch aACSwitch(*m_pDoc, true); // turn auto calc on. + + // Fill C2:C5 with values. + m_pDoc->SetValue(ScAddress(2,1,0), 1); + m_pDoc->SetValue(ScAddress(2,2,0), 2); + m_pDoc->SetValue(ScAddress(2,3,0), 3); + m_pDoc->SetValue(ScAddress(2,4,0), 4); + + // Add a named expression that references the immediate left cell. + ScRangeName* pGlobalNames = m_pDoc->GetRangeName(); + CPPUNIT_ASSERT_MESSAGE("Failed to obtain global named expression object.", pGlobalNames); + ScRangeData* pName = new ScRangeData( + m_pDoc, "ToLeft", "RC[-1]", ScAddress(2,1,0), RT_NAME, formula::FormulaGrammar::GRAM_NATIVE_XL_R1C1); + + bool bInserted = pGlobalNames->insert(pName); + CPPUNIT_ASSERT_MESSAGE("Failed to insert a new name.", bInserted); + + // Insert formulas in D2:D5 using the named expression. + m_pDoc->SetString(ScAddress(3,1,0), "=ToLeft"); + m_pDoc->SetString(ScAddress(3,2,0), "=ToLeft"); + m_pDoc->SetString(ScAddress(3,3,0), "=ToLeft"); + m_pDoc->SetString(ScAddress(3,4,0), "=ToLeft"); + + // Make sure the results are correct. + CPPUNIT_ASSERT_EQUAL(1.0, m_pDoc->GetValue(3,1,0)); + CPPUNIT_ASSERT_EQUAL(2.0, m_pDoc->GetValue(3,2,0)); + CPPUNIT_ASSERT_EQUAL(3.0, m_pDoc->GetValue(3,3,0)); + CPPUNIT_ASSERT_EQUAL(4.0, m_pDoc->GetValue(3,4,0)); + + // Push cells in column C down by one cell. + m_pDoc->InsertRow(ScRange(2,0,0,2,0,0)); + + // Make sure the results change accordingly. + CPPUNIT_ASSERT_EQUAL(0.0, m_pDoc->GetValue(3,1,0)); + CPPUNIT_ASSERT_EQUAL(1.0, m_pDoc->GetValue(3,2,0)); + CPPUNIT_ASSERT_EQUAL(2.0, m_pDoc->GetValue(3,3,0)); + CPPUNIT_ASSERT_EQUAL(3.0, m_pDoc->GetValue(3,4,0)); + + // Move cells back. + m_pDoc->DeleteRow(ScRange(2,0,0,2,0,0)); + + // Make sure the results are back as well. + CPPUNIT_ASSERT_EQUAL(1.0, m_pDoc->GetValue(3,1,0)); + CPPUNIT_ASSERT_EQUAL(2.0, m_pDoc->GetValue(3,2,0)); + CPPUNIT_ASSERT_EQUAL(3.0, m_pDoc->GetValue(3,3,0)); + CPPUNIT_ASSERT_EQUAL(4.0, m_pDoc->GetValue(3,4,0)); + + + + m_pDoc->DeleteTab(0); +} + void Test::testFuncCOLUMN() { m_pDoc->InsertTab(0, "Formula"); |