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