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