Gtk-WARNING gtktreestore.c:1047: Invalid column number 1 added to iter
[LibreOffice.git] / qadevOOo / runner / helper / UnoProvider.java
blob017c2227ccf9c4314ae9a27a1fe6b2bbba3d0f71
1 /*
2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 package helper;
20 import java.util.HashMap;
22 import lib.TestParameters;
23 import util.PropertyName;
24 import util.utils;
26 import com.sun.star.comp.helper.Bootstrap;
27 import com.sun.star.lang.XMultiComponentFactory;
28 import com.sun.star.lang.XMultiServiceFactory;
29 import com.sun.star.uno.UnoRuntime;
30 import com.sun.star.uno.XComponentContext;
32 /**
33 * Bootstrap UNO from a Java environment.
34 * Needed parameters:
35 * <ol>
36 * <li>
37 * <ul>
38 * <li>UNORC - complete path to the unorc file</li>
39 * </ul>
40 * </li>
41 * <li>
42 * <ul>
43 * <li>AppExecutionCommand - path to the soffice executable</li>
44 * <li>OS - the operating system in case it's Windows, because the
45 * unorc is called uno.ini</li>
46 * </ul>
47 * </li>
48 * </ol>
50 public class UnoProvider implements AppProvider {
52 /**
53 * Close existing office: calls disposeManager()
54 * @param param The test parameters.
55 * @param closeIfPossible Not needed, since UNO is bootstrapped by this
56 * class in every case.
57 * @return True, if bootstrapping worked.
59 public boolean closeExistingOffice(TestParameters param,
60 boolean closeIfPossible) {
61 return disposeManager(param);
64 /**
65 * Dispose the UNO environment: just clears the bootstrapped
66 * MultiServiceFactory
67 * @param param The test parameters.
68 * @return True, if bootstrapping worked.
70 public boolean disposeManager(TestParameters param) {
71 param.remove("ServiceManager");
72 System.gc();
73 util.utils.pause(1000);
74 return true;
77 /**
78 * Bootstrap UNO and return the created MultiServiceFactory.
79 * @param param The test parameters.
80 * @return A created MultiServiceFactory.
82 public Object getManager(TestParameters param) {
83 XMultiServiceFactory xMSF = param.getMSF();
84 if (xMSF == null) {
85 // bootstrap UNO.
86 String unorcName = getUnorcName(param);
87 HashMap<String,String> env = new HashMap<String,String>();
88 env.put("SYSBINDIR", getSysBinDir(param));
90 XComponentContext xContext = null;
91 try {
92 xContext = Bootstrap.defaultBootstrap_InitialComponentContext(
93 unorcName, env);
95 catch(Exception e) {
96 e.printStackTrace();
97 System.out.println("Could not get XComponentContext. Maybe you must add program folder to LD_LIBRARY_PATH");
98 return null;
100 XMultiComponentFactory xMCF = xContext.getServiceManager();
101 xMSF = UnoRuntime.queryInterface(
102 XMultiServiceFactory.class, xMCF);
104 return xMSF;
107 private String getUnorcName(TestParameters param) {
108 String unorcName = (String)param.get("UNORC");
109 if (unorcName == null) {
110 String office = (String)param.get("AppExecutionCommand");
111 // determine unorc name: unorc or uno.ini on windows
112 unorcName = (String)param.get(PropertyName.UNORC_NAME);
113 // use '/', because this will be a URL in any case.
114 unorcName = office.substring(0, office.indexOf("program")+7) +
115 "/" + unorcName;
117 unorcName = utils.getFullURL(unorcName);
118 if (param.getBool(PropertyName.DEBUG_IS_ACTIVE)) {
119 System.out.println("UnoUcr: " + unorcName);
121 return unorcName;
124 private String getSysBinDir(TestParameters param) {
125 String base = (String)param.get("AppExecutionCommand");
126 if (base == null)
127 base = (String)param.get("UNORC");
129 if (base == null)
130 return null;
132 String sysbindir = base.substring(0,
133 base.indexOf("program")+7);
135 sysbindir = utils.getFullURL(sysbindir);
136 if (param.getBool(PropertyName.DEBUG_IS_ACTIVE)) {
137 System.out.println("SysBinDir: " + sysbindir);
139 return sysbindir;