summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKohei Yoshida <kohei.yoshida@collabora.com>2014-08-29 18:07:29 -0400
committerKohei Yoshida <kohei.yoshida@collabora.com>2014-08-29 18:24:32 -0400
commit151d7a62230c98bb06628667170165f875788637 (patch)
tree90888233a66cc866880485bba01100b1d93b4aa3
parentf37c6e0d111c2237d422be07acbb67b7d0dcbbeb (diff)
Write test for importing and exporting of pivot table with 2 data fields.
This is for xlsx format. Change-Id: I8ef2ae41cc88eeeab610e1a89726c62acb9e2fcb
-rw-r--r--sc/qa/unit/data/xlsx/pivot-table/two-data-fields.xlsxbin0 -> 12287 bytes
-rw-r--r--sc/qa/unit/subsequent_export-test.cxx122
2 files changed, 122 insertions, 0 deletions
diff --git a/sc/qa/unit/data/xlsx/pivot-table/two-data-fields.xlsx b/sc/qa/unit/data/xlsx/pivot-table/two-data-fields.xlsx
new file mode 100644
index 000000000000..793af59d482f
--- /dev/null
+++ b/sc/qa/unit/data/xlsx/pivot-table/two-data-fields.xlsx
Binary files differ
diff --git a/sc/qa/unit/subsequent_export-test.cxx b/sc/qa/unit/subsequent_export-test.cxx
index d20bf7311d81..432bc753e02d 100644
--- a/sc/qa/unit/subsequent_export-test.cxx
+++ b/sc/qa/unit/subsequent_export-test.cxx
@@ -39,6 +39,7 @@
#include <dpcache.hxx>
#include <dpobject.hxx>
#include <dpsave.hxx>
+#include <dputil.hxx>
#include <svx/svdoole2.hxx>
#include "tabprotection.hxx"
@@ -122,6 +123,7 @@ public:
void testSheetProtection();
void testPivotTableXLSX();
+ void testPivotTableTwoDataFieldsXLSX();
CPPUNIT_TEST_SUITE(ScExportTest);
CPPUNIT_TEST(test);
@@ -160,6 +162,7 @@ public:
#endif
CPPUNIT_TEST(testSheetProtection);
CPPUNIT_TEST(testPivotTableXLSX);
+ CPPUNIT_TEST(testPivotTableTwoDataFieldsXLSX);
CPPUNIT_TEST(testFunctionsExcel2010ODS);
CPPUNIT_TEST_SUITE_END();
@@ -2121,6 +2124,125 @@ void ScExportTest::testPivotTableXLSX()
xDocSh2->DoClose();
}
+void ScExportTest::testPivotTableTwoDataFieldsXLSX()
+{
+ struct
+ {
+ bool check( const ScDocument& rDoc )
+ {
+ if (!rDoc.HasPivotTable())
+ {
+ cerr << "The document should have pivot table." << endl;
+ return false;
+ }
+
+ const ScDPCollection* pDPs = rDoc.GetDPCollection();
+ if (!pDPs)
+ {
+ cerr << "Pivot table container should exist." << endl;
+ return false;
+ }
+
+ ScRange aSrcRange(1,1,1,2,8,1); // B2:C9 on the 2nd sheet.
+ const ScDPCache* pCache = pDPs->GetSheetCaches().getExistingCache(aSrcRange);
+ if (!pCache)
+ {
+ cerr << "The document should have a pivot cache for B2:C9 on 'Src'." << endl;
+ return false;
+ }
+
+ const char* pNames[] = { "Name", "Value" };
+
+ size_t nCount = pCache->GetFieldCount();
+ if (nCount != SAL_N_ELEMENTS(pNames))
+ {
+ cout << "Incorrect number of fields in pivot cache." << endl;
+ return false;
+ }
+
+ const ScDPObject* pDPObj = rDoc.GetDPAtCursor(0,2,0); // A3
+ if (!pDPObj)
+ {
+ cerr << "A pivot table should exist over A3." << endl;
+ return false;
+ }
+
+ // Output range should be A3:C12.
+ ScRange aOutRange = pDPObj->GetOutRange();
+ if (ScRange(0,2,0,2,11,0) != aOutRange)
+ {
+ cerr << "Incorrect output range." << endl;
+ return false;
+ }
+
+ const ScDPSaveData* pSaveData = pDPObj->GetSaveData();
+ if (!pSaveData)
+ {
+ cerr << "Save data should exist in each pivot table object." << endl;
+ return false;
+ }
+
+ std::vector<const ScDPSaveDimension*> aDims;
+ pSaveData->GetAllDimensionsByOrientation(sheet::DataPilotFieldOrientation_ROW, aDims);
+ if (aDims.size() != 1 || aDims[0]->GetName() != "Name")
+ {
+ cerr << "Pivot table should have one row field labeld 'Name'" << endl;
+ return false;
+ }
+
+ pSaveData->GetAllDimensionsByOrientation(sheet::DataPilotFieldOrientation_DATA, aDims);
+ if (aDims.size() != 2 ||
+ ScDPUtil::getSourceDimensionName(aDims[0]->GetName()) != "Value" ||
+ ScDPUtil::getSourceDimensionName(aDims[1]->GetName()) != "Value")
+ {
+ cerr << "Pivot table should have two duplicated data fields both of which are named 'Value'." << endl;
+ return false;
+ }
+
+ if (aDims[0]->GetFunction() != sheet::GeneralFunction_SUM)
+ {
+ cerr << "First data field should be SUM." << endl;
+ return false;
+ }
+
+ if (aDims[1]->GetFunction() != sheet::GeneralFunction_COUNT)
+ {
+ cerr << "First data field should be COUNT." << endl;
+ return false;
+ }
+
+ pSaveData->GetAllDimensionsByOrientation(sheet::DataPilotFieldOrientation_COLUMN, aDims);
+ if (aDims.size() != 1 || !aDims[0]->IsDataLayout())
+ {
+ cerr << "Pivot table should have one column field which is a data layout field." << endl;
+ return false;
+ }
+
+ return true;
+ }
+
+ } aTest;
+
+ ScDocShellRef xDocSh = loadDoc("pivot-table/two-data-fields.", XLSX);
+ CPPUNIT_ASSERT(xDocSh.Is());
+ ScDocument* pDoc = &xDocSh->GetDocument();
+
+ // Initial check.
+ bool bCheck = aTest.check(*pDoc);
+ CPPUNIT_ASSERT_MESSAGE("Initial check failed.", bCheck);
+
+ ScDocShellRef xDocSh2 = saveAndReload(xDocSh, XLSX);
+ xDocSh->DoClose();
+ CPPUNIT_ASSERT(xDocSh2.Is());
+ pDoc = &xDocSh2->GetDocument();
+
+ // Reload check.
+ bCheck = aTest.check(*pDoc);
+ CPPUNIT_ASSERT_MESSAGE("Reload check failed.", bCheck);
+
+ xDocSh2->DoClose();
+}
+
void ScExportTest::testFunctionsExcel2010ODS()
{
//testFunctionsExcel2010(ODS);