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