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 .
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
;
36 import lib
.TestEnvironment
;
37 import lib
.TestParameters
;
39 import util
.AccessibilityTools
;
40 import util
.SOfficeFactory
;
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 :
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>
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;
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
,
84 XInterface oObj
= null;
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
);
99 AccessibilityTools at
= new AccessibilityTools();
101 Object atw
= tk
.getActiveTopWindow();
103 XWindow xWindow
= UnoRuntime
.queryInterface(XWindow
.class,
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
);
114 XAccessible Menu
= MenuBar
.getAccessibleChild(1);
115 XAccessibleAction act
= UnoRuntime
.queryInterface(
116 XAccessibleAction
.class, Menu
);
117 act
.doAccessibleAction(0);
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() {
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");
161 * Creates writer document.
163 protected void initialize(TestParameters Param
, PrintWriter log
) {
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
);
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>
185 private void shortWait() {
188 } catch (InterruptedException e
) {
189 log
.println("While waiting :" + e
);