xref: /AOO41X/main/qadevOOo/tests/java/mod/_sc/ScAccessibleCsvRuler.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 
28 package mod._sc;
29 
30 import java.io.PrintWriter;
31 
32 import lib.StatusException;
33 import lib.TestCase;
34 import lib.TestEnvironment;
35 import lib.TestParameters;
36 import util.AccessibilityTools;
37 import util.SOfficeFactory;
38 import util.utils;
39 
40 import com.sun.star.accessibility.AccessibleRole;
41 import com.sun.star.accessibility.XAccessible;
42 import com.sun.star.accessibility.XAccessibleAction;
43 import com.sun.star.accessibility.XAccessibleContext;
44 import com.sun.star.accessibility.XAccessibleText;
45 import com.sun.star.awt.XExtendedToolkit;
46 import com.sun.star.awt.XWindow;
47 import com.sun.star.beans.PropertyValue;
48 import com.sun.star.lang.XComponent;
49 import com.sun.star.lang.XMultiServiceFactory;
50 import com.sun.star.uno.UnoRuntime;
51 import com.sun.star.uno.XInterface;
52 
53 public class ScAccessibleCsvRuler extends TestCase {
54 
55     Thread lThread = null;
56     static XAccessibleAction accAction = null;
57 
58     /**
59      * Called to create an instance of <code>TestEnvironment</code> with an
60      * object to test and related objects. Subclasses should implement this
61      * method to provide the implementation and related objects. The method is
62      * called from <code>getTestEnvironment()</code>.
63      *
64      * @param tParam test parameters
65      * @param log writer to log information while testing
66      *
67      * @see TestEnvironment
68      * @see #getTestEnvironment()
69      */
70     protected TestEnvironment createTestEnvironment(TestParameters Param,
71                                                     PrintWriter log) {
72         XInterface oObj = null;
73 
74         shortWait();
75 
76         XMultiServiceFactory msf = (XMultiServiceFactory) Param.getMSF();
77 
78         try {
79             oObj = (XInterface) msf.createInstance("com.sun.star.awt.Toolkit");
80         } catch (com.sun.star.uno.Exception e) {
81             log.println("Couldn't get toolkit");
82             e.printStackTrace(log);
83             throw new StatusException("Couldn't get toolkit", e);
84         }
85 
86         XExtendedToolkit tk = (XExtendedToolkit) UnoRuntime.queryInterface(
87                                       XExtendedToolkit.class, oObj);
88 
89         XWindow xWindow = (XWindow) UnoRuntime.queryInterface(XWindow.class,
90                                                               tk.getActiveTopWindow());
91 
92         XAccessible xRoot = AccessibilityTools.getAccessibleObject(xWindow);
93 
94         oObj = AccessibilityTools.getAccessibleObjectForRole(xRoot, AccessibleRole.PUSH_BUTTON,
95                                              "Cancel");
96 
97         accAction = (XAccessibleAction) UnoRuntime.queryInterface(
98                             XAccessibleAction.class, oObj);
99 
100         XAccessibleContext acc = AccessibilityTools.getAccessibleObjectForRole(xRoot,
101                                                                AccessibleRole.RADIO_BUTTON);
102 
103         log.println("Click on: " + acc.getAccessibleName());
104 
105         XAccessibleAction accAction2 = (XAccessibleAction) UnoRuntime.queryInterface(
106                                                XAccessibleAction.class, acc);
107 
108         try {
109             accAction2.doAccessibleAction(0);
110         } catch (com.sun.star.lang.IndexOutOfBoundsException iae) {
111         }
112 
113 
114         //util.dbg.printInterfaces(oObj);
115         AccessibilityTools.printAccessibleTree(log, xRoot);
116         oObj = AccessibilityTools.getAccessibleObjectForRole(xRoot, AccessibleRole.TEXT,
117                                              "Ruler", true);
118 
119         log.println("ImplementationName " + utils.getImplName(oObj));
120 
121         TestEnvironment tEnv = new TestEnvironment(oObj);
122 
123         tEnv.addObjRelation("EditOnly",
124                             "This method isn't supported in this dialog");
125 
126         XAccessibleText text = (XAccessibleText) UnoRuntime.queryInterface(
127                                        XAccessibleText.class, oObj);
128 
129         int lastone = 100;
130 
131         for (int i = 0; i < 1000; i++) {
132             try {
133                 text.getCharacterBounds(i);
134             } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
135                 lastone = i - 1;
136 
137                 break;
138             }
139         }
140 
141         tEnv.addObjRelation("LimitedBounds", new Integer(lastone));
142         tEnv.addObjRelation("PreviousUsed",new int[]{11,22,33,44,55,66,77,88,99});
143 
144         return tEnv;
145     }
146 
147     /**
148     * Called while disposing a <code>TestEnvironment</code>.
149     * Disposes calc document.
150     * @param tParam test parameters
151     * @param tEnv the environment to cleanup
152     * @param log writer to log information while testing
153     */
154     protected void cleanup( TestParameters Param, PrintWriter log) {
155 /*        log.println( "    closing Dialog " );
156         try {
157             accAction.doAccessibleAction(0);
158         } catch (com.sun.star.lang.IndexOutOfBoundsException iae) {
159             log.println("Couldn't close dialog");
160         } */
161     }
162 
163     /**
164      * Called while the <code>TestCase</code> initialization. In the
165      * implementation does nothing. Subclasses can override to initialize
166      * objects shared among all <code>TestEnvironment</code>s.
167      *
168      * @param tParam test parameters
169      * @param log writer to log information while testing
170      *
171      * @see #initializeTestCase()
172      */
173     protected void initialize(TestParameters Param, PrintWriter log) {
174         // get a soffice factory object
175         SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)Param.getMSF());
176 
177         log.println("opening dialog");
178 
179         PropertyValue[] args = new PropertyValue[1];
180         try {
181             args[0] = new PropertyValue();
182             args[0].Name = "InteractionHandler";
183             args[0].Value = ((XMultiServiceFactory)Param.getMSF()).createInstance(
184                 "com.sun.star.comp.uui.UUIInteractionHandler");
185         } catch(com.sun.star.uno.Exception e) {
186         }
187 
188         lThread = new loadThread(SOF, args);
189         lThread.start();
190         shortWait();
191 
192     }
193 
194     /**
195     * Sleeps for 2 sec. to allow StarOffice to react on <code>
196     * reset</code> call.
197     */
198     private void shortWait() {
199         try {
200             Thread.sleep(2000) ;
201         } catch (InterruptedException e) {
202             log.println("While waiting :" + e) ;
203         }
204     }
205 
206     public class loadThread extends Thread {
207 
208         private SOfficeFactory SOF = null ;
209         private PropertyValue[] args = null;
210         public XComponent xSpreadSheedDoc = null;
211 
212         public loadThread(SOfficeFactory SOF, PropertyValue[] Args) {
213             this.SOF = SOF;
214             this.args = Args;
215         }
216 
217         public void run() {
218             try {
219                 String url= utils.getFullTestURL("10test.csv");
220                 log.println("loading "+url);
221                 SOF.loadDocument(url,args);
222             } catch (com.sun.star.uno.Exception e) {
223                 e.printStackTrace();
224                 throw new StatusException( "Couldn't create document ", e );
225             }
226         }
227     }
228 
229 }
230