1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * Version: MPL 1.1 / GPLv3+ / LGPLv3+
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License or as specified alternatively below. You may obtain a copy of
8 * the License at http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * Major Contributor(s):
16 * Copyright (C) 2010 Red Hat, Inc., Caolán McNamara <caolanm@redhat.com>
18 * Copyright (C) 2011 Markus Mohrhard <markus.mohrhard@googlemail.com>
20 * All Rights Reserved.
22 * For minor contributions see the git repository.
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
26 * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
27 * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
28 * instead of those above.
31 #include <sal/config.h>
32 #include <test/bootstrapfixture.hxx>
33 #include <unotest/macros_test.hxx>
34 #include <rtl/strbuf.hxx>
35 #include <osl/file.hxx>
37 #include <sfx2/app.hxx>
38 #include <sfx2/docfilt.hxx>
39 #include <sfx2/docfile.hxx>
40 #include <sfx2/sfxmodelfactory.hxx>
41 #include <svl/intitem.hxx>
43 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
44 #include <com/sun/star/sheet/XSpreadsheet.hpp>
45 #include <com/sun/star/container/XIndexAccess.hpp>
46 #include <com/sun/star/table/XTableChartsSupplier.hpp>
47 #include <com/sun/star/table/XTableCharts.hpp>
48 #include <com/sun/star/table/XTableChart.hpp>
49 #include <com/sun/star/document/XEmbeddedObjectSupplier.hpp>
50 #include <com/sun/star/chart2/XChartDocument.hpp>
51 #include <com/sun/star/qa/XDumper.hpp>
53 #include <test/xmldiff.hxx>
55 #include <basic/sbxdef.hxx>
58 #include "patattr.hxx"
59 #include "scitems.hxx"
60 #include "document.hxx"
62 using namespace ::com::sun::star
;
63 using namespace ::com::sun::star::uno
;
67 bool checkDumpAgainstFile( const rtl::OUString
& rDump
, const rtl::OUString aFilePath
, const rtl::OUString
& rToleranceFile
)
69 rtl::OString aOFile
= rtl::OUStringToOString(aFilePath
, RTL_TEXTENCODING_UTF8
);
70 rtl::OString aToleranceFile
= rtl::OUStringToOString(rToleranceFile
, RTL_TEXTENCODING_UTF8
);
72 CPPUNIT_ASSERT_MESSAGE("dump is empty", !rDump
.isEmpty());
74 rtl::OString aDump
= rtl::OUStringToOString(rDump
, RTL_TEXTENCODING_UTF8
);
75 return doXMLDiff(aOFile
.getStr(), aDump
.getStr(),
76 static_cast<int>(rDump
.getLength()), aToleranceFile
.getStr());
81 class ScChartRegressionTest
: public test::BootstrapFixture
, public unotest::MacrosTest
84 ScChartRegressionTest();
86 void createFileURL(const rtl::OUString
& aFileBase
, const rtl::OUString
& aFileExtension
, rtl::OUString
& rFilePath
);
89 virtual void tearDown();
93 CPPUNIT_TEST_SUITE(ScChartRegressionTest
);
95 CPPUNIT_TEST_SUITE_END();
98 uno::Reference
<uno::XInterface
> m_xCalcComponent
;
99 rtl::OUString m_aBaseString
;
103 void ScChartRegressionTest::createFileURL(const rtl::OUString
& aFileBase
, const rtl::OUString
& aFileExtension
, rtl::OUString
& rFilePath
)
105 rtl::OUString
aSep(RTL_CONSTASCII_USTRINGPARAM("/"));
106 rtl::OUStringBuffer
aBuffer( getSrcRootURL() );
107 aBuffer
.append(m_aBaseString
).append(aSep
).append(aFileExtension
);
108 aBuffer
.append(aSep
).append(aFileBase
).append(aFileExtension
);
109 rFilePath
= aBuffer
.makeStringAndClear();
112 void ScChartRegressionTest::test()
114 rtl::OUString aFileName
;
115 createFileURL( "testChart.", "ods", aFileName
);
116 uno::Reference
< com::sun::star::lang::XComponent
> xComponent
= loadFromDesktop(aFileName
);
118 CPPUNIT_ASSERT(xComponent
.is());
120 uno::Reference
< sheet::XSpreadsheetDocument
> xDoc(xComponent
, UNO_QUERY_THROW
);
121 CPPUNIT_ASSERT(xDoc
.is());
123 uno::Reference
< container::XIndexAccess
> xIA(xDoc
->getSheets(), UNO_QUERY_THROW
);
124 CPPUNIT_ASSERT(xIA
.is());
126 uno::Reference
< table::XTableChartsSupplier
> xChartSupplier( xIA
->getByIndex(0), UNO_QUERY_THROW
);
127 CPPUNIT_ASSERT(xChartSupplier
.is());
129 uno::Reference
< table::XTableCharts
> xCharts
= xChartSupplier
->getCharts();
130 CPPUNIT_ASSERT(xCharts
.is());
132 uno::Reference
< container::XIndexAccess
> xIACharts(xCharts
, UNO_QUERY_THROW
);
133 uno::Reference
< table::XTableChart
> xChart( xIACharts
->getByIndex(0), UNO_QUERY_THROW
);
134 CPPUNIT_ASSERT(xChart
.is());
136 uno::Reference
< document::XEmbeddedObjectSupplier
> xEmbObjectSupplier(xChart
, UNO_QUERY_THROW
);
137 CPPUNIT_ASSERT(xEmbObjectSupplier
.is());
139 uno::Reference
< lang::XComponent
> xChartComp( xEmbObjectSupplier
->getEmbeddedObject(), UNO_QUERY_THROW
);
140 CPPUNIT_ASSERT(xChartComp
.is());
142 uno::Reference
< chart2::XChartDocument
> xChartDoc ( xChartComp
, UNO_QUERY_THROW
);
143 CPPUNIT_ASSERT(xChartDoc
.is());
145 uno::Reference
< qa::XDumper
> xDumper( xChartDoc
, UNO_QUERY_THROW
);
146 CPPUNIT_ASSERT(xDumper
.is());
148 rtl::OUString aDump
= xDumper
->dump();
150 bool bCompare
= checkDumpAgainstFile( aDump
, getPathFromSrc("/chart2/qa/unit/data/reference/testChart.xml"), getPathFromSrc("/chart2/qa/unit/data/tolerance.xml") );
151 CPPUNIT_ASSERT(bCompare
);
154 ScChartRegressionTest::ScChartRegressionTest()
155 : m_aBaseString(RTL_CONSTASCII_USTRINGPARAM("/chart2/qa/unit/data"))
159 void ScChartRegressionTest::setUp()
161 test::BootstrapFixture::setUp();
163 // This is a bit of a fudge, we do this to ensure that ScGlobals::ensure,
164 // which is a private symbol to us, gets called
166 getMultiServiceFactory()->createInstance(rtl::OUString(
167 RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.Calc.SpreadsheetDocument")));
168 CPPUNIT_ASSERT_MESSAGE("no calc component!", m_xCalcComponent
.is());
169 mxDesktop
= Reference
<com::sun::star::frame::XDesktop
>( getMultiServiceFactory()->createInstance(
170 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.frame.Desktop" ))), UNO_QUERY
);
171 CPPUNIT_ASSERT(mxDesktop
.is());
174 void ScChartRegressionTest::tearDown()
176 uno::Reference
< lang::XComponent
>( m_xCalcComponent
, UNO_QUERY_THROW
)->dispose();
177 test::BootstrapFixture::tearDown();
180 CPPUNIT_TEST_SUITE_REGISTRATION(ScChartRegressionTest
);
182 CPPUNIT_PLUGIN_IMPLEMENT();
184 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */