diff options
author | Kohei Yoshida <kohei.yoshida@gmail.com> | 2013-06-26 23:06:02 -0400 |
---|---|---|
committer | Kohei Yoshida <kohei.yoshida@gmail.com> | 2013-06-27 15:50:06 -0400 |
commit | cfc732b858befd0f9102cb0161e9afde424dcecf (patch) | |
tree | df19c09f88aab911a3f5e7f53a89b3e4ac80a049 /sc/qa | |
parent | b5a195e65cd5de06e17e5a7aeb69024f8f8761c9 (diff) |
No need to increment formula row positions in InsertRow().
UpdateReference() which gets called before InsertRow() moves the formula
positions.
Change-Id: I6d00607a1a1b4463f69bb58610f6ba41871e4475
Diffstat (limited to 'sc/qa')
-rw-r--r-- | sc/qa/unit/ucalc.cxx | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx index 36c362837c0d..c66f3c0d40a5 100644 --- a/sc/qa/unit/ucalc.cxx +++ b/sc/qa/unit/ucalc.cxx @@ -237,6 +237,7 @@ public: void testUpdateReference(); void testSearchCells(); void testSharedFormulas(); + void testFormulaPosition(); /** * Make sure the sheet streams are invalidated properly. @@ -354,6 +355,7 @@ public: CPPUNIT_TEST(testUpdateReference); CPPUNIT_TEST(testSearchCells); CPPUNIT_TEST(testSharedFormulas); + CPPUNIT_TEST(testFormulaPosition); CPPUNIT_TEST(testJumpToPrecedentsDependents); CPPUNIT_TEST(testSetBackgroundColor); CPPUNIT_TEST(testRenameTable); @@ -6405,6 +6407,76 @@ void Test::testSharedFormulas() namespace { +bool checkFormulaPosition(ScDocument& rDoc, const ScAddress& rPos) +{ + OUString aStr; + rPos.Format(aStr, SCA_VALID); + const ScFormulaCell* pFC = rDoc.GetFormulaCell(rPos); + if (!pFC) + { + cerr << "Formula cell expected at " << aStr << " but not found." << endl; + return false; + } + + if (pFC->aPos != rPos) + { + OUString aStr2; + pFC->aPos.Format(aStr2, SCA_VALID); + cerr << "Formula cell at " << aStr << " has incorrect position of " << aStr2 << endl; + return false; + } + + return true; +} + +void checkFormulaPositions(ScDocument& rDoc, const ScAddress& rPos, const SCROW* pRows, size_t nRowCount) +{ + ScAddress aPos = rPos; + for (size_t i = 0; i < nRowCount; ++i) + { + SCROW nRow = pRows[i]; + aPos.SetRow(nRow); + + if (!checkFormulaPosition(rDoc, aPos)) + { + OUString aStr; + aPos.Format(aStr, SCA_VALID); + std::ostringstream os; + os << "Formula cell position failed at " << aStr; + CPPUNIT_FAIL(os.str().c_str()); + } + } +} + +} + +void Test::testFormulaPosition() +{ + m_pDoc->InsertTab(0, "Test"); + + ScAddress aPos(0,0,0); // A1 + m_pDoc->SetString(aPos, "=ROW()"); + aPos.IncRow(); // A2 + m_pDoc->SetString(aPos, "=ROW()"); + aPos.SetRow(3); // A4; + m_pDoc->SetString(aPos, "=ROW()"); + + { + SCROW aRows[] = { 0, 1, 3 }; + checkFormulaPositions(*m_pDoc, aPos, aRows, SAL_N_ELEMENTS(aRows)); + } + + m_pDoc->InsertRow(0,0,0,0,1,5); // Insert 5 rows at A2. + { + SCROW aRows[] = { 0, 6, 8 }; + checkFormulaPositions(*m_pDoc, aPos, aRows, SAL_N_ELEMENTS(aRows)); + } + + m_pDoc->DeleteTab(0); +} + +namespace { + bool hasRange(const std::vector<ScTokenRef>& rRefTokens, const ScRange& rRange) { std::vector<ScTokenRef>::const_iterator it = rRefTokens.begin(), itEnd = rRefTokens.end(); |