tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / chart2 / qa / extras / xshape / chart2xshape.cxx
blobca945c8baa293a13345c33a17c7e54bdfa67d244
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>
11 #include <com/sun/star/chart/XChartDocument.hpp>
13 #include <com/sun/star/qa/XDumper.hpp>
15 #include <test/xmldiff.hxx>
16 #include <test/xmltesttools.hxx>
18 #include <fstream>
19 #include <string_view>
21 class Chart2XShapeTest : public ChartTest
23 public:
24 Chart2XShapeTest()
25 : ChartTest(u"/chart2/qa/extras/xshape/data/"_ustr)
29 void testTdf150832();
30 void testTdf149204();
31 void testTdf151424();
32 void testFdo75075();
33 void testPropertyMappingBarChart();
34 void testPieChartLabels1();
35 void testPieChartLabels2();
36 void testPieChartLabels3();
37 void testPieChartLabels4();
38 void testChart();
39 void testTdf76649TrendLineBug();
40 void testTdf88154LabelRotatedLayout();
42 CPPUNIT_TEST_SUITE(Chart2XShapeTest);
43 CPPUNIT_TEST(testTdf150832);
44 CPPUNIT_TEST(testTdf149204);
45 CPPUNIT_TEST(testTdf151424);
46 CPPUNIT_TEST(testFdo75075);
47 CPPUNIT_TEST(testPropertyMappingBarChart);
48 CPPUNIT_TEST(testPieChartLabels1);
49 CPPUNIT_TEST(testPieChartLabels2);
50 CPPUNIT_TEST(testPieChartLabels3);
51 CPPUNIT_TEST(testPieChartLabels4);
52 CPPUNIT_TEST(testChart);
53 CPPUNIT_TEST(testTdf76649TrendLineBug);
54 CPPUNIT_TEST(testTdf88154LabelRotatedLayout);
56 CPPUNIT_TEST_SUITE_END();
58 private:
59 void compareAgainstReference(std::u16string_view rDump, std::u16string_view rReferenceFile);
60 OUString getXShapeDumpString();
61 xmlDocUniquePtr getXShapeDumpXmlDoc();
64 namespace
66 OUString getShapeDump(css::uno::Reference<css::chart::XChartDocument> const& doc)
68 return css::uno::Reference<css::qa::XDumper>(doc, css::uno::UNO_QUERY_THROW)
69 ->dump(u"shapes"_ustr);
72 bool checkDumpAgainstFile(std::u16string_view rDump, std::u16string_view aFilePath,
73 char const* toleranceFile)
75 OString aOFile = OUStringToOString(aFilePath, RTL_TEXTENCODING_UTF8);
77 CPPUNIT_ASSERT_MESSAGE("dump is empty", !rDump.empty());
79 OString aDump = OUStringToOString(rDump, RTL_TEXTENCODING_UTF8);
80 return doXMLDiff(aOFile.getStr(), aDump.getStr(), static_cast<int>(rDump.size()),
81 toleranceFile);
85 OUString Chart2XShapeTest::getXShapeDumpString()
87 uno::Reference<chart::XChartDocument> xChartDoc(getChartCompFromSheet(0, 0), UNO_QUERY_THROW);
88 return getShapeDump(xChartDoc);
91 xmlDocUniquePtr Chart2XShapeTest::getXShapeDumpXmlDoc()
93 OUString rDump = getXShapeDumpString();
94 OString aXmlDump = OUStringToOString(rDump, RTL_TEXTENCODING_UTF8);
95 return xmlDocUniquePtr(xmlParseDoc(reinterpret_cast<const xmlChar*>(aXmlDump.getStr())));
98 void Chart2XShapeTest::compareAgainstReference(std::u16string_view rDump,
99 std::u16string_view rReferenceFile)
101 checkDumpAgainstFile(
102 rDump,
103 Concat2View(m_directories.getPathFromSrc(u"/chart2/qa/extras/xshape/data/reference/")
104 + rReferenceFile),
105 OUStringToOString(
106 m_directories.getPathFromSrc(u"/chart2/qa/extras/xshape/data/reference/tolerance.xml"),
107 RTL_TEXTENCODING_UTF8)
108 .getStr());
111 void Chart2XShapeTest::testTdf150832()
113 // FIXME: the DPI check should be removed when either (1) the test is fixed to work with
114 // non-default DPI; or (2) unit tests on Windows are made to use svp VCL plugin.
115 if (!IsDefaultDPI())
116 return;
118 // Without the fix in place, this test would have failed with
119 // - Expected: 319
120 // - Actual : 0
121 loadFromFile(u"xls/tdf150832.xls");
122 compareAgainstReference(getXShapeDumpString(), u"tdf150832.xml");
125 void Chart2XShapeTest::testTdf149204()
127 // FIXME: the DPI check should be removed when either (1) the test is fixed to work with
128 // non-default DPI; or (2) unit tests on Windows are made to use svp VCL plugin.
129 if (!IsDefaultDPI())
130 return;
132 // Without the fix in place, this test would have failed with
133 // - Expected: 12230
134 // - Actual : 12940
135 // - Node: /XShapes/XShape[2]
136 // - Attr: sizeX
137 loadFromFile(u"pptx/tdf149204.pptx");
138 uno::Reference<chart::XChartDocument> xChartDoc = getChartDocFromDrawImpress(0, 0);
139 compareAgainstReference(getShapeDump(xChartDoc), u"tdf149204.xml");
142 void Chart2XShapeTest::testTdf151424()
144 // FIXME: the DPI check should be removed when either (1) the test is fixed to work with
145 // non-default DPI; or (2) unit tests on Windows are made to use svp VCL plugin.
146 if (!IsDefaultDPI())
147 return;
149 // Without the fix in place, this test would have failed with
150 // - Expected: 3717
151 // - Actual : 3530
152 // - Node: /XShapes/XShape[2]/XShapes/XShape[1]
153 // - Attr: positionX
154 loadFromFile(u"ods/tdf151424.ods");
155 compareAgainstReference(getXShapeDumpString(), u"tdf151424.xml");
158 void Chart2XShapeTest::testFdo75075()
160 // FIXME: the DPI check should be removed when either (1) the test is fixed to work with
161 // non-default DPI; or (2) unit tests on Windows are made to use svp VCL plugin.
162 if (!IsDefaultDPI())
163 return;
165 loadFromFile(u"ods/fdo75075.ods");
166 compareAgainstReference(getXShapeDumpString(), u"fdo75075.xml");
169 void Chart2XShapeTest::testPropertyMappingBarChart()
171 // FIXME: the DPI check should be removed when either (1) the test is fixed to work with
172 // non-default DPI; or (2) unit tests on Windows are made to use svp VCL plugin.
173 if (!IsDefaultDPI())
174 return;
176 loadFromFile(u"ods/property-mapping-bar.ods");
177 compareAgainstReference(getXShapeDumpString(), u"property-mapping-bar.xml");
180 void Chart2XShapeTest::testPieChartLabels1()
182 // FIXME: the DPI check should be removed when either (1) the test is fixed to work with
183 // non-default DPI; or (2) unit tests on Windows are made to use svp VCL plugin.
184 if (!IsDefaultDPI())
185 return;
187 // inside placement for the best fit case
188 loadFromFile(u"xlsx/tdf90839-1.xlsx");
189 compareAgainstReference(getXShapeDumpString(), u"tdf90839-1.xml");
192 void Chart2XShapeTest::testPieChartLabels2()
194 // FIXME: the DPI check should be removed when either (1) the test is fixed to work with
195 // non-default DPI; or (2) unit tests on Windows are made to use svp VCL plugin.
196 if (!IsDefaultDPI())
197 return;
199 // text wrap: wrap all text labels except Yellow one
200 loadFromFile(u"xlsx/tdf90839-2.xlsx");
201 compareAgainstReference(getXShapeDumpString(), u"tdf90839-2.xml");
204 void Chart2XShapeTest::testPieChartLabels3()
206 // FIXME: the DPI check should be removed when either (1) the test is fixed to work with
207 // non-default DPI; or (2) unit tests on Windows are made to use svp VCL plugin.
208 if (!IsDefaultDPI())
209 return;
211 // text wrap: wrap no text label except Yellow one
212 loadFromFile(u"xlsx/tdf90839-3.xlsx");
213 compareAgainstReference(getXShapeDumpString(), u"tdf90839-3.xml");
216 void Chart2XShapeTest::testPieChartLabels4()
218 // FIXME: the DPI check should be removed when either (1) the test is fixed to work with
219 // non-default DPI; or (2) unit tests on Windows are made to use svp VCL plugin.
220 if (!IsDefaultDPI())
221 return;
223 // data value and percent value are centered horizontally
224 loadFromFile(u"ods/tdf90839-4.ods");
225 compareAgainstReference(getXShapeDumpString(), u"tdf90839-4.xml");
228 void Chart2XShapeTest::testChart()
230 // FIXME: the DPI check should be removed when either (1) the test is fixed to work with
231 // non-default DPI; or (2) unit tests on Windows are made to use svp VCL plugin.
232 if (!IsDefaultDPI())
233 return;
235 loadFromFile(u"ods/testChart.ods");
236 compareAgainstReference(getXShapeDumpString(), u"testChart.xml");
239 void Chart2XShapeTest::testTdf76649TrendLineBug()
241 // This bug prevents that the trendline (regression curve) is drawn
242 // if the first cell is empty. See tdf#76649 for details.
244 loadFromFile(u"ods/tdf76649_TrendLineBug.ods");
246 xmlDocUniquePtr pXmlDoc = getXShapeDumpXmlDoc();
248 // Check if the regression curve exists (which means a XShape with a certain
249 // name should exist in the dump)
250 assertXPath(pXmlDoc, "//XShape[@name='CID/D=0:CS=0:CT=0:Series=0:Curve=0']", 1);
253 void Chart2XShapeTest::testTdf88154LabelRotatedLayout()
255 loadFromFile(u"pptx/tdf88154_LabelRotatedLayout.pptx");
256 uno::Reference<chart::XChartDocument> xChartDoc = getChartDocFromDrawImpress(0, 5);
257 OUString rDump = getShapeDump(xChartDoc);
258 OString aXmlDump = OUStringToOString(rDump, RTL_TEXTENCODING_UTF8);
259 xmlDocUniquePtr pXmlDoc(xmlParseDoc(reinterpret_cast<const xmlChar*>(aXmlDump.getStr())));
262 OString aPath("//XShape[@text='Oct-12']/Transformation"_ostr);
263 assertXPath(pXmlDoc, aPath, 1);
264 double fT11 = getXPath(pXmlDoc, aPath + "/Line1", "column1").toDouble();
265 double fT12 = getXPath(pXmlDoc, aPath + "/Line1", "column2").toDouble();
266 double fT21 = getXPath(pXmlDoc, aPath + "/Line2", "column1").toDouble();
267 double fT22 = getXPath(pXmlDoc, aPath + "/Line2", "column2").toDouble();
269 CPPUNIT_ASSERT_DOUBLES_EQUAL(fT11, -fT21, 1e-8);
270 CPPUNIT_ASSERT_DOUBLES_EQUAL(fT12, fT22, 1e-8);
273 OString aPath("//XShape[@text='Nov-12']/Transformation"_ostr);
274 assertXPath(pXmlDoc, aPath, 1);
275 double fT11 = getXPath(pXmlDoc, aPath + "/Line1", "column1").toDouble();
276 double fT12 = getXPath(pXmlDoc, aPath + "/Line1", "column2").toDouble();
277 double fT21 = getXPath(pXmlDoc, aPath + "/Line2", "column1").toDouble();
278 double fT22 = getXPath(pXmlDoc, aPath + "/Line2", "column2").toDouble();
280 CPPUNIT_ASSERT_DOUBLES_EQUAL(fT11, -fT21, 1e-8);
281 CPPUNIT_ASSERT_DOUBLES_EQUAL(fT12, fT22, 1e-8);
284 OString aPath("//XShape[@text='Dec-12']/Transformation"_ostr);
285 assertXPath(pXmlDoc, aPath, 1);
286 double fT11 = getXPath(pXmlDoc, aPath + "/Line1", "column1").toDouble();
287 double fT12 = getXPath(pXmlDoc, aPath + "/Line1", "column2").toDouble();
288 double fT21 = getXPath(pXmlDoc, aPath + "/Line2", "column1").toDouble();
289 double fT22 = getXPath(pXmlDoc, aPath + "/Line2", "column2").toDouble();
291 CPPUNIT_ASSERT_DOUBLES_EQUAL(fT11, -fT21, 1e-8);
292 CPPUNIT_ASSERT_DOUBLES_EQUAL(fT12, fT22, 1e-8);
295 OString aPath("//XShape[@text='May-13']/Transformation"_ostr);
296 assertXPath(pXmlDoc, aPath, 1);
297 double fT11 = getXPath(pXmlDoc, aPath + "/Line1", "column1").toDouble();
298 double fT12 = getXPath(pXmlDoc, aPath + "/Line1", "column2").toDouble();
299 double fT21 = getXPath(pXmlDoc, aPath + "/Line2", "column1").toDouble();
300 double fT22 = getXPath(pXmlDoc, aPath + "/Line2", "column2").toDouble();
302 CPPUNIT_ASSERT_DOUBLES_EQUAL(fT11, -fT21, 1e-8);
303 CPPUNIT_ASSERT_DOUBLES_EQUAL(fT12, fT22, 1e-8);
306 OString aPath("//XShape[@text='Jan-14']/Transformation"_ostr);
307 assertXPath(pXmlDoc, aPath, 1);
308 double fT11 = getXPath(pXmlDoc, aPath + "/Line1", "column1").toDouble();
309 double fT12 = getXPath(pXmlDoc, aPath + "/Line1", "column2").toDouble();
310 double fT21 = getXPath(pXmlDoc, aPath + "/Line2", "column1").toDouble();
311 double fT22 = getXPath(pXmlDoc, aPath + "/Line2", "column2").toDouble();
313 CPPUNIT_ASSERT_DOUBLES_EQUAL(fT11, -fT21, 1e-8);
314 CPPUNIT_ASSERT_DOUBLES_EQUAL(fT12, fT22, 1e-8);
318 CPPUNIT_TEST_SUITE_REGISTRATION(Chart2XShapeTest);
320 CPPUNIT_PLUGIN_IMPLEMENT();
322 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */