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