Avoid potential negative array index access to cached text.
[LibreOffice.git] / chart2 / qa / extras / chart2geometry.cxx
blobc7de713df1b24132c5c823a34c3f2a0e488cee7f
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 <test/xmltesttools.hxx>
14 #include <com/sun/star/chart2/XChartDocument.hpp>
15 #include <com/sun/star/chart2/XDataSeries.hpp>
16 #include <com/sun/star/drawing/FillStyle.hpp>
17 #include <com/sun/star/drawing/LineStyle.hpp>
19 #include <unotools/saveopt.hxx>
21 #include <string_view>
23 using uno::Reference;
24 using beans::XPropertySet;
26 class Chart2GeometryTest : public ChartTest
28 public:
29 Chart2GeometryTest()
30 : ChartTest("/chart2/qa/extras/data/")
33 // Mostly tests for line and fill properties
34 void testTdf135184RoundLineCap();
35 void testTdf135184RoundLineCap2();
36 void testTdf135184RoundLineCap3();
37 void testTdf135184RoundLineCap4();
38 void testTdf128345ChartArea_CG_TS_export();
39 void testTdf128345ChartArea_CG_TS_import();
40 void testTdf128345ChartWall_CS_TG_export();
41 void testTdf128345ChartWall_CS_TG_import();
42 void testTdf128345Legend_CS_TG_axial_export();
43 void testTdf128345Legend_CS_TG_axial_import();
44 void testTdf135366LabelOnSeries();
45 void testTdf135366LabelOnPoint();
46 void testTdf135366LabelExport();
47 void testTdf135366_CustomLabelText();
49 CPPUNIT_TEST_SUITE(Chart2GeometryTest);
50 CPPUNIT_TEST(testTdf135184RoundLineCap);
51 CPPUNIT_TEST(testTdf135184RoundLineCap2);
52 CPPUNIT_TEST(testTdf135184RoundLineCap3);
53 CPPUNIT_TEST(testTdf135184RoundLineCap4);
54 CPPUNIT_TEST(testTdf128345ChartArea_CG_TS_export);
55 CPPUNIT_TEST(testTdf128345ChartArea_CG_TS_import);
56 CPPUNIT_TEST(testTdf128345ChartWall_CS_TG_export);
57 CPPUNIT_TEST(testTdf128345ChartWall_CS_TG_import);
58 CPPUNIT_TEST(testTdf128345Legend_CS_TG_axial_export);
59 CPPUNIT_TEST(testTdf128345Legend_CS_TG_axial_import);
60 CPPUNIT_TEST(testTdf135366LabelOnSeries);
61 CPPUNIT_TEST(testTdf135366LabelOnPoint);
62 CPPUNIT_TEST(testTdf135366LabelExport);
63 CPPUNIT_TEST(testTdf135366_CustomLabelText);
65 CPPUNIT_TEST_SUITE_END();
68 static OString OU2O(std::u16string_view sOUSource)
70 return rtl::OUStringToOString(sOUSource, RTL_TEXTENCODING_UTF8);
73 // Without the patch for tdf#135184, charts were not able to use linecap at all.
74 // These two tests verify, that round linecaps in the xlsx file are saved in ods.
75 void Chart2GeometryTest::testTdf135184RoundLineCap()
77 // It tests chart area, data series line and regression-curve line.
78 loadFromFile(u"xlsx/tdf135184RoundLineCap.xlsx");
79 save("calc8");
80 xmlDocUniquePtr pXmlDoc = parseExport("Object 1/content.xml");
81 CPPUNIT_ASSERT(pXmlDoc);
83 static constexpr OString sStyleStart("/office:document-content/office:automatic-styles"_ostr);
84 static constexpr OString sCap("/style:graphic-properties[@svg:stroke-linecap='round']"_ostr);
85 static constexpr OString sChartStart(
86 "/office:document-content/office:body/office:chart/chart:chart"_ostr);
87 OString sPredicate;
88 // chart area
89 const OUString sOUAreaStyleName = getXPathContent(pXmlDoc, sChartStart + "/@chart:style-name");
90 sPredicate = "[@style:name='" + OU2O(sOUAreaStyleName) + "']";
91 assertXPath(pXmlDoc, sStyleStart + "/style:style" + sPredicate + sCap);
92 // data series line
93 const OString sSeries(sChartStart + "/chart:plot-area/chart:series");
94 const OUString sOUSeriesStyleName = getXPathContent(pXmlDoc, sSeries + "/@chart:style-name");
95 sPredicate = "[@style:name='" + OU2O(sOUSeriesStyleName) + "']";
96 assertXPath(pXmlDoc, sStyleStart + "/style:style" + sPredicate + sCap);
97 // regression-curve (trend line)
98 const OString sTrend(sChartStart + "/chart:plot-area/chart:series/chart:regression-curve");
99 const OUString sOUTrendStyleName = getXPathContent(pXmlDoc, sTrend + "/@chart:style-name");
100 sPredicate = "[@style:name='" + OU2O(sOUTrendStyleName) + "']";
101 assertXPath(pXmlDoc, sStyleStart + "/style:style" + sPredicate + sCap);
104 void Chart2GeometryTest::testTdf135184RoundLineCap2()
106 // It tests legend, data series sector and title.
107 loadFromFile(u"xlsx/tdf135184RoundLineCap2.xlsx");
108 save("calc8");
109 xmlDocUniquePtr pXmlDoc = parseExport("Object 1/content.xml");
110 CPPUNIT_ASSERT(pXmlDoc);
112 static constexpr OString sStyleStart("/office:document-content/office:automatic-styles"_ostr);
113 static constexpr OString sCap("/style:graphic-properties[@svg:stroke-linecap='round']"_ostr);
114 static constexpr OString sChartStart(
115 "/office:document-content/office:body/office:chart/chart:chart"_ostr);
116 OString sPredicate;
117 // legend
118 const OString sLegend(sChartStart + "/chart:legend");
119 const OUString sOULegendStyleName = getXPathContent(pXmlDoc, sLegend + "/@chart:style-name");
120 sPredicate = "[@style:name='" + OU2O(sOULegendStyleName) + "']";
121 assertXPath(pXmlDoc, sStyleStart + "/style:style" + sPredicate + sCap);
122 // title
123 const OString sTitle(sChartStart + "/chart:title");
124 const OUString sOUTitleStyleName = getXPathContent(pXmlDoc, sTitle + "/@chart:style-name");
125 sPredicate = "[@style:name='" + OU2O(sOUTitleStyleName) + "']";
126 assertXPath(pXmlDoc, sStyleStart + "/style:style" + sPredicate + sCap);
127 // sector
128 const OString sSector(sChartStart + "/chart:plot-area/chart:series/chart:data-point[3]");
129 const OUString sOUSectorStyleName = getXPathContent(pXmlDoc, sSector + "/@chart:style-name");
130 sPredicate = "[@style:name='" + OU2O(sOUSectorStyleName) + "']";
131 assertXPath(pXmlDoc, sStyleStart + "/style:style" + sPredicate + sCap);
134 // These two tests verify the round-trip of preset dash styles in the xlsx file.
135 void Chart2GeometryTest::testTdf135184RoundLineCap3()
137 // It tests chart area, data series line and regression-curve line.
138 loadFromFile(u"xlsx/tdf135184RoundLineCap.xlsx");
139 save("Calc Office Open XML");
140 xmlDocUniquePtr pXmlDoc = parseExport("xl/charts/chart1.xml");
141 CPPUNIT_ASSERT(pXmlDoc);
143 static constexpr OString sDash("/c:spPr/a:ln/a:prstDash"_ostr);
144 // chart area
145 assertXPath(pXmlDoc, "/c:chartSpace" + sDash, "val"_ostr, "dashDot");
146 // data series line
147 static constexpr OString sStart("/c:chartSpace/c:chart/c:plotArea/c:scatterChart/c:ser"_ostr);
148 assertXPath(pXmlDoc, sStart + sDash, "val"_ostr, "dash");
149 // regression-curve (trendline)
150 assertXPath(pXmlDoc, sStart + "/c:trendline" + sDash, "val"_ostr, "sysDot");
153 void Chart2GeometryTest::testTdf135184RoundLineCap4()
155 // It tests legend, data series sector and title.
156 loadFromFile(u"xlsx/tdf135184RoundLineCap2.xlsx");
157 save("Calc Office Open XML");
158 xmlDocUniquePtr pXmlDoc = parseExport("xl/charts/chart1.xml");
159 CPPUNIT_ASSERT(pXmlDoc);
161 static constexpr OString sChartStart("/c:chartSpace/c:chart"_ostr);
162 static constexpr OString sDash("/c:spPr/a:ln/a:prstDash"_ostr);
163 assertXPath(pXmlDoc, sChartStart + "/c:legend" + sDash, "val"_ostr, "sysDot");
164 const OString sSeries(sChartStart + "/c:plotArea/c:pieChart/c:ser/c:dPt[3]");
165 assertXPath(pXmlDoc, sSeries + sDash, "val"_ostr, "dash");
166 assertXPath(pXmlDoc, sChartStart + "/c:title" + sDash, "val"_ostr, "dashDot");
169 void Chart2GeometryTest::testTdf128345ChartArea_CG_TS_export()
171 // chart area with color gradient and solid transparency
172 // Without the patch the transparency was lost in saved pptx file.
173 loadFromFile(u"odp/tdf128345_ChartArea_CG_TS.odp");
175 // MCGR: Similar to testTdf128345Legend_CS_TG_axial_export:
176 // Checked that it works with the existing import file,
177 // but will change with ODF MCGR im/export again.
178 // Adapting for now, but need to re-check values after
179 // ODF im/export for MCGR is integrated
181 // Make sure the chart area has a transparency in gradient stops in saved pptx file.
182 save("Impress MS PowerPoint 2007 XML");
183 xmlDocUniquePtr pXmlDoc = parseExport("ppt/charts/chart1.xml");
184 CPPUNIT_ASSERT(pXmlDoc);
186 OString sPathStart("//c:chartSpace/c:spPr/a:gradFill"_ostr);
187 assertXPath(pXmlDoc, sPathStart + "/a:gsLst/a:gs", 2);
188 assertXPath(pXmlDoc, sPathStart + "/a:gsLst/a:gs[1]/a:srgbClr/a:alpha", "val"_ostr, "30000");
189 assertXPath(pXmlDoc, sPathStart + "/a:gsLst/a:gs[2]/a:srgbClr/a:alpha", "val"_ostr, "30000");
192 void Chart2GeometryTest::testTdf128345ChartArea_CG_TS_import()
194 // This works on the file, which was exported from file tdf128345_ChartArea_CG_TS.odp to pptx.
195 // It has gradient stops with identical transparency values.
196 // Make sure chart area has transparency when pptx document is opened and resaved as odp.
197 // As of Aug 2020, the import generates a transparency gradient. When import is changed to
198 // generate solid transparency, the test needs to be adapted.
200 // MCGR: Similar to testTdf128345Legend_CS_TG_axial_export:
201 // Checked that it works with the existing import file,
202 // but will change with ODF MCGR im/export again. We will need to
203 // update the *.odp input file. Disable unclear values for now and
204 // adapt when ODF im/export for MCGR is integrated
205 loadFromFile(u"pptx/tdf128345_ChartArea_CG_TS.pptx");
207 // Find transparency gradient name
208 save("impress8");
209 xmlDocUniquePtr pXmlDoc = parseExport("Object 1/content.xml");
210 CPPUNIT_ASSERT(pXmlDoc);
211 const OUString sOUChartStyleName = getXPathContent(
212 pXmlDoc,
213 "//office:document-content/office:body/office:chart/chart:chart/@chart:style-name"_ostr);
214 const OString sStylePath(
215 "//office:document-content/office:automatic-styles/style:style[@style:name='"
216 + OU2O(sOUChartStyleName) + "']");
217 assertXPath(pXmlDoc, sStylePath, 1);
218 assertXPath(pXmlDoc, sStylePath + "/style:graphic-properties/@draw:opacity-name", 1);
219 const OUString sOUOpacityName
220 = getXPathContent(pXmlDoc, sStylePath + "/style:graphic-properties/@draw:opacity-name");
222 // Verify the content of the opacity definition
223 save("impress8");
224 xmlDocUniquePtr pXmlDoc2 = parseExport("Object 1/styles.xml");
225 CPPUNIT_ASSERT(pXmlDoc2);
226 const OString sAttribute("@draw:name='" + OU2O(sOUOpacityName) + "'");
227 const OString sStart("//office:document-styles/office:styles/draw:opacity[" + sAttribute);
228 assertXPath(pXmlDoc2, sStart + "]", 1);
229 assertXPath(pXmlDoc2, sStart + " and @draw:style='linear']");
230 assertXPath(pXmlDoc2, sStart + " and @draw:start='30%']");
231 assertXPath(pXmlDoc2, sStart + " and @draw:end='30%']");
232 assertXPath(pXmlDoc2, sStart + " and @draw:angle='30deg']");
233 assertXPath(pXmlDoc2, sStart + " and @draw:border='0%']"); // MCGR: no border anymore 20% -> 0%
236 void Chart2GeometryTest::testTdf128345ChartWall_CS_TG_export()
238 // chart wall with solid color and transparency gradient
239 // Without the patch the transparency was lost.
240 loadFromFile(u"odp/tdf128345_ChartWall_CS_TG.odp");
242 // Make sure the chart has a gradient with transparency in gradient stops in saved pptx file.
243 save("Impress MS PowerPoint 2007 XML");
244 xmlDocUniquePtr pXmlDoc = parseExport("ppt/charts/chart1.xml");
245 CPPUNIT_ASSERT(pXmlDoc);
247 OString sPathStart("//c:chartSpace/c:chart/c:plotArea/c:spPr/a:gradFill"_ostr);
248 assertXPath(pXmlDoc, sPathStart + "/a:gsLst/a:gs", 2); //linear
249 // MS Office has opacity, so 100% transparency is val="0"
250 assertXPath(pXmlDoc, sPathStart + "/a:gsLst/a:gs[1]/a:srgbClr/a:alpha", "val"_ostr, "0");
251 // no element for 0% transparent
252 assertXPath(pXmlDoc, sPathStart + "/a:gsLst/a:gs[2]/a:srgbClr/a:alpha", 0);
255 void Chart2GeometryTest::testTdf128345ChartWall_CS_TG_import()
257 // This works on the file, which was exported from file tdf128345_ChartWall_CS_TG.odp to pptx.
258 // Make sure chart wall has transparency when pptx document is resaved as odp.
259 loadFromFile(u"pptx/tdf128345_ChartWall_CS_TG.pptx");
261 // Find transparency gradient name
262 save("impress8");
263 xmlDocUniquePtr pXmlDoc = parseExport("Object 1/content.xml");
264 CPPUNIT_ASSERT(pXmlDoc);
265 const OUString sOUChartStyleName
266 = getXPathContent(pXmlDoc, "//office:document-content/office:body/office:chart/chart:chart/"
267 "chart:plot-area/chart:wall/@chart:style-name"_ostr);
268 const OString sStylePath(
269 "//office:document-content/office:automatic-styles/style:style[@style:name='"
270 + OU2O(sOUChartStyleName) + "']");
271 assertXPath(pXmlDoc, sStylePath, 1);
272 assertXPath(pXmlDoc, sStylePath + "/style:graphic-properties/@draw:opacity-name", 1);
273 const OUString sOUOpacityName
274 = getXPathContent(pXmlDoc, sStylePath + "/style:graphic-properties/@draw:opacity-name");
276 // Verify content of the opacity definition
277 save("impress8");
278 xmlDocUniquePtr pXmlDoc2 = parseExport("Object 1/styles.xml");
279 CPPUNIT_ASSERT(pXmlDoc2);
280 const OString sAttribute("@draw:name='" + OU2O(sOUOpacityName) + "'");
281 const OString sStart("//office:document-styles/office:styles/draw:opacity[" + sAttribute);
282 assertXPath(pXmlDoc2, sStart + "]", 1);
283 assertXPath(pXmlDoc2, sStart + " and @draw:style='linear']");
284 assertXPath(pXmlDoc2, sStart + " and @draw:start='0%']");
285 assertXPath(pXmlDoc2, sStart + " and @draw:end='100%']");
288 void Chart2GeometryTest::testTdf128345Legend_CS_TG_axial_export()
290 // legend with solid color and transparency gradient
291 // Without the patch the transparency was lost.
292 loadFromFile(u"odp/tdf128345_Legend_CS_TG_axial.odp");
294 // Make sure the chart has a gradient with transparency in gradient stops in saved pptx file.
295 save("Impress MS PowerPoint 2007 XML");
296 xmlDocUniquePtr pXmlDoc = parseExport("ppt/charts/chart1.xml");
297 CPPUNIT_ASSERT(pXmlDoc);
299 OString sPathStart("//c:chartSpace/c:chart/c:legend/c:spPr/a:gradFill"_ostr);
301 // MCGR: three entries due to axial being mirrored+expanded to linear
302 assertXPath(pXmlDoc, sPathStart + "/a:gsLst/a:gs", 3);
304 // MCGR: start entry, no transparence, pos zero
305 assertXPath(pXmlDoc, sPathStart + "/a:gsLst/a:gs[1]/a:srgbClr/a:alpha", 0);
306 assertXPath(pXmlDoc, sPathStart + "/a:gsLst/a:gs[1]", "pos"_ostr, "0");
308 // MCGR: middle entry, 100% transparence, pos 0.5
309 assertXPath(pXmlDoc, sPathStart + "/a:gsLst/a:gs[2]/a:srgbClr/a:alpha", "val"_ostr, "0");
310 assertXPath(pXmlDoc, sPathStart + "/a:gsLst/a:gs[2]", "pos"_ostr, "50000");
312 // MCGR: end entry, no transparence, pos 1.0
313 assertXPath(pXmlDoc, sPathStart + "/a:gsLst/a:gs[3]/a:srgbClr/a:alpha", 0);
314 assertXPath(pXmlDoc, sPathStart + "/a:gsLst/a:gs[3]", "pos"_ostr, "100000");
317 void Chart2GeometryTest::testTdf128345Legend_CS_TG_axial_import()
319 // This works on the file, which was exported from file tdf128345_Legend_CS_TG_axial.odp to pptx.
320 // Error was, that in case of axial not the middle value was taken but start and end value.
321 loadFromFile(u"pptx/tdf128345_Legend_CS_TG_axial.pptx");
323 // Find transparency gradient name
324 save("impress8");
325 xmlDocUniquePtr pXmlDoc = parseExport("Object 1/content.xml");
326 CPPUNIT_ASSERT(pXmlDoc);
327 const OUString sOUChartStyleName
328 = getXPathContent(pXmlDoc, "//office:document-content/office:body/office:chart/chart:chart/"
329 "chart:legend/@chart:style-name"_ostr);
330 const OString sStylePath(
331 "//office:document-content/office:automatic-styles/style:style[@style:name='"
332 + OU2O(sOUChartStyleName) + "']");
333 assertXPath(pXmlDoc, sStylePath, 1);
334 assertXPath(pXmlDoc, sStylePath + "/style:graphic-properties/@draw:opacity-name", 1);
335 const OUString sOUOpacityName
336 = getXPathContent(pXmlDoc, sStylePath + "/style:graphic-properties/@draw:opacity-name");
338 // Verify content of the opacity definition
339 save("impress8");
340 xmlDocUniquePtr pXmlDoc2 = parseExport("Object 1/styles.xml");
341 CPPUNIT_ASSERT(pXmlDoc2);
342 const OString sAttribute("@draw:name='" + OU2O(sOUOpacityName) + "'");
343 const OString sStart("//office:document-styles/office:styles/draw:opacity[" + sAttribute);
344 assertXPath(pXmlDoc2, sStart + "]", 1);
345 assertXPath(pXmlDoc2, sStart + " and @draw:style='axial']");
346 assertXPath(pXmlDoc2, sStart + " and @draw:start='0%']");
347 assertXPath(pXmlDoc2, sStart + " and @draw:end='100%']");
350 void Chart2GeometryTest::testTdf135366LabelOnSeries()
352 // Error was, that the fill and line properties of a <chart:data-label> were not
353 // imported at all. Here they should be at the series.
354 loadFromFile(u"ods/tdf135366_data_label_series.ods");
355 uno::Reference<chart2::XChartDocument> xChartDoc = getChartDocFromSheet(0, mxComponent);
356 CPPUNIT_ASSERT(xChartDoc.is());
357 Reference<chart2::XDataSeries> xDataSeries = getDataSeriesFromDoc(xChartDoc, 0);
358 CPPUNIT_ASSERT(xDataSeries.is());
359 Reference<beans::XPropertySet> xPropSet(xDataSeries, UNO_QUERY_THROW);
360 uno::Any aAny;
362 aAny = xPropSet->getPropertyValue("LabelBorderStyle");
363 drawing::LineStyle eLineStyle;
364 CPPUNIT_ASSERT_MESSAGE("No LabelBorderStyle set.", aAny >>= eLineStyle);
365 CPPUNIT_ASSERT_EQUAL_MESSAGE("solid line expected", drawing::LineStyle_SOLID, eLineStyle);
367 sal_Int32 nBorderWidth;
368 sal_Int32 nExpectedWidth = 95;
369 xPropSet->getPropertyValue("LabelBorderWidth") >>= nBorderWidth;
370 CPPUNIT_ASSERT_EQUAL_MESSAGE("LabelBorderWidth", nExpectedWidth, nBorderWidth);
372 sal_Int32 nLineColor;
373 sal_Int32 nExpectedLineColor = 255;
374 xPropSet->getPropertyValue("LabelBorderColor") >>= nLineColor;
375 CPPUNIT_ASSERT_EQUAL_MESSAGE("line color blue, 255=#0000FF", nExpectedLineColor, nLineColor);
377 aAny = xPropSet->getPropertyValue("LabelFillStyle");
378 drawing::FillStyle eFillStyle;
379 CPPUNIT_ASSERT_MESSAGE("No LabelFillStyle set", aAny >>= eFillStyle);
380 CPPUNIT_ASSERT_EQUAL_MESSAGE("solid fill expected", drawing::FillStyle_SOLID, eFillStyle);
382 sal_Int32 nFillColor;
383 sal_Int32 nExpectedFillColor = 65280;
384 xPropSet->getPropertyValue("LabelFillColor") >>= nFillColor;
385 CPPUNIT_ASSERT_EQUAL_MESSAGE("fill color green, 65280=#00FF00", nExpectedFillColor, nFillColor);
388 void Chart2GeometryTest::testTdf135366LabelOnPoint()
390 // Error was, that the fill and line properties of a <chart:data-label> were not
391 // imported at all. Here they should be at point 2.
392 loadFromFile(u"odt/tdf135366_data_label_point.odt");
393 uno::Reference<chart2::XChartDocument> xChartDoc(getChartDocFromWriter(0), uno::UNO_QUERY);
394 CPPUNIT_ASSERT(xChartDoc.is());
395 Reference<chart2::XDataSeries> xDataSeries = getDataSeriesFromDoc(xChartDoc, 0);
396 CPPUNIT_ASSERT(xDataSeries.is());
397 Reference<beans::XPropertySet> xPropSet(xDataSeries->getDataPointByIndex(2),
398 uno::UNO_SET_THROW);
399 uno::Any aAny;
401 aAny = xPropSet->getPropertyValue("LabelBorderStyle");
402 drawing::LineStyle eLineStyle;
403 CPPUNIT_ASSERT_MESSAGE("No LabelBorderStyle set.", aAny >>= eLineStyle);
404 CPPUNIT_ASSERT_EQUAL_MESSAGE("solid line expected", drawing::LineStyle_SOLID, eLineStyle);
406 sal_Int32 nBorderWidth;
407 sal_Int32 nExpectedWidth = 381;
408 xPropSet->getPropertyValue("LabelBorderWidth") >>= nBorderWidth;
409 CPPUNIT_ASSERT_EQUAL_MESSAGE("LabelBorderWidth", nExpectedWidth, nBorderWidth);
411 sal_Int32 nLineTransparency;
412 sal_Int32 nExpectedTransparency = 30;
413 xPropSet->getPropertyValue("LabelBorderTransparency") >>= nLineTransparency;
414 CPPUNIT_ASSERT_EQUAL_MESSAGE("line transparency", nExpectedTransparency, nLineTransparency);
416 sal_Int32 nLineColor;
417 sal_Int32 nExpectedLineColor = 10206041;
418 xPropSet->getPropertyValue("LabelBorderColor") >>= nLineColor;
419 CPPUNIT_ASSERT_EQUAL_MESSAGE("line color greenish, 10206041=#9BBB59", nExpectedLineColor,
420 nLineColor);
422 aAny = xPropSet->getPropertyValue("LabelFillStyle");
423 drawing::FillStyle eFillStyle;
424 CPPUNIT_ASSERT_MESSAGE("No LabelFillStyle set", aAny >>= eFillStyle);
425 CPPUNIT_ASSERT_EQUAL_MESSAGE("solid fill expected", drawing::FillStyle_SOLID, eFillStyle);
427 sal_Int32 nFillColor;
428 sal_Int32 nExpectedFillColor = 14277081;
429 xPropSet->getPropertyValue("LabelFillColor") >>= nFillColor;
430 CPPUNIT_ASSERT_EQUAL_MESSAGE("fill color gray, 14277081=#d9d9d9", nExpectedFillColor,
431 nFillColor);
434 void Chart2GeometryTest::testTdf135366LabelExport()
436 // Error was, that line and fill properties were not exported as
437 // graphic-properties of a <chart:data-label> element, but only
438 // as loext chart-properties of the <chart:data-point> element.
439 loadFromFile(u"odt/tdf135366_data_label_export.odt");
441 // FIXME: Error: unexpected attribute "loext:label-stroke-color"
442 skipValidation();
444 save("writer8");
445 xmlDocUniquePtr pXmlDoc = parseExport("Object 1/content.xml");
446 CPPUNIT_ASSERT(pXmlDoc);
448 // Find label style
449 const OUString sOULabelStyleName = getXPathContent(
450 pXmlDoc, "//office:document-content/office:body/office:chart/chart:chart/chart:plot-area"
451 "/chart:series/chart:data-point[1]/chart:data-label/@chart:style-name"_ostr);
453 // Verify content of graphic properties of label style
454 const OString sStylePath(
455 "//office:document-content/office:automatic-styles/style:style[@style:name='"
456 + OU2O(sOULabelStyleName) + "']/style:graphic-properties");
457 assertXPath(pXmlDoc, sStylePath, 1);
458 assertXPath(pXmlDoc, sStylePath + "[@draw:fill='solid']");
459 assertXPath(pXmlDoc, sStylePath + "[@draw:fill-color='#5050a0']");
460 assertXPath(pXmlDoc, sStylePath + "[@draw:stroke='solid']");
461 assertXPath(pXmlDoc, sStylePath + "[@svg:stroke-width='0.254cm']");
462 assertXPath(pXmlDoc, sStylePath + "[@svg:stroke-color='#00ffff']");
465 void Chart2GeometryTest::testTdf135366_CustomLabelText()
467 // Error was, that custom text in a data label was only exported in ODF extended,
468 // although the used <chart:data-label> element exists since ODF 1.2.
469 const SvtSaveOptions::ODFDefaultVersion nCurrentODFVersion(GetODFDefaultVersion());
470 SetODFDefaultVersion(SvtSaveOptions::ODFVER_012);
471 loadFromFile(u"pptx/tdf135366_CustomLabelText.pptx");
472 save("impress8");
473 xmlDocUniquePtr pXmlDoc = parseExport("Object 1/content.xml");
474 CPPUNIT_ASSERT(pXmlDoc);
476 // Find custom text. As of version 7.0 it is in a <text:span> element.
477 static constexpr OString sCustomTextPath(
478 "//office:document-content/office:body/office:chart/chart:chart/chart:plot-area"
479 "/chart:series/chart:data-point[2]/chart:data-label/text:p/text:span"_ostr);
480 assertXPath(pXmlDoc, sCustomTextPath, 1);
482 // Verify text content
483 const OUString sOUTextContent = getXPathContent(pXmlDoc, sCustomTextPath);
484 CPPUNIT_ASSERT_EQUAL(OUString("Custom"), sOUTextContent);
486 SetODFDefaultVersion(nCurrentODFVersion);
489 CPPUNIT_TEST_SUITE_REGISTRATION(Chart2GeometryTest);
491 CPPUNIT_PLUGIN_IMPLEMENT();
493 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */