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