1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: AccessibleMenu.java,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
32 import com
.sun
.star
.accessibility
.AccessibleRole
;
33 import com
.sun
.star
.accessibility
.XAccessible
;
34 import com
.sun
.star
.accessibility
.XAccessibleAction
;
35 import com
.sun
.star
.accessibility
.XAccessibleContext
;
36 import com
.sun
.star
.accessibility
.XAccessibleText
;
37 import com
.sun
.star
.awt
.XExtendedToolkit
;
38 import com
.sun
.star
.awt
.XWindow
;
39 import com
.sun
.star
.lang
.XMultiServiceFactory
;
40 import com
.sun
.star
.text
.XTextDocument
;
41 import com
.sun
.star
.uno
.UnoRuntime
;
42 import com
.sun
.star
.uno
.XInterface
;
44 import java
.io
.PrintWriter
;
46 import lib
.StatusException
;
48 import lib
.TestEnvironment
;
49 import lib
.TestParameters
;
51 import util
.AccessibilityTools
;
52 import util
.SOfficeFactory
;
57 * Test for object which is represented accessible component of
58 * main menu of a document. <p>
60 * Object implements the following interfaces :
62 * <li> <code>::com::sun::star::accessibility::XAccessibleEventBroadcaster</code></li>
63 * <li> <code>::com::sun::star::accessibility::XAccessibleAction</code></li>
64 * <li> <code>::com::sun::star::accessibility::XAccessibleSelection</code></li>
65 * <li> <code>::com::sun::star::accessibility::XAccessibleValue</code></li>
66 * <li> <code>::com::sun::star::accessibility::XAccessibleExtendedComponent</code></li>
67 * <li> <code>::com::sun::star::accessibility::XAccessibleComponent</code></li>
68 * <li> <code>::com::sun::star::accessibility::XAccessibleText</code></li>
69 * <li> <code>::com::sun::star::accessibility::XAccessibleContext</code></li>
72 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
73 * @see com.sun.star.accessibility.XAccessibleAction
74 * @see com.sun.star.accessibility.XAccessibleSelection
75 * @see com.sun.star.accessibility.XAccessibleValue
76 * @see com.sun.star.accessibility.XAccessibleExtendedComponent
77 * @see com.sun.star.accessibility.XAccessibleComponent
78 * @see com.sun.star.accessibility.XAccessibleText
79 * @see com.sun.star.accessibility.XAccessibleContext
80 * @see ifc.accessibility._XAccessibleEventBroadcaster
81 * @see ifc.accessibility._XAccessibleAction
82 * @see ifc.accessibility._XAccessibleSelection
83 * @see ifc.accessibility._XAccessibleValue
84 * @see ifc.accessibility._XAccessibleExtendedComponent
85 * @see ifc.accessibility._XAccessibleComponent
86 * @see ifc.accessibility._XAccessibleText
87 * @see ifc.accessibility._XAccessibleContext
89 public class AccessibleMenu
extends TestCase
{
90 private static XTextDocument xTextDoc
= null;
91 private static XAccessibleAction action
= null;
94 * Finds accessible component with role <code>MENU</code>
95 * walking through the accessible component tree of a document.
97 protected TestEnvironment
createTestEnvironment(TestParameters Param
,
99 XMultiServiceFactory msf
= (XMultiServiceFactory
) Param
.getMSF();
102 SOfficeFactory SOF
= SOfficeFactory
.getFactory(msf
);
103 xTextDoc
= SOF
.createTextDoc(null);
104 } catch (com
.sun
.star
.uno
.Exception e
) {
105 throw new StatusException("Can't create document", e
);
108 XInterface oObj
= null;
111 oObj
= (XInterface
) msf
.createInstance("com.sun.star.awt.Toolkit");
112 } catch (com
.sun
.star
.uno
.Exception e
) {
113 log
.println("Couldn't get toolkit");
114 e
.printStackTrace(log
);
115 throw new StatusException("Couldn't get toolkit", e
);
118 XExtendedToolkit tk
= (XExtendedToolkit
) UnoRuntime
.queryInterface(
119 XExtendedToolkit
.class, oObj
);
123 XWindow xWindow
= (XWindow
) UnoRuntime
.queryInterface(XWindow
.class,
124 tk
.getActiveTopWindow());
126 AccessibilityTools at
= new AccessibilityTools();
128 XAccessible xRoot
= at
.getAccessibleObject(xWindow
);
130 at
.printAccessibleTree(log
, xRoot
, Param
.getBool(util
.PropertyName
.DEBUG_IS_ACTIVE
));
131 XAccessibleContext menubar
= at
.getAccessibleObjectForRole(xRoot
,
132 AccessibleRole
.MENU_BAR
);
136 oObj
= menubar
.getAccessibleChild(2);
137 menu2
= menubar
.getAccessibleChild(1);
138 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
141 log
.println("ImplementationName " + utils
.getImplName(oObj
));
143 TestEnvironment tEnv
= new TestEnvironment(oObj
);
145 final XAccessibleAction act1
= (XAccessibleAction
) UnoRuntime
.queryInterface(
146 XAccessibleAction
.class, oObj
);
147 final XAccessibleAction act2
= (XAccessibleAction
) UnoRuntime
.queryInterface(
148 XAccessibleAction
.class, menu2
);
150 tEnv
.addObjRelation("EventProducer",
151 new ifc
.accessibility
._XAccessibleEventBroadcaster
.EventProducer() {
152 public void fireEvent() {
154 act2
.doAccessibleAction(0);
158 } catch (InterruptedException e
) {
161 act1
.doAccessibleAction(0);
162 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
167 XAccessibleText text
= (XAccessibleText
) UnoRuntime
.queryInterface(
168 XAccessibleText
.class, oObj
);
170 tEnv
.addObjRelation("XAccessibleText.Text", text
.getText());
172 tEnv
.addObjRelation("EditOnly", "Can't change or select Text in Menu");
174 tEnv
.addObjRelation("LimitedBounds", "yes");
176 tEnv
.addObjRelation("XAccessibleSelection.OneAlwaysSelected",
179 tEnv
.addObjRelation("XAccessibleSelection.multiSelection",
185 protected void cleanup(TestParameters Param
, PrintWriter log
) {
187 util
.DesktopTools
.closeDoc(xTextDoc
);
189 } catch (com
.sun
.star
.lang
.DisposedException e
) {
190 log
.println("Object already disposed");
195 * Creates a new writer document
197 protected void initialize(TestParameters Param
, PrintWriter log
) {
201 * Sleeps for 0.5 sec. to allow StarOffice to react on <code>
204 private void shortWait() {
207 } catch (InterruptedException e
) {
208 log
.println("While waiting :" + e
);