bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _toolkit / AccessibleMenuItem.java
blob2d0d3de6337309fb52ec459cfa9594b245a8f73c
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 mod._toolkit;
20 import com.sun.star.accessibility.AccessibleRole;
21 import com.sun.star.accessibility.XAccessible;
22 import com.sun.star.accessibility.XAccessibleAction;
23 import com.sun.star.accessibility.XAccessibleContext;
24 import com.sun.star.accessibility.XAccessibleText;
25 import com.sun.star.awt.XExtendedToolkit;
26 import com.sun.star.awt.XWindow;
27 import com.sun.star.lang.XMultiServiceFactory;
28 import com.sun.star.text.XTextDocument;
29 import com.sun.star.uno.UnoRuntime;
30 import com.sun.star.uno.XInterface;
32 import java.io.PrintWriter;
34 import lib.StatusException;
35 import lib.TestCase;
36 import lib.TestEnvironment;
37 import lib.TestParameters;
39 import util.AccessibilityTools;
40 import util.SOfficeFactory;
41 import util.utils;
44 /**
45 * Test for object which is represented by accessible component
46 * of a menu item in main menu of a document. <p>
48 * Object implements the following interfaces :
49 * <ul>
50 * <li> <code>::com::sun::star::accessibility::XAccessibleExtendedComponent</code></li>
51 * <li> <code>::com::sun::star::accessibility::XAccessibleEventBroadcaster</code></li>
52 * <li> <code>::com::sun::star::accessibility::XAccessibleComponent</code></li>
53 * <li> <code>::com::sun::star::accessibility::XAccessibleValue</code></li>
54 * <li> <code>::com::sun::star::accessibility::XAccessibleAction</code></li>
55 * <li> <code>::com::sun::star::accessibility::XAccessibleContext</code></li>
56 * <li> <code>::com::sun::star::accessibility::XAccessibleText</code></li>
57 * </ul> <p>
59 * @see com.sun.star.accessibility.XAccessibleExtendedComponent
60 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
61 * @see com.sun.star.accessibility.XAccessibleComponent
62 * @see com.sun.star.accessibility.XAccessibleValue
63 * @see com.sun.star.accessibility.XAccessibleAction
64 * @see com.sun.star.accessibility.XAccessibleContext
65 * @see com.sun.star.accessibility.XAccessibleText
66 * @see ifc.accessibility._XAccessibleExtendedComponent
67 * @see ifc.accessibility._XAccessibleEventBroadcaster
68 * @see ifc.accessibility._XAccessibleComponent
69 * @see ifc.accessibility._XAccessibleValue
70 * @see ifc.accessibility._XAccessibleAction
71 * @see ifc.accessibility._XAccessibleContext
72 * @see ifc.accessibility._XAccessibleText
74 public class AccessibleMenuItem extends TestCase {
75 private static XTextDocument xTextDoc = null;
76 private static XMultiServiceFactory msf = null;
78 /**
79 * Finds first accessible component with role <code>MENUITEM</code>
80 * walking through the accessible component tree of a document.
82 protected TestEnvironment createTestEnvironment(TestParameters Param,
83 PrintWriter log) {
84 XInterface oObj = null;
86 try {
87 oObj = (XInterface) msf.createInstance("com.sun.star.awt.Toolkit");
88 } catch (com.sun.star.uno.Exception e) {
89 log.println("Couldn't get toolkit");
90 e.printStackTrace(log);
91 throw new StatusException("Couldn't get toolkit", e);
94 XExtendedToolkit tk = UnoRuntime.queryInterface(
95 XExtendedToolkit.class, oObj);
97 shortWait();
99 AccessibilityTools at = new AccessibilityTools();
101 Object atw = tk.getActiveTopWindow();
103 XWindow xWindow = UnoRuntime.queryInterface(XWindow.class,
104 atw);
106 XAccessible xRoot = AccessibilityTools.getAccessibleObject(xWindow);
108 AccessibilityTools.printAccessibleTree(log, xRoot, Param.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
109 XAccessibleContext MenuBar = AccessibilityTools.getAccessibleObjectForRole(xRoot,
110 AccessibleRole.MENU_BAR);
112 try {
113 //activate Edit-Menu
114 XAccessible Menu = MenuBar.getAccessibleChild(1);
115 XAccessibleAction act = UnoRuntime.queryInterface(
116 XAccessibleAction.class, Menu);
117 act.doAccessibleAction(0);
118 shortWait();
121 //get a menue-item
122 oObj = Menu.getAccessibleContext().getAccessibleChild(11);
123 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
127 //oObj = at.getAccessibleObjectForRole(xRoot, AccessibleRole.MENUITEM);
128 log.println("ImplementationName " + utils.getImplName(oObj));
130 TestEnvironment tEnv = new TestEnvironment(oObj);
132 final XAccessibleAction action = UnoRuntime.queryInterface(
133 XAccessibleAction.class, oObj);
135 tEnv.addObjRelation("EventProducer",
136 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
137 public void fireEvent() {
138 try {
139 action.doAccessibleAction(0);
140 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
145 XAccessibleText text = UnoRuntime.queryInterface(
146 XAccessibleText.class, oObj);
148 tEnv.addObjRelation("XAccessibleText.Text", text.getText());
150 tEnv.addObjRelation("EditOnly",
151 "Can't change or select Text in MenuBarItem");
153 tEnv.addObjRelation("Destroy", new Boolean(true));
155 tEnv.addObjRelation("LimitedBounds", "yes");
157 return tEnv;
161 * Creates writer document.
163 protected void initialize(TestParameters Param, PrintWriter log) {
164 try {
165 msf = (XMultiServiceFactory) Param.getMSF();
167 SOfficeFactory SOF = SOfficeFactory.getFactory(msf);
168 xTextDoc = SOF.createTextDoc(null);
169 } catch (com.sun.star.uno.Exception e) {
170 throw new StatusException("Can't create document", e);
175 * Disposes document.
177 protected void cleanup(TestParameters Param, PrintWriter log) {
178 util.DesktopTools.closeDoc(xTextDoc);
182 * Sleeps for 0.5 sec. to allow StarOffice to react on <code>
183 * reset</code> call.
185 private void shortWait() {
186 try {
187 Thread.sleep(500);
188 } catch (InterruptedException e) {
189 log.println("While waiting :" + e);