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.StatusException;
28 import lib.TestCase;
29 import lib.TestEnvironment;
30 import lib.TestParameters;
31 import util.AccessibilityTools;
32 import util.SOfficeFactory;
33 import util.WriterTools;
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.XAccessibleSelection;
39 import com.sun.star.awt.XWindow;
40 import com.sun.star.frame.XModel;
41 import com.sun.star.lang.XMultiServiceFactory;
42 import com.sun.star.text.XTextDocument;
43 import com.sun.star.text.XTextTable;
44 import com.sun.star.uno.UnoRuntime;
45 import com.sun.star.uno.XInterface;
46 
47 
48 /**
49 * Test of accessible object for the table cell of a text document.<p>
50 * Object implements the following interfaces :
51 * <ul>
52 *  <li> <code>::com::sun::star::accessibility::XAccessible</code></li>
53 * </ul>
54 * @see com.sun.star.accessibility.XAccessible
55 */
56 public class SwAccessibleTableCellView extends TestCase {
57     XTextDocument xTextDoc = null;
58 
59     /**
60     * Called to create an instance of <code>TestEnvironment</code>
61     * with an object to test and related objects.
62     * Creates a text table and inserts it to document. Then obtains accessible
63     * object for one of table cell.
64     *
65     * @param Param test parameters
66     * @param log writer to log information while testing
67     *
68     * @see TestEnvironment
69     * @see #getTestEnvironment
70     */
createTestEnvironment(TestParameters Param, PrintWriter log)71     protected TestEnvironment createTestEnvironment(TestParameters Param,
72                                                     PrintWriter log) {
73         XInterface oObj = null;
74         XTextTable oTable = null;
75 
76         SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory) Param.getMSF());
77 
78         try {
79             oTable = SOF.createTextTable(xTextDoc);
80         } catch (com.sun.star.uno.Exception e) {
81             e.printStackTrace(log);
82             throw new StatusException("Couldn't create TextTable : " +
83                                       e.getMessage(), e);
84         }
85 
86         try {
87             SOF.insertTextContent(xTextDoc, oTable);
88         } catch (com.sun.star.lang.IllegalArgumentException e) {
89             e.printStackTrace(log);
90             throw new StatusException("Couldn't insert text content :" +
91                                       e.getMessage(), e);
92         }
93 
94         XModel aModel = (XModel) UnoRuntime.queryInterface(XModel.class,
95                                                            xTextDoc);
96 
97         AccessibilityTools at = new AccessibilityTools();
98 
99         XWindow xWindow = at.getCurrentWindow( (XMultiServiceFactory) Param.getMSF(), aModel);
100         XAccessible xRoot = at.getAccessibleObject(xWindow);
101 
102         at.getAccessibleObjectForRole(xRoot, AccessibleRole.TABLE_CELL);
103 
104         oObj = at.SearchedContext;
105 
106         log.println("ImplementationName " + utils.getImplName(oObj));
107 
108         at.printAccessibleTree(log, xRoot, Param.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
109         TestEnvironment tEnv = new TestEnvironment(oObj);
110 
111         final XAccessibleSelection accSel = (XAccessibleSelection) UnoRuntime.queryInterface(
112                                                     XAccessibleSelection.class,
113                                                     at.SearchedContext.getAccessibleParent());
114 
115         tEnv.addObjRelation("EventProducer",
116                             new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
117             public void fireEvent() {
118                 accSel.selectAllAccessibleChildren();
119             }
120         });
121 
122         return tEnv;
123     }
124 
125     /**
126     * Called while disposing a <code>TestEnvironment</code>.
127     * Disposes text document.
128     * @param Param test parameters
129     * @param log writer to log information while testing
130     */
cleanup(TestParameters Param, PrintWriter log)131     protected void cleanup(TestParameters Param, PrintWriter log) {
132         log.println("dispose text document");
133         util.DesktopTools.closeDoc(xTextDoc);
134     }
135 
136     /**
137      * Called while the <code>TestCase</code> initialization.
138      * Creates a text document.
139      *
140      * @param Param test parameters
141      * @param log writer to log information while testing
142      *
143      * @see #initializeTestCase
144      */
initialize(TestParameters Param, PrintWriter log)145     protected void initialize(TestParameters Param, PrintWriter log) {
146         log.println("creating a text document");
147         xTextDoc = WriterTools.createTextDoc( (XMultiServiceFactory) Param.getMSF());
148     }
149 }
150