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._sw; 28 29 import java.io.PrintWriter; 30 31 import lib.StatusException; 32 import lib.TestCase; 33 import lib.TestEnvironment; 34 import lib.TestParameters; 35 import util.AccessibilityTools; 36 import util.SOfficeFactory; 37 import util.WriterTools; 38 import util.utils; 39 40 import com.sun.star.accessibility.AccessibleRole; 41 import com.sun.star.accessibility.XAccessible; 42 import com.sun.star.accessibility.XAccessibleSelection; 43 import com.sun.star.awt.XWindow; 44 import com.sun.star.frame.XModel; 45 import com.sun.star.lang.XMultiServiceFactory; 46 import com.sun.star.text.XTextDocument; 47 import com.sun.star.text.XTextTable; 48 import com.sun.star.uno.UnoRuntime; 49 import com.sun.star.uno.XInterface; 50 51 52 /** 53 * Test of accessible object for the table cell of a text document.<p> 54 * Object implements the following interfaces : 55 * <ul> 56 * <li> <code>::com::sun::star::accessibility::XAccessible</code></li> 57 * </ul> 58 * @see com.sun.star.accessibility.XAccessible 59 */ 60 public class SwAccessibleTableCellView extends TestCase { 61 XTextDocument xTextDoc = null; 62 63 /** 64 * Called to create an instance of <code>TestEnvironment</code> 65 * with an object to test and related objects. 66 * Creates a text table and inserts it to document. Then obtains accessible 67 * object for one of table cell. 68 * 69 * @param tParam test parameters 70 * @param log writer to log information while testing 71 * 72 * @see TestEnvironment 73 * @see #getTestEnvironment() 74 */ 75 protected TestEnvironment createTestEnvironment(TestParameters Param, 76 PrintWriter log) { 77 XInterface oObj = null; 78 XTextTable oTable = null; 79 80 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory) Param.getMSF()); 81 82 try { 83 oTable = SOF.createTextTable(xTextDoc); 84 } catch (com.sun.star.uno.Exception e) { 85 e.printStackTrace(log); 86 throw new StatusException("Couldn't create TextTable : " + 87 e.getMessage(), e); 88 } 89 90 try { 91 SOF.insertTextContent(xTextDoc, oTable); 92 } catch (com.sun.star.lang.IllegalArgumentException e) { 93 e.printStackTrace(log); 94 throw new StatusException("Couldn't insert text content :" + 95 e.getMessage(), e); 96 } 97 98 XModel aModel = (XModel) UnoRuntime.queryInterface(XModel.class, 99 xTextDoc); 100 101 AccessibilityTools at = new AccessibilityTools(); 102 103 XWindow xWindow = at.getCurrentWindow( (XMultiServiceFactory) Param.getMSF(), aModel); 104 XAccessible xRoot = at.getAccessibleObject(xWindow); 105 106 at.getAccessibleObjectForRole(xRoot, AccessibleRole.TABLE_CELL); 107 108 oObj = at.SearchedContext; 109 110 log.println("ImplementationName " + utils.getImplName(oObj)); 111 112 at.printAccessibleTree(log, xRoot, Param.getBool(util.PropertyName.DEBUG_IS_ACTIVE)); 113 TestEnvironment tEnv = new TestEnvironment(oObj); 114 115 final XAccessibleSelection accSel = (XAccessibleSelection) UnoRuntime.queryInterface( 116 XAccessibleSelection.class, 117 at.SearchedContext.getAccessibleParent()); 118 119 tEnv.addObjRelation("EventProducer", 120 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() { 121 public void fireEvent() { 122 accSel.selectAllAccessibleChildren(); 123 } 124 }); 125 126 return tEnv; 127 } 128 129 /** 130 * Called while disposing a <code>TestEnvironment</code>. 131 * Disposes text document. 132 * @param tParam test parameters 133 * @param tEnv the environment to cleanup 134 * @param log writer to log information while testing 135 */ 136 protected void cleanup(TestParameters Param, PrintWriter log) { 137 log.println("dispose text document"); 138 util.DesktopTools.closeDoc(xTextDoc); 139 } 140 141 /** 142 * Called while the <code>TestCase</code> initialization. 143 * Creates a text document. 144 * 145 * @param tParam test parameters 146 * @param log writer to log information while testing 147 * 148 * @see #initializeTestCase() 149 */ 150 protected void initialize(TestParameters Param, PrintWriter log) { 151 log.println("creating a text document"); 152 xTextDoc = WriterTools.createTextDoc( (XMultiServiceFactory) Param.getMSF()); 153 } 154 }