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