Bump version to 5.0-14
[LibreOffice.git] / unotest / source / cpp / bootstrapfixturebase.cxx
blob41272c68b753ad48f5fa939f1e23aa61d374d7ea
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
8 */
10 #include "sal/config.h"
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>
20 #include <com/sun/star/lang/Locale.hpp>
21 #include <com/sun/star/lang/XComponent.hpp>
22 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
24 using namespace ::com::sun::star;
26 namespace {
28 OUString getFileURLFromSystemPath(OUString const & path) {
29 OUString url;
30 osl::FileBase::RC e = osl::FileBase::getFileURLFromSystemPath(path, url);
31 CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, e);
32 if (!url.endsWith("/")) {
33 url += "/";
35 return url;
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 test::BootstrapFixtureBase::BootstrapFixtureBase()
46 #ifndef ANDROID
47 const char* pSrcRoot = getenv( "SRC_ROOT" );
48 CPPUNIT_ASSERT_MESSAGE("SRC_ROOT env variable not set", pSrcRoot != NULL && pSrcRoot[0] != 0);
49 const char* pWorkdirRoot = getenv( "WORKDIR_FOR_BUILD" );
50 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 m_aSrcRootPath = OUString::createFromAscii( pSrcRoot );
56 m_aSrcRootURL = getFileURLFromSystemPath(m_aSrcRootPath);
58 m_aWorkdirRootPath = OUString::createFromAscii( pWorkdirRoot );
59 m_aWorkdirRootURL = getFileURLFromSystemPath(m_aWorkdirRootPath);
63 test::BootstrapFixtureBase::~BootstrapFixtureBase()
67 OUString test::BootstrapFixtureBase::getURLFromSrc( const char *pPath )
69 return m_aSrcRootURL + OUString::createFromAscii( pPath );
72 OUString test::BootstrapFixtureBase::getURLFromSrc( const OUString& rPath )
74 return m_aSrcRootURL + rPath;
77 OUString test::BootstrapFixtureBase::getPathFromSrc( const char *pPath )
79 return m_aSrcRootPath + OUString::createFromAscii( pPath );
82 OUString test::BootstrapFixtureBase::getURLFromWorkdir( const char *pPath )
84 return m_aWorkdirRootURL + OUString::createFromAscii( pPath );
87 #ifdef _WIN32 // ifdef just to keep it out of unusedcode.easy
88 OUString test::BootstrapFixtureBase::getPathFromWorkdir( const char *pPath )
90 return m_aWorkdirRootPath + OUString::createFromAscii( pPath );
93 #endif
95 void test::BootstrapFixtureBase::setUp()
97 // set UserInstallation to user profile dir in test/user-template
98 OUString sUserInstallURL = m_aWorkdirRootURL + "/unittest";
99 rtl::Bootstrap::set(OUString("UserInstallation"), sUserInstallURL);
101 m_xContext = comphelper::getProcessComponentContext();
102 m_xFactory = m_xContext->getServiceManager();
103 m_xSFactory = uno::Reference<lang::XMultiServiceFactory>(m_xFactory, uno::UNO_QUERY_THROW);
106 void test::BootstrapFixtureBase::tearDown()
108 StarBASIC::DetachAllDocBasicItems();
111 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */