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/CurveStyle.hpp>
12 #include <com/sun/star/chart2/DataPointLabel.hpp>
13 #include <com/sun/star/chart2/XDataPointCustomLabelField.hpp>
14 #include <com/sun/star/chart2/DataPointCustomLabelFieldType.hpp>
15 #include <com/sun/star/chart/ErrorBarStyle.hpp>
16 #include <com/sun/star/chart2/XRegressionCurveContainer.hpp>
17 #include <com/sun/star/chart2/XChartDocument.hpp>
18 #include <com/sun/star/chart/XChartDocument.hpp>
19 #include <com/sun/star/chart2/XInternalDataProvider.hpp>
20 #include <com/sun/star/chart/XChartDataArray.hpp>
21 #include <com/sun/star/drawing/FillStyle.hpp>
22 #include <com/sun/star/drawing/LineStyle.hpp>
23 #include <com/sun/star/chart/XAxisXSupplier.hpp>
24 #include <com/sun/star/chart/XAxisYSupplier.hpp>
25 #include <com/sun/star/chart/MissingValueTreatment.hpp>
26 #include <com/sun/star/chart2/TickmarkStyle.hpp>
27 #include <com/sun/star/chart2/SymbolStyle.hpp>
28 #include <com/sun/star/chart2/Symbol.hpp>
29 #include <com/sun/star/chart2/data/XTextualDataSequence.hpp>
30 #include <com/sun/star/chart/DataLabelPlacement.hpp>
31 #include <com/sun/star/text/XTextRange.hpp>
32 #include <com/sun/star/qa/XDumper.hpp>
35 #include <com/sun/star/util/Color.hpp>
36 #include <com/sun/star/awt/Gradient2.hpp>
37 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
38 #include <docmodel/uno/UnoGradientTools.hxx>
42 class Chart2ImportTest
: public ChartTest
45 Chart2ImportTest() : ChartTest(u
"/chart2/qa/extras/data/"_ustr
) {}
48 void testTransparentBackground(std::u16string_view filename
);
51 OUString
getShapeDump(css::uno::Reference
<css::chart::XChartDocument
> const& doc
)
53 return css::uno::Reference
<css::qa::XDumper
>(doc
, css::uno::UNO_QUERY_THROW
)->dump(u
"shapes"_ustr
);
56 sal_Int32
getNumberFormat( const Reference
<chart2::XChartDocument
>& xChartDoc
, const OUString
& sFormat
)
58 Reference
<util::XNumberFormatsSupplier
> xNFS(xChartDoc
, uno::UNO_QUERY_THROW
);
59 Reference
<util::XNumberFormats
> xNumberFormats
= xNFS
->getNumberFormats();
60 CPPUNIT_ASSERT(xNumberFormats
.is());
62 return xNumberFormats
->queryKey(sFormat
, css::lang::Locale(), false);
66 // split method up into smaller chunks for more detailed tests
67 CPPUNIT_TEST_FIXTURE(Chart2ImportTest
, testFdo60083
)
69 loadFromFile(u
"ods/fdo60083.ods");
70 uno::Reference
< chart2::XChartDocument
> xChartDoc
= getChartDocFromSheet( 0);
71 CPPUNIT_ASSERT(xChartDoc
.is());
73 Reference
< chart2::XDataSeries
> xDataSeries
= getDataSeriesFromDoc( xChartDoc
, 0 );
74 CPPUNIT_ASSERT( xDataSeries
.is() );
76 Reference
< beans::XPropertySet
> xPropSet( xDataSeries
, UNO_QUERY_THROW
);
78 // test that y error bars are there
79 Reference
< beans::XPropertySet
> xErrorBarYProps
;
80 xPropSet
->getPropertyValue(CHART_UNONAME_ERRORBAR_Y
) >>= xErrorBarYProps
;
81 CPPUNIT_ASSERT(xErrorBarYProps
.is());
83 sal_Int32 nErrorBarStyle
;
85 xErrorBarYProps
->getPropertyValue(u
"ErrorBarStyle"_ustr
)
88 chart::ErrorBarStyle::RELATIVE
,
93 xErrorBarYProps
->getPropertyValue(u
"PositiveError"_ustr
) >>= nVal
);
94 CPPUNIT_ASSERT_DOUBLES_EQUAL(5.0, nVal
, 1e-8);
97 xErrorBarYProps
->getPropertyValue(u
"NegativeError"_ustr
) >>= nVal
);
98 CPPUNIT_ASSERT_DOUBLES_EQUAL(5.0, nVal
, 1e-8);
102 xErrorBarYProps
->getPropertyValue(u
"ShowPositiveError"_ustr
) >>= bVal
);
103 CPPUNIT_ASSERT_EQUAL(true, bVal
);
106 xErrorBarYProps
->getPropertyValue(u
"ShowNegativeError"_ustr
) >>= bVal
);
107 CPPUNIT_ASSERT_EQUAL(true, bVal
);
110 // test that x error bars are not imported
111 Reference
< beans::XPropertySet
> xErrorBarXProps
;
112 xPropSet
->getPropertyValue(CHART_UNONAME_ERRORBAR_X
) >>= xErrorBarXProps
;
113 CPPUNIT_ASSERT(!xErrorBarXProps
.is());
116 CPPUNIT_TEST_FIXTURE(Chart2ImportTest
, testErrorBarRange
)
118 loadFromFile(u
"ods/error_bar_range.ods");
119 uno::Reference
< chart2::XChartDocument
> xChartDoc
= getChartDocFromSheet( 0);
120 CPPUNIT_ASSERT(xChartDoc
.is());
122 Reference
< chart2::XDataSeries
> xDataSeries
= getDataSeriesFromDoc( xChartDoc
, 0 );
123 CPPUNIT_ASSERT( xDataSeries
.is() );
125 Reference
< beans::XPropertySet
> xPropSet( xDataSeries
, UNO_QUERY_THROW
);
127 // test that y error bars are there
128 Reference
< beans::XPropertySet
> xErrorBarYProps
;
129 xPropSet
->getPropertyValue(CHART_UNONAME_ERRORBAR_Y
) >>= xErrorBarYProps
;
130 CPPUNIT_ASSERT(xErrorBarYProps
.is());
132 sal_Int32 nErrorBarStyle
;
134 xErrorBarYProps
->getPropertyValue(u
"ErrorBarStyle"_ustr
)
136 CPPUNIT_ASSERT_EQUAL(
137 chart::ErrorBarStyle::FROM_DATA
,
141 CPPUNIT_ASSERT(xErrorBarYProps
->getPropertyValue(u
"ErrorBarRangePositive"_ustr
) >>= aRangePos
);
142 CPPUNIT_ASSERT_EQUAL(u
"$Sheet1.$C$2:$C$4"_ustr
, aRangePos
);
145 CPPUNIT_TEST_FIXTURE(Chart2ImportTest
, testErrorBarFormatting
)
147 loadFromFile(u
"ods/error_bar_properties.ods");
148 uno::Reference
< chart2::XChartDocument
> xChartDoc
= getChartDocFromSheet( 0);
149 CPPUNIT_ASSERT(xChartDoc
.is());
151 Reference
< chart2::XDataSeries
> xDataSeries
= getDataSeriesFromDoc( xChartDoc
, 0 );
152 CPPUNIT_ASSERT( xDataSeries
.is() );
154 Reference
< beans::XPropertySet
> xPropSet( xDataSeries
, UNO_QUERY_THROW
);
156 // test that y error bars are there
157 Reference
< beans::XPropertySet
> xErrorBarYProps
;
158 xPropSet
->getPropertyValue(CHART_UNONAME_ERRORBAR_Y
) >>= xErrorBarYProps
;
159 CPPUNIT_ASSERT(xErrorBarYProps
.is());
161 util::Color
aColor(0);
162 xErrorBarYProps
->getPropertyValue(u
"LineColor"_ustr
) >>= aColor
;
163 sal_uInt32 nColorValue
= aColor
;
164 CPPUNIT_ASSERT_EQUAL(sal_uInt32(0xff3333), nColorValue
);
167 // stepped line interpolation
168 CPPUNIT_TEST_FIXTURE(Chart2ImportTest
, testSteppedLines
)
170 const sal_Int32 MAXSHEET
= 14;
171 chart2::CurveStyle
const curveStyle
[] = {
172 chart2::CurveStyle_LINES
,
173 chart2::CurveStyle_CUBIC_SPLINES
,
174 chart2::CurveStyle_B_SPLINES
,
175 chart2::CurveStyle_STEP_START
,
176 chart2::CurveStyle_STEP_END
,
177 chart2::CurveStyle_STEP_CENTER_X
,
178 chart2::CurveStyle_STEP_CENTER_Y
,
179 chart2::CurveStyle_LINES
,
180 chart2::CurveStyle_CUBIC_SPLINES
,
181 chart2::CurveStyle_B_SPLINES
,
182 chart2::CurveStyle_STEP_START
,
183 chart2::CurveStyle_STEP_END
,
184 chart2::CurveStyle_STEP_CENTER_X
,
185 chart2::CurveStyle_STEP_CENTER_Y
188 loadFromFile(u
"ods/stepped_lines.ods");
189 for(sal_Int32 nSheet
= 0; nSheet
< MAXSHEET
; ++nSheet
)
191 uno::Reference
< chart2::XChartDocument
> xChart2Doc
= getChartDocFromSheet( nSheet
);
192 CPPUNIT_ASSERT(xChart2Doc
.is());
194 Reference
< chart2::XChartType
> xChartType
= getChartTypeFromDoc( xChart2Doc
, 0 );
195 CPPUNIT_ASSERT(xChartType
.is());
197 Reference
< beans::XPropertySet
> xPropSet( xChartType
, UNO_QUERY
);
198 CPPUNIT_ASSERT(xPropSet
.is());
200 chart2::CurveStyle eCurveStyle
;
201 xPropSet
->getPropertyValue(u
"CurveStyle"_ustr
) >>= eCurveStyle
;
202 CPPUNIT_ASSERT_EQUAL(eCurveStyle
, curveStyle
[nSheet
]);
206 uno::Sequence
< OUString
> getChartColumnDescriptions( uno::Reference
< chart::XChartDocument
> const & xChart1Doc
)
208 CPPUNIT_ASSERT(xChart1Doc
.is());
209 uno::Reference
< chart::XChartDataArray
> xChartData ( xChart1Doc
->getData(), UNO_QUERY_THROW
);
210 uno::Sequence
< OUString
> seriesList
= xChartData
->getColumnDescriptions();
214 CPPUNIT_TEST_FIXTURE(Chart2ImportTest
, testODSChartSeries
)
216 loadFromFile(u
"ods/chart.ods");
217 uno::Reference
< chart::XChartDocument
> xChart1Doc ( getChartCompFromSheet( 0, 0), UNO_QUERY_THROW
);
218 uno::Sequence
< OUString
> seriesList
= getChartColumnDescriptions( xChart1Doc
);
219 CPPUNIT_ASSERT_EQUAL(u
"Col 1"_ustr
, seriesList
[0]);
220 CPPUNIT_ASSERT_EQUAL(u
"Col2"_ustr
, seriesList
[1]);
221 CPPUNIT_ASSERT_EQUAL(u
"Col 33"_ustr
, seriesList
[2]);
225 CPPUNIT_TEST_FIXTURE(Chart2ImportTest
, testXLSXChartSeries
)
227 loadFromFile(u
"xlsx/chart.xlsx");
228 uno::Reference
< chart::XChartDocument
> xChart1Doc ( getChartCompFromSheet( 0, 0), UNO_QUERY_THROW
);
229 uno::Sequence
< OUString
> seriesList
= getChartColumnDescriptions(xChart1Doc
);
230 CPPUNIT_ASSERT_EQUAL(u
"Col 1"_ustr
, seriesList
[0]);
231 CPPUNIT_ASSERT_EQUAL(u
"Col2"_ustr
, seriesList
[1]);
232 CPPUNIT_ASSERT_EQUAL(u
"Col 33"_ustr
, seriesList
[2]);
236 CPPUNIT_TEST_FIXTURE(Chart2ImportTest
, testXLSChartSeries
)
238 loadFromFile(u
"xls/chart.xls");
239 uno::Reference
< chart::XChartDocument
> xChart1Doc ( getChartCompFromSheet( 0, 0), UNO_QUERY_THROW
);
240 uno::Sequence
< OUString
> seriesList
= getChartColumnDescriptions(xChart1Doc
);
241 CPPUNIT_ASSERT_EQUAL(u
"Col 1"_ustr
, seriesList
[0]);
242 CPPUNIT_ASSERT_EQUAL(u
"Col 2"_ustr
, seriesList
[1]);
243 CPPUNIT_ASSERT_EQUAL(u
"Col 3"_ustr
, seriesList
[2]);
247 CPPUNIT_TEST_FIXTURE(Chart2ImportTest
, testODTChartSeries
)
249 loadFromFile(u
"odt/chart.odt");
250 uno::Sequence
< OUString
> seriesList
= getWriterChartColumnDescriptions();
251 CPPUNIT_ASSERT_EQUAL(u
"Column 1"_ustr
, seriesList
[0]);
252 CPPUNIT_ASSERT_EQUAL(u
"Column 2"_ustr
, seriesList
[1]);
253 CPPUNIT_ASSERT_EQUAL(u
"Column 3"_ustr
, seriesList
[2]);
257 CPPUNIT_TEST_FIXTURE(Chart2ImportTest
, testDOCChartSeries
)
259 loadFromFile(u
"doc/chart.doc");
260 uno::Sequence
< OUString
> seriesList
= getWriterChartColumnDescriptions();
261 CPPUNIT_ASSERT_EQUAL(u
"Column 1"_ustr
, seriesList
[0]);
262 CPPUNIT_ASSERT_EQUAL(u
"Column 2"_ustr
, seriesList
[1]);
263 CPPUNIT_ASSERT_EQUAL(u
"Column 3"_ustr
, seriesList
[2]);
266 CPPUNIT_TEST_FIXTURE(Chart2ImportTest
, testDOCXChartSeries
)
268 loadFromFile(u
"docx/chart.docx");
269 Reference
<chart2::XChartDocument
> xChartDoc(getChartDocFromWriter(0), uno::UNO_QUERY
);
270 CPPUNIT_ASSERT(xChartDoc
.is());
272 Reference
<chart2::XChartType
> xCT
= getChartTypeFromDoc(xChartDoc
, 0);
273 CPPUNIT_ASSERT(xCT
.is());
275 std::vector
<uno::Sequence
<uno::Any
> > aLabels
= getDataSeriesLabelsFromChartType(xCT
);
276 CPPUNIT_ASSERT_EQUAL(size_t(3), aLabels
.size());
277 CPPUNIT_ASSERT_EQUAL(u
"Series 1"_ustr
, aLabels
[0][0].get
<OUString
>());
278 CPPUNIT_ASSERT_EQUAL(u
"Series 2"_ustr
, aLabels
[1][0].get
<OUString
>());
279 CPPUNIT_ASSERT_EQUAL(u
"Series 3"_ustr
, aLabels
[2][0].get
<OUString
>());
282 CPPUNIT_TEST_FIXTURE(Chart2ImportTest
, testDOCXChartEmptySeries
)
284 loadFromFile(u
"docx/tdf125337.docx");
285 Reference
<chart2::XChartDocument
> xChartDoc(getChartDocFromWriter(0), uno::UNO_QUERY
);
286 CPPUNIT_ASSERT(xChartDoc
.is());
288 Reference
<chart2::XChartType
> xCT
= getChartTypeFromDoc(xChartDoc
, 0);
289 CPPUNIT_ASSERT(xCT
.is());
291 std::vector
<uno::Sequence
<uno::Any
> > aLabels
= getDataSeriesLabelsFromChartType(xCT
);
292 CPPUNIT_ASSERT_EQUAL(size_t(3), aLabels
.size());
293 CPPUNIT_ASSERT_EQUAL(u
"1. dataseries"_ustr
, aLabels
[0][0].get
<OUString
>());
294 CPPUNIT_ASSERT_EQUAL(u
"2. dataseries"_ustr
, aLabels
[1][0].get
<OUString
>());
295 CPPUNIT_ASSERT_EQUAL(u
"Column 3"_ustr
, aLabels
[2][0].get
<OUString
>());
297 //test chart series sparse data for docx
298 std::vector
<std::vector
<double> > aValues
= getDataSeriesYValuesFromChartType(xCT
);
299 CPPUNIT_ASSERT_EQUAL(size_t(3), aValues
.size());
300 //test the second series values
301 CPPUNIT_ASSERT_EQUAL(2.4, aValues
[1][0]);
302 CPPUNIT_ASSERT_EQUAL(4.4, aValues
[1][1]);
303 //test the third series (empty) values
304 CPPUNIT_ASSERT(std::isnan(aValues
[2][0]));
305 CPPUNIT_ASSERT(std::isnan(aValues
[2][1]));
308 CPPUNIT_TEST_FIXTURE(Chart2ImportTest
, testTdf81396
)
310 loadFromFile(u
"xlsx/tdf81396.xlsx");
311 Reference
<chart::XChartDocument
> xChartDoc(getChartDocFromSheet(0),
314 Reference
<chart2::XChartDocument
> xChartDoc2(xChartDoc
, UNO_QUERY_THROW
);
315 Reference
<chart2::XChartType
> xChartType(getChartTypeFromDoc(xChartDoc2
, 0), UNO_SET_THROW
);
316 std::vector aDataSeriesYValues
= getDataSeriesYValuesFromChartType(xChartType
);
317 CPPUNIT_ASSERT_EQUAL(size_t(1), aDataSeriesYValues
.size());
319 // Without the fix in place, this test would have failed with
320 // - Expected: 105.210801910481
322 CPPUNIT_ASSERT_EQUAL(105.210801910481, aDataSeriesYValues
[0][0]);
325 CPPUNIT_TEST_FIXTURE(Chart2ImportTest
, testPPTXChartErrorBars
)
327 loadFromFile(u
"pptx/tdf127720.pptx");
328 Reference
<chart2::XChartDocument
> xChartDoc(getChartDocFromDrawImpress(0, 0), uno::UNO_QUERY
);
329 CPPUNIT_ASSERT(xChartDoc
.is());
331 uno::Reference
< chart::XChartDataArray
> xDataArray(xChartDoc
->getDataProvider(), UNO_QUERY_THROW
);
332 Sequence
<OUString
> aColumnDesc
= xDataArray
->getColumnDescriptions();
333 // Number of columns = 4 (Y-values, X-values and positive/negative error bars).
334 // Without the fix there would only be 2 columns (no error range).
335 CPPUNIT_ASSERT_EQUAL_MESSAGE("There must be 4 columns and descriptions", static_cast<sal_Int32
>(4), aColumnDesc
.getLength());
338 CPPUNIT_TEST_FIXTURE(Chart2ImportTest
, testDOCXChartValuesSize
)
340 loadFromFile(u
"docx/bubblechart.docx" );
341 Reference
<chart2::XChartDocument
> xChartDoc( getChartDocFromWriter(0), uno::UNO_QUERY
);
342 CPPUNIT_ASSERT( xChartDoc
.is() );
344 uno::Reference
< chart::XChartDataArray
> xDataArray( xChartDoc
->getDataProvider(), UNO_QUERY_THROW
);
345 Sequence
<OUString
> aColumnDesc
= xDataArray
->getColumnDescriptions();
346 // Number of columns = 3 (Y-values, X-values and bubble sizes).
347 // Without the fix there would only be 2 columns (no bubble sizes).
348 CPPUNIT_ASSERT_EQUAL_MESSAGE( "There must be 3 columns and descriptions", static_cast<sal_Int32
>(3), aColumnDesc
.getLength() );
349 Sequence
<Sequence
<double>> aData
= xDataArray
->getData();
350 CPPUNIT_ASSERT_EQUAL_MESSAGE( "There must be exactly 3 data points", static_cast<sal_Int32
>(3), aData
.getLength() );
352 std::vector
<std::vector
<double>> aExpected
= { { 2.7, 0.7, 10.0 }, { 3.2, 1.8, 4.0 }, { 0.8, 2.6, 8.0 } };
354 for ( sal_Int32 nRowIdx
= 0; nRowIdx
< 3; ++nRowIdx
)
355 for( sal_Int32 nColIdx
= 0; nColIdx
< 3; ++nColIdx
)
356 CPPUNIT_ASSERT_DOUBLES_EQUAL( aExpected
[nRowIdx
][nColIdx
], aData
[nRowIdx
][nColIdx
], 1e-1 );
359 CPPUNIT_TEST_FIXTURE(Chart2ImportTest
, testPPTChartSeries
)
361 //test chart series names for ppt
362 loadFromFile(u
"ppt/chart.ppt");
363 uno::Reference
< chart::XChartDocument
> xChartDoc
= getChartDocFromDrawImpress( 0, 0 );
364 uno::Reference
< chart::XChartDataArray
> xChartData ( xChartDoc
->getData(), uno::UNO_QUERY_THROW
);
365 uno::Sequence
< OUString
> seriesList
= xChartData
->getColumnDescriptions();
367 CPPUNIT_ASSERT_EQUAL(u
"Column 1"_ustr
, seriesList
[0]);
368 CPPUNIT_ASSERT_EQUAL(u
"Column 2"_ustr
, seriesList
[1]);
369 CPPUNIT_ASSERT_EQUAL(u
"Column 3"_ustr
, seriesList
[2]);
373 CPPUNIT_TEST_FIXTURE(Chart2ImportTest
, testPPTXChartSeries
)
375 //test chart series names for pptx
376 loadFromFile(u
"pptx/chart.pptx");
377 Reference
<chart2::XChartDocument
> xChartDoc(getChartDocFromDrawImpress(0, 0), uno::UNO_QUERY
);
378 CPPUNIT_ASSERT(xChartDoc
.is());
380 Reference
<chart2::XChartType
> xCT
= getChartTypeFromDoc(xChartDoc
, 0);
381 CPPUNIT_ASSERT(xCT
.is());
383 std::vector
<uno::Sequence
<uno::Any
> > aLabels
= getDataSeriesLabelsFromChartType(xCT
);
384 CPPUNIT_ASSERT_EQUAL(size_t(3), aLabels
.size());
385 CPPUNIT_ASSERT_EQUAL(u
"Column 1"_ustr
, aLabels
[0][0].get
<OUString
>());
386 CPPUNIT_ASSERT_EQUAL(u
"Column 2"_ustr
, aLabels
[1][0].get
<OUString
>());
387 CPPUNIT_ASSERT_EQUAL(u
"Column 3"_ustr
, aLabels
[2][0].get
<OUString
>());
390 CPPUNIT_TEST_FIXTURE(Chart2ImportTest
, testPPTXSparseChartSeries
)
392 //test chart series sparse data for pptx
393 loadFromFile(u
"pptx/sparse-chart.pptx");
394 Reference
<chart2::XChartDocument
> xChartDoc(getChartDocFromDrawImpress(0, 0), uno::UNO_QUERY
);
395 CPPUNIT_ASSERT(xChartDoc
.is());
397 Reference
<chart2::XChartType
> xCT
= getChartTypeFromDoc(xChartDoc
, 0);
398 CPPUNIT_ASSERT(xCT
.is());
400 std::vector
<std::vector
<double> > aValues
= getDataSeriesYValuesFromChartType(xCT
);
401 CPPUNIT_ASSERT_EQUAL(size_t(2), aValues
.size());
402 CPPUNIT_ASSERT( std::isnan( aValues
[0][0] ) );
403 CPPUNIT_ASSERT_EQUAL(2.5, aValues
[0][1]);
404 CPPUNIT_ASSERT_EQUAL(3.5, aValues
[0][2]);
405 CPPUNIT_ASSERT( std::isnan( aValues
[0][3] ) );
406 CPPUNIT_ASSERT_EQUAL(-2.4, aValues
[1][0]);
407 CPPUNIT_ASSERT( std::isnan( aValues
[1][1] ) );
408 CPPUNIT_ASSERT( std::isnan( aValues
[1][2] ) );
409 CPPUNIT_ASSERT_EQUAL(-2.8, aValues
[1][3]);
412 CPPUNIT_TEST_FIXTURE(Chart2ImportTest
, testPPTXHiddenDataSeries
)
415 * Original data contains 3 series but 2 of them are hidden. For now, we
416 * detect and skip those hidden series on import (since we don't support
417 * hidden columns for internal data table yet).
419 loadFromFile(u
"pptx/stacked-bar-chart-hidden-series.pptx");
420 Reference
<chart2::XChartDocument
> xChartDoc(getChartDocFromDrawImpress(0, 0), uno::UNO_QUERY
);
421 CPPUNIT_ASSERT(xChartDoc
.is());
423 // "Automatic" chart background fill in pptx should be loaded as no fill.
424 Reference
<beans::XPropertySet
> xPropSet
= xChartDoc
->getPageBackground();
425 CPPUNIT_ASSERT(xPropSet
.is());
426 drawing::FillStyle eStyle
= xPropSet
->getPropertyValue(u
"FillStyle"_ustr
).get
<drawing::FillStyle
>();
427 CPPUNIT_ASSERT_EQUAL_MESSAGE("'Automatic' chart background fill in pptx should be loaded as no fill (transparent).",
428 drawing::FillStyle_NONE
, eStyle
);
430 Reference
<chart2::XChartType
> xCT
= getChartTypeFromDoc(xChartDoc
, 0);
431 CPPUNIT_ASSERT(xCT
.is());
433 // There should be only one data series present.
434 std::vector
<uno::Sequence
<uno::Any
> > aLabels
= getDataSeriesLabelsFromChartType(xCT
);
435 CPPUNIT_ASSERT_EQUAL(size_t(1), aLabels
.size());
436 CPPUNIT_ASSERT_EQUAL(u
"Series 3"_ustr
, aLabels
[0][0].get
<OUString
>());
438 // Test the internal data.
439 CPPUNIT_ASSERT(xChartDoc
->hasInternalDataProvider());
441 Reference
<chart2::XInternalDataProvider
> xInternalProvider(xChartDoc
->getDataProvider(), uno::UNO_QUERY
);
442 CPPUNIT_ASSERT(xInternalProvider
.is());
444 Reference
<chart::XComplexDescriptionAccess
> xDescAccess(xInternalProvider
, uno::UNO_QUERY
);
445 CPPUNIT_ASSERT(xDescAccess
.is());
447 // Get the category labels.
448 Sequence
<Sequence
<OUString
> > aCategories
= xDescAccess
->getComplexRowDescriptions();
449 CPPUNIT_ASSERT_EQUAL(sal_Int32(4), aCategories
.getLength());
450 CPPUNIT_ASSERT_EQUAL(u
"Category 1"_ustr
, aCategories
[0][0]);
451 CPPUNIT_ASSERT_EQUAL(u
"Category 2"_ustr
, aCategories
[1][0]);
452 CPPUNIT_ASSERT_EQUAL(u
"Category 3"_ustr
, aCategories
[2][0]);
453 CPPUNIT_ASSERT_EQUAL(u
"Category 4"_ustr
, aCategories
[3][0]);
456 CPPUNIT_TEST_FIXTURE(Chart2ImportTest
, testPPTXPercentageNumberFormats
)
458 loadFromFile(u
"pptx/percentage-number-formats.pptx");
461 Reference
<chart2::XChartDocument
> xChartDoc(getChartDocFromDrawImpress(0, 0), uno::UNO_QUERY
);
462 CPPUNIT_ASSERT(xChartDoc
.is());
464 uno::Reference
<chart2::XDataSeries
> xDataSeries(getDataSeriesFromDoc(xChartDoc
, 0));
465 CPPUNIT_ASSERT(xDataSeries
.is());
466 uno::Reference
<beans::XPropertySet
> xPropertySet
;
467 chart2::DataPointLabel aLabel
;
468 sal_Int32 nNumberFormat
;
469 const sal_Int32 nPercentFormatSimple
= getNumberFormat(xChartDoc
, u
"0%"_ustr
);
470 const sal_Int32 nPercentFormatDecimal
= getNumberFormat(xChartDoc
, u
"0.00%"_ustr
);
472 xPropertySet
.set(xDataSeries
->getDataPointByIndex(0), uno::UNO_SET_THROW
);
473 xPropertySet
->getPropertyValue(u
"Label"_ustr
) >>= aLabel
;
474 CPPUNIT_ASSERT_EQUAL(sal_True
, aLabel
.ShowNumber
);
475 CPPUNIT_ASSERT_EQUAL(sal_True
, aLabel
.ShowNumberInPercent
);
476 xPropertySet
->getPropertyValue(u
"PercentageNumberFormat"_ustr
) >>= nNumberFormat
;
477 CPPUNIT_ASSERT_EQUAL(nPercentFormatSimple
, nNumberFormat
);
479 xPropertySet
.set(xDataSeries
->getDataPointByIndex(1), uno::UNO_SET_THROW
);
480 xPropertySet
->getPropertyValue(u
"Label"_ustr
) >>= aLabel
;
481 CPPUNIT_ASSERT_EQUAL(sal_True
, aLabel
.ShowNumber
);
482 CPPUNIT_ASSERT_EQUAL(sal_True
, aLabel
.ShowNumberInPercent
);
483 xPropertySet
->getPropertyValue(u
"PercentageNumberFormat"_ustr
) >>= nNumberFormat
;
484 CPPUNIT_ASSERT_EQUAL(nPercentFormatDecimal
, nNumberFormat
);
486 xPropertySet
.set(xDataSeries
->getDataPointByIndex(2), uno::UNO_SET_THROW
);
487 xPropertySet
->getPropertyValue(u
"Label"_ustr
) >>= aLabel
;
488 CPPUNIT_ASSERT_EQUAL(sal_False
, aLabel
.ShowNumber
);
489 CPPUNIT_ASSERT_EQUAL(sal_True
, aLabel
.ShowNumberInPercent
);
490 xPropertySet
->getPropertyValue(u
"PercentageNumberFormat"_ustr
) >>= nNumberFormat
;
491 CPPUNIT_ASSERT_EQUAL(nPercentFormatSimple
, nNumberFormat
);
493 xPropertySet
.set(xDataSeries
->getDataPointByIndex(3), uno::UNO_SET_THROW
);
494 xPropertySet
->getPropertyValue(u
"Label"_ustr
) >>= aLabel
;
495 CPPUNIT_ASSERT_EQUAL(sal_False
, aLabel
.ShowNumber
);
496 CPPUNIT_ASSERT_EQUAL(sal_True
, aLabel
.ShowNumberInPercent
);
497 xPropertySet
->getPropertyValue(u
"PercentageNumberFormat"_ustr
) >>= nNumberFormat
;
498 CPPUNIT_ASSERT_EQUAL(nPercentFormatDecimal
, nNumberFormat
);
501 xChartDoc
.set(getChartDocFromDrawImpress(1, 0), uno::UNO_QUERY
);
502 CPPUNIT_ASSERT(xChartDoc
.is());
504 Reference
<chart2::XAxis
> xYAxis
= getAxisFromDoc(xChartDoc
, 0, 1, 0);
505 CPPUNIT_ASSERT(xYAxis
.is());
507 Reference
<beans::XPropertySet
> xPS(xYAxis
, uno::UNO_QUERY_THROW
);
508 bool bLinkNumberFormatToSource
= true;
509 bool bSuccess
= xPS
->getPropertyValue(CHART_UNONAME_LINK_TO_SRC_NUMFMT
) >>= bLinkNumberFormatToSource
;
510 CPPUNIT_ASSERT_MESSAGE("\"LinkNumberFormatToSource\" should be set to false.", bSuccess
);
511 CPPUNIT_ASSERT_MESSAGE("\"LinkNumberFormatToSource\" should be set to false.", !bLinkNumberFormatToSource
);
513 // FIXME: This should be in fact "0.00%".
514 // see TODO in oox/source/drawingml/chart/modelbase.cxx
515 const sal_Int32 nPercentFormatDecimalShort
= getNumberFormat(xChartDoc
, u
"0.0%"_ustr
);
516 nNumberFormat
= getNumberFormatFromAxis(xYAxis
);
517 CPPUNIT_ASSERT_EQUAL(nPercentFormatDecimalShort
, nNumberFormat
);
518 sal_Int16 nType
= getNumberFormatType(xChartDoc
, nNumberFormat
);
519 CPPUNIT_ASSERT_MESSAGE("Y axis should be a percent format.", (nType
& util::NumberFormat::PERCENT
));
522 CPPUNIT_TEST_FIXTURE(Chart2ImportTest
, testPieChartLabelsNumFormat
)
524 loadFromFile(u
"xlsx/tdfPieNumFormat.xlsx");
525 uno::Reference
< chart::XChartDocument
> xChartDoc(getChartCompFromSheet(0, 0), UNO_QUERY_THROW
);
526 CPPUNIT_ASSERT(xChartDoc
.is());
527 // test data point labels format
528 Reference
<beans::XPropertySet
> xDataPointPropSet(xChartDoc
->getDiagram()->getDataPointProperties(0, 0), uno::UNO_SET_THROW
);
529 chart2::DataPointLabel aLabel
;
530 xDataPointPropSet
->getPropertyValue(u
"Label"_ustr
) >>= aLabel
;
531 CPPUNIT_ASSERT_EQUAL(sal_True
, aLabel
.ShowNumber
);
534 CPPUNIT_TEST_FIXTURE(Chart2ImportTest
, testPPTXStackedNonStackedYAxis
)
536 loadFromFile(u
"pptx/stacked-non-stacked-mix-y-axis.pptx");
538 // 1st chart is a normal stacked column.
539 Reference
<chart2::XChartDocument
> xChartDoc(getChartDocFromDrawImpress(0, 0), uno::UNO_QUERY
);
540 CPPUNIT_ASSERT(xChartDoc
.is());
542 Reference
<chart2::XTitled
> xTitled(xChartDoc
, uno::UNO_QUERY_THROW
);
543 OUString aTitle
= getTitleString(xTitled
);
544 CPPUNIT_ASSERT_EQUAL(u
"Stacked"_ustr
, aTitle
);
547 Reference
<chart2::XAxis
> xYAxis
= getAxisFromDoc(xChartDoc
, 0, 1, 0);
548 CPPUNIT_ASSERT(xYAxis
.is());
550 sal_Int32 nNumberFormat
= getNumberFormatFromAxis(xYAxis
);
551 sal_Int16 nType
= getNumberFormatType(xChartDoc
, nNumberFormat
);
552 CPPUNIT_ASSERT_MESSAGE("Y axis should be a normal number format.", (nType
& util::NumberFormat::NUMBER
));
553 CPPUNIT_ASSERT_MESSAGE("Y axis should NOT be a percent format.", !(nType
& util::NumberFormat::PERCENT
));
555 // 2nd chart is a percent-stacked column.
556 xChartDoc
.set(getChartDocFromDrawImpress(1, 0), uno::UNO_QUERY
);
557 CPPUNIT_ASSERT(xChartDoc
.is());
559 xTitled
.set(xChartDoc
, uno::UNO_QUERY_THROW
);
560 aTitle
= getTitleString(xTitled
);
561 CPPUNIT_ASSERT_EQUAL(u
"100% Stacked"_ustr
, aTitle
);
564 xYAxis
= getAxisFromDoc(xChartDoc
, 0, 1, 0);
565 CPPUNIT_ASSERT(xYAxis
.is());
567 // Get the number format of the Y-axis.
568 nNumberFormat
= getNumberFormatFromAxis(xYAxis
);
569 nType
= getNumberFormatType(xChartDoc
, nNumberFormat
);
570 CPPUNIT_ASSERT_MESSAGE("Y axis should be a percent format.", (nType
& util::NumberFormat::PERCENT
));
572 // 3rd chart is a mixture of normal-stacked column with a percent-stacked
573 // area chart series. Excel in this case sets the Y-axis to be
574 // non-percent axis and we should do the same for interoperability.
575 xChartDoc
.set(getChartDocFromDrawImpress(2, 0), uno::UNO_QUERY
);
576 CPPUNIT_ASSERT(xChartDoc
.is());
578 xTitled
.set(xChartDoc
, uno::UNO_QUERY_THROW
);
579 aTitle
= getTitleString(xTitled
);
580 CPPUNIT_ASSERT_EQUAL(u
"Stacked column mixed with 100% stacked area"_ustr
, aTitle
);
583 xYAxis
= getAxisFromDoc(xChartDoc
, 0, 1, 0);
584 CPPUNIT_ASSERT(xYAxis
.is());
586 // Get the number format of the Y-axis.
587 nNumberFormat
= getNumberFormatFromAxis(xYAxis
);
588 nType
= getNumberFormatType(xChartDoc
, nNumberFormat
);
589 CPPUNIT_ASSERT_MESSAGE("Y axis should be a normal number format.", (nType
& util::NumberFormat::NUMBER
));
590 CPPUNIT_ASSERT_MESSAGE("Y axis should NOT be a percent format.", !(nType
& util::NumberFormat::PERCENT
));
593 CPPUNIT_TEST_FIXTURE(Chart2ImportTest
, testODPChartSeries
)
595 //test chart series names for odp
596 loadFromFile(u
"odp/chart.odp");
597 uno::Reference
< chart::XChartDocument
> xChartDoc
= getChartDocFromDrawImpress( 0, 0 );
598 uno::Reference
< chart::XChartDataArray
> xChartData ( xChartDoc
->getData(), uno::UNO_QUERY_THROW
);
599 uno::Sequence
< OUString
> seriesList
= xChartData
->getColumnDescriptions();
600 CPPUNIT_ASSERT_EQUAL(u
"Column 1"_ustr
, seriesList
[0]);
601 CPPUNIT_ASSERT_EQUAL(u
"Column 2"_ustr
, seriesList
[1]);
602 CPPUNIT_ASSERT_EQUAL(u
"Column 3"_ustr
, seriesList
[2]);
606 CPPUNIT_TEST_FIXTURE(Chart2ImportTest
, testBnc864396
)
608 loadFromFile(u
"pptx/bnc864396.pptx");
609 uno::Reference
< chart2::XChartDocument
> xChartDoc(getChartDocFromDrawImpress(0,0), uno::UNO_QUERY_THROW
);
610 CPPUNIT_ASSERT(xChartDoc
->hasInternalDataProvider());
612 uno::Reference
< chart2::XInternalDataProvider
> xDataProvider( xChartDoc
->getDataProvider(), uno::UNO_QUERY_THROW
);
613 uno::Reference
< chart::XChartDataArray
> xChartDataArray(xDataProvider
, uno::UNO_QUERY_THROW
);
614 uno::Sequence
< OUString
> aRowLabels
= xChartDataArray
->getRowDescriptions();
615 for(sal_Int32 i
= 0; i
< aRowLabels
.getLength(); ++i
)
617 OUString aExpected
= "cat" + OUString::number(i
+1);
618 CPPUNIT_ASSERT_EQUAL(aExpected
, aRowLabels
[i
]);
622 CPPUNIT_TEST_FIXTURE(Chart2ImportTest
, testBnc889755
)
624 loadFromFile(u
"pptx/bnc889755.pptx");
625 uno::Reference
<chart2::XChartDocument
> xChartDoc(getChartDocFromDrawImpress(0, 5), uno::UNO_QUERY_THROW
);
626 CPPUNIT_ASSERT(xChartDoc
->hasInternalDataProvider());
628 constexpr sal_Int32 nNumCategories
= 16;
630 Reference
<util::XNumberFormatsSupplier
> xNFS(xChartDoc
, uno::UNO_QUERY_THROW
);
631 Reference
< util::XNumberFormatter
> xNumFormatter(
632 util::NumberFormatter::create(comphelper::getComponentContext(m_xSFactory
)), uno::UNO_QUERY_THROW
);
633 xNumFormatter
->attachNumberFormatsSupplier(xNFS
);
635 Reference
<chart2::XAxis
> xAxisX
= getAxisFromDoc(xChartDoc
, 0, 0, 0);
636 chart2::ScaleData aScaleData
= xAxisX
->getScaleData();
637 CPPUNIT_ASSERT_EQUAL(chart2::AxisType::DATE
, aScaleData
.AxisType
);
639 sal_Int32 nNumFmt
= getNumberFormatFromAxis(xAxisX
);
641 CPPUNIT_ASSERT(xChartDoc
->hasInternalDataProvider());
642 uno::Reference
< chart2::XInternalDataProvider
> xDataProvider( xChartDoc
->getDataProvider(), uno::UNO_QUERY_THROW
);
643 uno::Reference
< chart::XDateCategories
> xDateCategories( xDataProvider
, uno::UNO_QUERY_THROW
);
644 CPPUNIT_ASSERT(xDateCategories
.is());
645 Sequence
<double> aDateSeq
= xDateCategories
->getDateCategories();
646 Sequence
<OUString
> aFormattedDates(nNumCategories
);
647 auto aFormattedDatesRange
= asNonConstRange(aFormattedDates
);
649 for (sal_Int32 nIdx
= 0; nIdx
< nNumCategories
; ++nIdx
)
650 aFormattedDatesRange
[nIdx
] = xNumFormatter
->convertNumberToString(nNumFmt
, aDateSeq
[nIdx
]);
652 CPPUNIT_ASSERT_EQUAL(nNumCategories
, aDateSeq
.getLength());
654 const OUString aExpectedDateCategories
[nNumCategories
] = {
655 u
"Oct-12"_ustr
, u
"Nov-12"_ustr
, u
"Dec-12"_ustr
, u
"Jan-13"_ustr
,
656 u
"Feb-13"_ustr
, u
"Mar-13"_ustr
, u
"Apr-13"_ustr
, u
"May-13"_ustr
,
657 u
"Jun-13"_ustr
, u
"Jul-13"_ustr
, u
"Aug-13"_ustr
, u
"Sep-13"_ustr
,
658 u
"Oct-13"_ustr
, u
"Nov-13"_ustr
, u
"Dec-13"_ustr
, u
"Jan-14"_ustr
,
661 for (size_t nIdx
= 0; nIdx
< nNumCategories
; ++nIdx
)
662 CPPUNIT_ASSERT_EQUAL(aExpectedDateCategories
[nIdx
], aFormattedDates
[nIdx
]);
664 //tdf#139940 - the title's gradient was lost and was filled with solid blue, instead of a "blue underline".
665 uno::Reference
<drawing::XDrawPagesSupplier
> xDoc(mxComponent
, uno::UNO_QUERY_THROW
);
666 uno::Reference
<drawing::XDrawPage
> xPage(xDoc
->getDrawPages()->getByIndex(0), uno::UNO_QUERY_THROW
);
669 // MCGR: Use the whole completely imported transparency gradient to check for correctness
670 uno::Reference
<beans::XPropertySet
> xShapeProps(xPage
->getByIndex(4), uno::UNO_QUERY_THROW
);
671 awt::Gradient2 aTransparence
;
672 xShapeProps
->getPropertyValue(u
"FillTransparenceGradient"_ustr
) >>= aTransparence
;
673 const basegfx::BColorStops aColorStops
= model::gradient::getColorStopsFromUno(aTransparence
.ColorStops
);
675 CPPUNIT_ASSERT_EQUAL(size_t(3), aColorStops
.size());
676 CPPUNIT_ASSERT_EQUAL(0.0, aColorStops
[0].getStopOffset());
677 CPPUNIT_ASSERT_EQUAL(Color(0x404040), Color(aColorStops
[0].getStopColor()));
678 CPPUNIT_ASSERT(basegfx::fTools::equal(aColorStops
[1].getStopOffset(), 0.070000000000000007));
679 CPPUNIT_ASSERT_EQUAL(Color(0x404040), Color(aColorStops
[1].getStopColor()));
680 CPPUNIT_ASSERT(basegfx::fTools::equal(aColorStops
[2].getStopOffset(), 0.080000000000000002));
681 CPPUNIT_ASSERT_EQUAL(COL_WHITE
, Color(aColorStops
[2].getStopColor()));
684 CPPUNIT_TEST_FIXTURE(Chart2ImportTest
, testBnc882383
)
686 loadFromFile(u
"pptx/bnc882383.pptx");
687 uno::Reference
<chart2::XChartDocument
> xChartDoc(getChartDocFromDrawImpress(0, 0), uno::UNO_QUERY_THROW
);
688 uno::Reference
<chart2::XDataSeries
> xDataSeries(getDataSeriesFromDoc(xChartDoc
, 0));
689 CPPUNIT_ASSERT(xDataSeries
.is());
691 uno::Reference
<beans::XPropertySet
> xPropertySet(xDataSeries
->getDataPointByIndex(0), uno::UNO_SET_THROW
);
692 OUString sGradientName
;
693 xPropertySet
->getPropertyValue(u
"GradientName"_ustr
) >>= sGradientName
;
694 CPPUNIT_ASSERT(!sGradientName
.isEmpty());
697 CPPUNIT_TEST_FIXTURE(Chart2ImportTest
, testTransparencyGradientValue
)
699 loadFromFile(u
"xlsx/tdf128732.xlsx");
700 uno::Reference
< chart2::XChartDocument
> xChartDoc
= getChartDocFromSheet(0);
701 CPPUNIT_ASSERT(xChartDoc
.is());
702 uno::Reference
<chart2::XDataSeries
> xDataSeries(getDataSeriesFromDoc(xChartDoc
, 0));
703 CPPUNIT_ASSERT(xDataSeries
.is());
705 uno::Reference
<beans::XPropertySet
> xPropertySet(xDataSeries
->getDataPointByIndex(0), uno::UNO_SET_THROW
);
706 OUString sTranspGradientName
;
707 xPropertySet
->getPropertyValue(u
"FillTransparenceGradientName"_ustr
) >>= sTranspGradientName
;
708 CPPUNIT_ASSERT(!sTranspGradientName
.isEmpty());
710 awt::Gradient2 aTransparenceGradient
;
711 uno::Reference
< lang::XMultiServiceFactory
> xFact(xChartDoc
, uno::UNO_QUERY
);
712 CPPUNIT_ASSERT(xFact
.is());
713 uno::Reference
< container::XNameAccess
> xTransparenceGradient(xFact
->createInstance(u
"com.sun.star.drawing.TransparencyGradientTable"_ustr
), uno::UNO_QUERY
);
714 uno::Any rTransparenceValue
= xTransparenceGradient
->getByName(sTranspGradientName
);
715 CPPUNIT_ASSERT(rTransparenceValue
>>= aTransparenceGradient
);
716 const basegfx::BColorStops aColorStops
= model::gradient::getColorStopsFromUno(aTransparenceGradient
.ColorStops
);
718 // MCGR: Use the whole completely imported transparency gradient to check for correctness
719 CPPUNIT_ASSERT_EQUAL(size_t(2), aColorStops
.size());
720 CPPUNIT_ASSERT_EQUAL(0.0, aColorStops
[0].getStopOffset());
721 CPPUNIT_ASSERT_EQUAL(Color(0x4d4d4d), Color(aColorStops
[0].getStopColor()));
722 CPPUNIT_ASSERT(basegfx::fTools::equal(aColorStops
[1].getStopOffset(), 1.0));
723 CPPUNIT_ASSERT_EQUAL(Color(0x333333), Color(aColorStops
[1].getStopColor()));
726 CPPUNIT_TEST_FIXTURE(Chart2ImportTest
, testSimpleStrictXLSX
)
728 loadFromFile(u
"xlsx/strict_chart.xlsx");
729 uno::Reference
< chart2::XChartDocument
> xChartDoc
= getChartDocFromSheet( 0);
730 CPPUNIT_ASSERT(xChartDoc
.is());
732 Reference
< chart2::XDataSeries
> xDataSeries
= getDataSeriesFromDoc( xChartDoc
, 0 );
733 CPPUNIT_ASSERT(xDataSeries
.is());
737 CPPUNIT_TEST_FIXTURE(Chart2ImportTest
, testDelayedCellImport
)
739 // chart range referencing content on later sheets
740 loadFromFile(u
"xlsx/fdo70609.xlsx");
741 uno::Reference
< chart2::XChartDocument
> xChartDoc
= getChartDocFromSheet( 0);
742 Reference
< chart2::data::XDataSequence
> xDataSeq
=
743 getDataSequenceFromDocByRole(xChartDoc
, u
"values-x");
745 OUString aRange
= xDataSeq
->getSourceRangeRepresentation();
746 CPPUNIT_ASSERT_EQUAL(u
"$Sheet2.$C$5:$C$9"_ustr
, aRange
);
749 CPPUNIT_TEST_FIXTURE(Chart2ImportTest
, testFlatODSStackedColumnChart
)
751 loadFromFile(u
"fods/stacked-column-chart.fods");
752 Reference
<chart2::XChartDocument
> xChartDoc
= getChartDocFromSheet(0);
753 CPPUNIT_ASSERT(xChartDoc
.is());
755 Reference
<chart2::XChartType
> xChartType
= getChartTypeFromDoc(xChartDoc
, 0);
756 CPPUNIT_ASSERT(xChartType
.is());
758 Reference
<chart2::XDataSeriesContainer
> xDSCont(xChartType
, UNO_QUERY
);
759 CPPUNIT_ASSERT(xDSCont
.is());
760 Sequence
<Reference
<chart2::XDataSeries
> > aSeriesSeq
= xDSCont
->getDataSeries();
762 // The stacked column chart should consist of 5 data series.
763 CPPUNIT_ASSERT_EQUAL(sal_Int32(5), aSeriesSeq
.getLength());
766 CPPUNIT_TEST_FIXTURE(Chart2ImportTest
, testFdo78080
)
768 loadFromFile(u
"xlsx/fdo78080.xlsx");
769 Reference
<chart2::XChartDocument
> xChartDoc
= getChartDocFromSheet(0);
770 CPPUNIT_ASSERT(xChartDoc
.is());
772 Reference
<chart2::XTitled
> xTitled(xChartDoc
, uno::UNO_QUERY_THROW
);
773 Reference
<chart2::XTitle
> xTitle
= xTitled
->getTitleObject();
774 CPPUNIT_ASSERT(!xTitle
.is());
777 CPPUNIT_TEST_FIXTURE(Chart2ImportTest
, testTdf127811
)
779 loadFromFile(u
"pptx/tdf127811.pptx");
780 Reference
<chart2::XChartDocument
> xChartDoc(getChartDocFromDrawImpress(0, 0), uno::UNO_QUERY
);
781 CPPUNIT_ASSERT(xChartDoc
.is());
783 Reference
<chart2::XChartType
> xCT
= getChartTypeFromDoc(xChartDoc
, 0);
784 CPPUNIT_ASSERT(xCT
.is());
786 std::vector
<uno::Sequence
<uno::Any
> > aLabels
= getDataSeriesLabelsFromChartType(xCT
);
787 CPPUNIT_ASSERT_EQUAL(size_t(2), aLabels
.size());
789 // Without the fix in place, this test would have failed with
790 // - Expected: 1. first
791 // - Actual : 2. second
792 CPPUNIT_ASSERT_EQUAL(u
"1. first"_ustr
, aLabels
[0][0].get
<OUString
>());
793 CPPUNIT_ASSERT_EQUAL(u
"2. second"_ustr
, aLabels
[1][0].get
<OUString
>());
796 CPPUNIT_TEST_FIXTURE(Chart2ImportTest
, testTdf86624
)
798 // manually placed legends
799 loadFromFile(u
"ods/tdf86624.ods");
800 uno::Reference
< chart2::XChartDocument
> xChart2Doc
= getChartDocFromSheet(0);
801 uno::Reference
< chart::XChartDocument
> xChartDoc (xChart2Doc
, uno::UNO_QUERY
);
802 uno::Reference
<drawing::XShape
> xLegend
= xChartDoc
->getLegend();
803 awt::Point aPos
= xLegend
->getPosition();
804 CPPUNIT_ASSERT(aPos
.X
> 5000); // real value for me is above 8000 but before bug fix is below 1000
805 CPPUNIT_ASSERT(aPos
.Y
> 4000); // real value for ms is above 7000
808 CPPUNIT_TEST_FIXTURE(Chart2ImportTest
, testTdf105517
)
810 loadFromFile(u
"pptx/tdf105517.pptx");
811 Reference
<chart2::XChartDocument
> xChartDoc(getChartDocFromDrawImpress(0, 0), uno::UNO_QUERY
);
812 CPPUNIT_ASSERT(xChartDoc
.is());
814 Reference
<chart2::XCoordinateSystemContainer
> xCoordContainer(xChartDoc
->getFirstDiagram(), uno::UNO_QUERY
);
815 CPPUNIT_ASSERT(xCoordContainer
.is());
816 Reference
<chart2::XChartTypeContainer
> xChartTypeContainer(xCoordContainer
->getCoordinateSystems()[0], uno::UNO_QUERY
);
817 CPPUNIT_ASSERT(xChartTypeContainer
.is());
818 Reference
<chart2::XDataSeriesContainer
> xDSContainer(xChartTypeContainer
->getChartTypes()[0], uno::UNO_QUERY
);
819 CPPUNIT_ASSERT(xDSContainer
.is());
820 Reference
<beans::XPropertySet
> xPropSet1(xDSContainer
->getDataSeries()[0], uno::UNO_QUERY
);
821 CPPUNIT_ASSERT(xPropSet1
.is());
823 tools::Long lineColor
;
824 xPropSet1
->getPropertyValue(u
"Color"_ustr
) >>= lineColor
;
825 // incorrect line color was 0x4a7ebb due to not handling themeOverride
826 CPPUNIT_ASSERT_EQUAL(tools::Long(0xeaa700), lineColor
);
828 Reference
<beans::XPropertySet
> xPropSet2(xDSContainer
->getDataSeries()[1], uno::UNO_QUERY
);
829 CPPUNIT_ASSERT(xPropSet2
.is());
831 xPropSet2
->getPropertyValue(u
"Color"_ustr
) >>= lineColor
;
832 // incorrect line color was 0x98b855
833 CPPUNIT_ASSERT_EQUAL(tools::Long(0x1e69a8), lineColor
);
836 CPPUNIT_TEST_FIXTURE(Chart2ImportTest
, testTdf106217
)
838 loadFromFile(u
"pptx/tdf106217.pptx");
839 uno::Reference
< chart::XChartDocument
> xChartDoc
= getChartDocFromDrawImpress(0, 0);
840 CPPUNIT_ASSERT(xChartDoc
.is());
842 uno::Reference
<drawing::XDrawPageSupplier
> xDrawPageSupplier(xChartDoc
, uno::UNO_QUERY
);
843 uno::Reference
<drawing::XDrawPage
> xDrawPage
= xDrawPageSupplier
->getDrawPage();
844 uno::Reference
<drawing::XShape
> xCircle(xDrawPage
->getByIndex(1), uno::UNO_QUERY
);
845 CPPUNIT_ASSERT(xCircle
.is());
847 uno::Reference
<container::XNamed
> xNamedShape(xCircle
, uno::UNO_QUERY
);
848 CPPUNIT_ASSERT_EQUAL(u
"Oval 1"_ustr
, xNamedShape
->getName());
850 awt::Point aPosition
= xCircle
->getPosition();
851 CPPUNIT_ASSERT_EQUAL(sal_Int32(6870), aPosition
.X
);
852 CPPUNIT_ASSERT_EQUAL(sal_Int32(7261), aPosition
.Y
);
853 awt::Size aSize
= xCircle
->getSize();
854 CPPUNIT_ASSERT_EQUAL(sal_Int32(2701), aSize
.Width
);
855 CPPUNIT_ASSERT_EQUAL(sal_Int32(2700), aSize
.Height
);
858 CPPUNIT_TEST_FIXTURE(Chart2ImportTest
, testTdf108021
)
860 // Tdf108021 : To check TextBreak value is true.
861 loadFromFile(u
"ods/tdf108021.ods");
862 uno::Reference
< chart::XDiagram
> mxDiagram
;
863 uno::Reference
< beans::XPropertySet
> xAxisProp
;
864 bool bTextBreak
= false;
865 uno::Reference
< chart::XChartDocument
> xChartDoc ( getChartCompFromSheet( 0, 0), UNO_QUERY_THROW
);
866 mxDiagram
.set(xChartDoc
->getDiagram());
867 CPPUNIT_ASSERT(mxDiagram
.is());
868 uno::Reference
< chart::XAxisXSupplier
> xAxisXSupp( mxDiagram
, uno::UNO_QUERY
);
869 CPPUNIT_ASSERT(xAxisXSupp
.is());
870 xAxisProp
= xAxisXSupp
->getXAxis();
871 xAxisProp
->getPropertyValue(u
"TextBreak"_ustr
) >>= bTextBreak
;
872 // Expected value of 'TextBreak' is true
873 CPPUNIT_ASSERT(bTextBreak
);
876 CPPUNIT_TEST_FIXTURE(Chart2ImportTest
, testTdf100084
)
878 // The test file was created with IBM Cognos, make sure there is a diagram.
879 loadFromFile(u
"xlsx/tdf100084.xlsx");
880 Reference
<chart2::XChartDocument
> xChartDoc
= getChartDocFromSheet(0);
881 CPPUNIT_ASSERT_MESSAGE("failed to load chart", xChartDoc
.is());
882 Reference
<beans::XPropertySet
> xDiagram(xChartDoc
->getFirstDiagram(), UNO_QUERY
);
883 CPPUNIT_ASSERT_MESSAGE("There should be a Diagram.", xDiagram
.is());
886 CPPUNIT_TEST_FIXTURE(Chart2ImportTest
, testTdf124817
)
888 loadFromFile(u
"xlsx/tdf124817.xlsx");
889 Reference
<chart2::XChartDocument
> xChartDoc
= getChartDocFromSheet(0);
890 CPPUNIT_ASSERT_MESSAGE("failed to load chart", xChartDoc
.is());
892 uno::Reference
<chart2::XDataSeries
> xDataSeries
;
893 chart2::Symbol aSymblProp
;
895 // Check the symbol of data series 1 (marker style none)
896 xDataSeries
= getDataSeriesFromDoc(xChartDoc
, 0);
897 CPPUNIT_ASSERT(xDataSeries
.is());
898 uno::Reference
<beans::XPropertySet
> xPropSet_0(xDataSeries
, uno::UNO_QUERY_THROW
);
899 CPPUNIT_ASSERT((xPropSet_0
->getPropertyValue(u
"Symbol"_ustr
) >>= aSymblProp
));
900 CPPUNIT_ASSERT_EQUAL(chart2::SymbolStyle_NONE
, aSymblProp
.Style
);
902 // Check the symbol of data series 2 (marker style square)
903 xDataSeries
= getDataSeriesFromDoc(xChartDoc
, 1);
904 CPPUNIT_ASSERT(xDataSeries
.is());
905 uno::Reference
<beans::XPropertySet
> xPropSet_1(xDataSeries
, uno::UNO_QUERY_THROW
);
906 CPPUNIT_ASSERT((xPropSet_1
->getPropertyValue(u
"Symbol"_ustr
) >>= aSymblProp
));
907 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32
>(0xED7D31), aSymblProp
.FillColor
);
909 // Check the symbol of data series 3 (marker style diagonal cross)
910 xDataSeries
= getDataSeriesFromDoc(xChartDoc
, 2);
911 CPPUNIT_ASSERT(xDataSeries
.is());
912 uno::Reference
<beans::XPropertySet
> xPropSet_2(xDataSeries
, uno::UNO_QUERY_THROW
);
913 CPPUNIT_ASSERT((xPropSet_2
->getPropertyValue(u
"Symbol"_ustr
) >>= aSymblProp
));
914 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32
>(0xFF0000), aSymblProp
.BorderColor
);
917 CPPUNIT_TEST_FIXTURE(Chart2ImportTest
, testTdf126033
)
919 loadFromFile(u
"xlsx/tdf126033.xlsx");
920 Reference
<chart2::XChartDocument
> xChartDoc
= getChartDocFromSheet(0);
921 CPPUNIT_ASSERT_MESSAGE("failed to load chart", xChartDoc
.is());
923 // Check symbol style and size of data points
924 chart2::Symbol aSymblProp
;
925 uno::Reference
<chart2::XDataSeries
> xDataSeries(getDataSeriesFromDoc(xChartDoc
, 0));
926 CPPUNIT_ASSERT(xDataSeries
.is());
927 uno::Reference
<beans::XPropertySet
> xPropertySet(xDataSeries
->getDataPointByIndex(0), uno::UNO_SET_THROW
);
928 CPPUNIT_ASSERT(xPropertySet
->getPropertyValue(u
"Symbol"_ustr
) >>= aSymblProp
);
929 CPPUNIT_ASSERT_EQUAL(chart2::SymbolStyle_NONE
, aSymblProp
.Style
);
930 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32
>(176), aSymblProp
.Size
.Width
);
931 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32
>(176), aSymblProp
.Size
.Height
);
934 void Chart2ImportTest::testTransparentBackground(std::u16string_view filename
)
936 loadFromFile(filename
);
937 uno::Reference
< chart2::XChartDocument
> xChartDoc
= getChartDocFromSheet(0);
938 CPPUNIT_ASSERT_MESSAGE("failed to load chart", xChartDoc
.is());
940 uno::Reference
< chart::XChartDocument
> xChart2Doc (xChartDoc
, uno::UNO_QUERY
);
941 CPPUNIT_ASSERT_MESSAGE("failed to load chart", xChart2Doc
.is());
943 Reference
< beans::XPropertySet
> xPropSet
= xChart2Doc
->getArea();
944 CPPUNIT_ASSERT_MESSAGE("failed to get Area", xPropSet
.is());
946 css::drawing::FillStyle aStyle
;
947 xPropSet
-> getPropertyValue(u
"FillStyle"_ustr
) >>= aStyle
;
949 CPPUNIT_ASSERT_EQUAL_MESSAGE("Background needs to be with solid fill style", css::drawing::FillStyle_SOLID
, aStyle
);
952 // 2 test methods here so that tearDown() can dispose the document
953 CPPUNIT_TEST_FIXTURE(Chart2ImportTest
, testFdo54361
)
955 testTransparentBackground(u
"xlsx/fdo54361.xlsx");
957 CPPUNIT_TEST_FIXTURE(Chart2ImportTest
, testFdo54361_1
)
959 testTransparentBackground(u
"xlsx/fdo54361-1.xlsx");
962 CPPUNIT_TEST_FIXTURE(Chart2ImportTest
, testAutoBackgroundXLSX
)
964 loadFromFile(u
"xlsx/chart-auto-background.xlsx");
965 uno::Reference
<chart2::XChartDocument
> xChartDoc
= getChartDocFromSheet(0);
966 CPPUNIT_ASSERT_MESSAGE("failed to load chart", xChartDoc
.is());
968 // "Automatic" chart background fill in xlsx should be loaded as solid white.
969 Reference
<beans::XPropertySet
> xPropSet
= xChartDoc
->getPageBackground();
970 CPPUNIT_ASSERT(xPropSet
.is());
971 drawing::FillStyle eStyle
= xPropSet
->getPropertyValue(u
"FillStyle"_ustr
).get
<drawing::FillStyle
>();
972 sal_Int32 nColor
= xPropSet
->getPropertyValue(u
"FillColor"_ustr
).get
<sal_Int32
>();
973 CPPUNIT_ASSERT_EQUAL_MESSAGE("'Automatic' chart background fill in xlsx should be loaded as solid fill.",
974 drawing::FillStyle_SOLID
, eStyle
);
975 CPPUNIT_ASSERT_EQUAL_MESSAGE("'Automatic' chart background fill in xlsx should be loaded as solid white.",
976 sal_Int32(0x00FFFFFF), sal_Int32(nColor
& 0x00FFFFFF)); // highest 2 bytes are transparency which we ignore here.
979 CPPUNIT_TEST_FIXTURE(Chart2ImportTest
, testAutoChartAreaBorderPropXLSX
)
981 loadFromFile(u
"xlsx/chart-area-style-border.xlsx");
982 uno::Reference
<chart2::XChartDocument
> xChartDoc
= getChartDocFromSheet(0);
983 CPPUNIT_ASSERT_MESSAGE("failed to load chart", xChartDoc
.is());
985 // Test "Automatic" chartarea border style/color/width.
986 Reference
<beans::XPropertySet
> xPropSet
= xChartDoc
->getPageBackground();
987 CPPUNIT_ASSERT(xPropSet
.is());
988 drawing::LineStyle eStyle
= xPropSet
->getPropertyValue(u
"LineStyle"_ustr
).get
<drawing::LineStyle
>();
989 sal_Int32 nColor
= xPropSet
->getPropertyValue(u
"LineColor"_ustr
).get
<sal_Int32
>();
990 sal_Int32 nWidth
= xPropSet
->getPropertyValue(u
"LineWidth"_ustr
).get
<sal_Int32
>();
991 CPPUNIT_ASSERT_EQUAL_MESSAGE("'Automatic' chartarea border should be loaded as solid style.",
992 drawing::LineStyle_SOLID
, eStyle
);
993 CPPUNIT_ASSERT_EQUAL_MESSAGE("'Automatic' chartarea border color should be loaded as light gray.",
994 sal_Int32(0xD9D9D9), nColor
);
995 CPPUNIT_ASSERT_EQUAL_MESSAGE("'Automatic' chartarea border width should be loaded as 0.75 pt (~0.026 cm)",
996 sal_Int32(26), nWidth
);
999 CPPUNIT_TEST_FIXTURE(Chart2ImportTest
, testAutoChartAreaBorderPropPPTX
)
1001 loadFromFile(u
"pptx/tdf150176.pptx");
1002 Reference
<chart2::XChartDocument
> xChartDoc(getChartDocFromDrawImpress(0, 0), uno::UNO_QUERY
);
1003 CPPUNIT_ASSERT_MESSAGE("failed to load chart", xChartDoc
.is());
1005 // Test "Automatic" chartarea border style/color/width.
1006 Reference
<beans::XPropertySet
> xPropSet
= xChartDoc
->getPageBackground();
1007 CPPUNIT_ASSERT(xPropSet
.is());
1008 drawing::LineStyle eStyle
= xPropSet
->getPropertyValue(u
"LineStyle"_ustr
).get
<drawing::LineStyle
>();
1009 CPPUNIT_ASSERT_EQUAL_MESSAGE("'Automatic' chartarea border should be loaded as none style for pptx.",
1010 drawing::LineStyle_NONE
, eStyle
);
1013 CPPUNIT_TEST_FIXTURE(Chart2ImportTest
, testChartAreaStyleBackgroundXLSX
)
1015 loadFromFile(u
"xlsx/chart-area-style-background.xlsx");
1016 uno::Reference
<chart2::XChartDocument
> xChartDoc
= getChartDocFromSheet(0);
1017 CPPUNIT_ASSERT_MESSAGE("failed to load chart", xChartDoc
.is());
1019 // "Automatic" chart background fill in xlsx should be loaded as solid white.
1020 Reference
<beans::XPropertySet
> xPropSet
= xChartDoc
->getPageBackground();
1021 CPPUNIT_ASSERT(xPropSet
.is());
1022 drawing::FillStyle eStyle
= xPropSet
->getPropertyValue(u
"FillStyle"_ustr
).get
<drawing::FillStyle
>();
1023 sal_Int32 nColor
= xPropSet
->getPropertyValue(u
"FillColor"_ustr
).get
<sal_Int32
>();
1024 CPPUNIT_ASSERT_EQUAL_MESSAGE("'Automatic' chart background fill in xlsx should be loaded as solid fill.",
1025 drawing::FillStyle_SOLID
, eStyle
);
1026 CPPUNIT_ASSERT_EQUAL_MESSAGE("'Automatic' chart background fill in xlsx should be loaded as solid white.",
1027 sal_Int32(0), nColor
);
1030 CPPUNIT_TEST_FIXTURE(Chart2ImportTest
, testChartHatchFillXLSX
)
1032 loadFromFile(u
"xlsx/chart-hatch-fill.xlsx");
1033 uno::Reference
<chart2::XChartDocument
> xChartDoc
= getChartDocFromSheet(0);
1034 CPPUNIT_ASSERT_MESSAGE("failed to load chart", xChartDoc
.is());
1036 // Check the chart background FillStyle is HATCH
1037 Reference
<beans::XPropertySet
> xPropSet
= xChartDoc
->getPageBackground();
1038 CPPUNIT_ASSERT(xPropSet
.is());
1039 drawing::FillStyle eStyle
= xPropSet
->getPropertyValue(u
"FillStyle"_ustr
).get
<drawing::FillStyle
>();
1041 CPPUNIT_ASSERT_EQUAL_MESSAGE("Chart background fill in this xlsx should be loaded as hatch fill.",
1042 drawing::FillStyle_HATCH
, eStyle
);
1044 // Check the FillBackground of chart background
1045 bool bBackgroundFill
= false;
1046 xPropSet
->getPropertyValue(u
"FillBackground"_ustr
) >>= bBackgroundFill
;
1047 CPPUNIT_ASSERT(bBackgroundFill
);
1049 Color nBackgroundColor
;
1050 xPropSet
->getPropertyValue(u
"FillColor"_ustr
) >>= nBackgroundColor
;
1051 CPPUNIT_ASSERT_EQUAL(COL_WHITE
, nBackgroundColor
);
1053 // Check the datapoint has HatchName value
1054 uno::Reference
<chart2::XDataSeries
> xDataSeries(getDataSeriesFromDoc(xChartDoc
, 0));
1055 CPPUNIT_ASSERT(xDataSeries
.is());
1057 uno::Reference
<beans::XPropertySet
> xPropertySet(xDataSeries
->getDataPointByIndex(1), uno::UNO_SET_THROW
);
1058 OUString sHatchName
;
1059 xPropertySet
->getPropertyValue(u
"HatchName"_ustr
) >>= sHatchName
;
1060 CPPUNIT_ASSERT(!sHatchName
.isEmpty());
1062 // Check the FillBackground of datapoint
1063 bool bBackgroundFillofDatapoint
= false;
1064 xPropertySet
->getPropertyValue(u
"FillBackground"_ustr
) >>= bBackgroundFillofDatapoint
;
1065 CPPUNIT_ASSERT(bBackgroundFillofDatapoint
);
1067 sal_Int32 nBackgroundColorofDatapoint
;
1068 xPropertySet
->getPropertyValue(u
"FillColor"_ustr
) >>= nBackgroundColorofDatapoint
;
1069 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32
>(0x00B050), nBackgroundColorofDatapoint
);
1072 CPPUNIT_TEST_FIXTURE(Chart2ImportTest
, testAxisTextRotationXLSX
)
1074 loadFromFile(u
"xlsx/axis-label-rotation.xlsx");
1075 uno::Reference
<chart2::XChartDocument
> xChartDoc
= getChartDocFromSheet(0);
1076 CPPUNIT_ASSERT_MESSAGE("failed to load chart", xChartDoc
.is());
1078 Reference
<chart2::XAxis
> xYAxis
= getAxisFromDoc(xChartDoc
, 0, 0, 0);
1079 CPPUNIT_ASSERT(xYAxis
.is());
1081 Reference
<beans::XPropertySet
> xPS(xYAxis
, uno::UNO_QUERY_THROW
);
1082 double nRotation
= 0;
1083 bool bSuccess
= xPS
->getPropertyValue(u
"TextRotation"_ustr
) >>= nRotation
;
1085 CPPUNIT_ASSERT(bSuccess
);
1086 CPPUNIT_ASSERT_DOUBLES_EQUAL(90, nRotation
, 1e-10);
1089 CPPUNIT_TEST_FIXTURE(Chart2ImportTest
, testTextCanOverlapXLSX
)
1091 // fdo#84647 : To check textoverlap value is imported correctly.
1092 loadFromFile(u
"xlsx/chart-text-can-overlap.xlsx");
1093 uno::Reference
< chart::XDiagram
> mxDiagram
;
1094 uno::Reference
< beans::XPropertySet
> xAxisProp
;
1095 bool bTextCanOverlap
= false;
1096 uno::Reference
< chart::XChartDocument
> xChartDoc ( getChartCompFromSheet( 0, 0), UNO_QUERY_THROW
);
1097 mxDiagram
.set(xChartDoc
->getDiagram());
1098 CPPUNIT_ASSERT(mxDiagram
.is());
1099 uno::Reference
< chart::XAxisXSupplier
> xAxisXSupp( mxDiagram
, uno::UNO_QUERY
);
1100 CPPUNIT_ASSERT(xAxisXSupp
.is());
1101 xAxisProp
= xAxisXSupp
->getXAxis();
1102 xAxisProp
->getPropertyValue(u
"TextCanOverlap"_ustr
) >>= bTextCanOverlap
;
1103 CPPUNIT_ASSERT(!bTextCanOverlap
);
1106 CPPUNIT_TEST_FIXTURE(Chart2ImportTest
, testTextBreakXLSX
)
1108 // tdf#122091: To check textbreak value is true in case of 0° degree of Axis label rotation.
1109 loadFromFile(u
"xlsx/chart_label_text_break.xlsx");
1110 uno::Reference
< chart::XDiagram
> mxDiagram
;
1111 uno::Reference
< beans::XPropertySet
> xAxisProp
;
1112 bool textBreak
= false;
1113 uno::Reference
< chart::XChartDocument
> xChartDoc ( getChartCompFromSheet( 0, 0), UNO_QUERY_THROW
);
1114 CPPUNIT_ASSERT(xChartDoc
.is());
1115 mxDiagram
.set(xChartDoc
->getDiagram());
1116 CPPUNIT_ASSERT(mxDiagram
.is());
1117 uno::Reference
< chart::XAxisXSupplier
> xAxisXSupp( mxDiagram
, uno::UNO_QUERY
);
1118 CPPUNIT_ASSERT(xAxisXSupp
.is());
1119 xAxisProp
= xAxisXSupp
->getXAxis();
1120 xAxisProp
->getPropertyValue(u
"TextBreak"_ustr
) >>= textBreak
;
1121 // Expected value of 'TextBreak' is true
1122 CPPUNIT_ASSERT(textBreak
);
1125 CPPUNIT_TEST_FIXTURE(Chart2ImportTest
, testNumberFormatsXLSX
)
1127 loadFromFile(u
"xlsx/number-formats.xlsx");
1128 Reference
<chart2::XChartDocument
> xChartDoc
= getChartDocFromSheet(0);
1129 CPPUNIT_ASSERT_MESSAGE("failed to load chart", xChartDoc
.is());
1131 uno::Reference
<chart2::XDataSeries
> xDataSeries(getDataSeriesFromDoc(xChartDoc
, 0));
1132 CPPUNIT_ASSERT(xDataSeries
.is());
1133 uno::Reference
<beans::XPropertySet
> xPropertySet
;
1134 chart2::DataPointLabel aLabel
;
1135 sal_Int32 nNumberFormat
;
1136 bool bLinkNumberFormatToSource
= false;
1137 const sal_Int32 nChartDataNumberFormat
= getNumberFormat(
1138 xChartDoc
, u
"_(\"$\"* #,##0_);_(\"$\"* \\(#,##0\\);_(\"$\"* \"-\"??_);_(@_)"_ustr
);
1140 xPropertySet
.set(xDataSeries
->getDataPointByIndex(0), uno::UNO_SET_THROW
);
1141 xPropertySet
->getPropertyValue(u
"Label"_ustr
) >>= aLabel
;
1142 CPPUNIT_ASSERT_EQUAL(sal_True
, aLabel
.ShowNumber
);
1143 CPPUNIT_ASSERT_EQUAL(sal_True
, aLabel
.ShowNumberInPercent
);
1144 xPropertySet
->getPropertyValue(CHART_UNONAME_NUMFMT
) >>= nNumberFormat
;
1145 CPPUNIT_ASSERT_EQUAL(nChartDataNumberFormat
, nNumberFormat
);
1146 bool bSuccess
= xPropertySet
->getPropertyValue(u
"PercentageNumberFormat"_ustr
) >>= nNumberFormat
;
1147 CPPUNIT_ASSERT_EQUAL(false, bSuccess
);
1148 bSuccess
= xPropertySet
->getPropertyValue(CHART_UNONAME_LINK_TO_SRC_NUMFMT
) >>= bLinkNumberFormatToSource
;
1149 CPPUNIT_ASSERT_MESSAGE("\"LinkNumberFormatToSource\" should be set to true.", bSuccess
);
1150 CPPUNIT_ASSERT_MESSAGE("\"LinkNumberFormatToSource\" should be set to true.", bLinkNumberFormatToSource
);
1152 xPropertySet
.set(xDataSeries
->getDataPointByIndex(1), uno::UNO_SET_THROW
);
1153 xPropertySet
->getPropertyValue(u
"Label"_ustr
) >>= aLabel
;
1154 CPPUNIT_ASSERT_EQUAL(sal_True
, aLabel
.ShowNumber
);
1155 CPPUNIT_ASSERT_EQUAL(sal_False
, aLabel
.ShowNumberInPercent
);
1156 xPropertySet
->getPropertyValue(CHART_UNONAME_NUMFMT
) >>= nNumberFormat
;
1157 CPPUNIT_ASSERT_EQUAL(nChartDataNumberFormat
, nNumberFormat
);
1158 bSuccess
= xPropertySet
->getPropertyValue(u
"PercentageNumberFormat"_ustr
) >>= nNumberFormat
;
1159 CPPUNIT_ASSERT_EQUAL(false, bSuccess
);
1160 bSuccess
= xPropertySet
->getPropertyValue(CHART_UNONAME_LINK_TO_SRC_NUMFMT
) >>= bLinkNumberFormatToSource
;
1161 CPPUNIT_ASSERT_MESSAGE("\"LinkNumberFormatToSource\" should be set to true.", bSuccess
);
1162 CPPUNIT_ASSERT_MESSAGE("\"LinkNumberFormatToSource\" should be set to true.", bLinkNumberFormatToSource
);
1164 xPropertySet
.set(xDataSeries
->getDataPointByIndex(2), uno::UNO_SET_THROW
);
1165 xPropertySet
->getPropertyValue(u
"Label"_ustr
) >>= aLabel
;
1166 CPPUNIT_ASSERT_EQUAL(sal_False
, aLabel
.ShowNumber
);
1167 CPPUNIT_ASSERT_EQUAL(sal_True
, aLabel
.ShowNumberInPercent
);
1168 xPropertySet
->getPropertyValue(CHART_UNONAME_NUMFMT
) >>= nNumberFormat
;
1169 CPPUNIT_ASSERT_EQUAL(nChartDataNumberFormat
, nNumberFormat
);
1170 bSuccess
= xPropertySet
->getPropertyValue(u
"PercentageNumberFormat"_ustr
) >>= nNumberFormat
;
1171 CPPUNIT_ASSERT_EQUAL(false, bSuccess
);
1172 bSuccess
= xPropertySet
->getPropertyValue(CHART_UNONAME_LINK_TO_SRC_NUMFMT
) >>= bLinkNumberFormatToSource
;
1173 CPPUNIT_ASSERT_MESSAGE("\"LinkNumberFormatToSource\" should be set to true.", bSuccess
);
1174 CPPUNIT_ASSERT_MESSAGE("\"LinkNumberFormatToSource\" should be set to true.", bLinkNumberFormatToSource
);
1177 CPPUNIT_TEST_FIXTURE(Chart2ImportTest
, testNumberFormatsDOCX
)
1179 loadFromFile(u
"docx/tdf132174.docx");
1181 uno::Reference
< chart2::XChartDocument
> xChartDoc(getChartDocFromWriter(0), uno::UNO_QUERY
);
1182 CPPUNIT_ASSERT(xChartDoc
.is());
1184 css::uno::Reference
<chart2::XDiagram
> xDiagram(xChartDoc
->getFirstDiagram(), UNO_SET_THROW
);
1185 Reference
<chart2::XDataSeries
> xDataSeries
= getDataSeriesFromDoc(xChartDoc
, 0);
1186 uno::Reference
<beans::XPropertySet
> xPropertySet(xDataSeries
, uno::UNO_QUERY_THROW
);
1187 CPPUNIT_ASSERT(xPropertySet
.is());
1189 sal_Int32 nNumberFormat
;
1190 bool bLinkNumberFormatToSource
= true;
1191 const sal_Int32 nChartDataNumberFormat
= getNumberFormat(xChartDoc
, u
"0%"_ustr
);
1192 xPropertySet
->getPropertyValue(CHART_UNONAME_NUMFMT
) >>= nNumberFormat
;
1193 CPPUNIT_ASSERT_EQUAL(nChartDataNumberFormat
, nNumberFormat
);
1194 xPropertySet
->getPropertyValue(CHART_UNONAME_LINK_TO_SRC_NUMFMT
) >>= bLinkNumberFormatToSource
;
1195 // LinkNumberFormatToSource should be set to false even if the original OOXML contain a true value,
1196 // because the inner data table of charts have no own number format!
1197 CPPUNIT_ASSERT_MESSAGE("\"LinkNumberFormatToSource\" should be set to false.", !bLinkNumberFormatToSource
);
1200 loadFromFile(u
"docx/tdf136650.docx");
1202 uno::Reference
< chart2::XChartDocument
> xChartDoc(getChartDocFromWriter(0), uno::UNO_QUERY
);
1203 CPPUNIT_ASSERT(xChartDoc
.is());
1205 css::uno::Reference
<chart2::XDiagram
> xDiagram(xChartDoc
->getFirstDiagram(), UNO_SET_THROW
);
1206 Reference
<chart2::XDataSeries
> xDataSeries
= getDataSeriesFromDoc(xChartDoc
, 0);
1207 CPPUNIT_ASSERT(xDataSeries
.is());
1208 Reference
<beans::XPropertySet
> xPropertySet(xDataSeries
->getDataPointByIndex(1), uno::UNO_SET_THROW
);
1210 sal_Int32 nNumberFormat
;
1211 bool bLinkNumberFormatToSource
= true;
1212 const sal_Int32 nChartDataNumberFormat
= getNumberFormat(xChartDoc
, u
"0%"_ustr
);
1213 xPropertySet
->getPropertyValue(CHART_UNONAME_NUMFMT
) >>= nNumberFormat
;
1214 CPPUNIT_ASSERT_EQUAL(nChartDataNumberFormat
, nNumberFormat
);
1215 xPropertySet
->getPropertyValue(CHART_UNONAME_LINK_TO_SRC_NUMFMT
) >>= bLinkNumberFormatToSource
;
1216 // LinkNumberFormatToSource should be set to false even if the original OOXML file contain a true value,
1217 // because the inner data table of charts have no own number format!
1218 CPPUNIT_ASSERT_MESSAGE("\"LinkNumberFormatToSource\" should be set to false.", !bLinkNumberFormatToSource
);
1222 CPPUNIT_TEST_FIXTURE(Chart2ImportTest
, testPercentageNumberFormatsDOCX
)
1224 loadFromFile(u
"docx/tdf133632.docx");
1225 uno::Reference
< chart2::XChartDocument
> xChartDoc(getChartDocFromWriter(0), uno::UNO_QUERY
);
1226 CPPUNIT_ASSERT(xChartDoc
.is());
1228 css::uno::Reference
<chart2::XDiagram
> xDiagram(xChartDoc
->getFirstDiagram(), UNO_SET_THROW
);
1229 Reference
<chart2::XDataSeries
> xDataSeries
= getDataSeriesFromDoc(xChartDoc
, 0);
1230 uno::Reference
<beans::XPropertySet
> xPropertySet(xDataSeries
, uno::UNO_QUERY_THROW
);
1231 CPPUNIT_ASSERT(xPropertySet
.is());
1233 bool bLinkNumberFormatToSource
= false;
1234 chart2::DataPointLabel aLabel
;
1235 xPropertySet
->getPropertyValue(u
"Label"_ustr
) >>= aLabel
;
1236 CPPUNIT_ASSERT_EQUAL(sal_False
, aLabel
.ShowNumber
);
1237 CPPUNIT_ASSERT_EQUAL(sal_True
, aLabel
.ShowNumberInPercent
);
1238 bool bSuccess
= xPropertySet
->getPropertyValue(CHART_UNONAME_LINK_TO_SRC_NUMFMT
) >>= bLinkNumberFormatToSource
;
1239 CPPUNIT_ASSERT_MESSAGE("\"LinkNumberFormatToSource\" should be set to true.", bSuccess
);
1240 CPPUNIT_ASSERT_MESSAGE("\"LinkNumberFormatToSource\" should be set to true.", bLinkNumberFormatToSource
);
1243 CPPUNIT_TEST_FIXTURE(Chart2ImportTest
, testAutoTitleDelDefaultValue2007XLSX
)
1245 // below are OOXML default value tests for cases
1246 // where we fixed the handling of MSO 2007 vs OOXML
1247 loadFromFile(u
"xlsx/autotitledel_2007.xlsx");
1248 Reference
<chart2::XChartDocument
> xChartDoc
= getChartDocFromSheet(0);
1249 CPPUNIT_ASSERT_MESSAGE("failed to load chart", xChartDoc
.is());
1251 Reference
<chart2::XTitled
> xTitled(xChartDoc
, uno::UNO_QUERY_THROW
);
1252 OUString aTitle
= getTitleString(xTitled
);
1253 CPPUNIT_ASSERT_MESSAGE("autoTitleDel default value is false in MSO 2007 documents",
1257 CPPUNIT_TEST_FIXTURE(Chart2ImportTest
, testAutoTitleDelDefaultValue2013XLSX
)
1259 loadFromFile(u
"xlsx/autotitledel_2013.xlsx");
1260 Reference
<chart2::XChartDocument
> xChartDoc
= getChartDocFromSheet(0);
1261 CPPUNIT_ASSERT_MESSAGE("failed to load chart", xChartDoc
.is());
1263 Reference
<chart2::XTitled
> xTitled(xChartDoc
, uno::UNO_QUERY_THROW
);
1264 uno::Reference
<chart2::XTitle
> xTitle
= xTitled
->getTitleObject();
1265 CPPUNIT_ASSERT_MESSAGE("autoTitleDel default value is true in the OOXML spec",
1269 CPPUNIT_TEST_FIXTURE(Chart2ImportTest
, testDispBlanksAsDefaultValue2007XLSX
)
1271 loadFromFile(u
"xlsx/dispBlanksAs_2007.xlsx");
1272 Reference
<chart2::XChartDocument
> xChartDoc
= getChartDocFromSheet(0);
1273 CPPUNIT_ASSERT_MESSAGE("failed to load chart", xChartDoc
.is());
1275 Reference
<beans::XPropertySet
> xDiagram(xChartDoc
->getFirstDiagram(), UNO_QUERY
);
1276 CPPUNIT_ASSERT(xDiagram
.is());
1277 uno::Any aAny
= xDiagram
->getPropertyValue(u
"MissingValueTreatment"_ustr
);
1278 sal_Int32 nMissingValueTreatment
= -2;
1279 CPPUNIT_ASSERT(aAny
>>= nMissingValueTreatment
);
1280 CPPUNIT_ASSERT_EQUAL(chart::MissingValueTreatment::LEAVE_GAP
, nMissingValueTreatment
);
1283 CPPUNIT_TEST_FIXTURE(Chart2ImportTest
, testDispBlanksAsDefaultValue2013XLSX
)
1285 loadFromFile(u
"xlsx/dispBlanksAs_2013.xlsx");
1286 Reference
<chart2::XChartDocument
> xChartDoc
= getChartDocFromSheet(0);
1287 CPPUNIT_ASSERT_MESSAGE("failed to load chart", xChartDoc
.is());
1289 Reference
<beans::XPropertySet
> xDiagram(xChartDoc
->getFirstDiagram(), UNO_QUERY
);
1290 CPPUNIT_ASSERT(xDiagram
.is());
1291 uno::Any aAny
= xDiagram
->getPropertyValue(u
"MissingValueTreatment"_ustr
);
1292 sal_Int32 nMissingValueTreatment
= -2;
1293 CPPUNIT_ASSERT(aAny
>>= nMissingValueTreatment
);
1294 CPPUNIT_ASSERT_EQUAL(chart::MissingValueTreatment::USE_ZERO
, nMissingValueTreatment
);
1297 CPPUNIT_TEST_FIXTURE(Chart2ImportTest
, testSmoothDefaultValue2007XLSX
)
1299 loadFromFile(u
"xlsx/smoothed_series2007.xlsx");
1300 Reference
<chart2::XChartDocument
> xChartDoc
= getChartDocFromSheet(0);
1301 CPPUNIT_ASSERT_MESSAGE("failed to load chart", xChartDoc
.is());
1302 CPPUNIT_ASSERT(xChartDoc
.is());
1304 Reference
< chart2::XChartType
> xChartType
= getChartTypeFromDoc( xChartDoc
, 0 );
1305 CPPUNIT_ASSERT(xChartType
.is());
1307 Reference
< beans::XPropertySet
> xPropSet( xChartType
, UNO_QUERY
);
1308 CPPUNIT_ASSERT(xPropSet
.is());
1310 chart2::CurveStyle eCurveStyle
;
1311 xPropSet
->getPropertyValue(u
"CurveStyle"_ustr
) >>= eCurveStyle
;
1312 CPPUNIT_ASSERT_EQUAL(chart2::CurveStyle_LINES
, eCurveStyle
);
1315 CPPUNIT_TEST_FIXTURE(Chart2ImportTest
, testSmoothDefaultValue2013XLSX
)
1317 loadFromFile(u
"xlsx/smoothed_series.xlsx");
1318 Reference
<chart2::XChartDocument
> xChartDoc
= getChartDocFromSheet(0);
1319 CPPUNIT_ASSERT_MESSAGE("failed to load chart", xChartDoc
.is());
1320 CPPUNIT_ASSERT(xChartDoc
.is());
1322 Reference
< chart2::XChartType
> xChartType
= getChartTypeFromDoc( xChartDoc
, 0 );
1323 CPPUNIT_ASSERT(xChartType
.is());
1325 Reference
< beans::XPropertySet
> xPropSet( xChartType
, UNO_QUERY
);
1326 CPPUNIT_ASSERT(xPropSet
.is());
1328 chart2::CurveStyle eCurveStyle
;
1329 xPropSet
->getPropertyValue(u
"CurveStyle"_ustr
) >>= eCurveStyle
;
1330 CPPUNIT_ASSERT(eCurveStyle
!= chart2::CurveStyle_LINES
);
1333 CPPUNIT_TEST_FIXTURE(Chart2ImportTest
, testTrendlineDefaultValue2007XLSX
)
1335 loadFromFile(u
"xlsx/trendline2007.xlsx");
1336 Reference
<chart2::XChartDocument
> xChartDoc
= getChartDocFromSheet(0);
1337 CPPUNIT_ASSERT_MESSAGE("failed to load chart", xChartDoc
.is());
1338 CPPUNIT_ASSERT(xChartDoc
.is());
1339 Reference
<chart2::XDataSeries
> xDataSeries
= getDataSeriesFromDoc(xChartDoc
, 0);
1340 CPPUNIT_ASSERT(xDataSeries
.is());
1341 Reference
<chart2::XRegressionCurveContainer
> xRegressionCurveContainer(xDataSeries
, UNO_QUERY_THROW
);
1342 Sequence
< Reference
<chart2::XRegressionCurve
> > xRegressionCurveSequence
= xRegressionCurveContainer
->getRegressionCurves();
1343 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xRegressionCurveSequence
.getLength());
1345 Reference
<chart2::XRegressionCurve
> xCurve
= xRegressionCurveSequence
[0];
1347 Reference
<beans::XPropertySet
> xPropSet(xCurve
->getEquationProperties(), uno::UNO_SET_THROW
);
1348 uno::Any aAny
= xPropSet
->getPropertyValue(u
"ShowEquation"_ustr
);
1349 bool bShowEquation
= true;
1350 CPPUNIT_ASSERT(aAny
>>= bShowEquation
);
1351 CPPUNIT_ASSERT(!bShowEquation
);
1353 aAny
= xPropSet
->getPropertyValue(u
"ShowCorrelationCoefficient"_ustr
);
1354 bool bShowCorrelation
= true;
1355 CPPUNIT_ASSERT(aAny
>>= bShowCorrelation
);
1356 CPPUNIT_ASSERT(!bShowCorrelation
);
1359 CPPUNIT_TEST_FIXTURE(Chart2ImportTest
, testTrendlineDefaultValue2013XLSX
)
1361 loadFromFile(u
"xlsx/trendline.xlsx");
1362 Reference
<chart2::XChartDocument
> xChartDoc
= getChartDocFromSheet(0);
1363 CPPUNIT_ASSERT_MESSAGE("failed to load chart", xChartDoc
.is());
1364 CPPUNIT_ASSERT(xChartDoc
.is());
1365 Reference
<chart2::XDataSeries
> xDataSeries
= getDataSeriesFromDoc(xChartDoc
, 0);
1366 CPPUNIT_ASSERT(xDataSeries
.is());
1367 Reference
<chart2::XRegressionCurveContainer
> xRegressionCurveContainer(xDataSeries
, UNO_QUERY_THROW
);
1368 Sequence
< Reference
<chart2::XRegressionCurve
> > xRegressionCurveSequence
= xRegressionCurveContainer
->getRegressionCurves();
1369 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xRegressionCurveSequence
.getLength());
1371 Reference
<chart2::XRegressionCurve
> xCurve
= xRegressionCurveSequence
[0];
1373 Reference
<beans::XPropertySet
> xPropSet(xCurve
->getEquationProperties(), uno::UNO_SET_THROW
);
1374 uno::Any aAny
= xPropSet
->getPropertyValue(u
"ShowEquation"_ustr
);
1375 bool bShowEquation
= false;
1376 CPPUNIT_ASSERT(aAny
>>= bShowEquation
);
1377 CPPUNIT_ASSERT(bShowEquation
);
1379 aAny
= xPropSet
->getPropertyValue(u
"ShowCorrelationCoefficient"_ustr
);
1380 bool bShowCorrelation
= false;
1381 CPPUNIT_ASSERT(aAny
>>= bShowCorrelation
);
1382 CPPUNIT_ASSERT(bShowCorrelation
);
1385 CPPUNIT_TEST_FIXTURE(Chart2ImportTest
, testVaryColorDefaultValues2007XLSX
)
1387 loadFromFile(u
"xlsx/vary_color2007.xlsx");
1388 Reference
<chart2::XChartDocument
> xChartDoc
= getChartDocFromSheet(0);
1389 CPPUNIT_ASSERT_MESSAGE("failed to load chart", xChartDoc
.is());
1390 CPPUNIT_ASSERT(xChartDoc
.is());
1391 Reference
<chart2::XDataSeries
> xDataSeries
= getDataSeriesFromDoc(xChartDoc
, 0);
1392 CPPUNIT_ASSERT(xDataSeries
.is());
1393 Reference
<beans::XPropertySet
> xPropSet(xDataSeries
, uno::UNO_QUERY_THROW
);
1394 uno::Any aAny
= xPropSet
->getPropertyValue(u
"VaryColorsByPoint"_ustr
);
1395 bool bVaryColor
= true;
1396 CPPUNIT_ASSERT(aAny
>>= bVaryColor
);
1397 CPPUNIT_ASSERT(!bVaryColor
);
1400 CPPUNIT_TEST_FIXTURE(Chart2ImportTest
, testVaryColorDefaultValues2013XLSX
)
1402 loadFromFile(u
"xlsx/vary_color.xlsx");
1403 Reference
<chart2::XChartDocument
> xChartDoc
= getChartDocFromSheet(0);
1404 CPPUNIT_ASSERT_MESSAGE("failed to load chart", xChartDoc
.is());
1405 CPPUNIT_ASSERT(xChartDoc
.is());
1406 Reference
<chart2::XDataSeries
> xDataSeries
= getDataSeriesFromDoc(xChartDoc
, 0);
1407 CPPUNIT_ASSERT(xDataSeries
.is());
1408 Reference
<beans::XPropertySet
> xPropSet(xDataSeries
, uno::UNO_QUERY_THROW
);
1409 uno::Any aAny
= xPropSet
->getPropertyValue(u
"VaryColorsByPoint"_ustr
);
1410 bool bVaryColor
= false;
1411 CPPUNIT_ASSERT(aAny
>>= bVaryColor
);
1412 CPPUNIT_ASSERT(!bVaryColor
);
1415 CPPUNIT_TEST_FIXTURE(Chart2ImportTest
, testPlotVisOnlyDefaultValue2013XLSX
)
1417 loadFromFile(u
"xlsx/plotVisOnly.xlsx");
1418 uno::Reference
< chart::XChartDocument
> xChart1Doc ( getChartCompFromSheet( 0, 0), UNO_QUERY_THROW
);
1419 Reference
<beans::XPropertySet
> xPropSet(xChart1Doc
->getDiagram(), uno::UNO_QUERY_THROW
);
1420 uno::Any aAny
= xPropSet
->getPropertyValue(u
"IncludeHiddenCells"_ustr
);
1421 CPPUNIT_ASSERT(aAny
.hasValue());
1422 bool bShowHiddenValues
= true;
1423 CPPUNIT_ASSERT(aAny
>>= bShowHiddenValues
);
1424 CPPUNIT_ASSERT(!bShowHiddenValues
);
1427 CPPUNIT_TEST_FIXTURE(Chart2ImportTest
, testRAngAxDefaultValue2013XLSX
)
1429 loadFromFile(u
"xlsx/rAngAx.xlsx");
1430 uno::Reference
< chart::XChartDocument
> xChart1Doc ( getChartCompFromSheet( 0, 0), UNO_QUERY_THROW
);
1431 Reference
<beans::XPropertySet
> xPropSet(xChart1Doc
->getDiagram(), uno::UNO_QUERY_THROW
);
1432 uno::Any aAny
= xPropSet
->getPropertyValue(u
"RightAngledAxes"_ustr
);
1433 CPPUNIT_ASSERT(aAny
.hasValue());
1434 bool bRightAngleAxes
= false;
1435 CPPUNIT_ASSERT(aAny
>>= bRightAngleAxes
);
1436 CPPUNIT_ASSERT(bRightAngleAxes
);
1439 CPPUNIT_TEST_FIXTURE(Chart2ImportTest
, testMajorTickMarksDefaultValue2013XLSX
)
1441 loadFromFile(u
"xlsx/majorTickMark.xlsx");
1442 Reference
<chart2::XChartDocument
> xChartDoc
= getChartDocFromSheet(0);
1443 CPPUNIT_ASSERT_MESSAGE("failed to load chart", xChartDoc
.is());
1444 Reference
<chart2::XAxis
> xXAxis
= getAxisFromDoc(xChartDoc
, 0, 0, 0);
1445 CPPUNIT_ASSERT(xXAxis
.is());
1446 Reference
<beans::XPropertySet
> xPropSet(xXAxis
, uno::UNO_QUERY_THROW
);
1447 uno::Any aAny
= xPropSet
->getPropertyValue(u
"MajorTickmarks"_ustr
);
1448 sal_Int32 nMajorTickmarks
= chart2::TickmarkStyle::NONE
;
1449 CPPUNIT_ASSERT(aAny
.hasValue());
1450 CPPUNIT_ASSERT(aAny
>>= nMajorTickmarks
);
1451 CPPUNIT_ASSERT_EQUAL(chart2::TickmarkStyle::INNER
| chart2::TickmarkStyle::OUTER
, nMajorTickmarks
);
1454 CPPUNIT_TEST_FIXTURE(Chart2ImportTest
, testMinorTickMarksDefaultValue2013XLSX
)
1456 loadFromFile(u
"xlsx/minorTickMark.xlsx");
1457 Reference
<chart2::XChartDocument
> xChartDoc
= getChartDocFromSheet(0);
1458 CPPUNIT_ASSERT_MESSAGE("failed to load chart", xChartDoc
.is());
1459 Reference
<chart2::XAxis
> xXAxis
= getAxisFromDoc(xChartDoc
, 0, 0, 0);
1460 CPPUNIT_ASSERT(xXAxis
.is());
1461 Reference
<beans::XPropertySet
> xPropSet(xXAxis
, uno::UNO_QUERY_THROW
);
1462 uno::Any aAny
= xPropSet
->getPropertyValue(u
"MinorTickmarks"_ustr
);
1463 sal_Int32 nMajorTickmarks
= chart2::TickmarkStyle::NONE
;
1464 CPPUNIT_ASSERT(aAny
.hasValue());
1465 CPPUNIT_ASSERT(aAny
>>= nMajorTickmarks
);
1466 CPPUNIT_ASSERT_EQUAL(chart2::TickmarkStyle::INNER
| chart2::TickmarkStyle::OUTER
, nMajorTickmarks
);
1469 CPPUNIT_TEST_FIXTURE(Chart2ImportTest
, testAxisTitleDefaultRotationXLSX
)
1471 loadFromFile(u
"xlsx/axis_title_default_rotation.xlsx");
1472 Reference
<chart2::XChartDocument
> xChartDoc
= getChartDocFromSheet(0);
1473 CPPUNIT_ASSERT_MESSAGE("failed to load chart", xChartDoc
.is());
1474 Reference
<chart2::XAxis
> xYAxis
= getAxisFromDoc(xChartDoc
, 0, 1, 0);
1475 CPPUNIT_ASSERT(xYAxis
.is());
1476 Reference
<chart2::XTitled
> xTitled(xYAxis
, uno::UNO_QUERY_THROW
);
1477 Reference
<chart2::XTitle
> xTitle
= xTitled
->getTitleObject();
1478 CPPUNIT_ASSERT(xTitle
.is());
1479 Reference
<beans::XPropertySet
> xPropSet(xTitle
, uno::UNO_QUERY_THROW
);
1480 uno::Any aAny
= xPropSet
->getPropertyValue(u
"TextRotation"_ustr
);
1481 double nRotation
= 0;
1482 CPPUNIT_ASSERT(aAny
>>= nRotation
);
1483 CPPUNIT_ASSERT_EQUAL(90.0, nRotation
);
1486 CPPUNIT_TEST_FIXTURE(Chart2ImportTest
, testSecondaryAxisTitleDefaultRotationXLSX
)
1488 loadFromFile(u
"xlsx/secondary_axis_title_default_rotation.xlsx");
1489 Reference
<chart2::XChartDocument
> xChartDoc
= getChartDocFromSheet(0);
1490 CPPUNIT_ASSERT_MESSAGE("failed to load chart", xChartDoc
.is());
1491 Reference
<chart2::XAxis
> xYAxis
= getAxisFromDoc(xChartDoc
, 0, 1, 1);
1492 CPPUNIT_ASSERT(xYAxis
.is());
1493 Reference
<chart2::XTitled
> xTitled(xYAxis
, uno::UNO_QUERY_THROW
);
1494 Reference
<chart2::XTitle
> xTitle
= xTitled
->getTitleObject();
1495 CPPUNIT_ASSERT(xTitle
.is());
1496 Reference
<beans::XPropertySet
> xPropSet(xTitle
, uno::UNO_QUERY_THROW
);
1497 uno::Any aAny
= xPropSet
->getPropertyValue(u
"TextRotation"_ustr
);
1498 double nRotation
= 0;
1499 CPPUNIT_ASSERT(aAny
>>= nRotation
);
1500 CPPUNIT_ASSERT_EQUAL(90.0, nRotation
);
1503 CPPUNIT_TEST_FIXTURE(Chart2ImportTest
, testAxisTitleRotationXLSX
)
1505 loadFromFile(u
"xlsx/axis_title_rotated.xlsx");
1506 Reference
<chart2::XChartDocument
> xChartDoc
= getChartDocFromSheet(0);
1507 CPPUNIT_ASSERT_MESSAGE("failed to load chart", xChartDoc
.is());
1509 Reference
<chart2::XAxis
> xYAxis
= getAxisFromDoc(xChartDoc
, 0, 1, 0);
1510 CPPUNIT_ASSERT(xYAxis
.is());
1511 Reference
<chart2::XTitled
> xTitled(xYAxis
, uno::UNO_QUERY_THROW
);
1512 Reference
<chart2::XTitle
> xTitle
= xTitled
->getTitleObject();
1513 CPPUNIT_ASSERT(xTitle
.is());
1514 Reference
<beans::XPropertySet
> xPropSet(xTitle
, uno::UNO_QUERY_THROW
);
1515 uno::Any aAny
= xPropSet
->getPropertyValue(u
"TextRotation"_ustr
);
1516 double nRotation
= 0;
1517 CPPUNIT_ASSERT(aAny
>>= nRotation
);
1518 CPPUNIT_ASSERT_EQUAL(340.0, nRotation
);
1521 Reference
<chart2::XAxis
> xYAxis
= getAxisFromDoc(xChartDoc
, 0, 1, 1);
1522 CPPUNIT_ASSERT(xYAxis
.is());
1523 Reference
<chart2::XTitled
> xTitled(xYAxis
, uno::UNO_QUERY_THROW
);
1524 Reference
<chart2::XTitle
> xTitle
= xTitled
->getTitleObject();
1525 CPPUNIT_ASSERT(xTitle
.is());
1526 Reference
<beans::XPropertySet
> xPropSet(xTitle
, uno::UNO_QUERY_THROW
);
1527 uno::Any aAny
= xPropSet
->getPropertyValue(u
"TextRotation"_ustr
);
1528 double nRotation
= 0;
1529 CPPUNIT_ASSERT(aAny
>>= nRotation
);
1530 CPPUNIT_ASSERT_EQUAL(270.0, nRotation
);
1535 CPPUNIT_TEST_FIXTURE(Chart2ImportTest
, testAxisTitlePositionDOCX
)
1537 loadFromFile(u
"docx/testAxisTitlePosition.docx");
1538 uno::Reference
< chart::XDiagram
> mxDiagram
;
1539 uno::Reference
< drawing::XShape
> xAxisTitle
;
1540 uno::Reference
< chart::XChartDocument
> xChartDoc
= getChartDocFromWriter(0);
1541 CPPUNIT_ASSERT_MESSAGE("failed to load chart", xChartDoc
.is());
1542 mxDiagram
.set(xChartDoc
->getDiagram());
1543 CPPUNIT_ASSERT(mxDiagram
.is());
1544 // test X Axis title position
1545 uno::Reference
< chart::XAxisXSupplier
> xAxisXSupp(mxDiagram
, uno::UNO_QUERY
);
1546 CPPUNIT_ASSERT(xAxisXSupp
.is());
1548 xAxisTitle
= xAxisXSupp
->getXAxisTitle();
1549 CPPUNIT_ASSERT(xAxisTitle
.is());
1551 awt::Point aPos
= xAxisTitle
->getPosition();
1552 CPPUNIT_ASSERT_DOUBLES_EQUAL(10640, aPos
.X
, 2);
1553 CPPUNIT_ASSERT_DOUBLES_EQUAL(7157, aPos
.Y
, 2);
1555 // test Y Axis title position
1556 uno::Reference
< chart::XAxisYSupplier
> xAxisYSupp(mxDiagram
, uno::UNO_QUERY
);
1557 CPPUNIT_ASSERT(xAxisYSupp
.is());
1559 xAxisTitle
= xAxisYSupp
->getYAxisTitle();
1560 CPPUNIT_ASSERT(xAxisTitle
.is());
1562 aPos
= xAxisTitle
->getPosition();
1563 CPPUNIT_ASSERT_DOUBLES_EQUAL(387, aPos
.X
, 2);
1564 CPPUNIT_ASSERT_DOUBLES_EQUAL(6378, aPos
.Y
, 300);
1567 CPPUNIT_TEST_FIXTURE(Chart2ImportTest
, testCombinedChartAttachedAxisXLSX
)
1569 loadFromFile(u
"xlsx/testCombinedChartAxis.xlsx");
1570 Reference
< chart2::XChartDocument
> xChartDoc
= getChartDocFromSheet(0);
1572 Reference
<chart2::XDataSeries
> xSeries
= getDataSeriesFromDoc(xChartDoc
, 0);
1573 CPPUNIT_ASSERT(xSeries
.is());
1575 Reference
<beans::XPropertySet
> xPropSet(xSeries
, uno::UNO_QUERY_THROW
);
1576 sal_Int32 nAxisIndex
= -1;
1577 // First series (column chart) should be attached to secondary axis!
1578 uno::Any aAny
= xPropSet
->getPropertyValue(u
"AttachedAxisIndex"_ustr
);
1579 CPPUNIT_ASSERT(aAny
>>= nAxisIndex
);
1580 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), nAxisIndex
);
1583 xSeries
= getDataSeriesFromDoc(xChartDoc
, 0, 1);
1584 CPPUNIT_ASSERT(xSeries
.is());
1586 xPropSet
.set(xSeries
, uno::UNO_QUERY_THROW
);
1587 // Second series (line chart) should be attached to primary axis!
1588 aAny
= xPropSet
->getPropertyValue(u
"AttachedAxisIndex"_ustr
);
1589 CPPUNIT_ASSERT(aAny
>>= nAxisIndex
);
1590 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), nAxisIndex
);
1593 CPPUNIT_TEST_FIXTURE(Chart2ImportTest
, testTdf140489MultiSeriesChartAxisXLSX
)
1595 loadFromFile(u
"xlsx/tdf140489.xlsx");
1596 Reference
< chart2::XChartDocument
> xChartDoc
= getChartDocFromSheet(0);
1598 Reference
<chart2::XDataSeries
> xSeries
= getDataSeriesFromDoc(xChartDoc
, 0);
1599 CPPUNIT_ASSERT(xSeries
.is());
1601 Reference
<beans::XPropertySet
> xPropSet(xSeries
, uno::UNO_QUERY_THROW
);
1602 sal_Int32 nAxisIndex
= -1;
1603 uno::Any aAny
= xPropSet
->getPropertyValue(u
"AttachedAxisIndex"_ustr
);
1604 CPPUNIT_ASSERT(aAny
>>= nAxisIndex
);
1605 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), nAxisIndex
);
1608 xSeries
= getDataSeriesFromDoc(xChartDoc
, 0, 1);
1609 CPPUNIT_ASSERT(xSeries
.is());
1611 xPropSet
.set(xSeries
, uno::UNO_QUERY_THROW
);
1612 aAny
= xPropSet
->getPropertyValue(u
"AttachedAxisIndex"_ustr
);
1613 CPPUNIT_ASSERT(aAny
>>= nAxisIndex
);
1614 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), nAxisIndex
);
1617 xSeries
= getDataSeriesFromDoc(xChartDoc
, 0, 2);
1618 CPPUNIT_ASSERT(xSeries
.is());
1620 xPropSet
.set(xSeries
, uno::UNO_QUERY_THROW
);
1621 aAny
= xPropSet
->getPropertyValue(u
"AttachedAxisIndex"_ustr
);
1622 CPPUNIT_ASSERT(aAny
>>= nAxisIndex
);
1623 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), nAxisIndex
);
1626 CPPUNIT_TEST_FIXTURE(Chart2ImportTest
, testInternalDataProvider
)
1628 loadFromFile(u
"odp/chart.odp");
1629 uno::Reference
< chart2::XChartDocument
> xChartDoc(getChartDocFromDrawImpress(0,0), uno::UNO_QUERY_THROW
);
1630 const uno::Reference
< chart2::data::XDataProvider
> xDataProvider
= xChartDoc
->getDataProvider();
1633 Reference
<chart2::data::XDataSequence
> xDataSeq
= xDataProvider
->createDataSequenceByValueArray(u
"values-y"_ustr
, u
"{42;42;42;42}"_ustr
, u
""_ustr
);
1634 Sequence
<Any
> xSequence
= xDataSeq
->getData();
1635 CPPUNIT_ASSERT_EQUAL(uno::Any(sal_Int32(42)), xSequence
[0]);
1636 CPPUNIT_ASSERT_EQUAL(uno::Any(sal_Int32(42)), xSequence
[1]);
1637 CPPUNIT_ASSERT_EQUAL(uno::Any(sal_Int32(42)), xSequence
[2]);
1638 CPPUNIT_ASSERT_EQUAL(uno::Any(sal_Int32(42)), xSequence
[3]);
1640 // Parse empty first and last
1641 xDataSeq
= xDataProvider
->createDataSequenceByValueArray(u
"values-y"_ustr
, u
"{\"\";42;42;\"\"}"_ustr
, u
""_ustr
);
1642 xSequence
= xDataSeq
->getData();
1643 CPPUNIT_ASSERT( std::isnan( *static_cast<const double*>(xSequence
[0].getValue())));
1644 CPPUNIT_ASSERT_EQUAL(uno::Any(sal_Int32(42)), xSequence
[1]);
1645 CPPUNIT_ASSERT_EQUAL(uno::Any(sal_Int32(42)), xSequence
[2]);
1646 CPPUNIT_ASSERT( std::isnan( *static_cast<const double*>(xSequence
[3].getValue())));
1648 // Parse empty middle
1649 xDataSeq
= xDataProvider
->createDataSequenceByValueArray(u
"values-y"_ustr
, u
"{42;\"\";\"\";42}"_ustr
, u
""_ustr
);
1650 xSequence
= xDataSeq
->getData();
1651 CPPUNIT_ASSERT_EQUAL(uno::Any(sal_Int32(42)), xSequence
[0]);
1652 CPPUNIT_ASSERT( std::isnan( *static_cast<const double*>(xSequence
[1].getValue())) );
1653 CPPUNIT_ASSERT( std::isnan( *static_cast<const double*>(xSequence
[2].getValue())) );
1654 CPPUNIT_ASSERT_EQUAL(uno::Any(sal_Int32(42)), xSequence
[3]);
1656 // Parse mixed types, numeric only role
1657 xDataSeq
= xDataProvider
->createDataSequenceByValueArray(u
"values-y"_ustr
, u
"{42;\"hello\";0;\"world\"}"_ustr
, u
""_ustr
);
1658 xSequence
= xDataSeq
->getData();
1659 CPPUNIT_ASSERT_EQUAL(uno::Any(sal_Int32(42)), xSequence
[0]);
1660 CPPUNIT_ASSERT_EQUAL(uno::Any(sal_Int32(0)), xSequence
[1]);
1661 CPPUNIT_ASSERT_EQUAL(uno::Any(sal_Int32(0)), xSequence
[2]);
1662 CPPUNIT_ASSERT_EQUAL(uno::Any(sal_Int32(0)), xSequence
[3]);
1664 // Parse mixed types, mixed role
1665 xDataSeq
= xDataProvider
->createDataSequenceByValueArray(u
"categories"_ustr
, u
"{42;\"hello\";0;\"world\"}"_ustr
, u
""_ustr
);
1666 xSequence
= xDataSeq
->getData();
1667 CPPUNIT_ASSERT_EQUAL(uno::Any(u
"Row 1 42"_ustr
), xSequence
[0]);
1668 CPPUNIT_ASSERT_EQUAL(uno::Any(u
"Row 2 hello"_ustr
), xSequence
[1]);
1669 CPPUNIT_ASSERT_EQUAL(uno::Any(u
"Row 3 0"_ustr
), xSequence
[2]);
1670 CPPUNIT_ASSERT_EQUAL(uno::Any(u
"Row 4 world"_ustr
), xSequence
[3]);
1673 CPPUNIT_TEST_FIXTURE(Chart2ImportTest
, testTdf90510
)
1675 // Pie chart label placement settings(XLS)
1676 loadFromFile(u
"xls/piechart_outside.xls");
1677 uno::Reference
< chart::XChartDocument
> xChart1Doc( getChartCompFromSheet( 0, 0), UNO_QUERY_THROW
);
1678 Reference
<beans::XPropertySet
> xPropSet( xChart1Doc
->getDiagram()->getDataPointProperties( 0, 0 ), uno::UNO_SET_THROW
);
1679 uno::Any aAny
= xPropSet
->getPropertyValue( u
"LabelPlacement"_ustr
);
1680 CPPUNIT_ASSERT( aAny
.hasValue() );
1681 sal_Int32 nLabelPlacement
= 0;
1682 CPPUNIT_ASSERT( aAny
>>= nLabelPlacement
);
1683 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Data labels should be placed outside", chart::DataLabelPlacement::OUTSIDE
, nLabelPlacement
);
1686 CPPUNIT_TEST_FIXTURE(Chart2ImportTest
, testTdf109858
)
1688 // Pie chart label placement settings(XLSX)
1689 loadFromFile(u
"xlsx/piechart_outside.xlsx");
1690 uno::Reference
< chart::XChartDocument
> xChart1Doc( getChartCompFromSheet( 0, 0), UNO_QUERY_THROW
);
1692 // test data point labels position
1693 Reference
<beans::XPropertySet
> xDataPointPropSet( xChart1Doc
->getDiagram()->getDataPointProperties( 0, 0 ), uno::UNO_SET_THROW
);
1694 uno::Any aAny
= xDataPointPropSet
->getPropertyValue( u
"LabelPlacement"_ustr
);
1695 CPPUNIT_ASSERT( aAny
.hasValue() );
1696 sal_Int32 nLabelPlacement
= 0;
1697 CPPUNIT_ASSERT( aAny
>>= nLabelPlacement
);
1698 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Data point label should be placed bestfit", chart::DataLabelPlacement::CUSTOM
, nLabelPlacement
);
1700 // test data series label position
1701 Reference
<beans::XPropertySet
> xSeriesPropSet(xChart1Doc
->getDiagram()->getDataRowProperties(0), uno::UNO_SET_THROW
);
1702 aAny
= xSeriesPropSet
->getPropertyValue( u
"LabelPlacement"_ustr
);
1703 CPPUNIT_ASSERT( aAny
>>= nLabelPlacement
);
1704 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Data series labels should be placed outside", chart::DataLabelPlacement::OUTSIDE
, nLabelPlacement
);
1707 CPPUNIT_TEST_FIXTURE(Chart2ImportTest
, testTdf130105
)
1709 loadFromFile(u
"xlsx/barchart_outend.xlsx");
1710 uno::Reference
< chart2::XChartDocument
> xChartDoc
= getChartDocFromSheet(0);
1711 CPPUNIT_ASSERT(xChartDoc
.is());
1712 uno::Reference
<chart2::XDataSeries
> xDataSeries(getDataSeriesFromDoc(xChartDoc
, 0));
1713 CPPUNIT_ASSERT(xDataSeries
.is());
1715 uno::Reference
<beans::XPropertySet
> xPropertySet(xDataSeries
->getDataPointByIndex(0), uno::UNO_SET_THROW
);
1716 uno::Any aAny
= xPropertySet
->getPropertyValue(u
"LabelPlacement"_ustr
);
1717 CPPUNIT_ASSERT(aAny
.hasValue());
1718 sal_Int32 nLabelPlacement
= 0;
1719 CPPUNIT_ASSERT(aAny
>>= nLabelPlacement
);
1720 CPPUNIT_ASSERT_EQUAL_MESSAGE("Data label should be placed outend", chart::DataLabelPlacement::OUTSIDE
, nLabelPlacement
);
1723 CPPUNIT_TEST_FIXTURE(Chart2ImportTest
, testTdf111173
)
1725 loadFromFile(u
"xlsx/tdf111173.xlsx");
1726 uno::Reference
< chart::XChartDocument
> xChart1Doc( getChartCompFromSheet( 0, 0), UNO_QUERY_THROW
);
1729 CPPUNIT_TEST_FIXTURE(Chart2ImportTest
, testTdf122226
)
1731 loadFromFile(u
"docx/testTdf122226.docx" );
1732 uno::Reference
< chart2::XChartDocument
> xChartDoc ( getChartDocFromWriter(0), uno::UNO_QUERY
);
1733 CPPUNIT_ASSERT( xChartDoc
.is() );
1735 css::uno::Reference
<chart2::XDiagram
> xDiagram(xChartDoc
->getFirstDiagram(), UNO_SET_THROW
);
1736 Reference
<chart2::XDataSeries
> xDataSeries
= getDataSeriesFromDoc(xChartDoc
, 0);
1737 uno::Reference
<beans::XPropertySet
> xPropertySet(xDataSeries
->getDataPointByIndex(0), uno::UNO_SET_THROW
);
1738 CPPUNIT_ASSERT(xPropertySet
.is());
1740 uno::Any aAny
= xPropertySet
->getPropertyValue( u
"LabelSeparator"_ustr
);
1741 CPPUNIT_ASSERT( aAny
.hasValue() );
1742 OUString nLabelSeparator
;
1743 CPPUNIT_ASSERT( aAny
>>= nLabelSeparator
);
1744 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Data labels should be separated into new lines", u
"\n"_ustr
, nLabelSeparator
);
1747 CPPUNIT_TEST_FIXTURE(Chart2ImportTest
, testTdf115107
)
1749 // import complex data point labels
1750 loadFromFile(u
"pptx/tdf115107.pptx");
1752 Reference
<chart2::XChartDocument
> xChartDoc(getChartDocFromDrawImpress(0, 0), uno::UNO_QUERY
);
1753 CPPUNIT_ASSERT(xChartDoc
.is());
1755 uno::Reference
<chart2::XDataSeries
> xDataSeries(getDataSeriesFromDoc(xChartDoc
, 0));
1756 CPPUNIT_ASSERT(xDataSeries
.is());
1758 sal_Int64 nFontColor
;
1759 sal_Int32 nCharUnderline
;
1760 uno::Reference
<beans::XPropertySet
> xPropertySet
;
1761 uno::Sequence
<uno::Reference
<chart2::XDataPointCustomLabelField
>> aFields
;
1764 xPropertySet
.set(xDataSeries
->getDataPointByIndex(0), uno::UNO_SET_THROW
);
1765 xPropertySet
->getPropertyValue(u
"CustomLabelFields"_ustr
) >>= aFields
;
1766 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32
>(2), aFields
.getLength());
1768 CPPUNIT_ASSERT_EQUAL(chart2::DataPointCustomLabelFieldType::DataPointCustomLabelFieldType_TEXT
, aFields
[0]->getFieldType());
1769 CPPUNIT_ASSERT_EQUAL(u
"90.0 = "_ustr
, aFields
[0]->getString());
1770 aFields
[0]->getPropertyValue(u
"CharHeight"_ustr
) >>= nFontSize
;
1771 aFields
[0]->getPropertyValue(u
"CharColor"_ustr
) >>= nFontColor
;
1772 CPPUNIT_ASSERT_EQUAL(static_cast<float>(18), nFontSize
);
1773 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int64
>(0xed7d31), nFontColor
);
1775 CPPUNIT_ASSERT_EQUAL(chart2::DataPointCustomLabelFieldType::DataPointCustomLabelFieldType_VALUE
, aFields
[1]->getFieldType());
1776 CPPUNIT_ASSERT_EQUAL(u
"90"_ustr
, aFields
[1]->getString());
1779 xPropertySet
.set(xDataSeries
->getDataPointByIndex(1), uno::UNO_SET_THROW
);
1780 xPropertySet
->getPropertyValue(u
"CustomLabelFields"_ustr
) >>= aFields
;
1781 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32
>(8), aFields
.getLength());
1783 CPPUNIT_ASSERT_EQUAL(chart2::DataPointCustomLabelFieldType::DataPointCustomLabelFieldType_TEXT
, aFields
[0]->getFieldType());
1784 CPPUNIT_ASSERT_EQUAL(u
"Text"_ustr
, aFields
[0]->getString());
1786 CPPUNIT_ASSERT_EQUAL(chart2::DataPointCustomLabelFieldType::DataPointCustomLabelFieldType_TEXT
, aFields
[1]->getFieldType());
1787 CPPUNIT_ASSERT_EQUAL(u
" : "_ustr
, aFields
[1]->getString());
1789 CPPUNIT_ASSERT_EQUAL(chart2::DataPointCustomLabelFieldType::DataPointCustomLabelFieldType_CATEGORYNAME
, aFields
[2]->getFieldType());
1790 CPPUNIT_ASSERT_EQUAL(u
"B"_ustr
, aFields
[2]->getString());
1791 aFields
[2]->getPropertyValue(u
"CharHeight"_ustr
) >>= nFontSize
;
1792 aFields
[2]->getPropertyValue(u
"CharColor"_ustr
) >>= nFontColor
;
1793 CPPUNIT_ASSERT_EQUAL(static_cast<float>(16), nFontSize
);
1794 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int64
>(0xed7d31), nFontColor
);
1796 CPPUNIT_ASSERT_EQUAL(chart2::DataPointCustomLabelFieldType::DataPointCustomLabelFieldType_NEWLINE
, aFields
[3]->getFieldType());
1798 CPPUNIT_ASSERT_EQUAL(chart2::DataPointCustomLabelFieldType::DataPointCustomLabelFieldType_TEXT
, aFields
[4]->getFieldType());
1799 CPPUNIT_ASSERT_EQUAL(u
"Multi"_ustr
, aFields
[4]->getString());
1801 CPPUNIT_ASSERT_EQUAL(chart2::DataPointCustomLabelFieldType::DataPointCustomLabelFieldType_TEXT
, aFields
[5]->getFieldType());
1802 CPPUNIT_ASSERT_EQUAL(u
"line"_ustr
, aFields
[5]->getString());
1803 aFields
[5]->getPropertyValue(u
"CharHeight"_ustr
) >>= nFontSize
;
1804 aFields
[5]->getPropertyValue(u
"CharColor"_ustr
) >>= nFontColor
;
1805 CPPUNIT_ASSERT_EQUAL(static_cast<float>(11.97), nFontSize
);
1806 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int64
>(0xbf9000), nFontColor
);
1808 CPPUNIT_ASSERT_EQUAL(chart2::DataPointCustomLabelFieldType::DataPointCustomLabelFieldType_NEWLINE
, aFields
[6]->getFieldType());
1810 CPPUNIT_ASSERT_EQUAL(chart2::DataPointCustomLabelFieldType::DataPointCustomLabelFieldType_TEXT
, aFields
[7]->getFieldType());
1811 CPPUNIT_ASSERT_EQUAL(u
"Abc"_ustr
, aFields
[7]->getString());
1812 aFields
[7]->getPropertyValue(u
"CharHeight"_ustr
) >>= nFontSize
;
1813 aFields
[7]->getPropertyValue(u
"CharColor"_ustr
) >>= nFontColor
;
1814 aFields
[7]->getPropertyValue(u
"CharUnderline"_ustr
) >>= nCharUnderline
;
1815 CPPUNIT_ASSERT_EQUAL(static_cast<float>(12), nFontSize
);
1816 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int64
>(0xa9d18e), nFontColor
);
1817 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32
>(1), nCharUnderline
);
1820 xPropertySet
.set(xDataSeries
->getDataPointByIndex(2), uno::UNO_SET_THROW
);
1821 xPropertySet
->getPropertyValue(u
"CustomLabelFields"_ustr
) >>= aFields
;
1822 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32
>(1), aFields
.getLength());
1824 CPPUNIT_ASSERT_EQUAL(chart2::DataPointCustomLabelFieldType::DataPointCustomLabelFieldType_SERIESNAME
, aFields
[0]->getFieldType());
1825 CPPUNIT_ASSERT_EQUAL(u
"DATA"_ustr
, aFields
[0]->getString());
1828 xPropertySet
.set(xDataSeries
->getDataPointByIndex(3), uno::UNO_SET_THROW
);
1829 xPropertySet
->getPropertyValue(u
"CustomLabelFields"_ustr
) >>= aFields
;
1830 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32
>(2), aFields
.getLength());
1832 CPPUNIT_ASSERT_EQUAL(chart2::DataPointCustomLabelFieldType::DataPointCustomLabelFieldType_CELLREF
, aFields
[0]->getFieldType());
1833 //CPPUNIT_ASSERT_EQUAL(OUString("70"), aFields[0]->getString()); TODO: Not implemented yet
1835 CPPUNIT_ASSERT_EQUAL(chart2::DataPointCustomLabelFieldType::DataPointCustomLabelFieldType_TEXT
, aFields
[1]->getFieldType());
1836 CPPUNIT_ASSERT_EQUAL(u
" <CELLREF"_ustr
, aFields
[1]->getString());
1839 CPPUNIT_TEST_FIXTURE(Chart2ImportTest
, testTdf115107_2
)
1841 // import complex data point labels in cobo charts with multiple data series
1842 loadFromFile(u
"pptx/tdf115107-2.pptx");
1844 Reference
<chart2::XChartDocument
> xChartDoc(getChartDocFromDrawImpress(0, 0), uno::UNO_QUERY
);
1845 CPPUNIT_ASSERT(xChartDoc
.is());
1847 uno::Reference
<chart2::XDataSeries
> xDataSeries(getDataSeriesFromDoc(xChartDoc
, 0));
1848 CPPUNIT_ASSERT(xDataSeries
.is());
1850 sal_Int64 nFontColor
;
1851 uno::Reference
<beans::XPropertySet
> xPropertySet
;
1852 uno::Sequence
<uno::Reference
<chart2::XDataPointCustomLabelField
>> aFields
;
1855 xPropertySet
.set(xDataSeries
->getDataPointByIndex(0), uno::UNO_SET_THROW
);
1856 xPropertySet
->getPropertyValue(u
"CustomLabelFields"_ustr
) >>= aFields
;
1857 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32
>(3), aFields
.getLength());
1859 CPPUNIT_ASSERT_EQUAL(chart2::DataPointCustomLabelFieldType::DataPointCustomLabelFieldType_VALUE
, aFields
[0]->getFieldType());
1860 CPPUNIT_ASSERT_EQUAL(u
"4.3"_ustr
, aFields
[0]->getString());
1861 aFields
[0]->getPropertyValue(u
"CharHeight"_ustr
) >>= nFontSize
;
1862 aFields
[0]->getPropertyValue(u
"CharColor"_ustr
) >>= nFontColor
;
1863 CPPUNIT_ASSERT_EQUAL(static_cast<float>(18), nFontSize
);
1864 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int64
>(0xc00000), nFontColor
);
1866 CPPUNIT_ASSERT_EQUAL(chart2::DataPointCustomLabelFieldType::DataPointCustomLabelFieldType_TEXT
, aFields
[1]->getFieldType());
1867 CPPUNIT_ASSERT_EQUAL(u
" "_ustr
, aFields
[1]->getString());
1869 CPPUNIT_ASSERT_EQUAL(chart2::DataPointCustomLabelFieldType::DataPointCustomLabelFieldType_SERIESNAME
, aFields
[2]->getFieldType());
1870 CPPUNIT_ASSERT_EQUAL(u
"Bars"_ustr
, aFields
[2]->getString());
1873 xDataSeries
= getDataSeriesFromDoc(xChartDoc
, 0, 1);
1874 CPPUNIT_ASSERT(xDataSeries
.is());
1876 xPropertySet
.set(xDataSeries
->getDataPointByIndex(0), uno::UNO_SET_THROW
);
1877 xPropertySet
->getPropertyValue(u
"CustomLabelFields"_ustr
) >>= aFields
;
1878 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32
>(3), aFields
.getLength());
1880 CPPUNIT_ASSERT_EQUAL(chart2::DataPointCustomLabelFieldType::DataPointCustomLabelFieldType_VALUE
, aFields
[0]->getFieldType());
1881 CPPUNIT_ASSERT_EQUAL(u
"2"_ustr
, aFields
[0]->getString());
1882 aFields
[0]->getPropertyValue(u
"CharHeight"_ustr
) >>= nFontSize
;
1883 aFields
[0]->getPropertyValue(u
"CharColor"_ustr
) >>= nFontColor
;
1884 CPPUNIT_ASSERT_EQUAL(static_cast<float>(18), nFontSize
);
1885 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int64
>(0xffd966), nFontColor
);
1887 CPPUNIT_ASSERT_EQUAL(chart2::DataPointCustomLabelFieldType::DataPointCustomLabelFieldType_TEXT
, aFields
[1]->getFieldType());
1888 CPPUNIT_ASSERT_EQUAL(u
" "_ustr
, aFields
[1]->getString());
1890 CPPUNIT_ASSERT_EQUAL(chart2::DataPointCustomLabelFieldType::DataPointCustomLabelFieldType_SERIESNAME
, aFields
[2]->getFieldType());
1891 CPPUNIT_ASSERT_EQUAL(u
"Line"_ustr
, aFields
[2]->getString());
1895 CPPUNIT_TEST_FIXTURE(Chart2ImportTest
, testTdf116163
)
1897 loadFromFile(u
"pptx/tdf116163.pptx");
1899 Reference
<chart2::XChartDocument
> xChartDoc(getChartDocFromDrawImpress(0, 0), uno::UNO_QUERY
);
1900 CPPUNIT_ASSERT(xChartDoc
.is());
1902 Reference
<chart2::XAxis
> xHAxis
= getAxisFromDoc(xChartDoc
, 0, 0, 0);
1903 CPPUNIT_ASSERT(xHAxis
.is());
1905 chart2::ScaleData aScaleData
= xHAxis
->getScaleData();
1906 CPPUNIT_ASSERT(aScaleData
.Categories
.is());
1908 Reference
<chart2::data::XLabeledDataSequence
> xLabeledDataSequence
= aScaleData
.Categories
;
1909 CPPUNIT_ASSERT(xLabeledDataSequence
.is());
1911 Reference
<chart2::data::XDataSequence
> xDataSequence
= xLabeledDataSequence
->getValues();
1912 CPPUNIT_ASSERT(xDataSequence
.is());
1914 Reference
<chart2::data::XTextualDataSequence
> xTextualDataSequence(xDataSequence
, uno::UNO_QUERY
);
1915 CPPUNIT_ASSERT(xTextualDataSequence
.is());
1917 std::vector
<OUString
> aCategories
;
1918 const Sequence
<OUString
> aTextData(xTextualDataSequence
->getTextualData());
1919 ::std::copy(aTextData
.begin(), aTextData
.end(),
1920 ::std::back_inserter(aCategories
));
1922 CPPUNIT_ASSERT_EQUAL(u
"Aaaa"_ustr
, aCategories
[0]);
1923 CPPUNIT_ASSERT_EQUAL(u
"Bbbbbbb"_ustr
, aCategories
[1]);
1924 CPPUNIT_ASSERT_EQUAL(u
"Ccc"_ustr
, aCategories
[2]);
1925 CPPUNIT_ASSERT_EQUAL(u
"Ddddddddddddd"_ustr
, aCategories
[3]);
1927 // Check visible text
1929 uno::Reference
<drawing::XDrawPageSupplier
> xDrawPageSupplier(xChartDoc
, uno::UNO_QUERY
);
1930 uno::Reference
<drawing::XDrawPage
> xDrawPage
= xDrawPageSupplier
->getDrawPage();
1931 uno::Reference
<drawing::XShapes
> xShapes(xDrawPage
->getByIndex(0), uno::UNO_QUERY
);
1932 CPPUNIT_ASSERT(xShapes
.is());
1934 uno::Reference
<drawing::XShape
> xXAxis
= getShapeByName(xShapes
, u
"CID/D=0:CS=0:Axis=0,0"_ustr
,
1935 // Axis occurs twice in chart xshape representation so need to get the one related to labels
1936 [](const uno::Reference
<drawing::XShape
>& rXShape
) -> bool
1938 uno::Reference
<drawing::XShapes
> xAxisShapes(rXShape
, uno::UNO_QUERY
);
1939 CPPUNIT_ASSERT(xAxisShapes
.is());
1940 uno::Reference
<drawing::XShape
> xChildShape(xAxisShapes
->getByIndex(0), uno::UNO_QUERY
);
1941 uno::Reference
< drawing::XShapeDescriptor
> xShapeDescriptor(xChildShape
, uno::UNO_QUERY_THROW
);
1942 return (xShapeDescriptor
->getShapeType() == "com.sun.star.drawing.TextShape");
1944 CPPUNIT_ASSERT(xXAxis
.is());
1946 uno::Reference
<container::XIndexAccess
> xIndexAccess(xXAxis
, UNO_QUERY_THROW
);
1949 uno::Reference
<text::XTextRange
> xLabel0(xIndexAccess
->getByIndex(0), uno::UNO_QUERY
);
1950 CPPUNIT_ASSERT_EQUAL(u
"Aaaa"_ustr
, xLabel0
->getString());
1951 uno::Reference
<text::XTextRange
> xLabel1(xIndexAccess
->getByIndex(1), uno::UNO_QUERY
);
1952 // If there is space for 3 chars only then don't show "..."
1953 CPPUNIT_ASSERT_EQUAL(u
"Bbb"_ustr
, xLabel1
->getString());
1954 uno::Reference
<text::XTextRange
> xLabel2(xIndexAccess
->getByIndex(2), uno::UNO_QUERY
);
1955 CPPUNIT_ASSERT_EQUAL(u
"Ccc"_ustr
, xLabel2
->getString());
1956 uno::Reference
<text::XTextRange
> xLabel3(xIndexAccess
->getByIndex(3), uno::UNO_QUERY
);
1957 CPPUNIT_ASSERT_EQUAL(u
"Dddd..."_ustr
, xLabel3
->getString());
1960 CPPUNIT_TEST_FIXTURE(Chart2ImportTest
, testTdf48041
)
1962 loadFromFile(u
"pptx/tdf48041.pptx");
1964 Reference
<chart2::XChartDocument
> xChartDoc(getChartDocFromDrawImpress(0, 0), uno::UNO_QUERY
);
1965 CPPUNIT_ASSERT(xChartDoc
.is());
1967 Reference
<chart2::XAxis
> xYAxis
= getAxisFromDoc(xChartDoc
, 0, 1, 0);
1968 CPPUNIT_ASSERT(xYAxis
.is());
1970 chart2::ScaleData aScaleData
= xYAxis
->getScaleData();
1971 CPPUNIT_ASSERT(aScaleData
.Scaling
.is());
1973 // Check visible text
1974 uno::Reference
<drawing::XDrawPageSupplier
> xDrawPageSupplier(xChartDoc
, uno::UNO_QUERY
);
1975 uno::Reference
<drawing::XDrawPage
> xDrawPage
= xDrawPageSupplier
->getDrawPage();
1976 uno::Reference
<drawing::XShapes
> xShapes(xDrawPage
->getByIndex(0), uno::UNO_QUERY
);
1977 CPPUNIT_ASSERT(xShapes
.is());
1979 uno::Reference
<drawing::XShape
> xYAxisShape
= getShapeByName(xShapes
, u
"CID/D=0:CS=0:Axis=1,0"_ustr
, // Y Axis
1980 // Axis occurs twice in chart xshape representation so need to get the one related to labels
1981 [](const uno::Reference
<drawing::XShape
>& rXShape
) -> bool
1983 uno::Reference
<drawing::XShapes
> xAxisShapes(rXShape
, uno::UNO_QUERY
);
1984 CPPUNIT_ASSERT(xAxisShapes
.is());
1985 uno::Reference
<drawing::XShape
> xChildShape(xAxisShapes
->getByIndex(0), uno::UNO_QUERY
);
1986 uno::Reference
< drawing::XShapeDescriptor
> xShapeDescriptor(xChildShape
, uno::UNO_QUERY_THROW
);
1987 return (xShapeDescriptor
->getShapeType() == "com.sun.star.drawing.TextShape");
1989 CPPUNIT_ASSERT(xYAxisShape
.is());
1991 // Check label count
1992 uno::Reference
<container::XIndexAccess
> xIndexAccess(xYAxisShape
, UNO_QUERY_THROW
);
1993 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32
>(6), xIndexAccess
->getCount());
1996 uno::Reference
<text::XTextRange
> xLabel0(xIndexAccess
->getByIndex(0), uno::UNO_QUERY
);
1997 CPPUNIT_ASSERT_EQUAL(u
"0"_ustr
, xLabel0
->getString());
1998 uno::Reference
<text::XTextRange
> xLabel1(xIndexAccess
->getByIndex(1), uno::UNO_QUERY
);
1999 CPPUNIT_ASSERT_EQUAL(u
"1"_ustr
, xLabel1
->getString());
2000 uno::Reference
<text::XTextRange
> xLabel2(xIndexAccess
->getByIndex(2), uno::UNO_QUERY
);
2001 CPPUNIT_ASSERT_EQUAL(u
"2"_ustr
, xLabel2
->getString());
2002 uno::Reference
<text::XTextRange
> xLabel3(xIndexAccess
->getByIndex(3), uno::UNO_QUERY
);
2003 CPPUNIT_ASSERT_EQUAL(u
"3"_ustr
, xLabel3
->getString());
2004 uno::Reference
<text::XTextRange
> xLabel4(xIndexAccess
->getByIndex(4), uno::UNO_QUERY
);
2005 CPPUNIT_ASSERT_EQUAL(u
"4"_ustr
, xLabel4
->getString());
2006 uno::Reference
<text::XTextRange
> xLabel5(xIndexAccess
->getByIndex(5), uno::UNO_QUERY
);
2007 CPPUNIT_ASSERT_EQUAL(u
"5"_ustr
, xLabel5
->getString());
2010 CPPUNIT_TEST_FIXTURE(Chart2ImportTest
, testTdf121205
)
2012 loadFromFile(u
"pptx/tdf121205.pptx");
2013 Reference
<chart2::XChartDocument
> xChartDoc(getChartDocFromDrawImpress(0, 0), uno::UNO_QUERY
);
2015 uno::Reference
<chart2::XTitled
> xTitled(xChartDoc
, uno::UNO_QUERY_THROW
);
2016 CPPUNIT_ASSERT_MESSAGE("chart doc does not have title", xTitled
.is());
2017 OUString aTitle
= getTitleString(xTitled
);
2019 // We expect title split in 3 lines
2020 CPPUNIT_ASSERT_EQUAL(u
"Firstline\nSecondline\nThirdline"_ustr
, aTitle
);
2023 CPPUNIT_TEST_FIXTURE(Chart2ImportTest
, testTdf146487
)
2025 loadFromFile(u
"pptx/tdf146487.pptx");
2026 Reference
<chart2::XChartDocument
> xChartDoc(getChartDocFromDrawImpress(0, 0), uno::UNO_QUERY
);
2027 CPPUNIT_ASSERT_MESSAGE("failed to load chart", xChartDoc
.is());
2029 Reference
<chart2::XTitled
> xTitled(xChartDoc
, uno::UNO_QUERY_THROW
);
2030 uno::Reference
<chart2::XTitle
> xTitle
= xTitled
->getTitleObject();
2031 CPPUNIT_ASSERT_MESSAGE("chart doc should not have a title", !xTitle
.is());
2033 // tdf#146756 use manualLayout Width that was provided (so Green; $7,654,321 is not wrapped
2034 if (!IsDefaultDPI())
2036 uno::Reference
<chart::XChartDocument
> xDoc
= getChartDocFromDrawImpress(0, 0);
2037 OString aXmlDump
= OUStringToOString(getShapeDump(xDoc
), RTL_TEXTENCODING_UTF8
);
2038 xmlDocUniquePtr
pXmlDoc(xmlParseDoc(reinterpret_cast<const xmlChar
*>(aXmlDump
.getStr())));
2039 OString
aPath("//XShape[@text='Green; $7,654,321 ']"_ostr
);
2040 assertXPath(pXmlDoc
, aPath
, 1);
2041 // Expected - 1 line tall(371), not 4 lines(1481).
2042 assertXPath(pXmlDoc
, aPath
, "sizeY", u
"371");
2045 CPPUNIT_TEST_FIXTURE(Chart2ImportTest
, testTdf146756
)
2047 // FIXME: the DPI check should be removed when either (1) the test is fixed to work with
2048 // non-default DPI; or (2) unit tests on Windows are made to use svp VCL plugin.
2049 if (!IsDefaultDPI())
2052 // given a chart on page 2
2053 loadFromFile(u
"pptx/tdf146756_bestFit.pptx");
2054 Reference
<chart::XChartDocument
> xChartDoc
= getChartDocFromDrawImpress(1, 0);
2055 OString aXmlDump
= OUStringToOString(getShapeDump(xChartDoc
), RTL_TEXTENCODING_UTF8
);
2056 xmlDocUniquePtr
pXmlDoc(xmlParseDoc(reinterpret_cast<const xmlChar
*>(aXmlDump
.getStr())));
2057 OString
aPath("//XShape[@text='New service request and approval; 18%']"_ostr
);
2058 assertXPath(pXmlDoc
, aPath
, 1);
2059 // Expected something like 4 lines tall(1697), not 11 lines(3817).
2060 assertXPath(pXmlDoc
, aPath
, "sizeY", u
"1697");
2061 // Expected some reasonable maximum text length for the label like 2350, not 881.
2062 sal_Int32 nTextLength
= getXPath(pXmlDoc
, aPath
, "textMaximumFrameWidth").toInt32();
2063 CPPUNIT_ASSERT_EQUAL(sal_Int32(2350), nTextLength
);
2064 // MSO doesn't allow much more than 1/5 of the total chart width, so never go higher than that
2065 CPPUNIT_ASSERT_LESS(sal_Int32(2370.6), nTextLength
);
2068 CPPUNIT_TEST_FIXTURE(Chart2ImportTest
, testFixedSizeBarChartVeryLongLabel
)
2070 // Bar chart area size is fixed (not automatic) so we can't resize
2071 // the chart area to let the label break into multiple lines. In this
2072 // case the best course of action is to just crop the label text. This
2073 // test checks that the rendered text is actually cropped.
2075 loadFromFile(u
"odp/BarChartVeryLongLabel.odp");
2077 // Select shape 0 which has fixed size chart
2078 Reference
<chart2::XChartDocument
> xChartDoc(getChartDocFromDrawImpress(0, 0), uno::UNO_QUERY
);
2079 CPPUNIT_ASSERT(xChartDoc
.is());
2081 Reference
<chart2::XAxis
> xHAxis
= getAxisFromDoc(xChartDoc
, 0, 0, 0);
2082 CPPUNIT_ASSERT(xHAxis
.is());
2084 chart2::ScaleData aScaleData
= xHAxis
->getScaleData();
2085 CPPUNIT_ASSERT(aScaleData
.Categories
.is());
2087 Reference
<chart2::data::XLabeledDataSequence
> xLabeledDataSequence
= aScaleData
.Categories
;
2088 CPPUNIT_ASSERT(xLabeledDataSequence
.is());
2090 Reference
<chart2::data::XDataSequence
> xDataSequence
= xLabeledDataSequence
->getValues();
2091 CPPUNIT_ASSERT(xDataSequence
.is());
2093 Reference
<chart2::data::XTextualDataSequence
> xTextualDataSequence(xDataSequence
, uno::UNO_QUERY
);
2094 CPPUNIT_ASSERT(xTextualDataSequence
.is());
2096 std::vector
<OUString
> aCategories
;
2097 const Sequence
<OUString
> aTextData(xTextualDataSequence
->getTextualData());
2098 ::std::copy(aTextData
.begin(), aTextData
.end(),
2099 ::std::back_inserter(aCategories
));
2101 // Check that we have a very very long label text
2102 CPPUNIT_ASSERT_EQUAL(u
"Very very very very very very very very very very very loooooooooooong label"_ustr
, aCategories
[0]);
2104 // Check visible text
2105 uno::Reference
<drawing::XDrawPageSupplier
> xDrawPageSupplier(xChartDoc
, uno::UNO_QUERY
);
2106 uno::Reference
<drawing::XDrawPage
> xDrawPage
= xDrawPageSupplier
->getDrawPage();
2107 uno::Reference
<drawing::XShapes
> xShapes(xDrawPage
->getByIndex(0), uno::UNO_QUERY
);
2108 CPPUNIT_ASSERT(xShapes
.is());
2110 uno::Reference
<drawing::XShape
> xXAxis
= getShapeByName(xShapes
, u
"CID/D=0:CS=0:Axis=0,0"_ustr
,
2111 // Axis occurs twice in chart xshape representation so need to get the one related to labels
2112 [](const uno::Reference
<drawing::XShape
>& rXShape
) -> bool
2114 uno::Reference
<drawing::XShapes
> xAxisShapes(rXShape
, uno::UNO_QUERY
);
2115 CPPUNIT_ASSERT(xAxisShapes
.is());
2116 uno::Reference
<drawing::XShape
> xChildShape(xAxisShapes
->getByIndex(0), uno::UNO_QUERY
);
2117 uno::Reference
< drawing::XShapeDescriptor
> xShapeDescriptor(xChildShape
, uno::UNO_QUERY_THROW
);
2118 return (xShapeDescriptor
->getShapeType() == "com.sun.star.drawing.TextShape");
2120 CPPUNIT_ASSERT(xXAxis
.is());
2122 uno::Reference
<container::XIndexAccess
> xIndexAccess(xXAxis
, UNO_QUERY_THROW
);
2124 // Check text is actually cropped. Depending on DPI,
2125 // it may be "Very very very very very very..." or "Very very very very very ver..."
2126 uno::Reference
<text::XTextRange
> xLabel(xIndexAccess
->getByIndex(0), uno::UNO_QUERY_THROW
);
2127 const OUString aLabelString
= xLabel
->getString();
2128 CPPUNIT_ASSERT_LESSEQUAL(sal_Int32(32), aLabelString
.getLength());
2129 CPPUNIT_ASSERT(aLabelString
.endsWith(u
"..."));
2131 uno::Reference
<drawing::XShape
> xChartWall
= getShapeByName(xShapes
, u
"CID/DiagramWall="_ustr
);
2132 CPPUNIT_ASSERT(xChartWall
.is());
2134 // The text shape width should be smaller than the chart wall
2135 CPPUNIT_ASSERT_LESS(xChartWall
->getSize().Width
, xXAxis
->getSize().Width
);
2137 CPPUNIT_ASSERT_DOUBLES_EQUAL(7113, xChartWall
->getSize().Height
, 100);
2138 CPPUNIT_ASSERT_DOUBLES_EQUAL(398, xXAxis
->getSize().Height
, 100);
2141 CPPUNIT_TEST_FIXTURE(Chart2ImportTest
, testAutomaticSizeBarChartVeryLongLabel
)
2143 // Bar chart area size is automatic so we expect the label to be broken
2144 // into multiple lines.
2146 loadFromFile(u
"odp/BarChartVeryLongLabel.odp");
2148 // Select shape 1, which has an automatic sized chart
2149 Reference
<chart2::XChartDocument
> xChartDoc(getChartDocFromDrawImpress(0, 1), uno::UNO_QUERY
);
2150 CPPUNIT_ASSERT(xChartDoc
.is());
2152 Reference
<chart2::XAxis
> xHAxis
= getAxisFromDoc(xChartDoc
, 0, 0, 0);
2153 CPPUNIT_ASSERT(xHAxis
.is());
2155 chart2::ScaleData aScaleData
= xHAxis
->getScaleData();
2156 CPPUNIT_ASSERT(aScaleData
.Categories
.is());
2158 Reference
<chart2::data::XLabeledDataSequence
> xLabeledDataSequence
= aScaleData
.Categories
;
2159 CPPUNIT_ASSERT(xLabeledDataSequence
.is());
2161 Reference
<chart2::data::XDataSequence
> xDataSequence
= xLabeledDataSequence
->getValues();
2162 CPPUNIT_ASSERT(xDataSequence
.is());
2164 Reference
<chart2::data::XTextualDataSequence
> xTextualDataSequence(xDataSequence
, uno::UNO_QUERY
);
2165 CPPUNIT_ASSERT(xTextualDataSequence
.is());
2167 std::vector
<OUString
> aCategories
;
2168 const Sequence
<OUString
> aTextData(xTextualDataSequence
->getTextualData());
2169 ::std::copy(aTextData
.begin(), aTextData
.end(),
2170 ::std::back_inserter(aCategories
));
2172 // Check that we have a very very long label text
2173 CPPUNIT_ASSERT_EQUAL(u
"Very very very very very very very very very very very loooooooooooong label"_ustr
, aCategories
[0]);
2175 // Check visible text
2176 uno::Reference
<drawing::XDrawPageSupplier
> xDrawPageSupplier(xChartDoc
, uno::UNO_QUERY
);
2177 uno::Reference
<drawing::XDrawPage
> xDrawPage
= xDrawPageSupplier
->getDrawPage();
2178 uno::Reference
<drawing::XShapes
> xShapes(xDrawPage
->getByIndex(0), uno::UNO_QUERY
);
2179 CPPUNIT_ASSERT(xShapes
.is());
2181 uno::Reference
<drawing::XShape
> xXAxis
= getShapeByName(xShapes
, u
"CID/D=0:CS=0:Axis=0,0"_ustr
,
2182 // Axis occurs twice in chart xshape representation so need to get the one related to labels
2183 [](const uno::Reference
<drawing::XShape
>& rXShape
) -> bool
2185 uno::Reference
<drawing::XShapes
> xAxisShapes(rXShape
, uno::UNO_QUERY
);
2186 CPPUNIT_ASSERT(xAxisShapes
.is());
2187 uno::Reference
<drawing::XShape
> xChildShape(xAxisShapes
->getByIndex(0), uno::UNO_QUERY
);
2188 uno::Reference
< drawing::XShapeDescriptor
> xShapeDescriptor(xChildShape
, uno::UNO_QUERY_THROW
);
2189 return (xShapeDescriptor
->getShapeType() == "com.sun.star.drawing.TextShape");
2191 CPPUNIT_ASSERT(xXAxis
.is());
2193 uno::Reference
<container::XIndexAccess
> xIndexAccess(xXAxis
, UNO_QUERY_THROW
);
2195 // Check text is unmodified
2196 uno::Reference
<text::XTextRange
> xLabel(xIndexAccess
->getByIndex(0), uno::UNO_QUERY
);
2197 CPPUNIT_ASSERT_EQUAL(u
"Very very very very very very very very very very very loooooooooooong label"_ustr
, xLabel
->getString());
2199 uno::Reference
<drawing::XShape
> xChartWall
= getShapeByName(xShapes
, u
"CID/DiagramWall="_ustr
);
2200 CPPUNIT_ASSERT(xChartWall
.is());
2202 // The text shape width should be smaller than the chart wall
2203 CPPUNIT_ASSERT_LESS(xChartWall
->getSize().Width
, xXAxis
->getSize().Width
);
2205 CPPUNIT_ASSERT_DOUBLES_EQUAL(7200, xChartWall
->getSize().Height
, 100);
2206 CPPUNIT_ASSERT_DOUBLES_EQUAL(1192, xXAxis
->getSize().Height
, 100);
2209 CPPUNIT_TEST_FIXTURE(Chart2ImportTest
, testTotalsRowIgnored
)
2211 loadFromFile(u
"xlsx/barchart_totalsrow.xlsx");
2213 uno::Reference
<chart2::XChartDocument
> xChartDoc
= getChartDocFromSheet(0);
2214 CPPUNIT_ASSERT(xChartDoc
.is());
2216 Reference
<chart2::data::XDataSequence
> xDataSeq
=
2217 getDataSequenceFromDocByRole(xChartDoc
, u
"values-y");
2218 CPPUNIT_ASSERT(xDataSeq
.is());
2220 // Table data range is D2:D9 (8 rows) but because last row is totals row it is ignored
2221 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt32
>(7u), xDataSeq
->getData().size());
2224 uno::Reference
<chart2::XChartDocument
> xChartDoc
= getChartDocFromSheet(1);
2225 CPPUNIT_ASSERT(xChartDoc
.is());
2227 Reference
<chart2::data::XDataSequence
> xDataSeq
=
2228 getDataSequenceFromDocByRole(xChartDoc
, u
"values-y");
2229 CPPUNIT_ASSERT(xDataSeq
.is());
2231 // Table data range is D2:D10 (9 rows) and totals row isn't the last row so it's not ignored
2232 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt32
>(9u), xDataSeq
->getData().size());
2236 CPPUNIT_TEST_FIXTURE(Chart2ImportTest
, testPieChartPlotAreaMarginWithAutomaticLayout
)
2238 auto verify
= [this](std::u16string_view rName
, const Size
& rSize
, const Point
& rPoint
)
2240 uno::Reference
<drawing::XDrawPagesSupplier
> xPages(mxComponent
, uno::UNO_QUERY
);
2241 CPPUNIT_ASSERT(xPages
);
2243 uno::Reference
<drawing::XDrawPage
> xPage(xPages
->getDrawPages()->getByIndex(0), uno::UNO_QUERY
);
2244 CPPUNIT_ASSERT(xPage
);
2246 uno::Reference
<chart::XChartDocument
> xChart
;
2247 for (sal_Int32 i
=0; i
< xPage
->getCount(); ++i
)
2249 uno::Reference
<container::XNamed
> xNamedShape(xPage
->getByIndex(i
), uno::UNO_QUERY
);
2250 if (!xNamedShape
.is())
2253 if (xNamedShape
->getName() != rName
)
2256 uno::Reference
<beans::XPropertySet
> xShapeProps(xNamedShape
, uno::UNO_QUERY
);
2257 if (!xShapeProps
.is())
2260 uno::Reference
<frame::XModel
> xDocModel
;
2261 xShapeProps
->getPropertyValue(u
"Model"_ustr
) >>= xDocModel
;
2262 if (!xDocModel
.is())
2265 xChart
.set(xDocModel
, uno::UNO_QUERY
);
2267 CPPUNIT_ASSERT(xChart
);
2269 uno::Reference
<chart2::XChartDocument
>xChartDocument(xChart
, uno::UNO_QUERY
);
2270 CPPUNIT_ASSERT(xChartDocument
.is());
2272 // Get the shape of the diagram / chart
2273 uno::Reference
<drawing::XDrawPageSupplier
> xDrawPageSupplier(xChartDocument
, uno::UNO_QUERY
);
2274 CPPUNIT_ASSERT(xDrawPageSupplier
.is());
2275 uno::Reference
<drawing::XDrawPage
> xDrawPage
= xDrawPageSupplier
->getDrawPage();
2276 uno::Reference
<drawing::XShapes
> xShapes(xDrawPage
->getByIndex(0), uno::UNO_QUERY
);
2277 CPPUNIT_ASSERT(xShapes
.is());
2279 uno::Reference
<drawing::XShape
> xChartDiagramShape
= getShapeByName(xShapes
, u
"CID/D=0:CS=0:CT=0:Series=0"_ustr
);
2280 CPPUNIT_ASSERT(xChartDiagramShape
.is());
2283 CPPUNIT_ASSERT_DOUBLES_EQUAL(rSize
.Width(), xChartDiagramShape
->getSize().Width
, 5); // calculated chart area size - 2 * margin
2284 CPPUNIT_ASSERT_DOUBLES_EQUAL(rSize
.Height(), xChartDiagramShape
->getSize().Height
, 5); // calculated chart area size - 2 * margin
2286 CPPUNIT_ASSERT_DOUBLES_EQUAL(rPoint
.X(), xChartDiagramShape
->getPosition().X
, 5); // margin
2287 CPPUNIT_ASSERT_DOUBLES_EQUAL(rPoint
.Y(), xChartDiagramShape
->getPosition().Y
, 5); // margin
2291 // Checks the margin and calculation of the plot area for the pie chart inside the chart area.
2293 loadFromFile(u
"pptx/PieChartWithAutomaticLayout_SizeAndPosition.pptx");
2295 // Chart Wuse case Width == Height
2296 // Load chart Chart_2_2 - 2cm x 2cm -
2297 verify(u
"Chart_2_2", Size(1300, 1300), Point(350, 350));
2299 // Chart use case - Width < Height
2300 // Load chart Chart_3_4 - 3cm x 4cm
2301 verify(u
"Chart_3_4", Size(2300, 2300), Point(350, 850));
2303 // Chart use case - Width > Height
2304 // Load chart Chart_3_2 - 3cm x 2cm
2305 verify(u
"Chart_3_2", Size(1300, 1300), Point(850, 350));
2308 } // end of anonymous namespace
2309 CPPUNIT_PLUGIN_IMPLEMENT();
2311 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */