1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
10 #include "charttest.hxx"
11 #include <com/sun/star/chart2/DataPointLabel.hpp>
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/chart2/XChartDocument.hpp>
16 #include <com/sun/star/chart/XChartDocument.hpp>
17 #include <com/sun/star/chart2/XInternalDataProvider.hpp>
18 #include <com/sun/star/chart/XAxisXSupplier.hpp>
19 #include <com/sun/star/chart/DataLabelPlacement.hpp>
20 #include <com/sun/star/text/XText.hpp>
22 class Chart2ImportTest2
: public ChartTest
26 : ChartTest("/chart2/qa/extras/data/")
31 CPPUNIT_TEST_FIXTURE(Chart2ImportTest2
, testTdf114179
)
33 loadFromFile(u
"docx/testTdf114179.docx");
34 uno::Reference
<chart2::XChartDocument
> xChartDoc(getChartDocFromWriter(0), uno::UNO_QUERY
);
35 CPPUNIT_ASSERT(xChartDoc
.is());
36 css::uno::Reference
<chart2::XDiagram
> xDiagram
;
37 xDiagram
.set(xChartDoc
->getFirstDiagram());
38 CPPUNIT_ASSERT_MESSAGE("There is a Diagram.", xDiagram
.is());
39 awt::Size aPage
= getPageSize(xChartDoc
);
40 awt::Size aSize
= getSize(xDiagram
, aPage
);
41 CPPUNIT_ASSERT(aSize
.Width
> 0);
42 CPPUNIT_ASSERT(aSize
.Height
> 0);
45 CPPUNIT_TEST_FIXTURE(Chart2ImportTest2
, testTdf124243
)
47 loadFromFile(u
"docx/tdf124243.docx");
48 uno::Reference
<chart2::XChartDocument
> xChartDoc(getChartDocFromWriter(0), uno::UNO_QUERY
);
49 CPPUNIT_ASSERT_MESSAGE("failed to load chart", xChartDoc
.is());
51 Reference
<chart2::XAxis
> xAxis
= getAxisFromDoc(xChartDoc
, 0, 0, 0);
52 CPPUNIT_ASSERT(xAxis
.is());
54 Reference
<beans::XPropertySet
> xPS(xAxis
, uno::UNO_QUERY_THROW
);
56 // test X Axis is not visible.
57 bool bSuccess
= xPS
->getPropertyValue("Show") >>= bShow
;
58 CPPUNIT_ASSERT(bSuccess
);
59 CPPUNIT_ASSERT(!bShow
);
62 CPPUNIT_TEST_FIXTURE(Chart2ImportTest2
, testTdf127393
)
64 loadFromFile(u
"pptx/tdf127393.pptx");
67 Reference
<chart2::XChartDocument
> xChartDoc(getChartDocFromDrawImpress(0, 0), uno::UNO_QUERY
);
68 CPPUNIT_ASSERT(xChartDoc
.is());
70 Reference
<chart2::XAxis
> xAxis
= getAxisFromDoc(xChartDoc
, 0, 0, 0);
71 CPPUNIT_ASSERT(xAxis
.is());
73 chart2::ScaleData aScaleData1
= xAxis
->getScaleData();
74 CPPUNIT_ASSERT(aScaleData1
.Categories
.is());
75 CPPUNIT_ASSERT(aScaleData1
.ShiftedCategoryPosition
);
78 xChartDoc
.set(getChartDocFromDrawImpress(1, 0), uno::UNO_QUERY
);
79 CPPUNIT_ASSERT(xChartDoc
.is());
81 xAxis
.set(getAxisFromDoc(xChartDoc
, 0, 0, 0));
82 CPPUNIT_ASSERT(xAxis
.is());
84 chart2::ScaleData aScaleData2
= xAxis
->getScaleData();
85 CPPUNIT_ASSERT(aScaleData2
.Categories
.is());
86 CPPUNIT_ASSERT(!aScaleData2
.ShiftedCategoryPosition
);
89 CPPUNIT_TEST_FIXTURE(Chart2ImportTest2
, testTdf128733
)
91 loadFromFile(u
"odt/tdf128733.odt");
93 Reference
<chart2::XChartDocument
> xChartDoc(getChartDocFromWriter(0), uno::UNO_QUERY
);
94 CPPUNIT_ASSERT(xChartDoc
.is());
95 // test secondary X axis ShiftedCategoryPosition value
96 Reference
<chart2::XAxis
> xAxis
= getAxisFromDoc(xChartDoc
, 0, 0, 1);
97 CPPUNIT_ASSERT(xAxis
.is());
99 chart2::ScaleData aScaleData
= xAxis
->getScaleData();
100 CPPUNIT_ASSERT(aScaleData
.Categories
.is());
101 CPPUNIT_ASSERT(aScaleData
.ShiftedCategoryPosition
);
104 CPPUNIT_TEST_FIXTURE(Chart2ImportTest2
, testTdf128432
)
106 loadFromFile(u
"ods/tdf128432.ods");
108 uno::Reference
<chart2::XChartDocument
> xChartDoc
= getChartDocFromSheet(0, mxComponent
);
109 CPPUNIT_ASSERT(xChartDoc
.is());
111 Reference
<chart2::XAxis
> xAxis
= getAxisFromDoc(xChartDoc
, 0, 0, 0);
112 CPPUNIT_ASSERT(xAxis
.is());
114 chart2::ScaleData aScaleData
= xAxis
->getScaleData();
115 CPPUNIT_ASSERT(aScaleData
.Categories
.is());
116 CPPUNIT_ASSERT(aScaleData
.ShiftedCategoryPosition
);
119 CPPUNIT_TEST_FIXTURE(Chart2ImportTest2
, testTdf128627
)
121 loadFromFile(u
"xlsx/tdf128627.xlsx");
122 // Test ShiftedCategoryPosition for Radar Chart
123 uno::Reference
<chart2::XChartDocument
> xChartDoc
= getChartDocFromSheet(0, mxComponent
);
124 CPPUNIT_ASSERT_MESSAGE("failed to load chart", xChartDoc
.is());
126 Reference
<chart2::XAxis
> xAxis
= getAxisFromDoc(xChartDoc
, 0, 0, 0);
127 CPPUNIT_ASSERT(xAxis
.is());
129 chart2::ScaleData aScaleData
= xAxis
->getScaleData();
130 CPPUNIT_ASSERT(aScaleData
.Categories
.is());
131 CPPUNIT_ASSERT(!aScaleData
.ShiftedCategoryPosition
);
134 CPPUNIT_TEST_FIXTURE(Chart2ImportTest2
, testTdf128634
)
136 loadFromFile(u
"xlsx/tdf128634.xlsx");
137 // Test ShiftedCategoryPosition for 3D Charts
138 uno::Reference
<chart2::XChartDocument
> xChartDoc
= getChartDocFromSheet(0, mxComponent
);
139 CPPUNIT_ASSERT_MESSAGE("failed to load chart", xChartDoc
.is());
141 Reference
<chart2::XAxis
> xAxis
= getAxisFromDoc(xChartDoc
, 0, 0, 0);
142 CPPUNIT_ASSERT(xAxis
.is());
144 chart2::ScaleData aScaleData
= xAxis
->getScaleData();
145 CPPUNIT_ASSERT(aScaleData
.Categories
.is());
146 CPPUNIT_ASSERT(aScaleData
.ShiftedCategoryPosition
);
149 CPPUNIT_TEST_FIXTURE(Chart2ImportTest2
, testTdf130657
)
151 loadFromFile(u
"xlsx/tdf130657.xlsx");
152 // Test ShiftedCategoryPosition for charts which is not contain a "crossbetween" OOXML tag.
153 uno::Reference
<chart2::XChartDocument
> xChartDoc
= getChartDocFromSheet(0, mxComponent
);
154 CPPUNIT_ASSERT_MESSAGE("failed to load chart", xChartDoc
.is());
156 Reference
<chart2::XAxis
> xAxis
= getAxisFromDoc(xChartDoc
, 0, 0, 0);
157 CPPUNIT_ASSERT(xAxis
.is());
159 chart2::ScaleData aScaleData
= xAxis
->getScaleData();
160 CPPUNIT_ASSERT(aScaleData
.Categories
.is());
161 CPPUNIT_ASSERT(aScaleData
.ShiftedCategoryPosition
);
166 void checkDataLabelProperties(const Reference
<chart2::XDataSeries
>& xDataSeries
,
167 sal_Int32 nDataPointIndex
, bool bValueVisible
)
169 uno::Reference
<beans::XPropertySet
> xPropertySet(
170 xDataSeries
->getDataPointByIndex(nDataPointIndex
), uno::UNO_SET_THROW
);
171 chart2::DataPointLabel aLabel
;
172 xPropertySet
->getPropertyValue("Label") >>= aLabel
;
173 CPPUNIT_ASSERT_EQUAL(bValueVisible
, static_cast<bool>(aLabel
.ShowNumber
));
174 CPPUNIT_ASSERT_EQUAL(false, static_cast<bool>(aLabel
.ShowNumberInPercent
));
178 CPPUNIT_TEST_FIXTURE(Chart2ImportTest2
, testDeletedDataLabel
)
180 loadFromFile(u
"xlsx/deleted_data_labels.xlsx");
181 uno::Reference
<chart2::XChartDocument
> xChartDoc(getChartCompFromSheet(0, 0, mxComponent
),
183 Reference
<chart2::XDataSeries
> xDataSeries0
= getDataSeriesFromDoc(xChartDoc
, 0);
184 CPPUNIT_ASSERT(xDataSeries0
.is());
185 checkDataLabelProperties(xDataSeries0
, 0, true);
186 checkDataLabelProperties(xDataSeries0
, 1, false);
187 checkDataLabelProperties(xDataSeries0
, 2, true);
188 Reference
<chart2::XDataSeries
> xDataSeries1
= getDataSeriesFromDoc(xChartDoc
, 1);
189 CPPUNIT_ASSERT(xDataSeries1
.is());
190 checkDataLabelProperties(xDataSeries1
, 0, false);
191 checkDataLabelProperties(xDataSeries1
, 1, false);
192 checkDataLabelProperties(xDataSeries1
, 2, false);
195 CPPUNIT_TEST_FIXTURE(Chart2ImportTest2
, testDataPointInheritedColorDOCX
)
197 loadFromFile(u
"docx/data_point_inherited_color.docx");
198 uno::Reference
<chart2::XChartDocument
> xChartDoc(getChartDocFromWriter(0), uno::UNO_QUERY
);
199 CPPUNIT_ASSERT(xChartDoc
.is());
200 css::uno::Reference
<chart2::XDiagram
> xDiagram(xChartDoc
->getFirstDiagram(), UNO_SET_THROW
);
202 Reference
<chart2::XDataSeries
> xDataSeries
= getDataSeriesFromDoc(xChartDoc
, 0);
203 uno::Reference
<beans::XPropertySet
> xPropertySet(xDataSeries
->getDataPointByIndex(0),
205 CPPUNIT_ASSERT(xPropertySet
.is());
206 sal_Int32 nColor
= xPropertySet
->getPropertyValue("FillColor").get
<sal_Int32
>();
207 CPPUNIT_ASSERT_EQUAL(sal_Int32(16776960), nColor
);
210 CPPUNIT_TEST_FIXTURE(Chart2ImportTest2
, testExternalStrRefsXLSX
)
212 loadFromFile(u
"xlsx/external_str_ref.xlsx");
213 uno::Reference
<chart2::XChartDocument
> xChartDoc(getChartCompFromSheet(0, 0, mxComponent
),
215 CPPUNIT_ASSERT(xChartDoc
.is());
217 Reference
<chart2::XAxis
> xAxis
= getAxisFromDoc(xChartDoc
, 0, 0, 0);
218 chart2::ScaleData aScaleData
= xAxis
->getScaleData();
219 css::uno::Sequence
<css::uno::Any
> aValues
= aScaleData
.Categories
->getValues()->getData();
220 CPPUNIT_ASSERT_EQUAL(OUString("test1"), aValues
[0].get
<OUString
>());
221 CPPUNIT_ASSERT_EQUAL(OUString("test2"), aValues
[1].get
<OUString
>());
224 CPPUNIT_TEST_FIXTURE(Chart2ImportTest2
, testSourceNumberFormatComplexCategoriesXLS
)
226 loadFromFile(u
"xls/source_number_format_axis.xls");
227 uno::Reference
<chart2::XChartDocument
> xChartDoc(getChartCompFromSheet(0, 0, mxComponent
),
229 CPPUNIT_ASSERT(xChartDoc
.is());
231 Reference
<chart2::XAxis
> xAxis
= getAxisFromDoc(xChartDoc
, 0, 0, 0);
232 chart2::ScaleData aScaleData
= xAxis
->getScaleData();
233 sal_Int32 nNumberFormat
= aScaleData
.Categories
->getValues()->getNumberFormatKeyByIndex(-1);
234 CPPUNIT_ASSERT(nNumberFormat
!= 0);
237 CPPUNIT_TEST_FIXTURE(Chart2ImportTest2
, testSimpleCategoryAxis
)
239 loadFromFile(u
"docx/testSimpleCategoryAxis.docx");
240 uno::Reference
<chart2::XChartDocument
> xChartDoc(getChartDocFromWriter(0), uno::UNO_QUERY
);
241 CPPUNIT_ASSERT(xChartDoc
.is());
243 // Test the internal data.
244 CPPUNIT_ASSERT(xChartDoc
->hasInternalDataProvider());
246 Reference
<chart2::XInternalDataProvider
> xInternalProvider(xChartDoc
->getDataProvider(),
248 CPPUNIT_ASSERT(xInternalProvider
.is());
250 Reference
<chart::XComplexDescriptionAccess
> xDescAccess(xInternalProvider
, uno::UNO_QUERY
);
251 CPPUNIT_ASSERT(xDescAccess
.is());
253 // Get the category labels.
254 Sequence
<Sequence
<OUString
>> aCategories
= xDescAccess
->getComplexRowDescriptions();
255 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aCategories
[0].getLength());
256 CPPUNIT_ASSERT(aCategories
[0][0].endsWith("ria 1"));
257 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aCategories
[1].getLength());
258 CPPUNIT_ASSERT(aCategories
[1][0].endsWith("ria 2"));
259 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aCategories
[2].getLength());
260 CPPUNIT_ASSERT(aCategories
[2][0].endsWith("ria 3"));
261 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aCategories
[3].getLength());
262 CPPUNIT_ASSERT(aCategories
[3][0].endsWith("ria 4"));
265 CPPUNIT_TEST_FIXTURE(Chart2ImportTest2
, testMultilevelCategoryAxis
)
267 loadFromFile(u
"docx/testMultilevelCategoryAxis.docx");
268 uno::Reference
<chart2::XChartDocument
> xChartDoc(getChartDocFromWriter(0), uno::UNO_QUERY
);
269 CPPUNIT_ASSERT(xChartDoc
.is());
271 // Test the internal data.
272 CPPUNIT_ASSERT(xChartDoc
->hasInternalDataProvider());
274 Reference
<chart2::XInternalDataProvider
> xInternalProvider(xChartDoc
->getDataProvider(),
276 CPPUNIT_ASSERT(xInternalProvider
.is());
278 Reference
<chart::XComplexDescriptionAccess
> xDescAccess(xInternalProvider
, uno::UNO_QUERY
);
279 CPPUNIT_ASSERT(xDescAccess
.is());
281 // Get the complex category labels.
282 Sequence
<Sequence
<OUString
>> aCategories
= xDescAccess
->getComplexRowDescriptions();
283 CPPUNIT_ASSERT_EQUAL(sal_Int32(4), aCategories
.getLength());
284 CPPUNIT_ASSERT_EQUAL(OUString("2011"), aCategories
[0][0]);
285 CPPUNIT_ASSERT_EQUAL(OUString(""), aCategories
[1][0]);
286 CPPUNIT_ASSERT_EQUAL(OUString("2012"), aCategories
[2][0]);
287 CPPUNIT_ASSERT_EQUAL(OUString(""), aCategories
[3][0]);
288 CPPUNIT_ASSERT_EQUAL(OUString("Categoria 1"), aCategories
[0][1]);
289 CPPUNIT_ASSERT_EQUAL(OUString("Categoria 2"), aCategories
[1][1]);
290 CPPUNIT_ASSERT_EQUAL(OUString("Categoria 3"), aCategories
[2][1]);
291 CPPUNIT_ASSERT_EQUAL(OUString("Categoria 4"), aCategories
[3][1]);
294 CPPUNIT_TEST_FIXTURE(Chart2ImportTest2
, testXaxisValues
)
296 loadFromFile(u
"docx/tdf124083.docx");
297 uno::Reference
<chart2::XChartDocument
> xChartDoc(getChartDocFromWriter(0), uno::UNO_QUERY
);
298 CPPUNIT_ASSERT(xChartDoc
.is());
300 const uno::Reference
<chart2::data::XDataSequence
> xDataSeq
301 = getDataSequenceFromDocByRole(xChartDoc
, u
"values-x");
302 Sequence
<uno::Any
> xSequence
= xDataSeq
->getData();
304 CPPUNIT_ASSERT_EQUAL(uno::Any(0.04), xSequence
[0]);
305 CPPUNIT_ASSERT(std::isnan(*static_cast<const double*>(xSequence
[1].getValue())));
306 CPPUNIT_ASSERT_EQUAL(uno::Any(0.16), xSequence
[2]);
307 CPPUNIT_ASSERT_EQUAL(uno::Any(0.11), xSequence
[3]);
308 CPPUNIT_ASSERT(std::isnan(*static_cast<const double*>(xSequence
[4].getValue())));
311 CPPUNIT_TEST_FIXTURE(Chart2ImportTest2
, testTdf123504
)
313 loadFromFile(u
"ods/pie_chart_100_and_0.ods");
314 Reference
<chart::XChartDocument
> xChartDoc(getChartDocFromSheet(0, mxComponent
),
317 Reference
<chart2::XChartDocument
> xChartDoc2(xChartDoc
, UNO_QUERY_THROW
);
318 Reference
<chart2::XChartType
> xChartType(getChartTypeFromDoc(xChartDoc2
, 0), UNO_SET_THROW
);
319 std::vector aDataSeriesYValues
= getDataSeriesYValuesFromChartType(xChartType
);
320 CPPUNIT_ASSERT_EQUAL(size_t(1), aDataSeriesYValues
.size());
322 Reference
<drawing::XDrawPageSupplier
> xDrawPageSupplier(xChartDoc
, UNO_QUERY_THROW
);
323 Reference
<drawing::XDrawPage
> xDrawPage(xDrawPageSupplier
->getDrawPage(), UNO_SET_THROW
);
324 Reference
<drawing::XShapes
> xShapes(xDrawPage
->getByIndex(0), UNO_QUERY_THROW
);
325 Reference
<drawing::XShape
> xSeriesSlices(getShapeByName(xShapes
, "CID/D=0:CS=0:CT=0:Series=0"),
328 Reference
<container::XIndexAccess
> xIndexAccess(xSeriesSlices
, UNO_QUERY_THROW
);
329 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess
->getCount());
330 Reference
<drawing::XShape
> xSlice(xIndexAccess
->getByIndex(0), UNO_QUERY_THROW
);
332 // Check size and position of the only slice in the chart (100%)
333 // In the regressed state, it used to be 0-sized at position 0,0
334 awt::Point aSlicePosition
= xSlice
->getPosition();
335 CPPUNIT_ASSERT_GREATER(sal_Int32(3000), aSlicePosition
.X
);
336 CPPUNIT_ASSERT_GREATER(sal_Int32(150), aSlicePosition
.Y
);
337 awt::Size aSliceSize
= xSlice
->getSize();
338 CPPUNIT_ASSERT_DOUBLES_EQUAL(8300.0, aSliceSize
.Height
, 10);
339 CPPUNIT_ASSERT_DOUBLES_EQUAL(8300.0, aSliceSize
.Width
, 10);
342 CPPUNIT_TEST_FIXTURE(Chart2ImportTest2
, testTdf122765
)
344 // The horizontal position of the slices was wrong.
345 loadFromFile(u
"pptx/tdf122765.pptx");
346 Reference
<chart::XChartDocument
> xChartDoc
= getChartDocFromDrawImpress(0, 0);
347 Reference
<drawing::XDrawPageSupplier
> xDrawPageSupplier(xChartDoc
, UNO_QUERY_THROW
);
348 Reference
<drawing::XDrawPage
> xDrawPage(xDrawPageSupplier
->getDrawPage(), UNO_SET_THROW
);
349 Reference
<drawing::XShapes
> xShapes(xDrawPage
->getByIndex(0), UNO_QUERY_THROW
);
350 Reference
<drawing::XShape
> xSeriesSlices(getShapeByName(xShapes
, "CID/D=0:CS=0:CT=0:Series=0"),
353 Reference
<container::XIndexAccess
> xIndexAccess(xSeriesSlices
, UNO_QUERY_THROW
);
354 CPPUNIT_ASSERT_EQUAL(sal_Int32(9), xIndexAccess
->getCount());
355 Reference
<drawing::XShape
> xSlice(xIndexAccess
->getByIndex(0), UNO_QUERY_THROW
);
357 // Check position of the first slice, all slices move together, so enough to check only one.
358 // Wrong position was around 5856.
359 awt::Point aSlicePosition
= xSlice
->getPosition();
360 CPPUNIT_ASSERT_GREATER(sal_Int32(7000), aSlicePosition
.X
);
363 CPPUNIT_TEST_FIXTURE(Chart2ImportTest2
, testTdf123206CustomLabelField
)
365 // File contains the deprecated "custom-label-field" attribute of the
366 // "data-point" element. It should be interpreted and stored as a data point
368 loadFromFile(u
"odp/tdf123206.odp");
369 uno::Reference
<chart2::XChartDocument
> xChartDoc(getChartDocFromDrawImpress(0, 0),
370 uno::UNO_QUERY_THROW
);
371 CPPUNIT_ASSERT_MESSAGE("failed to load chart", xChartDoc
.is());
372 CPPUNIT_ASSERT(xChartDoc
.is());
373 Reference
<chart2::XDataSeries
> xDataSeries
= getDataSeriesFromDoc(xChartDoc
, 0);
374 CPPUNIT_ASSERT(xDataSeries
.is());
375 Reference
<beans::XPropertySet
> xDp
= xDataSeries
->getDataPointByIndex(1);
376 Sequence
<Reference
<chart2::XDataPointCustomLabelField
>> aLabelFields
;
377 CPPUNIT_ASSERT(xDp
->getPropertyValue("CustomLabelFields") >>= aLabelFields
);
378 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32
>(1), aLabelFields
.getLength());
379 CPPUNIT_ASSERT_EQUAL(OUString("Kiskacsa"), aLabelFields
[0]->getString());
382 CPPUNIT_TEST_FIXTURE(Chart2ImportTest2
, testTdf125444PercentageCustomLabel
)
384 loadFromFile(u
"pptx/tdf125444.pptx");
387 Reference
<chart2::XChartDocument
> xChartDoc(getChartDocFromDrawImpress(0, 0), uno::UNO_QUERY
);
388 CPPUNIT_ASSERT(xChartDoc
.is());
390 uno::Reference
<chart2::XDataSeries
> xDataSeries(getDataSeriesFromDoc(xChartDoc
, 0));
391 CPPUNIT_ASSERT(xDataSeries
.is());
392 Reference
<beans::XPropertySet
> xDp
= xDataSeries
->getDataPointByIndex(1);
393 Sequence
<Reference
<chart2::XDataPointCustomLabelField
>> aLabelFields
;
394 CPPUNIT_ASSERT(xDp
->getPropertyValue("CustomLabelFields") >>= aLabelFields
);
395 // There are three label field: a value label, a newline and a percentage label. We want
396 // to assert the latter.
397 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32
>(3), aLabelFields
.getLength());
398 CPPUNIT_ASSERT_EQUAL(chart2::DataPointCustomLabelFieldType_PERCENTAGE
,
399 aLabelFields
[2]->getFieldType());
402 CPPUNIT_TEST_FIXTURE(Chart2ImportTest2
, testDataPointLabelCustomPos
)
404 // test CustomLabelPosition on Bar chart
405 loadFromFile(u
"xlsx/testDataPointLabelCustomPos.xlsx");
406 uno::Reference
<chart2::XChartDocument
> xChartDoc
= getChartDocFromSheet(0, mxComponent
);
407 CPPUNIT_ASSERT(xChartDoc
.is());
408 uno::Reference
<chart2::XDataSeries
> xDataSeries(getDataSeriesFromDoc(xChartDoc
, 0));
409 CPPUNIT_ASSERT(xDataSeries
.is());
411 uno::Reference
<beans::XPropertySet
> xPropertySet(xDataSeries
->getDataPointByIndex(0),
413 CPPUNIT_ASSERT(xPropertySet
.is());
415 chart2::RelativePosition aCustomLabelPosition
;
416 xPropertySet
->getPropertyValue("CustomLabelPosition") >>= aCustomLabelPosition
;
417 CPPUNIT_ASSERT_DOUBLES_EQUAL(-0.14621409921671025, aCustomLabelPosition
.Primary
, 1e-7);
418 CPPUNIT_ASSERT_DOUBLES_EQUAL(-5.2887961029923464E-2, aCustomLabelPosition
.Secondary
, 1e-7);
420 sal_Int32 aPlacement
;
421 xPropertySet
->getPropertyValue("LabelPlacement") >>= aPlacement
;
422 CPPUNIT_ASSERT_EQUAL(chart::DataLabelPlacement::OUTSIDE
, aPlacement
);
425 CPPUNIT_TEST_FIXTURE(Chart2ImportTest2
, testTdf130032
)
427 // test CustomLabelPosition on Line chart
428 loadFromFile(u
"xlsx/testTdf130032.xlsx");
429 uno::Reference
<chart2::XChartDocument
> xChartDoc
= getChartDocFromSheet(0, mxComponent
);
430 CPPUNIT_ASSERT(xChartDoc
.is());
431 uno::Reference
<chart2::XDataSeries
> xDataSeries(getDataSeriesFromDoc(xChartDoc
, 0));
432 CPPUNIT_ASSERT(xDataSeries
.is());
434 uno::Reference
<beans::XPropertySet
> xPropertySet(xDataSeries
->getDataPointByIndex(1),
436 CPPUNIT_ASSERT(xPropertySet
.is());
438 chart2::RelativePosition aCustomLabelPosition
;
439 xPropertySet
->getPropertyValue("CustomLabelPosition") >>= aCustomLabelPosition
;
440 CPPUNIT_ASSERT_DOUBLES_EQUAL(-0.0438333333333334, aCustomLabelPosition
.Primary
, 1e-7);
441 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.086794050743657, aCustomLabelPosition
.Secondary
, 1e-7);
443 sal_Int32 aPlacement
;
444 xPropertySet
->getPropertyValue("LabelPlacement") >>= aPlacement
;
445 CPPUNIT_ASSERT_EQUAL(chart::DataLabelPlacement::RIGHT
, aPlacement
);
448 CPPUNIT_TEST_FIXTURE(Chart2ImportTest2
, testTdf134978
)
450 // test CustomLabelPosition on Pie chart
451 loadFromFile(u
"xlsx/tdf134978.xlsx");
452 uno::Reference
<chart2::XChartDocument
> xChartDoc
= getChartDocFromSheet(0, mxComponent
);
453 CPPUNIT_ASSERT(xChartDoc
.is());
454 uno::Reference
<chart2::XDataSeries
> xDataSeries(getDataSeriesFromDoc(xChartDoc
, 0));
455 CPPUNIT_ASSERT(xDataSeries
.is());
457 uno::Reference
<beans::XPropertySet
> xPropertySet(xDataSeries
->getDataPointByIndex(2),
459 CPPUNIT_ASSERT(xPropertySet
.is());
461 chart2::RelativePosition aCustomLabelPosition
;
462 xPropertySet
->getPropertyValue("CustomLabelPosition") >>= aCustomLabelPosition
;
463 CPPUNIT_ASSERT_DOUBLES_EQUAL(-0.040273622047244093, aCustomLabelPosition
.Primary
, 1e-7);
464 CPPUNIT_ASSERT_DOUBLES_EQUAL(-0.25635352872557599, aCustomLabelPosition
.Secondary
, 1e-7);
467 CPPUNIT_TEST_FIXTURE(Chart2ImportTest2
, testTdf119138MissingAutoTitleDeleted
)
469 loadFromFile(u
"xlsx/tdf119138-missing-autotitledeleted.xlsx");
470 Reference
<chart2::XChartDocument
> xChartDoc
= getChartDocFromSheet(0, mxComponent
);
471 CPPUNIT_ASSERT_MESSAGE("failed to load chart", xChartDoc
.is());
473 Reference
<chart2::XTitled
> xTitled(xChartDoc
, uno::UNO_QUERY_THROW
);
474 uno::Reference
<chart2::XTitle
> xTitle
= xTitled
->getTitleObject();
475 CPPUNIT_ASSERT_MESSAGE(
476 "Missing autoTitleDeleted is implied to be True if title text is present", xTitle
.is());
479 CPPUNIT_TEST_FIXTURE(Chart2ImportTest2
, testStockChartShiftedCategoryPosition
)
481 loadFromFile(u
"odt/stock_chart_LO_6_2.odt");
483 uno::Reference
<chart2::XChartDocument
> xChartDoc(getChartDocFromWriter(0), uno::UNO_QUERY
);
484 CPPUNIT_ASSERT(xChartDoc
.is());
486 Reference
<chart2::XAxis
> xAxis
= getAxisFromDoc(xChartDoc
, 0, 0, 0);
487 CPPUNIT_ASSERT(xAxis
.is());
489 chart2::ScaleData aScaleData
= xAxis
->getScaleData();
490 CPPUNIT_ASSERT(aScaleData
.Categories
.is());
491 CPPUNIT_ASSERT(aScaleData
.ShiftedCategoryPosition
);
494 CPPUNIT_TEST_FIXTURE(Chart2ImportTest2
, testTdf133376
)
496 // FIXME: the DPI check should be removed when either (1) the test is fixed to work with
497 // non-default DPI; or (2) unit tests on Windows are made to use svp VCL plugin.
501 loadFromFile(u
"xlsx/tdf133376.xlsx");
502 Reference
<chart::XChartDocument
> xChartDoc(getChartDocFromSheet(0, mxComponent
),
505 Reference
<drawing::XDrawPageSupplier
> xDrawPageSupplier(xChartDoc
, UNO_QUERY_THROW
);
506 Reference
<drawing::XDrawPage
> xDrawPage(xDrawPageSupplier
->getDrawPage(), UNO_SET_THROW
);
507 Reference
<drawing::XShapes
> xShapes(xDrawPage
->getByIndex(0), UNO_QUERY_THROW
);
508 Reference
<drawing::XShape
> xDataPointLabel(
509 getShapeByName(xShapes
,
510 "CID/MultiClick/CID/D=0:CS=0:CT=0:Series=0:DataLabels=:DataLabel=2"),
513 CPPUNIT_ASSERT(xDataPointLabel
.is());
514 // Check the position of the 3rd data point label, which is out from the pie slice
515 awt::Point aLabelPosition
= xDataPointLabel
->getPosition();
516 CPPUNIT_ASSERT_DOUBLES_EQUAL(1208, aLabelPosition
.X
, 30);
517 CPPUNIT_ASSERT_DOUBLES_EQUAL(5370, aLabelPosition
.Y
, 30);
520 CPPUNIT_TEST_FIXTURE(Chart2ImportTest2
, testTdf134225
)
522 loadFromFile(u
"xlsx/tdf134225.xlsx");
523 Reference
<chart::XChartDocument
> xChartDoc(getChartDocFromSheet(0, mxComponent
),
526 Reference
<drawing::XDrawPageSupplier
> xDrawPageSupplier(xChartDoc
, UNO_QUERY_THROW
);
527 Reference
<drawing::XDrawPage
> xDrawPage(xDrawPageSupplier
->getDrawPage(), UNO_SET_THROW
);
528 Reference
<drawing::XShapes
> xShapes(xDrawPage
->getByIndex(0), UNO_QUERY_THROW
);
529 Reference
<drawing::XShape
> xDataPointLabel1(
530 getShapeByName(xShapes
,
531 "CID/MultiClick/CID/D=0:CS=0:CT=0:Series=0:DataLabels=:DataLabel=0"),
533 CPPUNIT_ASSERT(xDataPointLabel1
.is());
535 Reference
<drawing::XShape
> xDataPointLabel2(
536 getShapeByName(xShapes
,
537 "CID/MultiClick/CID/D=0:CS=0:CT=0:Series=0:DataLabels=:DataLabel=1"),
539 CPPUNIT_ASSERT(xDataPointLabel2
.is());
542 // font is MS Comic Sans which we can only assume is available under windows
543 awt::Point aLabelPosition1
= xDataPointLabel1
->getPosition();
544 awt::Point aLabelPosition2
= xDataPointLabel2
->getPosition();
546 // Check the distance between the position of the 1st data point label and the second one
547 CPPUNIT_ASSERT_DOUBLES_EQUAL(1493, sal_Int32(aLabelPosition2
.X
- aLabelPosition1
.X
), 30);
548 CPPUNIT_ASSERT_DOUBLES_EQUAL(2015, sal_Int32(aLabelPosition2
.Y
- aLabelPosition1
.Y
), 30);
552 CPPUNIT_TEST_FIXTURE(Chart2ImportTest2
, testTdf136105
)
554 // FIXME: the DPI check should be removed when either (1) the test is fixed to work with
555 // non-default DPI; or (2) unit tests on Windows are made to use svp VCL plugin.
559 loadFromFile(u
"xlsx/tdf136105.xlsx");
560 // 1st chart with fix inner position and size
562 Reference
<chart::XChartDocument
> xChartDoc(getChartDocFromSheet(0, mxComponent
),
565 Reference
<drawing::XDrawPageSupplier
> xDrawPageSupplier(xChartDoc
, UNO_QUERY_THROW
);
566 Reference
<drawing::XDrawPage
> xDrawPage(xDrawPageSupplier
->getDrawPage(), UNO_SET_THROW
);
567 Reference
<drawing::XShapes
> xShapes(xDrawPage
->getByIndex(0), UNO_QUERY_THROW
);
568 Reference
<drawing::XShape
> xDataPointLabel(
569 getShapeByName(xShapes
,
570 "CID/MultiClick/CID/D=0:CS=0:CT=0:Series=0:DataLabels=:DataLabel=0"),
573 CPPUNIT_ASSERT(xDataPointLabel
.is());
574 // Check the position of the 1st data point label, which is out from the pie slice
575 awt::Point aLabelPosition
= xDataPointLabel
->getPosition();
576 CPPUNIT_ASSERT_DOUBLES_EQUAL(8797, aLabelPosition
.X
, 500);
577 CPPUNIT_ASSERT_DOUBLES_EQUAL(1374, aLabelPosition
.Y
, 500);
579 // 2nd chart with auto inner position and size
581 Reference
<chart::XChartDocument
> xChartDoc(getChartDocFromSheet(1, mxComponent
),
584 Reference
<drawing::XDrawPageSupplier
> xDrawPageSupplier(xChartDoc
, UNO_QUERY_THROW
);
585 Reference
<drawing::XDrawPage
> xDrawPage(xDrawPageSupplier
->getDrawPage(), UNO_SET_THROW
);
586 Reference
<drawing::XShapes
> xShapes(xDrawPage
->getByIndex(0), UNO_QUERY_THROW
);
587 Reference
<drawing::XShape
> xDataPointLabel(
588 getShapeByName(xShapes
,
589 "CID/MultiClick/CID/D=0:CS=0:CT=0:Series=0:DataLabels=:DataLabel=0"),
592 CPPUNIT_ASSERT(xDataPointLabel
.is());
593 // Check the position of the 1st data point label, which is out from the pie slice
594 awt::Point aLabelPosition
= xDataPointLabel
->getPosition();
595 CPPUNIT_ASSERT_DOUBLES_EQUAL(7978, aLabelPosition
.X
, 500);
596 CPPUNIT_ASSERT_DOUBLES_EQUAL(1550, aLabelPosition
.Y
, 500);
600 CPPUNIT_TEST_FIXTURE(Chart2ImportTest2
, testTdf91250
)
602 loadFromFile(u
"docx/tdf91250.docx");
603 uno::Reference
<chart2::XChartDocument
> xChartDoc(getChartDocFromWriter(0), uno::UNO_QUERY
);
604 CPPUNIT_ASSERT(xChartDoc
.is());
605 Reference
<chart2::XInternalDataProvider
> xInternalProvider(xChartDoc
->getDataProvider(),
607 CPPUNIT_ASSERT(xInternalProvider
.is());
609 Reference
<chart::XComplexDescriptionAccess
> xDescAccess(xInternalProvider
, uno::UNO_QUERY
);
610 CPPUNIT_ASSERT(xDescAccess
.is());
612 // Get the category labels.
613 Sequence
<OUString
> aCategories
= xDescAccess
->getRowDescriptions();
614 CPPUNIT_ASSERT_EQUAL(sal_Int32(4), aCategories
.getLength());
615 CPPUNIT_ASSERT_EQUAL(OUString("12.3254"), aCategories
[0]);
616 CPPUNIT_ASSERT_EQUAL(OUString("11.62315"), aCategories
[1]);
617 CPPUNIT_ASSERT_EQUAL(OUString("9.26"), aCategories
[2]);
618 CPPUNIT_ASSERT_EQUAL(OUString("8.657"), aCategories
[3]);
621 CPPUNIT_TEST_FIXTURE(Chart2ImportTest2
, testTdf134111
)
623 // tdf134111 : To check TextBreak value is true
624 loadFromFile(u
"docx/tdf134111.docx");
625 uno::Reference
<chart::XChartDocument
> xChartDoc
= getChartDocFromWriter(0);
626 CPPUNIT_ASSERT_MESSAGE("failed to load chart", xChartDoc
.is());
627 uno::Reference
<chart::XDiagram
> mxDiagram(xChartDoc
->getDiagram());
628 CPPUNIT_ASSERT(mxDiagram
.is());
629 uno::Reference
<chart::XAxisXSupplier
> xAxisXSupp(mxDiagram
, uno::UNO_QUERY
);
630 CPPUNIT_ASSERT(xAxisXSupp
.is());
631 uno::Reference
<beans::XPropertySet
> xAxisProp(xAxisXSupp
->getXAxis());
632 bool bTextBreak
= false;
633 xAxisProp
->getPropertyValue("TextBreak") >>= bTextBreak
;
634 // Expected value of 'TextBreak' is true
635 CPPUNIT_ASSERT(bTextBreak
);
638 CPPUNIT_TEST_FIXTURE(Chart2ImportTest2
, testTdf136752
)
640 loadFromFile(u
"xlsx/tdf136752.xlsx");
641 Reference
<chart::XChartDocument
> xChartDoc(getChartDocFromSheet(0, mxComponent
),
644 Reference
<drawing::XDrawPageSupplier
> xDrawPageSupplier(xChartDoc
, UNO_QUERY_THROW
);
645 Reference
<drawing::XDrawPage
> xDrawPage(xDrawPageSupplier
->getDrawPage(), UNO_SET_THROW
);
646 Reference
<drawing::XShapes
> xShapes(xDrawPage
->getByIndex(0), UNO_QUERY_THROW
);
647 Reference
<drawing::XShape
> xDataPointLabel(
648 getShapeByName(xShapes
,
649 "CID/MultiClick/CID/D=0:CS=0:CT=0:Series=0:DataLabels=:DataLabel=0"),
652 CPPUNIT_ASSERT(xDataPointLabel
.is());
653 // Check the position of the 1st data point label, which is out from the pie slice
654 awt::Point aLabelPosition
= xDataPointLabel
->getPosition();
655 CPPUNIT_ASSERT_DOUBLES_EQUAL(8675, aLabelPosition
.X
, 500);
656 CPPUNIT_ASSERT_DOUBLES_EQUAL(1458, aLabelPosition
.Y
, 500);
659 CPPUNIT_TEST_FIXTURE(Chart2ImportTest2
, testTdf137505
)
661 loadFromFile(u
"xlsx/tdf137505.xlsx");
662 Reference
<chart::XChartDocument
> xChartDoc(getChartDocFromSheet(0, mxComponent
),
665 Reference
<drawing::XDrawPageSupplier
> xDrawPageSupplier(xChartDoc
, UNO_QUERY_THROW
);
666 Reference
<drawing::XDrawPage
> xDrawPage(xDrawPageSupplier
->getDrawPage(), UNO_SET_THROW
);
667 Reference
<drawing::XShape
> xCustomShape(xDrawPage
->getByIndex(1), UNO_QUERY_THROW
);
668 CPPUNIT_ASSERT(xCustomShape
.is());
671 Reference
<text::XText
> xRange(xCustomShape
, uno::UNO_QUERY_THROW
);
672 Reference
<text::XTextCursor
> xAt
= xRange
->createTextCursor();
673 Reference
<beans::XPropertySet
> xProps(xAt
, UNO_QUERY
);
674 // check the text size of custom shape, inside the chart.
675 CPPUNIT_ASSERT(xProps
->getPropertyValue("CharHeight") >>= nFontSize
);
676 CPPUNIT_ASSERT_EQUAL(float(12), nFontSize
);
679 CPPUNIT_TEST_FIXTURE(Chart2ImportTest2
, testTdf137734
)
681 loadFromFile(u
"xlsx/tdf137734.xlsx");
682 Reference
<chart2::XChartDocument
> xChartDoc
= getChartDocFromSheet(0, mxComponent
);
683 CPPUNIT_ASSERT_MESSAGE("failed to load chart", xChartDoc
.is());
684 CPPUNIT_ASSERT(xChartDoc
.is());
685 Reference
<chart2::XDataSeries
> xDataSeries
= getDataSeriesFromDoc(xChartDoc
, 0);
686 CPPUNIT_ASSERT(xDataSeries
.is());
687 Reference
<beans::XPropertySet
> xPropSet(xDataSeries
, uno::UNO_QUERY_THROW
);
688 uno::Any aAny
= xPropSet
->getPropertyValue("VaryColorsByPoint");
689 bool bVaryColor
= true;
690 CPPUNIT_ASSERT(aAny
>>= bVaryColor
);
691 CPPUNIT_ASSERT(!bVaryColor
);
693 // tdf#126133 Test primary X axis Rotation value
694 Reference
<chart2::XAxis
> xXAxis
= getAxisFromDoc(xChartDoc
, 0, 0, 0);
695 CPPUNIT_ASSERT(xXAxis
.is());
696 Reference
<chart2::XTitled
> xTitled(xXAxis
, uno::UNO_QUERY_THROW
);
697 Reference
<chart2::XTitle
> xTitle
= xTitled
->getTitleObject();
698 CPPUNIT_ASSERT(xTitle
.is());
699 Reference
<beans::XPropertySet
> xTitlePropSet(xTitle
, uno::UNO_QUERY_THROW
);
700 uno::Any aAny2
= xTitlePropSet
->getPropertyValue("TextRotation");
701 double nRotation
= -1;
702 CPPUNIT_ASSERT(aAny2
>>= nRotation
);
703 CPPUNIT_ASSERT_EQUAL(0.0, nRotation
);
706 CPPUNIT_TEST_FIXTURE(Chart2ImportTest2
, testTdf137874
)
708 loadFromFile(u
"xlsx/piechart_legend.xlsx");
709 Reference
<chart::XChartDocument
> xChartDoc(getChartDocFromSheet(0, mxComponent
),
711 Reference
<drawing::XDrawPageSupplier
> xDrawPageSupplier(xChartDoc
, UNO_QUERY_THROW
);
712 Reference
<drawing::XDrawPage
> xDrawPage(xDrawPageSupplier
->getDrawPage(), UNO_SET_THROW
);
713 Reference
<drawing::XShapes
> xShapes(xDrawPage
->getByIndex(0), UNO_QUERY_THROW
);
714 Reference
<drawing::XShape
> xLegendEntry
;
716 = getShapeByName(xShapes
, "CID/MultiClick/D=0:CS=0:CT=0:Series=0:Point=0:LegendEntry=0");
717 CPPUNIT_ASSERT(xLegendEntry
.is());
720 CPPUNIT_TEST_FIXTURE(Chart2ImportTest2
, testTdf146463
)
722 loadFromFile(u
"ods/tdf146463.ods");
723 Reference
<chart2::XChartDocument
> xChartDoc(getChartDocFromSheet(0, mxComponent
));
724 Reference
<drawing::XDrawPageSupplier
> xDrawPageSupplier(xChartDoc
, UNO_QUERY_THROW
);
725 Reference
<drawing::XDrawPage
> xDrawPage(xDrawPageSupplier
->getDrawPage(), UNO_SET_THROW
);
726 Reference
<drawing::XShapes
> xShapes(xDrawPage
->getByIndex(0), UNO_QUERY_THROW
);
727 Reference
<chart2::XChartType
> xChartType
= getChartTypeFromDoc(xChartDoc
, 0);
728 std::vector
<std::vector
<double>> aDataSeriesYValues
729 = getDataSeriesYValuesFromChartType(xChartType
);
730 size_t nLegendEntryCount
= aDataSeriesYValues
.size();
731 CPPUNIT_ASSERT_EQUAL(size_t(14), nLegendEntryCount
);
733 for (size_t nSeriesIndex
= 0; nSeriesIndex
< nLegendEntryCount
; ++nSeriesIndex
)
735 uno::Reference
<drawing::XShape
> xLegendEntry
736 = getShapeByName(xShapes
, "CID/MultiClick/D=0:CS=0:CT=0:Series="
737 + OUString::number(nSeriesIndex
) + ":LegendEntry=0");
738 if (nSeriesIndex
== 0)
739 CPPUNIT_ASSERT_MESSAGE("Legend 0 is not visible", xLegendEntry
.is());
741 CPPUNIT_ASSERT_MESSAGE(
742 OString("Legend " + OString::number(nSeriesIndex
) + " is visible").getStr(),
747 CPPUNIT_TEST_FIXTURE(Chart2ImportTest2
, testTdfCustomShapePos
)
749 loadFromFile(u
"docx/testcustomshapepos.docx");
750 Reference
<chart2::XChartDocument
> xChartDoc(getChartDocFromWriter(0), UNO_QUERY_THROW
);
751 Reference
<drawing::XDrawPageSupplier
> xDrawPageSupplier(xChartDoc
, UNO_QUERY_THROW
);
752 Reference
<drawing::XDrawPage
> xDrawPage(xDrawPageSupplier
->getDrawPage(), UNO_SET_THROW
);
753 // test position and size of a custom shape within a chart, rotated by 0 degree.
755 Reference
<drawing::XShape
> xCustomShape(xDrawPage
->getByIndex(0), UNO_QUERY_THROW
);
756 awt::Point aPosition
= xCustomShape
->getPosition();
757 CPPUNIT_ASSERT_DOUBLES_EQUAL(8845, aPosition
.X
, 300);
758 CPPUNIT_ASSERT_DOUBLES_EQUAL(855, aPosition
.Y
, 300);
759 awt::Size aSize
= xCustomShape
->getSize();
760 CPPUNIT_ASSERT_DOUBLES_EQUAL(4831, aSize
.Width
, 300);
761 CPPUNIT_ASSERT_DOUBLES_EQUAL(1550, aSize
.Height
, 300);
763 // test position and size of a custom shape within a chart, rotated by 90 degree.
765 Reference
<drawing::XShape
> xCustomShape(xDrawPage
->getByIndex(1), UNO_QUERY_THROW
);
766 awt::Point aPosition
= xCustomShape
->getPosition();
767 CPPUNIT_ASSERT_DOUBLES_EQUAL(1658, aPosition
.X
, 300);
768 CPPUNIT_ASSERT_DOUBLES_EQUAL(6119, aPosition
.Y
, 300);
769 awt::Size aSize
= xCustomShape
->getSize();
770 CPPUNIT_ASSERT_DOUBLES_EQUAL(4165, aSize
.Width
, 300);
771 CPPUNIT_ASSERT_DOUBLES_EQUAL(1334, aSize
.Height
, 300);
775 CPPUNIT_TEST_FIXTURE(Chart2ImportTest2
, testTdf121281
)
777 loadFromFile(u
"xlsx/incorrect_label_position.xlsx");
778 Reference
<chart::XChartDocument
> xChartDoc(getChartDocFromSheet(0, mxComponent
),
780 Reference
<drawing::XDrawPageSupplier
> xDrawPageSupplier(xChartDoc
, UNO_QUERY_THROW
);
781 Reference
<drawing::XDrawPage
> xDrawPage(xDrawPageSupplier
->getDrawPage(), UNO_SET_THROW
);
782 Reference
<drawing::XShapes
> xShapes(xDrawPage
->getByIndex(0), UNO_QUERY_THROW
);
783 Reference
<drawing::XShape
> xDataPointLabel(
784 getShapeByName(xShapes
,
785 "CID/MultiClick/CID/D=0:CS=0:CT=0:Series=0:DataLabels=:DataLabel=0"),
788 CPPUNIT_ASSERT(xDataPointLabel
.is());
789 awt::Point aLabelPosition
= xDataPointLabel
->getPosition();
790 // This failed, if the data label flowed out of the chart area.
791 CPPUNIT_ASSERT_GREATEREQUAL(static_cast<sal_Int32
>(0), aLabelPosition
.Y
);
794 CPPUNIT_TEST_FIXTURE(Chart2ImportTest2
, testTdf139658
)
796 loadFromFile(u
"docx/tdf139658.docx");
797 uno::Reference
<chart2::XChartDocument
> xChartDoc(getChartDocFromWriter(0), uno::UNO_QUERY
);
798 CPPUNIT_ASSERT(xChartDoc
.is());
799 Reference
<chart2::XInternalDataProvider
> xInternalProvider(xChartDoc
->getDataProvider(),
801 CPPUNIT_ASSERT(xInternalProvider
.is());
803 Reference
<chart::XComplexDescriptionAccess
> xDescAccess(xInternalProvider
, uno::UNO_QUERY
);
804 CPPUNIT_ASSERT(xDescAccess
.is());
806 // Get the category labels.
807 Sequence
<OUString
> aCategories
= xDescAccess
->getRowDescriptions();
808 CPPUNIT_ASSERT_EQUAL(sal_Int32(3), aCategories
.getLength());
809 CPPUNIT_ASSERT_EQUAL(OUString("category1"), aCategories
[0]);
810 CPPUNIT_ASSERT_EQUAL(OUString("\"category2\""), aCategories
[1]);
811 CPPUNIT_ASSERT_EQUAL(OUString("category\"3"), aCategories
[2]);
814 CPPUNIT_TEST_FIXTURE(Chart2ImportTest2
, testTdf146066
)
816 loadFromFile(u
"ods/tdf146066.ods");
817 Reference
<chart::XChartDocument
> xChartDoc(getChartDocFromSheet(0, mxComponent
),
819 uno::Reference
<drawing::XDrawPageSupplier
> xDrawPageSupplier(xChartDoc
, uno::UNO_QUERY
);
820 uno::Reference
<drawing::XDrawPage
> xDrawPage
= xDrawPageSupplier
->getDrawPage();
821 uno::Reference
<drawing::XShapes
> xShapes(xDrawPage
->getByIndex(0), uno::UNO_QUERY
);
822 CPPUNIT_ASSERT(xShapes
.is());
824 uno::Reference
<drawing::XShape
> xYAxisShape
= getShapeByName(
825 xShapes
, "CID/D=0:CS=0:Axis=1,0", // Y Axis
826 // Axis occurs twice in chart xshape representation so need to get the one related to labels
827 [](const uno::Reference
<drawing::XShape
>& rXShape
) -> bool {
828 uno::Reference
<drawing::XShapes
> xAxisShapes(rXShape
, uno::UNO_QUERY
);
829 CPPUNIT_ASSERT(xAxisShapes
.is());
830 uno::Reference
<drawing::XShape
> xChildShape(xAxisShapes
->getByIndex(0), uno::UNO_QUERY
);
831 uno::Reference
<drawing::XShapeDescriptor
> xShapeDescriptor(xChildShape
,
832 uno::UNO_QUERY_THROW
);
833 return (xShapeDescriptor
->getShapeType() == "com.sun.star.drawing.TextShape");
835 CPPUNIT_ASSERT(xYAxisShape
.is());
838 uno::Reference
<container::XIndexAccess
> xIndexAccess(xYAxisShape
, UNO_QUERY_THROW
);
839 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32
>(8), xIndexAccess
->getCount());
842 uno::Reference
<text::XTextRange
> xLabel0(xIndexAccess
->getByIndex(0), uno::UNO_QUERY
);
843 CPPUNIT_ASSERT_EQUAL(OUString("0"), xLabel0
->getString());
844 uno::Reference
<text::XTextRange
> xLabel1(xIndexAccess
->getByIndex(1), uno::UNO_QUERY
);
845 CPPUNIT_ASSERT_EQUAL(OUString("5"), xLabel1
->getString());
846 uno::Reference
<text::XTextRange
> xLabel2(xIndexAccess
->getByIndex(2), uno::UNO_QUERY
);
847 CPPUNIT_ASSERT_EQUAL(OUString("10"), xLabel2
->getString());
848 uno::Reference
<text::XTextRange
> xLabel3(xIndexAccess
->getByIndex(3), uno::UNO_QUERY
);
849 CPPUNIT_ASSERT_EQUAL(OUString("15"), xLabel3
->getString());
850 uno::Reference
<text::XTextRange
> xLabel4(xIndexAccess
->getByIndex(4), uno::UNO_QUERY
);
851 CPPUNIT_ASSERT_EQUAL(OUString("20"), xLabel4
->getString());
852 uno::Reference
<text::XTextRange
> xLabel5(xIndexAccess
->getByIndex(5), uno::UNO_QUERY
);
853 CPPUNIT_ASSERT_EQUAL(OUString("25"), xLabel5
->getString());
854 uno::Reference
<text::XTextRange
> xLabel6(xIndexAccess
->getByIndex(6), uno::UNO_QUERY
);
855 CPPUNIT_ASSERT_EQUAL(OUString("30"), xLabel6
->getString());
856 uno::Reference
<text::XTextRange
> xLabel7(xIndexAccess
->getByIndex(7), uno::UNO_QUERY
);
857 CPPUNIT_ASSERT_EQUAL(OUString("35"), xLabel7
->getString());
860 CPPUNIT_TEST_FIXTURE(Chart2ImportTest2
, testTdf150434
)
862 loadFromFile(u
"xlsx/tdf150434.xlsx");
863 Reference
<chart::XChartDocument
> xChartDoc(getChartDocFromSheet(0, mxComponent
),
865 Reference
<drawing::XDrawPageSupplier
> xDrawPageSupplier(xChartDoc
, UNO_QUERY_THROW
);
866 Reference
<drawing::XDrawPage
> xDrawPage(xDrawPageSupplier
->getDrawPage(), UNO_SET_THROW
);
867 Reference
<drawing::XShapes
> xShapes(xDrawPage
->getByIndex(0), UNO_QUERY_THROW
);
868 Reference
<drawing::XShape
> xLegend
= getShapeByName(xShapes
, "CID/D=0:Legend=");
869 CPPUNIT_ASSERT(xLegend
.is());
870 awt::Point aPosition
= xLegend
->getPosition();
872 // This failed, if the legend flowed out of the chart area.
873 CPPUNIT_ASSERT_GREATEREQUAL(static_cast<sal_Int32
>(0), aPosition
.Y
);
876 CPPUNIT_TEST_FIXTURE(Chart2ImportTest2
, testChartDataTableWithMultipleLegendEntriesForOneDataSeries
)
878 loadFromFile(u
"xlsx/DataTable-MultipleLegendEntriesForOneDataSeries.xlsx");
879 // Loading this file caused a crash in the data table code
881 Reference
<chart::XChartDocument
> xChartDoc(getChartDocFromSheet(0, mxComponent
),
883 Reference
<drawing::XDrawPageSupplier
> xDrawPageSupplier(xChartDoc
, UNO_QUERY_THROW
);
884 Reference
<drawing::XDrawPage
> xDrawPage(xDrawPageSupplier
->getDrawPage(), UNO_SET_THROW
);
885 Reference
<drawing::XShapes
> xShapes(xDrawPage
->getByIndex(0), UNO_QUERY_THROW
);
886 Reference
<drawing::XShape
> xDataTableShape
= getShapeByName(xShapes
, "CID/D=0:DataTable=");
887 CPPUNIT_ASSERT(xDataTableShape
.is());
890 CPPUNIT_PLUGIN_IMPLEMENT();
892 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */