Avoid potential negative array index access to cached text.
[LibreOffice.git] / chart2 / qa / extras / PivotChartTest.cxx
blobd6a87ec057a93286f9379c92b75555dbc2a3bc63
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::sun::star::table { class XCellRange; }
32 namespace com::sun::star::util { class XNumberFormats; }
34 class PivotChartTest : public ChartTest
36 public:
37 PivotChartTest()
38 : ChartTest("/chart2/qa/extras/data/")
41 void testRoundtrip();
42 void testChangePivotTable();
43 void testPivotChartWithOneColumnField();
44 void testPivotChartWithOneRowField();
45 void testPivotTableDataProvider_PivotTableFields();
46 void testPivotChartRowFieldInOutlineMode();
47 void testPivotChartWithDateRowField();
49 CPPUNIT_TEST_SUITE(PivotChartTest);
50 CPPUNIT_TEST(testRoundtrip);
51 CPPUNIT_TEST(testChangePivotTable);
52 CPPUNIT_TEST(testPivotChartWithOneColumnField);
53 CPPUNIT_TEST(testPivotChartWithOneRowField);
54 CPPUNIT_TEST(testPivotTableDataProvider_PivotTableFields);
55 CPPUNIT_TEST(testPivotChartRowFieldInOutlineMode);
56 CPPUNIT_TEST(testPivotChartWithDateRowField);
57 CPPUNIT_TEST_SUITE_END();
60 namespace
63 void lclModifyOrientation(uno::Reference<sheet::XDataPilotDescriptor> const & xDescriptor,
64 std::u16string_view sFieldName,
65 sheet::DataPilotFieldOrientation eOrientation)
67 uno::Reference<container::XIndexAccess> xIndexAccess(xDescriptor->getDataPilotFields(), UNO_SET_THROW);
68 sal_Int32 nCount = xIndexAccess->getCount();
69 for (sal_Int32 i = 0; i < nCount; ++i)
71 uno::Reference<container::XNamed> xNamed(xIndexAccess->getByIndex(i), UNO_QUERY_THROW);
72 OUString aName = xNamed->getName();
73 uno::Reference<beans::XPropertySet> xPropSet(xNamed, UNO_QUERY_THROW);
74 if (aName == sFieldName)
75 xPropSet->setPropertyValue("Orientation", uno::Any(eOrientation));
79 void lclModifyFunction(uno::Reference<sheet::XDataPilotDescriptor> const & xDescriptor,
80 std::u16string_view sFieldName,
81 sheet::GeneralFunction eFunction)
83 uno::Reference<container::XIndexAccess> xPilotIndexAccess(xDescriptor->getDataPilotFields(), UNO_SET_THROW);
84 sal_Int32 nCount = xPilotIndexAccess->getCount();
85 for (sal_Int32 i = 0; i < nCount; ++i)
87 uno::Reference<container::XNamed> xNamed(xPilotIndexAccess->getByIndex(i), UNO_QUERY_THROW);
88 OUString aName = xNamed->getName();
89 uno::Reference<beans::XPropertySet> xPropSet(xNamed, UNO_QUERY_THROW);
90 if (aName == sFieldName)
91 xPropSet->setPropertyValue("Function", uno::Any(eFunction));
95 void lclModifyLayoutInfo(uno::Reference<sheet::XDataPilotDescriptor> const & xDescriptor,
96 std::u16string_view sFieldName,
97 sheet::DataPilotFieldLayoutInfo aLayoutInfo)
99 uno::Reference<container::XIndexAccess> xIndexAccess(xDescriptor->getDataPilotFields(), UNO_SET_THROW);
100 sal_Int32 nCount = xIndexAccess->getCount();
101 for (sal_Int32 i = 0; i < nCount; ++i)
103 uno::Reference<container::XNamed> xNamed(xIndexAccess->getByIndex(i), UNO_QUERY_THROW);
104 OUString aName = xNamed->getName();
105 uno::Reference<beans::XPropertySet> xPropSet(xNamed, UNO_QUERY_THROW);
106 if (aName == sFieldName)
108 uno::Any aValue;
109 aValue <<= aLayoutInfo;
110 xPropSet->setPropertyValue("LayoutInfo", aValue);
115 void lclModifySubtotals(uno::Reference<sheet::XDataPilotDescriptor> const & xDescriptor,
116 std::u16string_view sFieldName,
117 uno::Sequence<sheet::GeneralFunction> const & rSubtotalFunctions)
119 uno::Reference<container::XIndexAccess> xIndexAccess(xDescriptor->getDataPilotFields(), UNO_SET_THROW);
120 sal_Int32 nCount = xIndexAccess->getCount();
121 for (sal_Int32 i = 0; i < nCount; ++i)
123 uno::Reference<container::XNamed> xNamed(xIndexAccess->getByIndex(i), UNO_QUERY_THROW);
124 OUString aName = xNamed->getName();
125 uno::Reference<beans::XPropertySet> xPropSet(xNamed, UNO_QUERY_THROW);
126 if (aName == sFieldName)
128 uno::Any aValue;
129 aValue <<= rSubtotalFunctions;
130 xPropSet->setPropertyValue("Subtotals", aValue);
135 void lclModifyColumnGrandTotal(uno::Reference<sheet::XDataPilotDescriptor> const & xDataPilotDescriptor, bool bTotal)
137 uno::Reference<beans::XPropertySet> xProperties(xDataPilotDescriptor, uno::UNO_QUERY_THROW);
138 xProperties->setPropertyValue("ColumnGrand", uno::Any(bTotal));
141 void lclModifyRowGrandTotal(uno::Reference<sheet::XDataPilotDescriptor> const & xDataPilotDescriptor, bool bTotal)
143 uno::Reference<beans::XPropertySet> xProperties(xDataPilotDescriptor, uno::UNO_QUERY_THROW);
144 xProperties->setPropertyValue("RowGrand", uno::Any(bTotal));
147 void lclCheckSequence(std::vector<double> const & reference,
148 uno::Sequence<uno::Any> const & values,
149 double delta)
151 CPPUNIT_ASSERT_EQUAL(reference.size(), size_t(values.getLength()));
152 for (size_t i = 0; i < reference.size(); ++i)
154 CPPUNIT_ASSERT_DOUBLES_EQUAL(
155 reference[i], values[i].get<double>(), delta);
159 void lclCheckCategories(std::vector<OUString> const & reference,
160 uno::Reference<chart2::data::XDataSequence> const & xSequence)
162 uno::Reference<chart2::data::XTextualDataSequence> xTextualDataSequence(xSequence, uno::UNO_QUERY_THROW);
163 uno::Sequence<OUString> aText = xTextualDataSequence->getTextualData();
165 CPPUNIT_ASSERT_EQUAL(reference.size(), size_t(aText.getLength()));
166 for (size_t i = 0; i < reference.size(); ++i)
168 CPPUNIT_ASSERT_EQUAL(reference[i], aText[i]);
172 OUString lclGetLabel(Reference<chart2::XChartDocument> const & xChartDoc, sal_Int32 nSeriesIndex)
174 Reference<chart2::data::XDataSequence> xLabelDataSequence = getLabelDataSequenceFromDoc(xChartDoc, nSeriesIndex);
175 return xLabelDataSequence->getData()[0].get<OUString>();
178 uno::Reference<sheet::XDataPilotTable> lclGetPivotTableByName(sal_Int32 nIndex, OUString const & sPivotTableName,
179 uno::Reference<lang::XComponent> const & xComponent)
181 uno::Reference<sheet::XSpreadsheetDocument> xDoc(xComponent, UNO_QUERY_THROW);
182 uno::Reference<container::XIndexAccess> xSheetIndexAccess(xDoc->getSheets(), UNO_QUERY_THROW);
183 uno::Any aAny = xSheetIndexAccess->getByIndex(nIndex);
184 uno::Reference<sheet::XSpreadsheet> xSheet;
185 CPPUNIT_ASSERT(aAny >>= xSheet);
186 uno::Reference<sheet::XDataPilotTablesSupplier> xDataPilotTablesSupplier(xSheet, uno::UNO_QUERY_THROW);
187 uno::Reference<sheet::XDataPilotTables> xDataPilotTables = xDataPilotTablesSupplier->getDataPilotTables();
188 return uno::Reference<sheet::XDataPilotTable>(xDataPilotTables->getByName(sPivotTableName), UNO_QUERY_THROW);
191 uno::Sequence<uno::Reference<chart2::data::XLabeledDataSequence>>
192 lclGetCategories(Reference<chart2::XChartDocument> const & xChartDoc)
194 uno::Sequence<beans::PropertyValue> aArguments( comphelper::InitPropertySequence(
195 {{"CellRangeRepresentation", uno::Any(OUString("PT@categories"))}} ));
197 uno::Reference<chart2::data::XDataProvider> xDataProvider(xChartDoc->getDataProvider(), uno::UNO_SET_THROW);
198 return xDataProvider->createDataSource(aArguments)->getDataSequences();
201 struct Value
203 OUString maString;
204 double mfValue;
205 bool mbIsValue;
207 Value(OUString const & rString)
208 : maString(rString)
209 , mfValue(0.0)
210 , mbIsValue(false)
213 Value(double fValue)
214 : mfValue(fValue)
215 , mbIsValue(true)
219 uno::Reference< sheet::XDataPilotTables>
220 lclGetDataPilotTables(sal_Int32 nIndex, uno::Reference<sheet::XSpreadsheetDocument> const & xSheetDoc)
222 uno::Reference<sheet::XSpreadsheets> xSpreadsheets = xSheetDoc->getSheets();
223 uno::Reference<container::XIndexAccess> oIndexAccess(xSpreadsheets, uno::UNO_QUERY_THROW);
224 uno::Reference<sheet::XSpreadsheet> xSheet;
225 CPPUNIT_ASSERT(oIndexAccess->getByIndex(nIndex) >>= xSheet);
227 // create the test objects
228 uno::Reference< sheet::XDataPilotTablesSupplier> xDataPilotTablesSupplier(xSheet, uno::UNO_QUERY_THROW);
229 return xDataPilotTablesSupplier->getDataPilotTables();
232 table::CellRangeAddress lclCreateTestData(uno::Reference<sheet::XSpreadsheetDocument> const & xSheetDoc)
234 CPPUNIT_ASSERT_MESSAGE("no calc document!", xSheetDoc.is());
236 std::vector<OUString> aHeaders {
237 "Country", "City", "Type", "Sales T1", "Sales T2", "Sales T3", "Sales T4", "Date"
240 std::vector<std::vector<Value>> aData {
241 { {"FR"}, {"Paris"}, {"A"}, {123.0}, {223.0}, {323.0}, {423.0}, {"12/14/15"} },
242 { {"EN"}, {"London"}, {"A"}, {456.0}, {556.0}, {656.0}, {756.0}, {"12/11/15"} },
243 { {"DE"}, {"Berlin"}, {"A"}, {468.0}, {568.0}, {668.0}, {768.0}, {"12/11/15"} },
244 { {"FR"}, {"Nantes"}, {"A"}, {694.0}, {794.0}, {894.0}, {994.0}, {"12/11/15"} },
245 { {"EN"}, {"Glasgow"}, {"A"}, {298.0}, {398.0}, {498.0}, {598.0}, {"12/11/15"} },
246 { {"DE"}, {"Munich"}, {"A"}, {369.0}, {469.0}, {569.0}, {669.0}, {"12/11/15"} },
247 { {"FR"}, {"Paris"}, {"B"}, {645.0}, {745.0}, {845.0}, {945.0}, {"12/11/15"} },
248 { {"EN"}, {"London"}, {"B"}, {687.0}, {787.0}, {887.0}, {987.0}, {"03/21/17"} },
249 { {"DE"}, {"Munich"}, {"B"}, {253.0}, {353.0}, {453.0}, {553.0}, {"12/17/15"} },
250 { {"FR"}, {"Nantes"}, {"B"}, {474.0}, {574.0}, {674.0}, {774.0}, {"01/20/16"} },
251 { {"EN"}, {"Liverpool"}, {"B"}, {562.0}, {662.0}, {762.0}, {862.0}, {"01/20/16"} },
252 { {"DE"}, {"Berlin"}, {"B"}, {648.0}, {748.0}, {848.0}, {948.0}, {"01/20/16"} }
255 // Getting spreadsheet
256 uno::Reference<sheet::XSpreadsheets> xSpreadsheets = xSheetDoc->getSheets();
257 uno::Reference<container::XIndexAccess> oIndexAccess(xSpreadsheets, uno::UNO_QUERY_THROW);
258 uno::Reference<sheet::XSpreadsheet> xSheet;
259 CPPUNIT_ASSERT(oIndexAccess->getByIndex(0) >>= xSheet);
261 uno::Reference<sheet::XSpreadsheet> oPivotTableSheet;
262 xSpreadsheets->insertNewByName("Pivot Table", 1);
263 CPPUNIT_ASSERT(oIndexAccess->getByIndex(1) >>= oPivotTableSheet);
265 sal_Int32 currentRow = 0;
266 for (size_t column = 0; column < aHeaders.size(); ++column)
268 xSheet->getCellByPosition(column, currentRow)->setFormula(aHeaders[column]);
270 currentRow++;
272 for (std::vector<Value> const & rRowOfData : aData)
274 for (size_t column = 0; column < rRowOfData.size(); ++column)
276 Value const & rValue = rRowOfData[column];
277 uno::Reference<table::XCell> xCell(xSheet->getCellByPosition(column, currentRow));
278 if (rValue.mbIsValue)
279 xCell->setValue(rValue.mfValue);
280 else
281 xCell->setFormula(rValue.maString);
283 currentRow++;
286 sal_Int32 nEndCol = sal_Int32(aHeaders.size() - 1);
287 sal_Int32 nEndRow = sal_Int32(1/*HEADER*/ + aData.size() - 1);
289 // Apply date format to the last column
290 uno::Reference<util::XNumberFormatsSupplier> xNumberFormatsSupplier(xSheetDoc, UNO_QUERY_THROW);
291 uno::Reference<util::XNumberFormats> xNumberFormats = xNumberFormatsSupplier->getNumberFormats();
292 uno::Reference<util::XNumberFormatTypes> xNumberFormatTypes(xNumberFormats, UNO_QUERY_THROW);
293 lang::Locale aLocale;
294 sal_Int32 nDateKey = xNumberFormatTypes->getStandardFormat(util::NumberFormat::DATE, aLocale);
295 uno::Reference<table::XCellRange> xCellRange = xSheet->getCellRangeByPosition(nEndCol, 1, nEndCol, nEndRow);
296 uno::Reference<beans::XPropertySet> xCellProp(xCellRange, UNO_QUERY_THROW);
297 xCellProp->setPropertyValue("NumberFormat", uno::Any(nDateKey));
299 table::CellRangeAddress sCellRangeAddress;
300 sCellRangeAddress.Sheet = 0;
301 sCellRangeAddress.StartColumn = 0;
302 sCellRangeAddress.StartRow = 0;
303 sCellRangeAddress.EndColumn = nEndCol;
304 sCellRangeAddress.EndRow = nEndRow;
306 return sCellRangeAddress;
309 } // end anonymous namespace
311 void PivotChartTest::testRoundtrip()
313 uno::Sequence<uno::Any> xSequence;
314 Reference<chart2::XChartDocument> xChartDoc;
316 std::vector<double> aReference1 { 10162.033139, 16614.523063, 27944.146101 };
318 std::vector<double> aReference2 { 101879.458079, 178636.929704, 314626.484864 };
320 loadFromFile(u"ods/PivotChartRoundTrip.ods");
322 xChartDoc = getPivotChartDocFromSheet(1, mxComponent);
323 CPPUNIT_ASSERT(xChartDoc.is());
325 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), getNumberOfDataSeries(xChartDoc));
327 // Check the data series
329 xSequence = getDataSequenceFromDocByRole(xChartDoc, u"values-y", 0)->getData();
330 lclCheckSequence(aReference1, xSequence, 1E-4);
331 CPPUNIT_ASSERT_EQUAL(OUString("Exp."), lclGetLabel(xChartDoc, 0));
334 xSequence = getDataSequenceFromDocByRole(xChartDoc, u"values-y", 1)->getData();
335 lclCheckSequence(aReference2, xSequence, 1E-4);
336 CPPUNIT_ASSERT_EQUAL(OUString("Rev."), lclGetLabel(xChartDoc, 1));
339 // Modify the pivot table
341 uno::Reference<sheet::XDataPilotTable> xDataPilotTable = lclGetPivotTableByName(1, "DataPilot1", mxComponent);
342 uno::Reference<sheet::XDataPilotDescriptor> xDataPilotDescriptor(xDataPilotTable, UNO_QUERY_THROW);
343 lclModifyOrientation(xDataPilotDescriptor, u"Exp.", sheet::DataPilotFieldOrientation_HIDDEN);
346 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), getNumberOfDataSeries(xChartDoc));
348 // Check again the data series
350 xSequence = getDataSequenceFromDocByRole(xChartDoc, u"values-y", 0)->getData();
351 lclCheckSequence(aReference2, xSequence, 1E-4);
352 CPPUNIT_ASSERT_EQUAL(OUString("Total"), lclGetLabel(xChartDoc, 0));
355 saveAndReload("calc8");
357 xChartDoc = getPivotChartDocFromSheet(1, mxComponent);
358 CPPUNIT_ASSERT(xChartDoc.is());
360 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), getNumberOfDataSeries(xChartDoc));
362 // Check again the data series
364 xSequence = getDataSequenceFromDocByRole(xChartDoc, u"values-y", 0)->getData();
365 lclCheckSequence(aReference2, xSequence, 1E-4);
366 CPPUNIT_ASSERT_EQUAL(OUString("Total"), lclGetLabel(xChartDoc, 0));
370 void PivotChartTest::testChangePivotTable()
372 uno::Sequence<uno::Any> xSequence;
373 Reference<chart2::XChartDocument> xChartDoc;
375 loadFromFile(u"ods/PivotTableExample.ods");
377 // Check we have the Pivot Table
378 OUString sPivotTableName("DataPilot1");
379 uno::Reference<sheet::XDataPilotTable> xDataPilotTable = lclGetPivotTableByName(1, sPivotTableName, mxComponent);
380 CPPUNIT_ASSERT(xDataPilotTable.is());
382 // Check that we don't have any pivot chart in the document
383 uno::Reference<table::XTablePivotCharts> xTablePivotCharts = getTablePivotChartsFromSheet(1, mxComponent);
384 uno::Reference<container::XIndexAccess> xIndexAccess(xTablePivotCharts, UNO_QUERY_THROW);
385 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xIndexAccess->getCount());
387 // Create a new pivot chart
388 xTablePivotCharts->addNewByName("Chart", awt::Rectangle{0, 0, 9000, 9000}, sPivotTableName);
389 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount());
391 // Get the pivot chart document so we can access its data
392 xChartDoc.set(getPivotChartDocFromSheet(xTablePivotCharts, 0));
394 CPPUNIT_ASSERT(xChartDoc.is());
396 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), getNumberOfDataSeries(xChartDoc));
398 // Check first data series
400 std::vector<double> aReference { 10162.033139, 16614.523063, 27944.146101 };
402 xSequence = getDataSequenceFromDocByRole(xChartDoc, u"values-y", 0)->getData();
403 lclCheckSequence(aReference, xSequence, 1E-4);
405 CPPUNIT_ASSERT_EQUAL(OUString("Exp."), lclGetLabel(xChartDoc, 0));
408 // Check second data series
410 std::vector<double> aReference { 101879.458079, 178636.929704, 314626.484864 };
412 xSequence = getDataSequenceFromDocByRole(xChartDoc, u"values-y", 1)->getData();
413 lclCheckSequence(aReference, xSequence, 1E-4);
415 CPPUNIT_ASSERT_EQUAL(OUString("Rev."), lclGetLabel(xChartDoc, 1));
418 // Modify the pivot table, move "Group Segment" to Column fields,
419 // add "Service Month" to Row fields, remove "Rev." Data field
421 uno::Reference<sheet::XDataPilotDescriptor> xDataPilotDescriptor(xDataPilotTable, UNO_QUERY_THROW);
423 lclModifyOrientation(xDataPilotDescriptor, u"Service Month", sheet::DataPilotFieldOrientation_ROW);
424 lclModifyOrientation(xDataPilotDescriptor, u"Group Segment", sheet::DataPilotFieldOrientation_COLUMN);
425 lclModifyOrientation(xDataPilotDescriptor, u"Rev.", sheet::DataPilotFieldOrientation_HIDDEN);
428 // Check the pivot chart again as we expect it has been updated when we updated the pivot table
430 CPPUNIT_ASSERT_EQUAL(sal_Int32(3), getNumberOfDataSeries(xChartDoc));
432 // Check the first data series
434 std::vector<double> aReference { 2855.559, 1780.326, 2208.713, 2130.064, 1187.371 };
436 xSequence = getDataSequenceFromDocByRole(xChartDoc, u"values-y", 0)->getData();
437 lclCheckSequence(aReference, xSequence, 1E-3);
439 CPPUNIT_ASSERT_EQUAL(OUString("Big"), lclGetLabel(xChartDoc, 0));
442 // Check the second data series
444 std::vector<double> aReference { 4098.908, 2527.286, 4299.716, 2362.225, 3326.389 };
446 xSequence = getDataSequenceFromDocByRole(xChartDoc, u"values-y", 1)->getData();
447 lclCheckSequence(aReference, xSequence, 1E-3);
449 CPPUNIT_ASSERT_EQUAL(OUString("Medium"), lclGetLabel(xChartDoc, 1));
452 // Check the third data series
454 std::vector<double> aReference { 4926.303, 5684.060, 4201.398, 7290.795, 5841.591 };
456 xSequence = getDataSequenceFromDocByRole(xChartDoc, u"values-y", 2)->getData();
457 lclCheckSequence(aReference, xSequence, 1E-3);
459 CPPUNIT_ASSERT_EQUAL(OUString("Small"), lclGetLabel(xChartDoc, 2));
462 // Remove "Service Month" so row fields are empty - check we handle empty rows
464 uno::Reference<sheet::XDataPilotDescriptor> xDataPilotDescriptor(xDataPilotTable, uno::UNO_QUERY_THROW);
465 lclModifyOrientation(xDataPilotDescriptor, u"Service Month", sheet::DataPilotFieldOrientation_HIDDEN);
468 // Check the pivot chart again as we expect it has been updated when we updated the pivot table
470 CPPUNIT_ASSERT_EQUAL(sal_Int32(3), getNumberOfDataSeries(xChartDoc));
472 // Check the first data series
474 std::vector<double> aReference { 10162.033139 };
475 xSequence = getDataSequenceFromDocByRole(xChartDoc, u"values-y", 0)->getData();
476 lclCheckSequence(aReference, xSequence, 1E-3);
477 CPPUNIT_ASSERT_EQUAL(OUString("Big"), lclGetLabel(xChartDoc, 0));
479 // Check the second data series
481 std::vector<double> aReference { 16614.523063 };
482 xSequence = getDataSequenceFromDocByRole(xChartDoc, u"values-y", 1)->getData();
483 lclCheckSequence(aReference, xSequence, 1E-3);
484 CPPUNIT_ASSERT_EQUAL(OUString("Medium"), lclGetLabel(xChartDoc, 1));
486 // Check the third data series
488 std::vector<double> aReference { 27944.146101 };
489 xSequence = getDataSequenceFromDocByRole(xChartDoc, u"values-y", 2)->getData();
490 lclCheckSequence(aReference, xSequence, 1E-3);
491 CPPUNIT_ASSERT_EQUAL(OUString("Small"), lclGetLabel(xChartDoc, 2));
494 // Enable column totals and check the data is still unchanged
496 uno::Reference<beans::XPropertySet> xProperties(xDataPilotTable, uno::UNO_QUERY_THROW);
497 xProperties->setPropertyValue("ColumnGrand", uno::Any(true));
500 CPPUNIT_ASSERT_EQUAL(sal_Int32(3), getNumberOfDataSeries(xChartDoc));
502 // Check the first data series
504 std::vector<double> aReference { 10162.033139 };
505 xSequence = getDataSequenceFromDocByRole(xChartDoc, u"values-y", 0)->getData();
506 lclCheckSequence(aReference, xSequence, 1E-3);
507 CPPUNIT_ASSERT_EQUAL(OUString("Big"), lclGetLabel(xChartDoc, 0));
509 // Check the second data series
511 std::vector<double> aReference { 16614.523063 };
512 xSequence = getDataSequenceFromDocByRole(xChartDoc, u"values-y", 1)->getData();
513 lclCheckSequence(aReference, xSequence, 1E-3);
514 CPPUNIT_ASSERT_EQUAL(OUString("Medium"), lclGetLabel(xChartDoc, 1));
516 // Check the third data series
518 std::vector<double> aReference { 27944.146101 };
519 xSequence = getDataSequenceFromDocByRole(xChartDoc, u"values-y", 2)->getData();
520 lclCheckSequence(aReference, xSequence, 1E-3);
521 CPPUNIT_ASSERT_EQUAL(OUString("Small"), lclGetLabel(xChartDoc, 2));
525 void PivotChartTest::testPivotChartWithOneColumnField()
527 // We put one field as COLUMN field only and one DATA field. We expect we will get as many data series
528 // in the pivot table as many distinct column values we have (with this example data 3: DE, EN, FR).
530 // SETUP DATA and PIVOT TABLE
532 mxComponent = loadFromDesktop("private:factory/scalc");
534 uno::Reference<sheet::XSpreadsheetDocument> xSheetDoc(mxComponent, uno::UNO_QUERY_THROW);
536 OUString sPivotTableName("DataPilotTable");
538 table::CellRangeAddress sCellRangeAddress = lclCreateTestData(xSheetDoc);
540 uno::Reference<sheet::XDataPilotTables> xDataPilotTables = lclGetDataPilotTables(0, xSheetDoc);
542 uno::Reference<sheet::XDataPilotDescriptor> xDataPilotDescriptor = xDataPilotTables->createDataPilotDescriptor();
543 xDataPilotDescriptor->setSourceRange(sCellRangeAddress);
545 lclModifyOrientation(xDataPilotDescriptor, u"Country", sheet::DataPilotFieldOrientation_COLUMN);
546 lclModifyOrientation(xDataPilotDescriptor, u"Sales T1", sheet::DataPilotFieldOrientation_DATA);
547 lclModifyFunction(xDataPilotDescriptor, u"Sales T1", sheet::GeneralFunction_SUM);
549 xDataPilotTables->insertNewByName(sPivotTableName, table::CellAddress{1, 0, 0}, xDataPilotDescriptor);
551 // TEST
553 uno::Sequence<uno::Any> xSequence;
554 Reference<chart2::XChartDocument> xChartDoc;
556 // Check we have the Pivot Table
558 uno::Reference<sheet::XDataPilotTable> xDataPilotTable = lclGetPivotTableByName(1, sPivotTableName, mxComponent);
559 CPPUNIT_ASSERT(xDataPilotTable.is());
561 // Check that we don't have any pivot chart in the document
562 uno::Reference<table::XTablePivotCharts> xTablePivotCharts = getTablePivotChartsFromSheet(1, mxComponent);
563 uno::Reference<container::XIndexAccess> xIndexAccess(xTablePivotCharts, UNO_QUERY_THROW);
564 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xIndexAccess->getCount());
566 // Create a new pivot chart
567 xTablePivotCharts->addNewByName("PivotChart", awt::Rectangle{ 9000, 9000, 21000, 18000 }, sPivotTableName);
568 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount());
570 // Get the pivot chart document so we can access its data
571 xChartDoc.set(getPivotChartDocFromSheet(xTablePivotCharts, 0));
573 CPPUNIT_ASSERT(xChartDoc.is());
575 CPPUNIT_ASSERT_EQUAL(sal_Int32(3), getNumberOfDataSeries(xChartDoc));
576 // Check data series 1
578 std::vector<double> aReference { 1738.0 };
580 xSequence = getDataSequenceFromDocByRole(xChartDoc, u"values-y", 0)->getData();
581 lclCheckSequence(aReference, xSequence, 1E-4);
583 CPPUNIT_ASSERT_EQUAL(OUString("DE"), lclGetLabel(xChartDoc, 0));
586 // Check data series 2
588 std::vector<double> aReference { 2003.0 };
590 xSequence = getDataSequenceFromDocByRole(xChartDoc, u"values-y", 1)->getData();
591 lclCheckSequence(aReference, xSequence, 1E-4);
593 CPPUNIT_ASSERT_EQUAL(OUString("EN"), lclGetLabel(xChartDoc, 1));
595 // Check data series 3
597 std::vector<double> aReference { 1936.0 };
599 xSequence = getDataSequenceFromDocByRole(xChartDoc, u"values-y", 2)->getData();
600 lclCheckSequence(aReference, xSequence, 1E-4);
602 CPPUNIT_ASSERT_EQUAL(OUString("FR"), lclGetLabel(xChartDoc, 2));
606 void PivotChartTest::testPivotChartWithOneRowField()
608 // We put one field as ROW field only and one DATA field. We expect we will get one data series
609 // in the pivot table.
611 // SETUP DATA and PIVOT TABLE
613 mxComponent = loadFromDesktop("private:factory/scalc");
615 uno::Reference<sheet::XSpreadsheetDocument> xSheetDoc(mxComponent, uno::UNO_QUERY_THROW);
617 OUString sPivotTableName("DataPilotTable");
619 table::CellRangeAddress sCellRangeAddress = lclCreateTestData(xSheetDoc);
621 uno::Reference<sheet::XDataPilotTables> xDataPilotTables = lclGetDataPilotTables(0, xSheetDoc);
623 uno::Reference<sheet::XDataPilotDescriptor> xDataPilotDescriptor = xDataPilotTables->createDataPilotDescriptor();
624 xDataPilotDescriptor->setSourceRange(sCellRangeAddress);
626 lclModifyOrientation(xDataPilotDescriptor, u"Country", sheet::DataPilotFieldOrientation_ROW);
627 lclModifyOrientation(xDataPilotDescriptor, u"Sales T1", sheet::DataPilotFieldOrientation_DATA);
628 lclModifyFunction(xDataPilotDescriptor, u"Sales T1", sheet::GeneralFunction_SUM);
630 xDataPilotTables->insertNewByName(sPivotTableName, table::CellAddress{1, 0, 0}, xDataPilotDescriptor);
632 // TEST
634 uno::Sequence<uno::Any> xSequence;
635 Reference<chart2::XChartDocument> xChartDoc;
637 // Check we have the Pivot Table
639 uno::Reference<sheet::XDataPilotTable> xDataPilotTable = lclGetPivotTableByName(1, sPivotTableName, mxComponent);
640 CPPUNIT_ASSERT(xDataPilotTable.is());
642 // Check that we don't have any pivot chart in the document
643 uno::Reference<table::XTablePivotCharts> xTablePivotCharts = getTablePivotChartsFromSheet(1, mxComponent);
644 uno::Reference<container::XIndexAccess> xIndexAccess(xTablePivotCharts, UNO_QUERY_THROW);
645 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xIndexAccess->getCount());
647 // Create a new pivot chart
648 xTablePivotCharts->addNewByName("PivotChart", awt::Rectangle{ 9000, 9000, 21000, 18000 }, sPivotTableName);
649 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount());
651 // Get the pivot chart document so we can access its data
652 xChartDoc.set(getPivotChartDocFromSheet(xTablePivotCharts, 0));
654 CPPUNIT_ASSERT(xChartDoc.is());
656 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), getNumberOfDataSeries(xChartDoc));
657 // Check data series 1
659 std::vector<double> aReference { 1738.0, 2003.0, 1936.0 };
661 xSequence = getDataSequenceFromDocByRole(xChartDoc, u"values-y", 0)->getData();
662 lclCheckSequence(aReference, xSequence, 1E-4);
664 CPPUNIT_ASSERT_EQUAL(OUString("Total"), lclGetLabel(xChartDoc, 0));
668 void PivotChartTest::testPivotTableDataProvider_PivotTableFields()
670 // SETUP DATA and PIVOT TABLE
672 mxComponent = loadFromDesktop("private:factory/scalc");
674 uno::Reference<sheet::XSpreadsheetDocument> xSheetDoc(mxComponent, uno::UNO_QUERY_THROW);
676 OUString sPivotTableName("DataPilotTable");
678 table::CellRangeAddress sCellRangeAddress = lclCreateTestData(xSheetDoc);
680 uno::Reference<sheet::XDataPilotTables> xDataPilotTables = lclGetDataPilotTables(0, xSheetDoc);
682 uno::Reference<sheet::XDataPilotDescriptor> xDataPilotDescriptor = xDataPilotTables->createDataPilotDescriptor();
683 xDataPilotDescriptor->setSourceRange(sCellRangeAddress);
685 lclModifyOrientation(xDataPilotDescriptor, u"City", sheet::DataPilotFieldOrientation_ROW);
686 lclModifyOrientation(xDataPilotDescriptor, u"Country", sheet::DataPilotFieldOrientation_COLUMN);
687 lclModifyOrientation(xDataPilotDescriptor, u"Type", sheet::DataPilotFieldOrientation_COLUMN);
688 lclModifyOrientation(xDataPilotDescriptor, u"Sales T1", sheet::DataPilotFieldOrientation_DATA);
689 lclModifyFunction(xDataPilotDescriptor, u"Sales T1", sheet::GeneralFunction_SUM);
690 lclModifyOrientation(xDataPilotDescriptor, u"Sales T2", sheet::DataPilotFieldOrientation_DATA);
691 lclModifyFunction(xDataPilotDescriptor, u"Sales T2", sheet::GeneralFunction_SUM);
693 lclModifyColumnGrandTotal(xDataPilotDescriptor, true);
694 lclModifyRowGrandTotal(xDataPilotDescriptor, true);
696 xDataPilotTables->insertNewByName(sPivotTableName, table::CellAddress{1, 0, 0}, xDataPilotDescriptor);
698 // TEST
699 Reference<chart2::XChartDocument> xChartDoc;
701 // Check we have the Pivot Table
702 uno::Reference<sheet::XDataPilotTable> xDataPilotTable = lclGetPivotTableByName(1, sPivotTableName, mxComponent);
703 CPPUNIT_ASSERT(xDataPilotTable.is());
705 // refetch the XDataPilotDescriptor
706 xDataPilotDescriptor.set(xDataPilotTable, uno::UNO_QUERY_THROW);
708 // Check that we don't have any pivot chart in the document
709 uno::Reference<table::XTablePivotCharts> xTablePivotCharts = getTablePivotChartsFromSheet(1, mxComponent);
710 uno::Reference<container::XIndexAccess> xIndexAccess(xTablePivotCharts, UNO_QUERY_THROW);
711 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xIndexAccess->getCount());
713 // Create a new pivot chart
714 xTablePivotCharts->addNewByName("PivotChart", awt::Rectangle{ 9000, 9000, 21000, 18000 }, sPivotTableName);
715 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount());
717 // Get the pivot chart document so we can access its data
718 xChartDoc.set(getPivotChartDocFromSheet(xTablePivotCharts, 0));
720 CPPUNIT_ASSERT(xChartDoc.is());
722 uno::Reference<chart2::data::XPivotTableDataProvider> xPivotTableDataProvider(xChartDoc->getDataProvider(), UNO_QUERY_THROW);
723 uno::Sequence<chart2::data::PivotTableFieldEntry> aFieldEntries;
725 aFieldEntries = xPivotTableDataProvider->getColumnFields();
727 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), aFieldEntries.getLength());
728 CPPUNIT_ASSERT_EQUAL(OUString("Country"), aFieldEntries[0].Name);
729 CPPUNIT_ASSERT_EQUAL(OUString("Type"), aFieldEntries[1].Name);
731 aFieldEntries = xPivotTableDataProvider->getRowFields();
733 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), aFieldEntries.getLength());
734 CPPUNIT_ASSERT_EQUAL(OUString("City"), aFieldEntries[0].Name);
735 CPPUNIT_ASSERT_EQUAL(OUString("Data"), aFieldEntries[1].Name);
737 aFieldEntries = xPivotTableDataProvider->getDataFields();
739 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), aFieldEntries.getLength());
740 CPPUNIT_ASSERT_EQUAL(OUString("Sum - Sales T1"), aFieldEntries[0].Name);
741 CPPUNIT_ASSERT_EQUAL(OUString("Sum - Sales T2"), aFieldEntries[1].Name);
743 // Data to column fields
744 lclModifyOrientation(xDataPilotDescriptor, u"Data", sheet::DataPilotFieldOrientation_COLUMN);
746 // Change the order of column fields: expected data, type, country
747 lclModifyOrientation(xDataPilotDescriptor, u"Country", sheet::DataPilotFieldOrientation_HIDDEN);
748 lclModifyOrientation(xDataPilotDescriptor, u"Type", sheet::DataPilotFieldOrientation_HIDDEN);
750 lclModifyOrientation(xDataPilotDescriptor, u"Type", sheet::DataPilotFieldOrientation_COLUMN);
751 lclModifyOrientation(xDataPilotDescriptor, u"Country", sheet::DataPilotFieldOrientation_COLUMN);
753 // set the XPivotTableDataProvider again as the old one was exchanged
754 xPivotTableDataProvider.set(xChartDoc->getDataProvider(), uno::UNO_QUERY_THROW);
756 aFieldEntries = xPivotTableDataProvider->getColumnFields();
758 CPPUNIT_ASSERT_EQUAL(sal_Int32(3), aFieldEntries.getLength());
759 CPPUNIT_ASSERT_EQUAL(OUString("Data"), aFieldEntries[0].Name);
760 CPPUNIT_ASSERT_EQUAL(OUString("Type"), aFieldEntries[1].Name);
761 CPPUNIT_ASSERT_EQUAL(OUString("Country"), aFieldEntries[2].Name);
763 aFieldEntries = xPivotTableDataProvider->getRowFields();
765 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aFieldEntries.getLength());
766 CPPUNIT_ASSERT_EQUAL(OUString("City"), aFieldEntries[0].Name);
768 aFieldEntries = xPivotTableDataProvider->getDataFields();
770 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), aFieldEntries.getLength());
771 CPPUNIT_ASSERT_EQUAL(OUString("Sum - Sales T1"), aFieldEntries[0].Name);
772 CPPUNIT_ASSERT_EQUAL(OUString("Sum - Sales T2"), aFieldEntries[1].Name);
775 void PivotChartTest::testPivotChartRowFieldInOutlineMode()
777 // SETUP DATA and PIVOT TABLE
779 mxComponent = loadFromDesktop("private:factory/scalc");
781 uno::Reference<sheet::XSpreadsheetDocument> xSheetDoc(mxComponent, uno::UNO_QUERY_THROW);
783 OUString sPivotTableName("DataPilotTable");
785 table::CellRangeAddress sCellRangeAddress = lclCreateTestData(xSheetDoc);
787 uno::Reference<sheet::XDataPilotTables> xDataPilotTables = lclGetDataPilotTables(0, xSheetDoc);
789 uno::Reference<sheet::XDataPilotDescriptor> xDataPilotDescriptor = xDataPilotTables->createDataPilotDescriptor();
790 xDataPilotDescriptor->setSourceRange(sCellRangeAddress);
792 lclModifyOrientation(xDataPilotDescriptor, u"Country", sheet::DataPilotFieldOrientation_ROW);
793 lclModifyOrientation(xDataPilotDescriptor, u"City", sheet::DataPilotFieldOrientation_ROW);
794 lclModifyOrientation(xDataPilotDescriptor, u"Sales T1", sheet::DataPilotFieldOrientation_DATA);
795 lclModifyFunction(xDataPilotDescriptor, u"Sales T1", sheet::GeneralFunction_SUM);
796 xDataPilotTables->insertNewByName(sPivotTableName, table::CellAddress{1, 0, 0}, xDataPilotDescriptor);
798 // TEST
799 uno::Sequence<uno::Any> xSequence;
800 Reference<chart2::XChartDocument> xChartDoc;
802 // Check we have the Pivot Table
803 uno::Reference<sheet::XDataPilotTable> xDataPilotTable = lclGetPivotTableByName(1, sPivotTableName, mxComponent);
804 CPPUNIT_ASSERT(xDataPilotTable.is());
806 // refetch the XDataPilotDescriptor
807 xDataPilotDescriptor.set(xDataPilotTable, uno::UNO_QUERY_THROW);
809 // Check that we don't have any pivot chart in the document
810 uno::Reference<table::XTablePivotCharts> xTablePivotCharts = getTablePivotChartsFromSheet(1, mxComponent);
811 uno::Reference<container::XIndexAccess> xIndexAccess(xTablePivotCharts, UNO_QUERY_THROW);
812 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xIndexAccess->getCount());
814 // Create a new pivot chart
815 xTablePivotCharts->addNewByName("PivotChart", awt::Rectangle{ 9000, 9000, 21000, 18000 }, sPivotTableName);
816 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount());
818 // Get the pivot chart document so we can access its data
819 xChartDoc.set(getPivotChartDocFromSheet(xTablePivotCharts, 0));
821 CPPUNIT_ASSERT(xChartDoc.is());
823 // Test case with defaults
825 // Check when using defaults the data is as expected
826 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), getNumberOfDataSeries(xChartDoc));
828 std::vector<double> aReference { 1116.0, 622.0, 298.0, 562.0, 1143.0, 1168.0, 768.0 };
830 xSequence = getDataSequenceFromDocByRole(xChartDoc, u"values-y", 0)->getData();
831 lclCheckSequence(aReference, xSequence, 1E-4);
833 CPPUNIT_ASSERT_EQUAL(OUString("Total"), lclGetLabel(xChartDoc, 0));
835 // Check the categories
837 lclCheckCategories({ "DE", "", "EN", "", "", "FR", ""},
838 lclGetCategories(xChartDoc)[0]->getValues());
839 lclCheckCategories({ "Berlin", "Munich", "Glasgow", "Liverpool", "London", "Nantes", "Paris"},
840 lclGetCategories(xChartDoc)[1]->getValues());
843 sheet::DataPilotFieldLayoutInfo aLayoutInfoValue;
845 // Test case where we enable subtotals (auto) and set the outline subtotals at the bottom
846 // We don't expect any change in data as every extra subtotal row should be ignored
848 // Enable subtotals - set to auto
849 uno::Sequence<sheet::GeneralFunction> aGeneralFunctionSequence{ sheet::GeneralFunction_AUTO };
850 lclModifySubtotals(xDataPilotDescriptor, u"Country", aGeneralFunctionSequence);
851 // Set Subtotals layout to bottom + add empty lines
852 aLayoutInfoValue.AddEmptyLines = true;
853 aLayoutInfoValue.LayoutMode = sheet::DataPilotFieldLayoutMode::OUTLINE_SUBTOTALS_BOTTOM;
854 lclModifyLayoutInfo(xDataPilotDescriptor, u"Country", aLayoutInfoValue);
856 // Check data is unchanged
857 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), getNumberOfDataSeries(xChartDoc));
859 std::vector<double> aReference { 1116.0, 622.0, 298.0, 562.0, 1143.0, 1168.0, 768.0 };
861 xSequence = getDataSequenceFromDocByRole(xChartDoc, u"values-y", 0)->getData();
862 lclCheckSequence(aReference, xSequence, 1E-4);
864 CPPUNIT_ASSERT_EQUAL(OUString("Total"), lclGetLabel(xChartDoc, 0));
866 // Check categories
868 lclCheckCategories({ "DE", "", "EN", "", "", "FR", ""},
869 lclGetCategories(xChartDoc)[0]->getValues());
870 lclCheckCategories({ "Berlin", "Munich", "Glasgow", "Liverpool", "London", "Nantes", "Paris"},
871 lclGetCategories(xChartDoc)[1]->getValues());
874 // Test case where we enable subtotals (auto) and set the outline subtotals at the top
875 // We don't expect any change in data as every extra subtotal row should be ignored
877 // Enable subtotals - set to auto
878 aGeneralFunctionSequence.getArray()[0] = sheet::GeneralFunction_AUTO;
879 lclModifySubtotals(xDataPilotDescriptor, u"Country", aGeneralFunctionSequence);
880 // Set Subtotals layout to top + add empty lines
881 aLayoutInfoValue.AddEmptyLines = true;
882 aLayoutInfoValue.LayoutMode = sheet::DataPilotFieldLayoutMode::OUTLINE_SUBTOTALS_TOP;
883 lclModifyLayoutInfo(xDataPilotDescriptor, u"Country", aLayoutInfoValue);
885 // Check data is unchanged
886 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), getNumberOfDataSeries(xChartDoc));
888 std::vector<double> aReference { 1116.0, 622.0, 298.0, 562.0, 1143.0, 1168.0, 768.0 };
890 xSequence = getDataSequenceFromDocByRole(xChartDoc, u"values-y", 0)->getData();
891 lclCheckSequence(aReference, xSequence, 1E-4);
893 CPPUNIT_ASSERT_EQUAL(OUString("Total"), lclGetLabel(xChartDoc, 0));
895 // Check categories
897 lclCheckCategories({ "DE", "", "EN", "", "", "FR", ""},
898 lclGetCategories(xChartDoc)[0]->getValues());
899 lclCheckCategories({ "Berlin", "Munich", "Glasgow", "Liverpool", "London", "Nantes", "Paris"},
900 lclGetCategories(xChartDoc)[1]->getValues());
904 void PivotChartTest::testPivotChartWithDateRowField()
906 // SETUP DATA and PIVOT TABLE
908 mxComponent = loadFromDesktop("private:factory/scalc");
910 uno::Reference<sheet::XSpreadsheetDocument> xSheetDoc(mxComponent, uno::UNO_QUERY_THROW);
912 OUString sPivotTableName("DataPilotTable");
914 table::CellRangeAddress sCellRangeAddress = lclCreateTestData(xSheetDoc);
916 uno::Reference<sheet::XDataPilotTables> xDataPilotTables = lclGetDataPilotTables(0, xSheetDoc);
918 uno::Reference<sheet::XDataPilotDescriptor> xDataPilotDescriptor = xDataPilotTables->createDataPilotDescriptor();
919 xDataPilotDescriptor->setSourceRange(sCellRangeAddress);
921 lclModifyOrientation(xDataPilotDescriptor, u"Date", sheet::DataPilotFieldOrientation_ROW);
922 lclModifyOrientation(xDataPilotDescriptor, u"City", sheet::DataPilotFieldOrientation_ROW);
923 lclModifyOrientation(xDataPilotDescriptor, u"Country", sheet::DataPilotFieldOrientation_ROW);
924 lclModifyOrientation(xDataPilotDescriptor, u"Type", sheet::DataPilotFieldOrientation_COLUMN);
925 lclModifyOrientation(xDataPilotDescriptor, u"Sales T1", sheet::DataPilotFieldOrientation_DATA);
926 lclModifyFunction(xDataPilotDescriptor, u"Sales T1", sheet::GeneralFunction_SUM);
928 lclModifyColumnGrandTotal(xDataPilotDescriptor, true);
929 lclModifyRowGrandTotal(xDataPilotDescriptor, true);
931 xDataPilotTables->insertNewByName(sPivotTableName, table::CellAddress{1, 0, 0}, xDataPilotDescriptor);
933 // TEST
934 Reference<chart2::XChartDocument> xChartDoc;
936 // Check we have the Pivot Table
937 uno::Reference<sheet::XDataPilotTable> xDataPilotTable = lclGetPivotTableByName(1, sPivotTableName, mxComponent);
938 CPPUNIT_ASSERT(xDataPilotTable.is());
940 // refetch the XDataPilotDescriptor
941 xDataPilotDescriptor.set(xDataPilotTable, uno::UNO_QUERY_THROW);
943 // Check that we don't have any pivot chart in the document
944 uno::Reference<table::XTablePivotCharts> xTablePivotCharts = getTablePivotChartsFromSheet(1, mxComponent);
945 uno::Reference<container::XIndexAccess> xIndexAccess(xTablePivotCharts, UNO_QUERY_THROW);
946 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xIndexAccess->getCount());
948 // Create a new pivot chart
949 xTablePivotCharts->addNewByName("PivotChart", awt::Rectangle{ 9000, 9000, 21000, 18000 }, sPivotTableName);
950 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount());
952 // Get the pivot chart document so we can access its data
953 xChartDoc.set(getPivotChartDocFromSheet(xTablePivotCharts, 0));
955 CPPUNIT_ASSERT(xChartDoc.is());
957 // Check if Date category is date formatted.
958 lclCheckCategories( { "12/11/15", "", "", "", "", "", "12/14/15", "12/17/15", "01/20/16", "", "", "03/21/17" },
959 lclGetCategories( xChartDoc )[0]->getValues() );
963 CPPUNIT_TEST_SUITE_REGISTRATION(PivotChartTest);
965 CPPUNIT_PLUGIN_IMPLEMENT();
967 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */