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.XComponent; 36 import com.sun.star.lang.XMultiServiceFactory; 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::XAccessibleValue</code></li> 67 * <li><code> 68 * ::com::sun::star::accessibility::XAccessibleAction</code></li> 69 * </ul> <p> 70 * 71 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster 72 * @see com.sun.star.accessibility.XAccessibleContext 73 * @see com.sun.star.accessibility.XAccessibleComponent 74 * @see com.sun.star.accessibility.XAccessibleExtendedComponent 75 * @see com.sun.star.accessibility.XAccessibleValue 76 * @see com.sun.star.accessibility.XAccessibleAction 77 * @see ifc.accessibility._XAccessibleEventBroadcaster 78 * @see ifc.accessibility._XAccessibleContext 79 * @see ifc.accessibility._XAccessibleComponent 80 * @see ifc.accessibility.XAccessibleExtendedComponent 81 * @see ifc.accessibility.XAccessibleValue 82 * @see ifc.accessibility.XAccessibleAction 83 */ 84 public class AccessibleScrollBar extends TestCase { 85 private static XDesktop the_Desk; 86 private static XComponent xDoc; 87 88 /** 89 * Creates the Desktop service (<code>com.sun.star.frame.Desktop</code>). 90 */ 91 protected void initialize(TestParameters Param, PrintWriter log) { 92 the_Desk = (XDesktop) UnoRuntime.queryInterface(XDesktop.class, 93 DesktopTools.createDesktop( 94 (XMultiServiceFactory) Param.getMSF())); 95 } 96 97 /** 98 * Disposes the document, if exists, created in 99 * <code>createTestEnvironment</code> method. 100 */ 101 protected void cleanup(TestParameters Param, PrintWriter log) { 102 log.println("disposing xTextDoc"); 103 104 if (xDoc != null) { 105 closeDoc(); 106 } 107 } 108 109 /** 110 * Creates a text document. 111 * Then obtains an accessible object with 112 * the role <code>AccessibleRole.SCROLLBAR</code>. 113 * Object relations created : 114 * <ul> 115 * <li> <code>'EventProducer'</code> for 116 * {@link ifc.accessibility._XAccessibleEventBroadcaster}: 117 * grabs focus </li> 118 * </ul> 119 * 120 * @param tParam test parameters 121 * @param log writer to log information while testing 122 * 123 * @see com.sun.star.awt.Toolkit 124 * @see com.sun.star.accessibility.AccessibleRole 125 * @see ifc.accessibility._XAccessibleEventBroadcaster 126 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster 127 */ 128 protected TestEnvironment createTestEnvironment(TestParameters tParam, 129 PrintWriter log) { 130 log.println("creating a test environment"); 131 132 if (xDoc != null) { 133 closeDoc(); 134 } 135 136 // get a soffice factory object 137 SOfficeFactory SOF = SOfficeFactory.getFactory( 138 (XMultiServiceFactory) tParam.getMSF()); 139 140 try { 141 log.println("creating a text document"); 142 xDoc = SOF.createDrawDoc(null); 143 } catch (com.sun.star.uno.Exception e) { 144 // Some exception occures.FAILED 145 e.printStackTrace(log); 146 throw new StatusException("Couldn't create document", e); 147 } 148 149 XModel aModel = (XModel) UnoRuntime.queryInterface(XModel.class, xDoc); 150 151 XInterface oObj = null; 152 153 AccessibilityTools at = new AccessibilityTools(); 154 155 XWindow xWindow = at.getCurrentWindow( 156 (XMultiServiceFactory) tParam.getMSF(), 157 aModel); 158 159 XAccessible xRoot = at.getAccessibleObject(xWindow); 160 161 oObj = at.getAccessibleObjectForRole(xRoot, AccessibleRole.SCROLL_BAR); 162 163 final XAccessibleAction act = (XAccessibleAction) UnoRuntime.queryInterface( 164 XAccessibleAction.class, oObj); 165 166 log.println("ImplementationName: " + util.utils.getImplName(oObj)); 167 168 TestEnvironment tEnv = new TestEnvironment(oObj); 169 170 tEnv.addObjRelation("EventProducer", 171 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() { 172 public void fireEvent() { 173 try { 174 act.doAccessibleAction(1); 175 } catch (Exception e) { 176 } 177 } 178 }); 179 180 return tEnv; 181 } 182 183 protected void closeDoc() { 184 util.DesktopTools.closeDoc(xDoc); 185 } 186 } 187