Version 6.4.0.3, tag libreoffice-6.4.0.3
[LibreOffice.git] / sc / qa / extras / regression-test.cxx
blob27b85ece8a48d94ae22ff125cf04126b21604c7f
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 <sal/config.h>
11 #include <test/unoapi_test.hxx>
12 #include <rtl/strbuf.hxx>
13 #include <osl/file.hxx>
15 #include <sfx2/app.hxx>
16 #include <sfx2/docfilt.hxx>
17 #include <sfx2/docfile.hxx>
18 #include <sfx2/sfxmodelfactory.hxx>
19 #include <svl/intitem.hxx>
21 #include <com/sun/star/frame/Desktop.hpp>
22 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
23 #include <com/sun/star/sheet/XSpreadsheet.hpp>
24 #include <com/sun/star/container/XIndexAccess.hpp>
25 #include <com/sun/star/table/XTableChartsSupplier.hpp>
26 #include <com/sun/star/table/XTableCharts.hpp>
27 #include <com/sun/star/table/XTableChart.hpp>
28 #include <com/sun/star/document/XEmbeddedObjectSupplier.hpp>
29 #include <com/sun/star/chart2/XChartDocument.hpp>
30 #include <com/sun/star/qa/XDumper.hpp>
32 #include <test/xmldiff.hxx>
34 #include <basic/sbxdef.hxx>
36 #include "docsh.hxx"
37 #include "patattr.hxx"
38 #include "scitems.hxx"
39 #include "document.hxx"
41 using namespace ::com::sun::star;
42 using namespace ::com::sun::star::uno;
44 namespace {
46 bool checkDumpAgainstFile( const OUString& rDump, const OUString aFilePath, const OUString& rToleranceFile)
48 OString aOFile = OUStringToOString(aFilePath, RTL_TEXTENCODING_UTF8);
49 OString aToleranceFile = OUStringToOString(rToleranceFile, RTL_TEXTENCODING_UTF8);
51 CPPUNIT_ASSERT_MESSAGE("dump is empty", !rDump.isEmpty());
53 OString aDump = OUStringToOString(rDump, RTL_TEXTENCODING_UTF8);
54 return doXMLDiff(aOFile.getStr(), aDump.getStr(),
55 static_cast<int>(rDump.getLength()), aToleranceFile.getStr());
60 class ScChartRegressionTest : public UnoApiTest
62 public:
63 ScChartRegressionTest();
65 void test();
67 CPPUNIT_TEST_SUITE(ScChartRegressionTest);
68 CPPUNIT_TEST(test);
69 CPPUNIT_TEST_SUITE_END();
73 void ScChartRegressionTest::test()
75 OUString aFileName;
76 createFileURL( "testChart.ods", aFileName);
77 uno::Reference< css::lang::XComponent > xComponent = loadFromDesktop(aFileName, "com.sun.star.sheet.SpreadsheetDocument");
79 CPPUNIT_ASSERT(xComponent.is());
81 uno::Reference< sheet::XSpreadsheetDocument > xDoc(xComponent, UNO_QUERY_THROW);
83 uno::Reference< container::XIndexAccess > xIA(xDoc->getSheets(), UNO_QUERY_THROW);
85 uno::Reference< table::XTableChartsSupplier > xChartSupplier( xIA->getByIndex(0), UNO_QUERY_THROW);
87 uno::Reference< table::XTableCharts > xCharts = xChartSupplier->getCharts();
88 CPPUNIT_ASSERT(xCharts.is());
90 uno::Reference< container::XIndexAccess > xIACharts(xCharts, UNO_QUERY_THROW);
91 uno::Reference< table::XTableChart > xChart( xIACharts->getByIndex(0), UNO_QUERY_THROW);
93 uno::Reference< document::XEmbeddedObjectSupplier > xEmbObjectSupplier(xChart, UNO_QUERY_THROW);
95 uno::Reference< lang::XComponent > xChartComp( xEmbObjectSupplier->getEmbeddedObject(), UNO_QUERY_THROW );
97 uno::Reference< chart2::XChartDocument > xChartDoc ( xChartComp, UNO_QUERY_THROW );
99 uno::Reference< qa::XDumper > xDumper( xChartDoc, UNO_QUERY_THROW );
101 OUString aDump = xDumper->dump();
102 std::cout << aDump;
103 bool bCompare = checkDumpAgainstFile( aDump, getPathFromSrc("/chart2/qa/unit/data/reference/testChart.xml"), getPathFromSrc("/chart2/qa/unit/data/tolerance.xml") );
104 CPPUNIT_ASSERT(bCompare);
107 ScChartRegressionTest::ScChartRegressionTest()
108 : UnoApiTest("/chart2/qa/unit/data/ods")
112 CPPUNIT_TEST_SUITE_REGISTRATION(ScChartRegressionTest);
114 CPPUNIT_PLUGIN_IMPLEMENT();
116 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */