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

Generated by: LCOV version 1.10