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: AccessibleMenuSeparator.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
.awt
.XExtendedToolkit
;
37 import com
.sun
.star
.awt
.XWindow
;
38 import com
.sun
.star
.lang
.XMultiServiceFactory
;
39 import com
.sun
.star
.text
.XTextDocument
;
40 import com
.sun
.star
.uno
.UnoRuntime
;
41 import com
.sun
.star
.uno
.XInterface
;
43 import java
.io
.PrintWriter
;
45 import lib
.StatusException
;
47 import lib
.TestEnvironment
;
48 import lib
.TestParameters
;
50 import util
.AccessibilityTools
;
51 import util
.SOfficeFactory
;
56 * Test for object which is represented by accessible component
57 * of a menu separator in main menu of a document. <p>
59 * Object implements the following interfaces :
61 * <li> <code>::com::sun::star::accessibility::XAccessibleExtendedComponent</code></li>
62 * <li> <code>::com::sun::star::accessibility::XAccessibleEventBroadcaster</code></li>
63 * <li> <code>::com::sun::star::accessibility::XAccessibleComponent</code></li>
64 * <li> <code>::com::sun::star::accessibility::XAccessibleContext</code></li>
67 * @see com.sun.star.accessibility.XAccessibleExtendedComponent
68 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
69 * @see com.sun.star.accessibility.XAccessibleComponent
70 * @see com.sun.star.accessibility.XAccessibleContext
71 * @see ifc.accessibility._XAccessibleExtendedComponent
72 * @see ifc.accessibility._XAccessibleEventBroadcaster
73 * @see ifc.accessibility._XAccessibleComponent
74 * @see ifc.accessibility._XAccessibleContext
76 public class AccessibleMenuSeparator
extends TestCase
{
77 private static XTextDocument xTextDoc
= null;
78 private static XAccessibleAction action
= null;
79 private static XMultiServiceFactory msf
= null;
82 * Finds first accessible component with role <code>SEPARATOR</code>
83 * and implementation name <code>AccessibleMenuSeparator</code>
84 * walking through the accessible component tree of a document.
86 protected TestEnvironment
createTestEnvironment(TestParameters Param
,
88 XInterface oObj
= null;
91 oObj
= (XInterface
) msf
.createInstance("com.sun.star.awt.Toolkit");
92 } catch (com
.sun
.star
.uno
.Exception e
) {
93 log
.println("Couldn't get toolkit");
94 e
.printStackTrace(log
);
95 throw new StatusException("Couldn't get toolkit", e
);
98 XExtendedToolkit tk
= (XExtendedToolkit
) UnoRuntime
.queryInterface(
99 XExtendedToolkit
.class, oObj
);
103 AccessibilityTools at
= new AccessibilityTools();
105 Object atw
= tk
.getActiveTopWindow();
107 XWindow xWindow
= (XWindow
) UnoRuntime
.queryInterface(XWindow
.class,
110 XAccessible xRoot
= at
.getAccessibleObject(xWindow
);
112 at
.printAccessibleTree(log
, xRoot
, Param
.getBool(util
.PropertyName
.DEBUG_IS_ACTIVE
));
113 XAccessibleContext MenuBar
= at
.getAccessibleObjectForRole(xRoot
,
114 AccessibleRole
.MENU_BAR
);
115 XAccessibleAction act
= null;
119 XAccessible Menu
= MenuBar
.getAccessibleChild(1);
120 act
= (XAccessibleAction
) UnoRuntime
.queryInterface(
121 XAccessibleAction
.class, Menu
);
122 act
.doAccessibleAction(0);
127 //get a menue-separator
128 oObj
= Menu
.getAccessibleContext().getAccessibleChild(3);
129 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
130 e
.printStackTrace(log
);
133 log
.println("ImplementationName " + utils
.getImplName(oObj
));
135 TestEnvironment tEnv
= new TestEnvironment(oObj
);
137 final XAccessibleAction aAct
= act
;
139 tEnv
.addObjRelation("EventProducer",
140 new ifc
.accessibility
._XAccessibleEventBroadcaster
.EventProducer() {
141 public void fireEvent() {
143 aAct
.doAccessibleAction(0);
144 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
154 * Creates writer document.
156 protected void initialize(TestParameters Param
, PrintWriter log
) {
158 msf
= (XMultiServiceFactory
) Param
.getMSF();
160 SOfficeFactory SOF
= SOfficeFactory
.getFactory(msf
);
161 xTextDoc
= SOF
.createTextDoc(null);
162 } catch (com
.sun
.star
.uno
.Exception e
) {
163 throw new StatusException("Can't create document", e
);
170 protected void cleanup(TestParameters Param
, PrintWriter log
) {
171 util
.DesktopTools
.closeDoc(xTextDoc
);
176 * Sleeps for 0.5 sec. to allow StarOffice to react on <code>
179 private void shortWait() {
182 } catch (InterruptedException e
) {
183 log
.println("While waiting :" + e
);