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 package mod._svtools; 28 29 import com.sun.star.view.XSelectionSupplier; 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.DesktopTools; 38 import util.SOfficeFactory; 39 40 import com.sun.star.accessibility.AccessibleRole; 41 import com.sun.star.accessibility.XAccessible; 42 import com.sun.star.awt.XWindow; 43 import com.sun.star.beans.PropertyValue; 44 import com.sun.star.frame.XController; 45 import com.sun.star.frame.XDesktop; 46 import com.sun.star.frame.XDispatch; 47 import com.sun.star.frame.XDispatchProvider; 48 import com.sun.star.frame.XFrame; 49 import com.sun.star.frame.XModel; 50 import com.sun.star.lang.XMultiServiceFactory; 51 import com.sun.star.text.XTextDocument; 52 import com.sun.star.uno.UnoRuntime; 53 import com.sun.star.uno.XInterface; 54 import com.sun.star.util.URL; 55 56 57 /** 58 * Test for object that implements the following interfaces : 59 * <ul> 60 * <li> 61 * <code>::com::sun::star::accessibility::XAccessibleContext 62 * </code></li> 63 * <li> 64 * <code>::com::sun::star::accessibility::XAccessibleEventBroadcaster 65 * </code></li> 66 * </ul> <p> 67 * 68 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster 69 * @see com.sun.star.accessibility.XAccessibleContext 70 * @see ifc.accessibility._XAccessibleEventBroadcaster 71 * @see ifc.accessibility._XAccessibleContext 72 */ 73 public class AccessibleBrowseBoxTable extends TestCase { 74 static XDesktop the_Desk; 75 static XTextDocument xTextDoc; 76 77 /** 78 * Creates the Desktop service (<code>com.sun.star.frame.Desktop</code>). 79 */ 80 protected void initialize(TestParameters Param, PrintWriter log) { 81 the_Desk = (XDesktop) UnoRuntime.queryInterface(XDesktop.class, 82 DesktopTools.createDesktop( 83 (XMultiServiceFactory)Param.getMSF())); 84 } 85 86 /** 87 * Disposes the document, if exists, created in 88 * <code>createTestEnvironment</code> method. 89 */ 90 protected void cleanup(TestParameters Param, PrintWriter log) { 91 log.println("disposing xTextDoc"); 92 93 if (xTextDoc != null) { 94 xTextDoc.dispose(); 95 } 96 } 97 98 /** 99 * Creates a text document. Opens the DataSource browser. 100 * Creates an instance of the service 101 * <code>com.sun.star.awt.Toolkit</code> and gets active top window. 102 * Then obtains an accessible object with the role 103 * <code>AccessibleRole.TABLE</code> and with the name 104 * <code>"Table"</code>. 105 * Object relations created : 106 * <ul> 107 * <li> <code>'EventProducer'</code> for 108 * {@link ifc.accessibility._XAccessibleEventBroadcaster}: 109 * method <code>fireEvent()</code> is empty because object is transient 110 * </li> 111 * </ul> 112 * 113 * @param tParam test parameters 114 * @param log writer to log information while testing 115 * 116 * @see com.sun.star.awt.Toolkit 117 * @see com.sun.star.accessibility.AccessibleRole 118 * @see ifc.accessibility._XAccessibleEventBroadcaster 119 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster 120 */ 121 protected TestEnvironment createTestEnvironment(TestParameters tParam, 122 PrintWriter log) { 123 log.println("creating a test environment"); 124 125 if (xTextDoc != null) { 126 xTextDoc.dispose(); 127 } 128 129 // get a soffice factory object 130 SOfficeFactory SOF = SOfficeFactory.getFactory( 131 (XMultiServiceFactory)tParam.getMSF()); 132 133 try { 134 log.println("creating a text document"); 135 xTextDoc = SOF.createTextDoc(null); 136 } catch (com.sun.star.uno.Exception e) { 137 // Some exception occures.FAILED 138 e.printStackTrace(log); 139 throw new StatusException("Couldn't create document", e); 140 } 141 142 shortWait(); 143 144 XModel aModel1 = (XModel) UnoRuntime.queryInterface(XModel.class, 145 xTextDoc); 146 147 XController secondController = aModel1.getCurrentController(); 148 149 XDispatchProvider aProv = (XDispatchProvider)UnoRuntime.queryInterface( 150 XDispatchProvider.class, 151 secondController); 152 153 XDispatch getting = null; 154 155 log.println("opening DatasourceBrowser"); 156 157 URL the_url = new URL(); 158 the_url.Complete = ".component:DB/DataSourceBrowser"; 159 getting = aProv.queryDispatch(the_url, "_beamer", 12); 160 161 PropertyValue[] noArgs = new PropertyValue[0]; 162 getting.dispatch(the_url, noArgs); 163 164 shortWait(); 165 166 XFrame the_frame1 = the_Desk.getCurrentFrame(); 167 168 if (the_frame1 == null) { 169 log.println("Current frame was not found !!!"); 170 } 171 172 XFrame the_frame2 = the_frame1.findFrame("_beamer", 4); 173 XController xCont = the_frame2.getController(); 174 175 the_frame2.setName("DatasourceBrowser"); 176 177 final PropertyValue[] params = new PropertyValue[3]; 178 PropertyValue param1 = new PropertyValue(); 179 param1.Name = "DataSourceName"; 180 param1.Value = "Bibliography"; 181 params[0] = param1; 182 183 PropertyValue param2 = new PropertyValue(); 184 param2.Name = "CommandType"; 185 param2.Value = new Integer(com.sun.star.sdb.CommandType.TABLE); 186 params[1] = param2; 187 188 PropertyValue param3 = new PropertyValue(); 189 param3.Name = "Command"; 190 param3.Value = "biblio"; 191 params[2] = param3; 192 193 final XSelectionSupplier xSelect = (XSelectionSupplier) UnoRuntime.queryInterface( 194 XSelectionSupplier.class, xCont); 195 196 197 final Object[] initArgs = params; 198 199 XInterface oObj = null; 200 201 AccessibilityTools at = new AccessibilityTools(); 202 203 XWindow xWindow = secondController.getFrame().getContainerWindow(); 204 205 XAccessible xRoot = at.getAccessibleObject(xWindow); 206 207 oObj = at.getAccessibleObjectForRole(xRoot, AccessibleRole.TABLE, 208 "Table"); 209 210 log.println("ImplementationName: " + util.utils.getImplName(oObj)); 211 212 TestEnvironment tEnv = new TestEnvironment(oObj); 213 214 tEnv.addObjRelation("EventProducer", 215 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() { 216 public void fireEvent() { 217 try { 218 xSelect.select(params); 219 } catch (com.sun.star.lang.IllegalArgumentException ex) { 220 } 221 } 222 }); 223 224 return tEnv; 225 } 226 227 /** 228 * Sleeps for 0.5 sec. to allow StarOffice to react on <code> 229 * reset</code> call. 230 */ 231 private void shortWait() { 232 try { 233 Thread.sleep(5000); 234 } catch (InterruptedException e) { 235 System.out.println("While waiting :" + e); 236 } 237 } 238 } 239