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

fdo#82047: Write test for this.

Change-Id: I0e5e54b517d3fb3cb28eb133b2cbe5bf5ca6b1d6
üst 2f821f3b
...@@ -136,6 +136,7 @@ public: ...@@ -136,6 +136,7 @@ public:
void testFormulaRefUpdateName(); void testFormulaRefUpdateName();
void testFormulaRefUpdateNameMove(); void testFormulaRefUpdateNameMove();
void testFormulaRefUpdateNameExpandRef(); void testFormulaRefUpdateNameExpandRef();
void testFormulaRefUpdateNameDeleteRow();
void testFormulaRefUpdateValidity(); void testFormulaRefUpdateValidity();
void testMultipleOperations(); void testMultipleOperations();
void testFuncCOLUMN(); void testFuncCOLUMN();
...@@ -428,6 +429,7 @@ public: ...@@ -428,6 +429,7 @@ public:
CPPUNIT_TEST(testFormulaRefUpdateName); CPPUNIT_TEST(testFormulaRefUpdateName);
CPPUNIT_TEST(testFormulaRefUpdateNameMove); CPPUNIT_TEST(testFormulaRefUpdateNameMove);
CPPUNIT_TEST(testFormulaRefUpdateNameExpandRef); CPPUNIT_TEST(testFormulaRefUpdateNameExpandRef);
CPPUNIT_TEST(testFormulaRefUpdateNameDeleteRow);
CPPUNIT_TEST(testFormulaRefUpdateValidity); CPPUNIT_TEST(testFormulaRefUpdateValidity);
CPPUNIT_TEST(testMultipleOperations); CPPUNIT_TEST(testMultipleOperations);
CPPUNIT_TEST(testFuncCOLUMN); CPPUNIT_TEST(testFuncCOLUMN);
......
...@@ -2285,6 +2285,80 @@ void Test::testFormulaRefUpdateNameExpandRef() ...@@ -2285,6 +2285,80 @@ void Test::testFormulaRefUpdateNameExpandRef()
m_pDoc->DeleteTab(0); 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() void Test::testFormulaRefUpdateValidity()
{ {
struct { struct {
......
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