diff options
author | Kohei Yoshida <kohei.yoshida@collabora.com> | 2014-10-18 20:22:28 -0400 |
---|---|---|
committer | Kohei Yoshida <kohei.yoshida@collabora.com> | 2014-10-18 20:24:59 -0400 |
commit | 03075bfac25408d805b6cfecce56fa0c4cb9d88d (patch) | |
tree | a7339e887a44024106a69a80f992b295c2372b55 | |
parent | 2f821f3b81d093cb6f738c1a51822e907ab80054 (diff) |
fdo#82047: Write test for this.
Change-Id: I0e5e54b517d3fb3cb28eb133b2cbe5bf5ca6b1d6
-rw-r--r-- | sc/qa/unit/ucalc.hxx | 2 | ||||
-rw-r--r-- | sc/qa/unit/ucalc_formula.cxx | 74 |
2 files changed, 76 insertions, 0 deletions
diff --git a/sc/qa/unit/ucalc.hxx b/sc/qa/unit/ucalc.hxx index 114ca8d68a81..472779cdc675 100644 --- a/sc/qa/unit/ucalc.hxx +++ b/sc/qa/unit/ucalc.hxx @@ -136,6 +136,7 @@ public: void testFormulaRefUpdateName(); void testFormulaRefUpdateNameMove(); void testFormulaRefUpdateNameExpandRef(); + void testFormulaRefUpdateNameDeleteRow(); void testFormulaRefUpdateValidity(); void testMultipleOperations(); void testFuncCOLUMN(); @@ -428,6 +429,7 @@ public: CPPUNIT_TEST(testFormulaRefUpdateName); CPPUNIT_TEST(testFormulaRefUpdateNameMove); CPPUNIT_TEST(testFormulaRefUpdateNameExpandRef); + CPPUNIT_TEST(testFormulaRefUpdateNameDeleteRow); CPPUNIT_TEST(testFormulaRefUpdateValidity); CPPUNIT_TEST(testMultipleOperations); CPPUNIT_TEST(testFuncCOLUMN); diff --git a/sc/qa/unit/ucalc_formula.cxx b/sc/qa/unit/ucalc_formula.cxx index 3ae29cb4b2ca..5e0018aa0114 100644 --- a/sc/qa/unit/ucalc_formula.cxx +++ b/sc/qa/unit/ucalc_formula.cxx @@ -2285,6 +2285,80 @@ void Test::testFormulaRefUpdateNameExpandRef() m_pDoc->DeleteTab(0); } +void Test::testFormulaRefUpdateNameDeleteRow() +{ + m_pDoc->InsertTab(0, "Test"); + + // Insert a new name 'MyRange' to reference B2:B4. + bool bInserted = m_pDoc->InsertNewRangeName("MyRange", ScAddress(0,0,0), "$B$2:$B$4"); + CPPUNIT_ASSERT(bInserted); + + const ScRangeData* pName = m_pDoc->GetRangeName()->findByUpperName("MYRANGE"); + CPPUNIT_ASSERT(pName); + + sc::TokenStringContext aCxt(m_pDoc, formula::FormulaGrammar::GRAM_ENGLISH); + const ScTokenArray* pCode = pName->GetCode(); + OUString aExpr = pCode->CreateString(aCxt, ScAddress(0,0,0)); + CPPUNIT_ASSERT_EQUAL(OUString("$B$2:$B$4"), aExpr); + + ScDocFunc& rFunc = getDocShell().GetDocFunc(); + + // Delete row 3. + ScMarkData aMark; + aMark.SelectOneTable(0); + rFunc.DeleteCells(ScRange(0,2,0,MAXCOL,2,0), &aMark, DEL_CELLSUP, true, true); + + // The reference in the name should get updated to B2:B3. + aExpr = pCode->CreateString(aCxt, ScAddress(0,0,0)); + CPPUNIT_ASSERT_EQUAL(OUString("$B$2:$B$3"), aExpr); + + // Delete row 3 again. + rFunc.DeleteCells(ScRange(0,2,0,MAXCOL,2,0), &aMark, DEL_CELLSUP, true, true); + aExpr = pCode->CreateString(aCxt, ScAddress(0,0,0)); + CPPUNIT_ASSERT_EQUAL(OUString("$B$2:$B$2"), aExpr); + + // Undo and check. + SfxUndoManager* pUndoMgr = m_pDoc->GetUndoManager(); + CPPUNIT_ASSERT(pUndoMgr); + + pUndoMgr->Undo(); + + pName = m_pDoc->GetRangeName()->findByUpperName("MYRANGE"); + CPPUNIT_ASSERT(pName); + pCode = pName->GetCode(); + + aExpr = pCode->CreateString(aCxt, ScAddress(0,0,0)); + CPPUNIT_ASSERT_EQUAL(OUString("$B$2:$B$3"), aExpr); + + // Undo again and check. + pUndoMgr->Undo(); + + pName = m_pDoc->GetRangeName()->findByUpperName("MYRANGE"); + CPPUNIT_ASSERT(pName); + pCode = pName->GetCode(); + + aExpr = pCode->CreateString(aCxt, ScAddress(0,0,0)); + CPPUNIT_ASSERT_EQUAL(OUString("$B$2:$B$4"), aExpr); + + // Delete row 2-3. + rFunc.DeleteCells(ScRange(0,1,0,MAXCOL,2,0), &aMark, DEL_CELLSUP, true, true); + + aExpr = pCode->CreateString(aCxt, ScAddress(0,0,0)); + CPPUNIT_ASSERT_EQUAL(OUString("$B$2:$B$2"), aExpr); + + // Undo and check. + pUndoMgr->Undo(); + + pName = m_pDoc->GetRangeName()->findByUpperName("MYRANGE"); + CPPUNIT_ASSERT(pName); + pCode = pName->GetCode(); + + aExpr = pCode->CreateString(aCxt, ScAddress(0,0,0)); + CPPUNIT_ASSERT_EQUAL(OUString("$B$2:$B$4"), aExpr); + + m_pDoc->DeleteTab(0); +} + void Test::testFormulaRefUpdateValidity() { struct { |