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