Avoid potential negative array index access to cached text.
[LibreOffice.git] / chart2 / qa / extras / chart2export2.cxx
blobf5378dc9444cb9fd86cee340780483ecec929101
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/chart2/XDataPointCustomLabelField.hpp>
13 #include <com/sun/star/chart2/DataPointCustomLabelFieldType.hpp>
14 #include <com/sun/star/chart2/RelativePosition.hpp>
15 #include <com/sun/star/text/XText.hpp>
16 #include <com/sun/star/chart2/DataPointLabel.hpp>
17 #include <com/sun/star/chart/DataLabelPlacement.hpp>
18 #include <com/sun/star/graphic/XGraphic.hpp>
20 using uno::Reference;
21 using beans::XPropertySet;
23 class Chart2ExportTest2 : public ChartTest
25 public:
26 Chart2ExportTest2()
27 : ChartTest("/chart2/qa/extras/data/")
32 CPPUNIT_TEST_FIXTURE(Chart2ExportTest2, testSetSeriesToSecondaryAxisXLSX)
34 loadFromFile(u"xlsx/add_series_secondary_axis.xlsx");
35 Reference<chart2::XChartDocument> xChartDoc = getChartDocFromSheet(0, mxComponent);
36 // Second series
37 Reference<chart2::XDataSeries> xSeries = getDataSeriesFromDoc(xChartDoc, 1);
38 CPPUNIT_ASSERT(xSeries.is());
40 Reference<beans::XPropertySet> xPropSet(xSeries, uno::UNO_QUERY_THROW);
41 sal_Int32 AxisIndex = 1;
42 // Attach the second series to the secondary axis. (The third series is already attached.)
43 xPropSet->setPropertyValue("AttachedAxisIndex", uno::Any(AxisIndex));
45 save("Calc Office Open XML");
46 xmlDocUniquePtr pXmlDoc = parseExport("xl/charts/chart1.xml");
47 CPPUNIT_ASSERT(pXmlDoc);
48 // Check there are only two <lineChart> tag in the XML, one for the primary and one for the secondary axis.
49 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:lineChart"_ostr, 2);
52 CPPUNIT_TEST_FIXTURE(Chart2ExportTest2, testCombinedChartSecondaryAxisXLSX)
54 // Original file was created with MS Office
55 loadFromFile(u"xlsx/combined_chart_secondary_axis.xlsx");
56 save("Calc Office Open XML");
57 xmlDocUniquePtr pXmlDoc = parseExport("xl/charts/chart1.xml");
58 CPPUNIT_ASSERT(pXmlDoc);
59 // Collect barchart axID on secondary Axis
60 OUString XValueIdOfBarchart = getXPath(
61 pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:barChart/c:axId[1]"_ostr, "val"_ostr);
62 OUString YValueIdOfBarchart = getXPath(
63 pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:barChart/c:axId[2]"_ostr, "val"_ostr);
64 // Collect linechart axID on primary Axis
65 OUString XValueIdOfLinechart = getXPath(
66 pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:lineChart/c:axId[1]"_ostr, "val"_ostr);
67 OUString YValueIdOfLinechart = getXPath(
68 pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:lineChart/c:axId[2]"_ostr, "val"_ostr);
69 // Check which c:catAx and c:valAx contain the AxisId of charttypes
70 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:catAx[1]/c:axId"_ostr, "val"_ostr,
71 XValueIdOfLinechart);
72 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:valAx[1]/c:axId"_ostr, "val"_ostr,
73 YValueIdOfLinechart);
74 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:catAx[2]/c:axId"_ostr, "val"_ostr,
75 XValueIdOfBarchart);
76 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:valAx[2]/c:axId"_ostr, "val"_ostr,
77 YValueIdOfBarchart);
80 CPPUNIT_TEST_FIXTURE(Chart2ExportTest2, testCombinedChartSecondaryAxisODS)
82 // Original file was created with LibreOffice
83 loadFromFile(u"ods/combined_chart_secondary_axis.ods");
84 save("Calc Office Open XML");
85 xmlDocUniquePtr pXmlDoc = parseExport("xl/charts/chart1.xml");
86 CPPUNIT_ASSERT(pXmlDoc);
87 // Collect barchart axID on secondary Axis
88 OUString XValueIdOfBarchart = getXPath(
89 pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:barChart/c:axId[1]"_ostr, "val"_ostr);
90 OUString YValueIdOfBarchart = getXPath(
91 pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:barChart/c:axId[2]"_ostr, "val"_ostr);
92 // Collect linechart axID on primary Axis
93 OUString XValueIdOfLinechart = getXPath(
94 pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:lineChart/c:axId[1]"_ostr, "val"_ostr);
95 OUString YValueIdOfLinechart = getXPath(
96 pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:lineChart/c:axId[2]"_ostr, "val"_ostr);
97 // Check which c:catAx and c:valAx contain the AxisId of charttypes
98 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:catAx[1]/c:axId"_ostr, "val"_ostr,
99 XValueIdOfLinechart);
100 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:valAx[1]/c:axId"_ostr, "val"_ostr,
101 YValueIdOfLinechart);
102 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:catAx[2]/c:axId"_ostr, "val"_ostr,
103 XValueIdOfBarchart);
104 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:valAx[2]/c:axId"_ostr, "val"_ostr,
105 YValueIdOfBarchart);
106 // do not need CT_crosses tag if the actual axis is deleted, so we need to make sure it is not saved
107 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:catAx[2]/c:crosses"_ostr, 0);
110 CPPUNIT_TEST_FIXTURE(Chart2ExportTest2, testCrossBetweenXLSX)
112 // FIXME: validation error in OOXML export: Errors: 1
113 skipValidation();
115 // Original files were created with MS Office
117 loadFromFile(u"xlsx/tdf127777.xlsx");
118 save("Calc Office Open XML");
119 xmlDocUniquePtr pXmlDoc = parseExport("xl/charts/chart1.xml");
120 CPPUNIT_ASSERT(pXmlDoc);
121 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:valAx/c:crossBetween"_ostr,
122 "val"_ostr, "between");
125 loadFromFile(u"xlsx/tdf132076.xlsx");
126 save("Calc Office Open XML");
127 xmlDocUniquePtr pXmlDoc = parseExport("xl/charts/chart1.xml");
128 CPPUNIT_ASSERT(pXmlDoc);
129 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:valAx/c:crossBetween"_ostr,
130 "val"_ostr, "between");
134 CPPUNIT_TEST_FIXTURE(Chart2ExportTest2, testCrossBetweenWithDeletedAxis)
136 // Original file was created with MS Office (the category axis is deleted in the file)
137 loadFromFile(u"xlsx/tdf128633.xlsx");
138 save("Calc Office Open XML");
139 xmlDocUniquePtr pXmlDoc = parseExport("xl/charts/chart1.xml");
140 CPPUNIT_ASSERT(pXmlDoc);
141 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:valAx/c:crossBetween"_ostr, "val"_ostr,
142 "between");
145 CPPUNIT_TEST_FIXTURE(Chart2ExportTest2, testCrossBetweenODS)
147 // Original file was created with LibreOffice
148 loadFromFile(u"ods/test_CrossBetween.ods");
149 save("Calc Office Open XML");
150 xmlDocUniquePtr pXmlDoc = parseExport("xl/charts/chart1.xml");
151 CPPUNIT_ASSERT(pXmlDoc);
152 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:valAx/c:crossBetween"_ostr, "val"_ostr,
153 "between");
156 CPPUNIT_TEST_FIXTURE(Chart2ExportTest2, testAxisTitleRotationXLSX)
158 loadFromFile(u"xlsx/axis_title_rotation.xlsx");
159 save("Calc Office Open XML");
160 xmlDocUniquePtr pXmlDoc = parseExport("xl/charts/chart1.xml");
161 CPPUNIT_ASSERT(pXmlDoc);
163 assertXPath(pXmlDoc,
164 "/c:chartSpace/c:chart/c:plotArea/c:valAx/c:title/c:tx/c:rich/a:bodyPr"_ostr,
165 "rot"_ostr, "0");
168 CPPUNIT_TEST_FIXTURE(Chart2ExportTest2, testAxisTitlePositionDOCX)
170 loadFromFile(u"docx/testAxisTitlePosition.docx");
171 save("Office Open XML Text");
172 xmlDocUniquePtr pXmlDoc = parseExport("word/charts/chart1.xml");
173 CPPUNIT_ASSERT(pXmlDoc);
175 // test X Axis title position
176 OUString aXVal = getXPath(
177 pXmlDoc,
178 "/c:chartSpace/c:chart/c:plotArea/c:catAx/c:title/c:layout/c:manualLayout/c:x"_ostr,
179 "val"_ostr);
180 double nX = aXVal.toDouble();
181 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.698208543867708, nX, 1e-3);
182 OUString aYVal = getXPath(
183 pXmlDoc,
184 "/c:chartSpace/c:chart/c:plotArea/c:catAx/c:title/c:layout/c:manualLayout/c:y"_ostr,
185 "val"_ostr);
186 double nY = aYVal.toDouble();
187 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.805152435594555, nY, 1e-3);
189 // test Y Axis title position
190 aXVal = getXPath(
191 pXmlDoc,
192 "/c:chartSpace/c:chart/c:plotArea/c:valAx/c:title/c:layout/c:manualLayout/c:x"_ostr,
193 "val"_ostr);
194 nX = aXVal.toDouble();
195 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0253953671500755, nX, 1e-3);
196 aYVal = getXPath(
197 pXmlDoc,
198 "/c:chartSpace/c:chart/c:plotArea/c:valAx/c:title/c:layout/c:manualLayout/c:y"_ostr,
199 "val"_ostr);
200 nY = aYVal.toDouble();
201 // just test the first two decimal digits because it is not perfect in docx yet.
202 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.384070199122511, nY, 1e-2);
205 CPPUNIT_TEST_FIXTURE(Chart2ExportTest2, testAxisCrossBetweenDOCX)
207 loadFromFile(u"odt/axis-position.odt");
209 // FIXME: validation error in OOXML export: Errors: 3
210 skipValidation();
212 save("Office Open XML Text");
213 xmlDocUniquePtr pXmlDoc = parseExport("word/charts/chart1.xml");
214 assertXPath(pXmlDoc, "(//c:crossBetween)[1]"_ostr, "val"_ostr, "midCat");
217 CPPUNIT_TEST_FIXTURE(Chart2ExportTest2, testPieChartDataPointExplosionXLSX)
219 loadFromFile(u"xlsx/pie_chart_datapoint_explosion.xlsx");
220 save("Calc Office Open XML");
221 xmlDocUniquePtr pXmlDoc = parseExport("xl/charts/chart1.xml");
222 CPPUNIT_ASSERT(pXmlDoc);
224 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:pieChart/c:ser/c:dPt/c:explosion"_ostr,
225 "val"_ostr, "28");
228 CPPUNIT_TEST_FIXTURE(Chart2ExportTest2, testCustomDataLabel)
230 loadFromFile(u"pptx/tdf115107.pptx");
232 Reference<chart2::XChartDocument> xChartDoc(getChartDocFromDrawImpress(0, 0), uno::UNO_QUERY);
233 CPPUNIT_ASSERT(xChartDoc.is());
235 uno::Reference<chart2::XDataSeries> xDataSeries(getDataSeriesFromDoc(xChartDoc, 0));
236 CPPUNIT_ASSERT(xDataSeries.is());
237 float nFontSize;
238 sal_Int64 nFontColor;
239 sal_Int32 nCharUnderline;
240 uno::Reference<beans::XPropertySet> xPropertySet;
241 uno::Sequence<uno::Reference<chart2::XDataPointCustomLabelField>> aFields;
243 // 1
244 xPropertySet.set(xDataSeries->getDataPointByIndex(0), uno::UNO_SET_THROW);
245 xPropertySet->getPropertyValue("CustomLabelFields") >>= aFields;
246 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(2), aFields.getLength());
248 CPPUNIT_ASSERT_EQUAL(chart2::DataPointCustomLabelFieldType::DataPointCustomLabelFieldType_TEXT,
249 aFields[0]->getFieldType());
250 CPPUNIT_ASSERT_EQUAL(OUString("90.0 = "), aFields[0]->getString());
251 aFields[0]->getPropertyValue("CharHeight") >>= nFontSize;
252 aFields[0]->getPropertyValue("CharColor") >>= nFontColor;
253 CPPUNIT_ASSERT_EQUAL(static_cast<float>(18), nFontSize);
254 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int64>(0xed7d31), nFontColor);
256 CPPUNIT_ASSERT_EQUAL(chart2::DataPointCustomLabelFieldType::DataPointCustomLabelFieldType_VALUE,
257 aFields[1]->getFieldType());
258 CPPUNIT_ASSERT_EQUAL(OUString("90"), aFields[1]->getString());
259 CPPUNIT_ASSERT_EQUAL(OUString("{0C576297-5A9F-4B4E-A675-B6BA406B7D87}"), aFields[1]->getGuid());
261 // 2
262 xPropertySet.set(xDataSeries->getDataPointByIndex(1), uno::UNO_SET_THROW);
263 xPropertySet->getPropertyValue("CustomLabelFields") >>= aFields;
264 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(8), aFields.getLength());
266 CPPUNIT_ASSERT_EQUAL(chart2::DataPointCustomLabelFieldType::DataPointCustomLabelFieldType_TEXT,
267 aFields[0]->getFieldType());
268 CPPUNIT_ASSERT_EQUAL(OUString("Text"), aFields[0]->getString());
270 CPPUNIT_ASSERT_EQUAL(chart2::DataPointCustomLabelFieldType::DataPointCustomLabelFieldType_TEXT,
271 aFields[1]->getFieldType());
272 CPPUNIT_ASSERT_EQUAL(OUString(" : "), aFields[1]->getString());
274 CPPUNIT_ASSERT_EQUAL(
275 chart2::DataPointCustomLabelFieldType::DataPointCustomLabelFieldType_CATEGORYNAME,
276 aFields[2]->getFieldType());
277 CPPUNIT_ASSERT_EQUAL(OUString("B"), aFields[2]->getString());
278 CPPUNIT_ASSERT_EQUAL(OUString("{0CCAAACD-B393-42CE-8DBD-82F9F9ADC852}"), aFields[2]->getGuid());
279 aFields[2]->getPropertyValue("CharHeight") >>= nFontSize;
280 aFields[2]->getPropertyValue("CharColor") >>= nFontColor;
281 CPPUNIT_ASSERT_EQUAL(static_cast<float>(16), nFontSize);
282 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int64>(0xed7d31), nFontColor);
284 CPPUNIT_ASSERT_EQUAL(
285 chart2::DataPointCustomLabelFieldType::DataPointCustomLabelFieldType_NEWLINE,
286 aFields[3]->getFieldType());
288 CPPUNIT_ASSERT_EQUAL(chart2::DataPointCustomLabelFieldType::DataPointCustomLabelFieldType_TEXT,
289 aFields[4]->getFieldType());
290 CPPUNIT_ASSERT_EQUAL(OUString("Multi"), aFields[4]->getString());
292 CPPUNIT_ASSERT_EQUAL(chart2::DataPointCustomLabelFieldType::DataPointCustomLabelFieldType_TEXT,
293 aFields[5]->getFieldType());
294 CPPUNIT_ASSERT_EQUAL(OUString("line"), aFields[5]->getString());
295 aFields[5]->getPropertyValue("CharHeight") >>= nFontSize;
296 aFields[5]->getPropertyValue("CharColor") >>= nFontColor;
297 CPPUNIT_ASSERT_EQUAL(static_cast<float>(11.97), nFontSize);
298 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int64>(0xbf9000), nFontColor);
300 CPPUNIT_ASSERT_EQUAL(
301 chart2::DataPointCustomLabelFieldType::DataPointCustomLabelFieldType_NEWLINE,
302 aFields[6]->getFieldType());
304 CPPUNIT_ASSERT_EQUAL(chart2::DataPointCustomLabelFieldType::DataPointCustomLabelFieldType_TEXT,
305 aFields[7]->getFieldType());
306 CPPUNIT_ASSERT_EQUAL(OUString("Abc"), aFields[7]->getString());
307 aFields[7]->getPropertyValue("CharHeight") >>= nFontSize;
308 aFields[7]->getPropertyValue("CharColor") >>= nFontColor;
309 aFields[7]->getPropertyValue("CharUnderline") >>= nCharUnderline;
310 CPPUNIT_ASSERT_EQUAL(static_cast<float>(12), nFontSize);
311 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int64>(0xa9d18e), nFontColor);
312 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1), nCharUnderline);
314 // 3
315 xPropertySet.set(xDataSeries->getDataPointByIndex(2), uno::UNO_SET_THROW);
316 xPropertySet->getPropertyValue("CustomLabelFields") >>= aFields;
317 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1), aFields.getLength());
319 CPPUNIT_ASSERT_EQUAL(
320 chart2::DataPointCustomLabelFieldType::DataPointCustomLabelFieldType_SERIESNAME,
321 aFields[0]->getFieldType());
322 CPPUNIT_ASSERT_EQUAL(OUString("DATA"), aFields[0]->getString());
323 CPPUNIT_ASSERT_EQUAL(OUString("{C8F3EB90-8960-4F9A-A3AD-B4FAC4FE4566}"), aFields[0]->getGuid());
325 // 4
326 xPropertySet.set(xDataSeries->getDataPointByIndex(3), uno::UNO_SET_THROW);
327 xPropertySet->getPropertyValue("CustomLabelFields") >>= aFields;
328 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(2), aFields.getLength());
330 CPPUNIT_ASSERT_EQUAL(
331 chart2::DataPointCustomLabelFieldType::DataPointCustomLabelFieldType_CELLREF,
332 aFields[0]->getFieldType());
333 //CPPUNIT_ASSERT_EQUAL(OUString("70"), aFields[0]->getString()); TODO: Not implemented yet
335 CPPUNIT_ASSERT_EQUAL(chart2::DataPointCustomLabelFieldType::DataPointCustomLabelFieldType_TEXT,
336 aFields[1]->getFieldType());
337 CPPUNIT_ASSERT_EQUAL(OUString(" <CELLREF"), aFields[1]->getString());
339 save("Impress MS PowerPoint 2007 XML");
340 xmlDocUniquePtr pXmlDoc = parseExport("ppt/charts/chart1.xml");
341 CPPUNIT_ASSERT(pXmlDoc);
342 // Check the data labels font color for the complete data series
343 assertXPath(pXmlDoc,
344 "/c:chartSpace/c:chart/c:plotArea/c:barChart/c:ser/c:dLbls/c:txPr/a:p/a:pPr/"
345 "a:defRPr/a:solidFill/a:srgbClr"_ostr,
346 "val"_ostr, "404040");
349 /// Test for tdf#94235
350 CPPUNIT_TEST_FIXTURE(Chart2ExportTest2, testDataSeriesName)
352 // ODF
354 loadFromFile(u"ods/ser_labels.ods");
355 saveAndReload("calc8");
356 uno::Reference<chart2::XChartDocument> xChartDoc = getChartDocFromSheet(0, mxComponent);
357 uno::Reference<chart2::XDataSeries> xDataSeries(getDataSeriesFromDoc(xChartDoc, 0));
358 CPPUNIT_ASSERT(xDataSeries.is());
359 uno::Reference<beans::XPropertySet> xPropertySet;
360 chart2::DataPointLabel aDataPointLabel;
361 xPropertySet.set(xDataSeries->getDataPointByIndex(0), uno::UNO_SET_THROW);
362 xPropertySet->getPropertyValue("Label") >>= aDataPointLabel;
363 CPPUNIT_ASSERT_EQUAL(sal_True, aDataPointLabel.ShowSeriesName);
366 // OOXML
368 loadFromFile(u"xlsx/ser_labels.xlsx");
369 saveAndReload("Calc Office Open XML");
370 uno::Reference<chart2::XChartDocument> xChartDoc = getChartDocFromSheet(0, mxComponent);
371 uno::Reference<chart2::XDataSeries> xDataSeries(getDataSeriesFromDoc(xChartDoc, 0));
372 CPPUNIT_ASSERT(xDataSeries.is());
373 uno::Reference<beans::XPropertySet> xPropertySet;
374 chart2::DataPointLabel aDataPointLabel;
375 xPropertySet.set(xDataSeries->getDataPointByIndex(0), uno::UNO_SET_THROW);
376 xPropertySet->getPropertyValue("Label") >>= aDataPointLabel;
377 CPPUNIT_ASSERT_EQUAL(sal_True, aDataPointLabel.ShowSeriesName);
381 CPPUNIT_TEST_FIXTURE(Chart2ExportTest2, testCustomPositionofDataLabel)
383 // FIXME: validation error in OOXML export: Errors: 1
384 skipValidation();
386 loadFromFile(u"xlsx/testCustomPosDataLabels.xlsx");
388 save("Calc Office Open XML");
389 xmlDocUniquePtr pXmlDoc = parseExport("xl/charts/chart1.xml");
390 CPPUNIT_ASSERT(pXmlDoc);
392 // test custom position of data label (xlsx)
393 assertXPath(
394 pXmlDoc,
395 "/c:chartSpace/c:chart/c:plotArea/c:lineChart/c:ser/c:dLbls/c:dLbl[1]/c:idx"_ostr,
396 "val"_ostr, "2");
397 OUString aXVal = getXPath(pXmlDoc,
398 "/c:chartSpace/c:chart/c:plotArea/c:lineChart/c:ser/c:dLbls/"
399 "c:dLbl[1]/c:layout/c:manualLayout/c:x"_ostr,
400 "val"_ostr);
401 double nX = aXVal.toDouble();
402 CPPUNIT_ASSERT_DOUBLES_EQUAL(-0.11027682973075476, nX, 1e-7);
404 OUString aYVal = getXPath(pXmlDoc,
405 "/c:chartSpace/c:chart/c:plotArea/c:lineChart/c:ser/c:dLbls/"
406 "c:dLbl[1]/c:layout/c:manualLayout/c:y"_ostr,
407 "val"_ostr);
408 double nY = aYVal.toDouble();
409 CPPUNIT_ASSERT_DOUBLES_EQUAL(-0.0742140311063737, nY, 1e-7);
412 loadFromFile(u"docx/testTdf108110.docx");
414 save("Office Open XML Text");
415 xmlDocUniquePtr pXmlDoc = parseExport("word/charts/chart1.xml");
416 CPPUNIT_ASSERT(pXmlDoc);
418 // test custom position of data label (docx)
419 assertXPath(
420 pXmlDoc,
421 "/c:chartSpace/c:chart/c:plotArea/c:lineChart/c:ser/c:dLbls/c:dLbl[2]/c:idx"_ostr,
422 "val"_ostr, "2");
423 OUString aXVal = getXPath(pXmlDoc,
424 "/c:chartSpace/c:chart/c:plotArea/c:lineChart/c:ser/c:dLbls/"
425 "c:dLbl[2]/c:layout/c:manualLayout/c:x"_ostr,
426 "val"_ostr);
427 double nX = aXVal.toDouble();
428 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0227256488772236, nX, 1e-7);
430 OUString aYVal = getXPath(pXmlDoc,
431 "/c:chartSpace/c:chart/c:plotArea/c:lineChart/c:ser/c:dLbls/"
432 "c:dLbl[2]/c:layout/c:manualLayout/c:y"_ostr,
433 "val"_ostr);
434 double nY = aYVal.toDouble();
435 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.172648731408574, nY, 1e-7);
438 loadFromFile(u"ods/tdf136024.ods");
440 saveAndReload("calc8");
441 // tdf#136024: test custom position of pie chart data label after an ods export
442 Reference<chart2::XChartDocument> xChartDoc = getChartDocFromSheet(0, mxComponent);
443 CPPUNIT_ASSERT(xChartDoc.is());
445 Reference<chart2::XDataSeries> xDataSeries(getDataSeriesFromDoc(xChartDoc, 0));
446 CPPUNIT_ASSERT(xDataSeries.is());
447 uno::Reference<beans::XPropertySet> xPropertySet(xDataSeries->getDataPointByIndex(0),
448 uno::UNO_SET_THROW);
450 chart2::RelativePosition aCustomLabelPosition;
451 CPPUNIT_ASSERT(xPropertySet->getPropertyValue("CustomLabelPosition")
452 >>= aCustomLabelPosition);
453 CPPUNIT_ASSERT_DOUBLES_EQUAL(-0.0961935120945059, aCustomLabelPosition.Primary, 1e-5);
454 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.209578842093566, aCustomLabelPosition.Secondary, 1e-5);
458 CPPUNIT_TEST_FIXTURE(Chart2ExportTest2, testCustomDataLabelMultipleSeries)
460 loadFromFile(u"pptx/tdf115107-2.pptx");
462 Reference<chart2::XChartDocument> xChartDoc(getChartDocFromDrawImpress(0, 0), uno::UNO_QUERY);
463 CPPUNIT_ASSERT(xChartDoc.is());
465 uno::Reference<chart2::XDataSeries> xDataSeries(getDataSeriesFromDoc(xChartDoc, 0));
466 CPPUNIT_ASSERT(xDataSeries.is());
467 float nFontSize;
468 sal_Int64 nFontColor;
469 uno::Reference<beans::XPropertySet> xPropertySet;
470 uno::Sequence<uno::Reference<chart2::XDataPointCustomLabelField>> aFields;
472 // First series
473 xPropertySet.set(xDataSeries->getDataPointByIndex(0), uno::UNO_SET_THROW);
474 xPropertySet->getPropertyValue("CustomLabelFields") >>= aFields;
475 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(3), aFields.getLength());
477 CPPUNIT_ASSERT_EQUAL(chart2::DataPointCustomLabelFieldType::DataPointCustomLabelFieldType_VALUE,
478 aFields[0]->getFieldType());
479 CPPUNIT_ASSERT_EQUAL(OUString("4.3"), aFields[0]->getString());
480 aFields[0]->getPropertyValue("CharHeight") >>= nFontSize;
481 aFields[0]->getPropertyValue("CharColor") >>= nFontColor;
482 CPPUNIT_ASSERT_EQUAL(static_cast<float>(18), nFontSize);
483 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int64>(0xc00000), nFontColor);
485 CPPUNIT_ASSERT_EQUAL(chart2::DataPointCustomLabelFieldType::DataPointCustomLabelFieldType_TEXT,
486 aFields[1]->getFieldType());
487 CPPUNIT_ASSERT_EQUAL(OUString(" "), aFields[1]->getString());
489 CPPUNIT_ASSERT_EQUAL(
490 chart2::DataPointCustomLabelFieldType::DataPointCustomLabelFieldType_SERIESNAME,
491 aFields[2]->getFieldType());
492 CPPUNIT_ASSERT_EQUAL(OUString("Bars"), aFields[2]->getString());
494 // Second series
495 xDataSeries = getDataSeriesFromDoc(xChartDoc, 0, 1);
496 CPPUNIT_ASSERT(xDataSeries.is());
498 xPropertySet.set(xDataSeries->getDataPointByIndex(0), uno::UNO_SET_THROW);
499 xPropertySet->getPropertyValue("CustomLabelFields") >>= aFields;
500 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(3), aFields.getLength());
502 CPPUNIT_ASSERT_EQUAL(chart2::DataPointCustomLabelFieldType::DataPointCustomLabelFieldType_VALUE,
503 aFields[0]->getFieldType());
504 CPPUNIT_ASSERT_EQUAL(OUString("2"), aFields[0]->getString());
505 aFields[0]->getPropertyValue("CharHeight") >>= nFontSize;
506 aFields[0]->getPropertyValue("CharColor") >>= nFontColor;
507 CPPUNIT_ASSERT_EQUAL(static_cast<float>(18), nFontSize);
508 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int64>(0xffd966), nFontColor);
510 CPPUNIT_ASSERT_EQUAL(chart2::DataPointCustomLabelFieldType::DataPointCustomLabelFieldType_TEXT,
511 aFields[1]->getFieldType());
512 CPPUNIT_ASSERT_EQUAL(OUString(" "), aFields[1]->getString());
514 CPPUNIT_ASSERT_EQUAL(
515 chart2::DataPointCustomLabelFieldType::DataPointCustomLabelFieldType_SERIESNAME,
516 aFields[2]->getFieldType());
517 CPPUNIT_ASSERT_EQUAL(OUString("Line"), aFields[2]->getString());
520 CPPUNIT_TEST_FIXTURE(Chart2ExportTest2, testLeaderLines)
522 // FIXME: validation error in OOXML export: Errors: 2
523 skipValidation();
525 loadFromFile(u"xlsx/testTdf90749.xlsx");
527 save("Calc Office Open XML");
528 xmlDocUniquePtr pXmlDoc = parseExport("xl/charts/chart1.xml");
529 CPPUNIT_ASSERT(pXmlDoc);
530 assertXPath(pXmlDoc,
531 "/c:chartSpace/c:chart/c:plotArea/c:lineChart/c:ser[1]/c:dLbls/c:extLst/c:ext/"
532 "c15:showLeaderLines"_ostr,
533 "val"_ostr, "1");
534 assertXPath(pXmlDoc,
535 "/c:chartSpace/c:chart/c:plotArea/c:lineChart/c:ser[2]/c:dLbls/c:extLst/c:ext/"
536 "c15:showLeaderLines"_ostr,
537 "val"_ostr, "0");
539 loadFromFile(u"docx/MSO_Custom_Leader_Line.docx");
541 save("Office Open XML Text");
542 xmlDocUniquePtr pXmlDoc = parseExport("word/charts/chart1.xml");
543 CPPUNIT_ASSERT(pXmlDoc);
544 // tdf#134571: Check the leader line is switch off.
545 assertXPath(pXmlDoc,
546 "/c:chartSpace/c:chart/c:plotArea/c:barChart/c:ser/c:dLbls/c:extLst/c:ext/"
547 "c15:showLeaderLines"_ostr,
548 "val"_ostr, "0");
552 CPPUNIT_TEST_FIXTURE(Chart2ExportTest2, testNumberFormatExportPPTX)
554 loadFromFile(u"pptx/tdf115859.pptx");
555 save("Impress MS PowerPoint 2007 XML");
556 xmlDocUniquePtr pXmlDoc = parseExport("ppt/charts/chart1.xml");
557 CPPUNIT_ASSERT(pXmlDoc);
559 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:barChart/c:ser/c:dLbls/c:numFmt"_ostr,
560 "formatCode"_ostr, "#,##0.00,\\K");
561 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:barChart/c:ser/c:dLbls/c:numFmt"_ostr,
562 "sourceLinked"_ostr, "0");
565 CPPUNIT_TEST_FIXTURE(Chart2ExportTest2, testLabelSeparatorExportDOCX)
567 loadFromFile(u"docx/testLabelSeparator.docx");
569 Reference<chart2::XChartDocument> xChartDoc(getChartDocFromWriter(0), uno::UNO_QUERY);
570 CPPUNIT_ASSERT(xChartDoc.is());
572 save("Office Open XML Text");
573 xmlDocUniquePtr pXmlDoc = parseExport("word/charts/chart1.xml");
574 CPPUNIT_ASSERT(pXmlDoc);
576 // The text separator should be a new line
577 assertXPathContent(
578 pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:barChart/c:ser[1]/c:dLbls/c:separator"_ostr,
579 "\n");
580 // The text separator should be a comma
581 assertXPathContent(
582 pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:barChart/c:ser[2]/c:dLbls/c:separator"_ostr,
583 ", ");
584 // The text separator should be a semicolon
585 assertXPathContent(
586 pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:barChart/c:ser[3]/c:dLbls/c:separator"_ostr,
587 "; ");
590 CPPUNIT_TEST_FIXTURE(Chart2ExportTest2, testChartTitlePropertiesColorFillPPTX)
592 loadFromFile(u"pptx/testChartTitlePropertiesColorFill.pptx");
593 save("Impress MS PowerPoint 2007 XML");
594 xmlDocUniquePtr pXmlDoc = parseExport("ppt/charts/chart1.xml");
595 CPPUNIT_ASSERT(pXmlDoc);
596 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:title/c:spPr/a:solidFill/a:srgbClr"_ostr,
597 "val"_ostr, "ff0000");
598 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:title/c:spPr/a:ln/a:noFill"_ostr, 1);
601 CPPUNIT_TEST_FIXTURE(Chart2ExportTest2, testChartTitlePropertiesGradientFillPPTX)
603 loadFromFile(u"pptx/testChartTitlePropertiesGradientFill.pptx");
604 save("Impress MS PowerPoint 2007 XML");
605 xmlDocUniquePtr pXmlDoc = parseExport("ppt/charts/chart1.xml");
606 CPPUNIT_ASSERT(pXmlDoc);
607 assertXPath(pXmlDoc,
608 "/c:chartSpace/c:chart/c:title/c:spPr/a:gradFill/a:gsLst/a:gs[1]/a:srgbClr"_ostr,
609 "val"_ostr, "f6f8fc");
610 assertXPath(pXmlDoc,
611 "/c:chartSpace/c:chart/c:title/c:spPr/a:gradFill/a:gsLst/a:gs[2]/a:srgbClr"_ostr,
612 "val"_ostr, "c7d5ed");
613 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:title/c:spPr/a:ln/a:noFill"_ostr, 1);
616 CPPUNIT_TEST_FIXTURE(Chart2ExportTest2, testChartTitlePropertiesBitmapFillPPTX)
618 loadFromFile(u"pptx/testChartTitlePropertiesBitmapFill.pptx");
619 save("Impress MS PowerPoint 2007 XML");
620 xmlDocUniquePtr pXmlDoc = parseExport("ppt/charts/chart1.xml");
621 CPPUNIT_ASSERT(pXmlDoc);
622 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:title/c:spPr/a:blipFill/a:blip"_ostr,
623 "embed"_ostr, "rId1");
624 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:title/c:spPr/a:ln/a:noFill"_ostr, 1);
627 CPPUNIT_TEST_FIXTURE(Chart2ExportTest2, testxAxisLabelsRotation)
629 loadFromFile(u"xlsx/xAxisLabelsRotation.xlsx");
630 save("Calc Office Open XML");
631 xmlDocUniquePtr pXmlDoc1 = parseExport("xl/charts/chart1.xml");
632 CPPUNIT_ASSERT(pXmlDoc1);
634 // Chart1 xAxis labels should be 45 degree
635 assertXPath(pXmlDoc1, "/c:chartSpace/c:chart/c:plotArea/c:catAx/c:txPr/a:bodyPr"_ostr,
636 "rot"_ostr, "2700000");
639 CPPUNIT_TEST_FIXTURE(Chart2ExportTest2, testMultipleCategoryAxisLablesXLSX)
641 loadFromFile(u"ods/multilevelcat.ods");
642 save("Calc Office Open XML");
643 xmlDocUniquePtr pXmlDoc = parseExport("xl/charts/chart1.xml");
644 CPPUNIT_ASSERT(pXmlDoc);
645 // check category axis labels number of first level
646 assertXPath(pXmlDoc,
647 "/c:chartSpace/c:chart/c:plotArea/c:barChart/c:ser[1]/c:cat/c:multiLvlStrRef/"
648 "c:multiLvlStrCache/c:ptCount"_ostr,
649 "val"_ostr, "6");
650 // check category axis labels text of first level
651 assertXPathContent(pXmlDoc,
652 "/c:chartSpace/c:chart/c:plotArea/c:barChart/c:ser[1]/c:cat/"
653 "c:multiLvlStrRef/c:multiLvlStrCache/c:lvl[1]/c:pt[1]/c:v"_ostr,
654 "Categoria 1");
655 assertXPathContent(pXmlDoc,
656 "/c:chartSpace/c:chart/c:plotArea/c:barChart/c:ser[1]/c:cat/"
657 "c:multiLvlStrRef/c:multiLvlStrCache/c:lvl[1]/c:pt[6]/c:v"_ostr,
658 "Categoria 6");
659 // check category axis labels text of second level
660 assertXPathContent(pXmlDoc,
661 "/c:chartSpace/c:chart/c:plotArea/c:barChart/c:ser[1]/c:cat/"
662 "c:multiLvlStrRef/c:multiLvlStrCache/c:lvl[2]/c:pt[1]/c:v"_ostr,
663 "2011");
664 assertXPathContent(pXmlDoc,
665 "/c:chartSpace/c:chart/c:plotArea/c:barChart/c:ser[1]/c:cat/"
666 "c:multiLvlStrRef/c:multiLvlStrCache/c:lvl[2]/c:pt[3]/c:v"_ostr,
667 "2013");
668 // check the 'noMultiLvlLbl' tag - ChartExport.cxx:2950 FIXME: seems not support, so check the default noMultiLvlLbl value.
669 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:catAx/c:noMultiLvlLbl"_ostr,
670 "val"_ostr, "0");
673 CPPUNIT_TEST_FIXTURE(Chart2ExportTest2, testMultipleCategoryAxisLablesDOCX)
675 loadFromFile(u"odt/multilevelcat.odt");
676 save("Office Open XML Text");
677 xmlDocUniquePtr pXmlDoc = parseExport("word/charts/chart1.xml");
678 CPPUNIT_ASSERT(pXmlDoc);
679 // check category axis labels number of first level
680 assertXPath(pXmlDoc,
681 "/c:chartSpace/c:chart/c:plotArea/c:barChart/c:ser[1]/c:cat/c:multiLvlStrRef/"
682 "c:multiLvlStrCache/c:ptCount"_ostr,
683 "val"_ostr, "4");
684 // check category axis labels text of first level
685 assertXPathContent(pXmlDoc,
686 "/c:chartSpace/c:chart/c:plotArea/c:barChart/c:ser[1]/c:cat/"
687 "c:multiLvlStrRef/c:multiLvlStrCache/c:lvl[1]/c:pt[1]/c:v"_ostr,
688 "Categoria 1");
689 assertXPathContent(pXmlDoc,
690 "/c:chartSpace/c:chart/c:plotArea/c:barChart/c:ser[1]/c:cat/"
691 "c:multiLvlStrRef/c:multiLvlStrCache/c:lvl[1]/c:pt[4]/c:v"_ostr,
692 "Categoria 4");
693 // check category axis labels text of second level
694 assertXPathContent(pXmlDoc,
695 "/c:chartSpace/c:chart/c:plotArea/c:barChart/c:ser[1]/c:cat/"
696 "c:multiLvlStrRef/c:multiLvlStrCache/c:lvl[2]/c:pt[1]/c:v"_ostr,
697 "2011");
698 assertXPathContent(pXmlDoc,
699 "/c:chartSpace/c:chart/c:plotArea/c:barChart/c:ser[1]/c:cat/"
700 "c:multiLvlStrRef/c:multiLvlStrCache/c:lvl[2]/c:pt[2]/c:v"_ostr,
701 "2012");
702 // check the 'noMultiLvlLbl' tag - ChartExport.cxx:2950 FIXME: seems not support, so check the default noMultiLvlLbl value.
703 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:catAx/c:noMultiLvlLbl"_ostr,
704 "val"_ostr, "0");
707 CPPUNIT_TEST_FIXTURE(Chart2ExportTest2, testTdf116163)
709 loadFromFile(u"pptx/tdf116163.pptx");
710 save("Impress MS PowerPoint 2007 XML");
711 xmlDocUniquePtr pXmlDoc = parseExport("ppt/charts/chart1.xml");
712 CPPUNIT_ASSERT(pXmlDoc);
714 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:catAx/c:txPr/a:bodyPr"_ostr,
715 "rot"_ostr, "-5400000");
718 CPPUNIT_TEST_FIXTURE(Chart2ExportTest2, testTdf111824)
720 loadFromFile(u"xlsx/tdf111824.xlsx");
721 save("Calc Office Open XML");
722 xmlDocUniquePtr pXmlDoc = parseExport("xl/charts/chart1.xml");
723 CPPUNIT_ASSERT(pXmlDoc);
725 // Collect 3D barchart Z axID
726 OUString zAxisIdOf3DBarchart = getXPath(
727 pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:bar3DChart/c:axId[3]"_ostr, "val"_ostr);
728 // 3D barchart Z axis properties should be in a serAx OOXML tag instead of catAx
729 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:serAx/c:axId"_ostr, "val"_ostr,
730 zAxisIdOf3DBarchart);
733 CPPUNIT_TEST_FIXTURE(Chart2ExportTest2, test3DAreaChartZAxis)
735 loadFromFile(u"xlsx/test3DAreaChartZAxis.xlsx");
736 save("Calc Office Open XML");
737 xmlDocUniquePtr pXmlDoc = parseExport("xl/charts/chart1.xml");
738 CPPUNIT_ASSERT(pXmlDoc);
740 // Collect 3D area chart Z axID
741 OUString zAxisIdOf3DAreachart = getXPath(
742 pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:area3DChart/c:axId[3]"_ostr, "val"_ostr);
743 // 3D area chart z-axis properties should be in a serAx OOXML element instead of catAx
744 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:serAx/c:axId"_ostr, "val"_ostr,
745 zAxisIdOf3DAreachart);
748 CPPUNIT_TEST_FIXTURE(Chart2ExportTest2, testTdf119029)
750 loadFromFile(u"odp/tdf119029.odp");
751 // Only use "chart", without number, because the number depends on the previous tests
752 save("Impress MS PowerPoint 2007 XML");
753 xmlDocUniquePtr pXmlDoc = parseExport("ppt/charts/chart1.xml");
754 CPPUNIT_ASSERT(pXmlDoc);
756 assertXPath(pXmlDoc,
757 "/c:chartSpace/c:chart/c:plotArea/c:barChart/c:ser/c:dLbls/c:txPr/a:bodyPr"_ostr,
758 "rot"_ostr, "-5400000");
761 CPPUNIT_TEST_FIXTURE(Chart2ExportTest2, testTdf108022)
763 loadFromFile(u"odt/tdf108022.odt");
764 saveAndReload("Office Open XML Text");
766 // assert we really have two charts
767 Reference<chart2::XChartDocument> xChartDoc1(getChartDocFromWriter(0), uno::UNO_QUERY);
768 CPPUNIT_ASSERT(xChartDoc1.is());
769 Reference<chart2::XChartDocument> xChartDoc2(getChartDocFromWriter(1), uno::UNO_QUERY);
770 CPPUNIT_ASSERT(xChartDoc2.is());
773 CPPUNIT_TEST_FIXTURE(Chart2ExportTest2, testTdf121744)
775 loadFromFile(u"docx/tdf121744.docx");
776 save("Office Open XML Text");
777 xmlDocUniquePtr pXmlDoc = parseExport("word/charts/chart1.xml");
778 CPPUNIT_ASSERT(pXmlDoc);
780 OUString XValueId = getXPath(
781 pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:barChart/c:axId[1]"_ostr, "val"_ostr);
782 OUString YValueId = getXPath(
783 pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:barChart/c:axId[2]"_ostr, "val"_ostr);
785 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:lineChart/c:axId[1]"_ostr, "val"_ostr,
786 XValueId);
787 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:lineChart/c:axId[2]"_ostr, "val"_ostr,
788 YValueId);
791 CPPUNIT_TEST_FIXTURE(Chart2ExportTest2, testTdf121189)
793 loadFromFile(u"odp/tdf121189.odp");
794 saveAndReload("Impress Office Open XML");
796 uno::Reference<drawing::XDrawPagesSupplier> xDoc(mxComponent, uno::UNO_QUERY_THROW);
797 uno::Reference<drawing::XDrawPage> xPage(xDoc->getDrawPages()->getByIndex(0),
798 uno::UNO_QUERY_THROW);
799 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xPage->getCount());
800 uno::Reference<drawing::XShape> xShape(xPage->getByIndex(0), uno::UNO_QUERY_THROW);
801 CPPUNIT_ASSERT_EQUAL(OUString("com.sun.star.drawing.OLE2Shape"), xShape->getShapeType());
804 CPPUNIT_TEST_FIXTURE(Chart2ExportTest2, testTdf122031)
806 //Checks pie chart data label format.
807 loadFromFile(u"xlsx/tdf122031.xlsx");
809 // FIXME: validation error in OOXML export: Errors: 1
810 skipValidation();
812 save("Calc Office Open XML");
813 xmlDocUniquePtr pXmlDoc = parseExport("xl/charts/chart1.xml");
814 CPPUNIT_ASSERT(pXmlDoc);
816 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:pieChart/c:ser/c:dLbls/c:numFmt"_ostr,
817 "formatCode"_ostr, "0.000%");
818 assertXPath(pXmlDoc,
819 "/c:chartSpace/c:chart/c:plotArea/c:pieChart/c:ser/c:dLbls/c:dLbl[1]/c:numFmt"_ostr,
820 "formatCode"_ostr, "0.000%");
821 assertXPath(pXmlDoc,
822 "/c:chartSpace/c:chart/c:plotArea/c:pieChart/c:ser/c:dLbls/c:dLbl[2]/c:numFmt"_ostr,
823 "formatCode"_ostr, "0.000%");
824 assertXPath(pXmlDoc,
825 "/c:chartSpace/c:chart/c:plotArea/c:pieChart/c:ser/c:dLbls/c:dLbl[3]/c:numFmt"_ostr,
826 "formatCode"_ostr, "0.000%");
829 CPPUNIT_TEST_FIXTURE(Chart2ExportTest2, testTdf115012)
831 loadFromFile(u"xlsx/tdf115012.xlsx");
832 save("Calc Office Open XML");
833 xmlDocUniquePtr pXmlDoc = parseExport("xl/charts/chart1.xml");
834 CPPUNIT_ASSERT(pXmlDoc);
835 // workaround: use-zero instead of leave-gap to show the original line chart
836 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:dispBlanksAs"_ostr, "val"_ostr, "zero");
839 CPPUNIT_TEST_FIXTURE(Chart2ExportTest2, testTdf134118)
841 loadFromFile(u"xlsx/tdf134118.xlsx");
843 // FIXME: validation error in OOXML export: Errors: 1
844 skipValidation();
846 save("Calc Office Open XML");
847 xmlDocUniquePtr pXmlDoc = parseExport("xl/charts/chart1.xml");
848 CPPUNIT_ASSERT(pXmlDoc);
849 // workaround: use leave-gap instead of zero to show the original line chart
850 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:dispBlanksAs"_ostr, "val"_ostr, "gap");
853 CPPUNIT_TEST_FIXTURE(Chart2ExportTest2, testTdf123206_customLabelText)
855 loadFromFile(u"docx/tdf123206.docx");
857 Reference<chart2::XChartDocument> xChartDoc(getChartDocFromWriter(0), uno::UNO_QUERY);
858 CPPUNIT_ASSERT(xChartDoc.is());
860 // FIXME: validation error in OOXML export: Errors: 2
861 skipValidation();
863 save("Office Open XML Text");
864 xmlDocUniquePtr pXmlDoc = parseExport("word/charts/chart1.xml");
865 CPPUNIT_ASSERT(pXmlDoc);
867 assertXPathContent(pXmlDoc,
868 "/c:chartSpace/c:chart/c:plotArea/c:pieChart/c:ser/c:dLbls/c:dLbl[2]/c:tx/"
869 "c:rich/a:p/a:r/a:t"_ostr,
870 "kiscica");
873 CPPUNIT_TEST_FIXTURE(Chart2ExportTest2, testCustomLabelText)
875 loadFromFile(u"docx/testCustomlabeltext.docx");
877 Reference<chart2::XChartDocument> xChartDoc(getChartDocFromWriter(0), uno::UNO_QUERY);
878 CPPUNIT_ASSERT(xChartDoc.is());
880 // FIXME: validation error in OOXML export: Errors: 3
881 skipValidation();
883 save("Office Open XML Text");
884 xmlDocUniquePtr pXmlDoc = parseExport("word/charts/chart1.xml");
885 CPPUNIT_ASSERT(pXmlDoc);
887 assertXPath(pXmlDoc,
888 "/c:chartSpace/c:chart/c:plotArea/c:barChart/c:ser/c:dLbls/c:dLbl[1]/c:idx"_ostr,
889 "val"_ostr, "2");
890 assertXPathContent(pXmlDoc,
891 "/c:chartSpace/c:chart/c:plotArea/c:barChart/c:ser/c:dLbls/c:dLbl[1]/c:tx/"
892 "c:rich/a:p/a:r[1]/a:t"_ostr,
893 "3.5");
894 assertXPathContent(pXmlDoc,
895 "/c:chartSpace/c:chart/c:plotArea/c:barChart/c:ser/c:dLbls/c:dLbl[1]/c:tx/"
896 "c:rich/a:p/a:r[3]/a:t"_ostr,
897 "CustomLabel 1");
899 assertXPath(pXmlDoc,
900 "/c:chartSpace/c:chart/c:plotArea/c:barChart/c:ser/c:dLbls/c:dLbl[2]/c:idx"_ostr,
901 "val"_ostr, "3");
902 assertXPathContent(pXmlDoc,
903 "/c:chartSpace/c:chart/c:plotArea/c:barChart/c:ser/c:dLbls/c:dLbl[2]/c:tx/"
904 "c:rich/a:p/a:r[1]/a:t"_ostr,
905 "4.5");
906 assertXPathContent(pXmlDoc,
907 "/c:chartSpace/c:chart/c:plotArea/c:barChart/c:ser/c:dLbls/c:dLbl[2]/c:tx/"
908 "c:rich/a:p/a:r[3]/a:t"_ostr,
909 "CustomLabel 2");
912 CPPUNIT_TEST_FIXTURE(Chart2ExportTest2, testDeletedLegendEntries)
914 loadFromFile(u"xlsx/deleted_legend_entry.xlsx");
916 saveAndReload("Calc Office Open XML");
917 Reference<chart2::XChartDocument> xChartDoc = getChartDocFromSheet(0, mxComponent);
918 CPPUNIT_ASSERT(xChartDoc.is());
919 Reference<chart2::XDataSeries> xDataSeries(getDataSeriesFromDoc(xChartDoc, 1));
920 CPPUNIT_ASSERT(xDataSeries.is());
921 Reference<beans::XPropertySet> xPropertySet(xDataSeries, uno::UNO_QUERY_THROW);
922 bool bShowLegendEntry = true;
923 CPPUNIT_ASSERT(xPropertySet->getPropertyValue("ShowLegendEntry") >>= bShowLegendEntry);
924 CPPUNIT_ASSERT(!bShowLegendEntry);
927 loadFromFile(u"xlsx/deleted_legend_entry2.xlsx");
929 saveAndReload("Calc Office Open XML");
930 Reference<chart2::XChartDocument> xChartDoc = getChartDocFromSheet(0, mxComponent);
931 CPPUNIT_ASSERT(xChartDoc.is());
932 Reference<chart2::XDataSeries> xDataSeries(getDataSeriesFromDoc(xChartDoc, 0));
933 CPPUNIT_ASSERT(xDataSeries.is());
934 Reference<beans::XPropertySet> xPropertySet(xDataSeries, uno::UNO_QUERY_THROW);
935 bool bShowLegendEntry = true;
936 CPPUNIT_ASSERT(xPropertySet->getPropertyValue("ShowLegendEntry") >>= bShowLegendEntry);
937 CPPUNIT_ASSERT(!bShowLegendEntry);
939 Reference<chart2::XChartDocument> xChartDoc2 = getChartDocFromSheet(1, mxComponent);
940 CPPUNIT_ASSERT(xChartDoc.is());
941 Reference<chart2::XDataSeries> xDataSeries2(getDataSeriesFromDoc(xChartDoc2, 0));
942 CPPUNIT_ASSERT(xDataSeries2.is());
943 Reference<beans::XPropertySet> xPropertySet2(xDataSeries2, uno::UNO_QUERY_THROW);
944 Sequence<sal_Int32> deletedLegendEntriesSeq;
945 CPPUNIT_ASSERT(xPropertySet2->getPropertyValue("DeletedLegendEntries")
946 >>= deletedLegendEntriesSeq);
947 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), deletedLegendEntriesSeq[0]);
951 CPPUNIT_TEST_FIXTURE(Chart2ExportTest2, testTdf60316)
953 loadFromFile(u"pptx/tdf60316.pptx");
954 save("Impress MS PowerPoint 2007 XML");
955 xmlDocUniquePtr pXmlDoc = parseExport("ppt/charts/chart1.xml");
956 CPPUNIT_ASSERT(pXmlDoc);
958 // Without the fix in place, the shape would have had a solidFill background
959 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:spPr/a:noFill"_ostr, 1);
960 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:spPr/a:solidFill"_ostr, 0);
963 CPPUNIT_TEST_FIXTURE(Chart2ExportTest2, testTdf130225)
965 loadFromFile(u"docx/piechart_deleted_legend_entry.docx");
966 saveAndReload("Office Open XML Text");
967 Reference<chart2::XChartDocument> xChartDoc(getChartDocFromWriter(0), uno::UNO_QUERY);
968 CPPUNIT_ASSERT(xChartDoc.is());
969 Reference<chart2::XDataSeries> xDataSeries(getDataSeriesFromDoc(xChartDoc, 0));
970 CPPUNIT_ASSERT(xDataSeries.is());
971 Reference<beans::XPropertySet> xPropertySet(xDataSeries, uno::UNO_QUERY_THROW);
972 Sequence<sal_Int32> deletedLegendEntriesSeq;
973 CPPUNIT_ASSERT(xPropertySet->getPropertyValue("DeletedLegendEntries")
974 >>= deletedLegendEntriesSeq);
975 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), deletedLegendEntriesSeq[0]);
978 CPPUNIT_TEST_FIXTURE(Chart2ExportTest2, testTdf59857)
980 loadFromFile(u"ods/tdf59857.ods");
981 save("Calc Office Open XML");
982 xmlDocUniquePtr pXmlDoc = parseExport("xl/charts/chart1.xml");
983 CPPUNIT_ASSERT(pXmlDoc);
985 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:floor/c:spPr/a:ln/a:noFill"_ostr, 1);
986 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:floor/c:spPr/a:solidFill/a:srgbClr"_ostr,
987 "val"_ostr, "cccccc");
988 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:backWall/c:spPr/a:ln/a:noFill"_ostr, 0);
989 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:backWall/c:spPr/a:ln/a:solidFill/a:srgbClr"_ostr,
990 "val"_ostr, "b3b3b3");
993 CPPUNIT_TEST_FIXTURE(Chart2ExportTest2, testTdf126076)
995 loadFromFile(u"xlsx/auto_marker_excel10.xlsx");
996 save("Calc Office Open XML");
997 xmlDocUniquePtr pXmlDoc = parseExport("xl/charts/chart1.xml");
998 CPPUNIT_ASSERT(pXmlDoc);
1000 // This was 12: all series exported with square markers
1001 assertXPath(
1002 pXmlDoc,
1003 "/c:chartSpace/c:chart/c:plotArea/c:lineChart/c:ser/c:marker/c:symbol[@val='square']"_ostr,
1005 // instead of skipping markers
1006 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:lineChart/c:ser/c:marker"_ostr, 0);
1009 CPPUNIT_TEST_FIXTURE(Chart2ExportTest2, testTdf75330)
1011 loadFromFile(u"ods/legend_overlay.ods");
1012 saveAndReload("calc8");
1014 uno::Reference<chart2::XChartDocument> xChart2Doc = getChartDocFromSheet(0, mxComponent);
1015 uno::Reference<chart::XChartDocument> xChartDoc(xChart2Doc, uno::UNO_QUERY);
1016 uno::Reference<drawing::XShape> xLegend = xChartDoc->getLegend();
1017 Reference<beans::XPropertySet> xPropertySet(xLegend, uno::UNO_QUERY_THROW);
1018 bool bOverlay = false;
1019 CPPUNIT_ASSERT(xPropertySet->getPropertyValue("Overlay") >>= bOverlay);
1020 CPPUNIT_ASSERT(bOverlay);
1022 saveAndReload("Calc Office Open XML");
1024 uno::Reference<chart2::XChartDocument> xChart2Doc = getChartDocFromSheet(0, mxComponent);
1025 uno::Reference<chart::XChartDocument> xChartDoc(xChart2Doc, uno::UNO_QUERY);
1026 uno::Reference<drawing::XShape> xLegend = xChartDoc->getLegend();
1027 Reference<beans::XPropertySet> xPropertySet(xLegend, uno::UNO_QUERY_THROW);
1028 bool bOverlay = false;
1029 CPPUNIT_ASSERT(xPropertySet->getPropertyValue("Overlay") >>= bOverlay);
1030 CPPUNIT_ASSERT(bOverlay);
1034 CPPUNIT_TEST_FIXTURE(Chart2ExportTest2, testTdf127792)
1036 loadFromFile(u"docx/MSO_axis_position.docx");
1037 save("Office Open XML Text");
1038 xmlDocUniquePtr pXmlDoc = parseExport("word/charts/chart1.xml");
1039 CPPUNIT_ASSERT(pXmlDoc);
1040 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:valAx/c:crossBetween"_ostr, "val"_ostr,
1041 "between");
1043 pXmlDoc = parseExport("word/charts/chart2.xml");
1044 CPPUNIT_ASSERT(pXmlDoc);
1045 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:valAx/c:crossBetween"_ostr, "val"_ostr,
1046 "midCat");
1049 CPPUNIT_TEST_FIXTURE(Chart2ExportTest2, testTdf131979)
1051 loadFromFile(u"ods/tdf131115.ods");
1053 saveAndReload("calc8");
1054 Reference<chart2::XChartDocument> xChartDoc = getChartDocFromSheet(0, mxComponent);
1055 CPPUNIT_ASSERT(xChartDoc.is());
1056 Reference<chart2::XDataSeries> xDataSeries(getDataSeriesFromDoc(xChartDoc, 0));
1057 CPPUNIT_ASSERT(xDataSeries.is());
1058 Reference<beans::XPropertySet> xPropertySet;
1059 xPropertySet.set(xDataSeries->getDataPointByIndex(2), uno::UNO_SET_THROW);
1060 bool blinknumberformattosource = true;
1061 CPPUNIT_ASSERT(xPropertySet->getPropertyValue(CHART_UNONAME_LINK_TO_SRC_NUMFMT)
1062 >>= blinknumberformattosource);
1063 CPPUNIT_ASSERT_MESSAGE("\"LinkNumberFormatToSource\" should be set to false.",
1064 !blinknumberformattosource);
1067 loadFromFile(u"ods/tdf131979.ods");
1069 saveAndReload("calc8");
1070 Reference<chart2::XChartDocument> xChartDoc = getChartDocFromSheet(0, mxComponent);
1071 CPPUNIT_ASSERT(xChartDoc.is());
1072 Reference<chart2::XDataSeries> xDataSeries(getDataSeriesFromDoc(xChartDoc, 0));
1073 CPPUNIT_ASSERT(xDataSeries.is());
1074 Reference<beans::XPropertySet> xPropertySet;
1075 xPropertySet.set(xDataSeries->getDataPointByIndex(2), uno::UNO_SET_THROW);
1076 bool blinknumberformattosource = true;
1077 CPPUNIT_ASSERT(xPropertySet->getPropertyValue(CHART_UNONAME_LINK_TO_SRC_NUMFMT)
1078 >>= blinknumberformattosource);
1079 CPPUNIT_ASSERT_MESSAGE("\"LinkNumberFormatToSource\" should be set to true.",
1080 blinknumberformattosource);
1084 CPPUNIT_TEST_FIXTURE(Chart2ExportTest2, testTdf132076)
1086 // FIXME: validation error in OOXML export: Errors: 1
1087 skipValidation();
1090 loadFromFile(u"ods/tdf132076.ods");
1091 save("Calc Office Open XML");
1092 xmlDocUniquePtr pXmlDoc = parseExport("xl/charts/chart1.xml");
1093 CPPUNIT_ASSERT(pXmlDoc);
1094 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:catAx/c:numFmt"_ostr,
1095 "formatCode"_ostr, "dd");
1096 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:catAx/c:numFmt"_ostr,
1097 "sourceLinked"_ostr, "0");
1100 loadFromFile(u"xlsx/tdf132076.xlsx");
1101 save("Calc Office Open XML");
1102 xmlDocUniquePtr pXmlDoc = parseExport("xl/charts/chart1.xml");
1103 CPPUNIT_ASSERT(pXmlDoc);
1104 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:dateAx/c:numFmt"_ostr,
1105 "formatCode"_ostr, "dd");
1106 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:dateAx/c:numFmt"_ostr,
1107 "sourceLinked"_ostr, "0");
1111 CPPUNIT_TEST_FIXTURE(Chart2ExportTest2, testTdf125812)
1113 loadFromFile(u"odp/ellipticalGradientFill.odp");
1114 save("Impress MS PowerPoint 2007 XML");
1115 xmlDocUniquePtr pXmlDoc = parseExport("ppt/charts/chart1.xml");
1116 CPPUNIT_ASSERT(pXmlDoc);
1117 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:spPr/a:gradFill/a:path"_ostr,
1118 "path"_ostr, "circle");
1119 assertXPath(pXmlDoc,
1120 "/c:chartSpace/c:chart/c:plotArea/c:spPr/a:gradFill/a:path/a:fillToRect"_ostr,
1121 "l"_ostr, "50000");
1122 assertXPath(pXmlDoc,
1123 "/c:chartSpace/c:chart/c:plotArea/c:spPr/a:gradFill/a:path/a:fillToRect"_ostr,
1124 "t"_ostr, "49000");
1125 assertXPath(pXmlDoc,
1126 "/c:chartSpace/c:chart/c:plotArea/c:spPr/a:gradFill/a:path/a:fillToRect"_ostr,
1127 "r"_ostr, "50000");
1128 assertXPath(pXmlDoc,
1129 "/c:chartSpace/c:chart/c:plotArea/c:spPr/a:gradFill/a:path/a:fillToRect"_ostr,
1130 "b"_ostr, "51000");
1133 CPPUNIT_TEST_FIXTURE(Chart2ExportTest2, testTdf133190)
1135 loadFromFile(u"xlsx/tdf133190_tdf133191.xlsx");
1137 // FIXME: validation error in OOXML export: Errors: 1
1138 skipValidation();
1140 save("Calc Office Open XML");
1141 xmlDocUniquePtr pXmlDoc = parseExport("xl/charts/chart1.xml");
1142 CPPUNIT_ASSERT(pXmlDoc);
1144 // Test word wrap of data point label
1145 assertXPath(
1146 pXmlDoc,
1147 "/c:chartSpace/c:chart/c:plotArea/c:pieChart/c:ser/c:dLbls/c:dLbl[1]/c:txPr/a:bodyPr"_ostr,
1148 "wrap"_ostr, "none");
1149 assertXPath(
1150 pXmlDoc,
1151 "/c:chartSpace/c:chart/c:plotArea/c:pieChart/c:ser/c:dLbls/c:dLbl[2]/c:txPr/a:bodyPr"_ostr,
1152 "wrap"_ostr, "square");
1155 CPPUNIT_TEST_FIXTURE(Chart2ExportTest2, testTdf133191)
1157 loadFromFile(u"xlsx/tdf133190_tdf133191.xlsx");
1159 // FIXME: validation error in OOXML export: Errors: 1
1160 skipValidation();
1162 save("Calc Office Open XML");
1163 xmlDocUniquePtr pXmlDoc = parseExport("xl/charts/chart1.xml");
1164 CPPUNIT_ASSERT(pXmlDoc);
1166 // Test rotation of data point label
1167 assertXPath(
1168 pXmlDoc,
1169 "/c:chartSpace/c:chart/c:plotArea/c:pieChart/c:ser/c:dLbls/c:dLbl[3]/c:txPr/a:bodyPr"_ostr,
1170 "rot"_ostr, "-4500000");
1173 CPPUNIT_TEST_FIXTURE(Chart2ExportTest2, testTdf132594)
1175 loadFromFile(u"xlsx/chart_pie2007.xlsx");
1176 save("Calc Office Open XML");
1177 xmlDocUniquePtr pXmlDoc = parseExport("xl/charts/chart1.xml");
1178 CPPUNIT_ASSERT(pXmlDoc);
1180 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:pieChart/c:ser/c:cat"_ostr, 1);
1183 CPPUNIT_TEST_FIXTURE(Chart2ExportTest2, testTdf134255)
1185 loadFromFile(u"docx/tdf134255.docx");
1186 Reference<chart2::XChartDocument> xChartDoc(getChartDocFromWriter(0), uno::UNO_QUERY);
1187 CPPUNIT_ASSERT(xChartDoc.is());
1189 // import test
1190 Reference<chart2::XDataSeries> xDataSeries = getDataSeriesFromDoc(xChartDoc, 0);
1191 CPPUNIT_ASSERT(xDataSeries.is());
1192 Reference<beans::XPropertySet> xPropSet(xDataSeries, UNO_QUERY_THROW);
1193 bool bWrap = false;
1194 CPPUNIT_ASSERT((xPropSet->getPropertyValue("TextWordWrap") >>= bWrap));
1195 CPPUNIT_ASSERT(bWrap);
1197 // FIXME: validation error in OOXML export: Errors: 11
1198 skipValidation();
1200 // export test
1201 save("Office Open XML Text");
1202 xmlDocUniquePtr pXmlDoc = parseExport("word/charts/chart1.xml");
1203 CPPUNIT_ASSERT(pXmlDoc);
1205 assertXPath(pXmlDoc,
1206 "/c:chartSpace/c:chart/c:plotArea/c:pieChart/c:ser/c:dLbls/c:txPr/a:bodyPr"_ostr,
1207 "wrap"_ostr, "square");
1210 CPPUNIT_TEST_FIXTURE(Chart2ExportTest2, testTdf134977)
1212 loadFromFile(u"xlsx/custom_data_label.xlsx");
1214 //import test
1215 uno::Reference<chart2::XChartDocument> xChartDoc = getChartDocFromSheet(0, mxComponent);
1216 CPPUNIT_ASSERT(xChartDoc.is());
1217 Reference<chart2::XDataSeries> xDataSeries = getDataSeriesFromDoc(xChartDoc, 0);
1218 CPPUNIT_ASSERT(xDataSeries.is());
1219 uno::Reference<beans::XPropertySet> xPropertySet(xDataSeries->getDataPointByIndex(0),
1220 uno::UNO_SET_THROW);
1221 uno::Sequence<uno::Reference<chart2::XDataPointCustomLabelField>> aFields;
1222 float nFontSize;
1223 xPropertySet->getPropertyValue("CustomLabelFields") >>= aFields;
1224 aFields[0]->getPropertyValue("CharHeight") >>= nFontSize;
1225 CPPUNIT_ASSERT_EQUAL(static_cast<float>(9), nFontSize);
1227 // FIXME: validation error in OOXML export: Errors: 2
1228 skipValidation();
1230 //export test
1231 save("Calc Office Open XML");
1232 xmlDocUniquePtr pXmlDoc = parseExport("xl/charts/chart1.xml");
1233 CPPUNIT_ASSERT(pXmlDoc);
1234 assertXPath(pXmlDoc,
1235 "/c:chartSpace/c:chart/c:plotArea/c:barChart/c:ser/c:dLbls/c:dLbl/c:tx/c:rich/a:p/"
1236 "a:r/a:rPr"_ostr,
1237 "sz"_ostr, "900");
1240 CPPUNIT_TEST_FIXTURE(Chart2ExportTest2, testTdf123647)
1242 loadFromFile(u"xlsx/empty_chart.xlsx");
1243 save("Calc Office Open XML");
1244 xmlDocUniquePtr pXmlDoc = parseExport("xl/charts/chart1.xml");
1245 CPPUNIT_ASSERT(pXmlDoc);
1247 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:barChart"_ostr, 1);
1250 CPPUNIT_TEST_FIXTURE(Chart2ExportTest2, testTdf136267)
1252 loadFromFile(u"xlsx/tdf136267.xlsx");
1254 // FIXME: validation error in OOXML export: Errors: 2
1255 skipValidation();
1257 save("Calc Office Open XML");
1258 xmlDocUniquePtr pXmlDoc = parseExport("xl/charts/chart1.xml");
1259 CPPUNIT_ASSERT(pXmlDoc);
1261 assertXPathContent(
1262 pXmlDoc,
1263 "/c:chartSpace/c:chart/c:plotArea/c:barChart/c:ser/c:cat/c:strRef/c:strCache/c:pt/c:v"_ostr,
1264 "John");
1267 CPPUNIT_TEST_FIXTURE(Chart2ExportTest2, testDataLabelPlacementPieChart)
1269 loadFromFile(u"xlsx/tdf134978.xlsx");
1270 saveAndReload("calc8");
1271 uno::Reference<chart::XChartDocument> xChartDoc(getChartCompFromSheet(0, 0, mxComponent),
1272 UNO_QUERY_THROW);
1273 // test the placement of the manually positioned label
1274 Reference<beans::XPropertySet> xDataPointPropSet(
1275 xChartDoc->getDiagram()->getDataPointProperties(2, 0), uno::UNO_SET_THROW);
1276 uno::Any aAny = xDataPointPropSet->getPropertyValue("LabelPlacement");
1277 CPPUNIT_ASSERT(aAny.hasValue());
1278 sal_Int32 nLabelPlacement = 0;
1279 CPPUNIT_ASSERT(aAny >>= nLabelPlacement);
1280 CPPUNIT_ASSERT_EQUAL(chart::DataLabelPlacement::OUTSIDE, nLabelPlacement);
1283 CPPUNIT_TEST_FIXTURE(Chart2ExportTest2, testTdf137917)
1285 loadFromFile(u"xlsx/tdf137917.xlsx");
1287 // FIXME: validation error in OOXML export: Errors: 1
1288 skipValidation();
1290 save("Calc Office Open XML");
1291 xmlDocUniquePtr pXmlDoc = parseExport("xl/charts/chart1.xml");
1292 CPPUNIT_ASSERT(pXmlDoc);
1294 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:dateAx/c:baseTimeUnit"_ostr,
1295 "val"_ostr, "days");
1296 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:dateAx/c:majorUnit"_ostr, "val"_ostr,
1297 "1");
1298 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:dateAx/c:majorTimeUnit"_ostr,
1299 "val"_ostr, "months");
1300 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:dateAx/c:minorUnit"_ostr, "val"_ostr,
1301 "7");
1302 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:dateAx/c:minorTimeUnit"_ostr,
1303 "val"_ostr, "days");
1306 CPPUNIT_TEST_FIXTURE(Chart2ExportTest2, testTdf138204)
1308 loadFromFile(u"xlsx/tdf138204.xlsx");
1310 Reference<chart2::XChartDocument> xChartDoc = getChartDocFromSheet(0, mxComponent);
1311 CPPUNIT_ASSERT(xChartDoc.is());
1313 struct CustomLabelsTestData
1315 sal_Int32 nSeriesIdx;
1316 sal_Int32 nNumFields;
1317 // First field attributes.
1318 chart2::DataPointCustomLabelFieldType eFieldType;
1319 OUString aCellRange;
1320 OUString aString;
1323 const CustomLabelsTestData aTestEntries[2] = {
1325 // series id of c:ser[1] is 0.
1326 0, // nSeriesIdx
1327 1, // nNumFields
1328 chart2::DataPointCustomLabelFieldType::DataPointCustomLabelFieldType_CELLRANGE,
1329 "Munka1!$F$9", // aCellRange
1330 "67,5%", // aString
1334 // series id of c:ser[2] is 1.
1335 1, // nSeriesIdx
1336 1, // nNumFields
1337 chart2::DataPointCustomLabelFieldType::DataPointCustomLabelFieldType_CELLRANGE,
1338 "Munka1!$G$9", // aCellRange
1339 "32,3%", // aString
1343 for (const auto& aTestEntry : aTestEntries)
1345 uno::Reference<chart2::XDataSeries> xDataSeries(
1346 getDataSeriesFromDoc(xChartDoc, aTestEntry.nSeriesIdx));
1347 CPPUNIT_ASSERT(xDataSeries.is());
1349 uno::Reference<beans::XPropertySet> xPropertySet;
1350 uno::Sequence<uno::Reference<chart2::XDataPointCustomLabelField>> aFields;
1351 xPropertySet.set(xDataSeries->getDataPointByIndex(0), uno::UNO_SET_THROW);
1352 xPropertySet->getPropertyValue("CustomLabelFields") >>= aFields;
1353 CPPUNIT_ASSERT_EQUAL(aTestEntry.nNumFields, aFields.getLength());
1355 CPPUNIT_ASSERT_EQUAL(aTestEntry.eFieldType, aFields[0]->getFieldType());
1356 CPPUNIT_ASSERT_EQUAL(aTestEntry.aCellRange, aFields[0]->getCellRange());
1357 CPPUNIT_ASSERT_EQUAL(aTestEntry.aString, aFields[0]->getString());
1360 // FIXME: validation error in OOXML export: Errors: 2
1361 skipValidation();
1363 save("Calc Office Open XML");
1364 xmlDocUniquePtr pXmlDoc = parseExport("xl/charts/chart1.xml");
1365 CPPUNIT_ASSERT(pXmlDoc);
1367 // Check the first data label field type
1368 assertXPath(
1369 pXmlDoc,
1370 "/c:chartSpace/c:chart/c:plotArea/c:barChart/c:ser[1]/c:dLbls/c:dLbl/c:tx/c:rich/a:p/a:fld"_ostr,
1371 "type"_ostr, "CELLRANGE");
1373 assertXPath(
1374 pXmlDoc,
1375 "/c:chartSpace/c:chart/c:plotArea/c:barChart/c:ser[2]/c:dLbls/c:dLbl/c:tx/c:rich/a:p/a:fld"_ostr,
1376 "type"_ostr, "CELLRANGE");
1379 CPPUNIT_TEST_FIXTURE(Chart2ExportTest2, testTdf138181)
1381 loadFromFile(u"xlsx/piechart_deleted_legendentry.xlsx");
1382 Reference<chart::XChartDocument> xChartDoc(getChartDocFromSheet(0, mxComponent),
1383 UNO_QUERY_THROW);
1384 Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(xChartDoc, UNO_QUERY_THROW);
1385 Reference<drawing::XDrawPage> xDrawPage(xDrawPageSupplier->getDrawPage(), UNO_SET_THROW);
1386 Reference<drawing::XShapes> xShapes(xDrawPage->getByIndex(0), UNO_QUERY_THROW);
1387 Reference<drawing::XShape> xLegendEntry1, xLegendEntry2, xLegendEntry3;
1389 // first legend entry is visible
1390 xLegendEntry1
1391 = getShapeByName(xShapes, "CID/MultiClick/D=0:CS=0:CT=0:Series=0:Point=0:LegendEntry=0");
1392 CPPUNIT_ASSERT(xLegendEntry1.is());
1394 // second legend entry is not visible
1395 xLegendEntry2
1396 = getShapeByName(xShapes, "CID/MultiClick/D=0:CS=0:CT=0:Series=0:Point=1:LegendEntry=0");
1397 CPPUNIT_ASSERT(!xLegendEntry2.is());
1399 // third legend entry is visible
1400 xLegendEntry3
1401 = getShapeByName(xShapes, "CID/MultiClick/D=0:CS=0:CT=0:Series=0:Point=2:LegendEntry=0");
1402 CPPUNIT_ASSERT(xLegendEntry3.is());
1405 CPPUNIT_TEST_FIXTURE(Chart2ExportTest2, testCustomShapeText)
1407 loadFromFile(u"ods/tdf72776.ods");
1408 saveAndReload("calc8");
1409 Reference<chart::XChartDocument> xChartDoc(getChartDocFromSheet(0, mxComponent),
1410 UNO_QUERY_THROW);
1411 // test that the text of custom shape exists inside the chart
1412 Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(xChartDoc, UNO_QUERY_THROW);
1413 Reference<drawing::XDrawPage> xDrawPage(xDrawPageSupplier->getDrawPage(), UNO_SET_THROW);
1414 Reference<drawing::XShape> xCustomShape(xDrawPage->getByIndex(1), UNO_QUERY_THROW);
1415 CPPUNIT_ASSERT(xCustomShape.is());
1417 Reference<text::XText> xRange(xCustomShape, uno::UNO_QUERY_THROW);
1418 CPPUNIT_ASSERT(!xRange->getString().isEmpty());
1421 CPPUNIT_TEST_FIXTURE(Chart2ExportTest2, testuserShapesXLSX)
1423 loadFromFile(u"xlsx/tdf128621.xlsx");
1424 saveAndReload("Calc Office Open XML");
1426 Reference<chart2::XChartDocument> xChartDoc = getChartDocFromSheet(0, mxComponent);
1427 CPPUNIT_ASSERT(xChartDoc.is());
1429 // test that the custom shape exists
1430 Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(xChartDoc, UNO_QUERY_THROW);
1431 Reference<drawing::XDrawPage> xDrawPage(xDrawPageSupplier->getDrawPage(), UNO_SET_THROW);
1432 Reference<drawing::XShape> xCustomShape(xDrawPage->getByIndex(1), UNO_QUERY_THROW);
1433 CPPUNIT_ASSERT(xCustomShape.is());
1434 // test type of shape
1435 CPPUNIT_ASSERT(xCustomShape->getShapeType().endsWith("CustomShape"));
1436 // test custom shape position
1437 awt::Point aPosition = xCustomShape->getPosition();
1438 CPPUNIT_ASSERT_DOUBLES_EQUAL(1356, aPosition.X, 300);
1439 CPPUNIT_ASSERT_DOUBLES_EQUAL(9107, aPosition.Y, 300);
1440 // test custom shape size
1441 awt::Size aSize = xCustomShape->getSize();
1442 CPPUNIT_ASSERT_DOUBLES_EQUAL(9520, aSize.Width, 300);
1443 CPPUNIT_ASSERT_DOUBLES_EQUAL(1805, aSize.Height, 300);
1444 // test custom shape text
1445 Reference<text::XText> xRange(xCustomShape, uno::UNO_QUERY_THROW);
1446 CPPUNIT_ASSERT(!xRange->getString().isEmpty());
1449 CPPUNIT_TEST_FIXTURE(Chart2ExportTest2, testuserShapesDOCX)
1451 loadFromFile(u"docx/tdf143130.docx");
1452 saveAndReload("Office Open XML Text");
1454 Reference<chart2::XChartDocument> xChartDoc(getChartDocFromWriter(0), uno::UNO_QUERY);
1455 CPPUNIT_ASSERT(xChartDoc.is());
1457 // test that the custom shape exists
1458 Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(xChartDoc, UNO_QUERY_THROW);
1459 Reference<drawing::XDrawPage> xDrawPage(xDrawPageSupplier->getDrawPage(), UNO_SET_THROW);
1460 Reference<drawing::XShape> xCustomShape(xDrawPage->getByIndex(0), UNO_QUERY_THROW);
1461 CPPUNIT_ASSERT(xCustomShape.is());
1462 // test type of shape
1463 CPPUNIT_ASSERT(xCustomShape->getShapeType().endsWith("CustomShape"));
1464 // test custom shape position
1465 awt::Point aPosition = xCustomShape->getPosition();
1466 CPPUNIT_ASSERT_DOUBLES_EQUAL(9824, aPosition.X, 300);
1467 CPPUNIT_ASSERT_DOUBLES_EQUAL(547, aPosition.Y, 300);
1468 // test custom shape size
1469 awt::Size aSize = xCustomShape->getSize();
1470 CPPUNIT_ASSERT_DOUBLES_EQUAL(1848, aSize.Width, 300);
1471 CPPUNIT_ASSERT_DOUBLES_EQUAL(1003, aSize.Height, 300);
1472 // test custom shape text
1473 Reference<text::XText> xRange(xCustomShape, uno::UNO_QUERY_THROW);
1474 CPPUNIT_ASSERT(!xRange->getString().isEmpty());
1477 CPPUNIT_TEST_FIXTURE(Chart2ExportTest2, testGraphicBlipXLSX)
1479 loadFromFile(u"xlsx/tdf143127.xlsx");
1480 saveAndReload("Calc Office Open XML");
1482 Reference<chart2::XChartDocument> xChartDoc = getChartDocFromSheet(0, mxComponent);
1483 CPPUNIT_ASSERT(xChartDoc.is());
1485 // test that the Graphic shape exists
1486 Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(xChartDoc, UNO_QUERY_THROW);
1487 Reference<drawing::XDrawPage> xDrawPage(xDrawPageSupplier->getDrawPage(), UNO_SET_THROW);
1488 Reference<drawing::XShape> xCustomShape(xDrawPage->getByIndex(1), UNO_QUERY_THROW);
1489 CPPUNIT_ASSERT(xCustomShape.is());
1490 // test type of shape
1491 CPPUNIT_ASSERT(xCustomShape->getShapeType().endsWith("GraphicObjectShape"));
1492 Reference<XPropertySet> xShapeProps(xCustomShape, UNO_QUERY);
1494 uno::Reference<graphic::XGraphic> xGraphic;
1495 CPPUNIT_ASSERT(xShapeProps->getPropertyValue("Graphic") >>= xGraphic);
1497 Graphic aGraphic(xGraphic);
1498 GfxLink aLink = aGraphic.GetGfxLink();
1499 std::size_t nDataSize = aLink.GetDataSize();
1501 // test the image size is bigger then 0.
1502 CPPUNIT_ASSERT_GREATER(size_t(0), nDataSize);
1505 CPPUNIT_TEST_FIXTURE(Chart2ExportTest2, testNameRangeXLSX)
1507 loadFromFile(u"xlsx/chart_with_name_range.xlsx");
1508 save("Calc Office Open XML");
1509 xmlDocUniquePtr pXmlDoc = parseExport("xl/charts/chart1.xml");
1510 CPPUNIT_ASSERT(pXmlDoc);
1511 // test the syntax of local range name on the local sheet.
1512 assertXPathContent(pXmlDoc,
1513 "/c:chartSpace/c:chart/c:plotArea/c:barChart/c:ser/c:cat/c:strRef/c:f"_ostr,
1514 "Sheet1!local_name_range");
1515 // test the syntax of a global range name.
1516 assertXPathContent(pXmlDoc,
1517 "/c:chartSpace/c:chart/c:plotArea/c:barChart/c:ser/c:val/c:numRef/c:f"_ostr,
1518 "[0]!series1");
1521 CPPUNIT_TEST_FIXTURE(Chart2ExportTest2, testTdf143942)
1523 loadFromFile(u"xlsx/tdf143942.xlsx");
1525 Reference<chart2::XChartDocument> xChartDoc = getChartDocFromSheet(0, mxComponent);
1526 CPPUNIT_ASSERT(xChartDoc.is());
1528 uno::Reference<chart2::XDataSeries> xDataSeries(getDataSeriesFromDoc(xChartDoc, 0));
1529 CPPUNIT_ASSERT(xDataSeries.is());
1531 constexpr size_t nLabels = 4;
1532 OUString aCellRange = "Sheet1!$A$2:$A$5";
1533 OUString aLabels[nLabels] = {
1534 "Test1",
1535 "Test2",
1536 "Tes3",
1537 "Test4",
1540 uno::Reference<beans::XPropertySet> xPropertySet;
1541 uno::Sequence<uno::Reference<chart2::XDataPointCustomLabelField>> aFields;
1542 for (size_t i = 0; i < nLabels; ++i)
1544 xPropertySet.set(xDataSeries->getDataPointByIndex(i), uno::UNO_SET_THROW);
1545 xPropertySet->getPropertyValue("CustomLabelFields") >>= aFields;
1546 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1), aFields.getLength());
1547 CPPUNIT_ASSERT_EQUAL(
1548 chart2::DataPointCustomLabelFieldType::DataPointCustomLabelFieldType_CELLRANGE,
1549 aFields[0]->getFieldType());
1550 CPPUNIT_ASSERT_EQUAL(aCellRange, aFields[0]->getCellRange());
1551 CPPUNIT_ASSERT_EQUAL(aLabels[i], aFields[0]->getString());
1554 // FIXME: validation error in OOXML export: Errors: 4
1555 skipValidation();
1557 save("Calc Office Open XML");
1558 xmlDocUniquePtr pXmlDoc = parseExport("xl/charts/chart1.xml");
1559 CPPUNIT_ASSERT(pXmlDoc);
1561 assertXPath(pXmlDoc,
1562 "/c:chartSpace/c:chart/c:plotArea/c:scatterChart/c:ser[1]/c:extLst/c:ext"_ostr,
1563 "uri"_ostr, "{02D57815-91ED-43cb-92C2-25804820EDAC}");
1564 assertXPath(pXmlDoc,
1565 "/c:chartSpace/c:chart/c:plotArea/c:scatterChart/c:ser[1]/c:extLst/c:ext/"
1566 "c15:datalabelsRange/c15:dlblRangeCache/c:ptCount"_ostr,
1567 "val"_ostr, "4");
1568 assertXPathContent(pXmlDoc,
1569 "/c:chartSpace/c:chart/c:plotArea/c:scatterChart/c:ser[1]/c:extLst/c:ext/"
1570 "c15:datalabelsRange/c15:f"_ostr,
1571 aCellRange);
1572 for (size_t i = 0; i < nLabels; ++i)
1574 assertXPath(pXmlDoc,
1575 "/c:chartSpace/c:chart/c:plotArea/c:scatterChart/c:ser[1]/c:dLbls/c:dLbl["
1576 + OString::number(i + 1) + "]/c:tx/c:rich/a:p/a:fld",
1577 "type"_ostr, "CELLRANGE");
1578 assertXPath(pXmlDoc,
1579 "/c:chartSpace/c:chart/c:plotArea/c:scatterChart/c:ser[1]/c:dLbls/c:dLbl["
1580 + OString::number(i + 1) + "]/c:extLst/c:ext/c15:showDataLabelsRange",
1581 "val"_ostr, "1");
1582 // Check if the actual label is stored under c15:datalabelsRange
1583 assertXPathContent(pXmlDoc,
1584 "/c:chartSpace/c:chart/c:plotArea/c:scatterChart/c:ser[1]/c:extLst/"
1585 "c:ext/c15:datalabelsRange/c15:dlblRangeCache/c:pt["
1586 + OString::number(i + 1) + "]/c:v",
1587 aLabels[i]);
1591 CPPUNIT_TEST_FIXTURE(Chart2ExportTest2, testDateCategoriesPPTX)
1593 loadFromFile(u"pptx/bnc889755.pptx");
1595 // FIXME: validation error in OOXML export: Errors: 1
1596 skipValidation();
1598 save("Impress Office Open XML");
1599 xmlDocUniquePtr pXmlDoc = parseExport("ppt/charts/chart1.xml");
1600 CPPUNIT_ASSERT(pXmlDoc);
1602 constexpr size_t nCats = 16;
1603 double aDates[nCats] = {
1604 41183, 41214, 41244, 41275, 41306, 41334, 41365, 41395,
1605 41426, 41456, 41487, 41518, 41548, 41579, 41609, 41640,
1608 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:barChart/c:ser[1]/c:cat"_ostr);
1609 assertXPathContent(pXmlDoc,
1610 "/c:chartSpace/c:chart/c:plotArea/c:barChart/c:ser[1]/c:cat/c:numRef/"
1611 "c:numCache/c:formatCode"_ostr,
1612 "mmm\\-yy");
1613 assertXPath(
1614 pXmlDoc,
1615 "/c:chartSpace/c:chart/c:plotArea/c:barChart/c:ser[1]/c:cat/c:numRef/c:numCache/c:ptCount"_ostr,
1616 "val"_ostr, OUString::number(nCats));
1618 for (size_t i = 0; i < nCats; ++i)
1620 assertXPath(
1621 pXmlDoc,
1622 "/c:chartSpace/c:chart/c:plotArea/c:barChart/c:ser[1]/c:cat/c:numRef/c:numCache/c:pt["
1623 + OString::number(i + 1) + "]",
1624 "idx"_ostr, OUString::number(i));
1625 assertXPathContent(
1626 pXmlDoc,
1627 "/c:chartSpace/c:chart/c:plotArea/c:barChart/c:ser[1]/c:cat/c:numRef/c:numCache/c:pt["
1628 + OString::number(i + 1) + "]/c:v",
1629 OUString::number(aDates[i]));
1633 CPPUNIT_TEST_FIXTURE(Chart2ExportTest2, testDataTableImportExport)
1635 loadFromFile(u"xlsx/ChartDataTable.xlsx");
1637 uno::Reference<chart2::XChartDocument> xChartDoc = getChartDocFromSheet(0, mxComponent);
1638 CPPUNIT_ASSERT(xChartDoc.is());
1639 auto xDiagram = xChartDoc->getFirstDiagram();
1640 CPPUNIT_ASSERT(xDiagram.is());
1641 auto xDataTable = xDiagram->getDataTable();
1642 CPPUNIT_ASSERT(xDataTable.is());
1643 uno::Reference<beans::XPropertySet> xPropertySet(xDataTable, uno::UNO_QUERY);
1644 CPPUNIT_ASSERT(xPropertySet.is());
1645 bool bHBorder;
1646 CPPUNIT_ASSERT(xPropertySet->getPropertyValue("HBorder") >>= bHBorder);
1647 CPPUNIT_ASSERT_EQUAL(true, bHBorder);
1648 bool bVBorder;
1649 CPPUNIT_ASSERT(xPropertySet->getPropertyValue("VBorder") >>= bVBorder);
1650 CPPUNIT_ASSERT_EQUAL(true, bVBorder);
1651 bool bOutline;
1652 CPPUNIT_ASSERT(xPropertySet->getPropertyValue("Outline") >>= bOutline);
1653 CPPUNIT_ASSERT_EQUAL(false, bOutline);
1654 bool bKeys;
1655 CPPUNIT_ASSERT(xPropertySet->getPropertyValue("Keys") >>= bKeys);
1656 CPPUNIT_ASSERT_EQUAL(false, bKeys);
1658 saveAndReload("calc8");
1660 uno::Reference<chart2::XChartDocument> xChartDoc = getChartDocFromSheet(0, mxComponent);
1661 CPPUNIT_ASSERT(xChartDoc.is());
1662 auto xDiagram = xChartDoc->getFirstDiagram();
1663 CPPUNIT_ASSERT(xDiagram.is());
1664 auto xDataTable = xDiagram->getDataTable();
1665 CPPUNIT_ASSERT(xDataTable.is());
1666 uno::Reference<beans::XPropertySet> xPropertySet(xDataTable, uno::UNO_QUERY);
1667 CPPUNIT_ASSERT(xPropertySet.is());
1668 bool bHBorder;
1669 CPPUNIT_ASSERT(xPropertySet->getPropertyValue("HBorder") >>= bHBorder);
1670 CPPUNIT_ASSERT_EQUAL(true, bHBorder);
1671 bool bVBorder;
1672 CPPUNIT_ASSERT(xPropertySet->getPropertyValue("VBorder") >>= bVBorder);
1673 CPPUNIT_ASSERT_EQUAL(true, bVBorder);
1674 bool bOutline;
1675 CPPUNIT_ASSERT(xPropertySet->getPropertyValue("Outline") >>= bOutline);
1676 CPPUNIT_ASSERT_EQUAL(false, bOutline);
1677 bool bKeys;
1678 CPPUNIT_ASSERT(xPropertySet->getPropertyValue("Keys") >>= bKeys);
1679 CPPUNIT_ASSERT_EQUAL(false, bKeys);
1683 CPPUNIT_PLUGIN_IMPLEMENT();
1685 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */