merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / mod / _sw / SwAccessibleTextGraphicObject.java
blob669612af7272a16d3a4a6414dd189783fe851e5f
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: SwAccessibleTextGraphicObject.java,v $
10 * $Revision: 1.9 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 package mod._sw;
32 import java.io.PrintWriter;
34 import lib.StatusException;
35 import lib.TestCase;
36 import lib.TestEnvironment;
37 import lib.TestParameters;
38 import util.AccessibilityTools;
39 import util.SOfficeFactory;
40 import util.WriterTools;
41 import util.utils;
43 import com.sun.star.accessibility.AccessibleRole;
44 import com.sun.star.accessibility.XAccessible;
45 import com.sun.star.awt.XWindow;
46 import com.sun.star.beans.XPropertySet;
47 import com.sun.star.frame.XController;
48 import com.sun.star.frame.XModel;
49 import com.sun.star.lang.XMultiServiceFactory;
50 import com.sun.star.text.XText;
51 import com.sun.star.text.XTextContent;
52 import com.sun.star.text.XTextCursor;
53 import com.sun.star.text.XTextDocument;
54 import com.sun.star.uno.UnoRuntime;
55 import com.sun.star.uno.XInterface;
56 import com.sun.star.view.XViewSettingsSupplier;
58 /**
59 * Test of accessible object for the graphic object of a text document.<p>
60 * Object implements the following interfaces :
61 * <ul>
62 * <li> <code>::com::sun::star::accessibility::XAccessible</code></li>
63 * </ul>
64 * @see com.sun.star.accessibility.XAccessible
66 public class SwAccessibleTextGraphicObject extends TestCase {
68 XTextDocument xTextDoc = null;
70 /**
71 * Called to create an instance of <code>TestEnvironment</code>
72 * with an object to test and related objects.
73 * Creates a graphic object and inserts it into the document.
74 * Obtains accessible object for graphic object.
76 * @param tParam test parameters
77 * @param log writer to log information while testing
79 * @see TestEnvironment
80 * @see #getTestEnvironment()
82 protected TestEnvironment createTestEnvironment(
83 TestParameters Param, PrintWriter log) {
85 XInterface oObj = null;
87 SOfficeFactory SOF = SOfficeFactory.getFactory((XMultiServiceFactory)Param.getMSF());
88 Object oGraphObj = SOF.createInstance(
89 xTextDoc, "com.sun.star.text.GraphicObject");
91 XText the_text = xTextDoc.getText();
92 XTextCursor the_cursor = the_text.createTextCursor();
93 XTextContent the_content = (XTextContent)
94 UnoRuntime.queryInterface(XTextContent.class, oGraphObj);
96 log.println( "inserting graphic" );
97 try {
98 the_text.insertTextContent(the_cursor, the_content, true);
99 } catch (com.sun.star.lang.IllegalArgumentException e) {
100 e.printStackTrace();
101 throw new StatusException("Couldn't insert Content", e);
104 XModel aModel = (XModel)
105 UnoRuntime.queryInterface(XModel.class, xTextDoc);
107 AccessibilityTools at = new AccessibilityTools();
109 XWindow xWindow = at.getCurrentWindow((XMultiServiceFactory)Param.getMSF(), aModel);
110 XAccessible xRoot = at.getAccessibleObject(xWindow);
112 at.getAccessibleObjectForRole(xRoot, AccessibleRole.GRAPHIC);
114 oObj = at.SearchedContext;
116 log.println("ImplementationName " + utils.getImplName(oObj));
117 at.printAccessibleTree(log, xRoot, Param.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
119 TestEnvironment tEnv = new TestEnvironment(oObj);
121 XController xController = xTextDoc.getCurrentController();
122 XViewSettingsSupplier xViewSetSup = (XViewSettingsSupplier)
123 UnoRuntime.queryInterface(XViewSettingsSupplier.class,
124 xController);
126 final XPropertySet PropSet = xViewSetSup.getViewSettings();
128 tEnv.addObjRelation("EventProducer",
129 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
130 public void fireEvent() {
131 try {
132 //change zoom value to 15%
133 PropSet.setPropertyValue("ZoomValue", new Short("15"));
134 //and back to 100%
135 PropSet.setPropertyValue("ZoomValue", new Short("100"));
136 } catch ( com.sun.star.lang.WrappedTargetException e ) {
138 } catch ( com.sun.star.lang.IllegalArgumentException e ) {
140 } catch ( com.sun.star.beans.PropertyVetoException e ) {
142 } catch ( com.sun.star.beans.UnknownPropertyException e ) {
149 return tEnv;
155 * Called while disposing a <code>TestEnvironment</code>.
156 * Disposes text document.
157 * @param tParam test parameters
158 * @param tEnv the environment to cleanup
159 * @param log writer to log information while testing
161 protected void cleanup( TestParameters Param, PrintWriter log) {
162 log.println("dispose text document");
163 util.DesktopTools.closeDoc(xTextDoc);
167 * Called while the <code>TestCase</code> initialization.
168 * Creates a text document.
170 * @param tParam test parameters
171 * @param log writer to log information while testing
173 * @see #initializeTestCase()
175 protected void initialize(TestParameters Param, PrintWriter log) {
176 log.println( "creating a text document" );
177 xTextDoc = WriterTools.createTextDoc((XMultiServiceFactory)Param.getMSF());