tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / chart2 / qa / extras / chart2export.cxx
blob3f37794e1d1040b55cffec13294c01e315eb2ce6
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
10 #include "charttest.hxx"
12 #include <com/sun/star/chart/ErrorBarStyle.hpp>
13 #include <com/sun/star/chart2/XRegressionCurveContainer.hpp>
14 #include <com/sun/star/chart2/MovingAverageType.hpp>
15 #include <com/sun/star/lang/XServiceName.hpp>
16 #include <com/sun/star/text/XTextDocument.hpp>
17 #include <com/sun/star/drawing/LineStyle.hpp>
18 #include <com/sun/star/drawing/FillStyle.hpp>
19 #include <com/sun/star/chart/DataLabelPlacement.hpp>
20 #include <com/sun/star/chart2/PieChartSubType.hpp>
22 using uno::Reference;
23 using beans::XPropertySet;
25 class Chart2ExportTest : public ChartTest
27 public:
28 Chart2ExportTest() : ChartTest(u"/chart2/qa/extras/data/"_ustr) {}
31 namespace {
33 void testErrorBar( Reference< XPropertySet > const & xErrorBar )
35 sal_Int32 nErrorBarStyle;
36 CPPUNIT_ASSERT(
37 xErrorBar->getPropertyValue(u"ErrorBarStyle"_ustr) >>= nErrorBarStyle);
38 CPPUNIT_ASSERT_EQUAL(chart::ErrorBarStyle::RELATIVE, nErrorBarStyle);
39 bool bShowPositive = bool(), bShowNegative = bool();
40 CPPUNIT_ASSERT(
41 xErrorBar->getPropertyValue(u"ShowPositiveError"_ustr) >>= bShowPositive);
42 CPPUNIT_ASSERT(bShowPositive);
43 CPPUNIT_ASSERT(
44 xErrorBar->getPropertyValue(u"ShowNegativeError"_ustr) >>= bShowNegative);
45 CPPUNIT_ASSERT(bShowNegative);
46 double nVal = 0.0;
47 CPPUNIT_ASSERT(xErrorBar->getPropertyValue(u"PositiveError"_ustr) >>= nVal);
48 CPPUNIT_ASSERT_DOUBLES_EQUAL(10.0, nVal, 1e-10);
51 void checkCommonTrendline(
52 Reference<chart2::XRegressionCurve> const & xCurve,
53 double aExpectedExtrapolateForward, double aExpectedExtrapolateBackward,
54 bool aExpectedForceIntercept, double aExpectedInterceptValue,
55 bool aExpectedShowEquation, bool aExpectedR2, bool aExpectedMayHaveR2)
57 Reference<XPropertySet> xProperties( xCurve , uno::UNO_QUERY );
58 CPPUNIT_ASSERT(xProperties.is());
60 double aExtrapolateForward = 0.0;
61 CPPUNIT_ASSERT(xProperties->getPropertyValue(u"ExtrapolateForward"_ustr) >>= aExtrapolateForward);
62 CPPUNIT_ASSERT_EQUAL(aExpectedExtrapolateForward, aExtrapolateForward);
64 double aExtrapolateBackward = 0.0;
65 CPPUNIT_ASSERT(xProperties->getPropertyValue(u"ExtrapolateBackward"_ustr) >>= aExtrapolateBackward);
66 CPPUNIT_ASSERT_EQUAL(aExpectedExtrapolateBackward, aExtrapolateBackward);
68 bool bForceIntercept = false;
69 CPPUNIT_ASSERT(xProperties->getPropertyValue(u"ForceIntercept"_ustr) >>= bForceIntercept);
70 CPPUNIT_ASSERT_EQUAL(aExpectedForceIntercept, bForceIntercept);
72 if (bForceIntercept)
74 double aInterceptValue = 0.0;
75 CPPUNIT_ASSERT(xProperties->getPropertyValue(u"InterceptValue"_ustr) >>= aInterceptValue);
76 CPPUNIT_ASSERT_EQUAL(aExpectedInterceptValue, aInterceptValue);
79 Reference< XPropertySet > xEquationProperties( xCurve->getEquationProperties() );
80 CPPUNIT_ASSERT(xEquationProperties.is());
82 bool bShowEquation = false;
83 CPPUNIT_ASSERT(xEquationProperties->getPropertyValue(u"ShowEquation"_ustr) >>= bShowEquation);
84 CPPUNIT_ASSERT_EQUAL(aExpectedShowEquation, bShowEquation);
86 bool bShowCorrelationCoefficient = false;
87 CPPUNIT_ASSERT(xEquationProperties->getPropertyValue(u"ShowCorrelationCoefficient"_ustr) >>= bShowCorrelationCoefficient);
88 CPPUNIT_ASSERT_EQUAL(aExpectedR2, bShowCorrelationCoefficient);
90 bool bMayHaveR2 = false;
91 CPPUNIT_ASSERT(xEquationProperties->getPropertyValue(u"MayHaveCorrelationCoefficient"_ustr) >>= bMayHaveR2);
92 CPPUNIT_ASSERT_EQUAL(aExpectedMayHaveR2, bMayHaveR2);
95 void checkNameAndType(Reference<XPropertySet> const & xProperties, const OUString& aExpectedName, const OUString& aExpectedServiceName)
97 Reference< lang::XServiceName > xServiceName( xProperties, UNO_QUERY );
98 CPPUNIT_ASSERT(xServiceName.is());
100 OUString aServiceName = xServiceName->getServiceName();
101 CPPUNIT_ASSERT_EQUAL(aExpectedServiceName, aServiceName);
103 OUString aCurveName;
104 CPPUNIT_ASSERT(xProperties->getPropertyValue(u"CurveName"_ustr) >>= aCurveName);
105 CPPUNIT_ASSERT_EQUAL(aExpectedName, aCurveName);
108 void checkLinearTrendline(
109 Reference<chart2::XRegressionCurve> const & xCurve, const OUString& aExpectedName,
110 double aExpectedExtrapolateForward, double aExpectedExtrapolateBackward,
111 double aExpectedInterceptValue)
113 Reference<XPropertySet> xProperties( xCurve , uno::UNO_QUERY );
114 CPPUNIT_ASSERT(xProperties.is());
116 checkNameAndType(xProperties, aExpectedName, u"com.sun.star.chart2.LinearRegressionCurve"_ustr);
118 checkCommonTrendline(
119 xCurve,
120 aExpectedExtrapolateForward, aExpectedExtrapolateBackward,
121 /*aExpectedForceIntercept*/false, aExpectedInterceptValue,
122 /*aExpectedShowEquation*/true, /*aExpectedR2*/false, /*aExpectedMayHaveR2*/true);
125 void checkPolynomialTrendline(
126 Reference<chart2::XRegressionCurve> const & xCurve, const OUString& aExpectedName,
127 sal_Int32 aExpectedDegree,
128 double aExpectedExtrapolateForward, double aExpectedExtrapolateBackward,
129 double aExpectedInterceptValue)
131 Reference<XPropertySet> xProperties( xCurve , uno::UNO_QUERY );
132 CPPUNIT_ASSERT(xProperties.is());
134 checkNameAndType(xProperties, aExpectedName, u"com.sun.star.chart2.PolynomialRegressionCurve"_ustr);
136 sal_Int32 aDegree = 2;
137 CPPUNIT_ASSERT(xProperties->getPropertyValue(u"PolynomialDegree"_ustr) >>= aDegree);
138 CPPUNIT_ASSERT_EQUAL(aExpectedDegree, aDegree);
140 checkCommonTrendline(
141 xCurve,
142 aExpectedExtrapolateForward, aExpectedExtrapolateBackward,
143 /*aExpectedForceIntercept*/true, aExpectedInterceptValue,
144 /*aExpectedShowEquation*/true, /*aExpectedR2*/true, /*aExpectedMayHaveR2*/true);
147 void checkMovingAverageTrendline(
148 Reference<chart2::XRegressionCurve> const & xCurve, const OUString& aExpectedName, sal_Int32 aExpectedPeriod)
150 Reference<XPropertySet> xProperties( xCurve , uno::UNO_QUERY );
151 CPPUNIT_ASSERT(xProperties.is());
153 checkNameAndType(xProperties, aExpectedName, u"com.sun.star.chart2.MovingAverageRegressionCurve"_ustr);
155 sal_Int32 aPeriod = 2;
156 CPPUNIT_ASSERT(xProperties->getPropertyValue(u"MovingAveragePeriod"_ustr) >>= aPeriod);
157 CPPUNIT_ASSERT_EQUAL(aExpectedPeriod, aPeriod);
159 checkCommonTrendline(
160 xCurve,
161 /*aExpectedExtrapolateForward*/0.0, /*aExpectedExtrapolateBackward*/0.0,
162 /*aExpectedForceIntercept*/false, /*aExpectedInterceptValue*/0.0,
163 /*aExpectedShowEquation*/false, /*aExpectedR2*/false, /*aExpectedMayHaveR2*/false);
166 void checkTrendlinesInChart(uno::Reference< chart2::XDataSeries > const & xDataSeries )
168 Reference< chart2::XRegressionCurveContainer > xRegressionCurveContainer( xDataSeries, UNO_QUERY );
169 CPPUNIT_ASSERT( xRegressionCurveContainer.is() );
171 Sequence< Reference< chart2::XRegressionCurve > > xRegressionCurveSequence = xRegressionCurveContainer->getRegressionCurves();
172 CPPUNIT_ASSERT_EQUAL(sal_Int32(3), xRegressionCurveSequence.getLength());
174 Reference<chart2::XRegressionCurve> xCurve;
176 xCurve = xRegressionCurveSequence[0];
177 CPPUNIT_ASSERT(xCurve.is());
178 checkPolynomialTrendline(xCurve, u"col2_poly"_ustr, 3, 0.1, -0.1, -1.0);
180 xCurve = xRegressionCurveSequence[1];
181 CPPUNIT_ASSERT(xCurve.is());
182 checkLinearTrendline(xCurve, u"col2_linear"_ustr, -0.5, -0.5, 0.0);
184 xCurve = xRegressionCurveSequence[2];
185 CPPUNIT_ASSERT(xCurve.is());
186 checkMovingAverageTrendline(xCurve, u"col2_moving_avg"_ustr, 3);
191 // improve the test
192 CPPUNIT_TEST_FIXTURE(Chart2ExportTest, testErrorBarXLSX)
194 loadFromFile(u"ods/error_bar.ods");
196 // make sure the ODS import was successful
197 uno::Reference< chart2::XChartDocument > xChartDoc = getChartDocFromSheet( 0 );
198 CPPUNIT_ASSERT(xChartDoc.is());
200 Reference< chart2::XDataSeries > xDataSeries = getDataSeriesFromDoc( xChartDoc, 0 );
201 CPPUNIT_ASSERT( xDataSeries.is() );
203 Reference< beans::XPropertySet > xPropSet( xDataSeries, UNO_QUERY_THROW );
205 // test that y error bars are there
206 Reference< beans::XPropertySet > xErrorBarYProps;
207 xPropSet->getPropertyValue(CHART_UNONAME_ERRORBAR_Y) >>= xErrorBarYProps;
208 testErrorBar(xErrorBarYProps);
211 saveAndReload(u"Calc Office Open XML"_ustr);
213 uno::Reference< chart2::XChartDocument > xChartDoc = getChartDocFromSheet( 0 );
214 CPPUNIT_ASSERT(xChartDoc.is());
216 Reference< chart2::XDataSeries > xDataSeries = getDataSeriesFromDoc( xChartDoc, 0 );
217 CPPUNIT_ASSERT( xDataSeries.is() );
219 Reference< beans::XPropertySet > xPropSet( xDataSeries, UNO_QUERY_THROW );
221 // test that y error bars are there
222 Reference< beans::XPropertySet > xErrorBarYProps;
223 xPropSet->getPropertyValue(CHART_UNONAME_ERRORBAR_Y) >>= xErrorBarYProps;
224 testErrorBar(xErrorBarYProps);
228 CPPUNIT_TEST_FIXTURE(Chart2ExportTest, testErrorBarPropXLSX)
230 loadFromFile(u"xlsx/testErrorBarProp.xlsx");
231 save(u"Calc Office Open XML"_ustr);
232 xmlDocUniquePtr pXmlDoc = parseExport(u"xl/charts/chart1.xml"_ustr);
233 CPPUNIT_ASSERT(pXmlDoc);
235 // test y error bars property
236 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:scatterChart/c:ser/c:errBars[1]/c:errDir", "val", u"y");
237 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:scatterChart/c:ser/c:errBars[1]/c:spPr/a:ln", "w", u"12600");
238 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:scatterChart/c:ser/c:errBars[1]/c:spPr/a:ln/a:solidFill/a:srgbClr", "val", u"ff0000");
240 // test x error bars property
241 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:scatterChart/c:ser/c:errBars[2]/c:errDir", "val", u"x");
242 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:scatterChart/c:ser/c:errBars[2]/c:spPr/a:ln", "w", u"9360");
243 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:scatterChart/c:ser/c:errBars[2]/c:spPr/a:ln/a:solidFill/a:srgbClr", "val", u"595959");
246 // This method tests the preservation of properties for trendlines / regression curves
247 // in an export -> import cycle using different file formats - ODS, XLS and XLSX.
248 CPPUNIT_TEST_FIXTURE(Chart2ExportTest, testTrendline)
250 // Validation fails with
251 // Error: tag name "chart:symbol-image" is not allowed. Possible tag names are: <label-separator>
252 skipValidation();
253 loadFromFile(u"ods/trendline.ods");
254 checkTrendlinesInChart(getDataSeriesFromDoc( getChartDocFromSheet( 0), 0 ));
255 saveAndReload(u"calc8"_ustr);
256 checkTrendlinesInChart(getDataSeriesFromDoc( getChartDocFromSheet( 0), 0 ));
259 CPPUNIT_TEST_FIXTURE(Chart2ExportTest, testTrendlineOOXML)
261 loadFromFile(u"ods/trendline.ods");
262 checkTrendlinesInChart(getDataSeriesFromDoc( getChartDocFromSheet( 0), 0 ));
263 saveAndReload(u"Calc Office Open XML"_ustr);
264 checkTrendlinesInChart(getDataSeriesFromDoc( getChartDocFromSheet( 0), 0 ));
267 CPPUNIT_TEST_FIXTURE(Chart2ExportTest, testTrendlineXLS)
269 loadFromFile(u"ods/trendline.ods");
270 checkTrendlinesInChart(getDataSeriesFromDoc( getChartDocFromSheet( 0), 0 ));
271 saveAndReload(u"MS Excel 97"_ustr);
272 checkTrendlinesInChart(getDataSeriesFromDoc( getChartDocFromSheet( 0), 0 ));
275 CPPUNIT_TEST_FIXTURE(Chart2ExportTest, testMovingAverage)
277 loadFromFile(u"ods/moving-type.ods");
278 saveAndReload(u"calc8"_ustr);
280 uno::Reference< chart2::XChartDocument > xChartDoc = getChartDocFromSheet( 0);
281 CPPUNIT_ASSERT(xChartDoc.is());
283 Reference< chart2::XDataSeries > xDataSeries = getDataSeriesFromDoc( xChartDoc, 0 );
284 CPPUNIT_ASSERT( xDataSeries.is() );
286 Reference< chart2::XRegressionCurveContainer > xRegressionCurveContainer( xDataSeries, UNO_QUERY );
287 CPPUNIT_ASSERT( xRegressionCurveContainer.is() );
289 Sequence< Reference< chart2::XRegressionCurve > > xRegressionCurveSequence = xRegressionCurveContainer->getRegressionCurves();
290 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xRegressionCurveSequence.getLength());
292 Reference<chart2::XRegressionCurve> xCurve = xRegressionCurveSequence[0];
293 CPPUNIT_ASSERT(xCurve.is());
295 Reference<XPropertySet> xProperties( xCurve , uno::UNO_QUERY );
296 CPPUNIT_ASSERT(xProperties.is());
298 sal_Int32 nMovingAverageType = 0;
299 xProperties->getPropertyValue(u"MovingAverageType"_ustr) >>= nMovingAverageType;
300 CPPUNIT_ASSERT_EQUAL(chart2::MovingAverageType::Central, nMovingAverageType);
303 CPPUNIT_TEST_FIXTURE(Chart2ExportTest, testStockChart)
305 /* For attached file Stock_Chart.docx, in chart1.xml,
306 * <c:stockChart>, there are four types of series as
307 * Open,Low,High and Close.
308 * For Open series, in <c:idx val="0" />
309 * an attribute val of index should start from 1 and not from 0.
310 * Which was problem area.
312 loadFromFile(u"docx/testStockChart.docx");
314 save(u"Office Open XML Text"_ustr);
315 xmlDocUniquePtr pXmlDoc = parseExport(u"word/charts/chart1.xml"_ustr);
316 CPPUNIT_ASSERT(pXmlDoc);
318 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:stockChart/c:ser[1]/c:idx", "val", u"1");
319 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:stockChart/c:ser[1]/c:order", "val", u"1");
320 assertXPathContent(
321 pXmlDoc,
322 "/c:chartSpace/c:chart/c:plotArea/c:stockChart/c:ser[1]/c:tx/c:strRef/c:strCache/c:pt/c:v",
323 u"Open");
326 CPPUNIT_TEST_FIXTURE(Chart2ExportTest, testBarChart)
328 loadFromFile(u"docx/testBarChart.docx");
329 save(u"Office Open XML Text"_ustr);
330 xmlDocUniquePtr pXmlDoc = parseExport(u"word/charts/chart1.xml"_ustr);
331 CPPUNIT_ASSERT(pXmlDoc);
333 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:barChart/c:barDir", "val", u"col");
336 CPPUNIT_TEST_FIXTURE(Chart2ExportTest, testCrosses)
338 // test crosses val="autoZero" with DOCX
340 loadFromFile(u"docx/Bar_horizontal_cone.docx");
341 save(u"Office Open XML Text"_ustr);
342 xmlDocUniquePtr pXmlDoc = parseExport(u"word/charts/chart1.xml"_ustr);
344 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:catAx/c:crosses", "val", u"autoZero");
346 // tdf#142351: test crossesAt val="-50" with XLSX
348 loadFromFile(u"xlsx/tdf142351.xlsx");
349 save(u"Calc Office Open XML"_ustr);
350 xmlDocUniquePtr pXmlDoc = parseExport(u"xl/charts/chart1.xml"_ustr);
351 CPPUNIT_ASSERT(pXmlDoc);
353 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:catAx/c:crossesAt", "val", u"-50");
357 CPPUNIT_TEST_FIXTURE(Chart2ExportTest, testScatterChartTextXValues)
359 loadFromFile(u"docx/scatter-chart-text-x-values.docx");
361 Reference<chart2::XChartDocument> xChartDoc(getChartDocFromWriter(0), uno::UNO_QUERY);
362 CPPUNIT_ASSERT(xChartDoc.is());
364 Reference<chart2::XChartType> xCT = getChartTypeFromDoc(xChartDoc, 0);
365 CPPUNIT_ASSERT(xCT.is());
367 // Make sure we have exactly 3 data series.
368 std::vector<uno::Sequence<uno::Any> > aLabels = getDataSeriesLabelsFromChartType(xCT);
369 CPPUNIT_ASSERT_EQUAL(size_t(3), aLabels.size());
370 CPPUNIT_ASSERT_EQUAL(u"Series 1"_ustr, aLabels[0][0].get<OUString>());
371 CPPUNIT_ASSERT_EQUAL(u"Series 2"_ustr, aLabels[1][0].get<OUString>());
372 CPPUNIT_ASSERT_EQUAL(u"Series 3"_ustr, aLabels[2][0].get<OUString>());
374 std::vector<std::vector<double> > aYValues = getDataSeriesYValuesFromChartType(xCT);
375 CPPUNIT_ASSERT_EQUAL(size_t(3), aYValues.size());
377 // Check the Y values of "Series 1".
378 CPPUNIT_ASSERT_EQUAL(size_t(4), aYValues[0].size());
379 CPPUNIT_ASSERT_EQUAL(4.3, aYValues[0][0]);
380 CPPUNIT_ASSERT_EQUAL(2.5, aYValues[0][1]);
381 CPPUNIT_ASSERT_EQUAL(3.5, aYValues[0][2]);
382 CPPUNIT_ASSERT_EQUAL(4.5, aYValues[0][3]);
384 // And "Series 2".
385 CPPUNIT_ASSERT_EQUAL(size_t(4), aYValues[1].size());
386 CPPUNIT_ASSERT_EQUAL(2.4, aYValues[1][0]);
387 CPPUNIT_ASSERT_EQUAL(4.4, aYValues[1][1]);
388 CPPUNIT_ASSERT_EQUAL(1.8, aYValues[1][2]);
389 CPPUNIT_ASSERT_EQUAL(2.8, aYValues[1][3]);
391 // And "Series 3".
392 CPPUNIT_ASSERT_EQUAL(size_t(4), aYValues[2].size());
393 CPPUNIT_ASSERT_EQUAL(2.0, aYValues[2][0]);
394 CPPUNIT_ASSERT_EQUAL(2.0, aYValues[2][1]);
395 CPPUNIT_ASSERT_EQUAL(3.0, aYValues[2][2]);
396 CPPUNIT_ASSERT_EQUAL(5.0, aYValues[2][3]);
398 // Test the export.
399 save(u"Office Open XML Text"_ustr);
400 xmlDocUniquePtr pXmlDoc = parseExport(u"word/charts/chart1.xml"_ustr);
401 CPPUNIT_ASSERT(pXmlDoc);
403 assertXPathContent(pXmlDoc, "//c:scatterChart/c:ser[1]/c:xVal[1]/c:numRef[1]/c:numCache[1]/c:pt[1]/c:v[1]", u"1");
406 CPPUNIT_TEST_FIXTURE(Chart2ExportTest, testScatterXAxisValues)
408 loadFromFile(u"odt/tdf114657.odt");
410 save(u"Office Open XML Text"_ustr);
411 xmlDocUniquePtr pXmlDoc = parseExport(u"word/charts/chart1.xml"_ustr);
412 CPPUNIT_ASSERT(pXmlDoc);
414 assertXPath(pXmlDoc, "//c:scatterChart/c:ser/c:xVal/c:numRef/c:numCache/c:ptCount", "val", u"5");
415 assertXPathContent(pXmlDoc, "//c:scatterChart/c:ser/c:xVal/c:numRef/c:numCache/c:pt[1]/c:v", u"15");
416 assertXPathContent(pXmlDoc, "//c:scatterChart/c:ser/c:xVal/c:numRef/c:numCache/c:pt[2]/c:v", u"11");
417 assertXPathContent(pXmlDoc, "//c:scatterChart/c:ser/c:xVal/c:numRef/c:numCache/c:pt[3]/c:v", u"20");
418 assertXPathContent(pXmlDoc, "//c:scatterChart/c:ser/c:xVal/c:numRef/c:numCache/c:pt[4]/c:v", u"16");
421 CPPUNIT_TEST_FIXTURE(Chart2ExportTest, testScatterXAxisCategories)
423 loadFromFile(u"odt/tdf131143.odt");
425 save(u"Office Open XML Text"_ustr);
426 xmlDocUniquePtr pXmlDoc = parseExport(u"word/charts/chart1.xml"_ustr);
427 CPPUNIT_ASSERT(pXmlDoc);
428 assertXPath(pXmlDoc, "//c:scatterChart/c:ser[1]/c:xVal/c:strRef/c:strCache/c:ptCount", "val", u"4");
429 assertXPathContent(pXmlDoc, "//c:scatterChart/c:ser[1]/c:xVal/c:strRef/c:strCache/c:pt[1]/c:v", u"Row 1");
430 assertXPathContent(pXmlDoc, "//c:scatterChart/c:ser[1]/c:xVal/c:strRef/c:strCache/c:pt[2]/c:v", u"Row 2");
433 CPPUNIT_TEST_FIXTURE(Chart2ExportTest, testChartDataTable)
435 loadFromFile(u"docx/testChartDataTable.docx");
437 save(u"Office Open XML Text"_ustr);
438 xmlDocUniquePtr pXmlDoc = parseExport(u"word/charts/chart1.xml"_ustr);
439 CPPUNIT_ASSERT(pXmlDoc);
440 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:dTable/c:showHorzBorder", "val", u"1");
441 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:dTable/c:showVertBorder", "val", u"1");
442 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:dTable/c:showOutline", "val", u"1");
445 CPPUNIT_TEST_FIXTURE(Chart2ExportTest, testChartExternalData)
447 loadFromFile(u"docx/testMultipleChart.docx");
449 save(u"Office Open XML Text"_ustr);
450 xmlDocUniquePtr pXmlDoc = parseExport(u"word/charts/chart1.xml"_ustr);
451 CPPUNIT_ASSERT(pXmlDoc);
452 assertXPath(pXmlDoc, "/c:chartSpace/c:externalData");
455 CPPUNIT_TEST_FIXTURE(Chart2ExportTest, testEmbeddingsGrabBag)
457 // The problem was that .xlsx files were missing from docx file from embeddings folder
458 // after saving file.
459 // This test case tests whether embeddings files grabbagged properly in correct object.
461 loadFromFile(u"docx/testMultiplechartembeddings.docx" );
462 uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY);
463 uno::Reference<beans::XPropertySet> xTextDocumentPropertySet(xTextDocument, uno::UNO_QUERY);
464 uno::Sequence<beans::PropertyValue> aGrabBag(0);
465 xTextDocumentPropertySet->getPropertyValue(u"InteropGrabBag"_ustr) >>= aGrabBag;
466 CPPUNIT_ASSERT(aGrabBag.hasElements()); // Grab Bag not empty
467 bool bEmbeddings = false;
468 const char* const testEmbeddedFileNames[] {"word/embeddings/Microsoft_Excel_Worksheet3.xlsx",
469 "word/embeddings/Microsoft_Excel_Worksheet2.xlsx",
470 "word/embeddings/Microsoft_Excel_Worksheet1.xlsx"};
471 for (beans::PropertyValue const& prop : aGrabBag)
473 if (prop.Name == "OOXEmbeddings")
475 bEmbeddings = true;
476 uno::Sequence<beans::PropertyValue> aEmbeddingsList(0);
477 uno::Reference<io::XInputStream> aEmbeddingXlsxStream;
478 OUString aEmbeddedfileName;
479 CPPUNIT_ASSERT(prop.Value >>= aEmbeddingsList); // PropertyValue of proper type
480 sal_Int32 length = aEmbeddingsList.getLength();
481 CPPUNIT_ASSERT_EQUAL(sal_Int32(3), length);
482 for(int j = 0; j < length; ++j)
484 aEmbeddingsList[j].Value >>= aEmbeddingXlsxStream;
485 aEmbeddedfileName = aEmbeddingsList[j].Name;
486 CPPUNIT_ASSERT(aEmbeddingXlsxStream); // Reference not empty
487 CPPUNIT_ASSERT_EQUAL(OUString::createFromAscii(testEmbeddedFileNames[j]),aEmbeddedfileName);
491 CPPUNIT_ASSERT(bEmbeddings); // Grab Bag has all the expected elements
494 CPPUNIT_TEST_FIXTURE(Chart2ExportTest, testAreaChartLoad)
496 loadFromFile(u"docx/testAreaChartLoad.docx");
498 // FIXME: validation error in OOXML export: Errors: 1
499 skipValidation();
501 save(u"Office Open XML Text"_ustr);
502 xmlDocUniquePtr pXmlDoc = parseExport(u"word/charts/chart1.xml"_ustr);
503 CPPUNIT_ASSERT(pXmlDoc);
504 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:areaChart/c:ser/c:dLbls/c:showVal", "val", u"1");
505 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:areaChart/c:ser/c:dLbls/c:dLbl", 0);
508 CPPUNIT_TEST_FIXTURE(Chart2ExportTest, testUpDownBars)
510 loadFromFile(u"docx/UpDownBars.docx");
511 save(u"Office Open XML Text"_ustr);
512 xmlDocUniquePtr pXmlDoc = parseExport(u"word/charts/chart1.xml"_ustr);
513 CPPUNIT_ASSERT(pXmlDoc);
514 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:lineChart/c:upDownBars", 0);
517 CPPUNIT_TEST_FIXTURE(Chart2ExportTest, testDoughnutChart)
519 loadFromFile(u"docx/doughnutChart.docx");
520 save(u"Office Open XML Text"_ustr);
521 xmlDocUniquePtr pXmlDoc = parseExport(u"word/charts/chart1.xml"_ustr);
522 CPPUNIT_ASSERT(pXmlDoc);
524 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:doughnutChart");
527 CPPUNIT_TEST_FIXTURE(Chart2ExportTest, testPieOfPieChart)
529 loadFromFile(u"xlsx/pieOfPieChart.xlsx");
530 save(u"Calc Office Open XML"_ustr);
531 xmlDocUniquePtr pXmlDoc = parseExport(u"xl/charts/chart1.xml"_ustr);
532 CPPUNIT_ASSERT(pXmlDoc);
534 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:ofPieChart");
535 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:ofPieChart/c:ofPieType[1]", "val", u"pie");
538 CPPUNIT_TEST_FIXTURE(Chart2ExportTest, testBarOfPieChart)
540 loadFromFile(u"xlsx/barOfPieChart.xlsx");
541 save(u"Calc Office Open XML"_ustr);
542 xmlDocUniquePtr pXmlDoc = parseExport(u"xl/charts/chart1.xml"_ustr);
543 CPPUNIT_ASSERT(pXmlDoc);
545 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:ofPieChart");
546 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:ofPieChart/c:ofPieType[1]", "val", u"bar");
549 CPPUNIT_TEST_FIXTURE(Chart2ExportTest, testPieOfPieSplitPos)
551 loadFromFile(u"xlsx/pieOfPieChart2.xlsx");
552 save(u"Calc Office Open XML"_ustr);
553 xmlDocUniquePtr pXmlDoc = parseExport(u"xl/charts/chart1.xml"_ustr);
554 CPPUNIT_ASSERT(pXmlDoc);
556 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:ofPieChart");
557 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:ofPieChart/c:splitPos[1]", "val", u"4");
560 CPPUNIT_TEST_FIXTURE(Chart2ExportTest, testBarOfPieSplitPos)
562 loadFromFile(u"xlsx/barOfPieChart2.xlsx");
563 save(u"Calc Office Open XML"_ustr);
564 xmlDocUniquePtr pXmlDoc = parseExport(u"xl/charts/chart1.xml"_ustr);
565 CPPUNIT_ASSERT(pXmlDoc);
567 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:ofPieChart");
568 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:ofPieChart/c:splitPos[1]", "val", u"5");
571 CPPUNIT_TEST_FIXTURE(Chart2ExportTest, testDisplayUnits)
573 loadFromFile(u"docx/DisplayUnits.docx");
574 save(u"Office Open XML Text"_ustr);
575 xmlDocUniquePtr pXmlDoc = parseExport(u"word/charts/chart1.xml"_ustr);
576 CPPUNIT_ASSERT(pXmlDoc);
578 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:valAx/c:dispUnits/c:builtInUnit", "val", u"billions");
581 CPPUNIT_TEST_FIXTURE(Chart2ExportTest, testFdo74115WallGradientFill)
583 loadFromFile(u"docx/fdo74115_WallGradientFill.docx");
584 save(u"Office Open XML Text"_ustr);
585 xmlDocUniquePtr pXmlDoc = parseExport(u"word/charts/chart1.xml"_ustr);
586 CPPUNIT_ASSERT(pXmlDoc);
588 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:spPr/a:gradFill");
591 CPPUNIT_TEST_FIXTURE(Chart2ExportTest, testFdo74115WallBitmapFill)
593 loadFromFile(u"docx/fdo74115_WallBitmapFill.docx");
594 save(u"Office Open XML Text"_ustr);
595 xmlDocUniquePtr pXmlDoc = parseExport(u"word/charts/chart1.xml"_ustr);
596 CPPUNIT_ASSERT(pXmlDoc);
597 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:spPr/a:blipFill");
600 CPPUNIT_TEST_FIXTURE(Chart2ExportTest, testPieChartWallLineStyle)
602 loadFromFile(u"odt/testPieChartWallLineStyle.odt");
604 // FIXME: validation error in OOXML export: Errors: 9
605 skipValidation();
607 save(u"Office Open XML Text"_ustr);
608 xmlDocUniquePtr pXmlDoc = parseExport(u"word/charts/chart1.xml"_ustr);
609 CPPUNIT_ASSERT(pXmlDoc);
610 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:spPr/a:ln/a:noFill");
613 //The below test case tests the built in marker 'x' for Office 2010 in Line charts
615 CPPUNIT_TEST_FIXTURE(Chart2ExportTest, testFdo78290LineChartMarkerX)
617 loadFromFile(u"docx/fdo78290_Line_Chart_Marker_x.docx");
618 save(u"Office Open XML Text"_ustr);
619 xmlDocUniquePtr pXmlDoc = parseExport(u"word/charts/chart1.xml"_ustr);
620 CPPUNIT_ASSERT(pXmlDoc);
621 assertXPath(pXmlDoc, "/c:chartSpace[1]/c:chart[1]/c:plotArea[1]/c:lineChart[1]/c:ser[1]/c:marker[1]/c:symbol[1]","val",u"x");
622 assertXPath(pXmlDoc, "/c:chartSpace[1]/c:chart[1]/c:plotArea[1]/c:lineChart[1]/c:ser[1]/c:marker[1]/c:size[1]","val",u"7");
625 // We can also use the built in marker 'x' in scatter chart, hence writing the test case for the same.
627 CPPUNIT_TEST_FIXTURE(Chart2ExportTest, testFdo78290ScatterChartMarkerX)
629 loadFromFile(u"docx/fdo78290_Scatter_Chart_Marker_x.docx");
630 save(u"Office Open XML Text"_ustr);
631 xmlDocUniquePtr pXmlDoc = parseExport(u"word/charts/chart1.xml"_ustr);
632 CPPUNIT_ASSERT(pXmlDoc);
633 assertXPath(pXmlDoc, "/c:chartSpace[1]/c:chart[1]/c:plotArea[1]/c:scatterChart[1]/c:ser[1]/c:marker[1]/c:symbol[1]","val",u"x");
634 assertXPath(pXmlDoc, "/c:chartSpace[1]/c:chart[1]/c:plotArea[1]/c:scatterChart[1]/c:ser[1]/c:marker[1]/c:size[1]","val",u"7");
637 // Also in a combination of charts like a column chart and line chart, we can use the built in marker 'x'
638 // for the line chart too. hence put a test case for the combination chart also.
640 CPPUNIT_TEST_FIXTURE(Chart2ExportTest, testFdo78290CombinationChartMarkerX)
642 loadFromFile(u"docx/fdo78290_Combination_Chart_Marker_x.docx");
643 save(u"Office Open XML Text"_ustr);
644 xmlDocUniquePtr pXmlDoc = parseExport(u"word/charts/chart1.xml"_ustr);
645 CPPUNIT_ASSERT(pXmlDoc);
646 assertXPath(pXmlDoc, "/c:chartSpace[1]/c:chart[1]/c:plotArea[1]/c:lineChart[1]/c:ser[1]/c:marker[1]/c:symbol[1]","val",u"x");
647 assertXPath(pXmlDoc, "/c:chartSpace[1]/c:chart[1]/c:plotArea[1]/c:lineChart[1]/c:ser[1]/c:marker[1]/c:size[1]","val",u"7");
650 CPPUNIT_TEST_FIXTURE(Chart2ExportTest, testTdf126115IndividualMarker)
652 // Check individual marker properties.
653 loadFromFile(u"xlsx/tdf126115.xlsx");
654 save(u"Calc Office Open XML"_ustr);
655 xmlDocUniquePtr pXmlDoc = parseExport(u"xl/charts/chart1.xml"_ustr);
656 CPPUNIT_ASSERT(pXmlDoc);
657 // 1. series
658 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:scatterChart/c:ser[1]/c:dPt/c:marker/c:symbol", "val", u"square");
659 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:scatterChart/c:ser[1]/c:dPt/c:marker/c:size", "val", u"8");
660 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:scatterChart/c:ser[1]/c:dPt/c:marker/c:spPr/a:solidFill/a:srgbClr", "val", u"ff0000");
661 // 2. series
662 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:scatterChart/c:ser[2]/c:dPt/c:marker/c:symbol", "val", u"x");
663 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:scatterChart/c:ser[2]/c:dPt/c:marker/c:size", "val", u"15");
664 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:scatterChart/c:ser[2]/c:dPt/c:marker/c:spPr/a:solidFill/a:srgbClr", "val", u"7030a0");
667 CPPUNIT_TEST_FIXTURE(Chart2ExportTest, testAxisNumberFormatODS)
669 auto verify = [this]( const Reference<chart2::XChartDocument>& xChartDoc )
671 Reference<chart2::XAxis> xAxisX = getAxisFromDoc(xChartDoc, 0, 0, 0);
672 Reference<chart2::XTitled> xTitle(xAxisX, UNO_QUERY_THROW);
673 OUString aTitleText = getTitleString(xTitle);
674 CPPUNIT_ASSERT_EQUAL(u"Linked To Source"_ustr, aTitleText);
676 sal_Int32 nNumFmt = getNumberFormatFromAxis(xAxisX);
677 sal_Int16 nType = getNumberFormatType(xChartDoc, nNumFmt);
678 CPPUNIT_ASSERT_MESSAGE("X axis should be percentage format.", (nType & util::NumberFormat::PERCENT));
680 bool bNumFmtLinked = false;
681 Reference<beans::XPropertySet> xPS(xAxisX, uno::UNO_QUERY_THROW);
682 xPS->getPropertyValue(u"LinkNumberFormatToSource"_ustr) >>= bNumFmtLinked;
683 CPPUNIT_ASSERT_MESSAGE("X axis should have its number format linked to source.", bNumFmtLinked);
685 Reference<chart2::XAxis> xAxisY = getAxisFromDoc(xChartDoc, 0, 1, 0);
686 xTitle.set(xAxisY, UNO_QUERY_THROW);
687 aTitleText = getTitleString(xTitle);
688 CPPUNIT_ASSERT_EQUAL(u"Not Linked"_ustr, aTitleText);
690 nNumFmt = getNumberFormatFromAxis(xAxisY);
691 nType = getNumberFormatType(xChartDoc, nNumFmt);
692 CPPUNIT_ASSERT_MESSAGE("Y axis should be a normal number format.", (nType & util::NumberFormat::NUMBER));
694 bNumFmtLinked = true;
695 xPS.set(xAxisY, uno::UNO_QUERY_THROW);
696 xPS->getPropertyValue(u"LinkNumberFormatToSource"_ustr) >>= bNumFmtLinked;
697 CPPUNIT_ASSERT_MESSAGE("Y axis should not have its number format linked to source.", !bNumFmtLinked);
700 loadFromFile(u"ods/axis-numformats-linked.ods");
702 Reference<chart2::XChartDocument> xChartDoc = getChartDocFromSheet(0);
703 verify(xChartDoc);
705 // Reload the document and make sure everything remains intact.
706 saveAndReload(u"calc8"_ustr);
707 xChartDoc = getChartDocFromSheet(0);
708 verify(xChartDoc);
711 CPPUNIT_TEST_FIXTURE(Chart2ExportTest, testAxisNumberFormatXLS)
713 auto verify = [this]( const Reference<chart2::XChartDocument>& xChartDoc, bool bNumFmtLinkedActual, sal_Int16 nNumFmtTypeFlag )
715 Reference<chart2::XAxis> xAxisY = getAxisFromDoc( xChartDoc, 0, 1, 0 );
716 bool bNumFmtLinked = false;
717 Reference<beans::XPropertySet> xPS( xAxisY, uno::UNO_QUERY_THROW );
718 xPS->getPropertyValue( u"LinkNumberFormatToSource"_ustr ) >>= bNumFmtLinked;
720 if ( bNumFmtLinkedActual )
721 CPPUNIT_ASSERT_MESSAGE( "Y axis should have its number format linked to source.", bNumFmtLinked );
722 else
724 CPPUNIT_ASSERT_MESSAGE( "Y axis should not have its number format linked to source.", !bNumFmtLinked );
726 sal_Int32 nNumFmt = getNumberFormatFromAxis( xAxisY );
727 sal_Int16 nType = getNumberFormatType( xChartDoc, nNumFmt );
728 if ( nNumFmtTypeFlag == util::NumberFormat::PERCENT )
729 CPPUNIT_ASSERT_MESSAGE( "Y axis should be percentage format.", ( nType & util::NumberFormat::PERCENT ) );
730 else
731 CPPUNIT_ASSERT_MESSAGE( "Y axis should be number format.", ( nType & util::NumberFormat::NUMBER ) );
735 loadFromFile(u"xls/axis_sourceformatting.xls" );
737 Reference<chart2::XChartDocument> xChartDoc = getChartDocFromSheet( 0 );
738 verify( xChartDoc, true, util::NumberFormat::PERCENT );
740 Reference<chart2::XAxis> xAxisY = getAxisFromDoc( xChartDoc, 0, 1, 0 );
741 Reference<beans::XPropertySet> xPS( xAxisY, uno::UNO_QUERY_THROW );
742 Any aAny( false );
743 xPS->setPropertyValue( u"LinkNumberFormatToSource"_ustr, aAny );
745 Reference<util::XNumberFormatsSupplier> xNFS( xChartDoc, uno::UNO_QUERY_THROW );
746 Reference<util::XNumberFormats> xNumberFormats = xNFS->getNumberFormats();
747 CPPUNIT_ASSERT( xNumberFormats.is() );
748 lang::Locale aLocale{ u"en"_ustr, u"US"_ustr, u""_ustr };
749 Sequence<sal_Int32> aNumFmts = xNumberFormats->queryKeys( util::NumberFormat::NUMBER, aLocale, false );
750 CPPUNIT_ASSERT( aNumFmts.hasElements() );
751 aAny <<= aNumFmts[0];
752 xPS->setPropertyValue( CHART_UNONAME_NUMFMT, aAny );
754 // Write the document(xls) with changes made close it, load it and check if changes are intact
755 saveAndReload( u"MS Excel 97"_ustr );
756 xChartDoc = getChartDocFromSheet( 0 );
757 verify( xChartDoc, false, util::NumberFormat::NUMBER );
760 CPPUNIT_TEST_FIXTURE(Chart2ExportTest, testDataLabelBordersDOCX)
762 struct Check
764 sal_Int32 mnIndex;
765 css::drawing::LineStyle meStyle;
766 Color mnColor;
769 auto verify = [this]( const Reference<chart2::XChartDocument>& xChartDoc, sal_Int32 nShape )
771 CPPUNIT_ASSERT(xChartDoc.is());
773 Reference<chart2::XDataSeries> xDataSeries = getDataSeriesFromDoc(xChartDoc, 0);
774 CPPUNIT_ASSERT(xDataSeries.is());
776 // Check to make sure that data points 0 and 2 have local properties.
777 Reference<beans::XPropertySet> xPropSet(xDataSeries, uno::UNO_QUERY);
778 CPPUNIT_ASSERT(xPropSet.is());
780 Sequence<sal_Int32> aIndices;
781 xPropSet->getPropertyValue(u"AttributedDataPoints"_ustr) >>= aIndices;
783 CPPUNIT_ASSERT_EQUAL_MESSAGE("There should be 2 data points with local properties.", sal_Int32(2), aIndices.getLength());
784 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), aIndices[0]);
785 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), aIndices[1]);
788 static const Check aDataPoints[] =
790 { 0, css::drawing::LineStyle_SOLID, 0x00FFFF00 }, // solid yellow
791 { 2, css::drawing::LineStyle_SOLID, 0x00FF0000 } // solid red
794 for (size_t i = 0; i < std::size(aDataPoints); ++i)
796 xPropSet = xDataSeries->getDataPointByIndex(aDataPoints[i].mnIndex);
797 CPPUNIT_ASSERT(xPropSet.is());
799 css::drawing::LineStyle eLineStyle = css::drawing::LineStyle_NONE;
800 xPropSet->getPropertyValue(CHART_UNONAME_LABEL_BORDER_STYLE) >>= eLineStyle;
801 CPPUNIT_ASSERT_EQUAL(aDataPoints[i].meStyle, eLineStyle);
803 sal_Int32 nWidth = -1;
804 xPropSet->getPropertyValue(CHART_UNONAME_LABEL_BORDER_WIDTH) >>= nWidth;
805 CPPUNIT_ASSERT(nWidth > 0);
807 Color nColor;
808 xPropSet->getPropertyValue(CHART_UNONAME_LABEL_BORDER_COLOR) >>= nColor;
809 if (nShape == 0)
810 CPPUNIT_ASSERT_EQUAL_MESSAGE("Border color is wrong.", aDataPoints[i].mnColor, nColor);
811 else
812 CPPUNIT_ASSERT_EQUAL_MESSAGE("Border color should be green.", COL_LIGHTGREEN, nColor);
816 loadFromFile(u"docx/data-label-borders.docx");
818 Reference<chart2::XChartDocument> xChartDoc(getChartDocFromWriter(0), uno::UNO_QUERY);
820 // "Automatic" chart background fill in docx should be loaded as solid white.
821 Reference<beans::XPropertySet> xPropSet = xChartDoc->getPageBackground();
822 CPPUNIT_ASSERT(xPropSet.is());
823 drawing::FillStyle eStyle = xPropSet->getPropertyValue(u"FillStyle"_ustr).get<drawing::FillStyle>();
824 sal_Int32 nColor = xPropSet->getPropertyValue(u"FillColor"_ustr).get<sal_Int32>();
825 CPPUNIT_ASSERT_EQUAL_MESSAGE("'Automatic' chart background fill in docx should be loaded as solid fill.",
826 drawing::FillStyle_SOLID, eStyle);
827 CPPUNIT_ASSERT_EQUAL_MESSAGE("'Automatic' chart background fill in docx should be loaded as solid white.",
828 sal_Int32(0x00FFFFFF), sal_Int32(nColor & 0x00FFFFFF)); // highest 2 bytes are transparency which we ignore here.
830 // Chart 1 has 4 bars of which 1st and 3rd have labels with borders around them.
831 verify(xChartDoc, 0);
832 xChartDoc.set(getChartDocFromWriter(1), uno::UNO_QUERY);
834 // Chart 2 has all its data labels with identical borders.
835 verify(xChartDoc, 1);
837 // FIXME: validation error in OOXML export: Errors: 3
838 skipValidation();
840 saveAndReload(u"Office Open XML Text"_ustr);
842 xChartDoc.set(getChartDocFromWriter(0), uno::UNO_QUERY);
843 verify(xChartDoc , 0);
844 xChartDoc.set(getChartDocFromWriter(1), uno::UNO_QUERY);
845 verify(xChartDoc, 1);
848 CPPUNIT_TEST_FIXTURE(Chart2ExportTest, testDataLabel3DChartDOCX)
850 loadFromFile(u"docx/3d-bar-label.docx");
852 Reference<chart2::XChartDocument> xChartDoc(getChartDocFromWriter(0), uno::UNO_QUERY);
853 CPPUNIT_ASSERT(xChartDoc.is());
855 // FIXME: validation error in OOXML export: Errors: 1
856 skipValidation();
858 save(u"Office Open XML Text"_ustr);
859 xmlDocUniquePtr pXmlDoc = parseExport(u"word/charts/chart1.xml"_ustr);
860 CPPUNIT_ASSERT(pXmlDoc);
862 // We must not export label position attributes for 3D bar charts. The
863 // same rule also applies to several other 3D charts, apparently.
864 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:bar3DChart/c:ser/c:dLbls/c:dLblPos", 0);
865 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:bar3DChart/c:ser/c:dLbls/c:dLbl/c:dLblPos", 0);
868 CPPUNIT_TEST_FIXTURE(Chart2ExportTest, testDataLabelBarChartDOCX)
870 loadFromFile(u"docx/bar-chart-labels.docx");
872 Reference<chart2::XChartDocument> xChartDoc(getChartDocFromWriter(0), uno::UNO_QUERY);
873 CPPUNIT_ASSERT(xChartDoc.is());
875 save(u"Office Open XML Text"_ustr);
876 xmlDocUniquePtr pXmlDoc = parseExport(u"word/charts/chart1.xml"_ustr);
877 CPPUNIT_ASSERT(pXmlDoc);
879 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:barChart/c:ser[1]/c:dLbls/c:dLblPos", "val", u"ctr");
880 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:barChart/c:ser[2]/c:dLbls/c:dLblPos", "val", u"inEnd");
881 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:barChart/c:ser[3]/c:dLbls/c:dLblPos", "val", u"inBase");
884 CPPUNIT_TEST_FIXTURE(Chart2ExportTest, testDataLabelClusteredBarChartDOCX)
886 loadFromFile(u"docx/clustered-bar-chart-labels.docx");
888 Reference<chart2::XChartDocument> xChartDoc(getChartDocFromWriter(0), uno::UNO_QUERY);
889 CPPUNIT_ASSERT(xChartDoc.is());
891 // FIXME: validation error in OOXML export: Errors: 9
892 skipValidation();
894 save(u"Office Open XML Text"_ustr);
895 xmlDocUniquePtr pXmlDoc = parseExport(u"word/charts/chart1.xml"_ustr);
896 CPPUNIT_ASSERT(pXmlDoc);
898 // This was "t", should be one of the allowed values.
899 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:barChart/c:ser[1]/c:dLbls/c:dLbl[2]/c:dLblPos", "val", u"outEnd");
902 CPPUNIT_TEST_FIXTURE(Chart2ExportTest, testDataLabelRadarChartDOCX)
904 loadFromFile(u"docx/radar-chart-labels.docx");
906 Reference<chart2::XChartDocument> xChartDoc(getChartDocFromWriter(0), uno::UNO_QUERY);
907 CPPUNIT_ASSERT(xChartDoc.is());
909 save(u"Office Open XML Text"_ustr);
910 xmlDocUniquePtr pXmlDoc = parseExport(u"word/charts/chart1.xml"_ustr);
911 CPPUNIT_ASSERT(pXmlDoc);
913 // We must not export label position attributes for radar charts.
914 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:radarChart/c:ser/c:dLbls/c:dLblPos", 0);
915 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:radarChart/c:ser/c:dLbls/c:dLbl/c:dLblPos", 0);
918 CPPUNIT_TEST_FIXTURE(Chart2ExportTest, testDataLabelDoughnutChartDOCX)
920 loadFromFile(u"docx/doughnut-chart-labels.docx");
922 Reference<chart2::XChartDocument> xChartDoc(getChartDocFromWriter(0), uno::UNO_QUERY);
923 CPPUNIT_ASSERT(xChartDoc.is());
925 // FIXME: validation error in OOXML export: Errors: 1
926 skipValidation();
928 save(u"Office Open XML Text"_ustr);
929 xmlDocUniquePtr pXmlDoc = parseExport(u"word/charts/chart1.xml"_ustr);
930 CPPUNIT_ASSERT(pXmlDoc);
932 // We must not export label position attributes for doughnut charts.
933 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:doughnutChart/c:ser/c:dLbls/c:dLblPos", 0);
934 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:doughnutChart/c:ser/c:dLbls/c:dLbl/c:dLblPos", 0);
937 CPPUNIT_TEST_FIXTURE(Chart2ExportTest, testDataLabelAreaChartDOCX)
939 loadFromFile(u"docx/area-chart-labels.docx");
941 Reference<chart2::XChartDocument> xChartDoc(getChartDocFromWriter(0), uno::UNO_QUERY);
942 CPPUNIT_ASSERT(xChartDoc.is());
944 // FIXME: validation error in OOXML export: Errors: 1
945 skipValidation();
947 save(u"Office Open XML Text"_ustr);
948 xmlDocUniquePtr pXmlDoc = parseExport(u"word/charts/chart1.xml"_ustr);
949 CPPUNIT_ASSERT(pXmlDoc);
951 // We must not export label position attributes for area charts.
952 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:areaChart/c:ser/c:dLbls/c:dLblPos", 0);
953 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:areaChart/c:ser/c:dLbls/c:dLbl/c:dLblPos", 0);
956 CPPUNIT_TEST_FIXTURE(Chart2ExportTest, testDataLabelDefaultLineChartDOCX)
958 // This file was created by Word 2007, which doesn't provide default data
959 // label position (2010 does). Make sure its default data label position
960 // is RIGHT when exporting.
962 loadFromFile(u"docx/line-chart-label-default-placement.docx");
964 Reference<chart2::XChartDocument> xChartDoc(getChartDocFromWriter(0), uno::UNO_QUERY);
965 CPPUNIT_ASSERT(xChartDoc.is());
967 saveAndReload(u"Office Open XML Text"_ustr);
969 xChartDoc.set(getChartDocFromWriter(0), uno::UNO_QUERY);
970 Reference<chart2::XDataSeries> xDataSeries = getDataSeriesFromDoc(xChartDoc, 0);
971 Reference<beans::XPropertySet> xPropSet(xDataSeries, uno::UNO_QUERY);
972 CPPUNIT_ASSERT(xPropSet.is());
973 sal_Int32 nLabelPlacement = -1;
974 if (xPropSet->getPropertyValue(u"LabelPlacement"_ustr) >>= nLabelPlacement)
975 // This option may not be set. Check its value only when it's set.
976 CPPUNIT_ASSERT_EQUAL_MESSAGE("Line chart's default label placement should be 'right'.", chart::DataLabelPlacement::RIGHT, nLabelPlacement );
979 CPPUNIT_TEST_FIXTURE(Chart2ExportTest, testIndividualDataLabelProps)
981 loadFromFile(u"xlsx/tdf122915.xlsx");
983 // FIXME: validation error in OOXML export: Errors: 1
984 skipValidation();
986 save(u"Calc Office Open XML"_ustr);
987 xmlDocUniquePtr pXmlDoc = parseExport(u"xl/charts/chart1.xml"_ustr);
988 CPPUNIT_ASSERT(pXmlDoc);
989 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:scatterChart/c:ser[3]/c:dLbls/c:dLbl/c:txPr/a:p/a:pPr/a:defRPr", "b", u"1");
990 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:scatterChart/c:ser[3]/c:dLbls/c:dLbl/c:txPr/a:p/a:pPr/a:defRPr", "sz", u"1600");
991 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:scatterChart/c:ser[3]/c:dLbls/c:dLbl/c:txPr/a:p/a:pPr/a:defRPr/a:solidFill/a:srgbClr", "val", u"ff0000");
992 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:scatterChart/c:ser[3]/c:dLbls/c:dLbl/c:txPr/a:p/a:pPr/a:defRPr/a:latin", "typeface", u"Times New Roman");
995 CPPUNIT_TEST_FIXTURE(Chart2ExportTest, testBarChartRotation)
997 loadFromFile(u"docx/barChartRotation.docx");
998 save(u"Office Open XML Text"_ustr);
999 xmlDocUniquePtr pXmlDoc = parseExport(u"word/charts/chart1.xml"_ustr);
1000 CPPUNIT_ASSERT(pXmlDoc);
1002 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:view3D/c:rotX", "val", u"30");
1003 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:view3D/c:rotY", "val", u"50");
1006 CPPUNIT_TEST_FIXTURE(Chart2ExportTest, testShapeFollowedByChart)
1008 /* If there is a scenario where a chart is followed by a shape
1009 which is being exported as an alternate content then, the
1010 docPr Id is being repeated, ECMA 20.4.2.5 says that the
1011 docPr Id should be unique, ensuring the same here.
1013 loadFromFile(u"docx/FDO74430.docx");
1015 // FIXME: validation error in OOXML export: Errors: 5
1016 skipValidation();
1018 save(u"Office Open XML Text"_ustr );
1019 xmlDocUniquePtr pXmlDoc = parseExport(u"word/document.xml"_ustr);
1020 CPPUNIT_ASSERT(pXmlDoc);
1022 OUString aValueOfFirstDocPR = getXPath(pXmlDoc, "/w:document/w:body/w:p[3]/w:r[1]/w:drawing[1]/wp:inline[1]/wp:docPr[1]", "id");
1023 OUString aValueOfSecondDocPR = getXPath(pXmlDoc, "/w:document/w:body/w:p[3]/w:r[1]/mc:AlternateContent[1]/mc:Choice[1]/w:drawing[1]/wp:anchor[1]/wp:docPr[1]", "id");
1025 CPPUNIT_ASSERT( aValueOfFirstDocPR != aValueOfSecondDocPR );
1028 CPPUNIT_TEST_FIXTURE(Chart2ExportTest, testPieChartDataLabels)
1030 loadFromFile(u"docx/PieChartDataLabels.docx");
1032 // FIXME: validation error in OOXML export: Errors: 19
1033 skipValidation();
1035 save(u"Office Open XML Text"_ustr);
1036 xmlDocUniquePtr pXmlDoc = parseExport(u"word/charts/chart1.xml"_ustr);
1037 CPPUNIT_ASSERT(pXmlDoc);
1038 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:pie3DChart/c:ser[1]/c:dLbls/c:dLbl[1]/c:dLblPos", "val", u"outEnd");
1041 CPPUNIT_TEST_FIXTURE(Chart2ExportTest, testSeriesIdxOrder)
1043 loadFromFile(u"docx/testSeriesIdxOrder.docx");
1044 save(u"Office Open XML Text"_ustr);
1045 xmlDocUniquePtr pXmlDoc = parseExport(u"word/charts/chart1.xml"_ustr);
1046 CPPUNIT_ASSERT(pXmlDoc);
1047 assertXPath(pXmlDoc, "/c:chartSpace[1]/c:chart[1]/c:plotArea[1]/c:lineChart[1]/c:ser[1]/c:idx[1]", "val", u"1");
1048 assertXPath(pXmlDoc, "/c:chartSpace[1]/c:chart[1]/c:plotArea[1]/c:lineChart[1]/c:ser[1]/c:order[1]", "val", u"1");
1051 CPPUNIT_TEST_FIXTURE(Chart2ExportTest, testScatterPlotLabels)
1053 loadFromFile(u"odt/scatter-plot-labels.odt");
1054 Reference<chart2::XChartDocument> xChartDoc(getChartDocFromWriter(0), uno::UNO_QUERY);
1055 CPPUNIT_ASSERT(xChartDoc.is());
1057 Reference<chart2::XChartType> xCT = getChartTypeFromDoc(xChartDoc, 0);
1058 CPPUNIT_ASSERT(xCT.is());
1060 // Make sure the original chart has 'a', 'b', 'c' as its data labels.
1061 std::vector<uno::Sequence<uno::Any> > aLabels = getDataSeriesLabelsFromChartType(xCT);
1062 CPPUNIT_ASSERT_EQUAL(size_t(3), aLabels.size());
1063 CPPUNIT_ASSERT_EQUAL(u"a"_ustr, aLabels[0][0].get<OUString>());
1064 CPPUNIT_ASSERT_EQUAL(u"b"_ustr, aLabels[1][0].get<OUString>());
1065 CPPUNIT_ASSERT_EQUAL(u"c"_ustr, aLabels[2][0].get<OUString>());
1067 // Reload the doc and check again. The labels should not change.
1068 saveAndReload(u"writer8"_ustr);
1070 xChartDoc.set(getChartDocFromWriter(0), uno::UNO_QUERY);
1071 CPPUNIT_ASSERT(xChartDoc.is());
1073 xCT = getChartTypeFromDoc(xChartDoc, 0);
1074 CPPUNIT_ASSERT(xCT.is());
1076 aLabels = getDataSeriesLabelsFromChartType(xCT);
1077 CPPUNIT_ASSERT_EQUAL(size_t(3), aLabels.size());
1078 CPPUNIT_ASSERT_EQUAL(u"a"_ustr, aLabels[0][0].get<OUString>());
1079 CPPUNIT_ASSERT_EQUAL(u"b"_ustr, aLabels[1][0].get<OUString>());
1080 CPPUNIT_ASSERT_EQUAL(u"c"_ustr, aLabels[2][0].get<OUString>());
1083 CPPUNIT_TEST_FIXTURE(Chart2ExportTest, testErrorBarDataRangeODS)
1085 loadFromFile(u"ods/ErrorBarRange.ods");
1086 saveAndReload(u"calc8"_ustr);
1088 uno::Reference< chart2::XChartDocument > xChartDoc = getChartDocFromSheet( 0 );
1089 CPPUNIT_ASSERT(xChartDoc.is());
1091 Reference< chart2::XDataSeries > xDataSeries = getDataSeriesFromDoc( xChartDoc, 0 );
1092 CPPUNIT_ASSERT( xDataSeries.is() );
1094 Reference< beans::XPropertySet > xPropSet( xDataSeries, UNO_QUERY_THROW );
1096 // test that y error bars are there
1097 Reference< beans::XPropertySet > xErrorBarYProps;
1098 xPropSet->getPropertyValue(CHART_UNONAME_ERRORBAR_Y) >>= xErrorBarYProps;
1099 uno::Any aAny = xErrorBarYProps->getPropertyValue(u"ErrorBarRangePositive"_ustr);
1100 CPPUNIT_ASSERT(aAny.hasValue());
1101 OUString aPosRange;
1102 aAny >>= aPosRange;
1103 CPPUNIT_ASSERT_EQUAL(u"$Sheet1.$B$1:$B$3"_ustr, aPosRange);
1105 aAny = xErrorBarYProps->getPropertyValue(u"ErrorBarRangeNegative"_ustr);
1106 CPPUNIT_ASSERT(aAny.hasValue());
1107 OUString aNegRange;
1108 aAny >>= aNegRange;
1109 CPPUNIT_ASSERT_EQUAL(u"$Sheet1.$C$1:$C$3"_ustr, aNegRange);
1112 CPPUNIT_TEST_FIXTURE(Chart2ExportTest, tdf50934_barOfPie)
1114 loadFromFile(u"ods/tdf50934_barOfPie.ods");
1115 saveAndReload(u"calc8"_ustr);
1117 uno::Reference< chart2::XChartDocument > xChartDoc = getChartDocFromSheet( 0 );
1118 CPPUNIT_ASSERT(xChartDoc.is());
1120 Reference< chart2::XChartType > xChartType = getChartTypeFromDoc( xChartDoc, 0 );
1121 CPPUNIT_ASSERT(xChartType.is());
1123 CPPUNIT_ASSERT_EQUAL(u"com.sun.star.chart2.PieChartType"_ustr,
1124 xChartType->getChartType());
1126 // Verify that it saves and loads as bar-of-pie
1127 Reference< beans::XPropertySet > xPropSet( xChartType, uno::UNO_QUERY_THROW );
1128 uno::Any aAny = xPropSet->getPropertyValue(u"SubPieType"_ustr);
1129 CPPUNIT_ASSERT(aAny.hasValue());
1130 chart2::PieChartSubType subPieType;
1131 aAny >>= subPieType;
1132 CPPUNIT_ASSERT_EQUAL(chart2::PieChartSubType_BAR, subPieType);
1135 CPPUNIT_TEST_FIXTURE(Chart2ExportTest, tdf50934_pieOfPie)
1137 loadFromFile(u"ods/tdf50934_pieOfPie.ods");
1138 saveAndReload(u"calc8"_ustr);
1140 uno::Reference< chart2::XChartDocument > xChartDoc = getChartDocFromSheet( 0 );
1141 CPPUNIT_ASSERT(xChartDoc.is());
1143 Reference< chart2::XChartType > xChartType = getChartTypeFromDoc( xChartDoc, 0 );
1144 CPPUNIT_ASSERT(xChartType.is());
1146 CPPUNIT_ASSERT_EQUAL(u"com.sun.star.chart2.PieChartType"_ustr,
1147 xChartType->getChartType());
1149 // Verify that it saves and loads as pie-of-pie
1150 Reference< beans::XPropertySet > xPropSet( xChartType, uno::UNO_QUERY_THROW );
1151 uno::Any aAny = xPropSet->getPropertyValue(u"SubPieType"_ustr);
1152 CPPUNIT_ASSERT(aAny.hasValue());
1153 chart2::PieChartSubType subPieType;
1154 aAny >>= subPieType;
1155 CPPUNIT_ASSERT_EQUAL(chart2::PieChartSubType_PIE, subPieType);
1158 CPPUNIT_TEST_FIXTURE(Chart2ExportTest, tdf161800_barOfPie_split_pos)
1160 loadFromFile(u"ods/tdf161800_barOfPie_split_pos.ods");
1161 saveAndReload(u"calc8"_ustr);
1163 uno::Reference< chart2::XChartDocument > xChartDoc = getChartDocFromSheet( 0 );
1164 CPPUNIT_ASSERT(xChartDoc.is());
1166 Reference< chart2::XChartType > xChartType = getChartTypeFromDoc( xChartDoc, 0 );
1167 CPPUNIT_ASSERT(xChartType.is());
1169 // Verify that it saves and loads with the correct split position
1170 Reference< beans::XPropertySet > xPropSet( xChartType, uno::UNO_QUERY_THROW );
1171 uno::Any aAny = xPropSet->getPropertyValue(u"SplitPos"_ustr);
1172 CPPUNIT_ASSERT(aAny.hasValue());
1173 double nSplitPos;
1174 aAny >>= nSplitPos;
1175 CPPUNIT_ASSERT_EQUAL(4.0, nSplitPos);
1178 CPPUNIT_TEST_FIXTURE(Chart2ExportTest, tdf161800_pieOfPie_split_pos)
1180 loadFromFile(u"ods/tdf161800_pieOfPie_split_pos.ods");
1181 saveAndReload(u"calc8"_ustr);
1183 uno::Reference< chart2::XChartDocument > xChartDoc = getChartDocFromSheet( 0 );
1184 CPPUNIT_ASSERT(xChartDoc.is());
1186 Reference< chart2::XChartType > xChartType = getChartTypeFromDoc( xChartDoc, 0 );
1187 CPPUNIT_ASSERT(xChartType.is());
1189 CPPUNIT_ASSERT_EQUAL(u"com.sun.star.chart2.PieChartType"_ustr,
1190 xChartType->getChartType());
1192 // Verify that it saves and loads with the correct split position
1193 Reference< beans::XPropertySet > xPropSet( xChartType, uno::UNO_QUERY_THROW );
1194 uno::Any aAny = xPropSet->getPropertyValue(u"SplitPos"_ustr);
1195 CPPUNIT_ASSERT(aAny.hasValue());
1196 double nSplitPos;
1197 aAny >>= nSplitPos;
1198 CPPUNIT_ASSERT_EQUAL(3.0, nSplitPos);
1201 CPPUNIT_TEST_FIXTURE(Chart2ExportTest, testChartCrash)
1203 loadFromFile(u"docx/FDO75975.docx");
1204 save(u"Office Open XML Text"_ustr);
1205 xmlDocUniquePtr pXmlDoc = parseExport(u"word/charts/chart1.xml"_ustr);
1206 CPPUNIT_ASSERT(pXmlDoc);
1209 CPPUNIT_TEST_FIXTURE(Chart2ExportTest, testPieChartRotation)
1211 loadFromFile(u"docx/pieChartRotation.docx");
1212 save(u"Office Open XML Text"_ustr);
1213 xmlDocUniquePtr pXmlDoc = parseExport(u"word/charts/chart1.xml"_ustr);
1214 CPPUNIT_ASSERT(pXmlDoc);
1215 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:view3D/c:rotX", "val", u"40");
1216 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:view3D/c:rotY", "val", u"30");
1219 CPPUNIT_TEST_FIXTURE(Chart2ExportTest, testEmbeddingsOleObjectGrabBag)
1221 // The problem was that .bin files were missing from docx file from embeddings folder
1222 // after saving file.
1223 // This test case tests whether embeddings files grabbagged properly in correct object.
1225 loadFromFile(u"docx/testchartoleobjectembeddings.docx" );
1226 uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY);
1227 uno::Reference<beans::XPropertySet> xTextDocumentPropertySet(xTextDocument, uno::UNO_QUERY);
1228 uno::Sequence<beans::PropertyValue> aGrabBag(0);
1229 xTextDocumentPropertySet->getPropertyValue(u"InteropGrabBag"_ustr) >>= aGrabBag;
1230 CPPUNIT_ASSERT(aGrabBag.hasElements()); // Grab Bag not empty
1231 bool bEmbeddings = false;
1232 const char* const testEmbeddedFileNames[] = {"word/embeddings/oleObject1.bin"};
1233 for (beans::PropertyValue const& prop : aGrabBag)
1235 if (prop.Name == "OOXEmbeddings")
1237 bEmbeddings = true;
1238 uno::Sequence<beans::PropertyValue> aEmbeddingsList(0);
1239 uno::Reference<io::XInputStream> aEmbeddingXlsxStream;
1240 OUString aEmbeddedfileName;
1241 CPPUNIT_ASSERT(prop.Value >>= aEmbeddingsList); // PropertyValue of proper type
1242 sal_Int32 length = aEmbeddingsList.getLength();
1243 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), length);
1244 for(int j = 0; j < length; ++j)
1246 aEmbeddingsList[j].Value >>= aEmbeddingXlsxStream;
1247 aEmbeddedfileName = aEmbeddingsList[j].Name;
1248 CPPUNIT_ASSERT(aEmbeddingXlsxStream); // Reference not empty
1249 CPPUNIT_ASSERT_EQUAL(OUString::createFromAscii(testEmbeddedFileNames[j]),aEmbeddedfileName);
1253 CPPUNIT_ASSERT(bEmbeddings); // Grab Bag has all the expected elements
1256 namespace {
1258 void checkGapWidth(Reference<beans::XPropertySet> const & xPropSet, sal_Int32 nValue)
1260 uno::Any aAny = xPropSet->getPropertyValue(u"GapwidthSequence"_ustr);
1261 CPPUNIT_ASSERT(aAny.hasValue());
1262 uno::Sequence< sal_Int32 > aSequence;
1263 aAny >>= aSequence;
1264 CPPUNIT_ASSERT(aSequence.hasElements());
1265 CPPUNIT_ASSERT_EQUAL(nValue, aSequence[0]);
1268 void checkOverlap(Reference<beans::XPropertySet> const & xPropSet, sal_Int32 nValue)
1270 uno::Any aAny = xPropSet->getPropertyValue(u"OverlapSequence"_ustr);
1271 CPPUNIT_ASSERT(aAny.hasValue());
1272 uno::Sequence< sal_Int32 > aSequence;
1273 aAny >>= aSequence;
1274 CPPUNIT_ASSERT(aSequence.hasElements());
1275 CPPUNIT_ASSERT_EQUAL(nValue, aSequence[0]);
1278 void checkSheetForGapWidthAndOverlap(uno::Reference< chart2::XChartType > const & xChartType,
1279 sal_Int32 nExpectedGapWidth, sal_Int32 nExpectedOverlap)
1281 Reference< beans::XPropertySet > xPropSet( xChartType, uno::UNO_QUERY_THROW );
1282 checkGapWidth(xPropSet, nExpectedGapWidth);
1283 checkOverlap(xPropSet, nExpectedOverlap);
1288 CPPUNIT_TEST_FIXTURE(Chart2ExportTest, testGapWidthXLSX)
1290 loadFromFile(u"xlsx/gapWidth.xlsx");
1292 uno::Reference< chart2::XChartDocument > xChartDoc = getChartDocFromSheet( 0 );
1293 checkSheetForGapWidthAndOverlap(getChartTypeFromDoc( xChartDoc, 0 ), 120, -60);
1295 xChartDoc = getChartDocFromSheet( 1 );
1296 checkSheetForGapWidthAndOverlap(getChartTypeFromDoc( xChartDoc, 0 ), 50, 30);
1298 saveAndReload(u"Calc Office Open XML"_ustr);
1300 xChartDoc = getChartDocFromSheet( 0 );
1301 checkSheetForGapWidthAndOverlap(getChartTypeFromDoc( xChartDoc, 0 ), 120, -60);
1303 xChartDoc = getChartDocFromSheet( 1 );
1304 checkSheetForGapWidthAndOverlap(getChartTypeFromDoc( xChartDoc, 0 ), 50, 30);
1307 CPPUNIT_TEST_FIXTURE(Chart2ExportTest, testDataseriesOverlapStackedChartXLSX)
1309 loadFromFile(u"xlsx/testDataseriesOverlapStackedChart.xlsx");
1311 // test the overlap value of a simple Stacked Column Chart
1312 uno::Reference< chart2::XChartDocument > xChartDoc = getChartDocFromSheet( 0);
1313 checkSheetForGapWidthAndOverlap(getChartTypeFromDoc( xChartDoc, 0 ), 100, 0);
1315 // test the overlap value of a Percent Stacked Bar Chart
1316 xChartDoc = getChartDocFromSheet( 1);
1317 checkSheetForGapWidthAndOverlap(getChartTypeFromDoc( xChartDoc, 0 ), 100, 35);
1319 saveAndReload(u"Calc Office Open XML"_ustr);
1321 xChartDoc = getChartDocFromSheet( 0);
1322 checkSheetForGapWidthAndOverlap(getChartTypeFromDoc( xChartDoc, 0 ), 100, 100);
1324 xChartDoc = getChartDocFromSheet( 1);
1325 checkSheetForGapWidthAndOverlap(getChartTypeFromDoc( xChartDoc, 0 ), 100, 100);
1328 CPPUNIT_TEST_FIXTURE(Chart2ExportTest, testSmoothedLines)
1330 loadFromFile(u"ods/smoothedLines.ods");
1331 save(u"Calc Office Open XML"_ustr);
1332 xmlDocUniquePtr pXmlDoc = parseExport(u"xl/charts/chart1.xml"_ustr);
1333 CPPUNIT_ASSERT(pXmlDoc);
1334 assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:lineChart/c:ser[1]/c:smooth", "val", u"0");
1337 CPPUNIT_TEST_FIXTURE(Chart2ExportTest, testLabelStringODS)
1339 loadFromFile(u"ods/labelString.ods");
1341 uno::Reference< chart2::XChartDocument > xChartDoc = getChartDocFromSheet( 0 );
1342 Reference< chart2::data::XDataSequence > xLabelSeq =
1343 getLabelDataSequenceFromDoc(xChartDoc);
1344 CPPUNIT_ASSERT(xLabelSeq.is());
1346 OUString aLabelString = xLabelSeq->getSourceRangeRepresentation();
1347 CPPUNIT_ASSERT_EQUAL(u"\"LabelName\""_ustr, aLabelString);
1349 saveAndReload(u"calc8"_ustr);
1351 xChartDoc = getChartDocFromSheet( 0 );
1352 xLabelSeq = getLabelDataSequenceFromDoc(xChartDoc);
1353 CPPUNIT_ASSERT(xLabelSeq.is());
1355 aLabelString = xLabelSeq->getSourceRangeRepresentation();
1356 CPPUNIT_ASSERT_EQUAL(u"\"LabelName\""_ustr, aLabelString);
1360 CPPUNIT_TEST_FIXTURE(Chart2ExportTest, testInvertNegative)
1362 // Bar chart
1364 loadFromFile(u"xlsx/invertIfNeg_bar.xlsx");
1365 // make sure the import was successful
1366 uno::Reference< chart2::XChartDocument > xChartDoc = getChartDocFromSheet( 0 );
1367 CPPUNIT_ASSERT(xChartDoc.is());
1369 Reference< chart2::XDataSeries > xDataSeries = getDataSeriesFromDoc( xChartDoc, 0 );
1370 CPPUNIT_ASSERT( xDataSeries.is() );
1372 Reference< beans::XPropertySet > xPropSet( xDataSeries, UNO_QUERY_THROW );
1374 bool bInvertNeg;
1375 CPPUNIT_ASSERT(
1376 xPropSet->getPropertyValue(u"InvertNegative"_ustr) >>= bInvertNeg);
1377 CPPUNIT_ASSERT_EQUAL(true, bInvertNeg);
1380 // Bubble chart
1382 loadFromFile(u"xlsx/invertIfNeg_bubble.xlsx");
1383 // make sure the import was successful
1384 uno::Reference< chart2::XChartDocument > xChartDoc = getChartDocFromSheet( 0 );
1385 CPPUNIT_ASSERT(xChartDoc.is());
1387 Reference< chart2::XDataSeries > xDataSeries = getDataSeriesFromDoc( xChartDoc, 0 );
1388 CPPUNIT_ASSERT( xDataSeries.is() );
1390 Reference< beans::XPropertySet > xPropSet( xDataSeries, UNO_QUERY_THROW );
1392 bool bInvertNeg;
1393 CPPUNIT_ASSERT(
1394 xPropSet->getPropertyValue(u"InvertNegative"_ustr) >>= bInvertNeg);
1395 CPPUNIT_ASSERT_EQUAL(true, bInvertNeg);
1400 CPPUNIT_PLUGIN_IMPLEMENT();
1402 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */