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 package mod._svtools;
24 
25 import java.io.PrintWriter;
26 
27 import lib.StatusException;
28 import lib.TestCase;
29 import lib.TestEnvironment;
30 import lib.TestParameters;
31 import util.AccessibilityTools;
32 import util.SOfficeFactory;
33 
34 import com.sun.star.accessibility.AccessibleRole;
35 import com.sun.star.accessibility.XAccessible;
36 import com.sun.star.awt.PosSize;
37 import com.sun.star.awt.XWindow;
38 import com.sun.star.frame.XModel;
39 import com.sun.star.lang.XComponent;
40 import com.sun.star.lang.XMultiServiceFactory;
41 import com.sun.star.uno.UnoRuntime;
42 import com.sun.star.uno.XInterface;
43 import com.sun.star.util.XCloseable;
44 
45 
46 public class AccessibleTabBar extends TestCase {
47     static XComponent xDoc;
48 
49     /**
50      * Disposes the document, if exists, created in
51      * <code>createTestEnvironment</code> method.
52      */
cleanup(TestParameters Param, PrintWriter log)53     protected void cleanup(TestParameters Param, PrintWriter log) {
54         log.println("disposing xCalcDoc");
55 
56         if (xDoc != null) {
57             closeDoc(xDoc);
58         }
59     }
60 
61     /**
62      * Creates a spreadsheet document. Then obtains an accessible object with
63      * the role <code>AccessibleRole.PAGETAB</code>.
64      * Object relations created :
65      * <ul>
66      *  <li> <code>'EventProducer'</code> for
67      *      {@link ifc.accessibility._XAccessibleEventBroadcaster}:
68      *   </li>
69      * </ul>
70      *
71      * @param tParam test parameters
72      * @param log writer to log information while testing
73      *
74      * @see com.sun.star.awt.Toolkit
75      * @see com.sun.star.accessibility.AccessibleRole
76      * @see ifc.accessibility._XAccessibleEventBroadcaster
77      * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
78      */
createTestEnvironment(TestParameters tParam, PrintWriter log)79     protected TestEnvironment createTestEnvironment(TestParameters tParam,
80                                                     PrintWriter log) {
81         log.println("creating a test environment");
82 
83         if (xDoc != null) {
84             closeDoc(xDoc);
85         }
86 
87         XMultiServiceFactory msf = (XMultiServiceFactory) tParam.getMSF();
88 
89         // get a soffice factory object
90         SOfficeFactory SOF = SOfficeFactory.getFactory(msf);
91 
92         try {
93             log.println("creating a calc document");
94             xDoc = (XComponent) UnoRuntime.queryInterface(XComponent.class,
95                                                           SOF.createCalcDoc(
96                                                                   null));
97         } catch (com.sun.star.uno.Exception e) {
98             // Some exception occures.FAILED
99             e.printStackTrace(log);
100             throw new StatusException("Couldn't create document", e);
101         }
102 
103         shortWait();
104 
105         XInterface oObj = null;
106 
107         AccessibilityTools at = new AccessibilityTools();
108 
109         shortWait();
110 
111         XWindow xWindow = UnoRuntime.queryInterface(XModel.class, xDoc).
112             getCurrentController().getFrame().getContainerWindow();
113 
114         XAccessible xRoot = at.getAccessibleObject(xWindow);
115         at.printAccessibleTree(log, xRoot, tParam.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
116         oObj = at.getAccessibleObjectForRole(xRoot, AccessibleRole.PANEL);
117 
118         log.println("ImplementationName: " + util.utils.getImplName(oObj));
119 
120         TestEnvironment tEnv = new TestEnvironment(oObj);
121 
122         final XWindow aWin = xWindow;
123 
124         tEnv.addObjRelation("EventProducer",
125                             new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
126             public void fireEvent() {
127                 aWin.setPosSize(100,100, 500, 500, PosSize.POSSIZE);
128             }
129         });
130 
131         return tEnv;
132     }
133 
134     /**
135     * Sleeps for 3 sec. to allow StarOffice to react on <code>
136     * reset</code> call.
137     */
shortWait()138     private void shortWait() {
139         try {
140             Thread.sleep(5000);
141         } catch (InterruptedException e) {
142             System.out.println("While waiting :" + e);
143         }
144     }
145 
closeDoc(XComponent xDoc)146     protected void closeDoc(XComponent xDoc) {
147         XCloseable closer = (XCloseable) UnoRuntime.queryInterface(
148                                     XCloseable.class, xDoc);
149 
150         try {
151             closer.close(true);
152         } catch (com.sun.star.util.CloseVetoException e) {
153             log.println("Couldn't close document " + e.getMessage());
154         } catch (java.lang.NullPointerException e) {
155             log.println("Couldn't close document " + e.getMessage());
156         }
157     }
158 }