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 tParam test parameters
58     * @param log writer to log information while testing
59     *
60     * @see TestEnvironment
61     * @see #getTestEnvironment
62     */
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 tParam test parameters
114     * @param tEnv the environment to cleanup
115     * @param log writer to log information while testing
116     */
117     protected void cleanup( TestParameters Param, PrintWriter log) {
118         log.println( "    disposing xSheetDoc " );
119         util.DesktopTools.closeDoc(xSpreadsheetDoc);
120     }
121 
122     /**
123      * Called while the <code>TestCase</code> initialization. In the
124      * implementation does nothing. Subclasses can override to initialize
125      * objects shared among all <code>TestEnvironment</code>s.
126      *
127      * @param tParam test parameters
128      * @param log writer to log information while testing
129      *
130      * @see #initializeTestCase
131      */
132     protected void initialize(TestParameters Param, PrintWriter log) {
133         // get a soffice factory object
134         SOfficeFactory SOF = SOfficeFactory.getFactory(  (XMultiServiceFactory) Param.getMSF());
135 
136         try {
137             log.println("creating a spreadsheetdocument");
138             xSpreadsheetDoc = (XComponent) UnoRuntime.queryInterface(XComponent.class,SOF.createCalcDoc(null));
139             shortWait();
140         } catch (com.sun.star.uno.Exception e) {
141             e.printStackTrace( log );
142             throw new StatusException( "Couldn't create document ", e );
143         }
144     }
145 
146     /**
147     * Sleeps for 0.5 sec. to allow StarOffice to react on <code>
148     * reset</code> call.
149     */
150     private void shortWait() {
151         try {
152             Thread.sleep(500) ;
153         } catch (InterruptedException e) {
154             log.println("While waiting :" + e) ;
155         }
156     }
157 
158 }
159