[Libreoffice-commits] .: 3 commits - sc/qa

Kohei Yoshida kohei at kemper.freedesktop.org
Mon Sep 19 19:44:29 PDT 2011


 sc/qa/unit/ucalc.cxx |  174 +++++++++++++++++++++++++--------------------------
 1 file changed, 87 insertions(+), 87 deletions(-)

New commits:
commit 7171daea4be16dd3298023349b771993e5b9fd0f
Author: Kohei Yoshida <kohei.yoshida at suse.com>
Date:   Mon Sep 19 22:43:20 2011 -0400

    Unit test for refreshing while source data contains empty field name.

diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx
index 6afc80b..45ae344 100644
--- a/sc/qa/unit/ucalc.cxx
+++ b/sc/qa/unit/ucalc.cxx
@@ -1098,9 +1098,8 @@ void Test::testDataPilot()
 
     // This time clear the cache to refresh the data from the source range.
     CPPUNIT_ASSERT_MESSAGE("This datapilot should be based on sheet data.", pDPObj2->IsSheetData());
-    ScDPCollection::SheetCaches& rCaches = pDPs->GetSheetCaches();
-    const ScSheetSourceDesc* pDesc = pDPObj2->GetSheetDesc();
-    rCaches.removeCache(pDesc->GetSourceRange());
+    sal_uLong nErrId = pDPs->ClearCache(pDPObj2);
+    CPPUNIT_ASSERT_MESSAGE("Cache removal failed.", nErrId == 0);
     pDPObj2->ClearSource();
     pDPObj2->Output(aOutRange.aStart);
 
@@ -1122,6 +1121,28 @@ void Test::testDataPilot()
         CPPUNIT_ASSERT_MESSAGE("Table output check failed", bSuccess);
     }
 
+    // Now, intentionally delete one of the field header names from the source range.
+    ScMarkData aMarkData;
+    aMarkData.SelectOneTable(0);
+    m_pDoc->DeleteArea(1, 0, 1, 0, aMarkData, IDF_CONTENTS);
+    printer.resize(nRow2 - nRow1 + 1, nCol2 - nCol1 + 1);
+    for (SCROW nRow = nRow1; nRow <= nRow2; ++nRow)
+    {
+        for (SCCOL nCol = nCol1; nCol <= nCol2; ++nCol)
+        {
+            String aVal;
+            m_pDoc->GetString(nCol, nRow, 0, aVal);
+            printer.set(nRow, nCol, aVal);
+        }
+    }
+    printer.print("Data sheet content (header removed)");
+    printer.clear();
+
+    // An attempt to clear the cache whose original data now has an invalid
+    // field name (empty name) should not succeed.
+    nErrId = pDPs->ClearCache(pDPObj2);
+    CPPUNIT_ASSERT_MESSAGE("Clearing the cache while the source data is invalid should not be allowed.", nErrId != 0);
+
     pDPs->FreeTable(pDPObj2);
     CPPUNIT_ASSERT_MESSAGE("There shouldn't be any data pilot table stored with the document.",
                            pDPs->GetCount() == 0);
commit 311dbc3b4ccd202c3ca0f8f1b577262f3f666e69
Author: Kohei Yoshida <kohei.yoshida at suse.com>
Date:   Mon Sep 19 22:16:54 2011 -0400

    Use the method to insert source data.

diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx
index fd46aaf..6afc80b 100644
--- a/sc/qa/unit/ucalc.cxx
+++ b/sc/qa/unit/ucalc.cxx
@@ -997,52 +997,21 @@ void Test::testDataPilot()
     };
 
     // Raw data
-    struct {
-        const char* pName; const char* pGroup; int nScore;
-    } aData[] = {
-        { "Andy",    "A", 30 },
-        { "Bruce",   "A", 20 },
-        { "Charlie", "B", 45 },
-        { "David",   "B", 12 },
-        { "Edward",  "C",  8 },
-        { "Frank",   "C", 15 },
+    const char* aData[][3] = {
+        { "Andy",    "A", "30" },
+        { "Bruce",   "A", "20" },
+        { "Charlie", "B", "45" },
+        { "David",   "B", "12" },
+        { "Edward",  "C",  "8" },
+        { "Frank",   "C", "15" },
     };
 
     size_t nFieldCount = SAL_N_ELEMENTS(aFields);
     size_t nDataCount = SAL_N_ELEMENTS(aData);
 
-    // Insert field names in row 0.
-    for (size_t i = 0; i < nFieldCount; ++i)
-        m_pDoc->SetString(static_cast<SCCOL>(i), 0, 0, OUString(aFields[i].pName, strlen(aFields[i].pName), RTL_TEXTENCODING_UTF8));
-
-    // Insert data into row 1 and downward.
-    for (size_t i = 0; i < nDataCount; ++i)
-    {
-        SCROW nRow = static_cast<SCROW>(i) + 1;
-        m_pDoc->SetString(0, nRow, 0, OUString(aData[i].pName, strlen(aData[i].pName), RTL_TEXTENCODING_UTF8));
-        m_pDoc->SetString(1, nRow, 0, OUString(aData[i].pGroup, strlen(aData[i].pGroup), RTL_TEXTENCODING_UTF8));
-        m_pDoc->SetValue(2, nRow, 0, aData[i].nScore);
-    }
-
-    SCROW nRow1 = 0, nRow2 = 0;
-    SCCOL nCol1 = 0, nCol2 = 0;
-    m_pDoc->GetDataArea(0, nCol1, nRow1, nCol2, nRow2, true, false);
-    CPPUNIT_ASSERT_MESSAGE("Data is expected to start from (col=0,row=0).", nCol1 == 0 && nRow1 == 0);
-    CPPUNIT_ASSERT_MESSAGE("Unexpected data range.",
-                           nCol2 == static_cast<SCCOL>(nFieldCount - 1) && nRow2 == static_cast<SCROW>(nDataCount));
-
-    SheetPrinter printer(nRow2 - nRow1 + 1, nCol2 - nCol1 + 1);
-    for (SCROW nRow = nRow1; nRow <= nRow2; ++nRow)
-    {
-        for (SCCOL nCol = nCol1; nCol <= nCol2; ++nCol)
-        {
-            String aVal;
-            m_pDoc->GetString(nCol, nRow, 0, aVal);
-            printer.set(nRow, nCol, aVal);
-        }
-    }
-    printer.print("Data sheet content");
-    printer.clear();
+    ScRange aSrcRange = insertDPSourceData(m_pDoc, aFields, nFieldCount, aData, nDataCount);
+    SCROW nRow1 = aSrcRange.aStart.Row(), nRow2 = aSrcRange.aEnd.Row();
+    SCCOL nCol1 = aSrcRange.aStart.Col(), nCol2 = aSrcRange.aEnd.Col();
 
     ScDPObject* pDPObj = createDPFromRange(
         m_pDoc, ScRange(nCol1, nRow1, 0, nCol2, nRow2, 0), aFields, nFieldCount, false);
@@ -1086,7 +1055,7 @@ void Test::testDataPilot()
         m_pDoc->SetValue(2, nRow, 0, aData2[i]);
     }
 
-    printer.resize(nRow2 - nRow1 + 1, nCol2 - nCol1 + 1);
+    SheetPrinter printer(nRow2 - nRow1 + 1, nCol2 - nCol1 + 1);
     for (SCROW nRow = nRow1; nRow <= nRow2; ++nRow)
     {
         for (SCCOL nCol = nCol1; nCol <= nCol2; ++nCol)
commit cd1c0800bff4e1b801950f4fe431e49ae766e074
Author: Kohei Yoshida <kohei.yoshida at suse.com>
Date:   Mon Sep 19 22:10:53 2011 -0400

    Extracted method for inserting source data for pivot table testing.

diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx
index e1c7da2..fd46aaf 100644
--- a/sc/qa/unit/ucalc.cxx
+++ b/sc/qa/unit/ucalc.cxx
@@ -802,7 +802,55 @@ void Test::testMatrix()
 
 namespace {
 
-template<int _Size>
+struct DPFieldDef
+{
+    const char* pName;
+    sheet::DataPilotFieldOrientation eOrient;
+};
+
+template<size_t _Size>
+ScRange insertDPSourceData(ScDocument* pDoc, DPFieldDef aFields[], size_t nFieldCount, const char* aData[][_Size], size_t nDataCount)
+{
+    // Insert field names in row 0.
+    for (size_t i = 0; i < nFieldCount; ++i)
+        pDoc->SetString(static_cast<SCCOL>(i), 0, 0, OUString(aFields[i].pName, strlen(aFields[i].pName), RTL_TEXTENCODING_UTF8));
+
+    // Insert data into row 1 and downward.
+    for (size_t i = 0; i < nDataCount; ++i)
+    {
+        SCROW nRow = static_cast<SCROW>(i) + 1;
+        for (size_t j = 0; j < nFieldCount; ++j)
+        {
+            SCCOL nCol = static_cast<SCCOL>(j);
+            pDoc->SetString(
+                nCol, nRow, 0, OUString(aData[i][j], strlen(aData[i][j]), RTL_TEXTENCODING_UTF8));
+        }
+    }
+
+    SCROW nRow1 = 0, nRow2 = 0;
+    SCCOL nCol1 = 0, nCol2 = 0;
+    pDoc->GetDataArea(0, nCol1, nRow1, nCol2, nRow2, true, false);
+    CPPUNIT_ASSERT_MESSAGE("Data is expected to start from (col=0,row=0).", nCol1 == 0 && nRow1 == 0);
+    CPPUNIT_ASSERT_MESSAGE("Unexpected data range.",
+                           nCol2 == static_cast<SCCOL>(nFieldCount - 1) && nRow2 == static_cast<SCROW>(nDataCount));
+
+    SheetPrinter printer(nRow2 - nRow1 + 1, nCol2 - nCol1 + 1);
+    for (SCROW nRow = nRow1; nRow <= nRow2; ++nRow)
+    {
+        for (SCCOL nCol = nCol1; nCol <= nCol2; ++nCol)
+        {
+            String aVal;
+            pDoc->GetString(nCol, nRow, 0, aVal);
+            printer.set(nRow, nCol, aVal);
+        }
+    }
+    printer.print("Data sheet content");
+    printer.clear();
+
+    return ScRange(nCol1, nRow1, 0, nCol2, nRow2, 0);
+}
+
+template<size_t _Size>
 bool checkDPTableOutput(ScDocument* pDoc, const ScRange& aOutRange, const char* aOutputCheck[][_Size], const char* pCaption)
 {
     const ScAddress& s = aOutRange.aStart;
@@ -839,12 +887,6 @@ bool checkDPTableOutput(ScDocument* pDoc, const ScRange& aOutRange, const char*
     return true;
 }
 
-struct DPFieldDef
-{
-    const char* pName;
-    sheet::DataPilotFieldOrientation eOrient;
-};
-
 ScDPObject* createDPFromRange(
     ScDocument* pDoc, const ScRange& rRange, DPFieldDef aFields[], size_t nFieldCount,
     bool bFilterButton)
@@ -1148,41 +1190,9 @@ void Test::testDataPilotFilters()
     size_t nFieldCount = SAL_N_ELEMENTS(aFields);
     size_t nDataCount = SAL_N_ELEMENTS(aData);
 
-    // Insert field names in row 0.
-    for (size_t i = 0; i < nFieldCount; ++i)
-        m_pDoc->SetString(static_cast<SCCOL>(i), 0, 0, OUString(aFields[i].pName, strlen(aFields[i].pName), RTL_TEXTENCODING_UTF8));
-
-    // Insert data into row 1 and downward.
-    for (size_t i = 0; i < nDataCount; ++i)
-    {
-        SCROW nRow = static_cast<SCROW>(i) + 1;
-        for (size_t j = 0; j < nFieldCount; ++j)
-        {
-            SCCOL nCol = static_cast<SCCOL>(j);
-            m_pDoc->SetString(
-                nCol, nRow, 0, OUString(aData[i][j], strlen(aData[i][j]), RTL_TEXTENCODING_UTF8));
-        }
-    }
-
-    SCROW nRow1 = 0, nRow2 = 0;
-    SCCOL nCol1 = 0, nCol2 = 0;
-    m_pDoc->GetDataArea(0, nCol1, nRow1, nCol2, nRow2, true, false);
-    CPPUNIT_ASSERT_MESSAGE("Data is expected to start from (col=0,row=0).", nCol1 == 0 && nRow1 == 0);
-    CPPUNIT_ASSERT_MESSAGE("Unexpected data range.",
-                           nCol2 == static_cast<SCCOL>(nFieldCount - 1) && nRow2 == static_cast<SCROW>(nDataCount));
-
-    SheetPrinter printer(nRow2 - nRow1 + 1, nCol2 - nCol1 + 1);
-    for (SCROW nRow = nRow1; nRow <= nRow2; ++nRow)
-    {
-        for (SCCOL nCol = nCol1; nCol <= nCol2; ++nCol)
-        {
-            String aVal;
-            m_pDoc->GetString(nCol, nRow, 0, aVal);
-            printer.set(nRow, nCol, aVal);
-        }
-    }
-    printer.print("Data sheet content");
-    printer.clear();
+    ScRange aSrcRange = insertDPSourceData(m_pDoc, aFields, nFieldCount, aData, nDataCount);
+    SCROW nRow1 = aSrcRange.aStart.Row(), nRow2 = aSrcRange.aEnd.Row();
+    SCCOL nCol1 = aSrcRange.aStart.Col(), nCol2 = aSrcRange.aEnd.Col();
 
     ScDPObject* pDPObj = createDPFromRange(
         m_pDoc, ScRange(nCol1, nRow1, 0, nCol2, nRow2, 0), aFields, nFieldCount, true);


More information about the Libreoffice-commits mailing list