xref: /AOO41X/main/qadevOOo/tests/java/mod/_toolkit/AccessibleMenuSeparator.java (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 package mod._toolkit;
28 
29 import com.sun.star.accessibility.AccessibleRole;
30 import com.sun.star.accessibility.XAccessible;
31 import com.sun.star.accessibility.XAccessibleAction;
32 import com.sun.star.accessibility.XAccessibleContext;
33 import com.sun.star.awt.XExtendedToolkit;
34 import com.sun.star.awt.XWindow;
35 import com.sun.star.frame.XModel;
36 import com.sun.star.lang.XMultiServiceFactory;
37 import com.sun.star.text.XTextDocument;
38 import com.sun.star.uno.UnoRuntime;
39 import com.sun.star.uno.XInterface;
40 
41 import java.io.PrintWriter;
42 
43 import lib.StatusException;
44 import lib.TestCase;
45 import lib.TestEnvironment;
46 import lib.TestParameters;
47 
48 import util.AccessibilityTools;
49 import util.SOfficeFactory;
50 import util.utils;
51 
52 
53 /**
54  * Test for object which is represented by accessible component
55  * of a menu separator in main menu of a document. <p>
56  *
57  * Object implements the following interfaces :
58  * <ul>
59  *  <li> <code>::com::sun::star::accessibility::XAccessibleExtendedComponent</code></li>
60  *  <li> <code>::com::sun::star::accessibility::XAccessibleEventBroadcaster</code></li>
61  *  <li> <code>::com::sun::star::accessibility::XAccessibleComponent</code></li>
62  *  <li> <code>::com::sun::star::accessibility::XAccessibleContext</code></li>
63  * </ul> <p>
64  *
65  * @see com.sun.star.accessibility.XAccessibleExtendedComponent
66  * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
67  * @see com.sun.star.accessibility.XAccessibleComponent
68  * @see com.sun.star.accessibility.XAccessibleContext
69  * @see ifc.accessibility._XAccessibleExtendedComponent
70  * @see ifc.accessibility._XAccessibleEventBroadcaster
71  * @see ifc.accessibility._XAccessibleComponent
72  * @see ifc.accessibility._XAccessibleContext
73  */
74 public class AccessibleMenuSeparator extends TestCase {
75     private static XTextDocument xTextDoc = null;
76     private static XAccessibleAction action = null;
77     private static XMultiServiceFactory msf = null;
78 
79     /**
80      * Finds first accessible component with role <code>SEPARATOR</code>
81      * and implementation name <code>AccessibleMenuSeparator</code>
82      * walking through the accessible component tree of a document.
83      */
84     protected TestEnvironment createTestEnvironment(TestParameters Param,
85                                                     PrintWriter log) {
86         shortWait();
87 
88         AccessibilityTools at = new AccessibilityTools();
89 
90         XWindow xWindow = UnoRuntime.queryInterface(XModel.class, xTextDoc).
91             getCurrentController().getFrame().getContainerWindow();
92 
93         XAccessible xRoot = at.getAccessibleObject(xWindow);
94 
95         at.printAccessibleTree(log, xRoot, Param.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
96         XAccessibleContext MenuBar = at.getAccessibleObjectForRole(xRoot,
97                                                                    AccessibleRole.MENU_BAR);
98         XAccessibleAction act = null;
99         XInterface oObj = null;
100 
101         try {
102             //activate Edit-Menu
103             XAccessible Menu = MenuBar.getAccessibleChild(1);
104             act = (XAccessibleAction) UnoRuntime.queryInterface(
105                           XAccessibleAction.class, Menu);
106             act.doAccessibleAction(0);
107 
108             shortWait();
109 
110 
111             //get a menue-separator
112             oObj = Menu.getAccessibleContext().getAccessibleChild(3);
113         } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
114             e.printStackTrace(log);
115         }
116 
117         log.println("ImplementationName " + utils.getImplName(oObj));
118 
119         TestEnvironment tEnv = new TestEnvironment(oObj);
120 
121         final XAccessibleAction aAct = act;
122 
123         tEnv.addObjRelation("EventProducer",
124                             new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
125             public void fireEvent() {
126                 try {
127                     aAct.doAccessibleAction(0);
128                 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
129                     e.printStackTrace();
130                 }
131             }
132         });
133 
134         return tEnv;
135     }
136 
137     /**
138      * Creates writer document.
139      */
140     protected void initialize(TestParameters Param, PrintWriter log) {
141         try {
142             msf = (XMultiServiceFactory) Param.getMSF();
143 
144             SOfficeFactory SOF = SOfficeFactory.getFactory(msf);
145             xTextDoc = SOF.createTextDoc(null);
146         } catch (com.sun.star.uno.Exception e) {
147             throw new StatusException("Can't create document", e);
148         }
149     }
150 
151     /**
152      * Disposes document.
153      */
154     protected void cleanup(TestParameters Param, PrintWriter log) {
155         util.DesktopTools.closeDoc(xTextDoc);
156         ;
157     }
158 
159     /**
160     * Sleeps for 0.5 sec. to allow StarOffice to react on <code>
161     * reset</code> call.
162     */
163     private void shortWait() {
164         try {
165             Thread.sleep(500);
166         } catch (InterruptedException e) {
167             log.println("While waiting :" + e);
168         }
169     }
170 }