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

Kohei Yoshida kohei.yoshida at collabora.com
Tue Jan 7 20:01:31 PST 2014


 sc/inc/dputil.hxx                      |    2 -
 sc/qa/unit/subsequent_filters-test.cxx |   57 +++++++++++++++++++++++++++++++++
 sc/source/core/data/dpdimsave.cxx      |    4 +-
 sc/source/core/data/dpgroup.cxx        |    2 -
 sc/source/core/data/dputil.cxx         |   13 ++++---
 5 files changed, 69 insertions(+), 9 deletions(-)

New commits:
commit fb7899e2423d26710200e46f66cf85894525afec
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date:   Tue Jan 7 23:00:19 2014 -0500

    fdo#72774: Write test to ensure correct group items in pivot cache on load.
    
    Change-Id: Ib9656b8e321a12a6f971f5775aaed235eac8df58

diff --git a/sc/qa/unit/subsequent_filters-test.cxx b/sc/qa/unit/subsequent_filters-test.cxx
index fd0ae76..220e6b4 100644
--- a/sc/qa/unit/subsequent_filters-test.cxx
+++ b/sc/qa/unit/subsequent_filters-test.cxx
@@ -1741,6 +1741,7 @@ void ScFiltersTest::testPivotTableSharedCacheGroupODS()
 
     bool bHasYears = false;
     bool bHasMonths = false;
+    std::vector<SCROW> aMemberIds;
 
     for (long nGrpDim = 9; nGrpDim <= 10; ++nGrpDim)
     {
@@ -1748,10 +1749,66 @@ void ScFiltersTest::testPivotTableSharedCacheGroupODS()
         switch (nGrpType)
         {
             case sheet::DataPilotFieldGroupBy::MONTHS:
+            {
                 bHasMonths = true;
+                aMemberIds.clear();
+                pCache->GetGroupDimMemberIds(nGrpDim, aMemberIds);
+
+                // There should be a total of 14 items for the month group: 12
+                // months plus the start and end value items.
+
+                CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(14), aMemberIds.size());
+
+                std::vector<sal_Int32> aGrpValues;
+                for (size_t i = 0, n = aMemberIds.size(); i < n; ++i)
+                {
+                    const ScDPItemData* pItem = pCache->GetItemDataById(nGrpDim, aMemberIds[i]);
+                    CPPUNIT_ASSERT_MESSAGE("Failed to get pivot item.", pItem);
+                    CPPUNIT_ASSERT_EQUAL(ScDPItemData::GroupValue, pItem->GetType());
+                    ScDPItemData::GroupValueAttr aGrpVal = pItem->GetGroupValue();
+                    CPPUNIT_ASSERT_EQUAL(sheet::DataPilotFieldGroupBy::MONTHS, aGrpVal.mnGroupType);
+                    aGrpValues.push_back(aGrpVal.mnValue);
+                }
+
+                std::sort(aGrpValues.begin(), aGrpValues.end());
+                std::vector<sal_Int32> aChecks;
+                aChecks.push_back(ScDPItemData::DateFirst);
+                for (sal_Int32 i = 1; i <= 12; ++i)
+                    aChecks.push_back(i); // January through December.
+                aChecks.push_back(ScDPItemData::DateLast);
+                CPPUNIT_ASSERT_MESSAGE("Unexpected group values for the month group.", aGrpValues == aChecks);
+            }
             break;
             case sheet::DataPilotFieldGroupBy::YEARS:
+            {
                 bHasYears = true;
+                aMemberIds.clear();
+                pCache->GetGroupDimMemberIds(nGrpDim, aMemberIds);
+
+                // There should be a total of 4 items and they should be 2012,
+                // 2013 and the start and end value items.
+
+                CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(4), aMemberIds.size());
+
+                std::vector<sal_Int32> aGrpValues;
+                for (size_t i = 0, n = aMemberIds.size(); i < n; ++i)
+                {
+                    const ScDPItemData* pItem = pCache->GetItemDataById(nGrpDim, aMemberIds[i]);
+                    CPPUNIT_ASSERT_MESSAGE("Failed to get pivot item.", pItem);
+                    CPPUNIT_ASSERT_EQUAL(ScDPItemData::GroupValue, pItem->GetType());
+                    ScDPItemData::GroupValueAttr aGrpVal = pItem->GetGroupValue();
+                    CPPUNIT_ASSERT_EQUAL(sheet::DataPilotFieldGroupBy::YEARS, aGrpVal.mnGroupType);
+                    aGrpValues.push_back(aGrpVal.mnValue);
+                }
+
+                std::sort(aGrpValues.begin(), aGrpValues.end());
+                std::vector<sal_Int32> aChecks;
+                aChecks.push_back(ScDPItemData::DateFirst);
+                aChecks.push_back(2012);
+                aChecks.push_back(2013);
+                aChecks.push_back(ScDPItemData::DateLast);
+                CPPUNIT_ASSERT_MESSAGE("Unexpected group values for the year group.", aGrpValues == aChecks);
+            }
             break;
             default:
                 ;
commit c2e88a32314012afb799e321ec1d658f99f71781
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date:   Tue Jan 7 22:13:07 2014 -0500

    fdo#72774: Generate correct group items for the year group.
    
    This changes bring it back to the same algorithm used in 3.5.
    
    Change-Id: I16855cef1de133a1f886baa823d5b0d2b148e781

diff --git a/sc/inc/dputil.hxx b/sc/inc/dputil.hxx
index e4ed831..9568e95 100644
--- a/sc/inc/dputil.hxx
+++ b/sc/inc/dputil.hxx
@@ -45,7 +45,7 @@ public:
         SvNumberFormatter* pFormatter);
 
     static sal_Int32 getDatePartValue(
-        double fValue, const ScDPNumGroupInfo& rInfo, sal_Int32 nDatePart,
+        double fValue, const ScDPNumGroupInfo* pInfo, sal_Int32 nDatePart,
         SvNumberFormatter* pFormatter);
 
     static OUString getDisplayedMeasureName(const OUString& rName, ScSubTotalFunc eFunc);
diff --git a/sc/source/core/data/dpdimsave.cxx b/sc/source/core/data/dpdimsave.cxx
index d200971..3f51268 100644
--- a/sc/source/core/data/dpdimsave.cxx
+++ b/sc/source/core/data/dpdimsave.cxx
@@ -337,8 +337,8 @@ void fillDateGroupDimension(
     {
         case sheet::DataPilotFieldGroupBy::YEARS:
             nStart = ScDPUtil::getDatePartValue(
-                fSourceMin, rDateInfo, sheet::DataPilotFieldGroupBy::YEARS, pFormatter);
-            nEnd = ScDPUtil::getDatePartValue(fSourceMax, rDateInfo, sheet::DataPilotFieldGroupBy::YEARS, pFormatter);
+                fSourceMin, NULL, sheet::DataPilotFieldGroupBy::YEARS, pFormatter);
+            nEnd = ScDPUtil::getDatePartValue(fSourceMax, NULL, sheet::DataPilotFieldGroupBy::YEARS, pFormatter);
             break;
         case sheet::DataPilotFieldGroupBy::QUARTERS: nStart = 1; nEnd = 4;   break;
         case sheet::DataPilotFieldGroupBy::MONTHS:   nStart = 1; nEnd = 12;  break;
diff --git a/sc/source/core/data/dpgroup.cxx b/sc/source/core/data/dpgroup.cxx
index f79a740..e5da799 100644
--- a/sc/source/core/data/dpgroup.cxx
+++ b/sc/source/core/data/dpgroup.cxx
@@ -911,7 +911,7 @@ void ScDPGroupTableData::FillGroupValues(vector<SCROW>& rItems, const vector<lon
             {
                 SvNumberFormatter* pFormatter = pDoc->GetFormatTable();
                 sal_Int32 nPartValue = ScDPUtil::getDatePartValue(
-                    pData->GetValue(), *pNumInfo, nDatePart, pFormatter);
+                    pData->GetValue(), pNumInfo, nDatePart, pFormatter);
 
                 ScDPItemData aItem(nDatePart, nPartValue);
                 rItems[i] = pCache->GetIdByItemData(nColumn, aItem);
diff --git a/sc/source/core/data/dputil.cxx b/sc/source/core/data/dputil.cxx
index 14b8639..73fc4d7 100644
--- a/sc/source/core/data/dputil.cxx
+++ b/sc/source/core/data/dputil.cxx
@@ -290,16 +290,19 @@ OUString ScDPUtil::getNumGroupName(
 }
 
 sal_Int32 ScDPUtil::getDatePartValue(
-    double fValue, const ScDPNumGroupInfo& rInfo, sal_Int32 nDatePart,
+    double fValue, const ScDPNumGroupInfo* pInfo, sal_Int32 nDatePart,
     SvNumberFormatter* pFormatter)
 {
     // Start and end are inclusive
     // (End date without a time value is included, with a time value it's not)
 
-    if (fValue < rInfo.mfStart && !rtl::math::approxEqual(fValue, rInfo.mfStart))
-        return ScDPItemData::DateFirst;
-    if (fValue > rInfo.mfEnd && !rtl::math::approxEqual(fValue, rInfo.mfEnd))
-        return ScDPItemData::DateLast;
+    if (pInfo)
+    {
+        if (fValue < pInfo->mfStart && !rtl::math::approxEqual(fValue, pInfo->mfStart))
+            return ScDPItemData::DateFirst;
+        if (fValue > pInfo->mfEnd && !rtl::math::approxEqual(fValue, pInfo->mfEnd))
+            return ScDPItemData::DateLast;
+    }
 
     sal_Int32 nResult = 0;
 


More information about the Libreoffice-commits mailing list