summaryrefslogtreecommitdiff
path: root/chart2/qa/extras/chart2geometry.cxx
blob: 4f57654a3587779a01e7e7e27e53d9ebc96b6a8b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

#include "charttest.hxx"

#include <test/xmltesttools.hxx>

#include <com/sun/star/chart2/XChartDocument.hpp>
#include <com/sun/star/chart2/XDataSeries.hpp>
#include <com/sun/star/drawing/FillStyle.hpp>
#include <com/sun/star/drawing/LineStyle.hpp>
#include <com/sun/star/packages/zip/ZipFileAccess.hpp>

#include <unotools/ucbstreamhelper.hxx>
#include <unotools/saveopt.hxx>

#include <libxml/xpathInternals.h>

#include <algorithm>
#include <string_view>

using uno::Reference;
using beans::XPropertySet;

class Chart2GeometryTest : public ChartTest, public XmlTestTools
{
protected:
    virtual void registerNamespaces(xmlXPathContextPtr& pXmlXPathCtx) override;

public:
    Chart2GeometryTest()
        : ChartTest()
    {
    }
    // Mostly tests for line and fill properties
    void testTdf135184RoundLineCap();
    void testTdf135184RoundLineCap2();
    void testTdf135184RoundLineCap3();
    void testTdf135184RoundLineCap4();
    void testTdf128345ChartArea_CG_TS_export();
    void testTdf128345ChartArea_CG_TS_import();
    void testTdf128345ChartWall_CS_TG_export();
    void testTdf128345ChartWall_CS_TG_import();
    void testTdf128345Legend_CS_TG_axial_export();
    void testTdf128345Legend_CS_TG_axial_import();
    void testTdf135366LabelOnSeries();
    void testTdf135366LabelOnPoint();
    void testTdf135366LabelExport();
    void testTdf135366_CustomLabelText();

    CPPUNIT_TEST_SUITE(Chart2GeometryTest);
    CPPUNIT_TEST(testTdf135184RoundLineCap);
    CPPUNIT_TEST(testTdf135184RoundLineCap2);
    CPPUNIT_TEST(testTdf135184RoundLineCap3);
    CPPUNIT_TEST(testTdf135184RoundLineCap4);
    CPPUNIT_TEST(testTdf128345ChartArea_CG_TS_export);
    CPPUNIT_TEST(testTdf128345ChartArea_CG_TS_import);
    CPPUNIT_TEST(testTdf128345ChartWall_CS_TG_export);
    CPPUNIT_TEST(testTdf128345ChartWall_CS_TG_import);
    CPPUNIT_TEST(testTdf128345Legend_CS_TG_axial_export);
    CPPUNIT_TEST(testTdf128345Legend_CS_TG_axial_import);
    CPPUNIT_TEST(testTdf135366LabelOnSeries);
    CPPUNIT_TEST(testTdf135366LabelOnPoint);
    CPPUNIT_TEST(testTdf135366LabelExport);
    CPPUNIT_TEST(testTdf135366_CustomLabelText);

    CPPUNIT_TEST_SUITE_END();

protected:
    /**
     * Given that some problem doesn't affect the result in the importer, we
     * test the resulting file directly, by opening the zip file, parsing an
     * xml stream, and asserting an XPath expression. This method returns the
     * xml stream, so that you can do the asserting.
     */
    xmlDocUniquePtr parseExport(const OUString& rDir, const OUString& rFilterFormat);
};

namespace
{
// This is copied from Chart2ExportTest. It allows to access the chart from a MS Office document
// without knowing whether the file is a chart1.xml or chart2.xml... As of August 2020, Calc
// and Impress use a static variable for the number and therefore the number depends on whether
// there had already been savings before.
struct CheckForChartName
{
private:
    OUString aDir;

public:
    explicit CheckForChartName(const OUString& rDir)
        : aDir(rDir)
    {
    }

    bool operator()(const OUString& rName)
    {
        if (!rName.startsWith(aDir))
            return false;

        if (!rName.endsWith(".xml"))
            return false;

        return true;
    }
};

OUString findChartFile(const OUString& rDir, uno::Reference<container::XNameAccess> const& xNames)
{
    uno::Sequence<OUString> aNames = xNames->getElementNames();
    OUString* pElement = std::find_if(aNames.begin(), aNames.end(), CheckForChartName(rDir));

    CPPUNIT_ASSERT(pElement != aNames.end());
    return *pElement;
}
}

xmlDocUniquePtr Chart2GeometryTest::parseExport(const OUString& rDir, const OUString& rFilterFormat)
{
    std::shared_ptr<utl::TempFile> pTempFile = save(rFilterFormat);

    // Read the XML stream we're interested in.
    uno::Reference<packages::zip::XZipFileAccess2> xNameAccess
        = packages::zip::ZipFileAccess::createWithURL(comphelper::getComponentContext(m_xSFactory),
                                                      pTempFile->GetURL());
    uno::Reference<io::XInputStream> xInputStream(
        xNameAccess->getByName(findChartFile(rDir, xNameAccess)), uno::UNO_QUERY);
    CPPUNIT_ASSERT(xInputStream.is());
    std::unique_ptr<SvStream> pStream(utl::UcbStreamHelper::CreateStream(xInputStream, true));

    return parseXmlStream(pStream.get());
}

void Chart2GeometryTest::registerNamespaces(xmlXPathContextPtr& pXmlXPathCtx)
{
    static struct
    {
        char const* pPrefix;
        char const* pURI;
    } const aNamespaces[] = {
        // OOXML
        { "w", "http://schemas.openxmlformats.org/wordprocessingml/2006/main" },
        { "v", "urn:schemas-microsoft-com:vml" },
        { "c", "http://schemas.openxmlformats.org/drawingml/2006/chart" },
        { "a", "http://schemas.openxmlformats.org/drawingml/2006/main" },
        { "mc", "http://schemas.openxmlformats.org/markup-compatibility/2006" },
        { "wps", "http://schemas.microsoft.com/office/word/2010/wordprocessingShape" },
        { "wpg", "http://schemas.microsoft.com/office/word/2010/wordprocessingGroup" },
        { "wp", "http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" },
        { "c15", "http://schemas.microsoft.com/office/drawing/2012/chart" },
        // ODF
        { "office", "urn:oasis:names:tc:opendocument:xmlns:office:1.0" },
        { "chart", "urn:oasis:names:tc:opendocument:xmlns:chart:1.0" },
        { "draw", "urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" },
        { "style", "urn:oasis:names:tc:opendocument:xmlns:style:1.0" },
        { "svg", "urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" },
        { "table", "urn:oasis:names:tc:opendocument:xmlns:table:1.0" },
        { "text", "urn:oasis:names:tc:opendocument:xmlns:text:1.0" },
        { "xlink", "http://www.w3c.org/1999/xlink" },
    };
    for (size_t i = 0; i < SAL_N_ELEMENTS(aNamespaces); ++i)
    {
        xmlXPathRegisterNs(pXmlXPathCtx, reinterpret_cast<xmlChar const*>(aNamespaces[i].pPrefix),
                           reinterpret_cast<xmlChar const*>(aNamespaces[i].pURI));
    }
}

static OString OU2O(std::u16string_view sOUSource)
{
    return rtl::OUStringToOString(sOUSource, RTL_TEXTENCODING_UTF8);
}

// Without the patch for tdf#135184, charts were not able to use linecap at all.
// These two tests verify, that round linecaps in the xlsx file are saved in ods.
void Chart2GeometryTest::testTdf135184RoundLineCap()
{
    // It tests chart area, data series line and regression-curve line.
    load(u"/chart2/qa/extras/data/xlsx/", "tdf135184RoundLineCap.xlsx");
    xmlDocUniquePtr pXmlDoc = parseExport("Object 1/content.xml", "calc8");
    CPPUNIT_ASSERT(pXmlDoc);

    const OString sStyleStart("/office:document-content/office:automatic-styles");
    const OString sCap("/style:graphic-properties[@svg:stroke-linecap='round']");
    const OString sChartStart("/office:document-content/office:body/office:chart/chart:chart");
    OString sPredicate;
    // chart area
    const OUString sOUAreaStyleName = getXPathContent(pXmlDoc, sChartStart + "/@chart:style-name");
    sPredicate = "[@style:name='" + OU2O(sOUAreaStyleName) + "']";
    assertXPath(pXmlDoc, sStyleStart + "/style:style" + sPredicate + sCap);
    // data series line
    const OString sSeries(sChartStart + "/chart:plot-area/chart:series");
    const OUString sOUSeriesStyleName = getXPathContent(pXmlDoc, sSeries + "/@chart:style-name");
    sPredicate = "[@style:name='" + OU2O(sOUSeriesStyleName) + "']";
    assertXPath(pXmlDoc, sStyleStart + "/style:style" + sPredicate + sCap);
    // regression-curve (trend line)
    const OString sTrend(sChartStart + "/chart:plot-area/chart:series/chart:regression-curve");
    const OUString sOUTrendStyleName = getXPathContent(pXmlDoc, sTrend + "/@chart:style-name");
    sPredicate = "[@style:name='" + OU2O(sOUTrendStyleName) + "']";
    assertXPath(pXmlDoc, sStyleStart + "/style:style" + sPredicate + sCap);
}

void Chart2GeometryTest::testTdf135184RoundLineCap2()
{
    // It tests legend, data series sector and title.
    load(u"/chart2/qa/extras/data/xlsx/", "tdf135184RoundLineCap2.xlsx");
    xmlDocUniquePtr pXmlDoc = parseExport("Object 1/content.xml", "calc8");
    CPPUNIT_ASSERT(pXmlDoc);

    const OString sStyleStart("/office:document-content/office:automatic-styles");
    const OString sCap("/style:graphic-properties[@svg:stroke-linecap='round']");
    const OString sChartStart("/office:document-content/office:body/office:chart/chart:chart");
    OString sPredicate;
    // legend
    const OString sLegend(sChartStart + "/chart:legend");
    const OUString sOULegendStyleName = getXPathContent(pXmlDoc, sLegend + "/@chart:style-name");
    sPredicate = "[@style:name='" + OU2O(sOULegendStyleName) + "']";
    assertXPath(pXmlDoc, sStyleStart + "/style:style" + sPredicate + sCap);
    // title
    const OString sTitle(sChartStart + "/chart:title");
    const OUString sOUTitleStyleName = getXPathContent(pXmlDoc, sTitle + "/@chart:style-name");
    sPredicate = "[@style:name='" + OU2O(sOUTitleStyleName) + "']";
    assertXPath(pXmlDoc, sStyleStart + "/style:style" + sPredicate + sCap);
    // sector
    const OString sSector(sChartStart + "/chart:plot-area/chart:series/chart:data-point[3]");
    const OUString sOUSectorStyleName = getXPathContent(pXmlDoc, sSector + "/@chart:style-name");
    sPredicate = "[@style:name='" + OU2O(sOUSectorStyleName) + "']";
    assertXPath(pXmlDoc, sStyleStart + "/style:style" + sPredicate + sCap);
}

// These two tests verify the round-trip of preset dash styles in the xlsx file.
void Chart2GeometryTest::testTdf135184RoundLineCap3()
{
    // It tests chart area, data series line and regression-curve line.
    load(u"/chart2/qa/extras/data/xlsx/", "tdf135184RoundLineCap.xlsx");
    xmlDocUniquePtr pXmlDoc = parseExport("xl/charts/chart", "Calc Office Open XML");
    CPPUNIT_ASSERT(pXmlDoc);

    const OString sDash("/c:spPr/a:ln/a:prstDash");
    // chart area
    assertXPath(pXmlDoc, "/c:chartSpace" + sDash, "val", "dashDot");
    // data series line
    const OString sStart("/c:chartSpace/c:chart/c:plotArea/c:scatterChart/c:ser");
    assertXPath(pXmlDoc, sStart + sDash, "val", "dash");
    // regression-curve (trendline)
    assertXPath(pXmlDoc, sStart + "/c:trendline" + sDash, "val", "sysDot");
}

void Chart2GeometryTest::testTdf135184RoundLineCap4()
{
    // It tests legend, data series sector and title.
    load(u"/chart2/qa/extras/data/xlsx/", "tdf135184RoundLineCap2.xlsx");
    xmlDocUniquePtr pXmlDoc = parseExport("xl/charts/chart", "Calc Office Open XML");
    CPPUNIT_ASSERT(pXmlDoc);

    const OString sChartStart("/c:chartSpace/c:chart");
    const OString sDash("/c:spPr/a:ln/a:prstDash");
    assertXPath(pXmlDoc, sChartStart + "/c:legend" + sDash, "val", "sysDot");
    const OString sSeries(sChartStart + "/c:plotArea/c:pieChart/c:ser/c:dPt[3]");
    assertXPath(pXmlDoc, sSeries + sDash, "val", "dash");
    assertXPath(pXmlDoc, sChartStart + "/c:title" + sDash, "val", "dashDot");
}

void Chart2GeometryTest::testTdf128345ChartArea_CG_TS_export()
{
    // chart area with color gradient and solid transparency
    // Without the patch the transparency was lost in saved pptx file.
    load(u"/chart2/qa/extras/data/odp/", "tdf128345_ChartArea_CG_TS.odp");

    // Make sure the chart area has a transparency in gradient stops in saved pptx file.
    xmlDocUniquePtr pXmlDoc = parseExport("ppt/charts/chart", "Impress MS PowerPoint 2007 XML");
    CPPUNIT_ASSERT(pXmlDoc);

    OString sPathStart("//c:chartSpace/c:spPr/a:gradFill");
    assertXPath(pXmlDoc, sPathStart + "/a:gsLst/a:gs", 2);
    assertXPath(pXmlDoc, sPathStart + "/a:gsLst/a:gs[1]/a:srgbClr/a:alpha", "val", "30000");
    assertXPath(pXmlDoc, sPathStart + "/a:gsLst/a:gs[2]/a:srgbClr/a:alpha", "val", "30000");
}

void Chart2GeometryTest::testTdf128345ChartArea_CG_TS_import()
{
    // This works on the file, which was exported from file tdf128345_ChartArea_CG_TS.odp to pptx.
    // It has gradient stops with identical transparency values.
    // Make sure chart area has transparency when pptx document is opened and resaved as odp.
    // As of Aug 2020, the import generates a transparency gradient. When import is changed to
    // generate solid transparency, the test needs to be adapted.
    load(u"/chart2/qa/extras/data/pptx/", "tdf128345_ChartArea_CG_TS.pptx");

    // Find transparency gradient name
    xmlDocUniquePtr pXmlDoc = parseExport("Object 1/content.xml", "impress8");
    CPPUNIT_ASSERT(pXmlDoc);
    const OUString sOUChartStyleName = getXPathContent(
        pXmlDoc,
        "//office:document-content/office:body/office:chart/chart:chart/@chart:style-name");
    const OString sStylePath(
        "//office:document-content/office:automatic-styles/style:style[@style:name='"
        + OU2O(sOUChartStyleName) + "']");
    assertXPath(pXmlDoc, sStylePath, 1);
    assertXPath(pXmlDoc, sStylePath + "/style:graphic-properties/@draw:opacity-name", 1);
    const OUString sOUOpacityName
        = getXPathContent(pXmlDoc, sStylePath + "/style:graphic-properties/@draw:opacity-name");

    // Verify the content of the opacity definition
    xmlDocUniquePtr pXmlDoc2 = parseExport("Object 1/styles.xml", "impress8");
    CPPUNIT_ASSERT(pXmlDoc2);
    const OString sAttribute("@draw:name='" + OU2O(sOUOpacityName) + "'");
    const OString sStart("//office:document-styles/office:styles/draw:opacity[" + sAttribute);
    assertXPath(pXmlDoc2, sStart + "]", 1);
    assertXPath(pXmlDoc2, sStart + " and @draw:style='linear']");
    assertXPath(pXmlDoc2, sStart + " and @draw:start='30%']");
    assertXPath(pXmlDoc2, sStart + " and @draw:end='30%']");
    assertXPath(pXmlDoc2, sStart + " and @draw:angle='30deg']");
    assertXPath(pXmlDoc2, sStart + " and @draw:border='20%']");
}

void Chart2GeometryTest::testTdf128345ChartWall_CS_TG_export()
{
    // chart wall with solid color and transparency gradient
    // Without the patch the transparency was lost.
    load(u"/chart2/qa/extras/data/odp/", "tdf128345_ChartWall_CS_TG.odp");

    // Make sure the chart has a gradient with transparency in gradient stops in saved pptx file.
    xmlDocUniquePtr pXmlDoc = parseExport("ppt/charts/chart", "Impress MS PowerPoint 2007 XML");
    CPPUNIT_ASSERT(pXmlDoc);

    OString sPathStart("//c:chartSpace/c:chart/c:plotArea/c:spPr/a:gradFill");
    assertXPath(pXmlDoc, sPathStart + "/a:gsLst/a:gs", 2); //linear
    // MS Office has opacity, so 100% transparency is val="0"
    assertXPath(pXmlDoc, sPathStart + "/a:gsLst/a:gs[1]/a:srgbClr/a:alpha", "val", "0");
    // no element for 0% transparent
    assertXPath(pXmlDoc, sPathStart + "/a:gsLst/a:gs[2]/a:srgbClr/a:alpha", 0);
}

void Chart2GeometryTest::testTdf128345ChartWall_CS_TG_import()
{
    // This works on the file, which was exported from file tdf128345_ChartWall_CS_TG.odp to pptx.
    // Make sure chart wall has transparency when pptx document is resaved as odp.
    load(u"/chart2/qa/extras/data/pptx/", "tdf128345_ChartWall_CS_TG.pptx");

    // Find transparency gradient name
    xmlDocUniquePtr pXmlDoc = parseExport("Object 1/content.xml", "impress8");
    CPPUNIT_ASSERT(pXmlDoc);
    const OUString sOUChartStyleName
        = getXPathContent(pXmlDoc, "//office:document-content/office:body/office:chart/chart:chart/"
                                   "chart:plot-area/chart:wall/@chart:style-name");
    const OString sStylePath(
        "//office:document-content/office:automatic-styles/style:style[@style:name='"
        + OU2O(sOUChartStyleName) + "']");
    assertXPath(pXmlDoc, sStylePath, 1);
    assertXPath(pXmlDoc, sStylePath + "/style:graphic-properties/@draw:opacity-name", 1);
    const OUString sOUOpacityName
        = getXPathContent(pXmlDoc, sStylePath + "/style:graphic-properties/@draw:opacity-name");

    // Verify content of the opacity definition
    xmlDocUniquePtr pXmlDoc2 = parseExport("Object 1/styles.xml", "impress8");
    CPPUNIT_ASSERT(pXmlDoc2);
    const OString sAttribute("@draw:name='" + OU2O(sOUOpacityName) + "'");
    const OString sStart("//office:document-styles/office:styles/draw:opacity[" + sAttribute);
    assertXPath(pXmlDoc2, sStart + "]", 1);
    assertXPath(pXmlDoc2, sStart + " and @draw:style='linear']");
    assertXPath(pXmlDoc2, sStart + " and @draw:start='0%']");
    assertXPath(pXmlDoc2, sStart + " and @draw:end='100%']");
}

void Chart2GeometryTest::testTdf128345Legend_CS_TG_axial_export()
{
    // legend with solid color and transparency gradient
    // Without the patch the transparency was lost.
    load(u"/chart2/qa/extras/data/odp/", "tdf128345_Legend_CS_TG_axial.odp");

    // Make sure the chart has a gradient with transparency in gradient stops in saved pptx file.
    xmlDocUniquePtr pXmlDoc = parseExport("ppt/charts/chart", "Impress MS PowerPoint 2007 XML");
    CPPUNIT_ASSERT(pXmlDoc);

    OString sPathStart("//c:chartSpace/c:chart/c:legend/c:spPr/a:gradFill");
    assertXPath(pXmlDoc, sPathStart + "/a:gsLst/a:gs", 3); // axial
    // no element for 0% transparent
    assertXPath(pXmlDoc, sPathStart + "/a:gsLst/a:gs[1]/a:srgbClr/a:alpha", 0);
    // 100% transparent = opacity 0. It comes from "axial", therefore it is in the middle.
    assertXPath(pXmlDoc, sPathStart + "/a:gsLst/a:gs[2]/a:srgbClr/a:alpha", "val", "0");
    assertXPath(pXmlDoc, sPathStart + "/a:gsLst/a:gs[2]", "pos", "50000");
    assertXPath(pXmlDoc, sPathStart + "/a:gsLst/a:gs[3]/a:srgbClr/a:alpha", 0);
}

void Chart2GeometryTest::testTdf128345Legend_CS_TG_axial_import()
{
    // This works on the file, which was exported from file tdf128345_Legend_CS_TG_axial.odp to pptx.
    // Error was, that in case of axial not the middle value was taken but start and end value.
    load(u"/chart2/qa/extras/data/pptx/", "tdf128345_Legend_CS_TG_axial.pptx");

    // Find transparency gradient name
    xmlDocUniquePtr pXmlDoc = parseExport("Object 1/content.xml", "impress8");
    CPPUNIT_ASSERT(pXmlDoc);
    const OUString sOUChartStyleName
        = getXPathContent(pXmlDoc, "//office:document-content/office:body/office:chart/chart:chart/"
                                   "chart:legend/@chart:style-name");
    const OString sStylePath(
        "//office:document-content/office:automatic-styles/style:style[@style:name='"
        + OU2O(sOUChartStyleName) + "']");
    assertXPath(pXmlDoc, sStylePath, 1);
    assertXPath(pXmlDoc, sStylePath + "/style:graphic-properties/@draw:opacity-name", 1);
    const OUString sOUOpacityName
        = getXPathContent(pXmlDoc, sStylePath + "/style:graphic-properties/@draw:opacity-name");

    // Verify content of the opacity definition
    xmlDocUniquePtr pXmlDoc2 = parseExport("Object 1/styles.xml", "impress8");
    CPPUNIT_ASSERT(pXmlDoc2);
    const OString sAttribute("@draw:name='" + OU2O(sOUOpacityName) + "'");
    const OString sStart("//office:document-styles/office:styles/draw:opacity[" + sAttribute);
    assertXPath(pXmlDoc2, sStart + "]", 1);
    assertXPath(pXmlDoc2, sStart + " and @draw:style='axial']");
    assertXPath(pXmlDoc2, sStart + " and @draw:start='0%']");
    assertXPath(pXmlDoc2, sStart + " and @draw:end='100%']");
}

void Chart2GeometryTest::testTdf135366LabelOnSeries()
{
    // Error was, that the fill and line properties of a <chart:data-label> were not
    // imported at all. Here they should be at the series.
    load(u"/chart2/qa/extras/data/ods/", "tdf135366_data_label_series.ods");
    uno::Reference<chart2::XChartDocument> xChartDoc = getChartDocFromSheet(0, mxComponent);
    CPPUNIT_ASSERT(xChartDoc.is());
    Reference<chart2::XDataSeries> xDataSeries = getDataSeriesFromDoc(xChartDoc, 0);
    CPPUNIT_ASSERT(xDataSeries.is());
    Reference<beans::XPropertySet> xPropSet(xDataSeries, UNO_QUERY_THROW);
    uno::Any aAny;

    aAny = xPropSet->getPropertyValue("LabelBorderStyle");
    drawing::LineStyle eLineStyle;
    CPPUNIT_ASSERT_MESSAGE("No LabelBorderStyle set.", aAny >>= eLineStyle);
    CPPUNIT_ASSERT_EQUAL_MESSAGE("solid line expected", drawing::LineStyle_SOLID, eLineStyle);

    sal_Int32 nBorderWidth;
    sal_Int32 nExpectedWidth = 95;
    xPropSet->getPropertyValue("LabelBorderWidth") >>= nBorderWidth;
    CPPUNIT_ASSERT_EQUAL_MESSAGE("LabelBorderWidth", nExpectedWidth, nBorderWidth);

    sal_Int32 nLineColor;
    sal_Int32 nExpectedLineColor = 255;
    xPropSet->getPropertyValue("LabelBorderColor") >>= nLineColor;
    CPPUNIT_ASSERT_EQUAL_MESSAGE("line color blue, 255=#0000FF", nExpectedLineColor, nLineColor);

    aAny = xPropSet->getPropertyValue("LabelFillStyle");
    drawing::FillStyle eFillStyle;
    CPPUNIT_ASSERT_MESSAGE("No LabelFillStyle set", aAny >>= eFillStyle);
    CPPUNIT_ASSERT_EQUAL_MESSAGE("solid fill expected", drawing::FillStyle_SOLID, eFillStyle);

    sal_Int32 nFillColor;
    sal_Int32 nExpectedFillColor = 65280;
    xPropSet->getPropertyValue("LabelFillColor") >>= nFillColor;
    CPPUNIT_ASSERT_EQUAL_MESSAGE("fill color green, 65280=#00FF00", nExpectedFillColor, nFillColor);
}

void Chart2GeometryTest::testTdf135366LabelOnPoint()
{
    // Error was, that the fill and line properties of a <chart:data-label> were not
    // imported at all. Here they should be at point 2.
    load(u"/chart2/qa/extras/data/odt/", "tdf135366_data_label_point.odt");
    uno::Reference<chart2::XChartDocument> xChartDoc(getChartDocFromWriter(0), uno::UNO_QUERY);
    CPPUNIT_ASSERT(xChartDoc.is());
    Reference<chart2::XDataSeries> xDataSeries = getDataSeriesFromDoc(xChartDoc, 0);
    CPPUNIT_ASSERT(xDataSeries.is());
    Reference<beans::XPropertySet> xPropSet(xDataSeries->getDataPointByIndex(2),
                                            uno::UNO_SET_THROW);
    uno::Any aAny;

    aAny = xPropSet->getPropertyValue("LabelBorderStyle");
    drawing::LineStyle eLineStyle;
    CPPUNIT_ASSERT_MESSAGE("No LabelBorderStyle set.", aAny >>= eLineStyle);
    CPPUNIT_ASSERT_EQUAL_MESSAGE("solid line expected", drawing::LineStyle_SOLID, eLineStyle);

    sal_Int32 nBorderWidth;
    sal_Int32 nExpectedWidth = 381;
    xPropSet->getPropertyValue("LabelBorderWidth") >>= nBorderWidth;
    CPPUNIT_ASSERT_EQUAL_MESSAGE("LabelBorderWidth", nExpectedWidth, nBorderWidth);

    sal_Int32 nLineTransparency;
    sal_Int32 nExpectedTransparency = 30;
    xPropSet->getPropertyValue("LabelBorderTransparency") >>= nLineTransparency;
    CPPUNIT_ASSERT_EQUAL_MESSAGE("line transparency", nExpectedTransparency, nLineTransparency);

    sal_Int32 nLineColor;
    sal_Int32 nExpectedLineColor = 10206041;
    xPropSet->getPropertyValue("LabelBorderColor") >>= nLineColor;
    CPPUNIT_ASSERT_EQUAL_MESSAGE("line color greenish, 10206041=#9BBB59", nExpectedLineColor,
                                 nLineColor);

    aAny = xPropSet->getPropertyValue("LabelFillStyle");
    drawing::FillStyle eFillStyle;
    CPPUNIT_ASSERT_MESSAGE("No LabelFillStyle set", aAny >>= eFillStyle);
    CPPUNIT_ASSERT_EQUAL_MESSAGE("solid fill expected", drawing::FillStyle_SOLID, eFillStyle);

    sal_Int32 nFillColor;
    sal_Int32 nExpectedFillColor = 14277081;
    xPropSet->getPropertyValue("LabelFillColor") >>= nFillColor;
    CPPUNIT_ASSERT_EQUAL_MESSAGE("fill color gray, 14277081=#d9d9d9", nExpectedFillColor,
                                 nFillColor);
}

void Chart2GeometryTest::testTdf135366LabelExport()
{
    // Error was, that line and fill properties were not exported as
    // graphic-properties of a <chart:data-label> element, but only
    // as loext chart-properties of the <chart:data-point> element.
    load(u"/chart2/qa/extras/data/odt/", "tdf135366_data_label_export.odt");
    xmlDocUniquePtr pXmlDoc = parseExport("Object 1/content.xml", "writer8");
    CPPUNIT_ASSERT(pXmlDoc);

    // Find label style
    const OUString sOULabelStyleName = getXPathContent(
        pXmlDoc, "//office:document-content/office:body/office:chart/chart:chart/chart:plot-area"
                 "/chart:series/chart:data-point[1]/chart:data-label/@chart:style-name");

    // Verify content of graphic properties of label style
    const OString sStylePath(
        "//office:document-content/office:automatic-styles/style:style[@style:name='"
        + OU2O(sOULabelStyleName) + "']/style:graphic-properties");
    assertXPath(pXmlDoc, sStylePath, 1);
    assertXPath(pXmlDoc, sStylePath + "[@draw:fill='solid']");
    assertXPath(pXmlDoc, sStylePath + "[@draw:fill-color='#5050a0']");
    assertXPath(pXmlDoc, sStylePath + "[@draw:stroke='solid']");
    assertXPath(pXmlDoc, sStylePath + "[@svg:stroke-width='0.254cm']");
    assertXPath(pXmlDoc, sStylePath + "[@svg:stroke-color='#00ffff']");
}

void Chart2GeometryTest::testTdf135366_CustomLabelText()
{
    // Error was, that custom text in a data label was only exported in ODF extended,
    // although the used <chart:data-label> element exists since ODF 1.2.
    SvtSaveOptions aSaveOpt;
    const SvtSaveOptions::ODFDefaultVersion nCurrentODFVersion(aSaveOpt.GetODFDefaultVersion());
    aSaveOpt.SetODFDefaultVersion(SvtSaveOptions::ODFVER_012);
    load(u"/chart2/qa/extras/data/pptx/", "tdf135366_CustomLabelText.pptx");
    xmlDocUniquePtr pXmlDoc = parseExport("Object 1/content.xml", "impress8");
    CPPUNIT_ASSERT(pXmlDoc);

    // Find custom text. As of version 7.0 it is in a <text:span> element.
    const OString sCustomTextPath(
        "//office:document-content/office:body/office:chart/chart:chart/chart:plot-area"
        "/chart:series/chart:data-point[2]/chart:data-label/text:p/text:span");
    assertXPath(pXmlDoc, sCustomTextPath, 1);

    // Verify text content
    const OUString sOUTextContent = getXPathContent(pXmlDoc, sCustomTextPath);
    CPPUNIT_ASSERT_EQUAL(OUString("Custom"), sOUTextContent);

    aSaveOpt.SetODFDefaultVersion(nCurrentODFVersion);
}

CPPUNIT_TEST_SUITE_REGISTRATION(Chart2GeometryTest);

CPPUNIT_PLUGIN_IMPLEMENT();

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */