Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / ifc / ui / _XUIConfigurationManager.java
blob0c57bc23b374740b6400f73d3fdd9e91a4aa3573
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 ifc.ui;
20 import com.sun.star.beans.PropertyValue;
21 import com.sun.star.beans.XPropertySet;
22 import com.sun.star.container.XIndexAccess;
23 import com.sun.star.container.XIndexContainer;
24 import com.sun.star.lang.XMultiServiceFactory;
25 import com.sun.star.lang.XServiceInfo;
26 import com.sun.star.lang.XSingleComponentFactory;
27 import com.sun.star.uno.UnoRuntime;
28 import com.sun.star.uno.XComponentContext;
29 import com.sun.star.ui.UIElementType;
30 import com.sun.star.ui.XImageManager;
31 import com.sun.star.ui.XUIConfigurationManager;
32 import java.io.PrintWriter;
33 import lib.MultiMethodTest;
35 public class _XUIConfigurationManager extends MultiMethodTest {
37 public XUIConfigurationManager oObj;
38 private static final String msResourceUrl = "private:resource/menubar/menubar";
39 private static final String msMyResourceUrl = "private:resource/menubar/mymenubar";
40 private XIndexContainer mxSettings = null;
41 private XIndexAccess mxMenuBarSettings = null;
42 private XMultiServiceFactory mxMSF = null;
43 private String sShortCutManagerServiceName = null;
46 /**
47 * Some stuff before the tests:
48 * extract the multi service factory.
50 @Override
51 protected void before() {
52 mxMSF = tParam.getMSF();
53 sShortCutManagerServiceName = (String)tEnv.getObjRelation("XConfigurationManager.ShortCutManager");
57 /**
58 * reset all changes: do at the end.
60 public void _reset() {
61 requiredMethod("removeSettings()");
62 oObj.reset();
63 tRes.tested("reset()", true);
66 public void _getUIElementsInfo() {
67 boolean result = true;
68 try {
69 PropertyValue[][]props = oObj.getUIElementsInfo(UIElementType.UNKNOWN);
70 for (int i=0; i<props.length; i++)
71 for(int j=0; j<props[i].length; j++)
72 log.println("Prop["+i+"]["+j+"]: " + props[i][j].Name + " " + props[i][j].Value.toString());
74 catch(com.sun.star.lang.IllegalArgumentException e) {
75 result = false;
76 e.printStackTrace(log);
78 tRes.tested("getUIElementsInfo()", result);
81 public void _createSettings() {
82 mxSettings = oObj.createSettings();
83 util.dbg.printInterfaces(mxSettings);
84 tRes.tested("createSettings()", mxSettings != null);
87 public void _hasSettings() {
88 boolean result = false;
89 try {
90 result = oObj.hasSettings(msResourceUrl);
92 catch(com.sun.star.lang.IllegalArgumentException e) {
93 log.println(e);
94 result = false;
96 tRes.tested("hasSettings()", result);
99 public void _getSettings() {
100 requiredMethod("hasSettings()");
101 boolean result = true;
102 try {
103 mxMenuBarSettings = oObj.getSettings(msResourceUrl, true);
104 result = mxMenuBarSettings != null;
105 for (int i=0; i<mxMenuBarSettings.getCount(); i++) {
106 Object[] o = (Object[])mxMenuBarSettings.getByIndex(i);
107 log.println("+++++++++ i = " + i);
108 for (int j=0; j<o.length; j++) {
109 PropertyValue prop = (PropertyValue)o[j];
110 log.println("Property" + j + ": " + prop.Name + " " + prop.Value.toString());
114 catch(com.sun.star.container.NoSuchElementException e) {
115 result = false;
116 e.printStackTrace(log);
118 catch(com.sun.star.lang.IllegalArgumentException e) {
119 result = false;
120 e.printStackTrace(log);
122 catch(com.sun.star.lang.IndexOutOfBoundsException e) {
123 result = false;
124 e.printStackTrace(log);
126 catch(com.sun.star.lang.WrappedTargetException e) {
127 result = false;
128 e.printStackTrace(log);
130 tRes.tested("getSettings()", result);
133 public void _replaceSettings() {
134 requiredMethod("getSettings()");
135 boolean result = true;
136 PropertyValue[] prop = createMenuBarEntry("My Entry", mxMenuBarSettings, mxMSF, log);
137 if (prop == null) {
138 tRes.tested("replaceSettings()", false);
139 return;
142 createMenuBarItem("Click for Macro", UnoRuntime.queryInterface(
143 XIndexContainer.class, prop[3].Value), log);
145 XIndexContainer x = UnoRuntime.queryInterface(XIndexContainer.class, mxMenuBarSettings);
146 try {
147 x.insertByIndex(x.getCount(), prop);
149 catch(com.sun.star.lang.IllegalArgumentException e) {
150 result = false;
151 e.printStackTrace(log);
153 catch(com.sun.star.lang.IndexOutOfBoundsException e) {
154 result = false;
155 e.printStackTrace(log);
157 catch(com.sun.star.lang.WrappedTargetException e) {
158 result = false;
159 e.printStackTrace(log);
162 try {
163 oObj.replaceSettings(msResourceUrl, mxMenuBarSettings);
165 catch(com.sun.star.container.NoSuchElementException e) {
166 result = false;
167 e.printStackTrace(log);
169 catch(com.sun.star.lang.IllegalArgumentException e) {
170 result = false;
171 e.printStackTrace(log);
173 catch(com.sun.star.lang.IllegalAccessException e) {
174 result = false;
175 e.printStackTrace(log);
177 _getSettings();
178 tRes.tested("replaceSettings()", result);
181 public void _removeSettings() {
182 requiredMethod("insertSettings()");
183 boolean result = true;
184 try {
185 oObj.removeSettings(msMyResourceUrl);
187 catch(com.sun.star.container.NoSuchElementException e) {
188 result = false;
189 e.printStackTrace(log);
191 catch(com.sun.star.lang.IllegalArgumentException e) {
192 result = false;
193 e.printStackTrace(log);
195 catch(com.sun.star.lang.IllegalAccessException e) {
196 e.printStackTrace(log);
197 result = false;
199 tRes.tested("removeSettings()", result);
202 public void _insertSettings() {
203 requiredMethod("createSettings()");
204 requiredMethod("replaceSettings()");
205 boolean result = true;
206 util.dbg.printInterfaces(mxSettings);
207 PropertyValue[] prop = createMenuBarEntry("A new entry", mxSettings, mxMSF, log);
208 if (prop == null) {
209 tRes.tested("replaceSettings()", false);
210 return;
213 createMenuBarItem("A new sub entry", UnoRuntime.queryInterface(
214 XIndexContainer.class, prop[3].Value), log);
216 XIndexContainer x = UnoRuntime.queryInterface(XIndexContainer.class,mxSettings);
217 try {
218 int count = x.getCount();
219 x.insertByIndex(count, prop);
221 catch(com.sun.star.lang.IllegalArgumentException e) {
222 result = false;
223 e.printStackTrace(log);
225 catch(com.sun.star.lang.IndexOutOfBoundsException e) {
226 result = false;
227 e.printStackTrace(log);
229 catch(com.sun.star.lang.WrappedTargetException e) {
230 result = false;
231 e.printStackTrace(log);
234 try {
235 oObj.insertSettings(msMyResourceUrl, mxSettings);
237 catch(com.sun.star.container.ElementExistException e) {
238 e.printStackTrace(log);
239 result = false;
241 catch(com.sun.star.lang.IllegalArgumentException e) {
242 e.printStackTrace(log);
243 result = false;
245 catch(com.sun.star.lang.IllegalAccessException e) {
246 e.printStackTrace(log);
247 result = false;
249 tRes.tested("insertSettings()", result);
253 * Only a short test.
254 * See complex.imageManager.CheckImageManager for a more extensive test of
255 * this implementation.
257 public void _getImageManager() {
258 Object o = oObj.getImageManager();
259 log.println("###### ImageManager ");
260 XImageManager xImageManager = UnoRuntime.queryInterface(XImageManager.class, o);
261 tRes.tested("getImageManager()", xImageManager != null);
266 * get a shortcut manager
268 public void _getShortCutManager() {
269 Object o = oObj.getShortCutManager();
270 XServiceInfo xSI = UnoRuntime.queryInterface(XServiceInfo.class,o);
271 String[] serviceNames = xSI.getSupportedServiceNames();
272 boolean bSupportedServiceFound = false;
273 for (int i=0; i<serviceNames.length; i++) {
274 log.println("SuppService: " + serviceNames[i]);
275 if (serviceNames[i].equals(sShortCutManagerServiceName)) {
276 bSupportedServiceFound = true;
279 tRes.tested("getShortCutManager()", bSupportedServiceFound);
282 public void _getEventsManager() {
283 Object o = oObj.getEventsManager();
284 tRes.tested("getEventsManager()", o == null);
288 * Create a menu bar entry for adding to the menu bar of the Office.
289 * @param sLabelName The name of the new entry.
290 * @param xMenuBarSettings The existing menu bar settings, used for creating the new entry.
291 * @return An array of properties of the new entry.
293 public static PropertyValue[] createMenuBarEntry(String sLabelName, XIndexAccess xMenuBarSettings, XMultiServiceFactory xMSF, PrintWriter log) {
294 PropertyValue[] prop = new PropertyValue[4];
295 prop[0] = new PropertyValue();
296 prop[0].Name = "CommandURL";
297 prop[0].Value = "vnd.openoffice.org:MyMenu";
298 prop[1] = new PropertyValue();
299 prop[1].Name = "Label";
300 prop[1].Value = sLabelName;
301 prop[2] = new PropertyValue();
302 prop[2].Name = "Type";
303 prop[2].Value = Short.valueOf((short)0);
304 prop[3] = new PropertyValue();
305 prop[3].Name = "ItemDescriptorContainer";
307 XSingleComponentFactory xFactory = UnoRuntime.queryInterface(
308 XSingleComponentFactory.class, xMenuBarSettings);
309 try {
310 XPropertySet xProp = UnoRuntime.queryInterface(XPropertySet.class, xMSF);
311 XComponentContext xContext = UnoRuntime.queryInterface(
312 XComponentContext.class, xProp.getPropertyValue("DefaultContext"));
313 prop[3].Value = xFactory.createInstanceWithContext(xContext);
315 catch(com.sun.star.uno.Exception e) {
316 log.println("Could not create an instance for ItemDescriptorContainer property.");
317 e.printStackTrace(log);
318 return null;
320 return prop;
324 * Create a sub entry to the menu bar.
325 * @param sLabelName The name of the entry in the UI.
326 * @param xDescriptionContainer The parent entry in the menu bar where
327 * this entry is added.
329 public static void createMenuBarItem(String sLabelName, XIndexContainer xDescriptionContainer, PrintWriter log) {
330 PropertyValue[]aMenuItem = new PropertyValue[3];
331 // create a menu item
332 aMenuItem[0] = new PropertyValue();
333 aMenuItem[0].Name = "CommandURL";
334 aMenuItem[0].Value = "macro:///Standard.Module1.Test()";
335 aMenuItem[1] = new PropertyValue();
336 aMenuItem[1].Name = "Label";
337 aMenuItem[1].Value = sLabelName;
338 aMenuItem[2] = new PropertyValue();
339 aMenuItem[2].Name = "Type";
340 aMenuItem[2].Value = Short.valueOf((short)0);
342 try {
343 xDescriptionContainer.insertByIndex(0, aMenuItem);
345 catch(com.sun.star.lang.IllegalArgumentException e) {
346 e.printStackTrace(log);
348 catch(com.sun.star.lang.IndexOutOfBoundsException e) {
349 e.printStackTrace(log);
351 catch(com.sun.star.lang.WrappedTargetException e) {
352 e.printStackTrace(log);