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