diff options
author | Tamás Zolnai <zolnaitamas2000@gmail.com> | 2016-11-19 22:47:06 +0100 |
---|---|---|
committer | Tamás Zolnai <tamas.zolnai@collabora.com> | 2016-11-20 00:14:40 +0100 |
commit | 92c1128fb80b4e38df219ce60f018cfb1522b20a (patch) | |
tree | 05d7b41108b3b186f2783fd086c02cc7e0c5d096 /sc | |
parent | 298ee50676b849020a8a5042e8612f71379ecf3b (diff) |
PivotMedian: ODS import / export of pivot table median
Change-Id: I3b018f5a76bb3d89bcb6cbc34e4cb2f2057248d5
Diffstat (limited to 'sc')
-rwxr-xr-x | sc/qa/unit/data/ods/pivot-table-median.ods | bin | 0 -> 13835 bytes | |||
-rw-r--r-- | sc/qa/unit/subsequent_export-test.cxx | 37 | ||||
-rw-r--r-- | sc/source/filter/xml/XMLConverter.cxx | 8 |
3 files changed, 44 insertions, 1 deletions
diff --git a/sc/qa/unit/data/ods/pivot-table-median.ods b/sc/qa/unit/data/ods/pivot-table-median.ods Binary files differnew file mode 100755 index 000000000000..bb88170003bc --- /dev/null +++ b/sc/qa/unit/data/ods/pivot-table-median.ods diff --git a/sc/qa/unit/subsequent_export-test.cxx b/sc/qa/unit/subsequent_export-test.cxx index dbab3ccca3d2..8d8183b9d411 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 5a5c529289d4..9cd60bb42f27 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; |