summaryrefslogtreecommitdiff
path: root/chart2/qa/extras/xshape/chart2xshape.cxx
blob: bf2e381a75e5e516eee6ccefd4bf2d630cbcdb46 (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
/* -*- 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 <com/sun/star/chart/XChartDocument.hpp>

#include <com/sun/star/qa/XDumper.hpp>

#include <test/xmldiff.hxx>
#include <test/xmltesttools.hxx>

#include <fstream>
#include <string_view>

class Chart2XShapeTest : public ChartTest
{
public:
    void testTdf150832();
    void testTdf149204();
    void testTdf151424();
    void testFdo75075();
    void testPropertyMappingBarChart();
    void testPieChartLabels1();
    void testPieChartLabels2();
    void testPieChartLabels3();
    void testPieChartLabels4();
    void testChart();
    void testTdf76649TrendLineBug();
    void testTdf88154LabelRotatedLayout();

    CPPUNIT_TEST_SUITE(Chart2XShapeTest);
    CPPUNIT_TEST(testTdf150832);
    CPPUNIT_TEST(testTdf149204);
    CPPUNIT_TEST(testTdf151424);
    CPPUNIT_TEST(testFdo75075);
    CPPUNIT_TEST(testPropertyMappingBarChart);
    CPPUNIT_TEST(testPieChartLabels1);
    CPPUNIT_TEST(testPieChartLabels2);
    CPPUNIT_TEST(testPieChartLabels3);
    CPPUNIT_TEST(testPieChartLabels4);
    CPPUNIT_TEST(testChart);
    CPPUNIT_TEST(testTdf76649TrendLineBug);
    CPPUNIT_TEST(testTdf88154LabelRotatedLayout);

    CPPUNIT_TEST_SUITE_END();

private:
    void compareAgainstReference(const OUString& rDump, std::u16string_view rReferenceFile);
    OUString getXShapeDumpString();
    xmlDocUniquePtr getXShapeDumpXmlDoc();
};

namespace
{
bool checkDumpAgainstFile(const OUString& rDump, std::u16string_view aFilePath,
                          char const* toleranceFile)
{
    OString aOFile = OUStringToOString(aFilePath, RTL_TEXTENCODING_UTF8);

    CPPUNIT_ASSERT_MESSAGE("dump is empty", !rDump.isEmpty());

    OString aDump = OUStringToOString(rDump, RTL_TEXTENCODING_UTF8);
    return doXMLDiff(aOFile.getStr(), aDump.getStr(), static_cast<int>(rDump.getLength()),
                     toleranceFile);
}
}

OUString Chart2XShapeTest::getXShapeDumpString()
{
    uno::Reference<chart::XChartDocument> xChartDoc(getChartCompFromSheet(0, mxComponent),
                                                    UNO_QUERY_THROW);
    uno::Reference<qa::XDumper> xDumper(xChartDoc, UNO_QUERY_THROW);
    return xDumper->dump();
}

xmlDocUniquePtr Chart2XShapeTest::getXShapeDumpXmlDoc()
{
    OUString rDump = getXShapeDumpString();
    OString aXmlDump = OUStringToOString(rDump, RTL_TEXTENCODING_UTF8);
    return xmlDocUniquePtr(xmlParseDoc(reinterpret_cast<const xmlChar*>(aXmlDump.getStr())));
}

void Chart2XShapeTest::compareAgainstReference(const OUString& rDump,
                                               std::u16string_view rReferenceFile)
{
    checkDumpAgainstFile(
        rDump,
        Concat2View(m_directories.getPathFromSrc(u"/chart2/qa/extras/xshape/data/reference/")
                    + rReferenceFile),
        OUStringToOString(
            m_directories.getPathFromSrc(u"/chart2/qa/extras/xshape/data/reference/tolerance.xml"),
            RTL_TEXTENCODING_UTF8)
            .getStr());
}

void Chart2XShapeTest::testTdf150832()
{
    // FIXME: the DPI check should be removed when either (1) the test is fixed to work with
    // non-default DPI; or (2) unit tests on Windows are made to use svp VCL plugin.
    if (!IsDefaultDPI())
        return;

    // Without the fix in place, this test would have failed with
    // - Expected: 319
    // - Actual  : 0
    load(u"chart2/qa/extras/xshape/data/xls/", u"tdf150832.xls");
    compareAgainstReference(getXShapeDumpString(), u"tdf150832.xml");
}

void Chart2XShapeTest::testTdf149204()
{
    // FIXME: the DPI check should be removed when either (1) the test is fixed to work with
    // non-default DPI; or (2) unit tests on Windows are made to use svp VCL plugin.
    if (!IsDefaultDPI())
        return;

    // Without the fix in place, this test would have failed with
    // - Expected: 12230
    // - Actual  : 12940
    // - Node: /XShapes/XShape[2]
    // - Attr: sizeX
    load(u"chart2/qa/extras/xshape/data/pptx/", u"tdf149204.pptx");
    uno::Reference<chart::XChartDocument> xChartDoc = getChartDocFromDrawImpress(0, 0);
    uno::Reference<qa::XDumper> xDumper(xChartDoc, UNO_QUERY_THROW);
    compareAgainstReference(xDumper->dump(), u"tdf149204.xml");
}

void Chart2XShapeTest::testTdf151424()
{
    // FIXME: the DPI check should be removed when either (1) the test is fixed to work with
    // non-default DPI; or (2) unit tests on Windows are made to use svp VCL plugin.
    if (!IsDefaultDPI())
        return;

    // Without the fix in place, this test would have failed with
    // - Expected: 3717
    // - Actual  : 3530
    // - Node: /XShapes/XShape[2]/XShapes/XShape[1]
    // - Attr: positionX
    load(u"chart2/qa/extras/xshape/data/ods/", u"tdf151424.ods");
    compareAgainstReference(getXShapeDumpString(), u"tdf151424.xml");
}

void Chart2XShapeTest::testFdo75075()
{
    // FIXME: the DPI check should be removed when either (1) the test is fixed to work with
    // non-default DPI; or (2) unit tests on Windows are made to use svp VCL plugin.
    if (!IsDefaultDPI())
        return;

    load(u"chart2/qa/extras/xshape/data/ods/", u"fdo75075.ods");
    compareAgainstReference(getXShapeDumpString(), u"fdo75075.xml");
}

void Chart2XShapeTest::testPropertyMappingBarChart()
{
    // FIXME: the DPI check should be removed when either (1) the test is fixed to work with
    // non-default DPI; or (2) unit tests on Windows are made to use svp VCL plugin.
    if (!IsDefaultDPI())
        return;

    load(u"chart2/qa/extras/xshape/data/ods/", u"property-mapping-bar.ods");
    compareAgainstReference(getXShapeDumpString(), u"property-mapping-bar.xml");
}

void Chart2XShapeTest::testPieChartLabels1()
{
    // FIXME: the DPI check should be removed when either (1) the test is fixed to work with
    // non-default DPI; or (2) unit tests on Windows are made to use svp VCL plugin.
    if (!IsDefaultDPI())
        return;

    // inside placement for the best fit case
    load(u"chart2/qa/extras/xshape/data/xlsx/", u"tdf90839-1.xlsx");
    compareAgainstReference(getXShapeDumpString(), u"tdf90839-1.xml");
}

void Chart2XShapeTest::testPieChartLabels2()
{
    // FIXME: the DPI check should be removed when either (1) the test is fixed to work with
    // non-default DPI; or (2) unit tests on Windows are made to use svp VCL plugin.
    if (!IsDefaultDPI())
        return;

    // text wrap: wrap all text labels except one
    load(u"chart2/qa/extras/xshape/data/xlsx/", u"tdf90839-2.xlsx");
    compareAgainstReference(getXShapeDumpString(), u"tdf90839-2.xml");
}

void Chart2XShapeTest::testPieChartLabels3()
{
    // FIXME: the DPI check should be removed when either (1) the test is fixed to work with
    // non-default DPI; or (2) unit tests on Windows are made to use svp VCL plugin.
    if (!IsDefaultDPI())
        return;

    // text wrap: wrap no text label except one
    load(u"chart2/qa/extras/xshape/data/xlsx/", u"tdf90839-3.xlsx");
    compareAgainstReference(getXShapeDumpString(), u"tdf90839-3.xml");
}

void Chart2XShapeTest::testPieChartLabels4()
{
    // FIXME: the DPI check should be removed when either (1) the test is fixed to work with
    // non-default DPI; or (2) unit tests on Windows are made to use svp VCL plugin.
    if (!IsDefaultDPI())
        return;

    // data value and percent value are centered horizontally
    load(u"chart2/qa/extras/xshape/data/ods/", u"tdf90839-4.ods");
    compareAgainstReference(getXShapeDumpString(), u"tdf90839-4.xml");
}

void Chart2XShapeTest::testChart()
{
    // FIXME: the DPI check should be removed when either (1) the test is fixed to work with
    // non-default DPI; or (2) unit tests on Windows are made to use svp VCL plugin.
    if (!IsDefaultDPI())
        return;

    load(u"chart2/qa/extras/xshape/data/ods/", u"testChart.ods");
    compareAgainstReference(getXShapeDumpString(), u"testChart.xml");
}

void Chart2XShapeTest::testTdf76649TrendLineBug()
{
    // This bug prevents that the trendline (regression curve) is drawn
    // if the first cell is empty. See tdf#76649 for details.

    load(u"chart2/qa/extras/xshape/data/ods/", u"tdf76649_TrendLineBug.ods");

    xmlDocUniquePtr pXmlDoc = getXShapeDumpXmlDoc();

    // Check if the regression curve exists (which means a XShape with a certain
    // name should exist in the dump)
    assertXPath(pXmlDoc, "//XShape[@name='CID/D=0:CS=0:CT=0:Series=0:Curve=0']", 1);
}

void Chart2XShapeTest::testTdf88154LabelRotatedLayout()
{
    load(u"chart2/qa/extras/xshape/data/pptx/", u"tdf88154_LabelRotatedLayout.pptx");
    uno::Reference<chart::XChartDocument> xChartDoc = getChartDocFromDrawImpress(0, 5);
    uno::Reference<qa::XDumper> xDumper(xChartDoc, UNO_QUERY_THROW);
    OUString rDump = xDumper->dump();
    OString aXmlDump = OUStringToOString(rDump, RTL_TEXTENCODING_UTF8);
    xmlDocUniquePtr pXmlDoc(xmlParseDoc(reinterpret_cast<const xmlChar*>(aXmlDump.getStr())));

    {
        OString aPath("//XShape[@text='Oct-12']/Transformation");
        assertXPath(pXmlDoc, aPath, 1);
        double fT11 = getXPath(pXmlDoc, aPath + "/Line1", "column1").toDouble();
        double fT12 = getXPath(pXmlDoc, aPath + "/Line1", "column2").toDouble();
        double fT21 = getXPath(pXmlDoc, aPath + "/Line2", "column1").toDouble();
        double fT22 = getXPath(pXmlDoc, aPath + "/Line2", "column2").toDouble();

        CPPUNIT_ASSERT_DOUBLES_EQUAL(fT11, -fT21, 1e-8);
        CPPUNIT_ASSERT_DOUBLES_EQUAL(fT12, fT22, 1e-8);
    }
    {
        OString aPath("//XShape[@text='Nov-12']/Transformation");
        assertXPath(pXmlDoc, aPath, 1);
        double fT11 = getXPath(pXmlDoc, aPath + "/Line1", "column1").toDouble();
        double fT12 = getXPath(pXmlDoc, aPath + "/Line1", "column2").toDouble();
        double fT21 = getXPath(pXmlDoc, aPath + "/Line2", "column1").toDouble();
        double fT22 = getXPath(pXmlDoc, aPath + "/Line2", "column2").toDouble();

        CPPUNIT_ASSERT_DOUBLES_EQUAL(fT11, -fT21, 1e-8);
        CPPUNIT_ASSERT_DOUBLES_EQUAL(fT12, fT22, 1e-8);
    }
    {
        OString aPath("//XShape[@text='Dec-12']/Transformation");
        assertXPath(pXmlDoc, aPath, 1);
        double fT11 = getXPath(pXmlDoc, aPath + "/Line1", "column1").toDouble();
        double fT12 = getXPath(pXmlDoc, aPath + "/Line1", "column2").toDouble();
        double fT21 = getXPath(pXmlDoc, aPath + "/Line2", "column1").toDouble();
        double fT22 = getXPath(pXmlDoc, aPath + "/Line2", "column2").toDouble();

        CPPUNIT_ASSERT_DOUBLES_EQUAL(fT11, -fT21, 1e-8);
        CPPUNIT_ASSERT_DOUBLES_EQUAL(fT12, fT22, 1e-8);
    }
    {
        OString aPath("//XShape[@text='May-13']/Transformation");
        assertXPath(pXmlDoc, aPath, 1);
        double fT11 = getXPath(pXmlDoc, aPath + "/Line1", "column1").toDouble();
        double fT12 = getXPath(pXmlDoc, aPath + "/Line1", "column2").toDouble();
        double fT21 = getXPath(pXmlDoc, aPath + "/Line2", "column1").toDouble();
        double fT22 = getXPath(pXmlDoc, aPath + "/Line2", "column2").toDouble();

        CPPUNIT_ASSERT_DOUBLES_EQUAL(fT11, -fT21, 1e-8);
        CPPUNIT_ASSERT_DOUBLES_EQUAL(fT12, fT22, 1e-8);
    }
    {
        OString aPath("//XShape[@text='Jan-14']/Transformation");
        assertXPath(pXmlDoc, aPath, 1);
        double fT11 = getXPath(pXmlDoc, aPath + "/Line1", "column1").toDouble();
        double fT12 = getXPath(pXmlDoc, aPath + "/Line1", "column2").toDouble();
        double fT21 = getXPath(pXmlDoc, aPath + "/Line2", "column1").toDouble();
        double fT22 = getXPath(pXmlDoc, aPath + "/Line2", "column2").toDouble();

        CPPUNIT_ASSERT_DOUBLES_EQUAL(fT11, -fT21, 1e-8);
        CPPUNIT_ASSERT_DOUBLES_EQUAL(fT12, fT22, 1e-8);
    }
}

CPPUNIT_TEST_SUITE_REGISTRATION(Chart2XShapeTest);

CPPUNIT_PLUGIN_IMPLEMENT();

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