merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / mod / _svx / SvxGraphCtrlAccessibleContext.java
blob27a5f3b32b30433d1f86b837d80cc8e46c516bbd
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: SvxGraphCtrlAccessibleContext.java,v $
10 * $Revision: 1.8.8.1 $
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 ************************************************************************/
31 package mod._svx;
33 import java.io.PrintWriter;
35 import lib.StatusException;
36 import lib.TestCase;
37 import lib.TestEnvironment;
38 import lib.TestParameters;
39 import util.AccessibilityTools;
40 import util.DrawTools;
41 import util.SOfficeFactory;
42 import util.utils;
44 import com.sun.star.accessibility.AccessibleRole;
45 import com.sun.star.accessibility.XAccessible;
46 import com.sun.star.awt.XExtendedToolkit;
47 import com.sun.star.awt.XWindow;
48 import com.sun.star.beans.XPropertySet;
49 import com.sun.star.drawing.XShape;
50 import com.sun.star.frame.XController;
51 import com.sun.star.frame.XDispatch;
52 import com.sun.star.frame.XDispatchProvider;
53 import com.sun.star.frame.XModel;
54 import com.sun.star.lang.XComponent;
55 import com.sun.star.lang.XMultiServiceFactory;
56 import com.sun.star.uno.UnoRuntime;
57 import com.sun.star.uno.XInterface;
58 import com.sun.star.util.URL;
59 import com.sun.star.util.XURLTransformer;
60 import com.sun.star.view.XSelectionSupplier;
63 /**
65 * @author sw93809
66 * @version
68 public class SvxGraphCtrlAccessibleContext extends TestCase{
70 static XComponent xDrawDoc = null;
72 /**
73 * Called to create an instance of <code>TestEnvironment</code>
74 * with an object to test and related objects.
75 * Switchs the document to Print Preview mode.
76 * Obtains accissible object for the page view.
78 * @param tParam test parameters
79 * @param log writer to log information while testing
81 * @see TestEnvironment
82 * @see #getTestEnvironment()
85 protected TestEnvironment createTestEnvironment(
86 TestParameters Param, PrintWriter log) {
88 XInterface oObj = null;
91 XModel aModel = (XModel)
92 UnoRuntime.queryInterface(XModel.class, xDrawDoc);
94 XController xController = aModel.getCurrentController();
96 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)Param.getMSF());
97 final XShape oShape = SOF.createShape(xDrawDoc,
98 5000,5000,1500,1000,"GraphicObject");
101 DrawTools.getShapes(DrawTools.getDrawPage(xDrawDoc,0)).add(oShape);
103 XPropertySet shapeProps = (XPropertySet)
104 UnoRuntime.queryInterface(XPropertySet.class, oShape);
106 String url = util.utils.getFullTestURL("space-metal.jpg");
108 log.println("Inserting Graphic: "+url);
110 try {
111 shapeProps.setPropertyValue("GraphicURL", url);
112 } catch (com.sun.star.beans.UnknownPropertyException upe) {
113 log.println("Property GraphicURL is unknown");
114 } catch (com.sun.star.beans.PropertyVetoException pve) {
115 log.println("Property GraphicURL is read only");
116 } catch (com.sun.star.lang.IllegalArgumentException iae) {
117 log.println("Property GraphicURL tried to set to illegal argument");
118 } catch (com.sun.star.lang.WrappedTargetException wte) {
119 log.println("Wrapped Target Exception was thrown while setting Property GraphicURL");
123 //Opening ImageMapDialog
124 try {
125 String aSlotID = "slot:10371";
126 XDispatchProvider xDispProv = (XDispatchProvider)
127 UnoRuntime.queryInterface( XDispatchProvider.class, xController );
128 XURLTransformer xParser = (com.sun.star.util.XURLTransformer)
129 UnoRuntime.queryInterface(XURLTransformer.class,
130 ((XMultiServiceFactory)Param.getMSF()).createInstance("com.sun.star.util.URLTransformer"));
131 // Because it's an in/out parameter we must use an array of URL objects.
132 URL[] aParseURL = new URL[1];
133 aParseURL[0] = new URL();
134 aParseURL[0].Complete = aSlotID;
135 xParser.parseStrict(aParseURL);
136 URL aURL = aParseURL[0];
137 XDispatch xDispatcher = xDispProv.queryDispatch( aURL,"",0);
138 if( xDispatcher != null )
139 xDispatcher.dispatch( aURL, null );
140 utils.shortWait(Param.getInt(util.PropertyName.SHORT_WAIT));
141 } catch (com.sun.star.uno.Exception e) {
142 log.println("Couldn't change mode");
146 try {
147 oObj = (XInterface) ((XMultiServiceFactory)Param.getMSF()).createInstance
148 ("com.sun.star.awt.Toolkit") ;
149 } catch (com.sun.star.uno.Exception e) {
150 log.println("Couldn't get toolkit");
151 e.printStackTrace(log);
152 throw new StatusException("Couldn't get toolkit", e );
155 XExtendedToolkit tk = (XExtendedToolkit)
156 UnoRuntime.queryInterface(XExtendedToolkit.class,oObj);
159 AccessibilityTools at = new AccessibilityTools();
161 XWindow xWindow = (XWindow)
162 UnoRuntime.queryInterface(XWindow.class,tk.getActiveTopWindow());
164 XAccessible xRoot = at.getAccessibleObject(xWindow);
166 at.printAccessibleTree(log, xRoot, Param.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
168 oObj = at.getAccessibleObjectForRole(xRoot, AccessibleRole.PANEL);
170 log.println("ImplementationName " + utils.getImplName(oObj));
172 TestEnvironment tEnv = new TestEnvironment(oObj);
174 //selecting the inserted shape
175 final XSelectionSupplier SelSupp = (XSelectionSupplier)
176 UnoRuntime.queryInterface(XSelectionSupplier.class,xController);
178 tEnv.addObjRelation("EventProducer",
179 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
180 public void fireEvent() {
181 try {
182 SelSupp.select(oShape);
183 } catch (com.sun.star.lang.IllegalArgumentException iae) {
184 System.out.println("Couldn't select shape");
189 return tEnv;
194 * Called while disposing a <code>TestEnvironment</code>.
195 * Disposes text document.
196 * @param tParam test parameters
197 * @param tEnv the environment to cleanup
198 * @param log writer to log information while testing
200 protected void cleanup( TestParameters Param, PrintWriter log) {
202 XModel aModel = (XModel)
203 UnoRuntime.queryInterface(XModel.class, xDrawDoc);
205 XController xController = aModel.getCurrentController();
207 //Closing ImageMapDialog
208 try {
209 String aSlotID = "slot:10371";
210 XDispatchProvider xDispProv = (XDispatchProvider)
211 UnoRuntime.queryInterface( XDispatchProvider.class, xController );
212 XURLTransformer xParser = (com.sun.star.util.XURLTransformer)
213 UnoRuntime.queryInterface(XURLTransformer.class,
214 ((XMultiServiceFactory)Param.getMSF()).createInstance("com.sun.star.util.URLTransformer"));
215 // Because it's an in/out parameter we must use an array of URL objects.
216 URL[] aParseURL = new URL[1];
217 aParseURL[0] = new URL();
218 aParseURL[0].Complete = aSlotID;
219 xParser.parseStrict(aParseURL);
220 URL aURL = aParseURL[0];
221 XDispatch xDispatcher = xDispProv.queryDispatch( aURL,"",0);
222 if( xDispatcher != null )
223 xDispatcher.dispatch( aURL, null );
224 } catch (com.sun.star.uno.Exception e) {
225 log.println("Couldn't change mode");
227 log.println( " disposing xDrawDoc " );
228 util.DesktopTools.closeDoc(xDrawDoc);
232 * Called while the <code>TestCase</code> initialization. In the
233 * implementation does nothing. Subclasses can override to initialize
234 * objects shared among all <code>TestEnvironment</code>s.
236 * @param tParam test parameters
237 * @param log writer to log information while testing
239 * @see #initializeTestCase()
241 protected void initialize(TestParameters Param, PrintWriter log) {
242 // get a soffice factory object
243 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)Param.getMSF());
245 try {
246 log.println("creating a draw document");
247 xDrawDoc = SOF.createDrawDoc(null);
248 } catch (com.sun.star.uno.Exception e) {
249 e.printStackTrace( log );
250 throw new StatusException( "Couldn't create document ", e );