1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
9 #include <test/bootstrapfixture.hxx>
10 #include <tools/errinf.hxx>
11 #include <rtl/strbuf.hxx>
12 #include <rtl/bootstrap.hxx>
13 #include <cppuhelper/bootstrap.hxx>
14 #include <comphelper/processfactory.hxx>
16 #include <com/sun/star/lang/Locale.hpp>
17 #include <com/sun/star/lang/XComponent.hpp>
18 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
19 #include <com/sun/star/ucb/XContentProvider.hpp>
20 #include <com/sun/star/ucb/XUniversalContentBroker.hpp>
22 #include <vcl/svapp.hxx>
23 #include <tools/resmgr.hxx>
24 #include <vcl/graphicfilter.hxx>
25 #include <unotools/syslocaleoptions.hxx>
27 using namespace ::com::sun::star
;
29 static void aBasicErrorFunc( const OUString
&rErr
, const OUString
&rAction
)
31 OStringBuffer
aErr( "Unexpected dialog: " );
32 aErr
.append( OUStringToOString( rAction
, RTL_TEXTENCODING_ASCII_US
) );
33 aErr
.append( " Error: " );
34 aErr
.append( OUStringToOString( rErr
, RTL_TEXTENCODING_ASCII_US
) );
35 CPPUNIT_ASSERT_MESSAGE( aErr
.getStr(), false);
38 // NB. this constructor is called before any tests are run, once for each
39 // test function in a rather non-intuitive way. This is why all the 'real'
40 // heavy lifting is deferred until setUp. setUp and tearDown are interleaved
41 // between the tests as you might expect.
42 test::BootstrapFixture::BootstrapFixture( bool bAssertOnDialog
, bool bNeedUCB
)
43 : m_bNeedUCB( bNeedUCB
)
44 , m_bAssertOnDialog( bAssertOnDialog
)
51 void test_init_impl(bool bAssertOnDialog
, bool bNeedUCB
,
52 lang::XMultiServiceFactory
* pSFactory
)
54 // force locale (and resource files loaded) to en-US
55 OUString
aLangISO( "en-US" );
56 ResMgr::SetDefaultLocale( LanguageTag( aLangISO
) );
58 SvtSysLocaleOptions aLocalOptions
;
59 aLocalOptions
.SetLocaleConfigString( aLangISO
);
60 aLocalOptions
.SetUILocaleConfigString( aLangISO
);
63 if (Application::IsHeadlessModeRequested())
64 Application::EnableHeadlessMode(true);
67 ErrorHandler::RegisterDisplay( aBasicErrorFunc
);
69 // Make GraphicConverter work, normally done in desktop::Desktop::Main()
70 Application::SetFilterHdl(
71 STATIC_LINK(0, test::BootstrapFixture
, ImplInitFilterHdl
));
75 // initialise unconfigured UCB:
76 uno::Reference
<ucb::XUniversalContentBroker
> xUcb(pSFactory
->createInstance("com.sun.star.ucb.UniversalContentBroker"), uno::UNO_QUERY_THROW
);
77 uno::Reference
<ucb::XContentProvider
> xFileProvider(pSFactory
->createInstance("com.sun.star.ucb.FileContentProvider"), uno::UNO_QUERY_THROW
);
78 xUcb
->registerContentProvider(xFileProvider
, "file", sal_True
);
79 uno::Reference
<ucb::XContentProvider
> xTdocProvider(pSFactory
->createInstance("com.sun.star.ucb.TransientDocumentsContentProvider"), uno::UNO_QUERY
);
80 if (xTdocProvider
.is())
82 xUcb
->registerContentProvider(xTdocProvider
, "vnd.sun.star.tdoc", sal_True
);
87 // this is called from pyuno
88 SAL_DLLPUBLIC_EXPORT
void test_init(lang::XMultiServiceFactory
*pFactory
)
92 ::comphelper::setProcessServiceFactory(pFactory
);
93 test_init_impl(false, true, pFactory
);
95 catch (...) { abort(); }
100 void test::BootstrapFixture::setUp()
102 test::BootstrapFixtureBase::setUp();
104 test_init_impl(m_bAssertOnDialog
, m_bNeedUCB
, m_xSFactory
.get());
107 void test::BootstrapFixture::tearDown()
109 test::BootstrapFixtureBase::tearDown();
112 test::BootstrapFixture::~BootstrapFixture()
116 IMPL_STATIC_LINK_NOINSTANCE(
117 test::BootstrapFixture
, ImplInitFilterHdl
, ConvertData
*, pData
)
119 return GraphicFilter::GetGraphicFilter().GetFilterCallback().Call( pData
);
122 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */