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 :
12 : #include <test/xmltesttools.hxx>
13 :
14 : #include <com/sun/star/chart/ErrorBarStyle.hpp>
15 : #include <com/sun/star/chart2/XRegressionCurveContainer.hpp>
16 : #include <com/sun/star/lang/XServiceName.hpp>
17 : #include <com/sun/star/packages/zip/ZipFileAccess.hpp>
18 : #include <com/sun/star/text/XTextDocument.hpp>
19 : #include <com/sun/star/text/XTextFramesSupplier.hpp>
20 : #include <com/sun/star/drawing/LineStyle.hpp>
21 : #include <com/sun/star/chart2/DataPointLabel.hpp>
22 :
23 : #include <unotools/ucbstreamhelper.hxx>
24 : #include <rtl/strbuf.hxx>
25 :
26 : #include <libxml/xpathInternals.h>
27 : #include <libxml/parserInternals.h>
28 :
29 : #include <algorithm>
30 :
31 : using uno::Reference;
32 : using beans::XPropertySet;
33 :
34 120 : class Chart2ExportTest : public ChartTest, public XmlTestTools
35 : {
36 : protected:
37 :
38 : virtual void registerNamespaces(xmlXPathContextPtr& pXmlXPathCtx) SAL_OVERRIDE;
39 : public:
40 60 : Chart2ExportTest() : ChartTest() {}
41 : void testErrorBarXLSX();
42 : void testTrendline();
43 : void testTrendlineOOXML();
44 : void testTrendlineXLS();
45 : void testStockChart();
46 : void testBarChart();
47 : void testCrosses();
48 : void testScatterChartTextXValues();
49 : void testChartDataTable();
50 : void testChartExternalData();
51 : void testEmbeddingsGrabBag();
52 : void testAreaChartLoad();
53 : void testUpDownBars();
54 : void testDoughnutChart();
55 : void testDisplayUnits();
56 : // void testFdo74115WallGradientFill();
57 : void testFdo74115WallBitmapFill();
58 : void testBarChartRotation();
59 : void testShapeFollowedByChart();
60 : void testPieChartDataLabels();
61 : void testSeriesIdxOrder();
62 : void testScatterPlotLabels();
63 : void testErrorBarDataRangeODS();
64 : void testChartCrash();
65 : void testPieChartRotation();
66 : void testEmbeddingsOleObjectGrabBag();
67 : void testGapWidthXLSX();
68 : void testSmoothedLines();
69 : void testLabelStringODS();
70 : void testFdo78290LineChartMarkerX();
71 : void testFdo78290ScatterChartMarkerX();
72 : void testFdo78290CombinationChartMarkerX();
73 : void testAxisNumberFormatODS();
74 : void testDataLabelBordersDOCX();
75 : void testDataLabel3DChartDOCX();
76 : void testDataLabelBarChartDOCX();
77 : void testDataLabelClusteredBarChartDOCX();
78 : void testDataLabelRadarChartDOCX();
79 : void testDataLabelDoughnutChartDOCX();
80 : void testDataLabelAreaChartDOCX();
81 : void testDataLabelDefaultLineChartDOCX();
82 : void testFdo83058dlblPos();
83 : void testAutoTitleDelXLSX();
84 : void testDispBlanksAsXLSX();
85 : void testMarkerColorXLSX();
86 : void testRoundedCornersXLSX();
87 : void testAxisNumberFormatXLSX();
88 : void testDataLabelDefaultValuesXLSX();
89 : void testTitleOverlayXLSX();
90 : void testInvertIfNegativeXLSX();
91 : void testBubble3DXLSX();
92 : void testNoMarkerXLSX();
93 : void testTitleManualLayoutXLSX();
94 : void testPlotAreaManualLayoutXLSX();
95 : void testLegendManualLayoutXLSX();
96 : void testAxisCharacterPropertiesXLSX();
97 : void testTitleCharacterPropertiesXLSX();
98 : void testPlotVisOnlyXLSX();
99 : void testBarChartVaryColorsXLSX();
100 : void testMultipleAxisXLSX();
101 : void testAxisTitleRotationXLSX();
102 :
103 2 : CPPUNIT_TEST_SUITE(Chart2ExportTest);
104 1 : CPPUNIT_TEST(testErrorBarXLSX);
105 1 : CPPUNIT_TEST(testTrendline);
106 1 : CPPUNIT_TEST(testTrendlineOOXML);
107 1 : CPPUNIT_TEST(testTrendlineXLS);
108 1 : CPPUNIT_TEST(testStockChart);
109 1 : CPPUNIT_TEST(testBarChart);
110 1 : CPPUNIT_TEST(testCrosses);
111 1 : CPPUNIT_TEST(testScatterChartTextXValues);
112 1 : CPPUNIT_TEST(testChartDataTable);
113 1 : CPPUNIT_TEST(testChartExternalData);
114 1 : CPPUNIT_TEST(testEmbeddingsGrabBag);
115 1 : CPPUNIT_TEST(testAreaChartLoad);
116 1 : CPPUNIT_TEST(testUpDownBars);
117 1 : CPPUNIT_TEST(testDoughnutChart);
118 1 : CPPUNIT_TEST(testDisplayUnits);
119 : // CPPUNIT_TEST(testFdo74115WallGradientFill);
120 1 : CPPUNIT_TEST(testFdo74115WallBitmapFill);
121 1 : CPPUNIT_TEST(testBarChartRotation);
122 1 : CPPUNIT_TEST(testShapeFollowedByChart);
123 1 : CPPUNIT_TEST(testPieChartDataLabels);
124 1 : CPPUNIT_TEST(testSeriesIdxOrder);
125 1 : CPPUNIT_TEST(testScatterPlotLabels);
126 1 : CPPUNIT_TEST(testErrorBarDataRangeODS);
127 1 : CPPUNIT_TEST(testChartCrash);
128 1 : CPPUNIT_TEST(testPieChartRotation);
129 1 : CPPUNIT_TEST(testEmbeddingsOleObjectGrabBag);
130 1 : CPPUNIT_TEST(testGapWidthXLSX);
131 1 : CPPUNIT_TEST(testSmoothedLines);
132 1 : CPPUNIT_TEST(testLabelStringODS);
133 1 : CPPUNIT_TEST(testFdo78290LineChartMarkerX);
134 1 : CPPUNIT_TEST(testFdo78290ScatterChartMarkerX);
135 1 : CPPUNIT_TEST(testFdo78290CombinationChartMarkerX);
136 1 : CPPUNIT_TEST(testAxisNumberFormatODS);
137 1 : CPPUNIT_TEST(testDataLabelBordersDOCX);
138 1 : CPPUNIT_TEST(testDataLabel3DChartDOCX);
139 1 : CPPUNIT_TEST(testDataLabelBarChartDOCX);
140 1 : CPPUNIT_TEST(testDataLabelClusteredBarChartDOCX);
141 1 : CPPUNIT_TEST(testDataLabelRadarChartDOCX);
142 1 : CPPUNIT_TEST(testDataLabelDoughnutChartDOCX);
143 1 : CPPUNIT_TEST(testDataLabelAreaChartDOCX);
144 1 : CPPUNIT_TEST(testDataLabelDefaultLineChartDOCX);
145 1 : CPPUNIT_TEST(testFdo83058dlblPos);
146 1 : CPPUNIT_TEST(testAutoTitleDelXLSX);
147 1 : CPPUNIT_TEST(testDispBlanksAsXLSX);
148 1 : CPPUNIT_TEST(testMarkerColorXLSX);
149 1 : CPPUNIT_TEST(testRoundedCornersXLSX);
150 1 : CPPUNIT_TEST(testAxisNumberFormatXLSX);
151 1 : CPPUNIT_TEST(testDataLabelDefaultValuesXLSX);
152 1 : CPPUNIT_TEST(testTitleOverlayXLSX);
153 1 : CPPUNIT_TEST(testInvertIfNegativeXLSX);
154 1 : CPPUNIT_TEST(testBubble3DXLSX);
155 1 : CPPUNIT_TEST(testNoMarkerXLSX);
156 1 : CPPUNIT_TEST(testTitleManualLayoutXLSX);
157 1 : CPPUNIT_TEST(testPlotAreaManualLayoutXLSX);
158 1 : CPPUNIT_TEST(testLegendManualLayoutXLSX);
159 1 : CPPUNIT_TEST(testAxisCharacterPropertiesXLSX);
160 1 : CPPUNIT_TEST(testTitleCharacterPropertiesXLSX);
161 1 : CPPUNIT_TEST(testPlotVisOnlyXLSX);
162 1 : CPPUNIT_TEST(testBarChartVaryColorsXLSX);
163 1 : CPPUNIT_TEST(testMultipleAxisXLSX);
164 1 : CPPUNIT_TEST(testAxisTitleRotationXLSX);
165 5 : CPPUNIT_TEST_SUITE_END();
166 :
167 : protected:
168 : /**
169 : * Given that some problem doesn't affect the result in the importer, we
170 : * test the resulting file directly, by opening the zip file, parsing an
171 : * xml stream, and asserting an XPath expression. This method returns the
172 : * xml stream, so that you can do the asserting.
173 : */
174 : xmlDocPtr parseExport(const OUString& rDir, const OUString& rFilterFormat);
175 :
176 : };
177 :
178 : namespace {
179 :
180 138 : struct CheckForChartName
181 : {
182 : private:
183 : OUString aDir;
184 :
185 : public:
186 46 : explicit CheckForChartName( const OUString& rDir ):
187 46 : aDir(rDir) {}
188 :
189 450 : bool operator()(const OUString& rName)
190 : {
191 450 : if(!rName.startsWith(aDir))
192 404 : return false;
193 :
194 46 : if(!rName.endsWith(".xml"))
195 0 : return false;
196 :
197 46 : return true;
198 : }
199 : };
200 :
201 46 : OUString findChartFile(const OUString& rDir, uno::Reference< container::XNameAccess > xNames )
202 : {
203 46 : uno::Sequence<OUString> rNames = xNames->getElementNames();
204 46 : OUString* pElement = std::find_if(rNames.begin(), rNames.end(), CheckForChartName(rDir));
205 :
206 46 : CPPUNIT_ASSERT(pElement);
207 46 : CPPUNIT_ASSERT(pElement != rNames.end());
208 46 : return *pElement;
209 : }
210 :
211 : }
212 :
213 46 : xmlDocPtr Chart2ExportTest::parseExport(const OUString& rDir, const OUString& rFilterFormat)
214 : {
215 46 : boost::shared_ptr<utl::TempFile> pTempFile = reload(rFilterFormat);
216 :
217 : // Read the XML stream we're interested in.
218 92 : uno::Reference<packages::zip::XZipFileAccess2> xNameAccess = packages::zip::ZipFileAccess::createWithURL(comphelper::getComponentContext(m_xSFactory), pTempFile->GetURL());
219 92 : uno::Reference<io::XInputStream> xInputStream(xNameAccess->getByName(findChartFile(rDir, xNameAccess)), uno::UNO_QUERY);
220 46 : CPPUNIT_ASSERT(xInputStream.is());
221 92 : boost::shared_ptr<SvStream> pStream(utl::UcbStreamHelper::CreateStream(xInputStream, true));
222 :
223 92 : return parseXmlStream(pStream.get());
224 : }
225 :
226 101 : void Chart2ExportTest::registerNamespaces(xmlXPathContextPtr& pXmlXPathCtx)
227 : {
228 : struct { xmlChar* pPrefix; xmlChar* pURI; } aNamespaces[] =
229 : {
230 : { BAD_CAST("w"), BAD_CAST("http://schemas.openxmlformats.org/wordprocessingml/2006/main") },
231 : { BAD_CAST("v"), BAD_CAST("urn:schemas-microsoft-com:vml") },
232 : { BAD_CAST("c"), BAD_CAST("http://schemas.openxmlformats.org/drawingml/2006/chart") },
233 : { BAD_CAST("a"), BAD_CAST("http://schemas.openxmlformats.org/drawingml/2006/main") },
234 : { BAD_CAST("mc"), BAD_CAST("http://schemas.openxmlformats.org/markup-compatibility/2006") },
235 : { BAD_CAST("wps"), BAD_CAST("http://schemas.microsoft.com/office/word/2010/wordprocessingShape") },
236 : { BAD_CAST("wpg"), BAD_CAST("http://schemas.microsoft.com/office/word/2010/wordprocessingGroup") },
237 : { BAD_CAST("wp"), BAD_CAST("http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing") },
238 : { BAD_CAST("office"), BAD_CAST("urn:oasis:names:tc:opendocument:xmlns:office:1.0") },
239 : { BAD_CAST("table"), BAD_CAST("urn:oasis:names:tc:opendocument:xmlns:table:1.0") },
240 : { BAD_CAST("text"), BAD_CAST("urn:oasis:names:tc:opendocument:xmlns:text:1.0") },
241 : { BAD_CAST("xlink"), BAD_CAST("http://www.w3c.org/1999/xlink") }
242 101 : };
243 1313 : for(size_t i = 0; i < SAL_N_ELEMENTS(aNamespaces); ++i)
244 : {
245 1212 : xmlXPathRegisterNs(pXmlXPathCtx, aNamespaces[i].pPrefix, aNamespaces[i].pURI );
246 : }
247 101 : }
248 :
249 : namespace {
250 :
251 2 : void testErrorBar( Reference< XPropertySet > xErrorBar )
252 : {
253 : sal_Int32 nErrorBarStyle;
254 4 : CPPUNIT_ASSERT(
255 2 : xErrorBar->getPropertyValue("ErrorBarStyle") >>= nErrorBarStyle);
256 2 : CPPUNIT_ASSERT_EQUAL(nErrorBarStyle, chart::ErrorBarStyle::RELATIVE);
257 2 : bool bShowPositive = bool(), bShowNegative = bool();
258 4 : CPPUNIT_ASSERT(
259 2 : xErrorBar->getPropertyValue("ShowPositiveError") >>= bShowPositive);
260 2 : CPPUNIT_ASSERT(bShowPositive);
261 4 : CPPUNIT_ASSERT(
262 2 : xErrorBar->getPropertyValue("ShowNegativeError") >>= bShowNegative);
263 2 : CPPUNIT_ASSERT(bShowNegative);
264 2 : double nVal = 0.0;
265 2 : CPPUNIT_ASSERT(xErrorBar->getPropertyValue("PositiveError") >>= nVal);
266 2 : CPPUNIT_ASSERT_DOUBLES_EQUAL(nVal, 10.0, 1e-10);
267 2 : }
268 :
269 12 : void checkCommonTrendline(
270 : Reference<chart2::XRegressionCurve> xCurve,
271 : double aExpectedExtrapolateForward, double aExpectedExtrapolateBackward,
272 : bool aExpectedForceIntercept, double aExpectedInterceptValue,
273 : bool aExpectedShowEquation, bool aExpectedR2)
274 : {
275 12 : Reference<XPropertySet> xProperties( xCurve , uno::UNO_QUERY );
276 12 : CPPUNIT_ASSERT(xProperties.is());
277 :
278 12 : double aExtrapolateForward = 0.0;
279 12 : CPPUNIT_ASSERT(xProperties->getPropertyValue("ExtrapolateForward") >>= aExtrapolateForward);
280 12 : CPPUNIT_ASSERT_EQUAL(aExpectedExtrapolateForward, aExtrapolateForward);
281 :
282 12 : double aExtrapolateBackward = 0.0;
283 12 : CPPUNIT_ASSERT(xProperties->getPropertyValue("ExtrapolateBackward") >>= aExtrapolateBackward);
284 12 : CPPUNIT_ASSERT_EQUAL(aExpectedExtrapolateBackward, aExtrapolateBackward);
285 :
286 12 : bool aForceIntercept = false;
287 12 : CPPUNIT_ASSERT(xProperties->getPropertyValue("ForceIntercept") >>= aForceIntercept);
288 12 : CPPUNIT_ASSERT_EQUAL(aExpectedForceIntercept, aForceIntercept);
289 :
290 12 : if (aForceIntercept)
291 : {
292 6 : double aInterceptValue = 0.0;
293 6 : CPPUNIT_ASSERT(xProperties->getPropertyValue("InterceptValue") >>= aInterceptValue);
294 6 : CPPUNIT_ASSERT_EQUAL(aExpectedInterceptValue, aInterceptValue);
295 : }
296 :
297 24 : Reference< XPropertySet > xEquationProperties( xCurve->getEquationProperties() );
298 12 : CPPUNIT_ASSERT(xEquationProperties.is());
299 :
300 12 : bool aShowEquation = false;
301 12 : CPPUNIT_ASSERT(xEquationProperties->getPropertyValue("ShowEquation") >>= aShowEquation);
302 12 : CPPUNIT_ASSERT_EQUAL(aExpectedShowEquation, aShowEquation);
303 :
304 12 : bool aShowCorrelationCoefficient = false;
305 12 : CPPUNIT_ASSERT(xEquationProperties->getPropertyValue("ShowCorrelationCoefficient") >>= aShowCorrelationCoefficient);
306 24 : CPPUNIT_ASSERT_EQUAL(aExpectedR2, aShowCorrelationCoefficient);
307 12 : }
308 :
309 18 : void checkNameAndType(Reference<XPropertySet> xProperties, const OUString& aExpectedName, const OUString& aExpectedServiceName)
310 : {
311 18 : Reference< lang::XServiceName > xServiceName( xProperties, UNO_QUERY );
312 18 : CPPUNIT_ASSERT(xServiceName.is());
313 :
314 36 : OUString aServiceName = xServiceName->getServiceName();
315 18 : CPPUNIT_ASSERT_EQUAL(aExpectedServiceName, aServiceName);
316 :
317 36 : OUString aCurveName;
318 18 : CPPUNIT_ASSERT(xProperties->getPropertyValue("CurveName") >>= aCurveName);
319 36 : CPPUNIT_ASSERT_EQUAL(aExpectedName, aCurveName);
320 18 : }
321 :
322 6 : void checkLinearTrendline(
323 : Reference<chart2::XRegressionCurve> xCurve, const OUString& aExpectedName,
324 : double aExpectedExtrapolateForward, double aExpectedExtrapolateBackward,
325 : bool aExpectedForceIntercept, double aExpectedInterceptValue,
326 : bool aExpectedShowEquation, bool aExpectedR2)
327 : {
328 6 : Reference<XPropertySet> xProperties( xCurve , uno::UNO_QUERY );
329 6 : CPPUNIT_ASSERT(xProperties.is());
330 :
331 6 : checkNameAndType(xProperties, aExpectedName, "com.sun.star.chart2.LinearRegressionCurve");
332 :
333 : checkCommonTrendline(
334 : xCurve,
335 : aExpectedExtrapolateForward, aExpectedExtrapolateBackward,
336 : aExpectedForceIntercept, aExpectedInterceptValue,
337 6 : aExpectedShowEquation, aExpectedR2);
338 6 : }
339 :
340 6 : void checkPolynomialTrendline(
341 : Reference<chart2::XRegressionCurve> xCurve, const OUString& aExpectedName,
342 : sal_Int32 aExpectedDegree,
343 : double aExpectedExtrapolateForward, double aExpectedExtrapolateBackward,
344 : bool aExpectedForceIntercept, double aExpectedInterceptValue,
345 : bool aExpectedShowEquation, bool aExpectedR2)
346 : {
347 6 : Reference<XPropertySet> xProperties( xCurve , uno::UNO_QUERY );
348 6 : CPPUNIT_ASSERT(xProperties.is());
349 :
350 6 : checkNameAndType(xProperties, aExpectedName, "com.sun.star.chart2.PolynomialRegressionCurve");
351 :
352 6 : sal_Int32 aDegree = 2;
353 6 : CPPUNIT_ASSERT(xProperties->getPropertyValue("PolynomialDegree") >>= aDegree);
354 6 : CPPUNIT_ASSERT_EQUAL(aExpectedDegree, aDegree);
355 :
356 : checkCommonTrendline(
357 : xCurve,
358 : aExpectedExtrapolateForward, aExpectedExtrapolateBackward,
359 : aExpectedForceIntercept, aExpectedInterceptValue,
360 6 : aExpectedShowEquation, aExpectedR2);
361 6 : }
362 :
363 6 : void checkMovingAverageTrendline(
364 : Reference<chart2::XRegressionCurve> xCurve, const OUString& aExpectedName, sal_Int32 aExpectedPeriod)
365 : {
366 6 : Reference<XPropertySet> xProperties( xCurve , uno::UNO_QUERY );
367 6 : CPPUNIT_ASSERT(xProperties.is());
368 :
369 6 : checkNameAndType(xProperties, aExpectedName, "com.sun.star.chart2.MovingAverageRegressionCurve");
370 :
371 6 : sal_Int32 aPeriod = 2;
372 6 : CPPUNIT_ASSERT(xProperties->getPropertyValue("MovingAveragePeriod") >>= aPeriod);
373 6 : CPPUNIT_ASSERT_EQUAL(aExpectedPeriod, aPeriod);
374 6 : }
375 :
376 6 : void checkTrendlinesInChart(uno::Reference< chart2::XChartDocument > xChartDoc)
377 : {
378 6 : CPPUNIT_ASSERT(xChartDoc.is());
379 :
380 6 : Reference< chart2::XDataSeries > xDataSeries = getDataSeriesFromDoc( xChartDoc, 0 );
381 6 : CPPUNIT_ASSERT( xDataSeries.is() );
382 :
383 12 : Reference< chart2::XRegressionCurveContainer > xRegressionCurveContainer( xDataSeries, UNO_QUERY );
384 6 : CPPUNIT_ASSERT( xRegressionCurveContainer.is() );
385 :
386 12 : Sequence< Reference< chart2::XRegressionCurve > > xRegressionCurveSequence = xRegressionCurveContainer->getRegressionCurves();
387 6 : CPPUNIT_ASSERT_EQUAL((sal_Int32) 3, xRegressionCurveSequence.getLength());
388 :
389 12 : Reference<chart2::XRegressionCurve> xCurve;
390 :
391 6 : xCurve = xRegressionCurveSequence[0];
392 6 : CPPUNIT_ASSERT(xCurve.is());
393 6 : checkPolynomialTrendline(xCurve, "col2_poly", 3, 0.1, -0.1, true, -1.0, true, true);
394 :
395 6 : xCurve = xRegressionCurveSequence[1];
396 6 : CPPUNIT_ASSERT(xCurve.is());
397 6 : checkLinearTrendline(xCurve, "col2_linear", -0.5, -0.5, false, 0.0, true, false);
398 :
399 6 : xCurve = xRegressionCurveSequence[2];
400 6 : CPPUNIT_ASSERT(xCurve.is());
401 12 : checkMovingAverageTrendline(xCurve, "col2_moving_avg", 3);
402 6 : }
403 :
404 : }
405 :
406 : // improve the test
407 1 : void Chart2ExportTest::testErrorBarXLSX()
408 : {
409 1 : load("/chart2/qa/extras/data/ods/", "error_bar.ods");
410 : {
411 : // make sure the ODS import was successful
412 1 : uno::Reference< chart2::XChartDocument > xChartDoc = getChartDocFromSheet( 0, mxComponent );
413 1 : CPPUNIT_ASSERT(xChartDoc.is());
414 :
415 2 : Reference< chart2::XDataSeries > xDataSeries = getDataSeriesFromDoc( xChartDoc, 0 );
416 1 : CPPUNIT_ASSERT( xDataSeries.is() );
417 :
418 2 : Reference< beans::XPropertySet > xPropSet( xDataSeries, UNO_QUERY_THROW );
419 1 : CPPUNIT_ASSERT( xPropSet.is() );
420 :
421 : // test that y error bars are there
422 2 : Reference< beans::XPropertySet > xErrorBarYProps;
423 1 : xPropSet->getPropertyValue(CHART_UNONAME_ERRORBAR_Y) >>= xErrorBarYProps;
424 2 : testErrorBar(xErrorBarYProps);
425 : }
426 :
427 1 : reload("Calc Office Open XML");
428 : {
429 1 : uno::Reference< chart2::XChartDocument > xChartDoc = getChartDocFromSheet( 0, mxComponent );
430 1 : CPPUNIT_ASSERT(xChartDoc.is());
431 :
432 2 : Reference< chart2::XDataSeries > xDataSeries = getDataSeriesFromDoc( xChartDoc, 0 );
433 1 : CPPUNIT_ASSERT( xDataSeries.is() );
434 :
435 2 : Reference< beans::XPropertySet > xPropSet( xDataSeries, UNO_QUERY_THROW );
436 1 : CPPUNIT_ASSERT( xPropSet.is() );
437 :
438 : // test that y error bars are there
439 2 : Reference< beans::XPropertySet > xErrorBarYProps;
440 1 : xPropSet->getPropertyValue(CHART_UNONAME_ERRORBAR_Y) >>= xErrorBarYProps;
441 2 : testErrorBar(xErrorBarYProps);
442 : }
443 1 : }
444 :
445 : // This method tests the preservation of properties for trendlines / regression curves
446 : // in an export -> import cycle using different file formats - ODS, XLS and XLSX.
447 1 : void Chart2ExportTest::testTrendline()
448 : {
449 1 : mbSkipValidation = true;
450 1 : load("/chart2/qa/extras/data/ods/", "trendline.ods");
451 1 : checkTrendlinesInChart(getChartDocFromSheet( 0, mxComponent));
452 1 : reload("calc8");
453 1 : checkTrendlinesInChart(getChartDocFromSheet( 0, mxComponent));
454 1 : }
455 :
456 1 : void Chart2ExportTest::testTrendlineOOXML()
457 : {
458 1 : load("/chart2/qa/extras/data/ods/", "trendline.ods");
459 1 : checkTrendlinesInChart(getChartDocFromSheet( 0, mxComponent));
460 1 : reload("Calc Office Open XML");
461 1 : checkTrendlinesInChart(getChartDocFromSheet( 0, mxComponent));
462 1 : }
463 :
464 1 : void Chart2ExportTest::testTrendlineXLS()
465 : {
466 1 : load("/chart2/qa/extras/data/ods/", "trendline.ods");
467 1 : checkTrendlinesInChart(getChartDocFromSheet( 0, mxComponent));
468 1 : reload("MS Excel 97");
469 1 : checkTrendlinesInChart(getChartDocFromSheet( 0, mxComponent));
470 1 : }
471 :
472 1 : void Chart2ExportTest::testStockChart()
473 : {
474 : /* For attached file Stock_Chart.docx, in chart1.xml,
475 : * <c:stockChart>, there are four types of series as
476 : * Open,Low,High and Close.
477 : * For Open series, in <c:idx val="0" />
478 : * an attribute val of index should start from 1 and not from 0.
479 : * Which was problem area.
480 : */
481 1 : load("/chart2/qa/extras/data/docx/", "testStockChart.docx");
482 :
483 1 : xmlDocPtr pXmlDoc = parseExport("word/charts/chart", "Office Open XML Text");
484 1 : if (!pXmlDoc)
485 1 : return;
486 :
487 1 : assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:stockChart/c:ser[1]/c:idx", "val", "1");
488 1 : assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:stockChart/c:ser[1]/c:order", "val", "1");
489 1 : assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:stockChart/c:ser[1]/c:tx/c:strRef/c:strCache/c:pt/c:v", "Open");
490 : }
491 :
492 1 : void Chart2ExportTest::testBarChart()
493 : {
494 1 : load("/chart2/qa/extras/data/docx/", "testBarChart.docx");
495 1 : xmlDocPtr pXmlDoc = parseExport("word/charts/chart", "Office Open XML Text");
496 1 : if (!pXmlDoc)
497 1 : return;
498 :
499 1 : assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:barChart/c:barDir", "val", "col");
500 : }
501 :
502 1 : void Chart2ExportTest::testCrosses()
503 : {
504 1 : load("/chart2/qa/extras/data/docx/", "Bar_horizontal_cone.docx");
505 1 : xmlDocPtr pXmlDoc = parseExport("word/charts/chart", "Office Open XML Text");
506 :
507 1 : assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:catAx/c:crosses", "val", "autoZero");
508 1 : }
509 :
510 1 : void Chart2ExportTest::testScatterChartTextXValues()
511 : {
512 1 : load("/chart2/qa/extras/data/docx/", "scatter-chart-text-x-values.docx");
513 :
514 1 : Reference<chart2::XChartDocument> xChartDoc(getChartDocFromWriter(0), uno::UNO_QUERY);
515 1 : CPPUNIT_ASSERT(xChartDoc.is());
516 :
517 2 : Reference<chart2::XChartType> xCT = getChartTypeFromDoc(xChartDoc, 0, 0);
518 1 : CPPUNIT_ASSERT(xCT.is());
519 :
520 : // Make sure we have exactly 3 data series.
521 2 : std::vector<uno::Sequence<uno::Any> > aLabels = getDataSeriesLabelsFromChartType(xCT);
522 1 : CPPUNIT_ASSERT_EQUAL(size_t(3), aLabels.size());
523 1 : CPPUNIT_ASSERT_EQUAL(OUString("Series 1"), aLabels[0][0].get<OUString>());
524 1 : CPPUNIT_ASSERT_EQUAL(OUString("Series 2"), aLabels[1][0].get<OUString>());
525 1 : CPPUNIT_ASSERT_EQUAL(OUString("Series 3"), aLabels[2][0].get<OUString>());
526 :
527 2 : std::vector<std::vector<double> > aYValues = getDataSeriesYValuesFromChartType(xCT);
528 1 : CPPUNIT_ASSERT_EQUAL(size_t(3), aYValues.size());
529 :
530 : // Check the Y values of "Series 1".
531 1 : CPPUNIT_ASSERT_EQUAL(size_t(4), aYValues[0].size());
532 1 : CPPUNIT_ASSERT_EQUAL(4.3, aYValues[0][0]);
533 1 : CPPUNIT_ASSERT_EQUAL(2.5, aYValues[0][1]);
534 1 : CPPUNIT_ASSERT_EQUAL(3.5, aYValues[0][2]);
535 1 : CPPUNIT_ASSERT_EQUAL(4.5, aYValues[0][3]);
536 :
537 : // And "Series 2".
538 1 : CPPUNIT_ASSERT_EQUAL(size_t(4), aYValues[1].size());
539 1 : CPPUNIT_ASSERT_EQUAL(2.4, aYValues[1][0]);
540 1 : CPPUNIT_ASSERT_EQUAL(4.4, aYValues[1][1]);
541 1 : CPPUNIT_ASSERT_EQUAL(1.8, aYValues[1][2]);
542 1 : CPPUNIT_ASSERT_EQUAL(2.8, aYValues[1][3]);
543 :
544 : // And "Series 3".
545 1 : CPPUNIT_ASSERT_EQUAL(size_t(4), aYValues[2].size());
546 1 : CPPUNIT_ASSERT_EQUAL(2.0, aYValues[2][0]);
547 1 : CPPUNIT_ASSERT_EQUAL(2.0, aYValues[2][1]);
548 1 : CPPUNIT_ASSERT_EQUAL(3.0, aYValues[2][2]);
549 1 : CPPUNIT_ASSERT_EQUAL(5.0, aYValues[2][3]);
550 :
551 : // Test the export.
552 1 : xmlDocPtr pXmlDoc = parseExport("word/charts/chart", "Office Open XML Text");
553 1 : if (!pXmlDoc)
554 1 : return;
555 :
556 2 : assertXPathContent(pXmlDoc, "//c:scatterChart/c:ser[1]/c:xVal[1]/c:numRef[1]/c:numCache[1]/c:pt[1]/c:v[1]", "1");
557 : }
558 :
559 1 : void Chart2ExportTest::testChartDataTable()
560 : {
561 1 : load("/chart2/qa/extras/data/docx/", "testChartDataTable.docx");
562 :
563 1 : xmlDocPtr pXmlDoc = parseExport("word/charts/chart", "Office Open XML Text");
564 1 : CPPUNIT_ASSERT(pXmlDoc);
565 1 : assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:dTable/c:showHorzBorder", "val", "1");
566 1 : assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:dTable/c:showVertBorder", "val", "1");
567 1 : assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:dTable/c:showOutline", "val", "1");
568 1 : }
569 :
570 1 : void Chart2ExportTest::testChartExternalData()
571 : {
572 1 : load("/chart2/qa/extras/data/docx/", "testMultipleChart.docx");
573 :
574 1 : xmlDocPtr pXmlDoc = parseExport("word/charts/chart", "Office Open XML Text");
575 1 : CPPUNIT_ASSERT(pXmlDoc);
576 1 : xmlXPathObjectPtr pXmlPathObj = getXPathNode(pXmlDoc, "/c:chartSpace/c:externalData");
577 1 : xmlNodeSetPtr pXmlNodes = pXmlPathObj->nodesetval;
578 1 : CPPUNIT_ASSERT(pXmlNodes);
579 1 : }
580 :
581 1 : void Chart2ExportTest::testEmbeddingsGrabBag()
582 : {
583 : // The problem was that .xlsx files were missing from docx file from embeddings folder
584 : // after saving file.
585 : // This test case tests whether embeddings files grabbagged properly in correct object.
586 :
587 1 : load("/chart2/qa/extras/data/docx/", "testMultiplechartembeddings.docx" );
588 1 : uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY);
589 2 : uno::Reference<beans::XPropertySet> xTextDocumentPropertySet(xTextDocument, uno::UNO_QUERY);
590 2 : uno::Sequence<beans::PropertyValue> aGrabBag(0);
591 1 : xTextDocumentPropertySet->getPropertyValue(OUString("InteropGrabBag")) >>= aGrabBag;
592 1 : CPPUNIT_ASSERT(aGrabBag.hasElements()); // Grab Bag not empty
593 1 : bool bEmbeddings = false;
594 : const char* testEmbeddedFileNames[3] = {"word/embeddings/Microsoft_Excel_Worksheet3.xlsx",
595 : "word/embeddings/Microsoft_Excel_Worksheet2.xlsx",
596 1 : "word/embeddings/Microsoft_Excel_Worksheet1.xlsx"};
597 13 : for(int i = 0; i < aGrabBag.getLength(); ++i)
598 : {
599 12 : if (aGrabBag[i].Name == "OOXEmbeddings")
600 : {
601 1 : bEmbeddings = true;
602 1 : uno::Sequence<beans::PropertyValue> aEmbeddingsList(0);
603 2 : uno::Reference<io::XInputStream> aEmbeddingXlsxStream;
604 2 : OUString aEmbeddedfileName;
605 1 : CPPUNIT_ASSERT(aGrabBag[i].Value >>= aEmbeddingsList); // PropertyValue of proper type
606 1 : sal_Int32 length = aEmbeddingsList.getLength();
607 1 : CPPUNIT_ASSERT_EQUAL(sal_Int32(3), length);
608 4 : for(int j = 0; j < length; ++j)
609 : {
610 3 : aEmbeddingsList[j].Value >>= aEmbeddingXlsxStream;
611 3 : aEmbeddedfileName = aEmbeddingsList[j].Name;
612 3 : CPPUNIT_ASSERT(aEmbeddingXlsxStream.get()); // Reference not empty
613 3 : CPPUNIT_ASSERT_EQUAL(OUString::createFromAscii(testEmbeddedFileNames[j]),aEmbeddedfileName);
614 1 : }
615 : }
616 : }
617 2 : CPPUNIT_ASSERT(bEmbeddings); // Grab Bag has all the expected elements
618 1 : }
619 :
620 1 : void Chart2ExportTest::testAreaChartLoad()
621 : {
622 1 : load ("/chart2/qa/extras/data/docx/", "testAreaChartLoad.docx");
623 1 : xmlDocPtr pXmlDoc = parseExport("word/charts/chart","Office Open XML Text");
624 1 : CPPUNIT_ASSERT(pXmlDoc);
625 1 : assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:areaChart/c:ser/c:dLbls/c:showVal", "val", "1");
626 1 : assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:areaChart/c:ser/c:dLbls/c:dLbl", 0);
627 1 : }
628 :
629 1 : void Chart2ExportTest::testUpDownBars()
630 : {
631 : /*
632 : load("/chart2/qa/extras/data/docx/", "UpDownBars.docx");
633 : xmlDocPtr pXmlDoc = parseExport("word/charts/chart", "Office Open XML Text");
634 : CPPUNIT_ASSERT(pXmlDoc);
635 : assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:lineChart/c:upDownBars");
636 : */
637 1 : }
638 :
639 1 : void Chart2ExportTest::testDoughnutChart()
640 : {
641 1 : load("/chart2/qa/extras/data/docx/", "doughnutChart.docx");
642 1 : xmlDocPtr pXmlDoc = parseExport("word/charts/chart", "Office Open XML Text");
643 1 : CPPUNIT_ASSERT(pXmlDoc);
644 :
645 1 : assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:doughnutChart", "1");
646 1 : }
647 :
648 1 : void Chart2ExportTest::testDisplayUnits()
649 : {
650 1 : load("/chart2/qa/extras/data/docx/", "DisplayUnits.docx");
651 1 : xmlDocPtr pXmlDoc = parseExport("word/charts/chart", "Office Open XML Text");
652 1 : CPPUNIT_ASSERT(pXmlDoc);
653 :
654 1 : assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:valAx/c:dispUnits/c:builtInUnit", "val", "billions");
655 1 : }
656 :
657 : // void Chart2ExportTest::testFdo74115WallGradientFill()
658 : // {
659 : // load("/chart2/qa/extras/data/docx/", "fdo74115_WallGradientFill.docx");
660 : // xmlDocPtr pXmlDoc = parseExport("word/charts/chart", "Office Open XML Text");
661 : // CPPUNIT_ASSERT(pXmlDoc);
662 : //
663 : // assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:spPr/a:gradFill");
664 : // }
665 :
666 1 : void Chart2ExportTest::testFdo74115WallBitmapFill()
667 : {
668 1 : load("/chart2/qa/extras/data/docx/", "fdo74115_WallBitmapFill.docx");
669 1 : xmlDocPtr pXmlDoc = parseExport("word/charts/chart", "Office Open XML Text");
670 1 : CPPUNIT_ASSERT(pXmlDoc);
671 1 : assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:spPr/a:blipFill");
672 1 : }
673 :
674 : //The below test case tests the built in marker 'x' for Office 2010 in Line charts
675 :
676 1 : void Chart2ExportTest::testFdo78290LineChartMarkerX()
677 : {
678 1 : load("/chart2/qa/extras/data/docx/", "fdo78290_Line_Chart_Marker_x.docx");
679 1 : xmlDocPtr pXmlDoc = parseExport("word/charts/chart", "Office Open XML Text");
680 1 : CPPUNIT_ASSERT(pXmlDoc);
681 1 : assertXPath(pXmlDoc, "/c:chartSpace[1]/c:chart[1]/c:plotArea[1]/c:lineChart[1]/c:ser[1]/c:marker[1]/c:symbol[1]","val","x");
682 1 : assertXPath(pXmlDoc, "/c:chartSpace[1]/c:chart[1]/c:plotArea[1]/c:lineChart[1]/c:ser[1]/c:marker[1]/c:size[1]","val","7");
683 1 : }
684 :
685 : // We can also use the built in marker 'x' in scatter chart, hence writing the test case for the same.
686 :
687 1 : void Chart2ExportTest::testFdo78290ScatterChartMarkerX()
688 : {
689 1 : load("/chart2/qa/extras/data/docx/", "fdo78290_Scatter_Chart_Marker_x.docx");
690 1 : xmlDocPtr pXmlDoc = parseExport("word/charts/chart", "Office Open XML Text");
691 1 : CPPUNIT_ASSERT(pXmlDoc);
692 1 : assertXPath(pXmlDoc, "/c:chartSpace[1]/c:chart[1]/c:plotArea[1]/c:scatterChart[1]/c:ser[1]/c:marker[1]/c:symbol[1]","val","x");
693 1 : assertXPath(pXmlDoc, "/c:chartSpace[1]/c:chart[1]/c:plotArea[1]/c:scatterChart[1]/c:ser[1]/c:marker[1]/c:size[1]","val","7");
694 1 : }
695 :
696 : // Also in a combination of charts like a column chart and line chart, we can use the built in marker 'x'
697 : // for the line chart too. hence put a test case for the combination chart also.
698 :
699 1 : void Chart2ExportTest::testFdo78290CombinationChartMarkerX()
700 : {
701 1 : load("/chart2/qa/extras/data/docx/", "fdo78290_Combination_Chart_Marker_x.docx");
702 1 : xmlDocPtr pXmlDoc = parseExport("word/charts/chart", "Office Open XML Text");
703 1 : CPPUNIT_ASSERT(pXmlDoc);
704 1 : assertXPath(pXmlDoc, "/c:chartSpace[1]/c:chart[1]/c:plotArea[1]/c:lineChart[1]/c:ser[1]/c:marker[1]/c:symbol[1]","val","x");
705 1 : assertXPath(pXmlDoc, "/c:chartSpace[1]/c:chart[1]/c:plotArea[1]/c:lineChart[1]/c:ser[1]/c:marker[1]/c:size[1]","val","7");
706 1 : }
707 :
708 1 : void Chart2ExportTest::testAxisNumberFormatODS()
709 : {
710 : struct
711 : {
712 2 : void check( const Reference<chart2::XChartDocument>& xChartDoc )
713 : {
714 2 : Reference<chart2::XAxis> xAxisX = getAxisFromDoc(xChartDoc, 0, 0, 0);
715 4 : Reference<chart2::XTitled> xTitle(xAxisX, UNO_QUERY_THROW);
716 4 : OUString aTitleText = getTitleString(xTitle);
717 2 : CPPUNIT_ASSERT_EQUAL(OUString("Linked To Source"), aTitleText);
718 :
719 2 : sal_Int32 nNumFmt = getNumberFormatFromAxis(xAxisX);
720 2 : sal_Int16 nType = getNumberFormatType(xChartDoc, nNumFmt);
721 2 : CPPUNIT_ASSERT_MESSAGE("X axis should be percentage format.", (nType & util::NumberFormat::PERCENT));
722 :
723 2 : bool bNumFmtLinked = false;
724 4 : Reference<beans::XPropertySet> xPS(xAxisX, uno::UNO_QUERY_THROW);
725 2 : xPS->getPropertyValue("LinkNumberFormatToSource") >>= bNumFmtLinked;
726 2 : CPPUNIT_ASSERT_MESSAGE("X axis should have its number format linked to source.", bNumFmtLinked);
727 :
728 4 : Reference<chart2::XAxis> xAxisY = getAxisFromDoc(xChartDoc, 0, 1, 0);
729 2 : xTitle.set(xAxisY, UNO_QUERY_THROW);
730 2 : aTitleText = getTitleString(xTitle);
731 2 : CPPUNIT_ASSERT_EQUAL(OUString("Not Linked"), aTitleText);
732 :
733 2 : nNumFmt = getNumberFormatFromAxis(xAxisY);
734 2 : nType = getNumberFormatType(xChartDoc, nNumFmt);
735 2 : CPPUNIT_ASSERT_MESSAGE("Y axis should be a normal number format.", (nType & util::NumberFormat::NUMBER));
736 :
737 2 : bNumFmtLinked = true;
738 2 : xPS.set(xAxisY, uno::UNO_QUERY_THROW);
739 2 : xPS->getPropertyValue("LinkNumberFormatToSource") >>= bNumFmtLinked;
740 4 : CPPUNIT_ASSERT_MESSAGE("Y axis should not have its number format linked to source.", !bNumFmtLinked);
741 2 : }
742 :
743 : } aTest;
744 :
745 1 : load("/chart2/qa/extras/data/ods/", "axis-numformats-linked.ods");
746 :
747 1 : Reference<chart2::XChartDocument> xChartDoc = getChartDocFromSheet(0, mxComponent);
748 1 : aTest.check(xChartDoc);
749 :
750 : // Reload the document and make sure everything remains intact.
751 1 : reload("calc8");
752 1 : xChartDoc = getChartDocFromSheet(0, mxComponent);
753 1 : aTest.check(xChartDoc);
754 1 : }
755 :
756 1 : void Chart2ExportTest::testDataLabelBordersDOCX()
757 : {
758 : struct Check
759 : {
760 : sal_Int32 mnIndex;
761 : css::drawing::LineStyle meStyle;
762 : sal_Int32 mnColor;
763 : };
764 :
765 : struct
766 : {
767 : /**
768 : * Chart 1 has 4 bars of which 1st and 3rd have labels with borders
769 : * around them.
770 : */
771 2 : void checkObject1( const Reference<chart2::XChartDocument>& xChartDoc )
772 : {
773 2 : CPPUNIT_ASSERT(xChartDoc.is());
774 :
775 2 : Reference<chart2::XDataSeries> xDataSeries = getDataSeriesFromDoc(xChartDoc, 0);
776 2 : CPPUNIT_ASSERT(xDataSeries.is());
777 :
778 : // Check to make sure that data points 0 and 2 have local properties.
779 4 : Reference<beans::XPropertySet> xPropSet(xDataSeries, uno::UNO_QUERY);
780 2 : CPPUNIT_ASSERT(xPropSet.is());
781 :
782 4 : Sequence<sal_Int32> aIndices;
783 2 : xPropSet->getPropertyValue("AttributedDataPoints") >>= aIndices;
784 : /*
785 : CPPUNIT_ASSERT_EQUAL_MESSAGE("There should be 2 data points with local properties.", sal_Int32(2), aIndices.getLength());
786 : CPPUNIT_ASSERT_EQUAL(sal_Int32(0), aIndices[0]);
787 : CPPUNIT_ASSERT_EQUAL(sal_Int32(2), aIndices[1]);
788 : */
789 :
790 : const Check aDataPoints[] =
791 : {
792 : { 0, css::drawing::LineStyle_SOLID, 0x00FFFF00 }, // solid yellow
793 : { 2, css::drawing::LineStyle_SOLID, 0x00FF0000 } // solid red
794 2 : };
795 :
796 6 : for (size_t i = 0, n = SAL_N_ELEMENTS(aDataPoints); i < n; ++i)
797 : {
798 4 : xPropSet = xDataSeries->getDataPointByIndex(aDataPoints[i].mnIndex);
799 4 : CPPUNIT_ASSERT(xPropSet.is());
800 :
801 4 : css::drawing::LineStyle eLineStyle = css::drawing::LineStyle_NONE;
802 4 : xPropSet->getPropertyValue(CHART_UNONAME_LABEL_BORDER_STYLE) >>= eLineStyle;
803 4 : CPPUNIT_ASSERT_EQUAL(aDataPoints[i].meStyle, eLineStyle);
804 :
805 4 : sal_Int32 nWidth = -1;
806 4 : xPropSet->getPropertyValue(CHART_UNONAME_LABEL_BORDER_WIDTH) >>= nWidth;
807 4 : CPPUNIT_ASSERT(nWidth > 0);
808 :
809 4 : sal_Int32 nColor = -1;
810 4 : xPropSet->getPropertyValue(CHART_UNONAME_LABEL_BORDER_COLOR) >>= nColor;
811 4 : CPPUNIT_ASSERT_EQUAL_MESSAGE("Border color is wrong.", aDataPoints[i].mnColor, nColor);
812 2 : }
813 2 : }
814 :
815 : /**
816 : * Chart 2 has all its data labels with identical borders.
817 : */
818 2 : void checkObject2( const Reference<chart2::XChartDocument>& xChartDoc )
819 : {
820 2 : CPPUNIT_ASSERT(xChartDoc.is());
821 :
822 2 : Reference<chart2::XDataSeries> xDataSeries = getDataSeriesFromDoc(xChartDoc, 0);
823 2 : CPPUNIT_ASSERT(xDataSeries.is());
824 :
825 4 : Reference<beans::XPropertySet> xPropSet(xDataSeries, uno::UNO_QUERY);
826 2 : CPPUNIT_ASSERT(xPropSet.is());
827 :
828 2 : css::drawing::LineStyle eLineStyle = css::drawing::LineStyle_NONE;
829 2 : xPropSet->getPropertyValue(CHART_UNONAME_LABEL_BORDER_STYLE) >>= eLineStyle;
830 2 : CPPUNIT_ASSERT_EQUAL(css::drawing::LineStyle_SOLID, eLineStyle);
831 :
832 2 : sal_Int32 nWidth = -1;
833 2 : xPropSet->getPropertyValue(CHART_UNONAME_LABEL_BORDER_WIDTH) >>= nWidth;
834 2 : CPPUNIT_ASSERT(nWidth > 0);
835 :
836 2 : sal_Int32 nColor = -1;
837 2 : xPropSet->getPropertyValue(CHART_UNONAME_LABEL_BORDER_COLOR) >>= nColor;
838 4 : CPPUNIT_ASSERT_EQUAL_MESSAGE("Border color should be green.", sal_Int32(0x0000FF00), nColor);
839 2 : }
840 :
841 : } aTest;
842 :
843 1 : load("/chart2/qa/extras/data/docx/", "data-label-borders.docx");
844 :
845 1 : Reference<chart2::XChartDocument> xChartDoc(getChartDocFromWriter(0), uno::UNO_QUERY);
846 :
847 : // "Automatic" chart background fill in docx should be loaded as solid white.
848 2 : Reference<beans::XPropertySet> xPropSet = xChartDoc->getPageBackground();
849 1 : CPPUNIT_ASSERT(xPropSet.is());
850 1 : drawing::FillStyle eStyle = xPropSet->getPropertyValue("FillStyle").get<drawing::FillStyle>();
851 1 : sal_Int32 nColor = xPropSet->getPropertyValue("FillColor").get<sal_Int32>();
852 2 : CPPUNIT_ASSERT_MESSAGE("'Automatic' chart background fill in docx should be loaded as solid fill.",
853 1 : eStyle == drawing::FillStyle_SOLID);
854 2 : CPPUNIT_ASSERT_MESSAGE("'Automatic' chart background fill in docx should be loaded as solid white.",
855 1 : (nColor & 0x00FFFFFF) == 0x00FFFFFF); // highest 2 bytes are transparency which we ignore here.
856 :
857 1 : aTest.checkObject1(xChartDoc);
858 1 : xChartDoc.set(getChartDocFromWriter(1), uno::UNO_QUERY);
859 1 : aTest.checkObject2(xChartDoc);
860 :
861 1 : reload("Office Open XML Text");
862 :
863 1 : xChartDoc.set(getChartDocFromWriter(0), uno::UNO_QUERY);
864 1 : aTest.checkObject1(xChartDoc);
865 1 : xChartDoc.set(getChartDocFromWriter(1), uno::UNO_QUERY);
866 2 : aTest.checkObject2(xChartDoc);
867 1 : }
868 :
869 1 : void Chart2ExportTest::testDataLabel3DChartDOCX()
870 : {
871 1 : load("/chart2/qa/extras/data/docx/", "3d-bar-label.docx");
872 :
873 1 : Reference<chart2::XChartDocument> xChartDoc(getChartDocFromWriter(0), uno::UNO_QUERY);
874 1 : CPPUNIT_ASSERT(xChartDoc.is());
875 :
876 1 : xmlDocPtr pXmlDoc = parseExport("word/charts/chart","Office Open XML Text");
877 1 : CPPUNIT_ASSERT(pXmlDoc);
878 :
879 : // We must not export label position attributes for 3D bar charts. The
880 : // same rule also applies to several other 3D charts, apparently.
881 1 : assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:bar3DChart/c:ser/c:dLbls/c:dLblPos", 0);
882 1 : assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:bar3DChart/c:ser/c:dLbls/c:dLbl/c:dLblPos", 0);
883 1 : }
884 :
885 1 : void Chart2ExportTest::testDataLabelBarChartDOCX()
886 : {
887 1 : load("/chart2/qa/extras/data/docx/", "bar-chart-labels.docx");
888 :
889 1 : Reference<chart2::XChartDocument> xChartDoc(getChartDocFromWriter(0), uno::UNO_QUERY);
890 1 : CPPUNIT_ASSERT(xChartDoc.is());
891 :
892 1 : xmlDocPtr pXmlDoc = parseExport("word/charts/chart","Office Open XML Text");
893 1 : CPPUNIT_ASSERT(pXmlDoc);
894 :
895 1 : assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:barChart/c:ser[1]/c:dLbls/c:dLblPos", "val", "ctr");
896 1 : assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:barChart/c:ser[2]/c:dLbls/c:dLblPos", "val", "inEnd");
897 1 : assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:barChart/c:ser[3]/c:dLbls/c:dLblPos", "val", "inBase");
898 1 : }
899 :
900 1 : void Chart2ExportTest::testDataLabelClusteredBarChartDOCX()
901 : {
902 1 : load("/chart2/qa/extras/data/docx/", "clustered-bar-chart-labels.docx");
903 :
904 1 : Reference<chart2::XChartDocument> xChartDoc(getChartDocFromWriter(0), uno::UNO_QUERY);
905 1 : CPPUNIT_ASSERT(xChartDoc.is());
906 :
907 1 : xmlDocPtr pXmlDoc = parseExport("word/charts/chart","Office Open XML Text");
908 1 : CPPUNIT_ASSERT(pXmlDoc);
909 :
910 : // This was "t", should be one of the allowed values.
911 1 : assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:barChart/c:ser[1]/c:dLbls/c:dLbl[2]/c:dLblPos", "val", "outEnd");
912 1 : }
913 :
914 1 : void Chart2ExportTest::testDataLabelRadarChartDOCX()
915 : {
916 1 : load("/chart2/qa/extras/data/docx/", "radar-chart-labels.docx");
917 :
918 1 : Reference<chart2::XChartDocument> xChartDoc(getChartDocFromWriter(0), uno::UNO_QUERY);
919 1 : CPPUNIT_ASSERT(xChartDoc.is());
920 :
921 1 : xmlDocPtr pXmlDoc = parseExport("word/charts/chart","Office Open XML Text");
922 1 : CPPUNIT_ASSERT(pXmlDoc);
923 :
924 : // We must not export label position attributes for radar charts.
925 1 : assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:radarChart/c:ser/c:dLbls/c:dLblPos", 0);
926 1 : assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:radarChart/c:ser/c:dLbls/c:dLbl/c:dLblPos", 0);
927 1 : }
928 :
929 1 : void Chart2ExportTest::testDataLabelDoughnutChartDOCX()
930 : {
931 1 : load("/chart2/qa/extras/data/docx/", "doughnut-chart-labels.docx");
932 :
933 1 : Reference<chart2::XChartDocument> xChartDoc(getChartDocFromWriter(0), uno::UNO_QUERY);
934 1 : CPPUNIT_ASSERT(xChartDoc.is());
935 :
936 1 : xmlDocPtr pXmlDoc = parseExport("word/charts/chart","Office Open XML Text");
937 1 : CPPUNIT_ASSERT(pXmlDoc);
938 :
939 : // We must not export label position attributes for doughnut charts.
940 1 : assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:doughnutChart/c:ser/c:dLbls/c:dLblPos", 0);
941 1 : assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:doughnutChart/c:ser/c:dLbls/c:dLbl/c:dLblPos", 0);
942 1 : }
943 :
944 1 : void Chart2ExportTest::testDataLabelAreaChartDOCX()
945 : {
946 1 : load("/chart2/qa/extras/data/docx/", "area-chart-labels.docx");
947 :
948 1 : Reference<chart2::XChartDocument> xChartDoc(getChartDocFromWriter(0), uno::UNO_QUERY);
949 1 : CPPUNIT_ASSERT(xChartDoc.is());
950 :
951 1 : xmlDocPtr pXmlDoc = parseExport("word/charts/chart","Office Open XML Text");
952 1 : CPPUNIT_ASSERT(pXmlDoc);
953 :
954 : // We must not export label position attributes for area charts.
955 1 : assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:areaChart/c:ser/c:dLbls/c:dLblPos", 0);
956 1 : assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:areaChart/c:ser/c:dLbls/c:dLbl/c:dLblPos", 0);
957 1 : }
958 :
959 1 : void Chart2ExportTest::testDataLabelDefaultLineChartDOCX()
960 : {
961 : // This file was created by Word 2007, which doesn't provide default data
962 : // label position (2010 does). Make sure its default data label position
963 : // is RIGHT when exporting.
964 :
965 1 : load("/chart2/qa/extras/data/docx/", "line-chart-label-default-placement.docx");
966 :
967 1 : Reference<chart2::XChartDocument> xChartDoc(getChartDocFromWriter(0), uno::UNO_QUERY);
968 1 : CPPUNIT_ASSERT(xChartDoc.is());
969 :
970 1 : reload("Office Open XML Text");
971 :
972 1 : xChartDoc.set(getChartDocFromWriter(0), uno::UNO_QUERY);
973 2 : Reference<chart2::XDataSeries> xDataSeries = getDataSeriesFromDoc(xChartDoc, 0);
974 2 : Reference<beans::XPropertySet> xPropSet(xDataSeries, uno::UNO_QUERY);
975 1 : CPPUNIT_ASSERT(xPropSet.is());
976 1 : sal_Int32 nLabelPlacement = -1;
977 1 : if (xPropSet->getPropertyValue("LabelPlacement") >>= nLabelPlacement)
978 : // This option may not be set. Check its value only when it's set.
979 2 : CPPUNIT_ASSERT_MESSAGE("Line chart's default label placement should be 'right'.", nLabelPlacement == chart::DataLabelPlacement::RIGHT);
980 1 : }
981 :
982 1 : void Chart2ExportTest::testBarChartRotation()
983 : {
984 1 : load ("/chart2/qa/extras/data/docx/", "barChartRotation.docx");
985 1 : xmlDocPtr pXmlDoc = parseExport("word/charts/chart","Office Open XML Text");
986 1 : CPPUNIT_ASSERT(pXmlDoc);
987 :
988 1 : assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:view3D/c:rotX", "val", "30");
989 1 : assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:view3D/c:rotY", "val", "50");
990 1 : }
991 :
992 1 : void Chart2ExportTest::testShapeFollowedByChart()
993 : {
994 : /* If there is a scenario where a chart is followed by a shape
995 : which is being exported as an alternate content then, the
996 : docPr Id is being repeated, ECMA 20.4.2.5 says that the
997 : docPr Id should be unique, ensuring the same here.
998 : */
999 1 : load("/chart2/qa/extras/data/docx/", "FDO74430.docx");
1000 1 : xmlDocPtr pXmlDoc = parseExport("word/document", "Office Open XML Text" );
1001 1 : CPPUNIT_ASSERT(pXmlDoc);
1002 :
1003 1 : OUString aValueOfFirstDocPR = getXPath(pXmlDoc, "/w:document/w:body/w:p[3]/w:r[1]/w:drawing[1]/wp:inline[1]/wp:docPr[1]", "id");
1004 2 : OUString aValueOfSecondDocPR;
1005 :
1006 1 : 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");
1007 :
1008 2 : CPPUNIT_ASSERT( aValueOfFirstDocPR != aValueOfSecondDocPR );
1009 1 : }
1010 :
1011 1 : void Chart2ExportTest::testPieChartDataLabels()
1012 : {
1013 1 : load("/chart2/qa/extras/data/docx/", "PieChartDataLabels.docx");
1014 1 : xmlDocPtr pXmlDoc = parseExport("word/charts/chart", "Office Open XML Text");
1015 1 : CPPUNIT_ASSERT(pXmlDoc);
1016 1 : assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:pie3DChart/c:ser[1]/c:dLbls/c:dLbl[1]/c:dLblPos", "val", "bestFit");
1017 1 : }
1018 :
1019 1 : void Chart2ExportTest::testSeriesIdxOrder()
1020 : {
1021 1 : load("/chart2/qa/extras/data/docx/", "testSeriesIdxOrder.docx");
1022 1 : xmlDocPtr pXmlDoc = parseExport("word/charts/chart", "Office Open XML Text");
1023 1 : CPPUNIT_ASSERT(pXmlDoc);
1024 1 : assertXPath(pXmlDoc, "/c:chartSpace[1]/c:chart[1]/c:plotArea[1]/c:lineChart[1]/c:ser[1]/c:idx[1]", "val", "1");
1025 1 : assertXPath(pXmlDoc, "/c:chartSpace[1]/c:chart[1]/c:plotArea[1]/c:lineChart[1]/c:ser[1]/c:order[1]", "val", "1");
1026 1 : }
1027 :
1028 1 : void Chart2ExportTest::testScatterPlotLabels()
1029 : {
1030 1 : load("/chart2/qa/extras/data/odt/", "scatter-plot-labels.odt");
1031 1 : Reference<chart2::XChartDocument> xChartDoc(getChartDocFromWriter(0), uno::UNO_QUERY);
1032 1 : CPPUNIT_ASSERT(xChartDoc.is());
1033 :
1034 2 : Reference<chart2::XChartType> xCT = getChartTypeFromDoc(xChartDoc, 0, 0);
1035 1 : CPPUNIT_ASSERT(xCT.is());
1036 :
1037 : // Make sure the original chart has 'a', 'b', 'c' as its data labels.
1038 2 : std::vector<uno::Sequence<uno::Any> > aLabels = getDataSeriesLabelsFromChartType(xCT);
1039 1 : CPPUNIT_ASSERT_EQUAL(size_t(3), aLabels.size());
1040 1 : CPPUNIT_ASSERT_EQUAL(OUString("a"), aLabels[0][0].get<OUString>());
1041 1 : CPPUNIT_ASSERT_EQUAL(OUString("b"), aLabels[1][0].get<OUString>());
1042 1 : CPPUNIT_ASSERT_EQUAL(OUString("c"), aLabels[2][0].get<OUString>());
1043 :
1044 : // Reload the doc and check again. The labels should not change.
1045 1 : reload("writer8");
1046 :
1047 1 : xChartDoc.set(getChartDocFromWriter(0), uno::UNO_QUERY);
1048 1 : CPPUNIT_ASSERT(xChartDoc.is());
1049 :
1050 1 : xCT = getChartTypeFromDoc(xChartDoc, 0, 0);
1051 1 : CPPUNIT_ASSERT(xCT.is());
1052 :
1053 1 : aLabels = getDataSeriesLabelsFromChartType(xCT);
1054 1 : CPPUNIT_ASSERT_EQUAL(size_t(3), aLabels.size());
1055 1 : CPPUNIT_ASSERT_EQUAL(OUString("a"), aLabels[0][0].get<OUString>());
1056 1 : CPPUNIT_ASSERT_EQUAL(OUString("b"), aLabels[1][0].get<OUString>());
1057 2 : CPPUNIT_ASSERT_EQUAL(OUString("c"), aLabels[2][0].get<OUString>());
1058 1 : }
1059 :
1060 1 : void Chart2ExportTest::testErrorBarDataRangeODS()
1061 : {
1062 1 : load("/chart2/qa/extras/data/ods/", "ErrorBarRange.ods");
1063 1 : reload("calc8");
1064 :
1065 1 : uno::Reference< chart2::XChartDocument > xChartDoc = getChartDocFromSheet( 0, mxComponent );
1066 1 : CPPUNIT_ASSERT(xChartDoc.is());
1067 :
1068 2 : Reference< chart2::XDataSeries > xDataSeries = getDataSeriesFromDoc( xChartDoc, 0 );
1069 1 : CPPUNIT_ASSERT( xDataSeries.is() );
1070 :
1071 2 : Reference< beans::XPropertySet > xPropSet( xDataSeries, UNO_QUERY_THROW );
1072 1 : CPPUNIT_ASSERT( xPropSet.is() );
1073 :
1074 : // test that y error bars are there
1075 2 : Reference< beans::XPropertySet > xErrorBarYProps;
1076 1 : xPropSet->getPropertyValue(CHART_UNONAME_ERRORBAR_Y) >>= xErrorBarYProps;
1077 2 : uno::Any aAny = xErrorBarYProps->getPropertyValue("ErrorBarRangePositive");
1078 1 : CPPUNIT_ASSERT(aAny.hasValue());
1079 2 : OUString aPosRange;
1080 1 : aAny >>= aPosRange;
1081 1 : CPPUNIT_ASSERT_EQUAL(OUString("$Sheet1.$B$1:$B$3"), aPosRange);
1082 :
1083 1 : aAny = xErrorBarYProps->getPropertyValue("ErrorBarRangeNegative");
1084 1 : CPPUNIT_ASSERT(aAny.hasValue());
1085 2 : OUString aNegRange;
1086 1 : aAny >>= aNegRange;
1087 2 : CPPUNIT_ASSERT_EQUAL(OUString("$Sheet1.$C$1:$C$3"), aNegRange);
1088 1 : }
1089 :
1090 1 : void Chart2ExportTest::testChartCrash()
1091 : {
1092 1 : load("/chart2/qa/extras/data/docx/", "FDO75975.docx");
1093 1 : xmlDocPtr pXmlDoc = parseExport("word/charts/chart", "Office Open XML Text");
1094 1 : CPPUNIT_ASSERT(pXmlDoc);
1095 1 : }
1096 :
1097 1 : void Chart2ExportTest::testPieChartRotation()
1098 : {
1099 1 : load ("/chart2/qa/extras/data/docx/", "pieChartRotation.docx");
1100 1 : xmlDocPtr pXmlDoc = parseExport("word/charts/chart","Office Open XML Text");
1101 1 : CPPUNIT_ASSERT(pXmlDoc);
1102 1 : assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:view3D/c:rotX", "val", "40");
1103 1 : assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:view3D/c:rotY", "val", "30");
1104 1 : }
1105 :
1106 1 : void Chart2ExportTest::testEmbeddingsOleObjectGrabBag()
1107 : {
1108 : // The problem was that .bin files were missing from docx file from embeddings folder
1109 : // after saving file.
1110 : // This test case tests whether embeddings files grabbagged properly in correct object.
1111 :
1112 1 : load("/chart2/qa/extras/data/docx/", "testchartoleobjectembeddings.docx" );
1113 1 : uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY);
1114 2 : uno::Reference<beans::XPropertySet> xTextDocumentPropertySet(xTextDocument, uno::UNO_QUERY);
1115 2 : uno::Sequence<beans::PropertyValue> aGrabBag(0);
1116 1 : xTextDocumentPropertySet->getPropertyValue(OUString("InteropGrabBag")) >>= aGrabBag;
1117 1 : CPPUNIT_ASSERT(aGrabBag.hasElements()); // Grab Bag not empty
1118 1 : bool bEmbeddings = false;
1119 1 : const char* testEmbeddedFileNames[1] = {"word/embeddings/oleObject1.bin"};
1120 13 : for(int i = 0; i < aGrabBag.getLength(); ++i)
1121 : {
1122 12 : if (aGrabBag[i].Name == "OOXEmbeddings")
1123 : {
1124 1 : bEmbeddings = true;
1125 1 : uno::Sequence<beans::PropertyValue> aEmbeddingsList(0);
1126 2 : uno::Reference<io::XInputStream> aEmbeddingXlsxStream;
1127 2 : OUString aEmbeddedfileName;
1128 1 : CPPUNIT_ASSERT(aGrabBag[i].Value >>= aEmbeddingsList); // PropertyValue of proper type
1129 1 : sal_Int32 length = aEmbeddingsList.getLength();
1130 1 : CPPUNIT_ASSERT_EQUAL(sal_Int32(1), length);
1131 2 : for(int j = 0; j < length; ++j)
1132 : {
1133 1 : aEmbeddingsList[j].Value >>= aEmbeddingXlsxStream;
1134 1 : aEmbeddedfileName = aEmbeddingsList[j].Name;
1135 1 : CPPUNIT_ASSERT(aEmbeddingXlsxStream.get()); // Reference not empty
1136 1 : CPPUNIT_ASSERT_EQUAL(OUString::createFromAscii(testEmbeddedFileNames[j]),aEmbeddedfileName);
1137 1 : }
1138 : }
1139 : }
1140 2 : CPPUNIT_ASSERT(bEmbeddings); // Grab Bag has all the expected elements
1141 1 : }
1142 :
1143 : namespace {
1144 :
1145 4 : void checkGapWidth(Reference<beans::XPropertySet> xPropSet, sal_Int32 nValue)
1146 : {
1147 4 : uno::Any aAny = xPropSet->getPropertyValue("GapwidthSequence");
1148 4 : CPPUNIT_ASSERT(aAny.hasValue());
1149 8 : uno::Sequence< sal_Int32 > aSequence;
1150 4 : aAny >>= aSequence;
1151 4 : CPPUNIT_ASSERT(aSequence.getLength());
1152 8 : CPPUNIT_ASSERT_EQUAL(nValue, aSequence[0]);
1153 4 : }
1154 :
1155 4 : void checkOverlap(Reference<beans::XPropertySet> xPropSet, sal_Int32 nValue)
1156 : {
1157 4 : uno::Any aAny = xPropSet->getPropertyValue("OverlapSequence");
1158 4 : CPPUNIT_ASSERT(aAny.hasValue());
1159 8 : uno::Sequence< sal_Int32 > aSequence;
1160 4 : aAny >>= aSequence;
1161 4 : CPPUNIT_ASSERT(aSequence.getLength());
1162 8 : CPPUNIT_ASSERT_EQUAL(nValue, aSequence[0]);
1163 4 : }
1164 :
1165 4 : void checkSheetForGapWidthAndOverlap(uno::Reference< chart2::XChartDocument > xChartDoc,
1166 : sal_Int32 nExpectedGapWidth, sal_Int32 nExpectedOverlap)
1167 : {
1168 4 : CPPUNIT_ASSERT(xChartDoc.is());
1169 :
1170 4 : Reference< chart2::XChartType > xChartType = getChartTypeFromDoc( xChartDoc, 0, 0 );
1171 4 : CPPUNIT_ASSERT(xChartType.is());
1172 :
1173 8 : Reference< beans::XPropertySet > xPropSet( xChartType, uno::UNO_QUERY_THROW );
1174 4 : checkGapWidth(xPropSet, nExpectedGapWidth);
1175 8 : checkOverlap(xPropSet, nExpectedOverlap);
1176 :
1177 4 : }
1178 :
1179 : }
1180 :
1181 1 : void Chart2ExportTest::testGapWidthXLSX()
1182 : {
1183 1 : load("/chart2/qa/extras/data/xlsx/", "gapWidth.xlsx");
1184 :
1185 1 : uno::Reference< chart2::XChartDocument > xChartDoc = getChartDocFromSheet( 0, mxComponent );
1186 1 : checkSheetForGapWidthAndOverlap(xChartDoc, 120, -60);
1187 :
1188 1 : xChartDoc = getChartDocFromSheet( 1, mxComponent );
1189 1 : checkSheetForGapWidthAndOverlap(xChartDoc, 50, 30);
1190 :
1191 1 : reload("Calc Office Open XML");
1192 :
1193 1 : xChartDoc = getChartDocFromSheet( 0, mxComponent );
1194 1 : checkSheetForGapWidthAndOverlap(xChartDoc, 120, -60);
1195 :
1196 1 : xChartDoc = getChartDocFromSheet( 1, mxComponent );
1197 1 : checkSheetForGapWidthAndOverlap(xChartDoc, 50, 30);
1198 1 : }
1199 :
1200 1 : void Chart2ExportTest::testSmoothedLines()
1201 : {
1202 1 : load("/chart2/qa/extras/data/ods/", "smoothedLines.ods");
1203 1 : xmlDocPtr pXmlDoc = parseExport("xl/charts/chart", "Calc Office Open XML");
1204 1 : CPPUNIT_ASSERT(pXmlDoc);
1205 1 : assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:lineChart/c:ser[1]/c:smooth", "val", "0");
1206 1 : }
1207 :
1208 1 : void Chart2ExportTest::testLabelStringODS()
1209 : {
1210 1 : load("/chart2/qa/extras/data/ods/", "labelString.ods");
1211 :
1212 1 : uno::Reference< chart2::XChartDocument > xChartDoc = getChartDocFromSheet( 0, mxComponent );
1213 : Reference< chart2::data::XDataSequence > xLabelSeq =
1214 2 : getLabelDataSequenceFromDoc(xChartDoc);
1215 1 : CPPUNIT_ASSERT(xLabelSeq.is());
1216 :
1217 2 : OUString aLabelString = xLabelSeq->getSourceRangeRepresentation();
1218 1 : CPPUNIT_ASSERT_EQUAL(OUString("\"LabelName\""), aLabelString);
1219 :
1220 1 : reload("calc8");
1221 :
1222 1 : xChartDoc = getChartDocFromSheet( 0, mxComponent );
1223 1 : xLabelSeq = getLabelDataSequenceFromDoc(xChartDoc);
1224 1 : CPPUNIT_ASSERT(xLabelSeq.is());
1225 :
1226 1 : aLabelString = xLabelSeq->getSourceRangeRepresentation();
1227 2 : CPPUNIT_ASSERT_EQUAL(OUString("\"LabelName\""), aLabelString);
1228 1 : }
1229 :
1230 1 : void Chart2ExportTest::testFdo83058dlblPos()
1231 : {
1232 1 : load ("/chart2/qa/extras/data/docx/", "fdo83058_dlblPos.docx");
1233 1 : xmlDocPtr pXmlDoc = parseExport("word/charts/chart","Office Open XML Text");
1234 1 : CPPUNIT_ASSERT(pXmlDoc);
1235 1 : assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:barChart/c:ser[1]/c:dLbls[1]/c:dLbl[2]/c:dLblPos", "val", "outEnd");
1236 1 : assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:barChart/c:ser[1]/c:dLbls[1]/c:dLbl[3]/c:dLblPos", "val", "outEnd");
1237 1 : assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:barChart/c:ser[1]/c:dLbls[1]/c:dLbl[4]/c:dLblPos", "val", "outEnd");
1238 1 : assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:barChart/c:ser[1]/c:dLbls[1]/c:dLbl[5]/c:dLblPos", "val", "outEnd");
1239 1 : }
1240 :
1241 1 : void Chart2ExportTest::testAutoTitleDelXLSX()
1242 : {
1243 1 : load("/chart2/qa/extras/data/xlsx/", "autotitledel_2007.xlsx");
1244 1 : xmlDocPtr pXmlDoc = parseExport("xl/charts/chart","Calc Office Open XML");
1245 1 : CPPUNIT_ASSERT(pXmlDoc);
1246 1 : assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:autoTitleDeleted", "val", "0");
1247 1 : }
1248 :
1249 1 : void Chart2ExportTest::testDispBlanksAsXLSX()
1250 : {
1251 1 : load("/chart2/qa/extras/data/xlsx/", "dispBlanksAs_2007.xlsx");
1252 1 : xmlDocPtr pXmlDoc = parseExport("xl/charts/chart","Calc Office Open XML");
1253 1 : CPPUNIT_ASSERT(pXmlDoc);
1254 1 : assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:dispBlanksAs", "val", "gap");
1255 1 : }
1256 :
1257 1 : void Chart2ExportTest::testMarkerColorXLSX()
1258 : {
1259 1 : load("/chart2/qa/extras/data/xlsx/", "markerColor.xlsx");
1260 1 : xmlDocPtr pXmlDoc = parseExport("xl/charts/chart", "Calc Office Open XML");
1261 1 : CPPUNIT_ASSERT(pXmlDoc);
1262 1 : assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:scatterChart/c:ser/c:marker/c:spPr/a:solidFill/a:srgbClr", "val", "92d050");
1263 1 : }
1264 :
1265 1 : void Chart2ExportTest::testRoundedCornersXLSX()
1266 : {
1267 1 : load("/chart2/qa/extras/data/xlsx/", "markerColor.xlsx");
1268 1 : xmlDocPtr pXmlDoc = parseExport("xl/charts/chart", "Calc Office Open XML");
1269 1 : CPPUNIT_ASSERT(pXmlDoc);
1270 1 : assertXPath(pXmlDoc, "/c:chartSpace/c:roundedCorners", "val", "0");
1271 1 : }
1272 :
1273 1 : void Chart2ExportTest::testAxisNumberFormatXLSX()
1274 : {
1275 1 : load("/chart2/qa/extras/data/ods/", "axis_number_format.ods");
1276 1 : xmlDocPtr pXmlDoc = parseExport("xl/charts/chart", "Calc Office Open XML");
1277 1 : CPPUNIT_ASSERT(pXmlDoc);
1278 1 : assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:valAx", 2);
1279 1 : assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:valAx[1]/c:numFmt", "formatCode", "0.00E+000");
1280 1 : assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:valAx[1]/c:numFmt", "sourceLinked", "0");
1281 :
1282 1 : assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:valAx[2]/c:numFmt", "formatCode", "[$$-409]#,##0;-[$$-409]#,##0");
1283 1 : assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:valAx[2]/c:numFmt", "sourceLinked", "1");
1284 1 : }
1285 :
1286 1 : void Chart2ExportTest::testDataLabelDefaultValuesXLSX()
1287 : {
1288 1 : load("/chart2/qa/extras/data/xlsx/", "data_label.xlsx");
1289 1 : Reference< chart2::XChartDocument> xDoc = getChartDocFromSheet(0, mxComponent);
1290 2 : Reference<chart2::XDataSeries> xSeries = getDataSeriesFromDoc(xDoc, 0);
1291 2 : Reference<beans::XPropertySet> xPropSet(xSeries, uno::UNO_QUERY_THROW);
1292 2 : uno::Any aAny = xPropSet->getPropertyValue("Label");
1293 1 : chart2::DataPointLabel aLabel;
1294 1 : CPPUNIT_ASSERT(aAny >>= aLabel);
1295 1 : CPPUNIT_ASSERT(aLabel.ShowNumber);
1296 :
1297 1 : xmlDocPtr pXmlDoc = parseExport("xl/charts/chart", "Calc Office Open XML");
1298 1 : CPPUNIT_ASSERT(pXmlDoc);
1299 1 : assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:barChart/c:ser/c:dLbls/c:showVal", "val", "1");
1300 2 : assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:barChart/c:ser/c:dLbls/c:dLblPos", "val", "outEnd");
1301 1 : }
1302 :
1303 1 : void Chart2ExportTest::testTitleOverlayXLSX()
1304 : {
1305 1 : load("/chart2/qa/extras/data/xlsx/", "chart_title.xlsx");
1306 1 : xmlDocPtr pXmlDoc = parseExport("xl/charts/chart", "Calc Office Open XML");
1307 1 : CPPUNIT_ASSERT(pXmlDoc);
1308 1 : assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:title/c:overlay", "val", "0");
1309 1 : }
1310 :
1311 1 : void Chart2ExportTest::testInvertIfNegativeXLSX()
1312 : {
1313 1 : load("/chart2/qa/extras/data/xlsx/", "bar_chart_simple.xlsx");
1314 1 : xmlDocPtr pXmlDoc = parseExport("xl/charts/chart", "Calc Office Open XML");
1315 1 : CPPUNIT_ASSERT(pXmlDoc);
1316 1 : assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:barChart/c:ser/c:invertIfNegative", "val", "0");
1317 1 : }
1318 :
1319 1 : void Chart2ExportTest::testBubble3DXLSX()
1320 : {
1321 1 : load("/chart2/qa/extras/data/xlsx/", "bubble_chart_simple.xlsx");
1322 1 : xmlDocPtr pXmlDoc = parseExport("xl/charts/chart", "Calc Office Open XML");
1323 1 : CPPUNIT_ASSERT(pXmlDoc);
1324 1 : assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:bubbleChart/c:bubble3D", "val", "0");
1325 1 : }
1326 :
1327 1 : void Chart2ExportTest::testNoMarkerXLSX()
1328 : {
1329 1 : load("/chart2/qa/extras/data/xlsx/", "no_marker.xlsx");
1330 1 : xmlDocPtr pXmlDoc = parseExport("xl/charts/chart", "Calc Office Open XML");
1331 1 : CPPUNIT_ASSERT(pXmlDoc);
1332 1 : assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:lineChart/c:ser[1]/c:marker/c:symbol", "val", "none");
1333 1 : assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:lineChart/c:ser[2]/c:marker/c:symbol", "val", "none");
1334 1 : assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:lineChart/c:marker", "val", "0");
1335 1 : }
1336 :
1337 1 : void Chart2ExportTest::testTitleManualLayoutXLSX()
1338 : {
1339 1 : load("/chart2/qa/extras/data/xlsx/", "title_manual_layout.xlsx");
1340 1 : xmlDocPtr pXmlDoc = parseExport("xl/charts/chart", "Calc Office Open XML");
1341 1 : CPPUNIT_ASSERT(pXmlDoc);
1342 1 : assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:title/c:layout/c:manualLayout/c:xMode", "val", "edge");
1343 1 : assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:title/c:layout/c:manualLayout/c:yMode", "val", "edge");
1344 :
1345 1 : OUString aXVal = getXPath(pXmlDoc, "/c:chartSpace/c:chart/c:title/c:layout/c:manualLayout/c:x", "val");
1346 1 : double nX = aXVal.toDouble();
1347 1 : CPPUNIT_ASSERT(nX > 0 && nX < 1);
1348 :
1349 2 : OUString aYVal = getXPath(pXmlDoc, "/c:chartSpace/c:chart/c:title/c:layout/c:manualLayout/c:y", "val");
1350 1 : double nY = aYVal.toDouble();
1351 1 : CPPUNIT_ASSERT(nY > 0 && nY < 1);
1352 1 : CPPUNIT_ASSERT(nX != nY);
1353 :
1354 2 : assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:title/c:tx/c:rich/a:bodyPr", "rot", "1200000");
1355 1 : }
1356 :
1357 1 : void Chart2ExportTest::testPlotAreaManualLayoutXLSX()
1358 : {
1359 1 : load("/chart2/qa/extras/data/xlsx/", "plot_area_manual_layout.xlsx");
1360 1 : xmlDocPtr pXmlDoc = parseExport("xl/charts/chart", "Calc Office Open XML");
1361 1 : CPPUNIT_ASSERT(pXmlDoc);
1362 :
1363 1 : assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:layout/c:manualLayout/c:xMode", "val", "edge");
1364 1 : assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:layout/c:manualLayout/c:yMode", "val", "edge");
1365 :
1366 1 : OUString aXVal = getXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:layout/c:manualLayout/c:x", "val");
1367 1 : double nX = aXVal.toDouble();
1368 1 : CPPUNIT_ASSERT(nX > 0 && nX < 1);
1369 :
1370 2 : OUString aYVal = getXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:layout/c:manualLayout/c:y", "val");
1371 1 : double nY = aYVal.toDouble();
1372 1 : CPPUNIT_ASSERT(nY > 0 && nY < 1);
1373 1 : CPPUNIT_ASSERT(nX != nY);
1374 :
1375 2 : OUString aWVal = getXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:layout/c:manualLayout/c:w", "val");
1376 1 : double nW = aWVal.toDouble();
1377 1 : CPPUNIT_ASSERT(nW > 0 && nW < 1);
1378 :
1379 2 : OUString aHVal = getXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:layout/c:manualLayout/c:h", "val");
1380 1 : double nH = aHVal.toDouble();
1381 1 : CPPUNIT_ASSERT(nH > 0 && nH < 1);
1382 2 : CPPUNIT_ASSERT(nH != nW);
1383 1 : }
1384 :
1385 1 : void Chart2ExportTest::testLegendManualLayoutXLSX()
1386 : {
1387 1 : load("/chart2/qa/extras/data/xlsx/", "legend_manual_layout.xlsx");
1388 1 : xmlDocPtr pXmlDoc = parseExport("xl/charts/chart", "Calc Office Open XML");
1389 1 : CPPUNIT_ASSERT(pXmlDoc);
1390 :
1391 1 : assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:legend/c:layout/c:manualLayout/c:xMode", "val", "edge");
1392 1 : assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:legend/c:layout/c:manualLayout/c:yMode", "val", "edge");
1393 :
1394 1 : OUString aXVal = getXPath(pXmlDoc, "/c:chartSpace/c:chart/c:legend/c:layout/c:manualLayout/c:x", "val");
1395 1 : double nX = aXVal.toDouble();
1396 1 : CPPUNIT_ASSERT(nX > 0 && nX < 1);
1397 :
1398 2 : OUString aYVal = getXPath(pXmlDoc, "/c:chartSpace/c:chart/c:legend/c:layout/c:manualLayout/c:y", "val");
1399 1 : double nY = aYVal.toDouble();
1400 1 : CPPUNIT_ASSERT(nY > 0 && nY < 1);
1401 2 : CPPUNIT_ASSERT(nX != nY);
1402 1 : }
1403 :
1404 1 : void Chart2ExportTest::testAxisCharacterPropertiesXLSX()
1405 : {
1406 1 : load("/chart2/qa/extras/data/xlsx/", "axis_character_properties.xlsx");
1407 1 : xmlDocPtr pXmlDoc = parseExport("xl/charts/chart", "Calc Office Open XML");
1408 1 : CPPUNIT_ASSERT(pXmlDoc);
1409 :
1410 1 : assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:catAx/c:txPr/a:p/a:pPr/a:defRPr", "sz", "1000");
1411 1 : assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:catAx/c:txPr/a:p/a:pPr/a:defRPr", "b", "1");
1412 1 : assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:catAx/c:txPr/a:p/a:pPr/a:defRPr", "i", "1");
1413 1 : assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:catAx/c:txPr/a:p/a:pPr/a:defRPr", "u", "sng");
1414 :
1415 1 : assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:valAx/c:txPr/a:p/a:pPr/a:defRPr", "sz", "900");
1416 1 : assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:valAx/c:txPr/a:p/a:pPr/a:defRPr", "b", "1");
1417 1 : assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:valAx/c:txPr/a:p/a:pPr/a:defRPr", "strike", "sngStrike");
1418 1 : assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:valAx/c:txPr/a:p/a:pPr/a:defRPr/a:solidFill/a:srgbClr", "val", "ff0000");
1419 1 : }
1420 :
1421 1 : void Chart2ExportTest::testTitleCharacterPropertiesXLSX()
1422 : {
1423 1 : load("/chart2/qa/extras/data/xlsx/", "title_character_properties.xlsx");
1424 1 : xmlDocPtr pXmlDoc = parseExport("xl/charts/chart", "Calc Office Open XML");
1425 1 : CPPUNIT_ASSERT(pXmlDoc);
1426 :
1427 1 : assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:title/c:tx/c:rich/a:p/a:pPr/a:defRPr", "sz", "2400");
1428 1 : assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:title/c:tx/c:rich/a:p/a:pPr/a:defRPr", "b", "1");
1429 :
1430 1 : assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:title/c:tx/c:rich/a:p/a:r/a:rPr", "sz", "2400");
1431 1 : assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:title/c:tx/c:rich/a:p/a:r/a:rPr", "b", "1");
1432 1 : }
1433 :
1434 1 : void Chart2ExportTest::testPlotVisOnlyXLSX()
1435 : {
1436 1 : load("/chart2/qa/extras/data/xlsx/", "hidden_cells.xlsx");
1437 1 : xmlDocPtr pXmlDoc = parseExport("xl/charts/chart", "Calc Office Open XML");
1438 1 : CPPUNIT_ASSERT(pXmlDoc);
1439 :
1440 1 : assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotVisOnly", "val", "0");
1441 1 : }
1442 :
1443 1 : void Chart2ExportTest::testBarChartVaryColorsXLSX()
1444 : {
1445 1 : load("/chart2/qa/extras/data/xlsx/", "tdf90876.xlsx");
1446 1 : xmlDocPtr pXmlDoc = parseExport("xl/charts/chart", "Calc Office Open XML");
1447 1 : CPPUNIT_ASSERT(pXmlDoc);
1448 :
1449 1 : assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:barChart/c:varyColors", "val", "0");
1450 1 : }
1451 :
1452 1 : void Chart2ExportTest::testMultipleAxisXLSX()
1453 : {
1454 1 : load("/chart2/qa/extras/data/ods/", "multiple_axis.ods");
1455 1 : xmlDocPtr pXmlDoc = parseExport("xl/charts/chart", "Calc Office Open XML");
1456 1 : CPPUNIT_ASSERT(pXmlDoc);
1457 :
1458 1 : assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:scatterChart", 2);
1459 1 : assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:scatterChart[1]/c:ser", 1);
1460 1 : assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:scatterChart[2]/c:ser", 1);
1461 1 : assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:valAx", 4);
1462 1 : assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:valAx/c:delete[@val='1']", 1);
1463 1 : assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:valAx/c:axPos[@val='l']", 1);
1464 1 : assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:valAx/c:axPos[@val='r']", 1);
1465 1 : }
1466 :
1467 1 : void Chart2ExportTest::testAxisTitleRotationXLSX()
1468 : {
1469 1 : load("/chart2/qa/extras/data/xlsx/", "axis_title_rotation.xlsx");
1470 1 : xmlDocPtr pXmlDoc = parseExport("xl/charts/chart", "Calc Office Open XML");
1471 1 : CPPUNIT_ASSERT(pXmlDoc);
1472 :
1473 1 : assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:valAx/c:title/c:tx/c:rich/a:bodyPr", "rot", "0");
1474 1 : }
1475 :
1476 1 : CPPUNIT_TEST_SUITE_REGISTRATION(Chart2ExportTest);
1477 :
1478 4 : CPPUNIT_PLUGIN_IMPLEMENT();
1479 :
1480 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|