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