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/.
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
;
28 OUString
getFileURLFromSystemPath(OUString
const & path
) {
30 osl::FileBase::RC e
= osl::FileBase::getFileURLFromSystemPath(path
, url
);
31 CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None
, e
);
32 if (!url
.endsWith("/")) {
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()
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);
52 const char* pSrcRoot
= "/assets";
53 const char* pWorkdirRoot
= "/assets";
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
);
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: */