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 24 package mod._sm; 25 26 import java.io.PrintWriter; 27 28 import lib.StatusException; 29 import lib.TestCase; 30 import lib.TestEnvironment; 31 import lib.TestParameters; 32 import util.AccessibilityTools; 33 import util.SOfficeFactory; 34 import util.utils; 35 36 import com.sun.star.accessibility.AccessibleRole; 37 import com.sun.star.accessibility.XAccessible; 38 import com.sun.star.accessibility.XAccessibleContext; 39 import com.sun.star.awt.XWindow; 40 import com.sun.star.beans.XPropertySet; 41 import com.sun.star.frame.XModel; 42 import com.sun.star.lang.XComponent; 43 import com.sun.star.lang.XMultiServiceFactory; 44 import com.sun.star.uno.UnoRuntime; 45 import com.sun.star.uno.XInterface; 46 47 /** 48 * Object implements the following interfaces : 49 * <ul> 50 * <li> <code>::com::sun::star::accessibility::XAccessible</code></li> 51 * <li> <code>::com::sun::star::accessibility::XAccessibleComponent</code></li> 52 * <li> <code>::com::sun::star::accessibility::XAccessibleContext</code></li> 53 * <li> <code>::com::sun::star::accessibility::XAccessibleEventBroadcaster</code></li> 54 * <li> <code>::com::sun::star::accessibility::XAccessibleText</code></li> 55 * </ul> <p> 56 * 57 * @see com.sun.star.accessibility.XAccessible 58 * @see com.sun.star.accessibility.XAccessibleComponent 59 * @see com.sun.star.accessibility.XAccessibleContext 60 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster 61 * @see com.sun.star.accessibility.XAccessibleText 62 * @see ifc.accessibility._XAccessible 63 * @see ifc.accessibility._XAccessibleComponent 64 * @see ifc.accessibility._XAccessibleContext 65 * @see ifc.accessibility._XAccessibleEventBroadcaster 66 * @see ifc.accessibility._XAccessibleText 67 */ 68 public class SmEditAccessible extends TestCase { 69 XComponent xMathDoc; 70 71 /** 72 * Creates a <code>StarMath</code> document and obtains an accessibility 73 * component with the role <code>AccessibleRole.PANEL</code>. 74 */ createTestEnvironment(TestParameters Param, PrintWriter log)75 protected synchronized TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) { 76 77 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)Param.getMSF() ); 78 try { 79 xMathDoc = SOF.openDoc("smath","_blank"); 80 } catch (com.sun.star.lang.IllegalArgumentException ex) { 81 ex.printStackTrace( log ); 82 throw new StatusException( "Couldn't create document", ex ); 83 } catch (com.sun.star.io.IOException ex) { 84 ex.printStackTrace( log ); 85 throw new StatusException( "Couldn't create document", ex ); 86 } catch (com.sun.star.uno.Exception ex) { 87 ex.printStackTrace( log ); 88 throw new StatusException( "Couldn't create document", ex ); 89 } 90 91 // setting a formula in document 92 final String expFormula = "sum hat a"; 93 final XPropertySet xPS = (XPropertySet) UnoRuntime.queryInterface 94 (XPropertySet.class, xMathDoc); 95 try { 96 xPS.setPropertyValue("Formula", expFormula); 97 } catch(com.sun.star.lang.WrappedTargetException e) { 98 log.println("Couldn't set property value"); 99 e.printStackTrace(log); 100 } catch(com.sun.star.lang.IllegalArgumentException e) { 101 log.println("Couldn't set property value"); 102 e.printStackTrace(log); 103 } catch(com.sun.star.beans.PropertyVetoException e) { 104 log.println("Couldn't set property value"); 105 e.printStackTrace(log); 106 } catch(com.sun.star.beans.UnknownPropertyException e) { 107 log.println("Couldn't set property value"); 108 e.printStackTrace(log); 109 } 110 111 XInterface oObj = null; 112 113 XModel aModel = (XModel) 114 UnoRuntime.queryInterface(XModel.class, xMathDoc); 115 116 117 AccessibilityTools at = new AccessibilityTools(); 118 119 XWindow xWindow = at.getCurrentWindow((XMultiServiceFactory)Param.getMSF(), aModel); 120 XAccessible xRoot = at.getAccessibleObject(xWindow); 121 122 oObj = at.getAccessibleObjectForRole 123 (xRoot, AccessibleRole.PANEL, "", "SmEditAccessible"); 124 125 log.println("ImplementationName " + utils.getImplName(oObj)); 126 at.printAccessibleTree(log, xRoot, Param.getBool(util.PropertyName.DEBUG_IS_ACTIVE)); 127 TestEnvironment tEnv = new TestEnvironment(oObj); 128 129 tEnv.addObjRelation("Destroy", new Boolean(true)); 130 131 final XAccessibleContext con = (XAccessibleContext) UnoRuntime.queryInterface(XAccessibleContext.class, oObj); 132 tEnv.addObjRelation("EventProducer", 133 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer(){ 134 public void fireEvent() { 135 try { 136 System.out.println("Childs "+con.getAccessibleChildCount()); 137 xPS.setPropertyValue("Formula", "sum hat x \n int a \n sum b"); 138 shortWait(); 139 System.out.println("Childs "+con.getAccessibleChildCount()); 140 xPS.setPropertyValue("Formula", expFormula); 141 shortWait(); 142 } catch(com.sun.star.lang.WrappedTargetException e) { 143 } catch(com.sun.star.lang.IllegalArgumentException e) { 144 } catch(com.sun.star.beans.PropertyVetoException e) { 145 } catch(com.sun.star.beans.UnknownPropertyException e) { 146 } 147 } 148 }); 149 150 return tEnv; 151 } 152 153 /** 154 * Disposes the document created in <code>createTestEnvironment</code> 155 * method. 156 */ cleanup( TestParameters Param, PrintWriter log)157 protected void cleanup( TestParameters Param, PrintWriter log) { 158 159 log.println( " disposing xMathDoc " ); 160 xMathDoc.dispose(); 161 } 162 163 /** 164 * Sleeps for 0.5 sec. to allow StarOffice to react on <code> 165 * reset</code> call. 166 */ shortWait()167 private void shortWait() { 168 try { 169 Thread.sleep(1000) ; 170 } catch (InterruptedException e) { 171 log.println("While waiting :" + e) ; 172 } 173 } 174 } // finish class SmModel 175