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 java.io.PrintWriter; 30 31 import lib.StatusException; 32 import lib.TestCase; 33 import lib.TestEnvironment; 34 import lib.TestParameters; 35 import util.AccessibilityTools; 36 import util.DesktopTools; 37 import util.SOfficeFactory; 38 39 import com.sun.star.accessibility.AccessibleRole; 40 import com.sun.star.accessibility.XAccessible; 41 import com.sun.star.awt.XWindow; 42 import com.sun.star.beans.PropertyValue; 43 import com.sun.star.frame.XController; 44 import com.sun.star.frame.XDesktop; 45 import com.sun.star.frame.XDispatch; 46 import com.sun.star.frame.XDispatchProvider; 47 import com.sun.star.frame.XFrame; 48 import com.sun.star.frame.XModel; 49 import com.sun.star.lang.XMultiServiceFactory; 50 import com.sun.star.text.XTextDocument; 51 import com.sun.star.uno.UnoRuntime; 52 import com.sun.star.uno.XInterface; 53 import com.sun.star.util.URL; 54 import com.sun.star.view.XSelectionSupplier; 55 56 public class AccessibleBrowseBox extends TestCase { 57 58 static XDesktop the_Desk; 59 static XTextDocument xTextDoc; 60 61 /** 62 * Creates the Desktop service (<code>com.sun.star.frame.Desktop</code>). 63 */ 64 protected void initialize(TestParameters Param, PrintWriter log) { 65 the_Desk = (XDesktop) UnoRuntime.queryInterface( 66 XDesktop.class, DesktopTools.createDesktop((XMultiServiceFactory) Param.getMSF())); 67 } 68 69 /** 70 * Disposes the document, if exists, created in 71 * <code>createTestEnvironment</code> method. 72 */ 73 protected void cleanup(TestParameters Param, PrintWriter log) { 74 75 log.println("disposing xTextDoc"); 76 77 if (xTextDoc != null) { 78 xTextDoc.dispose(); 79 } 80 } 81 82 /** 83 * Called to create an instance of <code>TestEnvironment</code> with an 84 * object to test and related objects. Subclasses should implement this 85 * method to provide the implementation and related objects. The method is 86 * called from <code>getTestEnvironment()</code>. 87 * 88 * @param tParam test parameters 89 * @param log writer to log information while testing 90 * 91 * @see TestEnvironment 92 * @see #getTestEnvironment() 93 */ 94 protected TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) { 95 96 log.println("creating a test environment"); 97 98 if (xTextDoc != null) { 99 xTextDoc.dispose(); // get a soffice factory object 100 } 101 SOfficeFactory SOF = SOfficeFactory.getFactory((XMultiServiceFactory) tParam.getMSF()); 102 103 try { 104 log.println("creating a text document"); 105 xTextDoc = SOF.createTextDoc(null); 106 } catch (com.sun.star.uno.Exception e) { 107 // Some exception occures.FAILED 108 e.printStackTrace(log); 109 throw new StatusException("Couldn't create document", e); 110 } 111 112 shortWait(); 113 114 XModel aModel1 = (XModel) UnoRuntime.queryInterface(XModel.class, xTextDoc); 115 116 XController secondController = aModel1.getCurrentController(); 117 118 119 XDispatchProvider aProv = (XDispatchProvider) UnoRuntime.queryInterface(XDispatchProvider.class, 120 secondController); 121 122 XDispatch getting = null; 123 124 log.println("opening DatasourceBrowser"); 125 URL the_url = new URL(); 126 the_url.Complete = ".component:DB/DataSourceBrowser"; 127 getting = aProv.queryDispatch(the_url, "_beamer", 12); 128 PropertyValue[] noArgs = new PropertyValue[0]; 129 getting.dispatch(the_url, noArgs); 130 131 shortWait(); 132 133 XFrame the_frame1 = the_Desk.getCurrentFrame(); 134 135 if (the_frame1 == null) { 136 log.println("Current frame was not found !!!"); 137 } 138 139 XFrame the_frame2 = the_frame1.findFrame("_beamer", 4); 140 141 the_frame2.setName("DatasourceBrowser"); 142 143 XInterface oObj = null; 144 145 final XSelectionSupplier xSelect = (XSelectionSupplier) UnoRuntime.queryInterface( 146 XSelectionSupplier.class, the_frame2.getController()); 147 148 PropertyValue[] params = new PropertyValue[]{new PropertyValue(), new PropertyValue(), new PropertyValue()}; 149 params[0].Name = "DataSourceName"; 150 params[0].Value = "Bibliography"; 151 params[1].Name = "CommandType"; 152 params[1].Value = new Integer(com.sun.star.sdb.CommandType.TABLE); 153 params[2].Name = "Command"; 154 params[2].Value = "biblio"; 155 156 final PropertyValue[] fParams = params; 157 158 shortWait(); 159 160 AccessibilityTools at = new AccessibilityTools(); 161 162 XWindow xWindow = secondController.getFrame().getContainerWindow(); 163 164 XAccessible xRoot = at.getAccessibleObject(xWindow); 165 166 at.printAccessibleTree(log, xRoot, tParam.getBool(util.PropertyName.DEBUG_IS_ACTIVE)); 167 168 oObj = at.getAccessibleObjectForRole(xRoot, AccessibleRole.PANEL, "", "AccessibleBrowseBox"); 169 170 log.println("ImplementationName: " + util.utils.getImplName(oObj)); 171 172 TestEnvironment tEnv = new TestEnvironment(oObj); 173 174 175 tEnv.addObjRelation("EventProducer", 176 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() { 177 178 public void fireEvent() { 179 try { 180 xSelect.select(fParams); 181 } catch (com.sun.star.uno.Exception e) { 182 e.printStackTrace(); 183 } 184 } 185 }); 186 187 return tEnv; 188 } 189 190 /** 191 * Sleeps for 0.5 sec. to allow StarOffice to react on <code> 192 * reset</code> call. 193 */ 194 private void shortWait() { 195 try { 196 Thread.sleep(5000); 197 ; 198 } catch (InterruptedException e) { 199 System.out.println("While waiting :" + e); 200 } 201 } 202 } 203