1ef39d40dSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3ef39d40dSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4ef39d40dSAndrew Rist * or more contributor license agreements. See the NOTICE file 5ef39d40dSAndrew Rist * distributed with this work for additional information 6ef39d40dSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7ef39d40dSAndrew Rist * to you under the Apache License, Version 2.0 (the 8ef39d40dSAndrew Rist * "License"); you may not use this file except in compliance 9ef39d40dSAndrew Rist * with the License. You may obtain a copy of the License at 10ef39d40dSAndrew Rist * 11ef39d40dSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12ef39d40dSAndrew Rist * 13ef39d40dSAndrew Rist * Unless required by applicable law or agreed to in writing, 14ef39d40dSAndrew Rist * software distributed under the License is distributed on an 15ef39d40dSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16ef39d40dSAndrew Rist * KIND, either express or implied. See the License for the 17ef39d40dSAndrew Rist * specific language governing permissions and limitations 18ef39d40dSAndrew Rist * under the License. 19ef39d40dSAndrew Rist * 20ef39d40dSAndrew Rist *************************************************************/ 21ef39d40dSAndrew Rist 22ef39d40dSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir package mod._svx; 25cdf0e10cSrcweir 26cdf0e10cSrcweir import java.io.PrintWriter; 27cdf0e10cSrcweir 28cdf0e10cSrcweir import lib.StatusException; 29cdf0e10cSrcweir import lib.TestCase; 30cdf0e10cSrcweir import lib.TestEnvironment; 31cdf0e10cSrcweir import lib.TestParameters; 32cdf0e10cSrcweir import util.AccessibilityTools; 33cdf0e10cSrcweir import util.DrawTools; 34cdf0e10cSrcweir import util.SOfficeFactory; 35cdf0e10cSrcweir import util.utils; 36cdf0e10cSrcweir 37cdf0e10cSrcweir import com.sun.star.accessibility.AccessibleRole; 38cdf0e10cSrcweir import com.sun.star.accessibility.XAccessible; 39cdf0e10cSrcweir import com.sun.star.awt.XExtendedToolkit; 40cdf0e10cSrcweir import com.sun.star.awt.XWindow; 41cdf0e10cSrcweir import com.sun.star.beans.XPropertySet; 42cdf0e10cSrcweir import com.sun.star.drawing.XShape; 43cdf0e10cSrcweir import com.sun.star.frame.XController; 44cdf0e10cSrcweir import com.sun.star.frame.XDispatch; 45cdf0e10cSrcweir import com.sun.star.frame.XDispatchProvider; 46cdf0e10cSrcweir import com.sun.star.frame.XModel; 47cdf0e10cSrcweir import com.sun.star.lang.XComponent; 48cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory; 49cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 50cdf0e10cSrcweir import com.sun.star.uno.XInterface; 51cdf0e10cSrcweir import com.sun.star.util.URL; 52cdf0e10cSrcweir import com.sun.star.util.XURLTransformer; 53cdf0e10cSrcweir import com.sun.star.view.XSelectionSupplier; 54cdf0e10cSrcweir 55cdf0e10cSrcweir 56cdf0e10cSrcweir /** 57cdf0e10cSrcweir * 58cdf0e10cSrcweir * @author sw93809 59cdf0e10cSrcweir * @version 60cdf0e10cSrcweir */ 61cdf0e10cSrcweir public class SvxGraphCtrlAccessibleContext extends TestCase{ 62cdf0e10cSrcweir 63cdf0e10cSrcweir static XComponent xDrawDoc = null; 64cdf0e10cSrcweir 65cdf0e10cSrcweir /** 66cdf0e10cSrcweir * Called to create an instance of <code>TestEnvironment</code> 67cdf0e10cSrcweir * with an object to test and related objects. 68cdf0e10cSrcweir * Switchs the document to Print Preview mode. 69cdf0e10cSrcweir * Obtains accissible object for the page view. 70cdf0e10cSrcweir * 71cdf0e10cSrcweir * @param tParam test parameters 72cdf0e10cSrcweir * @param log writer to log information while testing 73cdf0e10cSrcweir * 74cdf0e10cSrcweir * @see TestEnvironment 755496b966SPedro Giffuni * @see #getTestEnvironment 76cdf0e10cSrcweir */ 77cdf0e10cSrcweir createTestEnvironment( TestParameters Param, PrintWriter log)78cdf0e10cSrcweir protected TestEnvironment createTestEnvironment( 79cdf0e10cSrcweir TestParameters Param, PrintWriter log) { 80cdf0e10cSrcweir 81cdf0e10cSrcweir XInterface oObj = null; 82cdf0e10cSrcweir 83cdf0e10cSrcweir 84cdf0e10cSrcweir XModel aModel = (XModel) 85cdf0e10cSrcweir UnoRuntime.queryInterface(XModel.class, xDrawDoc); 86cdf0e10cSrcweir 87cdf0e10cSrcweir XController xController = aModel.getCurrentController(); 88cdf0e10cSrcweir 89cdf0e10cSrcweir SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)Param.getMSF()); 90cdf0e10cSrcweir final XShape oShape = SOF.createShape(xDrawDoc, 91cdf0e10cSrcweir 5000,5000,1500,1000,"GraphicObject"); 92cdf0e10cSrcweir 93cdf0e10cSrcweir 94cdf0e10cSrcweir DrawTools.getShapes(DrawTools.getDrawPage(xDrawDoc,0)).add(oShape); 95cdf0e10cSrcweir 96cdf0e10cSrcweir XPropertySet shapeProps = (XPropertySet) 97cdf0e10cSrcweir UnoRuntime.queryInterface(XPropertySet.class, oShape); 98cdf0e10cSrcweir 99cdf0e10cSrcweir String url = util.utils.getFullTestURL("space-metal.jpg"); 100cdf0e10cSrcweir 101cdf0e10cSrcweir log.println("Inserting Graphic: "+url); 102cdf0e10cSrcweir 103cdf0e10cSrcweir try { 104cdf0e10cSrcweir shapeProps.setPropertyValue("GraphicURL", url); 105cdf0e10cSrcweir } catch (com.sun.star.beans.UnknownPropertyException upe) { 106cdf0e10cSrcweir log.println("Property GraphicURL is unknown"); 107cdf0e10cSrcweir } catch (com.sun.star.beans.PropertyVetoException pve) { 108cdf0e10cSrcweir log.println("Property GraphicURL is read only"); 109cdf0e10cSrcweir } catch (com.sun.star.lang.IllegalArgumentException iae) { 110cdf0e10cSrcweir log.println("Property GraphicURL tried to set to illegal argument"); 111cdf0e10cSrcweir } catch (com.sun.star.lang.WrappedTargetException wte) { 112cdf0e10cSrcweir log.println("Wrapped Target Exception was thrown while setting Property GraphicURL"); 113cdf0e10cSrcweir } 114cdf0e10cSrcweir 115cdf0e10cSrcweir 116cdf0e10cSrcweir //Opening ImageMapDialog 117cdf0e10cSrcweir try { 118cdf0e10cSrcweir String aSlotID = "slot:10371"; 119cdf0e10cSrcweir XDispatchProvider xDispProv = (XDispatchProvider) 120cdf0e10cSrcweir UnoRuntime.queryInterface( XDispatchProvider.class, xController ); 121cdf0e10cSrcweir XURLTransformer xParser = (com.sun.star.util.XURLTransformer) 122cdf0e10cSrcweir UnoRuntime.queryInterface(XURLTransformer.class, 123cdf0e10cSrcweir ((XMultiServiceFactory)Param.getMSF()).createInstance("com.sun.star.util.URLTransformer")); 124cdf0e10cSrcweir // Because it's an in/out parameter we must use an array of URL objects. 125cdf0e10cSrcweir URL[] aParseURL = new URL[1]; 126cdf0e10cSrcweir aParseURL[0] = new URL(); 127cdf0e10cSrcweir aParseURL[0].Complete = aSlotID; 128cdf0e10cSrcweir xParser.parseStrict(aParseURL); 129cdf0e10cSrcweir URL aURL = aParseURL[0]; 130cdf0e10cSrcweir XDispatch xDispatcher = xDispProv.queryDispatch( aURL,"",0); 131cdf0e10cSrcweir if( xDispatcher != null ) 132cdf0e10cSrcweir xDispatcher.dispatch( aURL, null ); 133cdf0e10cSrcweir utils.shortWait(Param.getInt(util.PropertyName.SHORT_WAIT)); 134cdf0e10cSrcweir } catch (com.sun.star.uno.Exception e) { 135cdf0e10cSrcweir log.println("Couldn't change mode"); 136cdf0e10cSrcweir } 137cdf0e10cSrcweir 138cdf0e10cSrcweir 139cdf0e10cSrcweir try { 140cdf0e10cSrcweir oObj = (XInterface) ((XMultiServiceFactory)Param.getMSF()).createInstance 141cdf0e10cSrcweir ("com.sun.star.awt.Toolkit") ; 142cdf0e10cSrcweir } catch (com.sun.star.uno.Exception e) { 143cdf0e10cSrcweir log.println("Couldn't get toolkit"); 144cdf0e10cSrcweir e.printStackTrace(log); 145cdf0e10cSrcweir throw new StatusException("Couldn't get toolkit", e ); 146cdf0e10cSrcweir } 147cdf0e10cSrcweir 148cdf0e10cSrcweir XExtendedToolkit tk = (XExtendedToolkit) 149cdf0e10cSrcweir UnoRuntime.queryInterface(XExtendedToolkit.class,oObj); 150cdf0e10cSrcweir 151cdf0e10cSrcweir 152cdf0e10cSrcweir AccessibilityTools at = new AccessibilityTools(); 153cdf0e10cSrcweir 154cdf0e10cSrcweir XWindow xWindow = (XWindow) 155cdf0e10cSrcweir UnoRuntime.queryInterface(XWindow.class,tk.getActiveTopWindow()); 156cdf0e10cSrcweir 157cdf0e10cSrcweir XAccessible xRoot = at.getAccessibleObject(xWindow); 158cdf0e10cSrcweir 159cdf0e10cSrcweir at.printAccessibleTree(log, xRoot, Param.getBool(util.PropertyName.DEBUG_IS_ACTIVE)); 160cdf0e10cSrcweir 161cdf0e10cSrcweir oObj = at.getAccessibleObjectForRole(xRoot, AccessibleRole.PANEL); 162cdf0e10cSrcweir 163cdf0e10cSrcweir log.println("ImplementationName " + utils.getImplName(oObj)); 164cdf0e10cSrcweir 165cdf0e10cSrcweir TestEnvironment tEnv = new TestEnvironment(oObj); 166cdf0e10cSrcweir 167cdf0e10cSrcweir //selecting the inserted shape 168cdf0e10cSrcweir final XSelectionSupplier SelSupp = (XSelectionSupplier) 169cdf0e10cSrcweir UnoRuntime.queryInterface(XSelectionSupplier.class,xController); 170cdf0e10cSrcweir 171cdf0e10cSrcweir tEnv.addObjRelation("EventProducer", 172cdf0e10cSrcweir new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() { 173cdf0e10cSrcweir public void fireEvent() { 174cdf0e10cSrcweir try { 175cdf0e10cSrcweir SelSupp.select(oShape); 176cdf0e10cSrcweir } catch (com.sun.star.lang.IllegalArgumentException iae) { 177cdf0e10cSrcweir System.out.println("Couldn't select shape"); 178cdf0e10cSrcweir } 179cdf0e10cSrcweir } 180cdf0e10cSrcweir }); 181cdf0e10cSrcweir 182cdf0e10cSrcweir return tEnv; 183cdf0e10cSrcweir 184cdf0e10cSrcweir } 185cdf0e10cSrcweir 186cdf0e10cSrcweir /** 187cdf0e10cSrcweir * Called while disposing a <code>TestEnvironment</code>. 188cdf0e10cSrcweir * Disposes text document. 189*e6b649b5SPedro Giffuni * @param Param test parameters 190cdf0e10cSrcweir * @param log writer to log information while testing 191cdf0e10cSrcweir */ cleanup( TestParameters Param, PrintWriter log)192cdf0e10cSrcweir protected void cleanup( TestParameters Param, PrintWriter log) { 193cdf0e10cSrcweir 194cdf0e10cSrcweir XModel aModel = (XModel) 195cdf0e10cSrcweir UnoRuntime.queryInterface(XModel.class, xDrawDoc); 196cdf0e10cSrcweir 197cdf0e10cSrcweir XController xController = aModel.getCurrentController(); 198cdf0e10cSrcweir 199cdf0e10cSrcweir //Closing ImageMapDialog 200cdf0e10cSrcweir try { 201cdf0e10cSrcweir String aSlotID = "slot:10371"; 202cdf0e10cSrcweir XDispatchProvider xDispProv = (XDispatchProvider) 203cdf0e10cSrcweir UnoRuntime.queryInterface( XDispatchProvider.class, xController ); 204cdf0e10cSrcweir XURLTransformer xParser = (com.sun.star.util.XURLTransformer) 205cdf0e10cSrcweir UnoRuntime.queryInterface(XURLTransformer.class, 206cdf0e10cSrcweir ((XMultiServiceFactory)Param.getMSF()).createInstance("com.sun.star.util.URLTransformer")); 207cdf0e10cSrcweir // Because it's an in/out parameter we must use an array of URL objects. 208cdf0e10cSrcweir URL[] aParseURL = new URL[1]; 209cdf0e10cSrcweir aParseURL[0] = new URL(); 210cdf0e10cSrcweir aParseURL[0].Complete = aSlotID; 211cdf0e10cSrcweir xParser.parseStrict(aParseURL); 212cdf0e10cSrcweir URL aURL = aParseURL[0]; 213cdf0e10cSrcweir XDispatch xDispatcher = xDispProv.queryDispatch( aURL,"",0); 214cdf0e10cSrcweir if( xDispatcher != null ) 215cdf0e10cSrcweir xDispatcher.dispatch( aURL, null ); 216cdf0e10cSrcweir } catch (com.sun.star.uno.Exception e) { 217cdf0e10cSrcweir log.println("Couldn't change mode"); 218cdf0e10cSrcweir } 219cdf0e10cSrcweir log.println( " disposing xDrawDoc " ); 220cdf0e10cSrcweir util.DesktopTools.closeDoc(xDrawDoc); 221cdf0e10cSrcweir } 222cdf0e10cSrcweir 223cdf0e10cSrcweir /** 224cdf0e10cSrcweir * Called while the <code>TestCase</code> initialization. In the 225cdf0e10cSrcweir * implementation does nothing. Subclasses can override to initialize 226cdf0e10cSrcweir * objects shared among all <code>TestEnvironment</code>s. 227cdf0e10cSrcweir * 228*e6b649b5SPedro Giffuni * @param Param test parameters 229cdf0e10cSrcweir * @param log writer to log information while testing 230cdf0e10cSrcweir * 2315496b966SPedro Giffuni * @see #initializeTestCase 232cdf0e10cSrcweir */ initialize(TestParameters Param, PrintWriter log)233cdf0e10cSrcweir protected void initialize(TestParameters Param, PrintWriter log) { 234cdf0e10cSrcweir // get a soffice factory object 235cdf0e10cSrcweir SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)Param.getMSF()); 236cdf0e10cSrcweir 237cdf0e10cSrcweir try { 238cdf0e10cSrcweir log.println("creating a draw document"); 239cdf0e10cSrcweir xDrawDoc = SOF.createDrawDoc(null); 240cdf0e10cSrcweir } catch (com.sun.star.uno.Exception e) { 241cdf0e10cSrcweir e.printStackTrace( log ); 242cdf0e10cSrcweir throw new StatusException( "Couldn't create document ", e ); 243cdf0e10cSrcweir } 244cdf0e10cSrcweir } 245cdf0e10cSrcweir 246cdf0e10cSrcweir } 247