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._svtools; 24 25 import com.sun.star.drawing.XLayerManager; 26 import com.sun.star.drawing.XLayerSupplier; 27 import java.io.PrintWriter; 28 29 import lib.StatusException; 30 import lib.TestCase; 31 import lib.TestEnvironment; 32 import lib.TestParameters; 33 import util.AccessibilityTools; 34 import util.SOfficeFactory; 35 36 import com.sun.star.accessibility.AccessibleRole; 37 import com.sun.star.accessibility.XAccessible; 38 import com.sun.star.awt.XExtendedToolkit; 39 import com.sun.star.awt.XWindow; 40 import com.sun.star.lang.XComponent; 41 import com.sun.star.lang.XMultiServiceFactory; 42 import com.sun.star.uno.UnoRuntime; 43 import com.sun.star.uno.XInterface; 44 import com.sun.star.util.XCloseable; 45 46 47 /** 48 * Test for object that implements the following interfaces : 49 * <ul> 50 * <li><code>::com::sun::star::accessibility::XAccessibleComponent 51 * </code></li> 52 * <li><code>::com::sun::star::accessibility::XAccessibleContext 53 * </code></li> 54 * <li><code>::com::sun::star::accessibility::XAccessibleEventBroadcaster 55 * </code></li> 56 * <li> 57 * <code>::com::sun::star::accessibility::XAccessibleExtendedComponent 58 * </code></li> 59 * <li><code>::com::sun::star::accessibility::XAccessibleSelection 60 * </code></li> 61 * </ul> <p> 62 * 63 * @see com.sun.star.accessibility.XAccessibleSelection 64 * @see com.sun.star.accessibility.XAccessibleExtendedComponent 65 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster 66 * @see com.sun.star.accessibility.XAccessibleContext 67 * @see com.sun.star.accessibility.XAccessibleComponent 68 * @see ifc.accessibility._XAccessibleSelection 69 * @see ifc.accessibility._XAccessibleComponent 70 * @see ifc.accessibility._XAccessibleExtendedComponent 71 * @see ifc.accessibility._XAccessibleEventBroadcaster 72 * @see ifc.accessibility._XAccessibleContext 73 */ 74 public class AccessibleTabBarPageList extends TestCase { 75 static XComponent xDoc; 76 77 /** 78 * Disposes the document, if exists, created in 79 * <code>createTestEnvironment</code> method. 80 */ cleanup(TestParameters Param, PrintWriter log)81 protected void cleanup(TestParameters Param, PrintWriter log) { 82 log.println("disposing xDoc"); 83 84 if (xDoc != null) { 85 closeDoc(); 86 } 87 } 88 89 /** 90 * Creates a spreadsheet document. Then obtains an accessible object with 91 * the role <code>AccessibleRole.PAGETABLIST</code>. 92 * Object relations created : 93 * <ul> 94 * <li> <code>'EventProducer'</code> for 95 * {@link ifc.accessibility._XAccessibleEventBroadcaster}: 96 * </li> 97 * </ul> 98 * 99 * @param tParam test parameters 100 * @param log writer to log information while testing 101 * 102 * @see com.sun.star.awt.Toolkit 103 * @see com.sun.star.accessibility.AccessibleRole 104 * @see ifc.accessibility._XAccessibleEventBroadcaster 105 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster 106 */ createTestEnvironment(TestParameters tParam, PrintWriter log)107 protected TestEnvironment createTestEnvironment(TestParameters tParam, 108 PrintWriter log) { 109 log.println("creating a test environment"); 110 111 if (xDoc != null) { 112 closeDoc(); 113 } 114 115 // get a soffice factory object 116 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory) tParam.getMSF()); 117 118 try { 119 log.println("creating a draw document"); 120 xDoc = SOF.createDrawDoc(null); 121 } catch (com.sun.star.uno.Exception e) { 122 // Some exception occures.FAILED 123 e.printStackTrace(log); 124 throw new StatusException("Couldn't create document", e); 125 } 126 127 shortWait(); 128 129 XInterface oObj = null; 130 131 try { 132 oObj = (XInterface) ( (XMultiServiceFactory) tParam.getMSF()) 133 .createInstance("com.sun.star.awt.Toolkit"); 134 } catch (com.sun.star.uno.Exception e) { 135 log.println("Couldn't get toolkit"); 136 e.printStackTrace(log); 137 throw new StatusException("Couldn't get toolkit", e); 138 } 139 140 XExtendedToolkit tk = (XExtendedToolkit) UnoRuntime.queryInterface( 141 XExtendedToolkit.class, oObj); 142 143 AccessibilityTools at = new AccessibilityTools(); 144 145 shortWait(); 146 147 XWindow xWindow = (XWindow) UnoRuntime.queryInterface(XWindow.class, 148 tk.getActiveTopWindow()); 149 150 XAccessible xRoot = at.getAccessibleObject(xWindow); 151 152 oObj = at.getAccessibleObjectForRole(xRoot, 153 AccessibleRole.PAGE_TAB_LIST); 154 155 log.println("ImplementationName: " + util.utils.getImplName(oObj)); 156 157 TestEnvironment tEnv = new TestEnvironment(oObj); 158 159 tEnv.addObjRelation("XAccessibleSelection.multiSelection", 160 new Boolean(false)); 161 162 tEnv.addObjRelation("XAccessibleSelection.OneAlwaysSelected", 163 new Boolean(true)); 164 165 XLayerSupplier oLS = (XLayerSupplier) 166 UnoRuntime.queryInterface(XLayerSupplier.class, xDoc); 167 XInterface oLM = oLS.getLayerManager(); 168 final XLayerManager xLM = (XLayerManager) UnoRuntime.queryInterface(XLayerManager.class, oLM); 169 170 171 tEnv.addObjRelation("EventProducer", 172 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() { 173 public void fireEvent() { 174 xLM.insertNewByIndex(0); 175 } 176 }); 177 178 return tEnv; 179 } 180 181 /** 182 * Sleeps for 0.5 sec. to allow StarOffice to react on <code> 183 * reset</code> call. 184 */ shortWait()185 private void shortWait() { 186 try { 187 Thread.sleep(5000); 188 } catch (InterruptedException e) { 189 System.out.println("While waiting :" + e); 190 } 191 } 192 closeDoc()193 protected void closeDoc() { 194 XCloseable closer = (XCloseable) UnoRuntime.queryInterface( 195 XCloseable.class, xDoc); 196 197 try { 198 closer.close(true); 199 } catch (com.sun.star.util.CloseVetoException e) { 200 log.println("Couldn't close document " + e.getMessage()); 201 } catch (com.sun.star.lang.DisposedException e) { 202 log.println("Couldn't close document " + e.getMessage()); 203 } 204 } 205 }