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 package mod._sw;
24 
25 import java.io.PrintWriter;
26 
27 import lib.TestCase;
28 import lib.TestEnvironment;
29 import lib.TestParameters;
30 import util.AccessibilityTools;
31 import util.WriterTools;
32 import util.utils;
33 
34 import com.sun.star.accessibility.AccessibleRole;
35 import com.sun.star.accessibility.XAccessible;
36 import com.sun.star.awt.XWindow;
37 import com.sun.star.frame.XModel;
38 import com.sun.star.lang.XMultiServiceFactory;
39 import com.sun.star.text.XText;
40 import com.sun.star.text.XTextDocument;
41 import com.sun.star.uno.UnoRuntime;
42 import com.sun.star.uno.XInterface;
43 
44 /**
45 * Test of accessible object for paragraph of a text document.<p>
46 * Object implements the following interfaces :
47 * <ul>
48 *  <li> <code>::com::sun::star::accessibility::XAccessible</code></li>
49 * </ul>
50 * @see com.sun.star.accessibility.XAccessible
51 */
52 public class SwAccessibleParagraphView extends TestCase {
53 
54     XTextDocument xTextDoc = null;
55 
56     /**
57     * Called to create an instance of <code>TestEnvironment</code>
58     * with an object to test and related objects. Obtains accessible object
59     * for one of document paragraph.
60     *
61     * @param tParam test parameters
62     * @param log writer to log information while testing
63     *
64     * @see TestEnvironment
65     * @see #getTestEnvironment
66     */
67     protected TestEnvironment createTestEnvironment(
68         TestParameters Param, PrintWriter log) {
69 
70         XInterface oObj = null;
71 
72         XText oText = xTextDoc.getText();
73         oText.setString("XAccessibleText");
74 
75         XModel aModel = (XModel)
76             UnoRuntime.queryInterface(XModel.class, xTextDoc);
77 
78         AccessibilityTools at = new AccessibilityTools();
79 
80         XWindow xWindow = at.getCurrentWindow( (XMultiServiceFactory) Param.getMSF(), aModel);
81         XAccessible xRoot = at.getAccessibleObject(xWindow);
82 
83         at.getAccessibleObjectForRole(xRoot, AccessibleRole.PARAGRAPH);
84 
85         oObj = at.SearchedContext;
86 
87         log.println("ImplementationName " + utils.getImplName(oObj));
88 
89         TestEnvironment tEnv = new TestEnvironment(oObj);
90 
91         final XText paraText = xTextDoc.getText();
92 
93         tEnv.addObjRelation("EventProducer",
94             new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
95                 public void fireEvent() {
96                     String old = paraText.getString();
97                     paraText.setString("Just a line");
98                     paraText.setString(old);
99                 }
100             });
101 
102         final String text = "XAccessibleText";
103 
104         tEnv.addObjRelation("XAccessibleText.Text", text);
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("dispose text document");
119         util.DesktopTools.closeDoc(xTextDoc);
120     }
121 
122     /**
123      * Called while the <code>TestCase</code> initialization.
124      * Creates a text document.
125      *
126      * @param tParam test parameters
127      * @param log writer to log information while testing
128      *
129      * @see #initializeTestCase
130      */
131     protected void initialize(TestParameters Param, PrintWriter log) {
132         log.println( "creating a text document" );
133         xTextDoc = WriterTools.createTextDoc( (XMultiServiceFactory) Param.getMSF());
134     }
135 }
136