fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / sc / qa / extras / regression-test.cxx
blob9c6cbcbc4f18f1dd870aa558efc994b3fb1a4bc7
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/bootstrapfixture.hxx>
12 #include <unotest/macros_test.hxx>
13 #include <rtl/strbuf.hxx>
14 #include <osl/file.hxx>
16 #include <sfx2/app.hxx>
17 #include <sfx2/docfilt.hxx>
18 #include <sfx2/docfile.hxx>
19 #include <sfx2/sfxmodelfactory.hxx>
20 #include <svl/intitem.hxx>
22 #include <com/sun/star/frame/Desktop.hpp>
23 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
24 #include <com/sun/star/sheet/XSpreadsheet.hpp>
25 #include <com/sun/star/container/XIndexAccess.hpp>
26 #include <com/sun/star/table/XTableChartsSupplier.hpp>
27 #include <com/sun/star/table/XTableCharts.hpp>
28 #include <com/sun/star/table/XTableChart.hpp>
29 #include <com/sun/star/document/XEmbeddedObjectSupplier.hpp>
30 #include <com/sun/star/chart2/XChartDocument.hpp>
31 #include <com/sun/star/qa/XDumper.hpp>
33 #include <test/xmldiff.hxx>
35 #include <basic/sbxdef.hxx>
37 #include "docsh.hxx"
38 #include "patattr.hxx"
39 #include "scitems.hxx"
40 #include "document.hxx"
42 using namespace ::com::sun::star;
43 using namespace ::com::sun::star::uno;
45 namespace {
47 bool checkDumpAgainstFile( const OUString& rDump, const OUString aFilePath, const OUString& rToleranceFile)
49 OString aOFile = OUStringToOString(aFilePath, RTL_TEXTENCODING_UTF8);
50 OString aToleranceFile = OUStringToOString(rToleranceFile, RTL_TEXTENCODING_UTF8);
52 CPPUNIT_ASSERT_MESSAGE("dump is empty", !rDump.isEmpty());
54 OString aDump = OUStringToOString(rDump, RTL_TEXTENCODING_UTF8);
55 return doXMLDiff(aOFile.getStr(), aDump.getStr(),
56 static_cast<int>(rDump.getLength()), aToleranceFile.getStr());
61 class ScChartRegressionTest : public test::BootstrapFixture, public unotest::MacrosTest
63 public:
64 ScChartRegressionTest();
66 void createFileURL(const OUString& aFileBase, const OUString& aFileExtension, OUString& rFilePath);
68 virtual void setUp();
69 virtual void tearDown();
71 void test();
73 CPPUNIT_TEST_SUITE(ScChartRegressionTest);
74 CPPUNIT_TEST(test);
75 CPPUNIT_TEST_SUITE_END();
77 private:
78 uno::Reference<uno::XInterface> m_xCalcComponent;
79 OUString m_aBaseString;
83 void ScChartRegressionTest::createFileURL(const OUString& aFileBase, const OUString& aFileExtension, OUString& rFilePath)
85 OUString aSep("/");
86 OUStringBuffer aBuffer( getSrcRootURL() );
87 aBuffer.append(m_aBaseString).append(aSep).append(aFileExtension);
88 aBuffer.append(aSep).append(aFileBase).append(aFileExtension);
89 rFilePath = aBuffer.makeStringAndClear();
92 void ScChartRegressionTest::test()
94 OUString aFileName;
95 createFileURL( "testChart.", "ods", aFileName);
96 uno::Reference< com::sun::star::lang::XComponent > xComponent = loadFromDesktop(aFileName, "com.sun.star.sheet.SpreadsheetDocument");
98 CPPUNIT_ASSERT(xComponent.is());
100 uno::Reference< sheet::XSpreadsheetDocument > xDoc(xComponent, UNO_QUERY_THROW);
101 CPPUNIT_ASSERT(xDoc.is());
103 uno::Reference< container::XIndexAccess > xIA(xDoc->getSheets(), UNO_QUERY_THROW);
104 CPPUNIT_ASSERT(xIA.is());
106 uno::Reference< table::XTableChartsSupplier > xChartSupplier( xIA->getByIndex(0), UNO_QUERY_THROW);
107 CPPUNIT_ASSERT(xChartSupplier.is());
109 uno::Reference< table::XTableCharts > xCharts = xChartSupplier->getCharts();
110 CPPUNIT_ASSERT(xCharts.is());
112 uno::Reference< container::XIndexAccess > xIACharts(xCharts, UNO_QUERY_THROW);
113 uno::Reference< table::XTableChart > xChart( xIACharts->getByIndex(0), UNO_QUERY_THROW);
114 CPPUNIT_ASSERT(xChart.is());
116 uno::Reference< document::XEmbeddedObjectSupplier > xEmbObjectSupplier(xChart, UNO_QUERY_THROW);
117 CPPUNIT_ASSERT(xEmbObjectSupplier.is());
119 uno::Reference< lang::XComponent > xChartComp( xEmbObjectSupplier->getEmbeddedObject(), UNO_QUERY_THROW );
120 CPPUNIT_ASSERT(xChartComp.is());
122 uno::Reference< chart2::XChartDocument > xChartDoc ( xChartComp, UNO_QUERY_THROW );
123 CPPUNIT_ASSERT(xChartDoc.is());
125 uno::Reference< qa::XDumper > xDumper( xChartDoc, UNO_QUERY_THROW );
126 CPPUNIT_ASSERT(xDumper.is());
128 OUString aDump = xDumper->dump();
129 std::cout << aDump;
130 bool bCompare = checkDumpAgainstFile( aDump, getPathFromSrc("/chart2/qa/unit/data/reference/testChart.xml"), getPathFromSrc("/chart2/qa/unit/data/tolerance.xml") );
131 CPPUNIT_ASSERT(bCompare);
134 ScChartRegressionTest::ScChartRegressionTest()
135 : m_aBaseString(RTL_CONSTASCII_USTRINGPARAM("/chart2/qa/unit/data"))
139 void ScChartRegressionTest::setUp()
141 test::BootstrapFixture::setUp();
143 // This is a bit of a fudge, we do this to ensure that ScGlobals::ensure,
144 // which is a private symbol to us, gets called
145 m_xCalcComponent =
146 getMultiServiceFactory()->createInstance(OUString("com.sun.star.comp.Calc.SpreadsheetDocument"));
147 CPPUNIT_ASSERT_MESSAGE("no calc component!", m_xCalcComponent.is());
148 mxDesktop = com::sun::star::frame::Desktop::create( comphelper::getComponentContext(getMultiServiceFactory()) );
151 void ScChartRegressionTest::tearDown()
153 uno::Reference< lang::XComponent >( m_xCalcComponent, UNO_QUERY_THROW )->dispose();
154 test::BootstrapFixture::tearDown();
157 CPPUNIT_TEST_SUITE_REGISTRATION(ScChartRegressionTest);
159 CPPUNIT_PLUGIN_IMPLEMENT();
161 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */