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