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