Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : */
9 :
10 : #include "charttest.hxx"
11 : #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
12 : #include <com/sun/star/chart2/CurveStyle.hpp>
13 : #include <com/sun/star/chart2/DataPointLabel.hpp>
14 : #include <com/sun/star/chart/ErrorBarStyle.hpp>
15 : #include <com/sun/star/chart2/XChartDocument.hpp>
16 : #include <com/sun/star/chart/XChartDocument.hpp>
17 : #include <com/sun/star/chart/XChartData.hpp>
18 : #include <com/sun/star/chart2/XInternalDataProvider.hpp>
19 : #include <com/sun/star/chart/XChartDataArray.hpp>
20 : #include <com/sun/star/drawing/FillStyle.hpp>
21 : #include <com/sun/star/chart/XTwoAxisXSupplier.hpp>
22 :
23 : #include <com/sun/star/util/Color.hpp>
24 :
25 :
26 162 : class Chart2ImportTest : public ChartTest
27 : {
28 : public:
29 : void Fdo60083();
30 : void testSteppedLines();
31 : void testErrorBarRange();
32 : void testErrorBarFormatting();
33 : void testODSChartSeries();
34 : void testXLSXChartSeries();
35 : void testXLSChartSeries();
36 : void testODTChartSeries();
37 : void testDOCChartSeries();
38 : void testDOCXChartSeries();
39 : void testPPTXChartSeries();
40 : /**
41 : * Original data contains 3 series but 2 of them are hidden. For now, we
42 : * detect and skip those hidden series on import (since we don't support
43 : * hidden columns for internal data table yet).
44 : */
45 : void testPPTXHiddenDataSeries();
46 : void testPPTXPercentageNumberFormats();
47 : void testPPTXStackedNonStackedYAxis();
48 : void testPPTChartSeries();
49 : void testODPChartSeries();
50 : void testBnc864396();
51 : void testBnc882383();
52 : void testSimpleStrictXLSX();
53 : void testDelayedCellImport(); // chart range referencing content on later sheets
54 : void testFlatODSStackedColumnChart();
55 : void testFdo78080();
56 : void testFdo54361();
57 : void testFdo54361_1();
58 : void testAutoBackgroundXLSX();
59 : void testTextCanOverlapXLSX();
60 : void testNumberFormatsXLSX();
61 :
62 : void testTransparentBackground(OUString const & filename);
63 :
64 4 : CPPUNIT_TEST_SUITE(Chart2ImportTest);
65 2 : CPPUNIT_TEST(Fdo60083);
66 2 : CPPUNIT_TEST(testSteppedLines);
67 2 : CPPUNIT_TEST(testErrorBarRange);
68 2 : CPPUNIT_TEST(testErrorBarFormatting);
69 2 : CPPUNIT_TEST(testODSChartSeries);
70 2 : CPPUNIT_TEST(testXLSXChartSeries);
71 2 : CPPUNIT_TEST(testXLSChartSeries);
72 2 : CPPUNIT_TEST(testODTChartSeries);
73 2 : CPPUNIT_TEST(testDOCChartSeries);
74 2 : CPPUNIT_TEST(testDOCXChartSeries);
75 2 : CPPUNIT_TEST(testPPTChartSeries);
76 2 : CPPUNIT_TEST(testPPTXChartSeries);
77 2 : CPPUNIT_TEST(testPPTXHiddenDataSeries);
78 2 : CPPUNIT_TEST(testPPTXPercentageNumberFormats);
79 2 : CPPUNIT_TEST(testPPTXStackedNonStackedYAxis);
80 2 : CPPUNIT_TEST(testODPChartSeries);
81 2 : CPPUNIT_TEST(testBnc864396);
82 2 : CPPUNIT_TEST(testBnc882383);
83 2 : CPPUNIT_TEST(testSimpleStrictXLSX);
84 2 : CPPUNIT_TEST(testDelayedCellImport);
85 2 : CPPUNIT_TEST(testFlatODSStackedColumnChart);
86 2 : CPPUNIT_TEST(testFdo78080);
87 2 : CPPUNIT_TEST(testFdo54361);
88 2 : CPPUNIT_TEST(testFdo54361_1);
89 2 : CPPUNIT_TEST(testAutoBackgroundXLSX);
90 2 : CPPUNIT_TEST(testTextCanOverlapXLSX);
91 2 : CPPUNIT_TEST(testNumberFormatsXLSX);
92 4 : CPPUNIT_TEST_SUITE_END();
93 :
94 : private:
95 :
96 : };
97 :
98 : // error bar import
99 : // split method up into smaller chunks for more detailed tests
100 2 : void Chart2ImportTest::Fdo60083()
101 : {
102 2 : load("/chart2/qa/extras/data/ods/", "fdo60083.ods");
103 2 : uno::Reference< chart2::XChartDocument > xChartDoc = getChartDocFromSheet( 0, mxComponent );
104 2 : CPPUNIT_ASSERT(xChartDoc.is());
105 :
106 4 : Reference< chart2::XDataSeries > xDataSeries = getDataSeriesFromDoc( xChartDoc, 0 );
107 2 : CPPUNIT_ASSERT( xDataSeries.is() );
108 :
109 4 : Reference< beans::XPropertySet > xPropSet( xDataSeries, UNO_QUERY_THROW );
110 2 : CPPUNIT_ASSERT( xPropSet.is() );
111 :
112 : // test that y error bars are there
113 4 : Reference< beans::XPropertySet > xErrorBarYProps;
114 2 : xPropSet->getPropertyValue(CHART_UNONAME_ERRORBAR_Y) >>= xErrorBarYProps;
115 2 : CPPUNIT_ASSERT(xErrorBarYProps.is());
116 : {
117 : sal_Int32 nErrorBarStyle;
118 4 : CPPUNIT_ASSERT(
119 : xErrorBarYProps->getPropertyValue("ErrorBarStyle")
120 2 : >>= nErrorBarStyle);
121 4 : CPPUNIT_ASSERT_EQUAL(
122 : static_cast<sal_Int32>(chart::ErrorBarStyle::RELATIVE),
123 2 : nErrorBarStyle);
124 :
125 2 : double nVal = 0.0;
126 4 : CPPUNIT_ASSERT(
127 2 : xErrorBarYProps->getPropertyValue("PositiveError") >>= nVal);
128 2 : CPPUNIT_ASSERT_DOUBLES_EQUAL(5.0, nVal, 1e-8);
129 :
130 4 : CPPUNIT_ASSERT(
131 2 : xErrorBarYProps->getPropertyValue("NegativeError") >>= nVal);
132 2 : CPPUNIT_ASSERT_DOUBLES_EQUAL(5.0, nVal, 1e-8);
133 :
134 : bool bVal;
135 4 : CPPUNIT_ASSERT(
136 2 : xErrorBarYProps->getPropertyValue("ShowPositiveError") >>= bVal);
137 2 : CPPUNIT_ASSERT_EQUAL(bVal, true);
138 :
139 4 : CPPUNIT_ASSERT(
140 2 : xErrorBarYProps->getPropertyValue("ShowNegativeError") >>= bVal);
141 2 : CPPUNIT_ASSERT_EQUAL(bVal, true);
142 : }
143 :
144 : // test that x error bars are not imported
145 4 : Reference< beans::XPropertySet > xErrorBarXProps;
146 2 : xPropSet->getPropertyValue(CHART_UNONAME_ERRORBAR_X) >>= xErrorBarXProps;
147 4 : CPPUNIT_ASSERT(!xErrorBarXProps.is());
148 2 : }
149 :
150 2 : void Chart2ImportTest::testErrorBarRange()
151 : {
152 2 : load("/chart2/qa/extras/data/ods/", "error_bar_range.ods");
153 2 : uno::Reference< chart2::XChartDocument > xChartDoc = getChartDocFromSheet( 0, mxComponent );
154 2 : CPPUNIT_ASSERT(xChartDoc.is());
155 :
156 4 : Reference< chart2::XDataSeries > xDataSeries = getDataSeriesFromDoc( xChartDoc, 0 );
157 2 : CPPUNIT_ASSERT( xDataSeries.is() );
158 :
159 4 : Reference< beans::XPropertySet > xPropSet( xDataSeries, UNO_QUERY_THROW );
160 2 : CPPUNIT_ASSERT( xPropSet.is() );
161 :
162 : // test that y error bars are there
163 4 : Reference< beans::XPropertySet > xErrorBarYProps;
164 2 : xPropSet->getPropertyValue(CHART_UNONAME_ERRORBAR_Y) >>= xErrorBarYProps;
165 2 : CPPUNIT_ASSERT(xErrorBarYProps.is());
166 :
167 : sal_Int32 nErrorBarStyle;
168 4 : CPPUNIT_ASSERT(
169 : xErrorBarYProps->getPropertyValue("ErrorBarStyle")
170 2 : >>= nErrorBarStyle);
171 4 : CPPUNIT_ASSERT_EQUAL(
172 : static_cast<sal_Int32>(chart::ErrorBarStyle::FROM_DATA),
173 2 : nErrorBarStyle);
174 :
175 4 : OUString aRangePos;
176 2 : CPPUNIT_ASSERT(xErrorBarYProps->getPropertyValue("ErrorBarRangePositive") >>= aRangePos);
177 4 : CPPUNIT_ASSERT_EQUAL(aRangePos, OUString("$Sheet1.$C$2:$C$4"));
178 2 : }
179 :
180 2 : void Chart2ImportTest::testErrorBarFormatting()
181 : {
182 2 : load("/chart2/qa/extras/data/ods/", "error_bar_properties.ods");
183 2 : uno::Reference< chart2::XChartDocument > xChartDoc = getChartDocFromSheet( 0, mxComponent );
184 2 : CPPUNIT_ASSERT(xChartDoc.is());
185 :
186 4 : Reference< chart2::XDataSeries > xDataSeries = getDataSeriesFromDoc( xChartDoc, 0 );
187 2 : CPPUNIT_ASSERT( xDataSeries.is() );
188 :
189 4 : Reference< beans::XPropertySet > xPropSet( xDataSeries, UNO_QUERY_THROW );
190 2 : CPPUNIT_ASSERT( xPropSet.is() );
191 :
192 : // test that y error bars are there
193 4 : Reference< beans::XPropertySet > xErrorBarYProps;
194 2 : xPropSet->getPropertyValue(CHART_UNONAME_ERRORBAR_Y) >>= xErrorBarYProps;
195 2 : CPPUNIT_ASSERT(xErrorBarYProps.is());
196 :
197 2 : util::Color aColor(0);
198 2 : xErrorBarYProps->getPropertyValue("LineColor") >>= aColor;
199 2 : sal_uInt32 nColorValue = aColor;
200 4 : CPPUNIT_ASSERT_EQUAL(sal_uInt32(0xff3333), nColorValue);
201 2 : }
202 :
203 : // stepped line interpolation
204 2 : void Chart2ImportTest::testSteppedLines()
205 : {
206 2 : const sal_Int32 MAXSHEET = 14;
207 : chart2::CurveStyle curveStyle[] = {
208 : chart2::CurveStyle_LINES,
209 : chart2::CurveStyle_CUBIC_SPLINES,
210 : chart2::CurveStyle_B_SPLINES,
211 : chart2::CurveStyle_STEP_START,
212 : chart2::CurveStyle_STEP_END,
213 : chart2::CurveStyle_STEP_CENTER_X,
214 : chart2::CurveStyle_STEP_CENTER_Y,
215 : chart2::CurveStyle_LINES,
216 : chart2::CurveStyle_CUBIC_SPLINES,
217 : chart2::CurveStyle_B_SPLINES,
218 : chart2::CurveStyle_STEP_START,
219 : chart2::CurveStyle_STEP_END,
220 : chart2::CurveStyle_STEP_CENTER_X,
221 : chart2::CurveStyle_STEP_CENTER_Y
222 2 : };
223 :
224 2 : load("/chart2/qa/extras/data/ods/", "stepped_lines.ods");
225 30 : for(sal_Int32 nSheet = 0; nSheet < MAXSHEET; ++nSheet)
226 : {
227 28 : uno::Reference< chart2::XChartDocument > xChart2Doc = getChartDocFromSheet( nSheet, mxComponent );
228 28 : CPPUNIT_ASSERT(xChart2Doc.is());
229 :
230 56 : Reference< chart2::XChartType > xChartType = getChartTypeFromDoc( xChart2Doc, 0 );
231 28 : CPPUNIT_ASSERT(xChartType.is());
232 :
233 56 : Reference< beans::XPropertySet > xPropSet( xChartType, UNO_QUERY );
234 28 : CPPUNIT_ASSERT(xPropSet.is());
235 :
236 : chart2::CurveStyle eCurveStyle;
237 28 : xPropSet->getPropertyValue("CurveStyle") >>= eCurveStyle;
238 28 : CPPUNIT_ASSERT_EQUAL(eCurveStyle, curveStyle[nSheet]);
239 28 : }
240 2 : }
241 :
242 6 : uno::Sequence < OUString > getChartColumnDescriptions( uno::Reference< chart::XChartDocument > xChart1Doc)
243 : {
244 6 : CPPUNIT_ASSERT(xChart1Doc.is());
245 6 : uno::Reference< chart::XChartDataArray > xChartData ( xChart1Doc->getData(), UNO_QUERY_THROW);
246 6 : CPPUNIT_ASSERT(xChartData.is());
247 6 : uno::Sequence < OUString > seriesList = xChartData->getColumnDescriptions();
248 6 : return seriesList;
249 : }
250 :
251 2 : void Chart2ImportTest::testODSChartSeries()
252 : {
253 2 : load("/chart2/qa/extras/data/ods/", "chart.ods");
254 2 : uno::Reference< chart::XChartDocument > xChart1Doc ( getChartCompFromSheet( 0, mxComponent ), UNO_QUERY_THROW);
255 4 : uno::Sequence < OUString > seriesList = getChartColumnDescriptions( xChart1Doc);
256 2 : CPPUNIT_ASSERT_EQUAL(OUString("Col 1"), seriesList[0]);
257 2 : CPPUNIT_ASSERT_EQUAL(OUString("Col2"), seriesList[1]);
258 4 : CPPUNIT_ASSERT_EQUAL(OUString("Col 33"), seriesList[2]);
259 :
260 2 : }
261 :
262 2 : void Chart2ImportTest::testXLSXChartSeries()
263 : {
264 2 : load("/chart2/qa/extras/data/xlsx/", "chart.xlsx");
265 2 : uno::Reference< chart::XChartDocument > xChart1Doc ( getChartCompFromSheet( 0, mxComponent ), UNO_QUERY_THROW);
266 4 : uno::Sequence < OUString > seriesList = getChartColumnDescriptions(xChart1Doc );
267 2 : CPPUNIT_ASSERT_EQUAL(OUString("Col 1"), seriesList[0]);
268 2 : CPPUNIT_ASSERT_EQUAL(OUString("Col2"), seriesList[1]);
269 4 : CPPUNIT_ASSERT_EQUAL(OUString("Col 33"), seriesList[2]);
270 :
271 2 : }
272 :
273 2 : void Chart2ImportTest::testXLSChartSeries()
274 : {
275 2 : load("/chart2/qa/extras/data/xls/", "chart.xls");
276 2 : uno::Reference< chart::XChartDocument > xChart1Doc ( getChartCompFromSheet( 0, mxComponent ), UNO_QUERY_THROW);
277 4 : uno::Sequence < OUString > seriesList = getChartColumnDescriptions(xChart1Doc );
278 2 : CPPUNIT_ASSERT_EQUAL(OUString("Col 1"), seriesList[0]);
279 2 : CPPUNIT_ASSERT_EQUAL(OUString("Col 2"), seriesList[1]);
280 4 : CPPUNIT_ASSERT_EQUAL(OUString("Col 3"), seriesList[2]);
281 :
282 2 : }
283 :
284 2 : void Chart2ImportTest::testODTChartSeries()
285 : {
286 2 : load("/chart2/qa/extras/data/odt/", "chart.odt");
287 2 : uno::Sequence< OUString > seriesList = getWriterChartColumnDescriptions(mxComponent);
288 2 : CPPUNIT_ASSERT_EQUAL(OUString("Column 1"), seriesList[0]);
289 2 : CPPUNIT_ASSERT_EQUAL(OUString("Column 2"), seriesList[1]);
290 2 : CPPUNIT_ASSERT_EQUAL(OUString("Column 3"), seriesList[2]);
291 :
292 2 : }
293 :
294 2 : void Chart2ImportTest::testDOCChartSeries()
295 : {
296 2 : load("/chart2/qa/extras/data/doc/", "chart.doc");
297 2 : uno::Sequence< OUString > seriesList = getWriterChartColumnDescriptions(mxComponent);
298 2 : CPPUNIT_ASSERT_EQUAL(OUString("Column 1"), seriesList[0]);
299 2 : CPPUNIT_ASSERT_EQUAL(OUString("Column 2"), seriesList[1]);
300 2 : CPPUNIT_ASSERT_EQUAL(OUString("Column 3"), seriesList[2]);
301 2 : }
302 :
303 2 : void Chart2ImportTest::testDOCXChartSeries()
304 : {
305 2 : load("/chart2/qa/extras/data/docx/", "chart.docx");
306 2 : Reference<chart2::XChartDocument> xChartDoc(getChartDocFromWriter(0), uno::UNO_QUERY);
307 2 : CPPUNIT_ASSERT(xChartDoc.is());
308 :
309 4 : Reference<chart2::XChartType> xCT = getChartTypeFromDoc(xChartDoc, 0, 0);
310 2 : CPPUNIT_ASSERT(xCT.is());
311 :
312 4 : std::vector<uno::Sequence<uno::Any> > aLabels = getDataSeriesLabelsFromChartType(xCT);
313 2 : CPPUNIT_ASSERT_EQUAL(size_t(3), aLabels.size());
314 2 : CPPUNIT_ASSERT_EQUAL(OUString("Series 1"), aLabels[0][0].get<OUString>());
315 2 : CPPUNIT_ASSERT_EQUAL(OUString("Series 2"), aLabels[1][0].get<OUString>());
316 4 : CPPUNIT_ASSERT_EQUAL(OUString("Series 3"), aLabels[2][0].get<OUString>());
317 2 : }
318 :
319 2 : void Chart2ImportTest::testPPTChartSeries()
320 : {
321 : //test chart series names for ppt
322 2 : uno::Sequence < OUString > seriesList = getImpressChartColumnDescriptions("/chart2/qa/extras/data/ppt/", "chart.ppt");
323 :
324 2 : CPPUNIT_ASSERT_EQUAL(OUString("Column 1"), seriesList[0]);
325 2 : CPPUNIT_ASSERT_EQUAL(OUString("Column 2"), seriesList[1]);
326 2 : CPPUNIT_ASSERT_EQUAL(OUString("Column 3"), seriesList[2]);
327 :
328 2 : }
329 :
330 2 : void Chart2ImportTest::testPPTXChartSeries()
331 : {
332 : //test chart series names for pptx
333 2 : load("/chart2/qa/extras/data/pptx/", "chart.pptx");
334 2 : Reference<chart2::XChartDocument> xChartDoc(getChartDocFromDrawImpress(0, 0), uno::UNO_QUERY);
335 2 : CPPUNIT_ASSERT(xChartDoc.is());
336 :
337 4 : Reference<chart2::XChartType> xCT = getChartTypeFromDoc(xChartDoc, 0, 0);
338 2 : CPPUNIT_ASSERT(xCT.is());
339 :
340 4 : std::vector<uno::Sequence<uno::Any> > aLabels = getDataSeriesLabelsFromChartType(xCT);
341 2 : CPPUNIT_ASSERT_EQUAL(size_t(3), aLabels.size());
342 2 : CPPUNIT_ASSERT_EQUAL(OUString("Column 1"), aLabels[0][0].get<OUString>());
343 2 : CPPUNIT_ASSERT_EQUAL(OUString("Column 2"), aLabels[1][0].get<OUString>());
344 4 : CPPUNIT_ASSERT_EQUAL(OUString("Column 3"), aLabels[2][0].get<OUString>());
345 2 : }
346 :
347 2 : void Chart2ImportTest::testPPTXHiddenDataSeries()
348 : {
349 2 : load("/chart2/qa/extras/data/pptx/", "stacked-bar-chart-hidden-series.pptx");
350 2 : Reference<chart2::XChartDocument> xChartDoc(getChartDocFromDrawImpress(0, 0), uno::UNO_QUERY);
351 2 : CPPUNIT_ASSERT(xChartDoc.is());
352 :
353 : // "Automatic" chart background fill in pptx should be loaded as no fill.
354 4 : Reference<beans::XPropertySet> xPropSet = xChartDoc->getPageBackground();
355 2 : CPPUNIT_ASSERT(xPropSet.is());
356 2 : drawing::FillStyle eStyle = xPropSet->getPropertyValue("FillStyle").get<drawing::FillStyle>();
357 4 : CPPUNIT_ASSERT_MESSAGE("'Automatic' chart background fill in pptx should be loaded as no fill (transparent).",
358 2 : eStyle == drawing::FillStyle_NONE);
359 :
360 4 : Reference<chart2::XChartType> xCT = getChartTypeFromDoc(xChartDoc, 0, 0);
361 2 : CPPUNIT_ASSERT(xCT.is());
362 :
363 : // There should be only one data series present.
364 4 : std::vector<uno::Sequence<uno::Any> > aLabels = getDataSeriesLabelsFromChartType(xCT);
365 2 : CPPUNIT_ASSERT_EQUAL(size_t(1), aLabels.size());
366 2 : CPPUNIT_ASSERT_EQUAL(OUString("Series 3"), aLabels[0][0].get<OUString>());
367 :
368 : // Test the internal data.
369 2 : CPPUNIT_ASSERT(xChartDoc->hasInternalDataProvider());
370 :
371 4 : Reference<chart2::XInternalDataProvider> xInternalProvider(xChartDoc->getDataProvider(), uno::UNO_QUERY);
372 2 : CPPUNIT_ASSERT(xInternalProvider.is());
373 :
374 4 : Reference<chart::XComplexDescriptionAccess> xDescAccess(xInternalProvider, uno::UNO_QUERY);
375 2 : CPPUNIT_ASSERT(xDescAccess.is());
376 :
377 : // Get the category labels.
378 4 : Sequence<Sequence<OUString> > aCategories = xDescAccess->getComplexRowDescriptions();
379 2 : CPPUNIT_ASSERT_EQUAL(sal_Int32(4), aCategories.getLength());
380 2 : CPPUNIT_ASSERT_EQUAL(OUString("Category 1"), aCategories[0][0]);
381 2 : CPPUNIT_ASSERT_EQUAL(OUString("Category 2"), aCategories[1][0]);
382 2 : CPPUNIT_ASSERT_EQUAL(OUString("Category 3"), aCategories[2][0]);
383 4 : CPPUNIT_ASSERT_EQUAL(OUString("Category 4"), aCategories[3][0]);
384 2 : }
385 :
386 2 : void Chart2ImportTest::testPPTXPercentageNumberFormats()
387 : {
388 2 : load("/chart2/qa/extras/data/pptx/", "percentage-number-formats.pptx");
389 :
390 : // 1st chart
391 2 : Reference<chart2::XChartDocument> xChartDoc(getChartDocFromDrawImpress(0, 0), uno::UNO_QUERY);
392 2 : CPPUNIT_ASSERT(xChartDoc.is());
393 :
394 4 : uno::Reference<chart2::XDataSeries> xDataSeries(getDataSeriesFromDoc(xChartDoc, 0));
395 2 : CPPUNIT_ASSERT(xDataSeries.is());
396 4 : uno::Reference<beans::XPropertySet> xPropertySet;
397 2 : chart2::DataPointLabel aLabel;
398 : sal_Int32 nNumberFormat;
399 2 : const sal_Int32 nPercentFormatSimple = getNumberFormat(xChartDoc, "0%");
400 2 : const sal_Int32 nPercentFormatDecimal = getNumberFormat(xChartDoc, "0.00%");
401 :
402 2 : xPropertySet.set(xDataSeries->getDataPointByIndex(0), uno::UNO_QUERY_THROW);
403 2 : xPropertySet->getPropertyValue("Label") >>= aLabel;
404 2 : CPPUNIT_ASSERT_EQUAL(sal_True, aLabel.ShowNumber);
405 2 : CPPUNIT_ASSERT_EQUAL(sal_True, aLabel.ShowNumberInPercent);
406 2 : xPropertySet->getPropertyValue("PercentageNumberFormat") >>= nNumberFormat;
407 2 : CPPUNIT_ASSERT_EQUAL(nPercentFormatSimple, nNumberFormat);
408 :
409 2 : xPropertySet.set(xDataSeries->getDataPointByIndex(1), uno::UNO_QUERY_THROW);
410 2 : xPropertySet->getPropertyValue("Label") >>= aLabel;
411 2 : CPPUNIT_ASSERT_EQUAL(sal_True, aLabel.ShowNumber);
412 2 : CPPUNIT_ASSERT_EQUAL(sal_True, aLabel.ShowNumberInPercent);
413 2 : xPropertySet->getPropertyValue("PercentageNumberFormat") >>= nNumberFormat;
414 2 : CPPUNIT_ASSERT_EQUAL(nPercentFormatDecimal, nNumberFormat);
415 :
416 2 : xPropertySet.set(xDataSeries->getDataPointByIndex(2), uno::UNO_QUERY_THROW);
417 2 : xPropertySet->getPropertyValue("Label") >>= aLabel;
418 2 : CPPUNIT_ASSERT_EQUAL(sal_False, aLabel.ShowNumber);
419 2 : CPPUNIT_ASSERT_EQUAL(sal_True, aLabel.ShowNumberInPercent);
420 2 : xPropertySet->getPropertyValue("PercentageNumberFormat") >>= nNumberFormat;
421 2 : CPPUNIT_ASSERT_EQUAL(nPercentFormatSimple, nNumberFormat);
422 :
423 2 : xPropertySet.set(xDataSeries->getDataPointByIndex(3), uno::UNO_QUERY_THROW);
424 2 : xPropertySet->getPropertyValue("Label") >>= aLabel;
425 2 : CPPUNIT_ASSERT_EQUAL(sal_False, aLabel.ShowNumber);
426 2 : CPPUNIT_ASSERT_EQUAL(sal_True, aLabel.ShowNumberInPercent);
427 2 : xPropertySet->getPropertyValue("PercentageNumberFormat") >>= nNumberFormat;
428 2 : CPPUNIT_ASSERT_EQUAL(nPercentFormatDecimal, nNumberFormat);
429 :
430 : // 2nd chart
431 2 : xChartDoc.set(getChartDocFromDrawImpress(1, 0), uno::UNO_QUERY);
432 2 : CPPUNIT_ASSERT(xChartDoc.is());
433 :
434 4 : Reference<chart2::XAxis> xYAxis = getAxisFromDoc(xChartDoc, 0, 1, 0);
435 2 : CPPUNIT_ASSERT(xYAxis.is());
436 :
437 4 : Reference<beans::XPropertySet> xPS(xYAxis, uno::UNO_QUERY_THROW);
438 2 : bool bLinkNumberFormatToSource = true;
439 2 : bool bSuccess = xPS->getPropertyValue(CHART_UNONAME_LINK_TO_SRC_NUMFMT) >>= bLinkNumberFormatToSource;
440 2 : CPPUNIT_ASSERT_MESSAGE("\"LinkNumberFormatToSource\" should be set to false.", bSuccess && !bLinkNumberFormatToSource);
441 :
442 : // FIXME: This should be in fact "0.00%".
443 : // see TODO in oox/source/drawingml/chart/modelbase.cxx
444 2 : const sal_Int32 nPercentFormatDecimalShort = getNumberFormat(xChartDoc, "0.0%");
445 2 : nNumberFormat = getNumberFormatFromAxis(xYAxis);
446 2 : CPPUNIT_ASSERT_EQUAL(nPercentFormatDecimalShort, nNumberFormat);
447 2 : sal_Int16 nType = getNumberFormatType(xChartDoc, nNumberFormat);
448 4 : CPPUNIT_ASSERT_MESSAGE("Y axis should be a percent format.", (nType & util::NumberFormat::PERCENT));
449 2 : }
450 :
451 2 : void Chart2ImportTest::testPPTXStackedNonStackedYAxis()
452 : {
453 2 : load("/chart2/qa/extras/data/pptx/", "stacked-non-stacked-mix-y-axis.pptx");
454 :
455 : // 1st chart is a normal stacked column.
456 2 : Reference<chart2::XChartDocument> xChartDoc(getChartDocFromDrawImpress(0, 0), uno::UNO_QUERY);
457 2 : CPPUNIT_ASSERT(xChartDoc.is());
458 :
459 4 : Reference<chart2::XTitled> xTitled(xChartDoc, uno::UNO_QUERY_THROW);
460 4 : OUString aTitle = getTitleString(xTitled);
461 2 : CPPUNIT_ASSERT_EQUAL(OUString("Stacked"), aTitle);
462 :
463 : // Get the Y-axis.
464 4 : Reference<chart2::XAxis> xYAxis = getAxisFromDoc(xChartDoc, 0, 1, 0);
465 2 : CPPUNIT_ASSERT(xYAxis.is());
466 :
467 2 : sal_Int32 nNumberFormat = getNumberFormatFromAxis(xYAxis);
468 2 : sal_Int16 nType = getNumberFormatType(xChartDoc, nNumberFormat);
469 2 : CPPUNIT_ASSERT_MESSAGE("Y axis should be a normal number format.", (nType & util::NumberFormat::NUMBER));
470 2 : CPPUNIT_ASSERT_MESSAGE("Y axis should NOT be a percent format.", !(nType & util::NumberFormat::PERCENT));
471 :
472 : // 2nd chart is a percent-stacked column.
473 2 : xChartDoc.set(getChartDocFromDrawImpress(1, 0), uno::UNO_QUERY);
474 2 : CPPUNIT_ASSERT(xChartDoc.is());
475 :
476 2 : xTitled.set(xChartDoc, uno::UNO_QUERY_THROW);
477 2 : aTitle = getTitleString(xTitled);
478 2 : CPPUNIT_ASSERT_EQUAL(OUString("100% Stacked"), aTitle);
479 :
480 : // Get the Y-axis.
481 2 : xYAxis = getAxisFromDoc(xChartDoc, 0, 1, 0);
482 2 : CPPUNIT_ASSERT(xYAxis.is());
483 :
484 : // Get the number format of the Y-axis.
485 2 : nNumberFormat = getNumberFormatFromAxis(xYAxis);
486 2 : nType = getNumberFormatType(xChartDoc, nNumberFormat);
487 2 : CPPUNIT_ASSERT_MESSAGE("Y axis should be a percent format.", (nType & util::NumberFormat::PERCENT));
488 :
489 : // 3rd chart is a mixture of normal-stacked column with a percent-stacked
490 : // area chart series. Excel in this case sets the Y-axis to be
491 : // non-percent axis and we should do the same for interoperability.
492 2 : xChartDoc.set(getChartDocFromDrawImpress(2, 0), uno::UNO_QUERY);
493 2 : CPPUNIT_ASSERT(xChartDoc.is());
494 :
495 2 : xTitled.set(xChartDoc, uno::UNO_QUERY_THROW);
496 2 : aTitle = getTitleString(xTitled);
497 2 : CPPUNIT_ASSERT_EQUAL(OUString("Stacked column mixed with 100% stacked area"), aTitle);
498 :
499 : // Get the Y-axis.
500 2 : xYAxis = getAxisFromDoc(xChartDoc, 0, 1, 0);
501 2 : CPPUNIT_ASSERT(xYAxis.is());
502 :
503 : // Get the number format of the Y-axis.
504 2 : nNumberFormat = getNumberFormatFromAxis(xYAxis);
505 2 : nType = getNumberFormatType(xChartDoc, nNumberFormat);
506 2 : CPPUNIT_ASSERT_MESSAGE("Y axis should be a normal number format.", (nType & util::NumberFormat::NUMBER));
507 4 : CPPUNIT_ASSERT_MESSAGE("Y axis should NOT be a percent format.", !(nType & util::NumberFormat::PERCENT));
508 2 : }
509 :
510 2 : void Chart2ImportTest::testODPChartSeries()
511 : {
512 : //test chart series names for odp
513 2 : uno::Sequence < OUString > seriesList = getImpressChartColumnDescriptions("/chart2/qa/extras/data/odp/", "chart.odp");
514 2 : CPPUNIT_ASSERT_EQUAL(OUString("Column 1"), seriesList[0]);
515 2 : CPPUNIT_ASSERT_EQUAL(OUString("Column 2"), seriesList[1]);
516 2 : CPPUNIT_ASSERT_EQUAL(OUString("Column 3"), seriesList[2]);
517 :
518 2 : }
519 :
520 2 : void Chart2ImportTest::testBnc864396()
521 : {
522 2 : uno::Reference< chart2::XChartDocument > xChartDoc(getChartDocFromImpress("/chart2/qa/extras/data/pptx/", "bnc864396.pptx"), uno::UNO_QUERY_THROW);
523 2 : CPPUNIT_ASSERT(xChartDoc->hasInternalDataProvider());
524 :
525 4 : uno::Reference< chart2::XInternalDataProvider > xDataProvider( xChartDoc->getDataProvider(), uno::UNO_QUERY_THROW );
526 4 : uno::Reference< chart::XChartDataArray > xChartDataArray(xDataProvider, uno::UNO_QUERY_THROW);
527 4 : uno::Sequence< OUString > aRowLabels = xChartDataArray->getRowDescriptions();
528 8 : for(sal_Int32 i = 0; i < aRowLabels.getLength(); ++i)
529 : {
530 6 : OUString aExpected = OUString("cat") + OUString::number(i+1);
531 6 : CPPUNIT_ASSERT_EQUAL(aExpected, aRowLabels[i]);
532 8 : }
533 2 : }
534 :
535 2 : void Chart2ImportTest::testBnc882383()
536 : {
537 2 : load("/chart2/qa/extras/data/pptx/", "bnc882383.pptx");
538 2 : uno::Reference<chart2::XChartDocument> xChartDoc(getChartDocFromDrawImpress(0, 0), uno::UNO_QUERY_THROW);
539 4 : uno::Reference<chart2::XDataSeries> xDataSeries(getDataSeriesFromDoc(xChartDoc, 0));
540 2 : CPPUNIT_ASSERT(xDataSeries.is());
541 :
542 4 : uno::Reference<beans::XPropertySet> xPropertySet(xDataSeries->getDataPointByIndex(0), uno::UNO_QUERY_THROW);
543 4 : OUString sGradientName;
544 2 : xPropertySet->getPropertyValue("GradientName") >>= sGradientName;
545 4 : CPPUNIT_ASSERT(!sGradientName.isEmpty());
546 2 : }
547 :
548 2 : void Chart2ImportTest::testSimpleStrictXLSX()
549 : {
550 2 : load("/chart2/qa/extras/data/xlsx/", "strict_chart.xlsx");
551 2 : uno::Reference< chart2::XChartDocument > xChartDoc = getChartDocFromSheet( 0, mxComponent );
552 2 : CPPUNIT_ASSERT(xChartDoc.is());
553 :
554 4 : Reference< chart2::XDataSeries > xDataSeries = getDataSeriesFromDoc( xChartDoc, 0 );
555 4 : CPPUNIT_ASSERT(xDataSeries.is());
556 :
557 2 : }
558 :
559 2 : void Chart2ImportTest::testDelayedCellImport()
560 : {
561 2 : load("/chart2/qa/extras/data/xlsx/", "fdo70609.xlsx");
562 2 : uno::Reference< chart2::XChartDocument > xChartDoc = getChartDocFromSheet( 0, mxComponent );
563 : Reference< chart2::data::XDataSequence > xDataSeq =
564 4 : getDataSequenceFromDocByRole(xChartDoc, "values-x");
565 :
566 4 : OUString aRange = xDataSeq->getSourceRangeRepresentation();
567 4 : CPPUNIT_ASSERT_EQUAL(OUString("$Sheet2.$C$5:$C$9"), aRange);
568 2 : }
569 :
570 2 : void Chart2ImportTest::testFlatODSStackedColumnChart()
571 : {
572 2 : load("/chart2/qa/extras/data/fods/", "stacked-column-chart.fods");
573 2 : Reference<chart2::XChartDocument> xChartDoc = getChartDocFromSheet(0, mxComponent);
574 2 : CPPUNIT_ASSERT(xChartDoc.is());
575 :
576 4 : Reference<chart2::XChartType> xChartType = getChartTypeFromDoc(xChartDoc, 0, 0);
577 2 : CPPUNIT_ASSERT(xChartType.is());
578 :
579 4 : Reference<chart2::XDataSeriesContainer> xDSCont(xChartType, UNO_QUERY);
580 2 : CPPUNIT_ASSERT(xDSCont.is());
581 4 : Sequence<Reference<chart2::XDataSeries> > aSeriesSeq = xDSCont->getDataSeries();
582 :
583 : // The stacked column chart should consist of 5 data series.
584 4 : CPPUNIT_ASSERT_EQUAL(sal_Int32(5), aSeriesSeq.getLength());
585 2 : }
586 :
587 2 : void Chart2ImportTest::testFdo78080()
588 : {
589 2 : load("/chart2/qa/extras/data/xlsx/", "fdo78080.xlsx");
590 2 : Reference<chart2::XChartDocument> xChartDoc = getChartDocFromSheet(0, mxComponent);
591 2 : CPPUNIT_ASSERT(xChartDoc.is());
592 :
593 4 : Reference<chart2::XTitled> xTitled(xChartDoc, uno::UNO_QUERY_THROW);
594 4 : Reference<chart2::XTitle> xTitle = xTitled->getTitleObject();
595 4 : CPPUNIT_ASSERT(!xTitle.is());
596 2 : }
597 :
598 4 : void Chart2ImportTest::testTransparentBackground(OUString const & filename)
599 : {
600 4 : load("/chart2/qa/extras/data/xlsx/", filename);
601 4 : uno::Reference< chart2::XChartDocument > xChartDoc = getChartDocFromSheet(0, mxComponent);
602 4 : CPPUNIT_ASSERT_MESSAGE("failed to load chart", xChartDoc.is());
603 :
604 8 : uno::Reference< chart::XChartDocument > xChart2Doc (xChartDoc, uno::UNO_QUERY);
605 4 : CPPUNIT_ASSERT_MESSAGE("failed to load chart", xChart2Doc.is());
606 :
607 8 : Reference< beans::XPropertySet > xPropSet( xChart2Doc->getArea(), uno::UNO_QUERY);
608 4 : CPPUNIT_ASSERT_MESSAGE("failed to get Area", xPropSet.is());
609 :
610 : com::sun::star::drawing::FillStyle aStyle;
611 4 : xPropSet -> getPropertyValue("FillStyle") >>= aStyle;
612 :
613 8 : CPPUNIT_ASSERT_MESSAGE("Background needs to be with solid fill style", aStyle == 1);
614 4 : }
615 : // 2 test methods here so that tearDown() can dispose the document
616 2 : void Chart2ImportTest::testFdo54361()
617 : {
618 2 : testTransparentBackground("fdo54361.xlsx");
619 2 : }
620 2 : void Chart2ImportTest::testFdo54361_1()
621 : {
622 2 : testTransparentBackground("fdo54361-1.xlsx");
623 2 : }
624 :
625 2 : void Chart2ImportTest::testAutoBackgroundXLSX()
626 : {
627 2 : load("/chart2/qa/extras/data/xlsx/", "chart-auto-background.xlsx");
628 2 : uno::Reference<chart2::XChartDocument> xChartDoc = getChartDocFromSheet(0, mxComponent);
629 2 : CPPUNIT_ASSERT_MESSAGE("failed to load chart", xChartDoc.is());
630 :
631 : // "Automatic" chart background fill in xlsx should be loaded as solid white.
632 4 : Reference<beans::XPropertySet> xPropSet = xChartDoc->getPageBackground();
633 2 : CPPUNIT_ASSERT(xPropSet.is());
634 2 : drawing::FillStyle eStyle = xPropSet->getPropertyValue("FillStyle").get<drawing::FillStyle>();
635 2 : sal_Int32 nColor = xPropSet->getPropertyValue("FillColor").get<sal_Int32>();
636 4 : CPPUNIT_ASSERT_MESSAGE("'Automatic' chart background fill in xlsx should be loaded as solid fill.",
637 2 : eStyle == drawing::FillStyle_SOLID);
638 4 : CPPUNIT_ASSERT_MESSAGE("'Automatic' chart background fill in xlsx should be loaded as solid white.",
639 4 : (nColor & 0x00FFFFFF) == 0x00FFFFFF); // highest 2 bytes are transparency which we ignore here.
640 2 : }
641 :
642 2 : void Chart2ImportTest::testTextCanOverlapXLSX()
643 : {
644 : // fdo#84647 : To check textoverlap value is imported correclty.
645 2 : load("/chart2/qa/extras/data/xlsx/", "chart-text-can-overlap.xlsx");
646 2 : uno::Reference< chart::XDiagram > mxDiagram;
647 4 : uno::Reference< beans::XPropertySet > xAxisProp;
648 2 : bool textCanOverlap = false;
649 4 : uno::Reference< chart::XChartDocument > xChartDoc ( getChartCompFromSheet( 0, mxComponent ), UNO_QUERY_THROW);
650 2 : CPPUNIT_ASSERT(xChartDoc.is());
651 2 : mxDiagram.set(xChartDoc->getDiagram());
652 2 : CPPUNIT_ASSERT(mxDiagram.is());
653 4 : uno::Reference< chart::XAxisXSupplier > xAxisXSupp( mxDiagram, uno::UNO_QUERY );
654 2 : CPPUNIT_ASSERT(xAxisXSupp.is());
655 2 : xAxisProp = xAxisXSupp->getXAxis();
656 2 : xAxisProp->getPropertyValue("TextCanOverlap") >>= textCanOverlap;
657 : // Expected value of 'TextCanOverlap' is true
658 4 : CPPUNIT_ASSERT(textCanOverlap);
659 2 : }
660 :
661 2 : void Chart2ImportTest::testNumberFormatsXLSX()
662 : {
663 2 : load("/chart2/qa/extras/data/xlsx/", "number-formats.xlsx");
664 2 : Reference<chart2::XChartDocument> xChartDoc = getChartDocFromSheet(0, mxComponent);
665 2 : CPPUNIT_ASSERT_MESSAGE("failed to load chart", xChartDoc.is());
666 :
667 4 : uno::Reference<chart2::XDataSeries> xDataSeries(getDataSeriesFromDoc(xChartDoc, 0));
668 2 : CPPUNIT_ASSERT(xDataSeries.is());
669 4 : uno::Reference<beans::XPropertySet> xPropertySet;
670 2 : chart2::DataPointLabel aLabel;
671 : sal_Int32 nNumberFormat;
672 2 : bool bLinkNumberFormatToSource = false;
673 2 : bool bSuccess = false;
674 : const sal_Int32 nChartDataNumberFormat = getNumberFormat(
675 2 : xChartDoc, "_(\"$\"* #,##0_);_(\"$\"* \\(#,##0\\);_(\"$\"* \"-\"??_);_(@_)");
676 :
677 2 : xPropertySet.set(xDataSeries->getDataPointByIndex(0), uno::UNO_QUERY_THROW);
678 2 : xPropertySet->getPropertyValue("Label") >>= aLabel;
679 2 : CPPUNIT_ASSERT_EQUAL(sal_True, aLabel.ShowNumber);
680 2 : CPPUNIT_ASSERT_EQUAL(sal_True, aLabel.ShowNumberInPercent);
681 2 : xPropertySet->getPropertyValue(CHART_UNONAME_NUMFMT) >>= nNumberFormat;
682 2 : CPPUNIT_ASSERT_EQUAL(nChartDataNumberFormat, nNumberFormat);
683 2 : bSuccess = xPropertySet->getPropertyValue("PercentageNumberFormat") >>= nNumberFormat;
684 2 : CPPUNIT_ASSERT_EQUAL(false, bSuccess);
685 2 : bSuccess = xPropertySet->getPropertyValue(CHART_UNONAME_LINK_TO_SRC_NUMFMT) >>= bLinkNumberFormatToSource;
686 2 : CPPUNIT_ASSERT_MESSAGE("\"LinkNumberFormatToSource\" should be set to true.", bSuccess && bLinkNumberFormatToSource);
687 :
688 2 : xPropertySet.set(xDataSeries->getDataPointByIndex(1), uno::UNO_QUERY_THROW);
689 2 : xPropertySet->getPropertyValue("Label") >>= aLabel;
690 2 : CPPUNIT_ASSERT_EQUAL(sal_True, aLabel.ShowNumber);
691 2 : CPPUNIT_ASSERT_EQUAL(sal_False, aLabel.ShowNumberInPercent);
692 2 : xPropertySet->getPropertyValue(CHART_UNONAME_NUMFMT) >>= nNumberFormat;
693 2 : CPPUNIT_ASSERT_EQUAL(nChartDataNumberFormat, nNumberFormat);
694 2 : bSuccess = xPropertySet->getPropertyValue("PercentageNumberFormat") >>= nNumberFormat;
695 2 : CPPUNIT_ASSERT_EQUAL(false, bSuccess);
696 2 : bSuccess = xPropertySet->getPropertyValue(CHART_UNONAME_LINK_TO_SRC_NUMFMT) >>= bLinkNumberFormatToSource;
697 2 : CPPUNIT_ASSERT_MESSAGE("\"LinkNumberFormatToSource\" should be set to true.", bSuccess && bLinkNumberFormatToSource);
698 :
699 2 : xPropertySet.set(xDataSeries->getDataPointByIndex(2), uno::UNO_QUERY_THROW);
700 2 : xPropertySet->getPropertyValue("Label") >>= aLabel;
701 2 : CPPUNIT_ASSERT_EQUAL(sal_False, aLabel.ShowNumber);
702 2 : CPPUNIT_ASSERT_EQUAL(sal_True, aLabel.ShowNumberInPercent);
703 2 : xPropertySet->getPropertyValue(CHART_UNONAME_NUMFMT) >>= nNumberFormat;
704 2 : CPPUNIT_ASSERT_EQUAL(nChartDataNumberFormat, nNumberFormat);
705 2 : bSuccess = xPropertySet->getPropertyValue("PercentageNumberFormat") >>= nNumberFormat;
706 2 : CPPUNIT_ASSERT_EQUAL(false, bSuccess);
707 2 : bSuccess = xPropertySet->getPropertyValue(CHART_UNONAME_LINK_TO_SRC_NUMFMT) >>= bLinkNumberFormatToSource;
708 4 : CPPUNIT_ASSERT_MESSAGE("\"LinkNumberFormatToSource\" should be set to true.", bSuccess && bLinkNumberFormatToSource);
709 2 : }
710 :
711 2 : CPPUNIT_TEST_SUITE_REGISTRATION(Chart2ImportTest);
712 :
713 8 : CPPUNIT_PLUGIN_IMPLEMENT();
714 :
715 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|