[Libreoffice-commits] .: sc/qa

Kohei Yoshida kohei at kemper.freedesktop.org
Mon Aug 13 12:07:30 PDT 2012


 sc/qa/unit/ucalc.cxx |   81 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 81 insertions(+)

New commits:
commit bf222b4985ca535903835980357687ae6e137ba1
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Mon Aug 13 15:07:56 2012 -0400

    Unit test for pivot table's text number field member output.
    
    Change-Id: Id7aa174fa26adb601ce652ba57c032e6b1c79dab

diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx
index 8a401e2..ea545f6 100644
--- a/sc/qa/unit/ucalc.cxx
+++ b/sc/qa/unit/ucalc.cxx
@@ -168,6 +168,7 @@ public:
     void testPivotTableNumberGrouping();
     void testPivotTableDateGrouping();
     void testPivotTableEmptyRows();
+    void testPivotTableTextNumber();
 
     void testSheetCopy();
     void testSheetMove();
@@ -239,6 +240,7 @@ public:
     CPPUNIT_TEST(testPivotTableNumberGrouping);
     CPPUNIT_TEST(testPivotTableDateGrouping);
     CPPUNIT_TEST(testPivotTableEmptyRows);
+    CPPUNIT_TEST(testPivotTableTextNumber);
     CPPUNIT_TEST(testSheetCopy);
     CPPUNIT_TEST(testSheetMove);
     CPPUNIT_TEST(testExternalRef);
@@ -2837,6 +2839,85 @@ void Test::testPivotTableEmptyRows()
     m_pDoc->DeleteTab(0);
 }
 
+void Test::testPivotTableTextNumber()
+{
+    m_pDoc->InsertTab(0, OUString("Data"));
+    m_pDoc->InsertTab(1, OUString("Table"));
+
+    // Raw data
+    const char* aData[][2] = {
+        { "Name", "Value" },
+        { "0001", "1" },
+        { "0002", "2" },
+        { "0003", "3" },
+        { "0004", "4" },
+    };
+
+    // Dimension definition
+    DPFieldDef aFields[] = {
+        { "Name", sheet::DataPilotFieldOrientation_ROW, 0 },
+        { "Value", sheet::DataPilotFieldOrientation_DATA, sheet::GeneralFunction_SUM },
+    };
+
+    // Insert raw data such that the first column values are entered as text.
+    size_t nRowCount = SAL_N_ELEMENTS(aData);
+    for (size_t nRow = 0; nRow < nRowCount; ++nRow)
+    {
+        ScSetStringParam aParam;
+        aParam.mbDetectNumberFormat = false;
+        aParam.meSetTextNumFormat = ScSetStringParam::Always;
+        m_pDoc->SetString(0, nRow, 0, OUString::createFromAscii(aData[nRow][0]), &aParam);
+        aParam.meSetTextNumFormat = ScSetStringParam::Never;
+        m_pDoc->SetString(1, nRow, 0, OUString::createFromAscii(aData[nRow][1]), &aParam);
+
+        if (nRow == 0)
+            // Don't check the header row.
+            continue;
+
+        // Check the data rows.
+        CPPUNIT_ASSERT_MESSAGE("This cell is supposed to be text.", m_pDoc->HasStringData(0, nRow, 0));
+        CPPUNIT_ASSERT_MESSAGE("This cell is supposed to be numeric.", m_pDoc->HasValueData(1, nRow, 0));
+    }
+
+    ScRange aDataRange(0, 0, 0, 1, 4, 0);
+
+    ScDPObject* pDPObj = createDPFromRange(
+        m_pDoc, aDataRange, aFields, SAL_N_ELEMENTS(aFields), false);
+
+    ScDPCollection* pDPs = m_pDoc->GetDPCollection();
+    bool bSuccess = pDPs->InsertNewTable(pDPObj);
+
+    CPPUNIT_ASSERT_MESSAGE("failed to insert a new pivot table object into document.", bSuccess);
+    CPPUNIT_ASSERT_MESSAGE("there should be only one data pilot table.",
+                           pDPs->GetCount() == 1);
+    pDPObj->SetName(pDPs->CreateNewName());
+
+    ScRange aOutRange = refresh(pDPObj);
+
+    {
+        // Expected output table content.  0 = empty cell
+        const char* aOutputCheck[][2] = {
+            { "Name", 0 },
+            { "0001", "1" },
+            { "0002", "2" },
+            { "0003", "3" },
+            { "0004", "4" },
+            { "Total Result", "10" },
+        };
+
+        bSuccess = checkDPTableOutput<2>(m_pDoc, aOutRange, aOutputCheck, "Text number field members");
+        CPPUNIT_ASSERT_MESSAGE("Table output check failed", bSuccess);
+    }
+
+    pDPs->FreeTable(pDPObj);
+    CPPUNIT_ASSERT_EQUAL_MESSAGE("There should be no more tables.", pDPs->GetCount(), static_cast<size_t>(0));
+    CPPUNIT_ASSERT_EQUAL_MESSAGE("There shouldn't be any more cache stored.",
+                                 pDPs->GetSheetCaches().size(), static_cast<size_t>(0));
+
+    m_pDoc->DeleteTab(1);
+    m_pDoc->DeleteTab(0);
+}
+
 void Test::testSheetCopy()
 {
     OUString aTabName("TestTab");


More information about the Libreoffice-commits mailing list