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._toolkit; 28 29 import com.sun.star.accessibility.AccessibleRole; 30 import com.sun.star.accessibility.XAccessible; 31 import com.sun.star.accessibility.XAccessibleAction; 32 import com.sun.star.awt.XWindow; 33 import com.sun.star.frame.XDesktop; 34 import com.sun.star.frame.XModel; 35 import com.sun.star.lang.XMultiServiceFactory; 36 import com.sun.star.text.XTextDocument; 37 import com.sun.star.uno.UnoRuntime; 38 import com.sun.star.uno.XInterface; 39 40 import java.io.PrintWriter; 41 42 import lib.StatusException; 43 import lib.TestCase; 44 import lib.TestEnvironment; 45 import lib.TestParameters; 46 47 import util.AccessibilityTools; 48 import util.DesktopTools; 49 import util.SOfficeFactory; 50 51 52 /** 53 * Test for object that implements the following interfaces : 54 * <ul> 55 * <li><code> 56 * ::com::sun::star::accessibility::XAccessibleContext</code></li> 57 * <li><code> 58 * ::com::sun::star::accessibility::XAccessibleEventBroadcaster 59 * </code></li> 60 * <li><code> 61 * ::com::sun::star::accessibility::XAccessibleComponent</code></li> 62 * <li><code> 63 * ::com::sun::star::accessibility::XAccessibleExtendedComponent 64 * </code></li> 65 * <li><code> 66 * ::com::sun::star::accessibility::XAccessibleAction</code></li> 67 * <li><code> 68 * ::com::sun::star::accessibility::XAccessibleText</code></li> 69 * <li><code> 70 * ::com::sun::star::accessibility::XAccessibleValue</code></li> 71 * </ul> <p> 72 * 73 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster 74 * @see com.sun.star.accessibility.XAccessibleContext 75 * @see com.sun.star.accessibility.XAccessibleComponent 76 * @see com.sun.star.accessibility.XAccessibleExtendedComponent 77 * @see com.sun.star.accessibility.XAccessibleAction 78 * @see com.sun.star.accessibility.XAccessibleText 79 * @see com.sun.star.accessibility.XAccessibleValue 80 * @see ifc.accessibility._XAccessibleEventBroadcaster 81 * @see ifc.accessibility._XAccessibleContext 82 * @see ifc.accessibility._XAccessibleComponent 83 * @see ifc.accessibility.XAccessibleExtendedComponent 84 * @see ifc.accessibility.XAccessibleAction 85 * @see ifc.accessibility.XAccessibleText 86 * @see ifc.accessibility.XAccessibleValue 87 */ 88 public class AccessibleToolBoxItem extends TestCase { 89 private static XDesktop the_Desk; 90 private static XTextDocument xTextDoc; 91 92 /** 93 * Creates the Desktop service (<code>com.sun.star.frame.Desktop</code>). 94 */ 95 protected void initialize(TestParameters Param, PrintWriter log) { 96 the_Desk = (XDesktop) UnoRuntime.queryInterface(XDesktop.class, 97 DesktopTools.createDesktop( 98 (XMultiServiceFactory) Param.getMSF())); 99 } 100 101 /** 102 * Disposes the document, if exists, created in 103 * <code>createTestEnvironment</code> method. 104 */ 105 protected void cleanup(TestParameters Param, PrintWriter log) { 106 log.println("disposing xTextDoc"); 107 108 if (xTextDoc != null) { 109 closeDoc(); 110 } 111 } 112 113 /** 114 * Creates a text document. 115 * Then obtains an accessible object with 116 * the role <code>AccessibleRole.PUSHBUTTON</code> and with the name 117 * <code>"Bold"</code>. 118 * Object relations created : 119 * <ul> 120 * <li> <code>'EventProducer'</code> for 121 * {@link ifc.accessibility._XAccessibleEventBroadcaster}</li> 122 * <li> <code>'XAccessibleText.Text'</code> for 123 * {@link ifc.accessibility._XAccessibleText}: the name of button</li> 124 * </ul> 125 * 126 * @param tParam test parameters 127 * @param log writer to log information while testing 128 * 129 * @see com.sun.star.awt.Toolkit 130 * @see com.sun.star.accessibility.AccessibleRole 131 * @see ifc.accessibility._XAccessibleEventBroadcaster 132 * @see ifc.accessibility._XAccessibleText 133 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster 134 * @see com.sun.star.accessibility.XAccessibleText 135 */ 136 protected TestEnvironment createTestEnvironment(TestParameters tParam, 137 PrintWriter log) { 138 log.println("creating a test environment"); 139 140 if (xTextDoc != null) { 141 closeDoc(); 142 } 143 144 // get a soffice factory object 145 SOfficeFactory SOF = SOfficeFactory.getFactory( 146 (XMultiServiceFactory) tParam.getMSF()); 147 148 try { 149 log.println("creating a text document"); 150 xTextDoc = SOF.createTextDoc(null); 151 } catch (com.sun.star.uno.Exception e) { 152 // Some exception occures.FAILED 153 e.printStackTrace(log); 154 throw new StatusException("Couldn't create document", e); 155 } 156 157 XModel aModel = (XModel) UnoRuntime.queryInterface(XModel.class, 158 xTextDoc); 159 160 XInterface oObj = null; 161 162 AccessibilityTools at = new AccessibilityTools(); 163 164 XWindow xWindow = at.getCurrentContainerWindow( 165 (XMultiServiceFactory) tParam.getMSF(), 166 aModel); 167 168 XAccessible xRoot = at.getAccessibleObject(xWindow); 169 170 171 at.printAccessibleTree(log, xRoot, tParam.getBool(util.PropertyName.DEBUG_IS_ACTIVE)); 172 oObj = at.getAccessibleObjectForRole(xRoot, 173 AccessibleRole.TOGGLE_BUTTON, 174 "Bold"); 175 176 log.println("ImplementationName: " + util.utils.getImplName(oObj)); 177 178 TestEnvironment tEnv = new TestEnvironment(oObj); 179 180 tEnv.addObjRelation("EditOnly", 181 "This method isn't supported in this dialog"); 182 183 tEnv.addObjRelation("LimitedBounds", "yes"); 184 185 final XAccessibleAction oAction = (XAccessibleAction) UnoRuntime.queryInterface( 186 XAccessibleAction.class, 187 oObj); 188 189 tEnv.addObjRelation("EventProducer", 190 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() { 191 public void fireEvent() { 192 try { 193 oAction.doAccessibleAction(0); 194 } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 195 } 196 } 197 }); 198 199 tEnv.addObjRelation("XAccessibleText.Text", "Bold"); 200 201 return tEnv; 202 } 203 204 protected void closeDoc() { 205 util.DesktopTools.closeDoc(xTextDoc); 206 } 207 } 208