Bump version to 5.0-14
[LibreOffice.git] / unotest / source / cpp / macros_test.cxx
blobcf23ee4d1e830890f842bc822fa6c9660885baa5
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
8 */
10 #include "unotest/macros_test.hxx"
12 #include <vector>
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>
21 using namespace css;
23 namespace unotest {
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";
42 aValue.Handle = -1;
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());
53 return xComponent;
58 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */