Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / test / source / bootstrapfixture.cxx
blobedb7b63b30a0cc77c1e770afeddd2e484cfdecb2
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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
13 * License.
15 * Major Contributor(s):
16 * Copyright (C) 2011 Michael Meeks <michael.meeks@suse.com>
17 * Caolán McNamara <caolanm@redhat.com>
19 * All Rights Reserved.
21 * For minor contributions see the git repository.
23 * Alternatively, the contents of this file may be used under the terms of
24 * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
25 * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
26 * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
27 * instead of those above.
29 #include <test/bootstrapfixture.hxx>
30 #include <tools/errinf.hxx>
31 #include <rtl/strbuf.hxx>
32 #include <rtl/bootstrap.hxx>
33 #include <cppuhelper/bootstrap.hxx>
34 #include <ucbhelper/contentbroker.hxx>
35 #include <comphelper/processfactory.hxx>
36 #include <i18npool/mslangid.hxx>
38 #include <com/sun/star/lang/Locale.hpp>
39 #include <com/sun/star/lang/XComponent.hpp>
40 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
42 #include <vcl/svapp.hxx>
43 #include <tools/resmgr.hxx>
44 #include <unotools/syslocaleoptions.hxx>
46 using namespace ::com::sun::star;
48 static void aBasicErrorFunc( const String &rErr, const String &rAction )
50 rtl::OStringBuffer aErr( "Unexpected dialog: " );
51 aErr.append( rtl::OUStringToOString( rAction, RTL_TEXTENCODING_ASCII_US ) );
52 aErr.append( " Error: " );
53 aErr.append( rtl::OUStringToOString( rErr, RTL_TEXTENCODING_ASCII_US ) );
54 CPPUNIT_ASSERT_MESSAGE( aErr.getStr(), false);
57 // NB. this constructor is called before any tests are run, once for each
58 // test function in a rather non-intuitive way. This is why all the 'real'
59 // heavy lifting is deferred until setUp. setUp and tearDown are interleaved
60 // between the tests as you might expect.
61 test::BootstrapFixture::BootstrapFixture( bool bAssertOnDialog, bool bNeedUCB )
62 : m_bNeedUCB( bNeedUCB )
63 , m_bAssertOnDialog( bAssertOnDialog )
67 void test::BootstrapFixture::setUp()
69 test::BootstrapFixtureBase::setUp();
71 // force locale (and resource files loaded) to en-US
72 const LanguageType eLang=LANGUAGE_ENGLISH_US;
74 rtl::OUString aLang, aCountry;
75 MsLangId::convertLanguageToIsoNames(eLang, aLang, aCountry);
76 lang::Locale aLocale(aLang, aCountry, rtl::OUString());
77 ResMgr::SetDefaultLocale( aLocale );
79 if (m_bNeedUCB)
81 // initialise UCB-Broker
82 uno::Sequence<uno::Any> aUcbInitSequence(2);
83 aUcbInitSequence[0] <<= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Local"));
84 aUcbInitSequence[1] <<= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Office"));
85 bool bInitUcb = ucbhelper::ContentBroker::initialize(m_xSFactory, aUcbInitSequence);
86 CPPUNIT_ASSERT_MESSAGE("Should be able to initialize UCB", bInitUcb);
88 uno::Reference<ucb::XContentProviderManager> xUcb =
89 ucbhelper::ContentBroker::get()->getContentProviderManagerInterface();
90 uno::Reference<ucb::XContentProvider> xFileProvider(m_xSFactory->createInstance(
91 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.ucb.FileContentProvider"))), uno::UNO_QUERY);
92 xUcb->registerContentProvider(xFileProvider, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("file")), sal_True);
95 SvtSysLocaleOptions aLocalOptions;
96 rtl::OUString aLangISO = MsLangId::convertLanguageToIsoString( LANGUAGE_ENGLISH_US );
97 aLocalOptions.SetLocaleConfigString( aLangISO );
98 aLocalOptions.SetUILocaleConfigString( aLangISO );
100 InitVCL(m_xSFactory);
101 if (Application::IsHeadlessModeRequested())
102 Application::EnableHeadlessMode(true);
104 if( m_bAssertOnDialog )
105 ErrorHandler::RegisterDisplay( aBasicErrorFunc );
108 void test::BootstrapFixture::tearDown()
110 ucbhelper::ContentBroker::deinitialize();
111 test::BootstrapFixtureBase::tearDown();
114 test::BootstrapFixture::~BootstrapFixture()
118 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */