[Libreoffice-commits] core.git: Branch 'private/kohei/calc-shared-string' - 2 commits - sc/qa sc/source

Kohei Yoshida kohei.yoshida at collabora.com
Tue Oct 15 19:26:32 PDT 2013


 sc/qa/unit/ucalc_formula.cxx    |   90 ++++++++++++++++++++++++++++++++--------
 sc/source/core/data/column2.cxx |    9 ++--
 2 files changed, 78 insertions(+), 21 deletions(-)

New commits:
commit 62f8229ee3a05f82757d8bcae2f5c0f239955637
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date:   Tue Oct 15 22:27:57 2013 -0400

    Add helper functions for unit test & add new test that currently fails.
    
    Change-Id: I503fc26ccc0f117c626e78a8a1dd07ff32a06432

diff --git a/sc/qa/unit/ucalc_formula.cxx b/sc/qa/unit/ucalc_formula.cxx
index ba73d11..034e0e3 100644
--- a/sc/qa/unit/ucalc_formula.cxx
+++ b/sc/qa/unit/ucalc_formula.cxx
@@ -28,6 +28,44 @@
 
 using namespace formula;
 
+namespace {
+
+bool isEmpty( const formula::VectorRefArray& rArray, size_t nPos )
+{
+    if (rArray.mpStringArray)
+    {
+        if (rArray.mpStringArray[nPos])
+            return false;
+    }
+
+    if (rArray.mpNumericArray)
+        return rtl::math::isNan(rArray.mpNumericArray[nPos]);
+    else
+        return true;
+}
+
+bool equals( const formula::VectorRefArray& rArray, size_t nPos, double fVal )
+{
+    if (rArray.mpStringArray && rArray.mpStringArray[nPos])
+        // This is a string cell.
+        return false;
+
+    if (rArray.mpNumericArray && rArray.mpNumericArray[nPos] == fVal)
+        return true;
+
+    return false;
+}
+
+bool equals( const formula::VectorRefArray& rArray, size_t nPos, const OUString& rVal )
+{
+    if (!rArray.mpStringArray)
+        return false;
+
+    return OUString(rArray.mpStringArray[nPos]).equalsIgnoreAsciiCase(rVal);
+}
+
+}
+
 void Test::testFetchVectorRefArray()
 {
     m_pDoc->InsertTab(0, "Test");
@@ -54,7 +92,7 @@ void Test::testFetchVectorRefArray()
     CPPUNIT_ASSERT_EQUAL(2.0, aArray.mpNumericArray[1]);
     CPPUNIT_ASSERT_EQUAL(3.0, aArray.mpNumericArray[2]);
     CPPUNIT_ASSERT_EQUAL(4.0, aArray.mpNumericArray[3]);
-    CPPUNIT_ASSERT_MESSAGE("Empty cell should be represented by a NaN.", rtl::math::isNan(aArray.mpNumericArray[4]));
+    CPPUNIT_ASSERT_MESSAGE("This should be empty.", isEmpty(aArray, 4));
 
     // All string cells in Column B.  Note that the fetched string arrays are
     // only to be compared case-insensitively.  Right now, we use upper cased
@@ -67,11 +105,11 @@ void Test::testFetchVectorRefArray()
     aArray = m_pDoc->FetchVectorRefArray(aCxt, ScAddress(1,0,0), 5);
     CPPUNIT_ASSERT_MESSAGE("Failed to fetch vector ref array.", aArray.isValid());
     CPPUNIT_ASSERT_MESSAGE("Array is expected to be string cells only.", !aArray.mpNumericArray);
-    CPPUNIT_ASSERT_MESSAGE("Failed on case in-sensitive equality test.", OUString(aArray.mpStringArray[0]).equalsIgnoreAsciiCaseAscii("Andy"));
-    CPPUNIT_ASSERT_MESSAGE("Failed on case in-sensitive equality test.", OUString(aArray.mpStringArray[1]).equalsIgnoreAsciiCaseAscii("Bruce"));
-    CPPUNIT_ASSERT_MESSAGE("Failed on case in-sensitive equality test.", OUString(aArray.mpStringArray[2]).equalsIgnoreAsciiCaseAscii("Charlie"));
-    CPPUNIT_ASSERT_MESSAGE("Failed on case in-sensitive equality test.", OUString(aArray.mpStringArray[3]).equalsIgnoreAsciiCaseAscii("David"));
-    CPPUNIT_ASSERT_MESSAGE("Empty cell should be represented by a NULL pointer.", !aArray.mpStringArray[4]);
+    CPPUNIT_ASSERT_MESSAGE("Unexpected string cell.", equals(aArray, 0, "Andy"));
+    CPPUNIT_ASSERT_MESSAGE("Unexpected string cell.", equals(aArray, 1, "Bruce"));
+    CPPUNIT_ASSERT_MESSAGE("Unexpected string cell.", equals(aArray, 2, "Charlie"));
+    CPPUNIT_ASSERT_MESSAGE("Unexpected string cell.", equals(aArray, 3, "David"));
+    CPPUNIT_ASSERT_MESSAGE("This should be empty.", isEmpty(aArray, 4));
 
     // Mixture of numeric, string, and empty cells in Column C.
     m_pDoc->SetString(ScAddress(2,0,0), "Header");
@@ -84,17 +122,35 @@ void Test::testFetchVectorRefArray()
     aArray = m_pDoc->FetchVectorRefArray(aCxt, ScAddress(2,0,0), 7);
     CPPUNIT_ASSERT_MESSAGE("Failed to fetch vector ref array.", aArray.isValid());
     CPPUNIT_ASSERT_MESSAGE("Array should have both numeric and string arrays.", aArray.mpNumericArray && aArray.mpStringArray);
-    CPPUNIT_ASSERT_MESSAGE("Failed on case in-sensitive equality test.", OUString(aArray.mpStringArray[0]).equalsIgnoreAsciiCaseAscii("Header"));
-    CPPUNIT_ASSERT_MESSAGE("String value should be NULL for numeric cell.", aArray.mpStringArray[1] == NULL);
-    CPPUNIT_ASSERT_MESSAGE("String value should be NULL for numeric cell.", aArray.mpStringArray[2] == NULL);
-    CPPUNIT_ASSERT_MESSAGE("String value should be NULL for numeric cell.", aArray.mpStringArray[3] == NULL);
-    CPPUNIT_ASSERT_EQUAL(11.0, aArray.mpNumericArray[1]);
-    CPPUNIT_ASSERT_EQUAL(12.0, aArray.mpNumericArray[2]);
-    CPPUNIT_ASSERT_EQUAL(13.0, aArray.mpNumericArray[3]);
-    CPPUNIT_ASSERT_MESSAGE("This cell should be empty.", aArray.mpStringArray[4] == NULL && rtl::math::isNan(aArray.mpNumericArray[4]));
-    CPPUNIT_ASSERT_MESSAGE("String value should be NULL for numeric cell.", aArray.mpStringArray[5] == NULL);
-    CPPUNIT_ASSERT_EQUAL(36.0, aArray.mpNumericArray[5]);
-    CPPUNIT_ASSERT_MESSAGE("This cell should be empty.", aArray.mpStringArray[6] == NULL && rtl::math::isNan(aArray.mpNumericArray[6]));
+    CPPUNIT_ASSERT_MESSAGE("Unexpected string cell.", equals(aArray, 0, "Header"));
+    CPPUNIT_ASSERT_MESSAGE("Unexpected numeric cell.", equals(aArray, 1, 11));
+    CPPUNIT_ASSERT_MESSAGE("Unexpected numeric cell.", equals(aArray, 2, 12));
+    CPPUNIT_ASSERT_MESSAGE("Unexpected numeric cell.", equals(aArray, 3, 13));
+    CPPUNIT_ASSERT_MESSAGE("This should be empty.", isEmpty(aArray, 4));
+    CPPUNIT_ASSERT_MESSAGE("Unexpected numeric cell.", equals(aArray, 5, 36));
+    CPPUNIT_ASSERT_MESSAGE("This should be empty.", isEmpty(aArray, 6));
+
+    // Mixed type again in Column D, but it starts with a numeric cell.
+    m_pDoc->SetValue(ScAddress(3,0,0), 10);
+    m_pDoc->SetString(ScAddress(3,1,0), "Below 10");
+    // Leave 2 empty cells.
+    m_pDoc->SetValue(ScAddress(3,4,0), 11);
+    m_pDoc->SetString(ScAddress(3,5,0), "=12");
+    m_pDoc->SetString(ScAddress(3,6,0), "=13");
+    m_pDoc->SetString(ScAddress(3,7,0), "=CONCATENATE(\"A\";\"B\";\"C\")");
+    m_pDoc->CalcAll();
+
+    aArray = m_pDoc->FetchVectorRefArray(aCxt, ScAddress(3,0,0), 8);
+    CPPUNIT_ASSERT_MESSAGE("Failed to fetch vector ref array.", aArray.isValid());
+    CPPUNIT_ASSERT_MESSAGE("Array should have both numeric and string arrays.", aArray.mpNumericArray && aArray.mpStringArray);
+    CPPUNIT_ASSERT_MESSAGE("Unexpected numeric cell.", equals(aArray, 0, 10));
+    CPPUNIT_ASSERT_MESSAGE("Unexpected string cell.", equals(aArray, 1, "Below 10"));
+    CPPUNIT_ASSERT_MESSAGE("This should be empty.", isEmpty(aArray, 2));
+    CPPUNIT_ASSERT_MESSAGE("This should be empty.", isEmpty(aArray, 3));
+    CPPUNIT_ASSERT_MESSAGE("Unexpected numeric cell.", equals(aArray, 4, 11));
+    CPPUNIT_ASSERT_MESSAGE("Unexpected numeric cell.", equals(aArray, 5, 12));
+    CPPUNIT_ASSERT_MESSAGE("Unexpected numeric cell.", equals(aArray, 6, 13));
+    CPPUNIT_ASSERT_MESSAGE("Unexpected string cell.", equals(aArray, 7, "ABC"));
 
     m_pDoc->DeleteTab(0);
 }
commit f7fca147210f2b018e7d724f2b099bbfc834b325
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date:   Tue Oct 15 22:27:32 2013 -0400

    Cleanup.
    
    Change-Id: I3d6e3bceda23255a138340dcea3d847481216e73

diff --git a/sc/source/core/data/column2.cxx b/sc/source/core/data/column2.cxx
index 8fbfd1b..32a4ded 100644
--- a/sc/source/core/data/column2.cxx
+++ b/sc/source/core/data/column2.cxx
@@ -2178,7 +2178,7 @@ bool appendDouble(
     return false;
 }
 
-formula::VectorRefArray appendBlocks(
+formula::VectorRefArray appendToStringBlock(
     ScDocument* pDoc, sc::FormulaGroupContext& rCxt, size_t nPos,
     size_t nLenRequested, sc::CellStoreType::iterator it, const sc::CellStoreType::iterator& itEnd )
 {
@@ -2338,6 +2338,9 @@ formula::VectorRefArray ScColumn::FetchVectorRefArray( sc::FormulaGroupContext&
     if (nRow1 > nRow2)
         return formula::VectorRefArray();
 
+    double fNan;
+    rtl::math::setNan(&fNan);
+
     size_t nLenRequested = nRow2 - nRow1 + 1;
     sc::CellStoreType::position_type aPos = maCells.position(nRow1);
     size_t nLen = aPos.first->size - aPos.second;
@@ -2450,7 +2453,7 @@ formula::VectorRefArray ScColumn::FetchVectorRefArray( sc::FormulaGroupContext&
 
             // Fill the remaining array with values from the following blocks.
             ++aPos.first;
-            return appendBlocks(pDocument, rCxt, nLen, nLenRequested, aPos.first, maCells.end());
+            return appendToStringBlock(pDocument, rCxt, nLen, nLenRequested, aPos.first, maCells.end());
         }
         break;
         case sc::element_type_empty:
@@ -2458,8 +2461,6 @@ formula::VectorRefArray ScColumn::FetchVectorRefArray( sc::FormulaGroupContext&
             if (nLenRequested <= nLen)
             {
                 // Fill the whole length with NaN's.
-                double fNan;
-                rtl::math::setNan(&fNan);
                 rCxt.maNumArrays.push_back(new sc::FormulaGroupContext::NumArrayType(nLenRequested, fNan));
                 return formula::VectorRefArray(&rCxt.maNumArrays.back()[0]);
             }


More information about the Libreoffice-commits mailing list