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

Kohei Yoshida kohei.yoshida at collabora.com
Tue Jan 7 13:39:48 PST 2014


 sc/inc/dpcache.hxx                     |   12 +++++++++
 sc/inc/dpobject.hxx                    |    3 --
 sc/qa/unit/subsequent_filters-test.cxx |   43 +++++++++++++++++++++++++++++++++
 sc/source/core/data/dpcache.cxx        |   10 +++++++
 sc/source/core/data/dpobject.cxx       |    3 ++
 5 files changed, 69 insertions(+), 2 deletions(-)

New commits:
commit 331518c39551afa3c63d0c2fc394af0e9566aa43
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date:   Tue Jan 7 16:39:20 2014 -0500

    fdo#72774: Add test for group field cache population on file load.
    
    Change-Id: Iddde39da57db0d6be9f066f3e2bdb0526932edc6

diff --git a/sc/inc/dpcache.hxx b/sc/inc/dpcache.hxx
index 707749c..b35fa3b 100644
--- a/sc/inc/dpcache.hxx
+++ b/sc/inc/dpcache.hxx
@@ -139,6 +139,15 @@ public:
     void GetGroupDimMemberIds(long nDim, std::vector<SCROW>& rIds) const;
     void ClearGroupFields();
     const ScDPNumGroupInfo* GetNumGroupInfo(long nDim) const;
+
+    /**
+     * Return a group type identifier.  The values correspond with
+     * com::sun::star::sheet::DataPilotFieldGroupBy constant values.
+     *
+     * @param nDim 0-based dimension index.
+     *
+     * @return group type identifier, or 0 on failure.
+     */
     sal_Int32 GetGroupType(long nDim) const;
 
     SCCOL GetDimensionIndex(const OUString& sName) const;
@@ -163,6 +172,9 @@ public:
 
     const ScDPItemData* GetItemDataById( long nDim, SCROW nId ) const;
 
+    size_t GetFieldCount() const;
+    size_t GetGroupFieldCount() const;
+
     ScDPCache(ScDocument* pDoc);
     ~ScDPCache();
 
diff --git a/sc/inc/dpobject.hxx b/sc/inc/dpobject.hxx
index 6c0a64d..05a063d 100644
--- a/sc/inc/dpobject.hxx
+++ b/sc/inc/dpobject.hxx
@@ -287,8 +287,7 @@ public:
         void updateReference(
             UpdateRefMode eMode, const ScRange& r, SCsCOL nDx, SCsROW nDy, SCsTAB nDz);
 
-    private:
-        ScDPCache* getExistingCache(const ScRange& rRange);
+        SC_DLLPUBLIC ScDPCache* getExistingCache(const ScRange& rRange);
 
         void updateCache(const ScRange& rRange, std::set<ScDPObject*>& rRefs);
         bool remove(const ScDPCache* p);
diff --git a/sc/qa/unit/subsequent_filters-test.cxx b/sc/qa/unit/subsequent_filters-test.cxx
index 2bb1dff..fd0ae76 100644
--- a/sc/qa/unit/subsequent_filters-test.cxx
+++ b/sc/qa/unit/subsequent_filters-test.cxx
@@ -46,11 +46,13 @@
 #include "cellvalue.hxx"
 #include "attrib.hxx"
 #include "dpsave.hxx"
+#include "dpshttab.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/DataPilotFieldGroupBy.hpp>
 #include <com/sun/star/sheet/GeneralFunction.hpp>
 #include <com/sun/star/container/XIndexAccess.hpp>
 #include <com/sun/star/frame/XModel.hpp>
@@ -1718,6 +1720,47 @@ void ScFiltersTest::testPivotTableSharedCacheGroupODS()
     ScDPCollection::SheetCaches& rSheetCaches = pDPs->GetSheetCaches();
     CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), rSheetCaches.size());
 
+    // Make sure that the cache contains all group field data upon load.
+    const ScSheetSourceDesc* pDesc = pDPObj->GetSheetDesc();
+    CPPUNIT_ASSERT_MESSAGE("Failed to get the pivot source description instance.", pDesc);
+    const ScDPCache* pCache = rSheetCaches.getExistingCache(pDesc->GetSourceRange());
+    CPPUNIT_ASSERT_MESSAGE("Pivot cache should exist for this range.", pCache);
+
+    CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(9), pCache->GetFieldCount());
+    CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), pCache->GetGroupFieldCount());
+
+    SCCOL nDim = pCache->GetDimensionIndex("StartDate");
+    CPPUNIT_ASSERT_MESSAGE("Dimension 'StartDate' doesn't exist in the cache.", nDim >= 0);
+    sal_Int32 nGrpType = pCache->GetGroupType(nDim);
+    CPPUNIT_ASSERT_EQUAL(sheet::DataPilotFieldGroupBy::DAYS, nGrpType);
+    const ScDPNumGroupInfo* pInfo = pCache->GetNumGroupInfo(nDim);
+    CPPUNIT_ASSERT_MESSAGE("Number group info doesn't exist in cache for 'StartDate'.", pInfo);
+
+    // We should have two additional group fields and one should be years and
+    // the other should be month.  The order is not guaranteed.
+
+    bool bHasYears = false;
+    bool bHasMonths = false;
+
+    for (long nGrpDim = 9; nGrpDim <= 10; ++nGrpDim)
+    {
+        nGrpType = pCache->GetGroupType(nGrpDim);
+        switch (nGrpType)
+        {
+            case sheet::DataPilotFieldGroupBy::MONTHS:
+                bHasMonths = true;
+            break;
+            case sheet::DataPilotFieldGroupBy::YEARS:
+                bHasYears = true;
+            break;
+            default:
+                ;
+        }
+    }
+
+    CPPUNIT_ASSERT_MESSAGE("Pivot cache doesn't have an additional year group.", bHasYears);
+    CPPUNIT_ASSERT_MESSAGE("Pivot cache doesn't have an additional month group.", bHasMonths);
+
     xDocSh->DoClose();
 }
 
diff --git a/sc/source/core/data/dpcache.cxx b/sc/source/core/data/dpcache.cxx
index 49e5d8f..1226878 100644
--- a/sc/source/core/data/dpcache.cxx
+++ b/sc/source/core/data/dpcache.cxx
@@ -821,6 +821,16 @@ const ScDPItemData* ScDPCache::GetItemDataById(long nDim, SCROW nId) const
     return &rGI[nItemId];
 }
 
+size_t ScDPCache::GetFieldCount() const
+{
+    return maFields.size();
+}
+
+size_t ScDPCache::GetGroupFieldCount() const
+{
+    return maGroupFields.size();
+}
+
 SCROW ScDPCache::GetRowCount() const
 {
     return mnRowCount;
commit 256e4ccba8a331f2d30c6b5da9dca70206deadae
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date:   Tue Jan 7 16:36:55 2014 -0500

    fdo#72774: Ensure that all the group fields are in cache upon file load.
    
    This resolves the originally reported issue in that bug (in Comment 1).
    
    Change-Id: I6fb85cff1eafb78d784605aa08e7d992a1ac36e0

diff --git a/sc/source/core/data/dpobject.cxx b/sc/source/core/data/dpobject.cxx
index 72f0b73..de077db 100644
--- a/sc/source/core/data/dpobject.cxx
+++ b/sc/source/core/data/dpobject.cxx
@@ -2858,6 +2858,9 @@ const ScDPCache* ScDPCollection::SheetCaches::getCache(const ScRange& rRange, co
             return NULL;
         }
 
+        if (pDimData)
+            pDimData->WriteToCache(*itCache->second);
+
         return itCache->second;
     }
 


More information about the Libreoffice-commits mailing list