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 28 package mod._svx; 29 30 import java.io.PrintWriter; 31 32 import lib.StatusException; 33 import lib.TestCase; 34 import lib.TestEnvironment; 35 import lib.TestParameters; 36 import util.AccessibilityTools; 37 import util.SOfficeFactory; 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.XAccessibleContext; 43 import com.sun.star.accessibility.XAccessibleEditableText; 44 import com.sun.star.awt.XWindow; 45 import com.sun.star.frame.XModel; 46 import com.sun.star.lang.XComponent; 47 import com.sun.star.lang.XMultiServiceFactory; 48 import com.sun.star.uno.UnoRuntime; 49 import com.sun.star.uno.XInterface; 50 51 52 public class AccessibleEditableTextPara extends TestCase { 53 54 static XComponent xSpreadsheetDoc = null; 55 56 /** 57 * Called to create an instance of <code>TestEnvironment</code> 58 * with an object to test and related objects. 59 * Obtains accissible object for the spreadsheet document. 60 * 61 * @param tParam test parameters 62 * @param log writer to log information while testing 63 * 64 * @see TestEnvironment 65 * @see #getTestEnvironment() 66 */ 67 protected TestEnvironment createTestEnvironment( 68 TestParameters Param, PrintWriter log) { 69 70 XInterface oObj = null; 71 72 73 XModel aModel = (XModel) 74 UnoRuntime.queryInterface(XModel.class, xSpreadsheetDoc); 75 76 AccessibilityTools at = new AccessibilityTools(); 77 78 XWindow xWindow = at.getCurrentWindow( (XMultiServiceFactory) Param.getMSF(), aModel); 79 XAccessible xRoot = at.getAccessibleObject(xWindow); 80 81 at.printAccessibleTree(log, xRoot, Param.getBool(util.PropertyName.DEBUG_IS_ACTIVE)); 82 83 XAccessibleContext InputLine = at.getAccessibleObjectForRole(xRoot, AccessibleRole.TEXT_FRAME,"Input line"); 84 try { 85 oObj = InputLine.getAccessibleChild(0); 86 XAccessibleEditableText et = (XAccessibleEditableText) UnoRuntime.queryInterface(XAccessibleEditableText.class, oObj); 87 et.setText("AccessibleEditablePara"); 88 } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 89 90 } 91 log.println("ImplementationName " + utils.getImplName(oObj)); 92 93 TestEnvironment tEnv = new TestEnvironment(oObj); 94 95 final XAccessibleEditableText edText = (XAccessibleEditableText) 96 UnoRuntime.queryInterface(XAccessibleEditableText.class,oObj) ; 97 98 tEnv.addObjRelation("EventProducer", 99 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() { 100 public void fireEvent() { 101 try { 102 int l = new String("AccessibleEditablePara").length(); 103 edText.deleteText(0, l); 104 edText.setText("Event"); 105 edText.setText("AccessibleEditablePara"); 106 }catch(com.sun.star.lang.IndexOutOfBoundsException e) {} 107 } 108 }); 109 110 return tEnv; 111 112 } 113 114 /** 115 * Called while disposing a <code>TestEnvironment</code>. 116 * Disposes text document. 117 * @param tParam test parameters 118 * @param tEnv the environment to cleanup 119 * @param log writer to log information while testing 120 */ 121 protected void cleanup( TestParameters Param, PrintWriter log) { 122 log.println( " disposing xSheetDoc " ); 123 util.DesktopTools.closeDoc(xSpreadsheetDoc); 124 } 125 126 /** 127 * Called while the <code>TestCase</code> initialization. In the 128 * implementation does nothing. Subclasses can override to initialize 129 * objects shared among all <code>TestEnvironment</code>s. 130 * 131 * @param tParam test parameters 132 * @param log writer to log information while testing 133 * 134 * @see #initializeTestCase() 135 */ 136 protected void initialize(TestParameters Param, PrintWriter log) { 137 // get a soffice factory object 138 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory) Param.getMSF()); 139 140 try { 141 log.println("creating a spreadsheetdocument"); 142 xSpreadsheetDoc = (XComponent) UnoRuntime.queryInterface(XComponent.class,SOF.createCalcDoc(null)); 143 shortWait(); 144 } catch (com.sun.star.uno.Exception e) { 145 e.printStackTrace( log ); 146 throw new StatusException( "Couldn't create document ", e ); 147 } 148 } 149 150 /** 151 * Sleeps for 0.5 sec. to allow StarOffice to react on <code> 152 * reset</code> call. 153 */ 154 private void shortWait() { 155 try { 156 Thread.sleep(500) ; 157 } catch (InterruptedException e) { 158 log.println("While waiting :" + e) ; 159 } 160 } 161 162 }