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