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(u
"/chart2/qa/extras/data/"_ustr
)
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(0, 0);
40 uno::Reference
<css::embed::XVisualObject
> xVisualObject(xChartDoc
, uno::UNO_QUERY
);
41 CPPUNIT_ASSERT(xVisualObject
.is());
42 aPage
= xVisualObject
->getVisualAreaSize(css::embed::Aspects::MSOLE_CONTENT
);
43 Reference
<beans::XPropertySet
> xProp(xDiagram
, uno::UNO_QUERY
);
44 chart2::RelativeSize aRelativeSize
;
45 xProp
->getPropertyValue(u
"RelativeSize"_ustr
) >>= aRelativeSize
;
46 double fX
= aRelativeSize
.Primary
* aPage
.Width
;
47 double fY
= aRelativeSize
.Secondary
* aPage
.Height
;
48 CPPUNIT_ASSERT(static_cast<sal_Int32
>(::rtl::math::round(fX
)) > 0);
49 CPPUNIT_ASSERT(static_cast<sal_Int32
>(::rtl::math::round(fY
)) > 0);
52 CPPUNIT_TEST_FIXTURE(Chart2ImportTest2
, testTdf124243
)
54 loadFromFile(u
"docx/tdf124243.docx");
55 uno::Reference
<chart2::XChartDocument
> xChartDoc(getChartDocFromWriter(0), uno::UNO_QUERY
);
56 CPPUNIT_ASSERT_MESSAGE("failed to load chart", xChartDoc
.is());
58 Reference
<chart2::XAxis
> xAxis
= getAxisFromDoc(xChartDoc
, 0, 0, 0);
59 CPPUNIT_ASSERT(xAxis
.is());
61 Reference
<beans::XPropertySet
> xPS(xAxis
, uno::UNO_QUERY_THROW
);
63 // test X Axis is not visible.
64 bool bSuccess
= xPS
->getPropertyValue(u
"Show"_ustr
) >>= bShow
;
65 CPPUNIT_ASSERT(bSuccess
);
66 CPPUNIT_ASSERT(!bShow
);
69 CPPUNIT_TEST_FIXTURE(Chart2ImportTest2
, testTdf127393
)
71 loadFromFile(u
"pptx/tdf127393.pptx");
74 Reference
<chart2::XChartDocument
> xChartDoc(getChartDocFromDrawImpress(0, 0), uno::UNO_QUERY
);
75 CPPUNIT_ASSERT(xChartDoc
.is());
77 Reference
<chart2::XAxis
> xAxis
= getAxisFromDoc(xChartDoc
, 0, 0, 0);
78 CPPUNIT_ASSERT(xAxis
.is());
80 chart2::ScaleData aScaleData1
= xAxis
->getScaleData();
81 CPPUNIT_ASSERT(aScaleData1
.Categories
.is());
82 CPPUNIT_ASSERT(aScaleData1
.ShiftedCategoryPosition
);
85 xChartDoc
.set(getChartDocFromDrawImpress(1, 0), uno::UNO_QUERY
);
86 CPPUNIT_ASSERT(xChartDoc
.is());
88 xAxis
.set(getAxisFromDoc(xChartDoc
, 0, 0, 0));
89 CPPUNIT_ASSERT(xAxis
.is());
91 chart2::ScaleData aScaleData2
= xAxis
->getScaleData();
92 CPPUNIT_ASSERT(aScaleData2
.Categories
.is());
93 CPPUNIT_ASSERT(!aScaleData2
.ShiftedCategoryPosition
);
96 CPPUNIT_TEST_FIXTURE(Chart2ImportTest2
, testTdf128733
)
98 loadFromFile(u
"odt/tdf128733.odt");
100 Reference
<chart2::XChartDocument
> xChartDoc(getChartDocFromWriter(0), uno::UNO_QUERY
);
101 CPPUNIT_ASSERT(xChartDoc
.is());
102 // test secondary X axis ShiftedCategoryPosition value
103 Reference
<chart2::XAxis
> xAxis
= getAxisFromDoc(xChartDoc
, 0, 0, 1);
104 CPPUNIT_ASSERT(xAxis
.is());
106 chart2::ScaleData aScaleData
= xAxis
->getScaleData();
107 CPPUNIT_ASSERT(aScaleData
.Categories
.is());
108 CPPUNIT_ASSERT(aScaleData
.ShiftedCategoryPosition
);
111 CPPUNIT_TEST_FIXTURE(Chart2ImportTest2
, testTdf128432
)
113 loadFromFile(u
"ods/tdf128432.ods");
115 uno::Reference
<chart2::XChartDocument
> xChartDoc
= getChartDocFromSheet(0);
116 CPPUNIT_ASSERT(xChartDoc
.is());
118 Reference
<chart2::XAxis
> xAxis
= getAxisFromDoc(xChartDoc
, 0, 0, 0);
119 CPPUNIT_ASSERT(xAxis
.is());
121 chart2::ScaleData aScaleData
= xAxis
->getScaleData();
122 CPPUNIT_ASSERT(aScaleData
.Categories
.is());
123 CPPUNIT_ASSERT(aScaleData
.ShiftedCategoryPosition
);
126 CPPUNIT_TEST_FIXTURE(Chart2ImportTest2
, testTdf128627
)
128 loadFromFile(u
"xlsx/tdf128627.xlsx");
129 // Test ShiftedCategoryPosition for Radar Chart
130 uno::Reference
<chart2::XChartDocument
> xChartDoc
= getChartDocFromSheet(0);
131 CPPUNIT_ASSERT_MESSAGE("failed to load chart", xChartDoc
.is());
133 Reference
<chart2::XAxis
> xAxis
= getAxisFromDoc(xChartDoc
, 0, 0, 0);
134 CPPUNIT_ASSERT(xAxis
.is());
136 chart2::ScaleData aScaleData
= xAxis
->getScaleData();
137 CPPUNIT_ASSERT(aScaleData
.Categories
.is());
138 CPPUNIT_ASSERT(!aScaleData
.ShiftedCategoryPosition
);
141 CPPUNIT_TEST_FIXTURE(Chart2ImportTest2
, testTdf128634
)
143 loadFromFile(u
"xlsx/tdf128634.xlsx");
144 // Test ShiftedCategoryPosition for 3D Charts
145 uno::Reference
<chart2::XChartDocument
> xChartDoc
= getChartDocFromSheet(0);
146 CPPUNIT_ASSERT_MESSAGE("failed to load chart", xChartDoc
.is());
148 Reference
<chart2::XAxis
> xAxis
= getAxisFromDoc(xChartDoc
, 0, 0, 0);
149 CPPUNIT_ASSERT(xAxis
.is());
151 chart2::ScaleData aScaleData
= xAxis
->getScaleData();
152 CPPUNIT_ASSERT(aScaleData
.Categories
.is());
153 CPPUNIT_ASSERT(aScaleData
.ShiftedCategoryPosition
);
156 CPPUNIT_TEST_FIXTURE(Chart2ImportTest2
, testTdf130657
)
158 loadFromFile(u
"xlsx/tdf130657.xlsx");
159 // Test ShiftedCategoryPosition for charts which is not contain a "crossbetween" OOXML tag.
160 uno::Reference
<chart2::XChartDocument
> xChartDoc
= getChartDocFromSheet(0);
161 CPPUNIT_ASSERT_MESSAGE("failed to load chart", xChartDoc
.is());
163 Reference
<chart2::XAxis
> xAxis
= getAxisFromDoc(xChartDoc
, 0, 0, 0);
164 CPPUNIT_ASSERT(xAxis
.is());
166 chart2::ScaleData aScaleData
= xAxis
->getScaleData();
167 CPPUNIT_ASSERT(aScaleData
.Categories
.is());
168 CPPUNIT_ASSERT(aScaleData
.ShiftedCategoryPosition
);
173 void checkDataLabelProperties(const Reference
<chart2::XDataSeries
>& xDataSeries
,
174 sal_Int32 nDataPointIndex
, bool bValueVisible
)
176 uno::Reference
<beans::XPropertySet
> xPropertySet(
177 xDataSeries
->getDataPointByIndex(nDataPointIndex
), uno::UNO_SET_THROW
);
178 chart2::DataPointLabel aLabel
;
179 xPropertySet
->getPropertyValue(u
"Label"_ustr
) >>= aLabel
;
180 CPPUNIT_ASSERT_EQUAL(bValueVisible
, static_cast<bool>(aLabel
.ShowNumber
));
181 CPPUNIT_ASSERT_EQUAL(false, static_cast<bool>(aLabel
.ShowNumberInPercent
));
185 CPPUNIT_TEST_FIXTURE(Chart2ImportTest2
, testDeletedDataLabel
)
187 loadFromFile(u
"xlsx/deleted_data_labels.xlsx");
188 uno::Reference
<chart2::XChartDocument
> xChartDoc(getChartCompFromSheet(0, 0), UNO_QUERY_THROW
);
189 Reference
<chart2::XDataSeries
> xDataSeries0
= getDataSeriesFromDoc(xChartDoc
, 0);
190 CPPUNIT_ASSERT(xDataSeries0
.is());
191 checkDataLabelProperties(xDataSeries0
, 0, true);
192 checkDataLabelProperties(xDataSeries0
, 1, false);
193 checkDataLabelProperties(xDataSeries0
, 2, true);
194 Reference
<chart2::XDataSeries
> xDataSeries1
= getDataSeriesFromDoc(xChartDoc
, 1);
195 CPPUNIT_ASSERT(xDataSeries1
.is());
196 checkDataLabelProperties(xDataSeries1
, 0, false);
197 checkDataLabelProperties(xDataSeries1
, 1, false);
198 checkDataLabelProperties(xDataSeries1
, 2, false);
201 CPPUNIT_TEST_FIXTURE(Chart2ImportTest2
, testDataPointInheritedColorDOCX
)
203 loadFromFile(u
"docx/data_point_inherited_color.docx");
204 uno::Reference
<chart2::XChartDocument
> xChartDoc(getChartDocFromWriter(0), uno::UNO_QUERY
);
205 CPPUNIT_ASSERT(xChartDoc
.is());
206 css::uno::Reference
<chart2::XDiagram
> xDiagram(xChartDoc
->getFirstDiagram(), UNO_SET_THROW
);
208 Reference
<chart2::XDataSeries
> xDataSeries
= getDataSeriesFromDoc(xChartDoc
, 0);
209 uno::Reference
<beans::XPropertySet
> xPropertySet(xDataSeries
->getDataPointByIndex(0),
211 CPPUNIT_ASSERT(xPropertySet
.is());
212 sal_Int32 nColor
= xPropertySet
->getPropertyValue(u
"FillColor"_ustr
).get
<sal_Int32
>();
213 CPPUNIT_ASSERT_EQUAL(sal_Int32(16776960), nColor
);
216 CPPUNIT_TEST_FIXTURE(Chart2ImportTest2
, testExternalStrRefsXLSX
)
218 loadFromFile(u
"xlsx/external_str_ref.xlsx");
219 uno::Reference
<chart2::XChartDocument
> xChartDoc(getChartCompFromSheet(0, 0), UNO_QUERY_THROW
);
220 CPPUNIT_ASSERT(xChartDoc
.is());
222 Reference
<chart2::XAxis
> xAxis
= getAxisFromDoc(xChartDoc
, 0, 0, 0);
223 chart2::ScaleData aScaleData
= xAxis
->getScaleData();
224 css::uno::Sequence
<css::uno::Any
> aValues
= aScaleData
.Categories
->getValues()->getData();
225 CPPUNIT_ASSERT_EQUAL(u
"test1"_ustr
, aValues
[0].get
<OUString
>());
226 CPPUNIT_ASSERT_EQUAL(u
"test2"_ustr
, aValues
[1].get
<OUString
>());
229 CPPUNIT_TEST_FIXTURE(Chart2ImportTest2
, testSourceNumberFormatComplexCategoriesXLS
)
231 loadFromFile(u
"xls/source_number_format_axis.xls");
232 uno::Reference
<chart2::XChartDocument
> xChartDoc(getChartCompFromSheet(0, 0), UNO_QUERY_THROW
);
233 CPPUNIT_ASSERT(xChartDoc
.is());
235 Reference
<chart2::XAxis
> xAxis
= getAxisFromDoc(xChartDoc
, 0, 0, 0);
236 chart2::ScaleData aScaleData
= xAxis
->getScaleData();
237 sal_Int32 nNumberFormat
= aScaleData
.Categories
->getValues()->getNumberFormatKeyByIndex(-1);
238 CPPUNIT_ASSERT(nNumberFormat
!= 0);
241 CPPUNIT_TEST_FIXTURE(Chart2ImportTest2
, testSimpleCategoryAxis
)
243 loadFromFile(u
"docx/testSimpleCategoryAxis.docx");
244 uno::Reference
<chart2::XChartDocument
> xChartDoc(getChartDocFromWriter(0), uno::UNO_QUERY
);
245 CPPUNIT_ASSERT(xChartDoc
.is());
247 // Test the internal data.
248 CPPUNIT_ASSERT(xChartDoc
->hasInternalDataProvider());
250 Reference
<chart2::XInternalDataProvider
> xInternalProvider(xChartDoc
->getDataProvider(),
252 CPPUNIT_ASSERT(xInternalProvider
.is());
254 Reference
<chart::XComplexDescriptionAccess
> xDescAccess(xInternalProvider
, uno::UNO_QUERY
);
255 CPPUNIT_ASSERT(xDescAccess
.is());
257 // Get the category labels.
258 Sequence
<Sequence
<OUString
>> aCategories
= xDescAccess
->getComplexRowDescriptions();
259 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aCategories
[0].getLength());
260 CPPUNIT_ASSERT(aCategories
[0][0].endsWith("ria 1"));
261 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aCategories
[1].getLength());
262 CPPUNIT_ASSERT(aCategories
[1][0].endsWith("ria 2"));
263 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aCategories
[2].getLength());
264 CPPUNIT_ASSERT(aCategories
[2][0].endsWith("ria 3"));
265 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aCategories
[3].getLength());
266 CPPUNIT_ASSERT(aCategories
[3][0].endsWith("ria 4"));
269 CPPUNIT_TEST_FIXTURE(Chart2ImportTest2
, testMultilevelCategoryAxis
)
271 loadFromFile(u
"docx/testMultilevelCategoryAxis.docx");
272 uno::Reference
<chart2::XChartDocument
> xChartDoc(getChartDocFromWriter(0), uno::UNO_QUERY
);
273 CPPUNIT_ASSERT(xChartDoc
.is());
275 // Test the internal data.
276 CPPUNIT_ASSERT(xChartDoc
->hasInternalDataProvider());
278 Reference
<chart2::XInternalDataProvider
> xInternalProvider(xChartDoc
->getDataProvider(),
280 CPPUNIT_ASSERT(xInternalProvider
.is());
282 Reference
<chart::XComplexDescriptionAccess
> xDescAccess(xInternalProvider
, uno::UNO_QUERY
);
283 CPPUNIT_ASSERT(xDescAccess
.is());
285 // Get the complex category labels.
286 Sequence
<Sequence
<OUString
>> aCategories
= xDescAccess
->getComplexRowDescriptions();
287 CPPUNIT_ASSERT_EQUAL(sal_Int32(4), aCategories
.getLength());
288 CPPUNIT_ASSERT_EQUAL(u
"2011"_ustr
, aCategories
[0][0]);
289 CPPUNIT_ASSERT_EQUAL(u
""_ustr
, aCategories
[1][0]);
290 CPPUNIT_ASSERT_EQUAL(u
"2012"_ustr
, aCategories
[2][0]);
291 CPPUNIT_ASSERT_EQUAL(u
""_ustr
, aCategories
[3][0]);
292 CPPUNIT_ASSERT_EQUAL(u
"Categoria 1"_ustr
, aCategories
[0][1]);
293 CPPUNIT_ASSERT_EQUAL(u
"Categoria 2"_ustr
, aCategories
[1][1]);
294 CPPUNIT_ASSERT_EQUAL(u
"Categoria 3"_ustr
, aCategories
[2][1]);
295 CPPUNIT_ASSERT_EQUAL(u
"Categoria 4"_ustr
, aCategories
[3][1]);
298 CPPUNIT_TEST_FIXTURE(Chart2ImportTest2
, testXaxisValues
)
300 loadFromFile(u
"docx/tdf124083.docx");
301 uno::Reference
<chart2::XChartDocument
> xChartDoc(getChartDocFromWriter(0), uno::UNO_QUERY
);
302 CPPUNIT_ASSERT(xChartDoc
.is());
304 const uno::Reference
<chart2::data::XDataSequence
> xDataSeq
305 = getDataSequenceFromDocByRole(xChartDoc
, u
"values-x");
306 Sequence
<uno::Any
> xSequence
= xDataSeq
->getData();
308 CPPUNIT_ASSERT_EQUAL(uno::Any(0.04), xSequence
[0]);
309 CPPUNIT_ASSERT(std::isnan(*static_cast<const double*>(xSequence
[1].getValue())));
310 CPPUNIT_ASSERT_EQUAL(uno::Any(0.16), xSequence
[2]);
311 CPPUNIT_ASSERT_EQUAL(uno::Any(0.11), xSequence
[3]);
312 CPPUNIT_ASSERT(std::isnan(*static_cast<const double*>(xSequence
[4].getValue())));
315 CPPUNIT_TEST_FIXTURE(Chart2ImportTest2
, testTdf123504
)
317 loadFromFile(u
"ods/pie_chart_100_and_0.ods");
318 Reference
<chart::XChartDocument
> xChartDoc(getChartDocFromSheet(0), UNO_QUERY_THROW
);
320 Reference
<chart2::XChartDocument
> xChartDoc2(xChartDoc
, UNO_QUERY_THROW
);
321 Reference
<chart2::XChartType
> xChartType(getChartTypeFromDoc(xChartDoc2
, 0), UNO_SET_THROW
);
322 std::vector aDataSeriesYValues
= getDataSeriesYValuesFromChartType(xChartType
);
323 CPPUNIT_ASSERT_EQUAL(size_t(1), aDataSeriesYValues
.size());
325 Reference
<drawing::XDrawPageSupplier
> xDrawPageSupplier(xChartDoc
, UNO_QUERY_THROW
);
326 Reference
<drawing::XDrawPage
> xDrawPage(xDrawPageSupplier
->getDrawPage(), UNO_SET_THROW
);
327 Reference
<drawing::XShapes
> xShapes(xDrawPage
->getByIndex(0), UNO_QUERY_THROW
);
328 Reference
<drawing::XShape
> xSeriesSlices(
329 getShapeByName(xShapes
, u
"CID/D=0:CS=0:CT=0:Series=0"_ustr
), UNO_SET_THROW
);
331 Reference
<container::XIndexAccess
> xIndexAccess(xSeriesSlices
, UNO_QUERY_THROW
);
332 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess
->getCount());
333 Reference
<drawing::XShape
> xSlice(xIndexAccess
->getByIndex(0), UNO_QUERY_THROW
);
335 // Check size and position of the only slice in the chart (100%)
336 // In the regressed state, it used to be 0-sized at position 0,0
337 awt::Point aSlicePosition
= xSlice
->getPosition();
338 CPPUNIT_ASSERT_GREATER(sal_Int32(3000), aSlicePosition
.X
);
339 CPPUNIT_ASSERT_GREATER(sal_Int32(150), aSlicePosition
.Y
);
340 awt::Size aSliceSize
= xSlice
->getSize();
341 CPPUNIT_ASSERT_DOUBLES_EQUAL(8300.0, aSliceSize
.Height
, 10);
342 CPPUNIT_ASSERT_DOUBLES_EQUAL(8300.0, aSliceSize
.Width
, 10);
345 CPPUNIT_TEST_FIXTURE(Chart2ImportTest2
, testTdf122765
)
347 // The horizontal position of the slices was wrong.
348 loadFromFile(u
"pptx/tdf122765.pptx");
349 Reference
<chart::XChartDocument
> xChartDoc
= getChartDocFromDrawImpress(0, 0);
350 Reference
<drawing::XDrawPageSupplier
> xDrawPageSupplier(xChartDoc
, UNO_QUERY_THROW
);
351 Reference
<drawing::XDrawPage
> xDrawPage(xDrawPageSupplier
->getDrawPage(), UNO_SET_THROW
);
352 Reference
<drawing::XShapes
> xShapes(xDrawPage
->getByIndex(0), UNO_QUERY_THROW
);
353 Reference
<drawing::XShape
> xSeriesSlices(
354 getShapeByName(xShapes
, u
"CID/D=0:CS=0:CT=0:Series=0"_ustr
), UNO_SET_THROW
);
356 Reference
<container::XIndexAccess
> xIndexAccess(xSeriesSlices
, UNO_QUERY_THROW
);
357 CPPUNIT_ASSERT_EQUAL(sal_Int32(9), xIndexAccess
->getCount());
358 Reference
<drawing::XShape
> xSlice(xIndexAccess
->getByIndex(0), UNO_QUERY_THROW
);
360 // Check position of the first slice, all slices move together, so enough to check only one.
361 // Wrong position was around 5856.
362 awt::Point aSlicePosition
= xSlice
->getPosition();
363 CPPUNIT_ASSERT_GREATER(sal_Int32(7000), aSlicePosition
.X
);
366 CPPUNIT_TEST_FIXTURE(Chart2ImportTest2
, testTdf123206CustomLabelField
)
368 // File contains the deprecated "custom-label-field" attribute of the
369 // "data-point" element. It should be interpreted and stored as a data point
371 loadFromFile(u
"odp/tdf123206.odp");
372 uno::Reference
<chart2::XChartDocument
> xChartDoc(getChartDocFromDrawImpress(0, 0),
373 uno::UNO_QUERY_THROW
);
374 CPPUNIT_ASSERT_MESSAGE("failed to load chart", xChartDoc
.is());
375 CPPUNIT_ASSERT(xChartDoc
.is());
376 Reference
<chart2::XDataSeries
> xDataSeries
= getDataSeriesFromDoc(xChartDoc
, 0);
377 CPPUNIT_ASSERT(xDataSeries
.is());
378 Reference
<beans::XPropertySet
> xDp
= xDataSeries
->getDataPointByIndex(1);
379 Sequence
<Reference
<chart2::XDataPointCustomLabelField
>> aLabelFields
;
380 CPPUNIT_ASSERT(xDp
->getPropertyValue(u
"CustomLabelFields"_ustr
) >>= aLabelFields
);
381 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32
>(1), aLabelFields
.getLength());
382 CPPUNIT_ASSERT_EQUAL(u
"Kiskacsa"_ustr
, aLabelFields
[0]->getString());
385 CPPUNIT_TEST_FIXTURE(Chart2ImportTest2
, testTdf125444PercentageCustomLabel
)
387 loadFromFile(u
"pptx/tdf125444.pptx");
390 Reference
<chart2::XChartDocument
> xChartDoc(getChartDocFromDrawImpress(0, 0), uno::UNO_QUERY
);
391 CPPUNIT_ASSERT(xChartDoc
.is());
393 uno::Reference
<chart2::XDataSeries
> xDataSeries(getDataSeriesFromDoc(xChartDoc
, 0));
394 CPPUNIT_ASSERT(xDataSeries
.is());
395 Reference
<beans::XPropertySet
> xDp
= xDataSeries
->getDataPointByIndex(1);
396 Sequence
<Reference
<chart2::XDataPointCustomLabelField
>> aLabelFields
;
397 CPPUNIT_ASSERT(xDp
->getPropertyValue(u
"CustomLabelFields"_ustr
) >>= aLabelFields
);
398 // There are three label field: a value label, a newline and a percentage label. We want
399 // to assert the latter.
400 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32
>(3), aLabelFields
.getLength());
401 CPPUNIT_ASSERT_EQUAL(chart2::DataPointCustomLabelFieldType_PERCENTAGE
,
402 aLabelFields
[2]->getFieldType());
405 CPPUNIT_TEST_FIXTURE(Chart2ImportTest2
, testDataPointLabelCustomPos
)
407 // test CustomLabelPosition on Bar chart
408 loadFromFile(u
"xlsx/testDataPointLabelCustomPos.xlsx");
409 uno::Reference
<chart2::XChartDocument
> xChartDoc
= getChartDocFromSheet(0);
410 CPPUNIT_ASSERT(xChartDoc
.is());
411 uno::Reference
<chart2::XDataSeries
> xDataSeries(getDataSeriesFromDoc(xChartDoc
, 0));
412 CPPUNIT_ASSERT(xDataSeries
.is());
414 uno::Reference
<beans::XPropertySet
> xPropertySet(xDataSeries
->getDataPointByIndex(0),
416 CPPUNIT_ASSERT(xPropertySet
.is());
418 chart2::RelativePosition aCustomLabelPosition
;
419 xPropertySet
->getPropertyValue(u
"CustomLabelPosition"_ustr
) >>= aCustomLabelPosition
;
420 CPPUNIT_ASSERT_DOUBLES_EQUAL(-0.14621409921671025, aCustomLabelPosition
.Primary
, 1e-7);
421 CPPUNIT_ASSERT_DOUBLES_EQUAL(-5.2887961029923464E-2, aCustomLabelPosition
.Secondary
, 1e-7);
423 sal_Int32 aPlacement
;
424 xPropertySet
->getPropertyValue(u
"LabelPlacement"_ustr
) >>= aPlacement
;
425 CPPUNIT_ASSERT_EQUAL(chart::DataLabelPlacement::OUTSIDE
, aPlacement
);
428 CPPUNIT_TEST_FIXTURE(Chart2ImportTest2
, testTdf130032
)
430 // test CustomLabelPosition on Line chart
431 loadFromFile(u
"xlsx/testTdf130032.xlsx");
432 uno::Reference
<chart2::XChartDocument
> xChartDoc
= getChartDocFromSheet(0);
433 CPPUNIT_ASSERT(xChartDoc
.is());
434 uno::Reference
<chart2::XDataSeries
> xDataSeries(getDataSeriesFromDoc(xChartDoc
, 0));
435 CPPUNIT_ASSERT(xDataSeries
.is());
437 uno::Reference
<beans::XPropertySet
> xPropertySet(xDataSeries
->getDataPointByIndex(1),
439 CPPUNIT_ASSERT(xPropertySet
.is());
441 chart2::RelativePosition aCustomLabelPosition
;
442 xPropertySet
->getPropertyValue(u
"CustomLabelPosition"_ustr
) >>= aCustomLabelPosition
;
443 CPPUNIT_ASSERT_DOUBLES_EQUAL(-0.0438333333333334, aCustomLabelPosition
.Primary
, 1e-7);
444 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.086794050743657, aCustomLabelPosition
.Secondary
, 1e-7);
446 sal_Int32 aPlacement
;
447 xPropertySet
->getPropertyValue(u
"LabelPlacement"_ustr
) >>= aPlacement
;
448 CPPUNIT_ASSERT_EQUAL(chart::DataLabelPlacement::RIGHT
, aPlacement
);
451 CPPUNIT_TEST_FIXTURE(Chart2ImportTest2
, testTdf134978
)
453 // test CustomLabelPosition on Pie chart
454 loadFromFile(u
"xlsx/tdf134978.xlsx");
455 uno::Reference
<chart2::XChartDocument
> xChartDoc
= getChartDocFromSheet(0);
456 CPPUNIT_ASSERT(xChartDoc
.is());
457 uno::Reference
<chart2::XDataSeries
> xDataSeries(getDataSeriesFromDoc(xChartDoc
, 0));
458 CPPUNIT_ASSERT(xDataSeries
.is());
460 uno::Reference
<beans::XPropertySet
> xPropertySet(xDataSeries
->getDataPointByIndex(2),
462 CPPUNIT_ASSERT(xPropertySet
.is());
464 chart2::RelativePosition aCustomLabelPosition
;
465 xPropertySet
->getPropertyValue(u
"CustomLabelPosition"_ustr
) >>= aCustomLabelPosition
;
466 CPPUNIT_ASSERT_DOUBLES_EQUAL(-0.040273622047244093, aCustomLabelPosition
.Primary
, 1e-7);
467 CPPUNIT_ASSERT_DOUBLES_EQUAL(-0.25635352872557599, aCustomLabelPosition
.Secondary
, 1e-7);
470 CPPUNIT_TEST_FIXTURE(Chart2ImportTest2
, testTdf119138MissingAutoTitleDeleted
)
472 loadFromFile(u
"xlsx/tdf119138-missing-autotitledeleted.xlsx");
473 Reference
<chart2::XChartDocument
> xChartDoc
= getChartDocFromSheet(0);
474 CPPUNIT_ASSERT_MESSAGE("failed to load chart", xChartDoc
.is());
476 Reference
<chart2::XTitled
> xTitled(xChartDoc
, uno::UNO_QUERY_THROW
);
477 uno::Reference
<chart2::XTitle
> xTitle
= xTitled
->getTitleObject();
478 CPPUNIT_ASSERT_MESSAGE(
479 "Missing autoTitleDeleted is implied to be True if title text is present", xTitle
.is());
482 CPPUNIT_TEST_FIXTURE(Chart2ImportTest2
, testStockChartShiftedCategoryPosition
)
484 loadFromFile(u
"odt/stock_chart_LO_6_2.odt");
486 uno::Reference
<chart2::XChartDocument
> xChartDoc(getChartDocFromWriter(0), uno::UNO_QUERY
);
487 CPPUNIT_ASSERT(xChartDoc
.is());
489 Reference
<chart2::XAxis
> xAxis
= getAxisFromDoc(xChartDoc
, 0, 0, 0);
490 CPPUNIT_ASSERT(xAxis
.is());
492 chart2::ScaleData aScaleData
= xAxis
->getScaleData();
493 CPPUNIT_ASSERT(aScaleData
.Categories
.is());
494 CPPUNIT_ASSERT(aScaleData
.ShiftedCategoryPosition
);
497 CPPUNIT_TEST_FIXTURE(Chart2ImportTest2
, testTdf133376
)
499 // FIXME: the DPI check should be removed when either (1) the test is fixed to work with
500 // non-default DPI; or (2) unit tests on Windows are made to use svp VCL plugin.
504 loadFromFile(u
"xlsx/tdf133376.xlsx");
505 Reference
<chart::XChartDocument
> xChartDoc(getChartDocFromSheet(0), UNO_QUERY_THROW
);
507 Reference
<drawing::XDrawPageSupplier
> xDrawPageSupplier(xChartDoc
, UNO_QUERY_THROW
);
508 Reference
<drawing::XDrawPage
> xDrawPage(xDrawPageSupplier
->getDrawPage(), UNO_SET_THROW
);
509 Reference
<drawing::XShapes
> xShapes(xDrawPage
->getByIndex(0), UNO_QUERY_THROW
);
510 Reference
<drawing::XShape
> xDataPointLabel(
511 getShapeByName(xShapes
,
512 u
"CID/MultiClick/CID/D=0:CS=0:CT=0:Series=0:DataLabels=:DataLabel=2"_ustr
),
515 CPPUNIT_ASSERT(xDataPointLabel
.is());
516 // Check the position of the 3rd data point label, which is out from the pie slice
517 awt::Point aLabelPosition
= xDataPointLabel
->getPosition();
518 CPPUNIT_ASSERT_DOUBLES_EQUAL(1624, aLabelPosition
.X
, 30);
519 CPPUNIT_ASSERT_DOUBLES_EQUAL(5635, aLabelPosition
.Y
, 30);
522 CPPUNIT_TEST_FIXTURE(Chart2ImportTest2
, testTdf134225
)
524 loadFromFile(u
"xlsx/tdf134225.xlsx");
525 Reference
<chart::XChartDocument
> xChartDoc(getChartDocFromSheet(0), UNO_QUERY_THROW
);
527 Reference
<drawing::XDrawPageSupplier
> xDrawPageSupplier(xChartDoc
, UNO_QUERY_THROW
);
528 Reference
<drawing::XDrawPage
> xDrawPage(xDrawPageSupplier
->getDrawPage(), UNO_SET_THROW
);
529 Reference
<drawing::XShapes
> xShapes(xDrawPage
->getByIndex(0), UNO_QUERY_THROW
);
530 Reference
<drawing::XShape
> xDataPointLabel1(
531 getShapeByName(xShapes
,
532 u
"CID/MultiClick/CID/D=0:CS=0:CT=0:Series=0:DataLabels=:DataLabel=0"_ustr
),
534 CPPUNIT_ASSERT(xDataPointLabel1
.is());
536 Reference
<drawing::XShape
> xDataPointLabel2(
537 getShapeByName(xShapes
,
538 u
"CID/MultiClick/CID/D=0:CS=0:CT=0:Series=0:DataLabels=:DataLabel=1"_ustr
),
540 CPPUNIT_ASSERT(xDataPointLabel2
.is());
543 // font is MS Comic Sans which we can only assume is available under windows
544 awt::Point aLabelPosition1
= xDataPointLabel1
->getPosition();
545 awt::Point aLabelPosition2
= xDataPointLabel2
->getPosition();
547 // Check the distance between the position of the 1st data point label and the second one
548 CPPUNIT_ASSERT_DOUBLES_EQUAL(1493, sal_Int32(aLabelPosition2
.X
- aLabelPosition1
.X
), 30);
549 CPPUNIT_ASSERT_DOUBLES_EQUAL(2015, sal_Int32(aLabelPosition2
.Y
- aLabelPosition1
.Y
), 30);
553 CPPUNIT_TEST_FIXTURE(Chart2ImportTest2
, testTdf136105
)
555 // FIXME: the DPI check should be removed when either (1) the test is fixed to work with
556 // non-default DPI; or (2) unit tests on Windows are made to use svp VCL plugin.
560 loadFromFile(u
"xlsx/tdf136105.xlsx");
561 // 1st chart with fix inner position and size
563 Reference
<chart::XChartDocument
> xChartDoc(getChartDocFromSheet(0), UNO_QUERY_THROW
);
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(
570 xShapes
, u
"CID/MultiClick/CID/D=0:CS=0:CT=0:Series=0:DataLabels=:DataLabel=0"_ustr
),
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), UNO_QUERY_THROW
);
583 Reference
<drawing::XDrawPageSupplier
> xDrawPageSupplier(xChartDoc
, UNO_QUERY_THROW
);
584 Reference
<drawing::XDrawPage
> xDrawPage(xDrawPageSupplier
->getDrawPage(), UNO_SET_THROW
);
585 Reference
<drawing::XShapes
> xShapes(xDrawPage
->getByIndex(0), UNO_QUERY_THROW
);
586 Reference
<drawing::XShape
> xDataPointLabel(
588 xShapes
, u
"CID/MultiClick/CID/D=0:CS=0:CT=0:Series=0:DataLabels=:DataLabel=0"_ustr
),
591 CPPUNIT_ASSERT(xDataPointLabel
.is());
592 // Check the position of the 1st data point label, which is out from the pie slice
593 awt::Point aLabelPosition
= xDataPointLabel
->getPosition();
594 CPPUNIT_ASSERT_DOUBLES_EQUAL(7978, aLabelPosition
.X
, 500);
595 CPPUNIT_ASSERT_DOUBLES_EQUAL(1550, aLabelPosition
.Y
, 500);
599 CPPUNIT_TEST_FIXTURE(Chart2ImportTest2
, testTdf91250
)
601 loadFromFile(u
"docx/tdf91250.docx");
602 uno::Reference
<chart2::XChartDocument
> xChartDoc(getChartDocFromWriter(0), uno::UNO_QUERY
);
603 CPPUNIT_ASSERT(xChartDoc
.is());
604 Reference
<chart2::XInternalDataProvider
> xInternalProvider(xChartDoc
->getDataProvider(),
606 CPPUNIT_ASSERT(xInternalProvider
.is());
608 Reference
<chart::XComplexDescriptionAccess
> xDescAccess(xInternalProvider
, uno::UNO_QUERY
);
609 CPPUNIT_ASSERT(xDescAccess
.is());
611 // Get the category labels.
612 Sequence
<OUString
> aCategories
= xDescAccess
->getRowDescriptions();
613 CPPUNIT_ASSERT_EQUAL(sal_Int32(4), aCategories
.getLength());
614 CPPUNIT_ASSERT_EQUAL(u
"12.3254"_ustr
, aCategories
[0]);
615 CPPUNIT_ASSERT_EQUAL(u
"11.62315"_ustr
, aCategories
[1]);
616 CPPUNIT_ASSERT_EQUAL(u
"9.26"_ustr
, aCategories
[2]);
617 CPPUNIT_ASSERT_EQUAL(u
"8.657"_ustr
, aCategories
[3]);
620 CPPUNIT_TEST_FIXTURE(Chart2ImportTest2
, testTdf134111
)
622 // tdf134111 : To check TextBreak value is true
623 loadFromFile(u
"docx/tdf134111.docx");
624 uno::Reference
<chart::XChartDocument
> xChartDoc
= getChartDocFromWriter(0);
625 CPPUNIT_ASSERT_MESSAGE("failed to load chart", xChartDoc
.is());
626 uno::Reference
<chart::XDiagram
> mxDiagram(xChartDoc
->getDiagram());
627 CPPUNIT_ASSERT(mxDiagram
.is());
628 uno::Reference
<chart::XAxisXSupplier
> xAxisXSupp(mxDiagram
, uno::UNO_QUERY
);
629 CPPUNIT_ASSERT(xAxisXSupp
.is());
630 uno::Reference
<beans::XPropertySet
> xAxisProp(xAxisXSupp
->getXAxis());
631 bool bTextBreak
= false;
632 xAxisProp
->getPropertyValue(u
"TextBreak"_ustr
) >>= bTextBreak
;
633 // Expected value of 'TextBreak' is true
634 CPPUNIT_ASSERT(bTextBreak
);
637 CPPUNIT_TEST_FIXTURE(Chart2ImportTest2
, testTdf136752
)
639 loadFromFile(u
"xlsx/tdf136752.xlsx");
640 Reference
<chart::XChartDocument
> xChartDoc(getChartDocFromSheet(0), UNO_QUERY_THROW
);
642 Reference
<drawing::XDrawPageSupplier
> xDrawPageSupplier(xChartDoc
, UNO_QUERY_THROW
);
643 Reference
<drawing::XDrawPage
> xDrawPage(xDrawPageSupplier
->getDrawPage(), UNO_SET_THROW
);
644 Reference
<drawing::XShapes
> xShapes(xDrawPage
->getByIndex(0), UNO_QUERY_THROW
);
645 Reference
<drawing::XShape
> xDataPointLabel(
646 getShapeByName(xShapes
,
647 u
"CID/MultiClick/CID/D=0:CS=0:CT=0:Series=0:DataLabels=:DataLabel=0"_ustr
),
650 CPPUNIT_ASSERT(xDataPointLabel
.is());
651 // Check the position of the 1st data point label, which is out from the pie slice
652 awt::Point aLabelPosition
= xDataPointLabel
->getPosition();
653 CPPUNIT_ASSERT_DOUBLES_EQUAL(8675, aLabelPosition
.X
, 500);
654 CPPUNIT_ASSERT_DOUBLES_EQUAL(1458, aLabelPosition
.Y
, 500);
657 CPPUNIT_TEST_FIXTURE(Chart2ImportTest2
, testTdf137505
)
659 loadFromFile(u
"xlsx/tdf137505.xlsx");
660 Reference
<chart::XChartDocument
> xChartDoc(getChartDocFromSheet(0), UNO_QUERY_THROW
);
662 Reference
<drawing::XDrawPageSupplier
> xDrawPageSupplier(xChartDoc
, UNO_QUERY_THROW
);
663 Reference
<drawing::XDrawPage
> xDrawPage(xDrawPageSupplier
->getDrawPage(), UNO_SET_THROW
);
664 Reference
<drawing::XShape
> xCustomShape(xDrawPage
->getByIndex(1), UNO_QUERY_THROW
);
665 CPPUNIT_ASSERT(xCustomShape
.is());
668 Reference
<text::XText
> xRange(xCustomShape
, uno::UNO_QUERY_THROW
);
669 Reference
<text::XTextCursor
> xAt
= xRange
->createTextCursor();
670 Reference
<beans::XPropertySet
> xProps(xAt
, UNO_QUERY
);
671 // check the text size of custom shape, inside the chart.
672 CPPUNIT_ASSERT(xProps
->getPropertyValue(u
"CharHeight"_ustr
) >>= nFontSize
);
673 CPPUNIT_ASSERT_EQUAL(float(12), nFontSize
);
676 CPPUNIT_TEST_FIXTURE(Chart2ImportTest2
, testTdf137734
)
678 loadFromFile(u
"xlsx/tdf137734.xlsx");
679 Reference
<chart2::XChartDocument
> xChartDoc
= getChartDocFromSheet(0);
680 CPPUNIT_ASSERT_MESSAGE("failed to load chart", xChartDoc
.is());
681 CPPUNIT_ASSERT(xChartDoc
.is());
682 Reference
<chart2::XDataSeries
> xDataSeries
= getDataSeriesFromDoc(xChartDoc
, 0);
683 CPPUNIT_ASSERT(xDataSeries
.is());
684 Reference
<beans::XPropertySet
> xPropSet(xDataSeries
, uno::UNO_QUERY_THROW
);
685 uno::Any aAny
= xPropSet
->getPropertyValue(u
"VaryColorsByPoint"_ustr
);
686 bool bVaryColor
= true;
687 CPPUNIT_ASSERT(aAny
>>= bVaryColor
);
688 CPPUNIT_ASSERT(!bVaryColor
);
690 // tdf#126133 Test primary X axis Rotation value
691 Reference
<chart2::XAxis
> xXAxis
= getAxisFromDoc(xChartDoc
, 0, 0, 0);
692 CPPUNIT_ASSERT(xXAxis
.is());
693 Reference
<chart2::XTitled
> xTitled(xXAxis
, uno::UNO_QUERY_THROW
);
694 Reference
<chart2::XTitle
> xTitle
= xTitled
->getTitleObject();
695 CPPUNIT_ASSERT(xTitle
.is());
696 Reference
<beans::XPropertySet
> xTitlePropSet(xTitle
, uno::UNO_QUERY_THROW
);
697 uno::Any aAny2
= xTitlePropSet
->getPropertyValue(u
"TextRotation"_ustr
);
698 double nRotation
= -1;
699 CPPUNIT_ASSERT(aAny2
>>= nRotation
);
700 CPPUNIT_ASSERT_EQUAL(0.0, nRotation
);
703 CPPUNIT_TEST_FIXTURE(Chart2ImportTest2
, testTdf137874
)
705 loadFromFile(u
"xlsx/piechart_legend.xlsx");
706 Reference
<chart::XChartDocument
> xChartDoc(getChartDocFromSheet(0), UNO_QUERY_THROW
);
707 Reference
<drawing::XDrawPageSupplier
> xDrawPageSupplier(xChartDoc
, UNO_QUERY_THROW
);
708 Reference
<drawing::XDrawPage
> xDrawPage(xDrawPageSupplier
->getDrawPage(), UNO_SET_THROW
);
709 Reference
<drawing::XShapes
> xShapes(xDrawPage
->getByIndex(0), UNO_QUERY_THROW
);
710 Reference
<drawing::XShape
> xLegendEntry
;
711 xLegendEntry
= getShapeByName(
712 xShapes
, u
"CID/MultiClick/D=0:CS=0:CT=0:Series=0:Point=0:LegendEntry=0"_ustr
);
713 CPPUNIT_ASSERT(xLegendEntry
.is());
716 CPPUNIT_TEST_FIXTURE(Chart2ImportTest2
, testTdf146463
)
718 loadFromFile(u
"ods/tdf146463.ods");
719 Reference
<chart2::XChartDocument
> xChartDoc(getChartDocFromSheet(0));
720 Reference
<drawing::XDrawPageSupplier
> xDrawPageSupplier(xChartDoc
, UNO_QUERY_THROW
);
721 Reference
<drawing::XDrawPage
> xDrawPage(xDrawPageSupplier
->getDrawPage(), UNO_SET_THROW
);
722 Reference
<drawing::XShapes
> xShapes(xDrawPage
->getByIndex(0), UNO_QUERY_THROW
);
723 Reference
<chart2::XChartType
> xChartType
= getChartTypeFromDoc(xChartDoc
, 0);
724 std::vector
<std::vector
<double>> aDataSeriesYValues
725 = getDataSeriesYValuesFromChartType(xChartType
);
726 size_t nLegendEntryCount
= aDataSeriesYValues
.size();
727 CPPUNIT_ASSERT_EQUAL(size_t(14), nLegendEntryCount
);
729 for (size_t nSeriesIndex
= 0; nSeriesIndex
< nLegendEntryCount
; ++nSeriesIndex
)
731 uno::Reference
<drawing::XShape
> xLegendEntry
732 = getShapeByName(xShapes
, "CID/MultiClick/D=0:CS=0:CT=0:Series="
733 + OUString::number(nSeriesIndex
) + ":LegendEntry=0");
734 if (nSeriesIndex
== 0)
735 CPPUNIT_ASSERT_MESSAGE("Legend 0 is not visible", xLegendEntry
.is());
737 CPPUNIT_ASSERT_MESSAGE(
738 OString("Legend " + OString::number(nSeriesIndex
) + " is visible").getStr(),
743 CPPUNIT_TEST_FIXTURE(Chart2ImportTest2
, testTdfCustomShapePos
)
745 loadFromFile(u
"docx/testcustomshapepos.docx");
746 Reference
<chart2::XChartDocument
> xChartDoc(getChartDocFromWriter(0), UNO_QUERY_THROW
);
747 Reference
<drawing::XDrawPageSupplier
> xDrawPageSupplier(xChartDoc
, UNO_QUERY_THROW
);
748 Reference
<drawing::XDrawPage
> xDrawPage(xDrawPageSupplier
->getDrawPage(), UNO_SET_THROW
);
749 // test position and size of a custom shape within a chart, rotated by 0 degree.
751 Reference
<drawing::XShape
> xCustomShape(xDrawPage
->getByIndex(0), UNO_QUERY_THROW
);
752 awt::Point aPosition
= xCustomShape
->getPosition();
753 CPPUNIT_ASSERT_DOUBLES_EQUAL(8845, aPosition
.X
, 300);
754 CPPUNIT_ASSERT_DOUBLES_EQUAL(855, aPosition
.Y
, 300);
755 awt::Size aSize
= xCustomShape
->getSize();
756 CPPUNIT_ASSERT_DOUBLES_EQUAL(4831, aSize
.Width
, 300);
757 CPPUNIT_ASSERT_DOUBLES_EQUAL(1550, aSize
.Height
, 300);
759 // test position and size of a custom shape within a chart, rotated by 90 degree.
761 Reference
<drawing::XShape
> xCustomShape(xDrawPage
->getByIndex(1), UNO_QUERY_THROW
);
762 awt::Point aPosition
= xCustomShape
->getPosition();
763 CPPUNIT_ASSERT_DOUBLES_EQUAL(1658, aPosition
.X
, 300);
764 CPPUNIT_ASSERT_DOUBLES_EQUAL(6119, aPosition
.Y
, 300);
765 awt::Size aSize
= xCustomShape
->getSize();
766 CPPUNIT_ASSERT_DOUBLES_EQUAL(4165, aSize
.Width
, 300);
767 CPPUNIT_ASSERT_DOUBLES_EQUAL(1334, aSize
.Height
, 300);
771 CPPUNIT_TEST_FIXTURE(Chart2ImportTest2
, testTdf121281
)
773 loadFromFile(u
"xlsx/incorrect_label_position.xlsx");
774 Reference
<chart::XChartDocument
> xChartDoc(getChartDocFromSheet(0), UNO_QUERY_THROW
);
775 Reference
<drawing::XDrawPageSupplier
> xDrawPageSupplier(xChartDoc
, UNO_QUERY_THROW
);
776 Reference
<drawing::XDrawPage
> xDrawPage(xDrawPageSupplier
->getDrawPage(), UNO_SET_THROW
);
777 Reference
<drawing::XShapes
> xShapes(xDrawPage
->getByIndex(0), UNO_QUERY_THROW
);
778 Reference
<drawing::XShape
> xDataPointLabel(
779 getShapeByName(xShapes
,
780 u
"CID/MultiClick/CID/D=0:CS=0:CT=0:Series=0:DataLabels=:DataLabel=0"_ustr
),
783 CPPUNIT_ASSERT(xDataPointLabel
.is());
784 awt::Point aLabelPosition
= xDataPointLabel
->getPosition();
785 // This failed, if the data label flowed out of the chart area.
786 CPPUNIT_ASSERT_GREATEREQUAL(static_cast<sal_Int32
>(0), aLabelPosition
.Y
);
789 CPPUNIT_TEST_FIXTURE(Chart2ImportTest2
, testTdf139658
)
791 loadFromFile(u
"docx/tdf139658.docx");
792 uno::Reference
<chart2::XChartDocument
> xChartDoc(getChartDocFromWriter(0), uno::UNO_QUERY
);
793 CPPUNIT_ASSERT(xChartDoc
.is());
794 Reference
<chart2::XInternalDataProvider
> xInternalProvider(xChartDoc
->getDataProvider(),
796 CPPUNIT_ASSERT(xInternalProvider
.is());
798 Reference
<chart::XComplexDescriptionAccess
> xDescAccess(xInternalProvider
, uno::UNO_QUERY
);
799 CPPUNIT_ASSERT(xDescAccess
.is());
801 // Get the category labels.
802 Sequence
<OUString
> aCategories
= xDescAccess
->getRowDescriptions();
803 CPPUNIT_ASSERT_EQUAL(sal_Int32(3), aCategories
.getLength());
804 CPPUNIT_ASSERT_EQUAL(u
"category1"_ustr
, aCategories
[0]);
805 CPPUNIT_ASSERT_EQUAL(u
"\"category2\""_ustr
, aCategories
[1]);
806 CPPUNIT_ASSERT_EQUAL(u
"category\"3"_ustr
, aCategories
[2]);
809 CPPUNIT_TEST_FIXTURE(Chart2ImportTest2
, testTdf146066
)
811 loadFromFile(u
"ods/tdf146066.ods");
812 Reference
<chart::XChartDocument
> xChartDoc(getChartDocFromSheet(0), UNO_QUERY_THROW
);
813 uno::Reference
<drawing::XDrawPageSupplier
> xDrawPageSupplier(xChartDoc
, uno::UNO_QUERY
);
814 uno::Reference
<drawing::XDrawPage
> xDrawPage
= xDrawPageSupplier
->getDrawPage();
815 uno::Reference
<drawing::XShapes
> xShapes(xDrawPage
->getByIndex(0), uno::UNO_QUERY
);
816 CPPUNIT_ASSERT(xShapes
.is());
818 uno::Reference
<drawing::XShape
> xYAxisShape
= getShapeByName(
819 xShapes
, u
"CID/D=0:CS=0:Axis=1,0"_ustr
, // Y Axis
820 // Axis occurs twice in chart xshape representation so need to get the one related to labels
821 [](const uno::Reference
<drawing::XShape
>& rXShape
) -> bool {
822 uno::Reference
<drawing::XShapes
> xAxisShapes(rXShape
, uno::UNO_QUERY
);
823 CPPUNIT_ASSERT(xAxisShapes
.is());
824 uno::Reference
<drawing::XShape
> xChildShape(xAxisShapes
->getByIndex(0), uno::UNO_QUERY
);
825 uno::Reference
<drawing::XShapeDescriptor
> xShapeDescriptor(xChildShape
,
826 uno::UNO_QUERY_THROW
);
827 return (xShapeDescriptor
->getShapeType() == "com.sun.star.drawing.TextShape");
829 CPPUNIT_ASSERT(xYAxisShape
.is());
832 uno::Reference
<container::XIndexAccess
> xIndexAccess(xYAxisShape
, UNO_QUERY_THROW
);
833 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32
>(8), xIndexAccess
->getCount());
836 uno::Reference
<text::XTextRange
> xLabel0(xIndexAccess
->getByIndex(0), uno::UNO_QUERY
);
837 CPPUNIT_ASSERT_EQUAL(u
"0"_ustr
, xLabel0
->getString());
838 uno::Reference
<text::XTextRange
> xLabel1(xIndexAccess
->getByIndex(1), uno::UNO_QUERY
);
839 CPPUNIT_ASSERT_EQUAL(u
"5"_ustr
, xLabel1
->getString());
840 uno::Reference
<text::XTextRange
> xLabel2(xIndexAccess
->getByIndex(2), uno::UNO_QUERY
);
841 CPPUNIT_ASSERT_EQUAL(u
"10"_ustr
, xLabel2
->getString());
842 uno::Reference
<text::XTextRange
> xLabel3(xIndexAccess
->getByIndex(3), uno::UNO_QUERY
);
843 CPPUNIT_ASSERT_EQUAL(u
"15"_ustr
, xLabel3
->getString());
844 uno::Reference
<text::XTextRange
> xLabel4(xIndexAccess
->getByIndex(4), uno::UNO_QUERY
);
845 CPPUNIT_ASSERT_EQUAL(u
"20"_ustr
, xLabel4
->getString());
846 uno::Reference
<text::XTextRange
> xLabel5(xIndexAccess
->getByIndex(5), uno::UNO_QUERY
);
847 CPPUNIT_ASSERT_EQUAL(u
"25"_ustr
, xLabel5
->getString());
848 uno::Reference
<text::XTextRange
> xLabel6(xIndexAccess
->getByIndex(6), uno::UNO_QUERY
);
849 CPPUNIT_ASSERT_EQUAL(u
"30"_ustr
, xLabel6
->getString());
850 uno::Reference
<text::XTextRange
> xLabel7(xIndexAccess
->getByIndex(7), uno::UNO_QUERY
);
851 CPPUNIT_ASSERT_EQUAL(u
"35"_ustr
, xLabel7
->getString());
854 CPPUNIT_TEST_FIXTURE(Chart2ImportTest2
, testTdf150434
)
856 loadFromFile(u
"xlsx/tdf150434.xlsx");
857 Reference
<chart::XChartDocument
> xChartDoc(getChartDocFromSheet(0), UNO_QUERY_THROW
);
858 Reference
<drawing::XDrawPageSupplier
> xDrawPageSupplier(xChartDoc
, UNO_QUERY_THROW
);
859 Reference
<drawing::XDrawPage
> xDrawPage(xDrawPageSupplier
->getDrawPage(), UNO_SET_THROW
);
860 Reference
<drawing::XShapes
> xShapes(xDrawPage
->getByIndex(0), UNO_QUERY_THROW
);
861 Reference
<drawing::XShape
> xLegend
= getShapeByName(xShapes
, u
"CID/D=0:Legend="_ustr
);
862 CPPUNIT_ASSERT(xLegend
.is());
863 awt::Point aPosition
= xLegend
->getPosition();
865 // This failed, if the legend flowed out of the chart area.
866 CPPUNIT_ASSERT_GREATEREQUAL(static_cast<sal_Int32
>(0), aPosition
.Y
);
869 CPPUNIT_TEST_FIXTURE(Chart2ImportTest2
, testChartDataTableWithMultipleLegendEntriesForOneDataSeries
)
871 loadFromFile(u
"xlsx/DataTable-MultipleLegendEntriesForOneDataSeries.xlsx");
872 // Loading this file caused a crash in the data table code
874 Reference
<chart::XChartDocument
> xChartDoc(getChartDocFromSheet(0), UNO_QUERY_THROW
);
875 Reference
<drawing::XDrawPageSupplier
> xDrawPageSupplier(xChartDoc
, UNO_QUERY_THROW
);
876 Reference
<drawing::XDrawPage
> xDrawPage(xDrawPageSupplier
->getDrawPage(), UNO_SET_THROW
);
877 Reference
<drawing::XShapes
> xShapes(xDrawPage
->getByIndex(0), UNO_QUERY_THROW
);
878 Reference
<drawing::XShape
> xDataTableShape
879 = getShapeByName(xShapes
, u
"CID/D=0:DataTable="_ustr
);
880 CPPUNIT_ASSERT(xDataTableShape
.is());
885 void lcl_assertAngles(const Reference
<chart2::XAxis
>& rAxis
, const double& rExpectedLabelAngle
,
886 const double& rExpectedTitleAngle
)
888 Reference
<beans::XPropertySet
> xPS(rAxis
, uno::UNO_QUERY_THROW
);
889 double fAxisLabelAngle
= 0.0;
890 xPS
->getPropertyValue(u
"TextRotation"_ustr
) >>= fAxisLabelAngle
;
891 CPPUNIT_ASSERT_DOUBLES_EQUAL(rExpectedLabelAngle
, fAxisLabelAngle
, 1e-10);
893 Reference
<chart2::XTitled
> xAxisTitled(rAxis
, uno::UNO_QUERY_THROW
);
894 Reference
<chart2::XTitle
> xAxisTitle
= xAxisTitled
->getTitleObject();
895 CPPUNIT_ASSERT(xAxisTitle
.is());
896 Reference
<beans::XPropertySet
> xPropSet(xAxisTitle
, uno::UNO_QUERY_THROW
);
897 double fAxisTitleAngle
= 0.0;
898 xPropSet
->getPropertyValue(u
"TextRotation"_ustr
) >>= fAxisTitleAngle
;
899 CPPUNIT_ASSERT_DOUBLES_EQUAL(rExpectedTitleAngle
, fAxisTitleAngle
, 1e-10);
903 CPPUNIT_TEST_FIXTURE(Chart2ImportTest2
, testAngleUnits
)
905 loadFromFile(u
"fods/tdf161483_AngleUnits.fods");
906 double fExpXAxisLabelAngle
= 344.61; // = 382.9grad = 6.01457913529766rad
907 double fExpXAxisTitleAngle
= 342.63; // = 380.7grad = 5.98002161610817rad
908 double fExpYAxisLabelAngle
= 15.12; // = 16.8grad = 0.263893782901543rad
909 double fExpYAxisTitleAngle
= 14.94; // = 16.6grad = 0.260752190247953rad
910 double fExpZAxisLabelAngle
= 344.16; // = 382.4grad = 6.00672515366369rad
911 double fExpZAxisTitleAngle
= 60.39; // = 67.1grad = 1.05400433527938rad
913 // sheet 0: no unit; sheet 1: unit deg; sheet 2: unit rad; sheet 3: unit grad
914 // Without fix, the values with unit grad and rad were read as if they are in degrees.
915 for (size_t i
= 0; i
< 4; i
++)
917 uno::Reference
<chart2::XChartDocument
> xChartDoc
= getChartDocFromSheet(i
);
918 CPPUNIT_ASSERT_MESSAGE("failed to load chart", xChartDoc
.is());
921 Reference
<chart2::XAxis
> xAxis
= getAxisFromDoc(xChartDoc
, 0, 0, 0);
922 CPPUNIT_ASSERT(xAxis
.is());
923 lcl_assertAngles(xAxis
, fExpXAxisLabelAngle
, fExpXAxisTitleAngle
);
926 xAxis
= getAxisFromDoc(xChartDoc
, 0, 1, 0);
927 CPPUNIT_ASSERT(xAxis
.is());
928 lcl_assertAngles(xAxis
, fExpYAxisLabelAngle
, fExpYAxisTitleAngle
);
931 xAxis
= getAxisFromDoc(xChartDoc
, 0, 2, 0);
932 CPPUNIT_ASSERT(xAxis
.is());
933 lcl_assertAngles(xAxis
, fExpZAxisLabelAngle
, fExpZAxisTitleAngle
);
937 CPPUNIT_PLUGIN_IMPLEMENT();
939 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */