[Libreoffice-commits] core.git: Branch 'feature/pivot_median' - sc/qa sc/source

Tamás Zolnai zolnaitamas2000 at gmail.com
Sat Nov 19 21:47:41 UTC 2016


Rebased ref, commits from common ancestor:
commit ad7d8ba4bf0affe7e11bef92743d47eb1b0c0294
Author: Tamás Zolnai <zolnaitamas2000 at gmail.com>
Date:   Sat Nov 19 22:47:06 2016 +0100

    PivotMedian: ODS import / export of pivot table median
    
    Change-Id: I3b018f5a76bb3d89bcb6cbc34e4cb2f2057248d5

diff --git a/sc/qa/unit/data/ods/pivot-table-median.ods b/sc/qa/unit/data/ods/pivot-table-median.ods
new file mode 100755
index 0000000..bb88170
Binary files /dev/null and b/sc/qa/unit/data/ods/pivot-table-median.ods differ
diff --git a/sc/qa/unit/subsequent_export-test.cxx b/sc/qa/unit/subsequent_export-test.cxx
index dbab3cc..8d8183b 100644
--- a/sc/qa/unit/subsequent_export-test.cxx
+++ b/sc/qa/unit/subsequent_export-test.cxx
@@ -149,6 +149,7 @@ public:
 
     void testPivotTableXLSX();
     void testPivotTableTwoDataFieldsXLSX();
+    void testPivotTableMedian();
 
     void testSwappedOutImageExport();
     void testLinkedGraphicRT();
@@ -238,6 +239,7 @@ public:
     CPPUNIT_TEST(testSheetProtection);
     CPPUNIT_TEST(testPivotTableXLSX);
     CPPUNIT_TEST(testPivotTableTwoDataFieldsXLSX);
+    CPPUNIT_TEST(testPivotTableMedian);
 #if !defined(_WIN32)
     CPPUNIT_TEST(testSupBookVirtualPath);
 #endif
@@ -2936,6 +2938,41 @@ void ScExportTest::testPivotTableTwoDataFieldsXLSX()
     xDocSh2->DoClose();
 }
 
+void ScExportTest::testPivotTableMedian()
+{
+    ScDocShellRef xDocSh = loadDoc("pivot-table-median.", FORMAT_ODS);
+    CPPUNIT_ASSERT_MESSAGE("Failed to load test document.", xDocSh.Is());
+
+    // Export the document and import again for a check
+    ScDocShellRef xDocSh2 = saveAndReload(xDocSh.get(), FORMAT_ODS);
+    xDocSh->DoClose();
+
+    // Check sheet
+    ScDocument& rDoc = xDocSh2->GetDocument();
+    CPPUNIT_ASSERT_EQUAL_MESSAGE("There should be exactly one sheet.", sal_Int16(1), rDoc.GetTableCount());
+
+    // Check pivot table
+    ScDPCollection* pDPs = rDoc.GetDPCollection();
+    CPPUNIT_ASSERT_MESSAGE("Failed to get a live ScDPCollection instance.", pDPs);
+    CPPUNIT_ASSERT_EQUAL_MESSAGE("There should be one pivot table instance.", size_t(1), pDPs->GetCount());
+    const ScDPObject* pDPObj = &(*pDPs)[0];
+    CPPUNIT_ASSERT_MESSAGE("Failed to get pivot table object.", pDPObj);
+    const ScDPSaveData* pSaveData = pDPObj->GetSaveData();
+    CPPUNIT_ASSERT_MESSAGE("Failed to get ScDPSaveData instance.", pSaveData);
+
+    // Check the data field function.
+    std::vector<const ScDPSaveDimension*> aDims;
+    pSaveData->GetAllDimensionsByOrientation(sheet::DataPilotFieldOrientation_DATA, aDims);
+    CPPUNIT_ASSERT_EQUAL_MESSAGE(
+        "There should be exactly 1 data field.",
+        std::vector<ScDPSaveDimension const *>::size_type(1), aDims.size());
+
+    const ScDPSaveDimension* pDim = aDims.back();
+    CPPUNIT_ASSERT_EQUAL_MESSAGE(
+        "Function for the data field should be COUNT.",
+        sal_uInt16(sheet::GeneralFunction_MEDIAN), pDim->GetFunction());
+}
+
 void ScExportTest::testFunctionsExcel2010ODS()
 {
     //testFunctionsExcel2010(FORMAT_ODS);
diff --git a/sc/source/filter/xml/XMLConverter.cxx b/sc/source/filter/xml/XMLConverter.cxx
index 5a5c529..9cd60bb 100644
--- a/sc/source/filter/xml/XMLConverter.cxx
+++ b/sc/source/filter/xml/XMLConverter.cxx
@@ -56,6 +56,8 @@ sheet::GeneralFunction ScXMLConverter::GetFunctionFromString( const OUString& sF
         return sheet::GeneralFunction_PRODUCT;
     if( IsXMLToken(sFunction, XML_AVERAGE ) )
         return sheet::GeneralFunction_AVERAGE;
+    if( IsXMLToken(sFunction, XML_MEDIAN ) )
+        return sheet::GeneralFunction_MEDIAN;
     if( IsXMLToken(sFunction, XML_MAX ) )
         return sheet::GeneralFunction_MAX;
     if( IsXMLToken(sFunction, XML_MIN ) )
@@ -83,6 +85,8 @@ ScSubTotalFunc ScXMLConverter::GetSubTotalFuncFromString( const OUString& sFunct
         return SUBTOTAL_FUNC_PROD;
     if( IsXMLToken(sFunction, XML_AVERAGE ) )
         return SUBTOTAL_FUNC_AVE;
+    if( IsXMLToken(sFunction, XML_MEDIAN ) )
+        return SUBTOTAL_FUNC_MED;
     if( IsXMLToken(sFunction, XML_MAX ) )
         return SUBTOTAL_FUNC_MAX;
     if( IsXMLToken(sFunction, XML_MIN ) )
@@ -107,6 +111,7 @@ void ScXMLConverter::GetStringFromFunction(
     {
         case sheet::GeneralFunction_AUTO:       sFuncStr = GetXMLToken( XML_AUTO );         break;
         case sheet::GeneralFunction_AVERAGE:    sFuncStr = GetXMLToken( XML_AVERAGE );      break;
+        case sheet::GeneralFunction_MEDIAN:     sFuncStr = GetXMLToken( XML_MEDIAN );       break;
         case sheet::GeneralFunction_COUNT:      sFuncStr = GetXMLToken( XML_COUNT );        break;
         case sheet::GeneralFunction_COUNTNUMS:  sFuncStr = GetXMLToken( XML_COUNTNUMS );    break;
         case sheet::GeneralFunction_MAX:        sFuncStr = GetXMLToken( XML_MAX );          break;
@@ -120,7 +125,7 @@ void ScXMLConverter::GetStringFromFunction(
         case sheet::GeneralFunction_VARP:       sFuncStr = GetXMLToken( XML_VARP );         break;
         default:
         {
-            // added to avoid warnings
+            assert(false);
         }
     }
     ScRangeStringConverter::AssignString( rString, sFuncStr, false );
@@ -134,6 +139,7 @@ void ScXMLConverter::GetStringFromFunction(
     switch( eFunction )
     {
         case SUBTOTAL_FUNC_AVE:     sFuncStr = GetXMLToken( XML_AVERAGE );      break;
+        case SUBTOTAL_FUNC_MED:     sFuncStr = GetXMLToken( XML_MEDIAN );       break;
         case SUBTOTAL_FUNC_CNT:     sFuncStr = GetXMLToken( XML_COUNT );        break;
         case SUBTOTAL_FUNC_CNT2:    sFuncStr = GetXMLToken( XML_COUNTNUMS );    break;
         case SUBTOTAL_FUNC_MAX:     sFuncStr = GetXMLToken( XML_MAX );          break;


More information about the Libreoffice-commits mailing list