[Libreoffice-commits] .: sc/qa

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Mon Aug 27 10:06:28 PDT 2012


 sc/qa/unit/data/ods/pivot-table-basic.ods |binary
 sc/qa/unit/subsequent_filters-test.cxx    |   84 ++++++++++++++++++++++++++++++
 2 files changed, 84 insertions(+)

New commits:
commit 95379eb197b98c2ce6e2a29e970e60bf5c02385b
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Mon Aug 27 13:05:35 2012 -0400

    Add unit test for pivot table import from ods.
    
    Change-Id: I7e7bf5746636e0f13aaaec91d526ac59f6054796

diff --git a/sc/qa/unit/data/ods/pivot-table-basic.ods b/sc/qa/unit/data/ods/pivot-table-basic.ods
new file mode 100644
index 0000000..9bbb5fe
Binary files /dev/null and b/sc/qa/unit/data/ods/pivot-table-basic.ods differ
diff --git a/sc/qa/unit/subsequent_filters-test.cxx b/sc/qa/unit/subsequent_filters-test.cxx
index 126f7a5..a6387e6 100644
--- a/sc/qa/unit/subsequent_filters-test.cxx
+++ b/sc/qa/unit/subsequent_filters-test.cxx
@@ -48,10 +48,14 @@
 #include "cell.hxx"
 #include "drwlayer.hxx"
 #include "userdat.hxx"
+#include "dpobject.hxx"
+#include "dpsave.hxx"
 
 #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
 #include <com/sun/star/drawing/XControlShape.hpp>
 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
+#include <com/sun/star/sheet/DataPilotFieldOrientation.hpp>
+#include <com/sun/star/sheet/GeneralFunction.hpp>
 #include <com/sun/star/container/XIndexAccess.hpp>
 #include <com/sun/star/frame/XModel.hpp>
 
@@ -157,6 +161,8 @@ public:
 
     void testCellAnchoredShapesODS();
 
+    void testPivotTableBasicODS();
+
     CPPUNIT_TEST_SUITE(ScFiltersTest);
     CPPUNIT_TEST(testRangeNameXLS);
     CPPUNIT_TEST(testRangeNameXLSX);
@@ -196,6 +202,8 @@ public:
 
     CPPUNIT_TEST(testCellAnchoredShapesODS);
 
+    CPPUNIT_TEST(testPivotTableBasicODS);
+
     //disable testPassword on MacOSX due to problems with libsqlite3
     //also crashes on DragonFly due to problems with nss/nspr headers
 #if !defined(MACOSX) && !defined(DRAGONFLY) && !defined(WNT)
@@ -1389,6 +1397,82 @@ void ScFiltersTest::testCellAnchoredShapesODS()
     xDocSh->DoClose();
 }
 
+namespace {
+
+class FindDimByName : std::unary_function<const ScDPSaveDimension*, bool>
+{
+    OUString maName;
+public:
+    FindDimByName(const OUString& rName) : maName(rName) {}
+
+    bool operator() (const ScDPSaveDimension* p) const
+    {
+        return p && p->GetName() == maName;
+    }
+};
+
+bool hasDimension(const std::vector<const ScDPSaveDimension*>& rDims, const OUString& aName)
+{
+    return std::find_if(rDims.begin(), rDims.end(), FindDimByName(aName)) != rDims.end();
+}
+
+}
+
+void ScFiltersTest::testPivotTableBasicODS()
+{
+    OUString aFileNameBase("pivot-table-basic.");
+    OUString aFileExt = OUString::createFromAscii(aFileFormats[ODS].pName);
+    OUString aFilterName = OUString::createFromAscii(aFileFormats[ODS].pFilterName);
+    OUString aFilterType = OUString::createFromAscii(aFileFormats[ODS].pTypeName);
+
+    rtl::OUString aFileName;
+    createFileURL(aFileNameBase, aFileExt, aFileName);
+    ScDocShellRef xDocSh = load (aFilterName, aFileName, rtl::OUString(), aFilterType, aFileFormats[ODS].nFormatType);
+    CPPUNIT_ASSERT_MESSAGE("Failed to load pivot-table-basic.ods", xDocSh.Is());
+
+    ScDocument* pDoc = xDocSh->GetDocument();
+    CPPUNIT_ASSERT_MESSAGE("There should be exactly two sheets.", pDoc->GetTableCount() == 2);
+
+    ScDPCollection* pDPs = pDoc->GetDPCollection();
+    CPPUNIT_ASSERT_MESSAGE("Failed to get a live ScDPCollection instance.", pDPs);
+    CPPUNIT_ASSERT_MESSAGE("There should be exactly one pivot table instance.", pDPs->GetCount() == 1);
+
+    const ScDPObject* pDPObj = (*pDPs)[0];
+    CPPUNIT_ASSERT_MESSAGE("Failed to get an pivot table object.", pDPObj);
+    const ScDPSaveData* pSaveData = pDPObj->GetSaveData();
+    CPPUNIT_ASSERT_MESSAGE("Failed to get ScDPSaveData instance.", pSaveData);
+    std::vector<const ScDPSaveDimension*> aDims;
+
+    // Row fields
+    pSaveData->GetAllDimensionsByOrientation(sheet::DataPilotFieldOrientation_ROW, aDims);
+    CPPUNIT_ASSERT_MESSAGE("There should be exactly 3 row fields (2 normal dimensions and 1 layout dimension).", aDims.size() == 3);
+    CPPUNIT_ASSERT_MESSAGE("Dimension expected, but not found.", hasDimension(aDims, "Row1"));
+    CPPUNIT_ASSERT_MESSAGE("Dimension expected, but not found.", hasDimension(aDims, "Row2"));
+    const ScDPSaveDimension* pDataLayout = pSaveData->GetExistingDataLayoutDimension();
+    CPPUNIT_ASSERT_MESSAGE("There should be a data layout field as a row field.",
+                           pDataLayout && pDataLayout->GetOrientation() == sheet::DataPilotFieldOrientation_ROW);
+
+    // Column fields
+    pSaveData->GetAllDimensionsByOrientation(sheet::DataPilotFieldOrientation_COLUMN, aDims);
+    CPPUNIT_ASSERT_MESSAGE("There should be exactly 2 column fields.", aDims.size() == 2);
+    CPPUNIT_ASSERT_MESSAGE("Dimension expected, but not found.", hasDimension(aDims, "Col1"));
+    CPPUNIT_ASSERT_MESSAGE("Dimension expected, but not found.", hasDimension(aDims, "Col2"));
+
+    // Page fields
+    pSaveData->GetAllDimensionsByOrientation(sheet::DataPilotFieldOrientation_PAGE, aDims);
+    CPPUNIT_ASSERT_MESSAGE("There should be exactly 2 page fields.", aDims.size() == 2);
+    CPPUNIT_ASSERT_MESSAGE("Dimension expected, but not found.", hasDimension(aDims, "Page1"));
+    CPPUNIT_ASSERT_MESSAGE("Dimension expected, but not found.", hasDimension(aDims, "Page2"));
+
+    // Check the data field.
+    pSaveData->GetAllDimensionsByOrientation(sheet::DataPilotFieldOrientation_DATA, aDims);
+    CPPUNIT_ASSERT_MESSAGE("There should be exactly 1 data field.", aDims.size() == 1);
+    const ScDPSaveDimension* pDim = aDims.back();
+    CPPUNIT_ASSERT_MESSAGE("Function for the data field should be COUNT.", pDim->GetFunction() == sheet::GeneralFunction_COUNT);
+
+    xDocSh->DoClose();
+}
+
 void ScFiltersTest::testColorScale()
 {
     const rtl::OUString aFileNameBase(RTL_CONSTASCII_USTRINGPARAM("colorScale."));


More information about the Libreoffice-commits mailing list