diff options
author | Kohei Yoshida <kohei.yoshida@gmail.com> | 2012-09-21 20:20:18 -0400 |
---|---|---|
committer | Kohei Yoshida <kohei.yoshida@gmail.com> | 2012-09-21 20:21:48 -0400 |
commit | cb7ee824dc0b9dcc2fd466f190945de01a9d1fa5 (patch) | |
tree | 1a9586b3f172d8a32873dbc0080bcee2f027e92f /sc | |
parent | 5551cd0209981f71ea5fb252b791391a6427066e (diff) |
Fixed all discovered errors and extra unit tests to cover them.
Change-Id: I1f91d66caed7fd3839f68f1e4495f0c05ee49acc
Diffstat (limited to 'sc')
-rw-r--r-- | sc/qa/unit/rangelst_test.cxx | 87 | ||||
-rw-r--r-- | sc/source/core/tool/rangelst.cxx | 46 |
2 files changed, 109 insertions, 24 deletions
diff --git a/sc/qa/unit/rangelst_test.cxx b/sc/qa/unit/rangelst_test.cxx index 70791665e36c..f6e1d53c2ff2 100644 --- a/sc/qa/unit/rangelst_test.cxx +++ b/sc/qa/unit/rangelst_test.cxx @@ -22,8 +22,12 @@ public: void testDeleteArea_4Ranges(); void testDeleteArea_3Ranges(); + void testDeleteArea_3Ranges_Case2(); + void testDeleteArea_3Ranges_Case3(); void testDeleteArea_2Ranges(); void testDeleteArea_2Ranges_Case2(); + void testDeleteArea_2Ranges_Case3(); + void testDeleteArea_2Ranges_Case4(); void testDeleteArea_1Range(); void testDeleteArea_0Ranges(); @@ -33,8 +37,12 @@ public: CPPUNIT_TEST_SUITE(Test); CPPUNIT_TEST(testDeleteArea_4Ranges); CPPUNIT_TEST(testDeleteArea_3Ranges); + CPPUNIT_TEST(testDeleteArea_3Ranges_Case2); + CPPUNIT_TEST(testDeleteArea_3Ranges_Case3); CPPUNIT_TEST(testDeleteArea_2Ranges); CPPUNIT_TEST(testDeleteArea_2Ranges_Case2); + CPPUNIT_TEST(testDeleteArea_2Ranges_Case3); + CPPUNIT_TEST(testDeleteArea_2Ranges_Case4); CPPUNIT_TEST(testDeleteArea_1Range); CPPUNIT_TEST(testDeleteArea_0Ranges); CPPUNIT_TEST(testUpdateReference_DeleteRow); @@ -105,6 +113,47 @@ void Test::testDeleteArea_3Ranges() CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(28), aList.GetCellCount()); } +void Test::testDeleteArea_3Ranges_Case2() +{ + ScRangeList aList(ScRange(1,1,0,6,6,0)); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), aList.size()); + aList.DeleteArea(0,2,0,2,4,0); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(3), aList.size()); + + // Column 1-2 && Row 2-4 should not be in the range list. The rest should + // be in the list. + for (SCCOL nCol = 1; nCol <= 6; ++nCol) + { + for (SCROW nRow = 1; nRow <= 6; ++nRow) + { + if ((1 <= nCol && nCol <= 2) && (2 <= nRow && nRow <= 4)) + CPPUNIT_ASSERT(!aList.In(ScRange(nCol, nRow, 0))); + else + CPPUNIT_ASSERT(aList.In(ScRange(nCol, nRow, 0))); + } + } +} + +void Test::testDeleteArea_3Ranges_Case3() +{ + ScRangeList aList(ScRange(1,5,0,6,11,0)); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), aList.size()); + aList.DeleteArea(3,2,0,4,8,0); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(3), aList.size()); + + // Column 3-4 && Row 5-8 should not be in the range list. + for (SCCOL nCol = 1; nCol <= 6; ++nCol) + { + for (SCROW nRow = 5; nRow <= 11; ++nRow) + { + if ((3 <= nCol && nCol <= 4) && (5 <= nRow && nRow <= 8)) + CPPUNIT_ASSERT(!aList.In(ScRange(nCol, nRow, 0))); + else + CPPUNIT_ASSERT(aList.In(ScRange(nCol, nRow, 0))); + } + } +} + void Test::testDeleteArea_2Ranges() { ScRangeList aList(ScRange(0,0,0,5,5,5)); @@ -142,6 +191,44 @@ void Test::testDeleteArea_2Ranges_Case2() CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(4), aList.GetCellCount()); } +void Test::testDeleteArea_2Ranges_Case3() +{ + ScRangeList aList(ScRange(0,5,0,2,10,0)); + aList.DeleteArea(2,3,0,3,7,0); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), aList.size()); + + // Column 2 Row 5-7 shouldn't be in the list. + for (SCCOL nCol = 0; nCol <= 2; ++nCol) + { + for (SCROW nRow = 5; nRow <= 10; ++nRow) + { + if (nCol == 2 && (5 <= nRow && nRow <= 7)) + CPPUNIT_ASSERT(!aList.In(ScRange(nCol,nRow,0))); + else + CPPUNIT_ASSERT(aList.In(ScRange(nCol,nRow,0))); + } + } +} + +void Test::testDeleteArea_2Ranges_Case4() +{ + ScRangeList aList(ScRange(2,3,0,4,7,0)); + aList.DeleteArea(0,1,0,2,5,0); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), aList.size()); + + // Column 2 Row 3-5 shouldn't be in the list. + for (SCCOL nCol = 2; nCol <= 4; ++nCol) + { + for (SCROW nRow = 3; nRow <= 7; ++nRow) + { + if (nCol == 2 && (3 <= nRow && nRow <= 5)) + CPPUNIT_ASSERT(!aList.In(ScRange(nCol,nRow,0))); + else + CPPUNIT_ASSERT(aList.In(ScRange(nCol,nRow,0))); + } + } +} + void Test::testDeleteArea_1Range() { ScRangeList aList(ScRange(1,1,0,3,3,0)); diff --git a/sc/source/core/tool/rangelst.cxx b/sc/source/core/tool/rangelst.cxx index b4b873255efd..96f7de528d76 100644 --- a/sc/source/core/tool/rangelst.cxx +++ b/sc/source/core/tool/rangelst.cxx @@ -517,6 +517,7 @@ bool handleOneRange( const ScRange& rDeleteRange, ScRange* p ) // +------+ (xxx) = deleted region p->aStart.SetRow(nDeleteRow1+1); + return true; } else if (nRow2 <= nDeleteRow2) { @@ -527,9 +528,8 @@ bool handleOneRange( const ScRange& rDeleteRange, ScRange* p ) // +------+ (xxx) = deleted region p->aEnd.SetRow(nDeleteRow1-1); + return true; } - - return true; } else if (checkForOneRange(nDeleteRow1, nDeleteRow2, nDeleteCol1, nDeleteCol2, nRow1, nRow2, nCol1, nCol2)) { @@ -543,6 +543,7 @@ bool handleOneRange( const ScRange& rDeleteRange, ScRange* p ) // +--+--+ (xxx) = deleted region p->aStart.SetCol(nDeleteCol2+1); + return true; } else if (nCol2 <= nDeleteCol2) { @@ -553,9 +554,8 @@ bool handleOneRange( const ScRange& rDeleteRange, ScRange* p ) // +--+--+ (xxx) = deleted region p->aEnd.SetCol(nDeleteCol1-1); + return true; } - - return true; } return false; } @@ -600,7 +600,7 @@ bool handleTwoRanges( const ScRange& rDeleteRange, ScRange* p, std::vector<ScRan SCROW nRow2 = aPEnd.Row(); SCTAB nTab = aPStart.Tab(); - if (nCol1 < nDeleteCol1 && nDeleteCol1 < nCol2 && nCol2 <= nDeleteCol2) + if (nCol1 < nDeleteCol1 && nDeleteCol1 <= nCol2 && nCol2 <= nDeleteCol2) { // column deleted : |-------| // column original: |-------| @@ -636,32 +636,30 @@ bool handleTwoRanges( const ScRange& rDeleteRange, ScRange* p, std::vector<ScRan // | 2 | (xxx) deleted region // +-------+ - ScRange aNewRange( aPStart, ScAddress( nCol1-1, nRow2, nTab ) ); // 1 (TODO: looks wrong) + ScRange aNewRange( aPStart, ScAddress(nDeleteCol1-1, nRow2, nTab) ); // 1 rNewRanges.push_back(aNewRange); p->aStart.SetRow(nDeleteRow2+1); // 2 return true; } } - else if (nCol1 < nDeleteCol2 && nDeleteCol2 < nCol2 && nDeleteCol1 <= nCol1) + else if (nCol1 <= nDeleteCol2 && nDeleteCol2 < nCol2 && nDeleteCol1 <= nCol1) { // column deleted : |-------| // column original: |-------| - if (nRow1 < nDeleteRow1 && nDeleteRow1 < nRow2) + if (nRow1 < nDeleteRow1 && nDeleteRow1 < nRow2 && nRow2 <= nDeleteRow2) { - // row deleted: |------| |--| - // row original: |------| or |--------| + // row deleted: |------| + // row original: |------| // - // +-------+ +-------+ - // | 1 | | | - // +-------+---+ +---+---+ | - // |xxxxxxx| 2 | or |xxxxxxx| | - // |xxxxxxx+---+ +---+---+ | - // |xxxxxxx| | | - // +-------+ +-------+ + // +-------+ + // | 1 | + // +-------+---+ + // |xxxxxxx| 2 | + // |xxxxxxx+---+ + // |xxxxxxx| + // +-------+ // (xxx) deleted region - // - // TODO: Is this correct especially on the second case? ScRange aNewRange( ScAddress( nDeleteCol2+1, nDeleteRow1, nTab ), aPEnd ); // 2 rNewRanges.push_back(aNewRange); @@ -669,7 +667,7 @@ bool handleTwoRanges( const ScRange& rDeleteRange, ScRange* p, std::vector<ScRan p->aEnd.SetRow(nDeleteRow1-1); // 1 return true; } - else if (nRow1 < nDeleteRow2 && nDeleteRow2 < nRow2) + else if (nRow1 < nDeleteRow2 && nDeleteRow2 < nRow2 && nDeleteRow1 <= nRow1) { // row deleted: |-------| // row original: |--------| @@ -682,7 +680,7 @@ bool handleTwoRanges( const ScRange& rDeleteRange, ScRange* p, std::vector<ScRan // | 2 | // +-------+ (xxx) deleted region - ScRange aNewRange( nDeleteCol2 +1, nRow1, nTab, nDeleteCol2, nDeleteRow2, nTab ); // 1 (TODO: this doesn't look right) + ScRange aNewRange(nDeleteCol2+1, nRow1, nTab, nCol2, nDeleteRow2, nTab); // 1 rNewRanges.push_back(aNewRange); p->aStart.SetRow(nDeleteRow2+1); // 2 @@ -808,10 +806,10 @@ bool handleThreeRanges( const ScRange& rDeleteRange, ScRange* p, std::vector<ScR // | 3 | | // +------+---+ - ScRange aNewRange(aPStart, ScAddress(nDeleteCol2-1, nDeleteRow1-1, nTab)); // 1 (TODO: End column should be nDeleteCol2.) + ScRange aNewRange(aPStart, ScAddress(nDeleteCol2, nDeleteRow1-1, nTab)); // 1 rNewRanges.push_back(aNewRange); - aNewRange = ScRange(nCol1, nDeleteRow2+1, nTab, nDeleteCol2+1, nRow2, nTab); // 3 (TODO: End column should be nDeleteCol2.) + aNewRange = ScRange(nCol1, nDeleteRow2+1, nTab, nDeleteCol2, nRow2, nTab); // 3 rNewRanges.push_back(aNewRange); p->aStart.SetCol(nDeleteCol2+1); // 2 @@ -854,7 +852,7 @@ bool handleThreeRanges( const ScRange& rDeleteRange, ScRange* p, std::vector<ScR ScRange aNewRange(aPStart, ScAddress(nDeleteCol1-1, nDeleteRow2, nTab)); // 1 rNewRanges.push_back(aNewRange); - aNewRange = ScRange(nDeleteCol2+1, nCol1, nTab, nCol2, nDeleteRow2, nTab); // 2 (TODO: start column should be nDeleteCol2+1.) + aNewRange = ScRange(nDeleteCol2+1, nRow1, nTab, nCol2, nDeleteRow2, nTab); // 2 rNewRanges.push_back( aNewRange ); p->aStart.SetRow(nDeleteRow2+1); // 3 |