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