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