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