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) 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
)
65 // force locale (and resource files loaded) to en-US
66 const LanguageType eLang
=LANGUAGE_ENGLISH_US
;
68 rtl::OUString aLang
, aCountry
;
69 MsLangId::convertLanguageToIsoNames(eLang
, aLang
, aCountry
);
70 lang::Locale
aLocale(aLang
, aCountry
, rtl::OUString());
71 ResMgr::SetDefaultLocale( aLocale
);
74 void test::BootstrapFixture::setUp()
76 test::BootstrapFixtureBase::setUp();
79 // initialise UCB-Broker
80 uno::Sequence
<uno::Any
> aUcbInitSequence(2);
81 aUcbInitSequence
[0] <<= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Local"));
82 aUcbInitSequence
[1] <<= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Office"));
83 bool bInitUcb
= ucbhelper::ContentBroker::initialize(m_xSFactory
, aUcbInitSequence
);
84 CPPUNIT_ASSERT_MESSAGE("Should be able to initialize UCB", bInitUcb
);
86 uno::Reference
<ucb::XContentProviderManager
> xUcb
=
87 ucbhelper::ContentBroker::get()->getContentProviderManagerInterface();
88 uno::Reference
<ucb::XContentProvider
> xFileProvider(m_xSFactory
->createInstance(
89 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.ucb.FileContentProvider"))), uno::UNO_QUERY
);
90 xUcb
->registerContentProvider(xFileProvider
, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("file")), sal_True
);
93 SvtSysLocaleOptions aLocalOptions
;
94 rtl::OUString aLangISO
= MsLangId::convertLanguageToIsoString( LANGUAGE_ENGLISH_US
);
95 aLocalOptions
.SetLocaleConfigString( aLangISO
);
96 aLocalOptions
.SetUILocaleConfigString( aLangISO
);
100 if( m_bAssertOnDialog
)
101 ErrorHandler::RegisterDisplay( aBasicErrorFunc
);
104 void test::BootstrapFixture::tearDown()
106 ucbhelper::ContentBroker::get()->deinitialize();
107 test::BootstrapFixtureBase::tearDown();
110 test::BootstrapFixture::~BootstrapFixture()
114 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */