LCOV - code coverage report
Current view: top level - unotest/source/cpp - bootstrapfixturebase.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 37 37 100.0 %
Date: 2015-06-13 12:38:46 Functions: 11 12 91.7 %
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             : 
      10             : #include "sal/config.h"
      11             : 
      12             : #include <unotest/bootstrapfixturebase.hxx>
      13             : #include <osl/file.hxx>
      14             : #include <rtl/strbuf.hxx>
      15             : #include <rtl/bootstrap.hxx>
      16             : #include <cppuhelper/bootstrap.hxx>
      17             : #include <comphelper/processfactory.hxx>
      18             : #include <basic/sbstar.hxx>
      19             : 
      20             : #include <com/sun/star/lang/Locale.hpp>
      21             : #include <com/sun/star/lang/XComponent.hpp>
      22             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      23             : 
      24             : using namespace ::com::sun::star;
      25             : 
      26             : namespace {
      27             : 
      28        5478 : OUString getFileURLFromSystemPath(OUString const & path) {
      29        5478 :     OUString url;
      30        5478 :     osl::FileBase::RC e = osl::FileBase::getFileURLFromSystemPath(path, url);
      31        5478 :     CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, e);
      32        5478 :     if (!url.endsWith("/")) {
      33        5478 :         url += "/";
      34             :     }
      35        5478 :     return url;
      36             : }
      37             : 
      38             : }
      39             : 
      40             : // NB. this constructor is called before any tests are run, once for each
      41             : // test function in a rather non-intuitive way. This is why all the 'real'
      42             : // heavy lifting is deferred until setUp. setUp and tearDown are interleaved
      43             : // between the tests as you might expect.
      44        2739 : test::BootstrapFixtureBase::BootstrapFixtureBase()
      45             : {
      46             : #ifndef ANDROID
      47        2739 :     const char* pSrcRoot = getenv( "SRC_ROOT" );
      48        2739 :     CPPUNIT_ASSERT_MESSAGE("SRC_ROOT env variable not set", pSrcRoot != NULL && pSrcRoot[0] != 0);
      49        2739 :     const char* pWorkdirRoot = getenv( "WORKDIR_FOR_BUILD" );
      50        2739 :     CPPUNIT_ASSERT_MESSAGE("$WORKDIR_FOR_BUILD env variable not set", pWorkdirRoot != NULL && pWorkdirRoot[0] != 0);
      51             : #else
      52             :     const char* pSrcRoot = "/assets";
      53             :     const char* pWorkdirRoot = "/assets";
      54             : #endif
      55        2739 :     m_aSrcRootPath = OUString::createFromAscii( pSrcRoot );
      56        2739 :     m_aSrcRootURL = getFileURLFromSystemPath(m_aSrcRootPath);
      57             : 
      58        2739 :     m_aWorkdirRootPath = OUString::createFromAscii( pWorkdirRoot );
      59        2739 :     m_aWorkdirRootURL = getFileURLFromSystemPath(m_aWorkdirRootPath);
      60             : 
      61        2739 : }
      62             : 
      63        2739 : test::BootstrapFixtureBase::~BootstrapFixtureBase()
      64             : {
      65        2739 : }
      66             : 
      67        1789 : OUString test::BootstrapFixtureBase::getURLFromSrc( const char *pPath )
      68             : {
      69        1789 :     return m_aSrcRootURL + OUString::createFromAscii( pPath );
      70             : }
      71             : 
      72         124 : OUString test::BootstrapFixtureBase::getURLFromSrc( const OUString& rPath )
      73             : {
      74         124 :     return m_aSrcRootURL + rPath;
      75             : }
      76             : 
      77          40 : OUString test::BootstrapFixtureBase::getPathFromSrc( const char *pPath )
      78             : {
      79          40 :     return m_aSrcRootPath + OUString::createFromAscii( pPath );
      80             : }
      81             : 
      82           4 : OUString test::BootstrapFixtureBase::getURLFromWorkdir( const char *pPath )
      83             : {
      84           4 :     return m_aWorkdirRootURL + OUString::createFromAscii( pPath );
      85             : }
      86             : 
      87             : #ifdef _WIN32 // ifdef just to keep it out of unusedcode.easy
      88             : OUString test::BootstrapFixtureBase::getPathFromWorkdir( const char *pPath )
      89             : {
      90             :     return m_aWorkdirRootPath + OUString::createFromAscii( pPath );
      91             : 
      92             : }
      93             : #endif
      94             : 
      95        2739 : void test::BootstrapFixtureBase::setUp()
      96             : {
      97             :     // set UserInstallation to user profile dir in test/user-template
      98        2739 :     OUString sUserInstallURL = m_aWorkdirRootURL + "/unittest";
      99        2739 :     rtl::Bootstrap::set(OUString("UserInstallation"), sUserInstallURL);
     100             : 
     101        2739 :     m_xContext = comphelper::getProcessComponentContext();
     102        2739 :     m_xFactory = m_xContext->getServiceManager();
     103        2739 :     m_xSFactory = uno::Reference<lang::XMultiServiceFactory>(m_xFactory, uno::UNO_QUERY_THROW);
     104        2739 : }
     105             : 
     106        2739 : void test::BootstrapFixtureBase::tearDown()
     107             : {
     108        2739 :     StarBASIC::DetachAllDocBasicItems();
     109        3141 : }
     110             : 
     111             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11