diff options
author | Kohei Yoshida <kohei.yoshida@gmail.com> | 2013-06-25 11:06:43 -0400 |
---|---|---|
committer | Kohei Yoshida <kohei.yoshida@gmail.com> | 2013-06-25 11:08:52 -0400 |
commit | f9704bf73dfba50421132e5379165912a2779906 (patch) | |
tree | 198d884d819015565095498dfe19fc0543151975 /sc | |
parent | one more fix for mdds with msvc (diff) | |
download | core-f9704bf73dfba50421132e5379165912a2779906.tar.gz core-f9704bf73dfba50421132e5379165912a2779906.zip |
The horizontal cell iterator was *still* broken. Let's fix it again.
And add a test for it.
Change-Id: If76a67e02ac6ad5199d664850bd8591bd3032f32
Diffstat (limited to 'sc')
-rw-r--r-- | sc/qa/unit/ucalc.cxx | 122 | ||||
-rw-r--r-- | sc/source/core/data/dociter.cxx | 6 |
2 files changed, 90 insertions, 38 deletions
diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx index b29a89ea6361..462087a4a0f2 100644 --- a/sc/qa/unit/ucalc.cxx +++ b/sc/qa/unit/ucalc.cxx @@ -404,6 +404,12 @@ void printRange(ScDocument* pDoc, const ScRange& rRange, const char* pCaption) template<size_t _Size> ScRange insertRangeData(ScDocument* pDoc, const ScAddress& rPos, const char* aData[][_Size], size_t nRowCount) { + ScRange aRange(rPos); + aRange.aEnd.SetCol(rPos.Col()+_Size-1); + aRange.aEnd.SetRow(rPos.Row()+nRowCount-1); + + clearRange(pDoc, aRange); + for (size_t i = 0; i < _Size; ++i) { for (size_t j = 0; j < nRowCount; ++j) @@ -417,9 +423,6 @@ ScRange insertRangeData(ScDocument* pDoc, const ScAddress& rPos, const char* aDa } } - ScRange aRange(rPos); - aRange.aEnd.SetCol(rPos.Col()+_Size-1); - aRange.aEnd.SetRow(rPos.Row()+nRowCount-1); printRange(pDoc, aRange, "Range data content"); return aRange; } @@ -1785,48 +1788,97 @@ void Test::testVolatileFunc() m_pDoc->DeleteTab(0); } -void Test::testHorizontalIterator() -{ - m_pDoc->InsertTab(0, "test"); +namespace { - // Raw data - const char* aData[][2] = { - { "A", "B" }, - { "C", "1" }, - { "D", "2" }, - { "E", "3" } - }; +struct HoriIterCheck +{ + SCCOL nCol; + SCROW nRow; + const char* pVal; +}; +template<size_t _Size> +bool checkHorizontalIterator(ScDocument* pDoc, const char* pData[][_Size], size_t nDataCount, const HoriIterCheck* pChecks, size_t nCheckCount) +{ ScAddress aPos(0,0,0); - insertRangeData(m_pDoc, aPos, aData, SAL_N_ELEMENTS(aData)); - ScHorizontalCellIterator aIter(m_pDoc, 0, 0, 0, 1, SAL_N_ELEMENTS(aData)); - - struct { - SCCOL nCol; - SCROW nRow; - const char* pVal; - } aChecks[] = { - { 0, 0, "A" }, - { 1, 0, "B" }, - { 0, 1, "C" }, - { 1, 1, "1" }, - { 0, 2, "D" }, - { 1, 2, "2" }, - { 0, 3, "E" }, - { 1, 3, "3" }, - }; + insertRangeData(pDoc, aPos, pData, nDataCount); + ScHorizontalCellIterator aIter(pDoc, 0, 0, 0, 1, nDataCount-1); SCCOL nCol; SCROW nRow; - size_t i = 0, n = SAL_N_ELEMENTS(aChecks); + size_t i = 0; for (ScRefCellValue* pCell = aIter.GetNext(nCol, nRow); pCell; pCell = aIter.GetNext(nCol, nRow), ++i) { - if (i >= n) + if (i >= nCheckCount) CPPUNIT_FAIL("Iterator claims there is more data than there should be."); - CPPUNIT_ASSERT_EQUAL(aChecks[i].nCol, nCol); - CPPUNIT_ASSERT_EQUAL(aChecks[i].nRow, nRow); - CPPUNIT_ASSERT_EQUAL(OUString::createFromAscii(aChecks[i].pVal), pCell->getString()); + if (pChecks[i].nCol != nCol) + return false; + + if (pChecks[i].nRow != nRow) + return false; + + if (OUString::createFromAscii(pChecks[i].pVal) != pCell->getString()) + return false; + } + + return true; +} + +} + +void Test::testHorizontalIterator() +{ + m_pDoc->InsertTab(0, "test"); + + { + // Raw data + const char* aData[][2] = { + { "A", "B" }, + { "C", "1" }, + { "D", "2" }, + { "E", "3" } + }; + + HoriIterCheck aChecks[] = { + { 0, 0, "A" }, + { 1, 0, "B" }, + { 0, 1, "C" }, + { 1, 1, "1" }, + { 0, 2, "D" }, + { 1, 2, "2" }, + { 0, 3, "E" }, + { 1, 3, "3" }, + }; + + bool bRes = checkHorizontalIterator( + m_pDoc, aData, SAL_N_ELEMENTS(aData), aChecks, SAL_N_ELEMENTS(aChecks)); + + if (!bRes) + CPPUNIT_FAIL("Failed on test 1."); + } + + { + // Raw data + const char* aData[][2] = { + { "A", "B" }, + { "C", 0 }, + { "D", "E" }, + }; + + HoriIterCheck aChecks[] = { + { 0, 0, "A" }, + { 1, 0, "B" }, + { 0, 1, "C" }, + { 0, 2, "D" }, + { 1, 2, "E" }, + }; + + bool bRes = checkHorizontalIterator( + m_pDoc, aData, SAL_N_ELEMENTS(aData), aChecks, SAL_N_ELEMENTS(aChecks)); + + if (!bRes) + CPPUNIT_FAIL("Failed on test 2."); } m_pDoc->DeleteTab(0); diff --git a/sc/source/core/data/dociter.cxx b/sc/source/core/data/dociter.cxx index b5c36b8e7830..507656959ec4 100644 --- a/sc/source/core/data/dociter.cxx +++ b/sc/source/core/data/dociter.cxx @@ -1787,9 +1787,6 @@ void ScHorizontalCellIterator::Advance() if (r.maPos == r.maEnd) continue; - if (r.maPos->type == sc::element_type_empty) - continue; - size_t nRow = static_cast<size_t>(mnRow); if (nRow < r.maPos->position) continue; @@ -1798,6 +1795,9 @@ void ScHorizontalCellIterator::Advance() if (!advanceBlock(nRow, r.maPos, r.maEnd)) continue; + if (r.maPos->type == sc::element_type_empty) + continue; + // Found in the current row. mnCol = i; bMore = true; |