LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/test/source - bootstrapfixture.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 41 49 83.7 %
Date: 2013-07-09 Functions: 9 11 81.8 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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             :  */
       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>
      15             : 
      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>
      21             : 
      22             : #include <vcl/svapp.hxx>
      23             : #include <tools/resmgr.hxx>
      24             : #include <vcl/graphicfilter.hxx>
      25             : #include <unotools/syslocaleoptions.hxx>
      26             : 
      27             : using namespace ::com::sun::star;
      28             : 
      29           0 : static void aBasicErrorFunc( const OUString &rErr, const OUString &rAction )
      30             : {
      31           0 :     OStringBuffer aErr( "Unexpected dialog: " );
      32           0 :     aErr.append( OUStringToOString( rAction, RTL_TEXTENCODING_ASCII_US ) );
      33           0 :     aErr.append( " Error: " );
      34           0 :     aErr.append( OUStringToOString( rErr, RTL_TEXTENCODING_ASCII_US ) );
      35           0 :     CPPUNIT_ASSERT_MESSAGE( aErr.getStr(), false);
      36           0 : }
      37             : 
      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         363 : test::BootstrapFixture::BootstrapFixture( bool bAssertOnDialog, bool bNeedUCB )
      43             :     : m_bNeedUCB( bNeedUCB )
      44         363 :     , m_bAssertOnDialog( bAssertOnDialog )
      45             : {
      46         363 : }
      47             : 
      48             : extern "C"
      49             : {
      50             : 
      51         368 : void test_init_impl(bool bAssertOnDialog, bool bNeedUCB,
      52             :         lang::XMultiServiceFactory * pSFactory)
      53             : {
      54             :     // force locale (and resource files loaded) to en-US
      55         368 :     OUString aLangISO( "en-US" );
      56         368 :     ResMgr::SetDefaultLocale( LanguageTag( aLangISO) );
      57             : 
      58         736 :     SvtSysLocaleOptions aLocalOptions;
      59         368 :     aLocalOptions.SetLocaleConfigString( aLangISO );
      60         368 :     aLocalOptions.SetUILocaleConfigString( aLangISO );
      61             : 
      62         368 :     InitVCL();
      63         368 :     if (Application::IsHeadlessModeRequested())
      64         362 :         Application::EnableHeadlessMode(true);
      65             : 
      66         368 :     if (bAssertOnDialog)
      67         349 :         ErrorHandler::RegisterDisplay( aBasicErrorFunc );
      68             : 
      69             :     // Make GraphicConverter work, normally done in desktop::Desktop::Main()
      70             :     Application::SetFilterHdl(
      71         368 :             STATIC_LINK(0, test::BootstrapFixture, ImplInitFilterHdl));
      72             : 
      73         368 :     if (bNeedUCB)
      74             :     {
      75             :         // initialise unconfigured UCB:
      76         332 :         uno::Reference<ucb::XUniversalContentBroker> xUcb(pSFactory->createInstance("com.sun.star.ucb.UniversalContentBroker"), uno::UNO_QUERY_THROW);
      77         664 :         uno::Reference<ucb::XContentProvider> xFileProvider(pSFactory->createInstance("com.sun.star.ucb.FileContentProvider"), uno::UNO_QUERY_THROW);
      78         332 :         xUcb->registerContentProvider(xFileProvider, "file", sal_True);
      79         664 :         uno::Reference<ucb::XContentProvider> xTdocProvider(pSFactory->createInstance("com.sun.star.ucb.TransientDocumentsContentProvider"), uno::UNO_QUERY);
      80         332 :         if (xTdocProvider.is())
      81             :         {
      82         204 :             xUcb->registerContentProvider(xTdocProvider, "vnd.sun.star.tdoc", sal_True);
      83         332 :         }
      84         368 :     }
      85         368 : }
      86             : 
      87             : // this is called from pyuno
      88           5 : SAL_DLLPUBLIC_EXPORT void test_init(lang::XMultiServiceFactory *pFactory)
      89             : {
      90             :     try
      91             :     {
      92           5 :         ::comphelper::setProcessServiceFactory(pFactory);
      93           5 :         test_init_impl(false, true, pFactory);
      94             :     }
      95           0 :     catch (...) { abort(); }
      96           5 : }
      97             : 
      98             : } // extern "C"
      99             : 
     100         363 : void test::BootstrapFixture::setUp()
     101             : {
     102         363 :     test::BootstrapFixtureBase::setUp();
     103             : 
     104         363 :     test_init_impl(m_bAssertOnDialog, m_bNeedUCB, m_xSFactory.get());
     105         363 : }
     106             : 
     107         363 : void test::BootstrapFixture::tearDown()
     108             : {
     109         363 :     test::BootstrapFixtureBase::tearDown();
     110         363 : }
     111             : 
     112         363 : test::BootstrapFixture::~BootstrapFixture()
     113             : {
     114         363 : }
     115             : 
     116          78 : IMPL_STATIC_LINK_NOINSTANCE(
     117             :         test::BootstrapFixture, ImplInitFilterHdl, ConvertData*, pData)
     118             : {
     119          78 :     return GraphicFilter::GetGraphicFilter().GetFilterCallback().Call( pData );
     120         171 : }
     121             : 
     122             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10