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/.
9 #include <unotest/bootstrapfixturebase.hxx>
10 #include <rtl/strbuf.hxx>
11 #include <rtl/bootstrap.hxx>
12 #include <cppuhelper/bootstrap.hxx>
13 #include <comphelper/processfactory.hxx>
15 #include <com/sun/star/lang/Locale.hpp>
16 #include <com/sun/star/lang/XComponent.hpp>
17 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
19 using namespace ::com::sun::star
;
21 // NB. this constructor is called before any tests are run, once for each
22 // test function in a rather non-intuitive way. This is why all the 'real'
23 // heavy lifting is deferred until setUp. setUp and tearDown are interleaved
24 // between the tests as you might expect.
25 test::BootstrapFixtureBase::BootstrapFixtureBase()
26 : m_aSrcRootURL("file://"), m_aSolverRootURL( m_aSrcRootURL
)
29 const char* pSrcRoot
= getenv( "SRC_ROOT" );
30 CPPUNIT_ASSERT_MESSAGE("SRC_ROOT env variable not set", pSrcRoot
!= NULL
&& pSrcRoot
[0] != 0);
31 const char* pSolverRoot
= getenv( "OUTDIR_FOR_BUILD" );
32 CPPUNIT_ASSERT_MESSAGE("$OUTDIR_FOR_BUILD env variable not set", pSolverRoot
!= NULL
&& pSolverRoot
[0] != 0);
33 const char* pWorkdirRoot
= getenv( "WORKDIR_FOR_BUILD" );
34 CPPUNIT_ASSERT_MESSAGE("$WORKDIR_FOR_BUILD env variable not set", pWorkdirRoot
!= NULL
&& pWorkdirRoot
[0] != 0);
36 if (pSrcRoot
[1] == ':')
38 m_aSrcRootURL
+= OUString::createFromAscii( "/" );
40 if (pSolverRoot
[1] == ':')
42 m_aSolverRootURL
+= OUString::createFromAscii( "/" );
44 if (pWorkdirRoot
[1] == ':')
46 m_aWorkdirRootURL
+= OUString::createFromAscii( "/" );
50 const char* pSrcRoot
= "/assets";
51 const char* pSolverRoot
= "/assets";
52 const char* pWorkdirRoot
= "/assets";
54 m_aSrcRootPath
= OUString::createFromAscii( pSrcRoot
);
55 m_aSrcRootURL
+= m_aSrcRootPath
;
57 m_aSolverRootPath
= OUString::createFromAscii( pSolverRoot
);
58 m_aSolverRootURL
+= m_aSolverRootPath
;
60 m_aWorkdirRootPath
= OUString::createFromAscii( pWorkdirRoot
);
61 m_aWorkdirRootURL
+= m_aWorkdirRootPath
;
65 test::BootstrapFixtureBase::~BootstrapFixtureBase()
69 OUString
test::BootstrapFixtureBase::getURLFromSrc( const char *pPath
)
71 return m_aSrcRootURL
+ OUString::createFromAscii( pPath
);
74 OUString
test::BootstrapFixtureBase::getPathFromSrc( const char *pPath
)
76 return m_aSrcRootPath
+ OUString::createFromAscii( pPath
);
80 OUString
test::BootstrapFixtureBase::getURLFromWorkdir( const char *pPath
)
82 return m_aWorkdirRootURL
+ OUString::createFromAscii( pPath
);
85 OUString
test::BootstrapFixtureBase::getPathFromWorkdir( const char *pPath
)
87 return m_aWorkdirRootPath
+ OUString::createFromAscii( pPath
);
91 void test::BootstrapFixtureBase::setUp()
93 // set UserInstallation to user profile dir in test/user-template
94 rtl::Bootstrap aDefaultVars
;
95 OUString sUserInstallURL
= m_aSolverRootURL
+ OUString("/unittest");
96 aDefaultVars
.set(OUString("UserInstallation"), sUserInstallURL
);
98 m_xContext
= comphelper::getProcessComponentContext();
99 m_xFactory
= m_xContext
->getServiceManager();
100 m_xSFactory
= uno::Reference
<lang::XMultiServiceFactory
>(m_xFactory
, uno::UNO_QUERY_THROW
);
103 void test::BootstrapFixtureBase::tearDown()
107 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */