1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 package mod._svtools;
25 
26 import com.sun.star.accessibility.AccessibleRole;
27 import com.sun.star.accessibility.XAccessibleComponent;
28 import com.sun.star.accessibility.XAccessibleContext;
29 import com.sun.star.awt.Point;
30 import java.awt.Robot;
31 import java.awt.event.InputEvent;
32 import java.io.PrintWriter;
33 
34 import lib.StatusException;
35 import lib.TestCase;
36 import lib.TestEnvironment;
37 import lib.TestParameters;
38 import util.AccessibilityTools;
39 import util.SOfficeFactory;
40 
41 import com.sun.star.accessibility.XAccessible;
42 import com.sun.star.awt.XExtendedToolkit;
43 import com.sun.star.awt.XWindow;
44 import com.sun.star.lang.XComponent;
45 import com.sun.star.lang.XMultiServiceFactory;
46 import com.sun.star.uno.UnoRuntime;
47 import com.sun.star.uno.XInterface;
48 
49 /**
50  * Test for object that implements the following interfaces :
51  * <ul>
52  *  <li><code>::com::sun::star::accessibility::XAccessibleComponent
53  *  </code></li>
54  *  <li><code>::com::sun::star::accessibility::XAccessibleContext
55  *  </code></li>
56  *  <li><code>::com::sun::star::accessibility::XAccessibleEventBroadcaster
57  *  </code></li>
58  *  <li>
59  *  <code>::com::sun::star::accessibility::XAccessibleExtendedComponent
60  *  </code></li>
61  * </ul> <p>
62  *
63  * @see com.sun.star.accessibility.XAccessibleExtendedComponent
64  * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
65  * @see com.sun.star.accessibility.XAccessibleContext
66  * @see com.sun.star.accessibility.XAccessibleComponent
67  * @see ifc.accessibility._XAccessibleComponent
68  * @see ifc.accessibility._XAccessibleExtendedComponent
69  * @see ifc.accessibility._XAccessibleEventBroadcaster
70  * @see ifc.accessibility._XAccessibleContext
71  */
72 public class AccessibleTabBarPage extends TestCase {
73 
74     static XComponent xDoc;
75 
76     /**
77      * Disposes the document, if exists, created in
78      * <code>createTestEnvironment</code> method.
79      */
cleanup( TestParameters Param, PrintWriter log)80     protected void cleanup( TestParameters Param, PrintWriter log) {
81 
82         log.println("disposing xCalcDoc");
83         if (xDoc != null) {
84             util.DesktopTools.closeDoc(xDoc);
85         }
86     }
87 
88     /**
89      * Creates a spreadsheet document. Then obtains an accessible object with
90      * the role <code>AccessibleRole.PAGETAB</code>.
91      * Object relations created :
92      * <ul>
93      *  <li> <code>'EventProducer'</code> for
94      *      {@link ifc.accessibility._XAccessibleEventBroadcaster}:
95      *   </li>
96      * </ul>
97      *
98      * @param tParam test parameters
99      * @param log writer to log information while testing
100      *
101      * @see com.sun.star.awt.Toolkit
102      * @see com.sun.star.accessibility.AccessibleRole
103      * @see ifc.accessibility._XAccessibleEventBroadcaster
104      * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
105      */
createTestEnvironment(TestParameters tParam, PrintWriter log)106     protected TestEnvironment createTestEnvironment(TestParameters tParam,
107         PrintWriter log) {
108 
109         log.println( "creating a test environment" );
110 
111         if (xDoc != null) xDoc.dispose();
112 
113         // get a soffice factory object
114         SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF());
115 
116         try {
117             log.println( "creating a calc document" );
118             xDoc = (XComponent) UnoRuntime.queryInterface(XComponent.class, SOF.createCalcDoc(null));// SOF.createDrawDoc(null);
119         } catch ( com.sun.star.uno.Exception e ) {
120             // Some exception occured.FAILED
121             e.printStackTrace( log );
122             throw new StatusException( "Couldn't create document", e );
123         }
124 
125         shortWait();
126 
127         XInterface oObj = null;
128 
129         try {
130             oObj = (XInterface) ((XMultiServiceFactory)tParam.getMSF()).createInstance
131                 ("com.sun.star.awt.Toolkit") ;
132         } catch (com.sun.star.uno.Exception e) {
133             log.println("Couldn't get toolkit");
134             e.printStackTrace(log);
135             throw new StatusException("Couldn't get toolkit", e );
136         }
137 
138 
139         XExtendedToolkit tk = (XExtendedToolkit)
140             UnoRuntime.queryInterface(XExtendedToolkit.class, oObj);
141 
142 
143         AccessibilityTools at = new AccessibilityTools();
144 
145         shortWait();
146 
147         XWindow xWindow = (XWindow)
148             UnoRuntime.queryInterface(XWindow.class,tk.getActiveTopWindow());
149 
150         XAccessible xRoot = at.getAccessibleObject(xWindow);
151         at.printAccessibleTree(log, xRoot, tParam.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
152         oObj = at.getAccessibleObjectForRole(xRoot, AccessibleRole.PAGE_TAB, "Sheet1");
153         XAccessibleContext acc = at.getAccessibleObjectForRole(xRoot, AccessibleRole.PAGE_TAB, "Sheet2");
154         XAccessibleComponent accComp = (XAccessibleComponent) UnoRuntime.queryInterface(
155                                                XAccessibleComponent.class,
156                                                acc);
157         final Point point = accComp.getLocationOnScreen();
158         log.println("ImplementationName: " + util.utils.getImplName(oObj));
159 
160         TestEnvironment tEnv = new TestEnvironment( oObj );
161         tEnv.addObjRelation("Destroy","yes");
162         tEnv.addObjRelation("EventProducer",
163             new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer(){
164                 public void fireEvent() {
165                 try {
166                     Robot rob = new Robot();
167                     rob.mouseMove(point.X + 25, point.Y + 5);
168                     rob.mousePress(InputEvent.BUTTON1_MASK);
169                 } catch (java.awt.AWTException e) {
170                     System.out.println("couldn't fire event");
171                 }
172                 }
173             });
174 
175         return tEnv;
176     }
177 
178     /**
179     * Sleeps for 0.5 sec. to allow StarOffice to react on <code>
180     * reset</code> call.
181     */
shortWait()182     private void shortWait() {
183         try {
184             Thread.sleep(5000);
185         } catch (InterruptedException e) {
186             System.out.println("While waiting :" + e) ;
187         }
188     }
189 
190 }
191