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 "unotest/macros_test.hxx"
11 :
12 : #include <com/sun/star/frame/XComponentLoader.hpp>
13 : #include <com/sun/star/document/MacroExecMode.hpp>
14 :
15 : #include "cppunit/TestAssert.h"
16 : #include <rtl/ustrbuf.hxx>
17 :
18 : using namespace css;
19 :
20 : namespace unotest {
21 :
22 4026 : uno::Reference<css::lang::XComponent> MacrosTest::loadFromDesktop(const OUString& rURL, const OUString& rDocService)
23 : {
24 4026 : CPPUNIT_ASSERT_MESSAGE("no desktop", mxDesktop.is());
25 4026 : uno::Reference<frame::XComponentLoader> xLoader = uno::Reference<frame::XComponentLoader>(mxDesktop, uno::UNO_QUERY);
26 4026 : CPPUNIT_ASSERT_MESSAGE("no loader", xLoader.is());
27 8052 : uno::Sequence<beans::PropertyValue> args(1);
28 4026 : args[0].Name = "MacroExecutionMode";
29 4026 : args[0].Handle = -1;
30 4026 : args[0].Value <<= document::MacroExecMode::ALWAYS_EXECUTE_NO_WARN;
31 4026 : args[0].State = beans::PropertyState_DIRECT_VALUE;
32 :
33 4026 : if (!rDocService.isEmpty())
34 : {
35 3954 : args.realloc(2);
36 3954 : args[1].Name = "DocumentService";
37 3954 : args[1].Handle = -1;
38 3954 : args[1].Value <<= rDocService;
39 3954 : args[1].State = beans::PropertyState_DIRECT_VALUE;
40 : }
41 :
42 4026 : uno::Reference<lang::XComponent> xComponent = xLoader->loadComponentFromURL(rURL, OUString("_default"), 0, args);
43 8052 : OUString sMessage = "loading failed: " + rURL;
44 4026 : CPPUNIT_ASSERT_MESSAGE(OUStringToOString( sMessage, RTL_TEXTENCODING_UTF8 ).getStr( ), xComponent.is());
45 8052 : return xComponent;
46 : }
47 :
48 696 : }
49 :
50 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|