merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / mod / _sm / SmGraphicAccessible.java
blobede29e298c47799532b52f973c86ee857315673e
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: SmGraphicAccessible.java,v $
10 * $Revision: 1.11 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 package mod._sm;
33 import java.io.PrintWriter;
35 import lib.StatusException;
36 import lib.TestCase;
37 import lib.TestEnvironment;
38 import lib.TestParameters;
39 import util.AccessibilityTools;
40 import util.SOfficeFactory;
41 import util.utils;
43 import com.sun.star.accessibility.AccessibleRole;
44 import com.sun.star.accessibility.XAccessible;
45 import com.sun.star.accessibility.XAccessibleComponent;
46 import com.sun.star.awt.XWindow;
47 import com.sun.star.beans.XPropertySet;
48 import com.sun.star.frame.XModel;
49 import com.sun.star.lang.XComponent;
50 import com.sun.star.lang.XMultiServiceFactory;
51 import com.sun.star.uno.UnoRuntime;
52 import com.sun.star.uno.XInterface;
56 /**
57 * Object implements the following interfaces :
58 * <ul>
59 * <li> <code>::com::sun::star::accessibility::XAccessible</code></li>
60 * <li> <code>::com::sun::star::accessibility::XAccessibleComponent</code></li>
61 * <li> <code>::com::sun::star::accessibility::XAccessibleContext</code></li>
62 * <li> <code>::com::sun::star::accessibility::XAccessibleEventBroadcaster</code></li>
63 * <li> <code>::com::sun::star::accessibility::XAccessibleText</code></li>
64 * </ul> <p>
66 * @see com.sun.star.accessibility.XAccessible
67 * @see com.sun.star.accessibility.XAccessibleComponent
68 * @see com.sun.star.accessibility.XAccessibleContext
69 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
70 * @see com.sun.star.accessibility.XAccessibleText
71 * @see ifc.accessibility._XAccessible
72 * @see ifc.accessibility._XAccessibleComponent
73 * @see ifc.accessibility._XAccessibleContext
74 * @see ifc.accessibility._XAccessibleEventBroadcaster
75 * @see ifc.accessibility._XAccessibleText
77 public class SmGraphicAccessible extends TestCase {
78 XComponent xMathDoc;
80 /**
81 * Creates a <code>StarMath</code> document and obtains an accessibility
82 * component with the role <code>AccessibleRole.PANEL</code>.
84 protected synchronized TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) {
86 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory) Param.getMSF() );
87 try {
88 xMathDoc = SOF.openDoc("smath","_blank");
89 } catch (com.sun.star.lang.IllegalArgumentException ex) {
90 ex.printStackTrace( log );
91 throw new StatusException( "Couldn't create document", ex );
92 } catch (com.sun.star.io.IOException ex) {
93 ex.printStackTrace( log );
94 throw new StatusException( "Couldn't create document", ex );
95 } catch (com.sun.star.uno.Exception ex) {
96 ex.printStackTrace( log );
97 throw new StatusException( "Couldn't create document", ex );
100 // setting a formula in document
101 final String expFormula = "sum a cdot b";
102 final XPropertySet xPS = (XPropertySet) UnoRuntime.queryInterface
103 (XPropertySet.class, xMathDoc);
104 try {
105 xPS.setPropertyValue("Formula", expFormula);
106 } catch(com.sun.star.lang.WrappedTargetException e) {
107 log.println("Couldn't set property value");
108 e.printStackTrace(log);
109 } catch(com.sun.star.lang.IllegalArgumentException e) {
110 log.println("Couldn't set property value");
111 e.printStackTrace(log);
112 } catch(com.sun.star.beans.PropertyVetoException e) {
113 log.println("Couldn't set property value");
114 e.printStackTrace(log);
115 } catch(com.sun.star.beans.UnknownPropertyException e) {
116 log.println("Couldn't set property value");
117 e.printStackTrace(log);
120 XInterface oObj = null;
122 XModel aModel = (XModel)
123 UnoRuntime.queryInterface(XModel.class, xMathDoc);
126 AccessibilityTools at = new AccessibilityTools();
128 XWindow xWindow = at.getCurrentWindow( (XMultiServiceFactory) Param.getMSF(), aModel);
129 XAccessible xRoot = at.getAccessibleObject(xWindow);
131 oObj = at.getAccessibleObjectForRole
132 (xRoot, AccessibleRole.DOCUMENT, "Formula");
134 log.println("ImplementationName " + utils.getImplName(oObj));
136 final XAccessibleComponent xAC = (XAccessibleComponent)
137 UnoRuntime.queryInterface(XAccessibleComponent.class, oObj);
139 TestEnvironment tEnv = new TestEnvironment(oObj);
141 tEnv.addObjRelation("EditOnly",
142 "This method isn't supported in this dialog");
145 tEnv.addObjRelation("EventProducer",
146 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer(){
147 public void fireEvent() {
148 try {
149 xAC.grabFocus();
150 xPS.setPropertyValue("Formula", "sum hat x");
151 shortWait();
152 xPS.setPropertyValue("Formula", expFormula);
153 shortWait();
154 } catch(com.sun.star.lang.WrappedTargetException e) {
155 } catch(com.sun.star.lang.IllegalArgumentException e) {
156 } catch(com.sun.star.beans.PropertyVetoException e) {
157 } catch(com.sun.star.beans.UnknownPropertyException e) {
159 }});
161 return tEnv;
165 * Disposes the document created in <code>createTestEnvironment</code>
166 * method.
168 protected void cleanup( TestParameters Param, PrintWriter log) {
170 log.println( " disposing xMathDoc " );
171 xMathDoc.dispose();
175 * Sleeps for 0.5 sec. to allow StarOffice to react on <code>
176 * reset</code> call.
178 private void shortWait() {
179 try {
180 Thread.sleep(1000) ;
181 } catch (InterruptedException e) {
182 log.println("While waiting :" + e) ;
185 } // finish class SmModel