[Libreoffice-commits] core.git: sc/qa sc/source

Kohei Yoshida kohei.yoshida at gmail.com
Tue Jun 25 08:06:38 PDT 2013


 sc/qa/unit/ucalc.cxx            |  122 ++++++++++++++++++++++++++++------------
 sc/source/core/data/dociter.cxx |    6 -
 2 files changed, 90 insertions(+), 38 deletions(-)

New commits:
commit f9704bf73dfba50421132e5379165912a2779906
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Tue Jun 25 11:06:43 2013 -0400

    The horizontal cell iterator was *still* broken. Let's fix it again.
    
    And add a test for it.
    
    Change-Id: If76a67e02ac6ad5199d664850bd8591bd3032f32

diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx
index b29a89e..462087a4 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 b5c36b8..5076569 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;


More information about the Libreoffice-commits mailing list