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 "unotest/macros_test.hxx"
14 #include <com/sun/star/frame/XComponentLoader.hpp>
15 #include <com/sun/star/document/MacroExecMode.hpp>
17 #include "cppunit/TestAssert.h"
18 #include <rtl/ustrbuf.hxx>
19 #include <comphelper/sequence.hxx>
25 uno::Reference
<css::lang::XComponent
> MacrosTest::loadFromDesktop(const OUString
& rURL
, const OUString
& rDocService
, const uno::Sequence
<beans::PropertyValue
>& rExtraArgs
)
27 CPPUNIT_ASSERT_MESSAGE("no desktop", mxDesktop
.is());
28 uno::Reference
<frame::XComponentLoader
> xLoader
= uno::Reference
<frame::XComponentLoader
>(mxDesktop
, uno::UNO_QUERY
);
29 CPPUNIT_ASSERT_MESSAGE("no loader", xLoader
.is());
30 std::vector
<beans::PropertyValue
> args
;
31 beans::PropertyValue aMacroValue
;
32 aMacroValue
.Name
= "MacroExecutionMode";
33 aMacroValue
.Handle
= -1;
34 aMacroValue
.Value
<<= document::MacroExecMode::ALWAYS_EXECUTE_NO_WARN
;
35 aMacroValue
.State
= beans::PropertyState_DIRECT_VALUE
;
36 args
.push_back(aMacroValue
);
38 if (!rDocService
.isEmpty())
40 beans::PropertyValue aValue
;
41 aValue
.Name
= "DocumentService";
43 aValue
.Value
<<= rDocService
;
44 aValue
.State
= beans::PropertyState_DIRECT_VALUE
;
45 args
.push_back(aValue
);
48 args
.insert(args
.end(), rExtraArgs
.begin(), rExtraArgs
.end());
50 uno::Reference
<lang::XComponent
> xComponent
= xLoader
->loadComponentFromURL(rURL
, OUString("_default"), 0, comphelper::containerToSequence(args
));
51 OUString sMessage
= "loading failed: " + rURL
;
52 CPPUNIT_ASSERT_MESSAGE(OUStringToOString( sMessage
, RTL_TEXTENCODING_UTF8
).getStr( ), xComponent
.is());
58 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */