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 9324 : OUString getFileURLFromSystemPath(OUString const & path) {
29 9324 : OUString url;
30 9324 : osl::FileBase::RC e = osl::FileBase::getFileURLFromSystemPath(path, url);
31 9324 : CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, e);
32 9324 : if (!url.endsWith("/")) {
33 9324 : url += "/";
34 : }
35 9324 : 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 4662 : test::BootstrapFixtureBase::BootstrapFixtureBase()
45 : {
46 : #ifndef ANDROID
47 4662 : const char* pSrcRoot = getenv( "SRC_ROOT" );
48 4662 : CPPUNIT_ASSERT_MESSAGE("SRC_ROOT env variable not set", pSrcRoot != NULL && pSrcRoot[0] != 0);
49 4662 : const char* pWorkdirRoot = getenv( "WORKDIR_FOR_BUILD" );
50 4662 : 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 4662 : m_aSrcRootPath = OUString::createFromAscii( pSrcRoot );
56 4662 : m_aSrcRootURL = getFileURLFromSystemPath(m_aSrcRootPath);
57 :
58 4662 : m_aWorkdirRootPath = OUString::createFromAscii( pWorkdirRoot );
59 4662 : m_aWorkdirRootURL = getFileURLFromSystemPath(m_aWorkdirRootPath);
60 :
61 4662 : }
62 :
63 4662 : test::BootstrapFixtureBase::~BootstrapFixtureBase()
64 : {
65 4662 : }
66 :
67 2962 : OUString test::BootstrapFixtureBase::getURLFromSrc( const char *pPath )
68 : {
69 2962 : return m_aSrcRootURL + OUString::createFromAscii( pPath );
70 : }
71 :
72 170 : OUString test::BootstrapFixtureBase::getURLFromSrc( const OUString& rPath )
73 : {
74 170 : return m_aSrcRootURL + rPath;
75 : }
76 :
77 68 : OUString test::BootstrapFixtureBase::getPathFromSrc( const char *pPath )
78 : {
79 68 : return m_aSrcRootPath + OUString::createFromAscii( pPath );
80 : }
81 :
82 6 : OUString test::BootstrapFixtureBase::getURLFromWorkdir( const char *pPath )
83 : {
84 6 : 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 4662 : void test::BootstrapFixtureBase::setUp()
96 : {
97 : // set UserInstallation to user profile dir in test/user-template
98 4662 : OUString sUserInstallURL = m_aWorkdirRootURL + "/unittest";
99 4662 : rtl::Bootstrap::set(OUString("UserInstallation"), sUserInstallURL);
100 :
101 4662 : m_xContext = comphelper::getProcessComponentContext();
102 4662 : m_xFactory = m_xContext->getServiceManager();
103 4662 : m_xSFactory = uno::Reference<lang::XMultiServiceFactory>(m_xFactory, uno::UNO_QUERY_THROW);
104 4662 : }
105 :
106 4662 : void test::BootstrapFixtureBase::tearDown()
107 : {
108 4662 : StarBASIC::DetachAllDocBasicItems();
109 5358 : }
110 :
111 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|