Bump version to 6.4-15
[LibreOffice.git] / chart2 / qa / extras / PivotChartTest.cxx
blobbafec060c31e2654b5ee72dcdd51323b4cbfb652
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
10 #include "charttest.hxx"
12 #include <com/sun/star/sheet/DataPilotFieldOrientation.hpp>
13 #include <com/sun/star/sheet/DataPilotFieldLayoutMode.hpp>
14 #include <com/sun/star/sheet/DataPilotFieldLayoutInfo.hpp>
15 #include <com/sun/star/sheet/XDataPilotTable.hpp>
16 #include <com/sun/star/sheet/XDataPilotDescriptor.hpp>
17 #include <com/sun/star/sheet/XDataPilotTables.hpp>
18 #include <com/sun/star/sheet/XDataPilotTablesSupplier.hpp>
19 #include <com/sun/star/sheet/XSpreadsheet.hpp>
20 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
21 #include <com/sun/star/sheet/XSpreadsheets.hpp>
22 #include <com/sun/star/table/XTablePivotCharts.hpp>
23 #include <com/sun/star/sheet/GeneralFunction.hpp>
24 #include <com/sun/star/util/XNumberFormatsSupplier.hpp>
25 #include <com/sun/star/util/XNumberFormatTypes.hpp>
26 #include <com/sun/star/util/NumberFormat.hpp>
28 #include <com/sun/star/chart2/data/XPivotTableDataProvider.hpp>
29 #include <com/sun/star/chart2/data/XTextualDataSequence.hpp>
31 namespace com { namespace sun { namespace star { namespace table { class XCellRange; } } } }
32 namespace com { namespace sun { namespace star { namespace util { class XNumberFormats; } } } }
34 class PivotChartTest : public ChartTest
36 public:
37 PivotChartTest() : ChartTest()
40 void testRoundtrip();
41 void testChangePivotTable();
42 void testPivotChartWithOneColumnField();
43 void testPivotChartWithOneRowField();
44 void testPivotTableDataProvider_PivotTableFields();
45 void testPivotChartRowFieldInOutlineMode();
46 void testPivotChartWithDateRowField();
48 CPPUNIT_TEST_SUITE(PivotChartTest);
49 CPPUNIT_TEST(testRoundtrip);
50 CPPUNIT_TEST(testChangePivotTable);
51 CPPUNIT_TEST(testPivotChartWithOneColumnField);
52 CPPUNIT_TEST(testPivotChartWithOneRowField);
53 CPPUNIT_TEST(testPivotTableDataProvider_PivotTableFields);
54 CPPUNIT_TEST(testPivotChartRowFieldInOutlineMode);
55 CPPUNIT_TEST(testPivotChartWithDateRowField);
56 CPPUNIT_TEST_SUITE_END();
59 namespace
62 void lclModifyOrientation(uno::Reference<sheet::XDataPilotDescriptor> const & xDescriptor,
63 OUString const & sFieldName,
64 sheet::DataPilotFieldOrientation eOrientation)
66 uno::Reference<container::XIndexAccess> xIndexAccess(xDescriptor->getDataPilotFields(), UNO_SET_THROW);
67 sal_Int32 nCount = xIndexAccess->getCount();
68 for (sal_Int32 i = 0; i < nCount; ++i)
70 uno::Reference<container::XNamed> xNamed(xIndexAccess->getByIndex(i), UNO_QUERY_THROW);
71 OUString aName = xNamed->getName();
72 uno::Reference<beans::XPropertySet> xPropSet(xNamed, UNO_QUERY_THROW);
73 if (aName == sFieldName)
74 xPropSet->setPropertyValue("Orientation", uno::makeAny(eOrientation));
78 void lclModifyFunction(uno::Reference<sheet::XDataPilotDescriptor> const & xDescriptor,
79 OUString const & sFieldName,
80 sheet::GeneralFunction eFunction)
82 uno::Reference<container::XIndexAccess> xPilotIndexAccess(xDescriptor->getDataPilotFields(), UNO_SET_THROW);
83 sal_Int32 nCount = xPilotIndexAccess->getCount();
84 for (sal_Int32 i = 0; i < nCount; ++i)
86 uno::Reference<container::XNamed> xNamed(xPilotIndexAccess->getByIndex(i), UNO_QUERY_THROW);
87 OUString aName = xNamed->getName();
88 uno::Reference<beans::XPropertySet> xPropSet(xNamed, UNO_QUERY_THROW);
89 if (aName == sFieldName)
90 xPropSet->setPropertyValue("Function", uno::makeAny(eFunction));
94 void lclModifyLayoutInfo(uno::Reference<sheet::XDataPilotDescriptor> const & xDescriptor,
95 OUString const & sFieldName,
96 sheet::DataPilotFieldLayoutInfo aLayoutInfo)
98 uno::Reference<container::XIndexAccess> xIndexAccess(xDescriptor->getDataPilotFields(), UNO_SET_THROW);
99 sal_Int32 nCount = xIndexAccess->getCount();
100 for (sal_Int32 i = 0; i < nCount; ++i)
102 uno::Reference<container::XNamed> xNamed(xIndexAccess->getByIndex(i), UNO_QUERY_THROW);
103 OUString aName = xNamed->getName();
104 uno::Reference<beans::XPropertySet> xPropSet(xNamed, UNO_QUERY_THROW);
105 if (aName == sFieldName)
107 uno::Any aValue;
108 aValue <<= aLayoutInfo;
109 xPropSet->setPropertyValue("LayoutInfo", aValue);
114 void lclModifySubtotals(uno::Reference<sheet::XDataPilotDescriptor> const & xDescriptor,
115 OUString const & sFieldName,
116 uno::Sequence<sheet::GeneralFunction> const & rSubtotalFunctions)
118 uno::Reference<container::XIndexAccess> xIndexAccess(xDescriptor->getDataPilotFields(), UNO_SET_THROW);
119 sal_Int32 nCount = xIndexAccess->getCount();
120 for (sal_Int32 i = 0; i < nCount; ++i)
122 uno::Reference<container::XNamed> xNamed(xIndexAccess->getByIndex(i), UNO_QUERY_THROW);
123 OUString aName = xNamed->getName();
124 uno::Reference<beans::XPropertySet> xPropSet(xNamed, UNO_QUERY_THROW);
125 if (aName == sFieldName)
127 uno::Any aValue;
128 aValue <<= rSubtotalFunctions;
129 xPropSet->setPropertyValue("Subtotals", aValue);
134 void lclModifyColumnGrandTotal(uno::Reference<sheet::XDataPilotDescriptor> const & xDataPilotDescriptor, bool bTotal)
136 uno::Reference<beans::XPropertySet> xProperties(xDataPilotDescriptor, uno::UNO_QUERY_THROW);
137 xProperties->setPropertyValue("ColumnGrand", uno::makeAny(bTotal));
140 void lclModifyRowGrandTotal(uno::Reference<sheet::XDataPilotDescriptor> const & xDataPilotDescriptor, bool bTotal)
142 uno::Reference<beans::XPropertySet> xProperties(xDataPilotDescriptor, uno::UNO_QUERY_THROW);
143 xProperties->setPropertyValue("RowGrand", uno::makeAny(bTotal));
146 void lclCheckSequence(std::vector<double> const & reference,
147 uno::Sequence<uno::Any> const & values,
148 double delta)
150 CPPUNIT_ASSERT_EQUAL(reference.size(), size_t(values.getLength()));
151 for (size_t i = 0; i < reference.size(); ++i)
153 CPPUNIT_ASSERT_DOUBLES_EQUAL(
154 reference[i], values[i].get<double>(), delta);
158 void lclCheckCategories(std::vector<OUString> const & reference,
159 uno::Reference<chart2::data::XDataSequence> const & xSequence)
161 uno::Reference<chart2::data::XTextualDataSequence> xTextualDataSequence(xSequence, uno::UNO_QUERY_THROW);
162 uno::Sequence<OUString> aText = xTextualDataSequence->getTextualData();
164 CPPUNIT_ASSERT_EQUAL(reference.size(), size_t(aText.getLength()));
165 for (size_t i = 0; i < reference.size(); ++i)
167 CPPUNIT_ASSERT_EQUAL(reference[i], aText[i]);
171 OUString lclGetLabel(Reference<chart2::XChartDocument> const & xChartDoc, sal_Int32 nSeriesIndex)
173 Reference<chart2::data::XDataSequence> xLabelDataSequence = getLabelDataSequenceFromDoc(xChartDoc, nSeriesIndex);
174 return xLabelDataSequence->getData()[0].get<OUString>();
177 uno::Reference<sheet::XDataPilotTable> lclGetPivotTableByName(sal_Int32 nIndex, OUString const & sPivotTableName,
178 uno::Reference<lang::XComponent> const & xComponent)
180 uno::Reference<sheet::XSpreadsheetDocument> xDoc(xComponent, UNO_QUERY_THROW);
181 uno::Reference<container::XIndexAccess> xSheetIndexAccess(xDoc->getSheets(), UNO_QUERY_THROW);
182 uno::Any aAny = xSheetIndexAccess->getByIndex(nIndex);
183 uno::Reference<sheet::XSpreadsheet> xSheet;
184 CPPUNIT_ASSERT(aAny >>= xSheet);
185 uno::Reference<sheet::XDataPilotTablesSupplier> xDataPilotTablesSupplier(xSheet, uno::UNO_QUERY_THROW);
186 uno::Reference<sheet::XDataPilotTables> xDataPilotTables = xDataPilotTablesSupplier->getDataPilotTables();
187 return uno::Reference<sheet::XDataPilotTable>(xDataPilotTables->getByName(sPivotTableName), UNO_QUERY_THROW);
190 uno::Sequence<uno::Reference<chart2::data::XLabeledDataSequence>>
191 lclGetCategories(Reference<chart2::XChartDocument> const & xChartDoc)
193 uno::Sequence<beans::PropertyValue> aArguments( comphelper::InitPropertySequence(
194 {{"CellRangeRepresentation", uno::Any(OUString("PT@categories"))}} ));
196 uno::Reference<chart2::data::XDataProvider> xDataProvider(xChartDoc->getDataProvider(), uno::UNO_SET_THROW);
197 return xDataProvider->createDataSource(aArguments)->getDataSequences();
200 struct Value
202 OUString maString;
203 double mfValue;
204 bool mbIsValue;
206 Value(OUString const & rString)
207 : maString(rString)
208 , mfValue(0.0)
209 , mbIsValue(false)
212 Value(double fValue)
213 : mfValue(fValue)
214 , mbIsValue(true)
218 uno::Reference< sheet::XDataPilotTables>
219 lclGetDataPilotTables(sal_Int32 nIndex, uno::Reference<sheet::XSpreadsheetDocument> const & xSheetDoc)
221 uno::Reference<sheet::XSpreadsheets> xSpreadsheets = xSheetDoc->getSheets();
222 uno::Reference<container::XIndexAccess> oIndexAccess(xSpreadsheets, uno::UNO_QUERY_THROW);
223 uno::Reference<sheet::XSpreadsheet> xSheet;
224 CPPUNIT_ASSERT(oIndexAccess->getByIndex(nIndex) >>= xSheet);
226 // create the test objects
227 uno::Reference< sheet::XDataPilotTablesSupplier> xDataPilotTablesSupplier(xSheet, uno::UNO_QUERY_THROW);
228 return xDataPilotTablesSupplier->getDataPilotTables();
231 table::CellRangeAddress lclCreateTestData(uno::Reference<sheet::XSpreadsheetDocument> const & xSheetDoc)
233 CPPUNIT_ASSERT_MESSAGE("no calc document!", xSheetDoc.is());
235 std::vector<OUString> aHeaders {
236 "Country", "City", "Type", "Sales T1", "Sales T2", "Sales T3", "Sales T4", "Date"
239 std::vector<std::vector<Value>> aData {
240 { {"FR"}, {"Paris"}, {"A"}, {123.0}, {223.0}, {323.0}, {423.0}, {"12/14/15"} },
241 { {"EN"}, {"London"}, {"A"}, {456.0}, {556.0}, {656.0}, {756.0}, {"12/11/15"} },
242 { {"DE"}, {"Berlin"}, {"A"}, {468.0}, {568.0}, {668.0}, {768.0}, {"12/11/15"} },
243 { {"FR"}, {"Nantes"}, {"A"}, {694.0}, {794.0}, {894.0}, {994.0}, {"12/11/15"} },
244 { {"EN"}, {"Glasgow"}, {"A"}, {298.0}, {398.0}, {498.0}, {598.0}, {"12/11/15"} },
245 { {"DE"}, {"Munich"}, {"A"}, {369.0}, {469.0}, {569.0}, {669.0}, {"12/11/15"} },
246 { {"FR"}, {"Paris"}, {"B"}, {645.0}, {745.0}, {845.0}, {945.0}, {"12/11/15"} },
247 { {"EN"}, {"London"}, {"B"}, {687.0}, {787.0}, {887.0}, {987.0}, {"03/21/17"} },
248 { {"DE"}, {"Munich"}, {"B"}, {253.0}, {353.0}, {453.0}, {553.0}, {"12/17/15"} },
249 { {"FR"}, {"Nantes"}, {"B"}, {474.0}, {574.0}, {674.0}, {774.0}, {"01/20/16"} },
250 { {"EN"}, {"Liverpool"}, {"B"}, {562.0}, {662.0}, {762.0}, {862.0}, {"01/20/16"} },
251 { {"DE"}, {"Berlin"}, {"B"}, {648.0}, {748.0}, {848.0}, {948.0}, {"01/20/16"} }
254 // Getting spreadsheet
255 uno::Reference<sheet::XSpreadsheets> xSpreadsheets = xSheetDoc->getSheets();
256 uno::Reference<container::XIndexAccess> oIndexAccess(xSpreadsheets, uno::UNO_QUERY_THROW);
257 uno::Reference<sheet::XSpreadsheet> xSheet;
258 CPPUNIT_ASSERT(oIndexAccess->getByIndex(0) >>= xSheet);
260 uno::Reference<sheet::XSpreadsheet> oPivotTableSheet;
261 xSpreadsheets->insertNewByName("Pivot Table", 1);
262 CPPUNIT_ASSERT(oIndexAccess->getByIndex(1) >>= oPivotTableSheet);
264 sal_Int32 currentRow = 0;
265 for (size_t column = 0; column < aHeaders.size(); ++column)
267 xSheet->getCellByPosition(column, currentRow)->setFormula(aHeaders[column]);
269 currentRow++;
271 for (std::vector<Value> const & rRowOfData : aData)
273 for (size_t column = 0; column < rRowOfData.size(); ++column)
275 Value const & rValue = rRowOfData[column];
276 uno::Reference<table::XCell> xCell(xSheet->getCellByPosition(column, currentRow));
277 if (rValue.mbIsValue)
278 xCell->setValue(rValue.mfValue);
279 else
280 xCell->setFormula(rValue.maString);
282 currentRow++;
285 sal_Int32 nEndCol = sal_Int32(aHeaders.size() - 1);
286 sal_Int32 nEndRow = sal_Int32(1/*HEADER*/ + aData.size() - 1);
288 // Apply date format to the last column
289 uno::Reference<util::XNumberFormatsSupplier> xNumberFormatsSupplier(xSheetDoc, UNO_QUERY_THROW);
290 uno::Reference<util::XNumberFormats> xNumberFormats = xNumberFormatsSupplier->getNumberFormats();
291 uno::Reference<util::XNumberFormatTypes> xNumberFormatTypes(xNumberFormats, UNO_QUERY_THROW);
292 lang::Locale aLocale;
293 sal_Int32 nDateKey = xNumberFormatTypes->getStandardFormat(util::NumberFormat::DATE, aLocale);
294 uno::Reference<table::XCellRange> xCellRange = xSheet->getCellRangeByPosition(nEndCol, 1, nEndCol, nEndRow);
295 uno::Reference<beans::XPropertySet> xCellProp(xCellRange, UNO_QUERY_THROW);
296 xCellProp->setPropertyValue("NumberFormat", uno::makeAny(nDateKey));
298 table::CellRangeAddress sCellRangeAdress;
299 sCellRangeAdress.Sheet = 0;
300 sCellRangeAdress.StartColumn = 0;
301 sCellRangeAdress.StartRow = 0;
302 sCellRangeAdress.EndColumn = nEndCol;
303 sCellRangeAdress.EndRow = nEndRow;
305 return sCellRangeAdress;
308 } // end anonymous namespace
310 void PivotChartTest::testRoundtrip()
312 uno::Sequence<uno::Any> xSequence;
313 Reference<chart2::XChartDocument> xChartDoc;
315 std::vector<double> aReference1 { 10162.033139, 16614.523063, 27944.146101 };
316 OUString const aExpectedLabel1("Exp.");
318 std::vector<double> aReference2 { 101879.458079, 178636.929704, 314626.484864 };
319 OUString const aExpectedLabel2("Rev.");
321 load("/chart2/qa/extras/data/ods/", "PivotChartRoundTrip.ods");
323 xChartDoc = getPivotChartDocFromSheet(1, mxComponent);
324 CPPUNIT_ASSERT(xChartDoc.is());
326 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), getNumberOfDataSeries(xChartDoc));
328 // Check the data series
330 xSequence = getDataSequenceFromDocByRole(xChartDoc, "values-y", 0)->getData();
331 lclCheckSequence(aReference1, xSequence, 1E-4);
332 CPPUNIT_ASSERT_EQUAL(aExpectedLabel1, lclGetLabel(xChartDoc, 0));
335 xSequence = getDataSequenceFromDocByRole(xChartDoc, "values-y", 1)->getData();
336 lclCheckSequence(aReference2, xSequence, 1E-4);
337 CPPUNIT_ASSERT_EQUAL(aExpectedLabel2, lclGetLabel(xChartDoc, 1));
340 // Modify the pivot table
342 uno::Reference<sheet::XDataPilotTable> xDataPilotTable = lclGetPivotTableByName(1, "DataPilot1", mxComponent);
343 uno::Reference<sheet::XDataPilotDescriptor> xDataPilotDescriptor(xDataPilotTable, UNO_QUERY_THROW);
344 lclModifyOrientation(xDataPilotDescriptor, "Exp.", sheet::DataPilotFieldOrientation_HIDDEN);
347 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), getNumberOfDataSeries(xChartDoc));
349 // Check again the data series
351 xSequence = getDataSequenceFromDocByRole(xChartDoc, "values-y", 0)->getData();
352 lclCheckSequence(aReference2, xSequence, 1E-4);
353 CPPUNIT_ASSERT_EQUAL(OUString("Total"), lclGetLabel(xChartDoc, 0));
356 reload("calc8");
358 xChartDoc = getPivotChartDocFromSheet(1, mxComponent);
359 CPPUNIT_ASSERT(xChartDoc.is());
361 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), getNumberOfDataSeries(xChartDoc));
363 // Check again the data series
365 xSequence = getDataSequenceFromDocByRole(xChartDoc, "values-y", 0)->getData();
366 lclCheckSequence(aReference2, xSequence, 1E-4);
367 CPPUNIT_ASSERT_EQUAL(OUString("Total"), lclGetLabel(xChartDoc, 0));
371 void PivotChartTest::testChangePivotTable()
373 uno::Sequence<uno::Any> xSequence;
374 Reference<chart2::XChartDocument> xChartDoc;
376 load("/chart2/qa/extras/data/ods/", "PivotTableExample.ods");
378 // Check we have the Pivot Table
379 OUString sPivotTableName("DataPilot1");
380 uno::Reference<sheet::XDataPilotTable> xDataPilotTable = lclGetPivotTableByName(1, sPivotTableName, mxComponent);
381 CPPUNIT_ASSERT(xDataPilotTable.is());
383 // Check that we don't have any pivot chart in the document
384 uno::Reference<table::XTablePivotCharts> xTablePivotCharts = getTablePivotChartsFromSheet(1, mxComponent);
385 uno::Reference<container::XIndexAccess> xIndexAccess(xTablePivotCharts, UNO_QUERY_THROW);
386 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xIndexAccess->getCount());
388 // Create a new pivot chart
389 xTablePivotCharts->addNewByName("Chart", awt::Rectangle{0, 0, 9000, 9000}, sPivotTableName);
390 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount());
392 // Get the pivot chart document so we can access its data
393 xChartDoc.set(getPivotChartDocFromSheet(xTablePivotCharts, 0));
395 CPPUNIT_ASSERT(xChartDoc.is());
397 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), getNumberOfDataSeries(xChartDoc));
399 // Check first data series
401 std::vector<double> aReference { 10162.033139, 16614.523063, 27944.146101 };
402 OUString const aExpectedLabel("Exp.");
404 xSequence = getDataSequenceFromDocByRole(xChartDoc, "values-y", 0)->getData();
405 lclCheckSequence(aReference, xSequence, 1E-4);
407 CPPUNIT_ASSERT_EQUAL(aExpectedLabel, lclGetLabel(xChartDoc, 0));
410 // Check second data series
412 std::vector<double> aReference { 101879.458079, 178636.929704, 314626.484864 };
413 OUString const aExpectedLabel("Rev.");
415 xSequence = getDataSequenceFromDocByRole(xChartDoc, "values-y", 1)->getData();
416 lclCheckSequence(aReference, xSequence, 1E-4);
418 CPPUNIT_ASSERT_EQUAL(aExpectedLabel, lclGetLabel(xChartDoc, 1));
421 // Modify the pivot table, move "Group Segment" to Column fields,
422 // add "Service Month" to Row fields, remove "Rev." Data field
424 uno::Reference<sheet::XDataPilotDescriptor> xDataPilotDescriptor(xDataPilotTable, UNO_QUERY_THROW);
426 lclModifyOrientation(xDataPilotDescriptor, "Service Month", sheet::DataPilotFieldOrientation_ROW);
427 lclModifyOrientation(xDataPilotDescriptor, "Group Segment", sheet::DataPilotFieldOrientation_COLUMN);
428 lclModifyOrientation(xDataPilotDescriptor, "Rev.", sheet::DataPilotFieldOrientation_HIDDEN);
431 // Check the pivot chart again as we expect it has been updated when we updated the pivot table
433 CPPUNIT_ASSERT_EQUAL(sal_Int32(3), getNumberOfDataSeries(xChartDoc));
435 // Check the first data series
437 std::vector<double> aReference { 2855.559, 1780.326, 2208.713, 2130.064, 1187.371 };
438 OUString const aExpectedLabel("Big");
440 xSequence = getDataSequenceFromDocByRole(xChartDoc, "values-y", 0)->getData();
441 lclCheckSequence(aReference, xSequence, 1E-3);
443 CPPUNIT_ASSERT_EQUAL(aExpectedLabel, lclGetLabel(xChartDoc, 0));
446 // Check the second data series
448 std::vector<double> aReference { 4098.908, 2527.286, 4299.716, 2362.225, 3326.389 };
449 OUString const aExpectedLabel("Medium");
451 xSequence = getDataSequenceFromDocByRole(xChartDoc, "values-y", 1)->getData();
452 lclCheckSequence(aReference, xSequence, 1E-3);
454 CPPUNIT_ASSERT_EQUAL(aExpectedLabel, lclGetLabel(xChartDoc, 1));
457 // Check the third data series
459 std::vector<double> aReference { 4926.303, 5684.060, 4201.398, 7290.795, 5841.591 };
460 OUString const aExpectedLabel("Small");
462 xSequence = getDataSequenceFromDocByRole(xChartDoc, "values-y", 2)->getData();
463 lclCheckSequence(aReference, xSequence, 1E-3);
465 CPPUNIT_ASSERT_EQUAL(aExpectedLabel, lclGetLabel(xChartDoc, 2));
468 // Remove "Service Month" so row fields are empty - check we handle empty rows
470 uno::Reference<sheet::XDataPilotDescriptor> xDataPilotDescriptor(xDataPilotTable, uno::UNO_QUERY_THROW);
471 lclModifyOrientation(xDataPilotDescriptor, "Service Month", sheet::DataPilotFieldOrientation_HIDDEN);
474 // Check the pivot chart again as we expect it has been updated when we updated the pivot table
476 CPPUNIT_ASSERT_EQUAL(sal_Int32(3), getNumberOfDataSeries(xChartDoc));
478 // Check the first data series
480 std::vector<double> aReference { 10162.033139 };
481 xSequence = getDataSequenceFromDocByRole(xChartDoc, "values-y", 0)->getData();
482 lclCheckSequence(aReference, xSequence, 1E-3);
483 CPPUNIT_ASSERT_EQUAL(OUString("Big"), lclGetLabel(xChartDoc, 0));
485 // Check the second data series
487 std::vector<double> aReference { 16614.523063 };
488 xSequence = getDataSequenceFromDocByRole(xChartDoc, "values-y", 1)->getData();
489 lclCheckSequence(aReference, xSequence, 1E-3);
490 CPPUNIT_ASSERT_EQUAL(OUString("Medium"), lclGetLabel(xChartDoc, 1));
492 // Check the third data series
494 std::vector<double> aReference { 27944.146101 };
495 xSequence = getDataSequenceFromDocByRole(xChartDoc, "values-y", 2)->getData();
496 lclCheckSequence(aReference, xSequence, 1E-3);
497 CPPUNIT_ASSERT_EQUAL(OUString("Small"), lclGetLabel(xChartDoc, 2));
500 // Enable column totals and check the data is still unchanged
502 uno::Reference<beans::XPropertySet> xProperties(xDataPilotTable, uno::UNO_QUERY_THROW);
503 xProperties->setPropertyValue("ColumnGrand", uno::makeAny(true));
506 CPPUNIT_ASSERT_EQUAL(sal_Int32(3), getNumberOfDataSeries(xChartDoc));
508 // Check the first data series
510 std::vector<double> aReference { 10162.033139 };
511 xSequence = getDataSequenceFromDocByRole(xChartDoc, "values-y", 0)->getData();
512 lclCheckSequence(aReference, xSequence, 1E-3);
513 CPPUNIT_ASSERT_EQUAL(OUString("Big"), lclGetLabel(xChartDoc, 0));
515 // Check the second data series
517 std::vector<double> aReference { 16614.523063 };
518 xSequence = getDataSequenceFromDocByRole(xChartDoc, "values-y", 1)->getData();
519 lclCheckSequence(aReference, xSequence, 1E-3);
520 CPPUNIT_ASSERT_EQUAL(OUString("Medium"), lclGetLabel(xChartDoc, 1));
522 // Check the third data series
524 std::vector<double> aReference { 27944.146101 };
525 xSequence = getDataSequenceFromDocByRole(xChartDoc, "values-y", 2)->getData();
526 lclCheckSequence(aReference, xSequence, 1E-3);
527 CPPUNIT_ASSERT_EQUAL(OUString("Small"), lclGetLabel(xChartDoc, 2));
531 void PivotChartTest::testPivotChartWithOneColumnField()
533 // We put one field as COLUMN field only and one DATA field. We expect we will get as many data series
534 // in the pivot table as many distinct column values we have (with this example data 3: DE, EN, FR).
536 // SETUP DATA and PIVOT TABLE
538 if (!mxComponent.is())
539 mxComponent = loadFromDesktop("private:factory/scalc");
541 uno::Reference<sheet::XSpreadsheetDocument> xSheetDoc(mxComponent, uno::UNO_QUERY_THROW);
543 OUString sPivotTableName("DataPilotTable");
545 table::CellRangeAddress sCellRangeAdress = lclCreateTestData(xSheetDoc);
547 uno::Reference<sheet::XDataPilotTables> xDataPilotTables = lclGetDataPilotTables(0, xSheetDoc);
549 uno::Reference<sheet::XDataPilotDescriptor> xDataPilotDescriptor = xDataPilotTables->createDataPilotDescriptor();
550 xDataPilotDescriptor->setSourceRange(sCellRangeAdress);
552 lclModifyOrientation(xDataPilotDescriptor, "Country", sheet::DataPilotFieldOrientation_COLUMN);
553 lclModifyOrientation(xDataPilotDescriptor, "Sales T1", sheet::DataPilotFieldOrientation_DATA);
554 lclModifyFunction(xDataPilotDescriptor, "Sales T1", sheet::GeneralFunction_SUM);
556 xDataPilotTables->insertNewByName(sPivotTableName, table::CellAddress{1, 0, 0}, xDataPilotDescriptor);
558 // TEST
560 uno::Sequence<uno::Any> xSequence;
561 Reference<chart2::XChartDocument> xChartDoc;
563 // Check we have the Pivot Table
565 uno::Reference<sheet::XDataPilotTable> xDataPilotTable = lclGetPivotTableByName(1, sPivotTableName, mxComponent);
566 CPPUNIT_ASSERT(xDataPilotTable.is());
568 // Check that we don't have any pivot chart in the document
569 uno::Reference<table::XTablePivotCharts> xTablePivotCharts = getTablePivotChartsFromSheet(1, mxComponent);
570 uno::Reference<container::XIndexAccess> xIndexAccess(xTablePivotCharts, UNO_QUERY_THROW);
571 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xIndexAccess->getCount());
573 // Create a new pivot chart
574 xTablePivotCharts->addNewByName("PivotChart", awt::Rectangle{ 9000, 9000, 21000, 18000 }, sPivotTableName);
575 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount());
577 // Get the pivot chart document so we can access its data
578 xChartDoc.set(getPivotChartDocFromSheet(xTablePivotCharts, 0));
580 CPPUNIT_ASSERT(xChartDoc.is());
582 CPPUNIT_ASSERT_EQUAL(sal_Int32(3), getNumberOfDataSeries(xChartDoc));
583 // Check data series 1
585 std::vector<double> aReference { 1738.0 };
586 OUString const aExpectedLabel("DE");
588 xSequence = getDataSequenceFromDocByRole(xChartDoc, "values-y", 0)->getData();
589 lclCheckSequence(aReference, xSequence, 1E-4);
591 CPPUNIT_ASSERT_EQUAL(aExpectedLabel, lclGetLabel(xChartDoc, 0));
594 // Check data series 2
596 std::vector<double> aReference { 2003.0 };
597 OUString const aExpectedLabel("EN");
599 xSequence = getDataSequenceFromDocByRole(xChartDoc, "values-y", 1)->getData();
600 lclCheckSequence(aReference, xSequence, 1E-4);
602 CPPUNIT_ASSERT_EQUAL(aExpectedLabel, lclGetLabel(xChartDoc, 1));
604 // Check data series 3
606 std::vector<double> aReference { 1936.0 };
607 OUString const aExpectedLabel("FR");
609 xSequence = getDataSequenceFromDocByRole(xChartDoc, "values-y", 2)->getData();
610 lclCheckSequence(aReference, xSequence, 1E-4);
612 CPPUNIT_ASSERT_EQUAL(aExpectedLabel, lclGetLabel(xChartDoc, 2));
616 void PivotChartTest::testPivotChartWithOneRowField()
618 // We put one field as ROW field only and one DATA field. We expect we will get one data series
619 // in the pivot table.
621 // SETUP DATA and PIVOT TABLE
623 if (!mxComponent.is())
624 mxComponent = loadFromDesktop("private:factory/scalc");
626 uno::Reference<sheet::XSpreadsheetDocument> xSheetDoc(mxComponent, uno::UNO_QUERY_THROW);
628 OUString sPivotTableName("DataPilotTable");
630 table::CellRangeAddress sCellRangeAdress = lclCreateTestData(xSheetDoc);
632 uno::Reference<sheet::XDataPilotTables> xDataPilotTables = lclGetDataPilotTables(0, xSheetDoc);
634 uno::Reference<sheet::XDataPilotDescriptor> xDataPilotDescriptor = xDataPilotTables->createDataPilotDescriptor();
635 xDataPilotDescriptor->setSourceRange(sCellRangeAdress);
637 lclModifyOrientation(xDataPilotDescriptor, "Country", sheet::DataPilotFieldOrientation_ROW);
638 lclModifyOrientation(xDataPilotDescriptor, "Sales T1", sheet::DataPilotFieldOrientation_DATA);
639 lclModifyFunction(xDataPilotDescriptor, "Sales T1", sheet::GeneralFunction_SUM);
641 xDataPilotTables->insertNewByName(sPivotTableName, table::CellAddress{1, 0, 0}, xDataPilotDescriptor);
643 // TEST
645 uno::Sequence<uno::Any> xSequence;
646 Reference<chart2::XChartDocument> xChartDoc;
648 // Check we have the Pivot Table
650 uno::Reference<sheet::XDataPilotTable> xDataPilotTable = lclGetPivotTableByName(1, sPivotTableName, mxComponent);
651 CPPUNIT_ASSERT(xDataPilotTable.is());
653 // Check that we don't have any pivot chart in the document
654 uno::Reference<table::XTablePivotCharts> xTablePivotCharts = getTablePivotChartsFromSheet(1, mxComponent);
655 uno::Reference<container::XIndexAccess> xIndexAccess(xTablePivotCharts, UNO_QUERY_THROW);
656 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xIndexAccess->getCount());
658 // Create a new pivot chart
659 xTablePivotCharts->addNewByName("PivotChart", awt::Rectangle{ 9000, 9000, 21000, 18000 }, sPivotTableName);
660 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount());
662 // Get the pivot chart document so we can access its data
663 xChartDoc.set(getPivotChartDocFromSheet(xTablePivotCharts, 0));
665 CPPUNIT_ASSERT(xChartDoc.is());
667 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), getNumberOfDataSeries(xChartDoc));
668 // Check data series 1
670 std::vector<double> aReference { 1738.0, 2003.0, 1936.0 };
671 OUString const aExpectedLabel("Total");
673 xSequence = getDataSequenceFromDocByRole(xChartDoc, "values-y", 0)->getData();
674 lclCheckSequence(aReference, xSequence, 1E-4);
676 CPPUNIT_ASSERT_EQUAL(aExpectedLabel, lclGetLabel(xChartDoc, 0));
680 void PivotChartTest::testPivotTableDataProvider_PivotTableFields()
682 // SETUP DATA and PIVOT TABLE
684 if (!mxComponent.is())
685 mxComponent = loadFromDesktop("private:factory/scalc");
687 uno::Reference<sheet::XSpreadsheetDocument> xSheetDoc(mxComponent, uno::UNO_QUERY_THROW);
689 OUString sPivotTableName("DataPilotTable");
691 table::CellRangeAddress sCellRangeAdress = lclCreateTestData(xSheetDoc);
693 uno::Reference<sheet::XDataPilotTables> xDataPilotTables = lclGetDataPilotTables(0, xSheetDoc);
695 uno::Reference<sheet::XDataPilotDescriptor> xDataPilotDescriptor = xDataPilotTables->createDataPilotDescriptor();
696 xDataPilotDescriptor->setSourceRange(sCellRangeAdress);
698 lclModifyOrientation(xDataPilotDescriptor, "City", sheet::DataPilotFieldOrientation_ROW);
699 lclModifyOrientation(xDataPilotDescriptor, "Country", sheet::DataPilotFieldOrientation_COLUMN);
700 lclModifyOrientation(xDataPilotDescriptor, "Type", sheet::DataPilotFieldOrientation_COLUMN);
701 lclModifyOrientation(xDataPilotDescriptor, "Sales T1", sheet::DataPilotFieldOrientation_DATA);
702 lclModifyFunction(xDataPilotDescriptor, "Sales T1", sheet::GeneralFunction_SUM);
703 lclModifyOrientation(xDataPilotDescriptor, "Sales T2", sheet::DataPilotFieldOrientation_DATA);
704 lclModifyFunction(xDataPilotDescriptor, "Sales T2", sheet::GeneralFunction_SUM);
706 lclModifyColumnGrandTotal(xDataPilotDescriptor, true);
707 lclModifyRowGrandTotal(xDataPilotDescriptor, true);
709 xDataPilotTables->insertNewByName(sPivotTableName, table::CellAddress{1, 0, 0}, xDataPilotDescriptor);
711 // TEST
712 Reference<chart2::XChartDocument> xChartDoc;
714 // Check we have the Pivot Table
715 uno::Reference<sheet::XDataPilotTable> xDataPilotTable = lclGetPivotTableByName(1, sPivotTableName, mxComponent);
716 CPPUNIT_ASSERT(xDataPilotTable.is());
718 // refetch the XDataPilotDescriptor
719 xDataPilotDescriptor.set(xDataPilotTable, uno::UNO_QUERY_THROW);
721 // Check that we don't have any pivot chart in the document
722 uno::Reference<table::XTablePivotCharts> xTablePivotCharts = getTablePivotChartsFromSheet(1, mxComponent);
723 uno::Reference<container::XIndexAccess> xIndexAccess(xTablePivotCharts, UNO_QUERY_THROW);
724 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xIndexAccess->getCount());
726 // Create a new pivot chart
727 xTablePivotCharts->addNewByName("PivotChart", awt::Rectangle{ 9000, 9000, 21000, 18000 }, sPivotTableName);
728 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount());
730 // Get the pivot chart document so we can access its data
731 xChartDoc.set(getPivotChartDocFromSheet(xTablePivotCharts, 0));
733 CPPUNIT_ASSERT(xChartDoc.is());
735 uno::Reference<chart2::data::XPivotTableDataProvider> xPivotTableDataProvider(xChartDoc->getDataProvider(), UNO_QUERY_THROW);
736 uno::Sequence<chart2::data::PivotTableFieldEntry> aFieldEntries;
738 aFieldEntries = xPivotTableDataProvider->getColumnFields();
740 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), aFieldEntries.getLength());
741 CPPUNIT_ASSERT_EQUAL(OUString("Country"), aFieldEntries[0].Name);
742 CPPUNIT_ASSERT_EQUAL(OUString("Type"), aFieldEntries[1].Name);
744 aFieldEntries = xPivotTableDataProvider->getRowFields();
746 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), aFieldEntries.getLength());
747 CPPUNIT_ASSERT_EQUAL(OUString("City"), aFieldEntries[0].Name);
748 CPPUNIT_ASSERT_EQUAL(OUString("Data"), aFieldEntries[1].Name);
750 aFieldEntries = xPivotTableDataProvider->getDataFields();
752 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), aFieldEntries.getLength());
753 CPPUNIT_ASSERT_EQUAL(OUString("Sum - Sales T1"), aFieldEntries[0].Name);
754 CPPUNIT_ASSERT_EQUAL(OUString("Sum - Sales T2"), aFieldEntries[1].Name);
756 // Data to column fields
757 lclModifyOrientation(xDataPilotDescriptor, "Data", sheet::DataPilotFieldOrientation_COLUMN);
759 // Change the order of column fields: expected data, type, country
760 lclModifyOrientation(xDataPilotDescriptor, "Country", sheet::DataPilotFieldOrientation_HIDDEN);
761 lclModifyOrientation(xDataPilotDescriptor, "Type", sheet::DataPilotFieldOrientation_HIDDEN);
763 lclModifyOrientation(xDataPilotDescriptor, "Type", sheet::DataPilotFieldOrientation_COLUMN);
764 lclModifyOrientation(xDataPilotDescriptor, "Country", sheet::DataPilotFieldOrientation_COLUMN);
766 // set the XPivotTableDataProvider again as the old one was exchanged
767 xPivotTableDataProvider.set(xChartDoc->getDataProvider(), uno::UNO_QUERY_THROW);
769 aFieldEntries = xPivotTableDataProvider->getColumnFields();
771 CPPUNIT_ASSERT_EQUAL(sal_Int32(3), aFieldEntries.getLength());
772 CPPUNIT_ASSERT_EQUAL(OUString("Data"), aFieldEntries[0].Name);
773 CPPUNIT_ASSERT_EQUAL(OUString("Type"), aFieldEntries[1].Name);
774 CPPUNIT_ASSERT_EQUAL(OUString("Country"), aFieldEntries[2].Name);
776 aFieldEntries = xPivotTableDataProvider->getRowFields();
778 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aFieldEntries.getLength());
779 CPPUNIT_ASSERT_EQUAL(OUString("City"), aFieldEntries[0].Name);
781 aFieldEntries = xPivotTableDataProvider->getDataFields();
783 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), aFieldEntries.getLength());
784 CPPUNIT_ASSERT_EQUAL(OUString("Sum - Sales T1"), aFieldEntries[0].Name);
785 CPPUNIT_ASSERT_EQUAL(OUString("Sum - Sales T2"), aFieldEntries[1].Name);
788 void PivotChartTest::testPivotChartRowFieldInOutlineMode()
790 // SETUP DATA and PIVOT TABLE
792 if (!mxComponent.is())
793 mxComponent = loadFromDesktop("private:factory/scalc");
795 uno::Reference<sheet::XSpreadsheetDocument> xSheetDoc(mxComponent, uno::UNO_QUERY_THROW);
797 OUString sPivotTableName("DataPilotTable");
799 table::CellRangeAddress sCellRangeAdress = lclCreateTestData(xSheetDoc);
801 uno::Reference<sheet::XDataPilotTables> xDataPilotTables = lclGetDataPilotTables(0, xSheetDoc);
803 uno::Reference<sheet::XDataPilotDescriptor> xDataPilotDescriptor = xDataPilotTables->createDataPilotDescriptor();
804 xDataPilotDescriptor->setSourceRange(sCellRangeAdress);
806 lclModifyOrientation(xDataPilotDescriptor, "Country", sheet::DataPilotFieldOrientation_ROW);
807 lclModifyOrientation(xDataPilotDescriptor, "City", sheet::DataPilotFieldOrientation_ROW);
808 lclModifyOrientation(xDataPilotDescriptor, "Sales T1", sheet::DataPilotFieldOrientation_DATA);
809 lclModifyFunction(xDataPilotDescriptor, "Sales T1", sheet::GeneralFunction_SUM);
810 xDataPilotTables->insertNewByName(sPivotTableName, table::CellAddress{1, 0, 0}, xDataPilotDescriptor);
812 // TEST
813 uno::Sequence<uno::Any> xSequence;
814 Reference<chart2::XChartDocument> xChartDoc;
816 // Check we have the Pivot Table
817 uno::Reference<sheet::XDataPilotTable> xDataPilotTable = lclGetPivotTableByName(1, sPivotTableName, mxComponent);
818 CPPUNIT_ASSERT(xDataPilotTable.is());
820 // refetch the XDataPilotDescriptor
821 xDataPilotDescriptor.set(xDataPilotTable, uno::UNO_QUERY_THROW);
823 // Check that we don't have any pivot chart in the document
824 uno::Reference<table::XTablePivotCharts> xTablePivotCharts = getTablePivotChartsFromSheet(1, mxComponent);
825 uno::Reference<container::XIndexAccess> xIndexAccess(xTablePivotCharts, UNO_QUERY_THROW);
826 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xIndexAccess->getCount());
828 // Create a new pivot chart
829 xTablePivotCharts->addNewByName("PivotChart", awt::Rectangle{ 9000, 9000, 21000, 18000 }, sPivotTableName);
830 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount());
832 // Get the pivot chart document so we can access its data
833 xChartDoc.set(getPivotChartDocFromSheet(xTablePivotCharts, 0));
835 CPPUNIT_ASSERT(xChartDoc.is());
837 // Test case with defaults
839 // Check when using defaults the data is as expected
840 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), getNumberOfDataSeries(xChartDoc));
842 std::vector<double> aReference { 1116.0, 622.0, 298.0, 562.0, 1143.0, 1168.0, 768.0 };
843 OUString const aExpectedLabel("Total");
845 xSequence = getDataSequenceFromDocByRole(xChartDoc, "values-y", 0)->getData();
846 lclCheckSequence(aReference, xSequence, 1E-4);
848 CPPUNIT_ASSERT_EQUAL(aExpectedLabel, lclGetLabel(xChartDoc, 0));
850 // Check the categories
852 lclCheckCategories({ "DE", "", "EN", "", "", "FR", ""},
853 lclGetCategories(xChartDoc)[0]->getValues());
854 lclCheckCategories({ "Berlin", "Munich", "Glasgow", "Liverpool", "London", "Nantes", "Paris"},
855 lclGetCategories(xChartDoc)[1]->getValues());
858 sheet::DataPilotFieldLayoutInfo aLayoutInfoValue;
859 uno::Sequence<sheet::GeneralFunction> aGeneralFunctionSequence(1);
861 // Test case where we enable subtotals (auto) and set the outline subtotals at the bottom
862 // We don't expect any change in data as every extra subtotal row should be ignored
864 // Enable subtotals - set to auto
865 aGeneralFunctionSequence[0] = sheet::GeneralFunction_AUTO;
866 lclModifySubtotals(xDataPilotDescriptor, "Country", aGeneralFunctionSequence);
867 // Set Subtotals layout to bottom + add empty lines
868 aLayoutInfoValue.AddEmptyLines = true;
869 aLayoutInfoValue.LayoutMode = sheet::DataPilotFieldLayoutMode::OUTLINE_SUBTOTALS_BOTTOM;
870 lclModifyLayoutInfo(xDataPilotDescriptor, "Country", aLayoutInfoValue);
872 // Check data is unchanged
873 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), getNumberOfDataSeries(xChartDoc));
875 std::vector<double> aReference { 1116.0, 622.0, 298.0, 562.0, 1143.0, 1168.0, 768.0 };
876 OUString const aExpectedLabel("Total");
878 xSequence = getDataSequenceFromDocByRole(xChartDoc, "values-y", 0)->getData();
879 lclCheckSequence(aReference, xSequence, 1E-4);
881 CPPUNIT_ASSERT_EQUAL(aExpectedLabel, lclGetLabel(xChartDoc, 0));
883 // Check categories
885 lclCheckCategories({ "DE", "", "EN", "", "", "FR", ""},
886 lclGetCategories(xChartDoc)[0]->getValues());
887 lclCheckCategories({ "Berlin", "Munich", "Glasgow", "Liverpool", "London", "Nantes", "Paris"},
888 lclGetCategories(xChartDoc)[1]->getValues());
891 // Test case where we enable subtotals (auto) and set the outline subtotals at the top
892 // We don't expect any change in data as every extra subtotal row should be ignored
894 // Enable subtotals - set to auto
895 aGeneralFunctionSequence[0] = sheet::GeneralFunction_AUTO;
896 lclModifySubtotals(xDataPilotDescriptor, "Country", aGeneralFunctionSequence);
897 // Set Subtotals layout to top + add empty lines
898 aLayoutInfoValue.AddEmptyLines = true;
899 aLayoutInfoValue.LayoutMode = sheet::DataPilotFieldLayoutMode::OUTLINE_SUBTOTALS_TOP;
900 lclModifyLayoutInfo(xDataPilotDescriptor, "Country", aLayoutInfoValue);
902 // Check data is unchanged
903 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), getNumberOfDataSeries(xChartDoc));
905 std::vector<double> aReference { 1116.0, 622.0, 298.0, 562.0, 1143.0, 1168.0, 768.0 };
906 OUString const aExpectedLabel("Total");
908 xSequence = getDataSequenceFromDocByRole(xChartDoc, "values-y", 0)->getData();
909 lclCheckSequence(aReference, xSequence, 1E-4);
911 CPPUNIT_ASSERT_EQUAL(aExpectedLabel, lclGetLabel(xChartDoc, 0));
913 // Check categories
915 lclCheckCategories({ "DE", "", "EN", "", "", "FR", ""},
916 lclGetCategories(xChartDoc)[0]->getValues());
917 lclCheckCategories({ "Berlin", "Munich", "Glasgow", "Liverpool", "London", "Nantes", "Paris"},
918 lclGetCategories(xChartDoc)[1]->getValues());
922 void PivotChartTest::testPivotChartWithDateRowField()
924 // SETUP DATA and PIVOT TABLE
926 if (!mxComponent.is())
927 mxComponent = loadFromDesktop("private:factory/scalc");
929 uno::Reference<sheet::XSpreadsheetDocument> xSheetDoc(mxComponent, uno::UNO_QUERY_THROW);
931 OUString sPivotTableName("DataPilotTable");
933 table::CellRangeAddress sCellRangeAdress = lclCreateTestData(xSheetDoc);
935 uno::Reference<sheet::XDataPilotTables> xDataPilotTables = lclGetDataPilotTables(0, xSheetDoc);
937 uno::Reference<sheet::XDataPilotDescriptor> xDataPilotDescriptor = xDataPilotTables->createDataPilotDescriptor();
938 xDataPilotDescriptor->setSourceRange(sCellRangeAdress);
940 lclModifyOrientation(xDataPilotDescriptor, "Date", sheet::DataPilotFieldOrientation_ROW);
941 lclModifyOrientation(xDataPilotDescriptor, "City", sheet::DataPilotFieldOrientation_ROW);
942 lclModifyOrientation(xDataPilotDescriptor, "Country", sheet::DataPilotFieldOrientation_ROW);
943 lclModifyOrientation(xDataPilotDescriptor, "Type", sheet::DataPilotFieldOrientation_COLUMN);
944 lclModifyOrientation(xDataPilotDescriptor, "Sales T1", sheet::DataPilotFieldOrientation_DATA);
945 lclModifyFunction(xDataPilotDescriptor, "Sales T1", sheet::GeneralFunction_SUM);
947 lclModifyColumnGrandTotal(xDataPilotDescriptor, true);
948 lclModifyRowGrandTotal(xDataPilotDescriptor, true);
950 xDataPilotTables->insertNewByName(sPivotTableName, table::CellAddress{1, 0, 0}, xDataPilotDescriptor);
952 // TEST
953 Reference<chart2::XChartDocument> xChartDoc;
955 // Check we have the Pivot Table
956 uno::Reference<sheet::XDataPilotTable> xDataPilotTable = lclGetPivotTableByName(1, sPivotTableName, mxComponent);
957 CPPUNIT_ASSERT(xDataPilotTable.is());
959 // refetch the XDataPilotDescriptor
960 xDataPilotDescriptor.set(xDataPilotTable, uno::UNO_QUERY_THROW);
962 // Check that we don't have any pivot chart in the document
963 uno::Reference<table::XTablePivotCharts> xTablePivotCharts = getTablePivotChartsFromSheet(1, mxComponent);
964 uno::Reference<container::XIndexAccess> xIndexAccess(xTablePivotCharts, UNO_QUERY_THROW);
965 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xIndexAccess->getCount());
967 // Create a new pivot chart
968 xTablePivotCharts->addNewByName("PivotChart", awt::Rectangle{ 9000, 9000, 21000, 18000 }, sPivotTableName);
969 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount());
971 // Get the pivot chart document so we can access its data
972 xChartDoc.set(getPivotChartDocFromSheet(xTablePivotCharts, 0));
974 CPPUNIT_ASSERT(xChartDoc.is());
976 // Check if Date category is date formatted.
977 lclCheckCategories( { "12/11/15", "", "", "", "", "", "12/14/15", "12/17/15", "01/20/16", "", "", "03/21/17" },
978 lclGetCategories( xChartDoc )[0]->getValues() );
982 CPPUNIT_TEST_SUITE_REGISTRATION(PivotChartTest);
984 CPPUNIT_PLUGIN_IMPLEMENT();
986 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */