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