xref: /AOO41X/main/qadevOOo/tests/java/mod/_sw/SwAccessibleTextEmbeddedObject.java (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 package mod._sw;
28 
29 import java.io.PrintWriter;
30 
31 import lib.TestCase;
32 import lib.TestEnvironment;
33 import lib.TestParameters;
34 import util.AccessibilityTools;
35 import util.WriterTools;
36 import util.utils;
37 
38 import com.sun.star.accessibility.AccessibleRole;
39 import com.sun.star.accessibility.XAccessible;
40 import com.sun.star.awt.XWindow;
41 import com.sun.star.beans.XPropertySet;
42 import com.sun.star.frame.XController;
43 import com.sun.star.frame.XModel;
44 import com.sun.star.lang.XMultiServiceFactory;
45 import com.sun.star.text.XTextDocument;
46 import com.sun.star.uno.UnoRuntime;
47 import com.sun.star.uno.XInterface;
48 import com.sun.star.view.XViewSettingsSupplier;
49 
50 /**
51 * Test of accessible object for the text embedded object of a text document.<p>
52 * Object implements the following interfaces :
53 * <ul>
54 *  <li> <code>::com::sun::star::accessibility::XAccessible</code></li>
55 * </ul>
56 * @see com.sun.star.accessibility.XAccessible
57 */
58 public class SwAccessibleTextEmbeddedObject extends TestCase {
59 
60     XTextDocument xTextDoc = null;
61 
62     /**
63     * Called to create an instance of <code>TestEnvironment</code>
64     * with an object to test and related objects.
65     * Obtains accessible object for the embedded object.
66     *
67     * @param tParam test parameters
68     * @param log writer to log information while testing
69     *
70     * @see TestEnvironment
71     * @see #getTestEnvironment()
72     */
73     protected TestEnvironment createTestEnvironment(
74         TestParameters Param, PrintWriter log) {
75 
76         XInterface oObj = null;
77 
78         XModel aModel = (XModel)
79             UnoRuntime.queryInterface(XModel.class, xTextDoc);
80 
81         AccessibilityTools at = new AccessibilityTools();
82 
83         XWindow xWindow = at.getCurrentWindow((XMultiServiceFactory)Param.getMSF(), aModel);
84         XAccessible xRoot = at.getAccessibleObject(xWindow);
85 
86         at.getAccessibleObjectForRole(xRoot, AccessibleRole.EMBEDDED_OBJECT);
87 
88         oObj = at.SearchedContext;
89 
90         log.println("ImplementationName " + utils.getImplName(oObj));
91         at.printAccessibleTree(log, xRoot, Param.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
92 
93         TestEnvironment tEnv = new TestEnvironment(oObj);
94 
95         XController xController = xTextDoc.getCurrentController();
96         XViewSettingsSupplier xViewSetSup = (XViewSettingsSupplier)
97                 UnoRuntime.queryInterface(XViewSettingsSupplier.class,
98                 xController);
99 
100         final XPropertySet PropSet = xViewSetSup.getViewSettings();
101 
102         tEnv.addObjRelation("EventProducer",
103             new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
104                 public void fireEvent() {
105                     try {
106                         //change zoom value to 15%
107                         PropSet.setPropertyValue("ZoomValue", new Short("15"));
108                         //and back to 100%
109                         PropSet.setPropertyValue("ZoomValue", new Short("100"));
110                     } catch ( com.sun.star.lang.WrappedTargetException e ) {
111 
112                     }  catch ( com.sun.star.lang.IllegalArgumentException e ) {
113 
114                     } catch ( com.sun.star.beans.PropertyVetoException e ) {
115 
116                     } catch ( com.sun.star.beans.UnknownPropertyException e ) {
117 
118                     }
119                 }
120             });
121 
122 
123         return tEnv;
124 
125     }
126 
127     /**
128     * Called while disposing a <code>TestEnvironment</code>.
129     * Disposes text document.
130     * @param tParam test parameters
131     * @param tEnv the environment to cleanup
132     * @param log writer to log information while testing
133     */
134     protected void cleanup( TestParameters Param, PrintWriter log) {
135         log.println("dispose text document");
136         util.DesktopTools.closeDoc(xTextDoc);
137     }
138 
139     /**
140      * Called while the <code>TestCase</code> initialization.
141      * Loads the text document <code>SwXTextEmbeddedObject.sxw</code>
142      * with a text embedded object.
143      *
144      * @param tParam test parameters
145      * @param log writer to log information while testing
146      *
147      * @see #initializeTestCase()
148      */
149     protected void initialize(TestParameters Param, PrintWriter log) {
150         log.println( "open a text document" );
151         String testdoc = utils.getFullTestURL("SwXTextEmbeddedObject.sxw");
152         log.println(testdoc);
153         xTextDoc = WriterTools.loadTextDoc((XMultiServiceFactory)Param.getMSF(),testdoc);
154     }
155 }
156 
157