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
loadFromDesktop(const OUString & rURL,const OUString & rDocService,const uno::Sequence<beans::PropertyValue> & rExtraArgs)25 uno::Reference<css::lang::XComponent> MacrosTest::loadFromDesktop(const OUString& rURL, const OUString& rDocService, const uno::Sequence<beans::PropertyValue>& rExtraArgs)
26 {
27 CPPUNIT_ASSERT_MESSAGE("no desktop", mxDesktop.is());
28 std::vector<beans::PropertyValue> args;
29 beans::PropertyValue aMacroValue;
30 aMacroValue.Name = "MacroExecutionMode";
31 aMacroValue.Handle = -1;
32 aMacroValue.Value <<= document::MacroExecMode::ALWAYS_EXECUTE_NO_WARN;
33 aMacroValue.State = beans::PropertyState_DIRECT_VALUE;
34 args.push_back(aMacroValue);
35
36 if (!rDocService.isEmpty())
37 {
38 beans::PropertyValue aValue;
39 aValue.Name = "DocumentService";
40 aValue.Handle = -1;
41 aValue.Value <<= rDocService;
42 aValue.State = beans::PropertyState_DIRECT_VALUE;
43 args.push_back(aValue);
44 }
45
46 args.insert(args.end(), rExtraArgs.begin(), rExtraArgs.end());
47
48 uno::Reference<lang::XComponent> xComponent = mxDesktop->loadComponentFromURL(rURL, "_default", 0, comphelper::containerToSequence(args));
49 OUString sMessage = "loading failed: " + rURL;
50 CPPUNIT_ASSERT_MESSAGE(OUStringToOString( sMessage, RTL_TEXTENCODING_UTF8 ).getStr( ), xComponent.is());
51 return xComponent;
52 }
53
54 }
55
56 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
57