2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 import java
.io
.PrintWriter
;
23 import lib
.StatusException
;
25 import lib
.TestEnvironment
;
26 import lib
.TestParameters
;
27 import util
.AccessibilityTools
;
28 import util
.DrawTools
;
29 import util
.SOfficeFactory
;
32 import com
.sun
.star
.accessibility
.AccessibleRole
;
33 import com
.sun
.star
.accessibility
.XAccessible
;
34 import com
.sun
.star
.awt
.XExtendedToolkit
;
35 import com
.sun
.star
.awt
.XWindow
;
36 import com
.sun
.star
.beans
.XPropertySet
;
37 import com
.sun
.star
.drawing
.XShape
;
38 import com
.sun
.star
.frame
.XController
;
39 import com
.sun
.star
.frame
.XDispatch
;
40 import com
.sun
.star
.frame
.XDispatchProvider
;
41 import com
.sun
.star
.frame
.XModel
;
42 import com
.sun
.star
.lang
.XComponent
;
43 import com
.sun
.star
.uno
.UnoRuntime
;
44 import com
.sun
.star
.uno
.XInterface
;
45 import com
.sun
.star
.util
.URL
;
46 import com
.sun
.star
.util
.XURLTransformer
;
47 import com
.sun
.star
.view
.XSelectionSupplier
;
49 public class SvxGraphCtrlAccessibleContext
extends TestCase
{
51 static XComponent xDrawDoc
= null;
54 * Called to create an instance of <code>TestEnvironment</code>
55 * with an object to test and related objects.
56 * Switches the document to Print Preview mode.
57 * Obtains accessible object for the page view.
59 * @param Param test parameters
60 * @param log writer to log information while testing
62 * @see TestEnvironment
63 * @see #getTestEnvironment
66 protected TestEnvironment
createTestEnvironment(
67 TestParameters Param
, PrintWriter log
) {
69 XInterface oObj
= null;
72 XModel aModel
= UnoRuntime
.queryInterface(XModel
.class, xDrawDoc
);
74 XController xController
= aModel
.getCurrentController();
76 SOfficeFactory SOF
= SOfficeFactory
.getFactory( Param
.getMSF());
77 final XShape oShape
= SOF
.createShape(xDrawDoc
,
78 5000,5000,1500,1000,"GraphicObject");
81 DrawTools
.getShapes(DrawTools
.getDrawPage(xDrawDoc
,0)).add(oShape
);
83 XPropertySet shapeProps
= UnoRuntime
.queryInterface(XPropertySet
.class, oShape
);
85 String url
= util
.utils
.getFullTestURL("space-metal.jpg");
87 log
.println("Inserting Graphic: "+url
);
90 shapeProps
.setPropertyValue("GraphicURL", url
);
91 } catch (com
.sun
.star
.beans
.UnknownPropertyException upe
) {
92 log
.println("Property GraphicURL is unknown");
93 } catch (com
.sun
.star
.beans
.PropertyVetoException pve
) {
94 log
.println("Property GraphicURL is read only");
95 } catch (com
.sun
.star
.lang
.IllegalArgumentException iae
) {
96 log
.println("Property GraphicURL tried to set to illegal argument");
97 } catch (com
.sun
.star
.lang
.WrappedTargetException wte
) {
98 log
.println("Wrapped Target Exception was thrown while setting Property GraphicURL");
102 //Opening ImageMapDialog
104 String aSlotID
= "slot:10371";
105 XDispatchProvider xDispProv
= UnoRuntime
.queryInterface( XDispatchProvider
.class, xController
);
106 XURLTransformer xParser
= UnoRuntime
.queryInterface(XURLTransformer
.class,
107 Param
.getMSF().createInstance("com.sun.star.util.URLTransformer"));
108 // Because it's an in/out parameter we must use an array of URL objects.
109 URL
[] aParseURL
= new URL
[1];
110 aParseURL
[0] = new URL();
111 aParseURL
[0].Complete
= aSlotID
;
112 xParser
.parseStrict(aParseURL
);
113 URL aURL
= aParseURL
[0];
114 XDispatch xDispatcher
= xDispProv
.queryDispatch( aURL
,"",0);
115 if( xDispatcher
!= null )
116 xDispatcher
.dispatch( aURL
, null );
118 } catch (com
.sun
.star
.uno
.Exception e
) {
119 log
.println("Couldn't change mode");
124 oObj
= (XInterface
) Param
.getMSF().createInstance
125 ("com.sun.star.awt.Toolkit") ;
126 } catch (com
.sun
.star
.uno
.Exception e
) {
127 log
.println("Couldn't get toolkit");
128 e
.printStackTrace(log
);
129 throw new StatusException("Couldn't get toolkit", e
);
132 XExtendedToolkit tk
= UnoRuntime
.queryInterface(XExtendedToolkit
.class,oObj
);
134 XWindow xWindow
= UnoRuntime
.queryInterface(XWindow
.class,tk
.getActiveTopWindow());
136 XAccessible xRoot
= AccessibilityTools
.getAccessibleObject(xWindow
);
138 AccessibilityTools
.printAccessibleTree(log
, xRoot
, Param
.getBool(util
.PropertyName
.DEBUG_IS_ACTIVE
));
140 oObj
= AccessibilityTools
.getAccessibleObjectForRole(xRoot
, AccessibleRole
.PANEL
);
142 log
.println("ImplementationName " + utils
.getImplName(oObj
));
144 TestEnvironment tEnv
= new TestEnvironment(oObj
);
146 //selecting the inserted shape
147 final XSelectionSupplier SelSupp
= UnoRuntime
.queryInterface(XSelectionSupplier
.class,xController
);
149 tEnv
.addObjRelation("EventProducer",
150 new ifc
.accessibility
._XAccessibleEventBroadcaster
.EventProducer() {
151 public void fireEvent() {
153 SelSupp
.select(oShape
);
154 } catch (com
.sun
.star
.lang
.IllegalArgumentException iae
) {
155 System
.out
.println("Couldn't select shape");
165 * Called while disposing a <code>TestEnvironment</code>.
166 * Disposes text document.
167 * @param Param test parameters
168 * @param log writer to log information while testing
171 protected void cleanup( TestParameters Param
, PrintWriter log
) {
173 XModel aModel
= UnoRuntime
.queryInterface(XModel
.class, xDrawDoc
);
175 XController xController
= aModel
.getCurrentController();
177 //Closing ImageMapDialog
179 String aSlotID
= "slot:10371";
180 XDispatchProvider xDispProv
= UnoRuntime
.queryInterface( XDispatchProvider
.class, xController
);
181 XURLTransformer xParser
= UnoRuntime
.queryInterface(XURLTransformer
.class,
182 Param
.getMSF().createInstance("com.sun.star.util.URLTransformer"));
183 // Because it's an in/out parameter we must use an array of URL objects.
184 URL
[] aParseURL
= new URL
[1];
185 aParseURL
[0] = new URL();
186 aParseURL
[0].Complete
= aSlotID
;
187 xParser
.parseStrict(aParseURL
);
188 URL aURL
= aParseURL
[0];
189 XDispatch xDispatcher
= xDispProv
.queryDispatch( aURL
,"",0);
190 if( xDispatcher
!= null )
191 xDispatcher
.dispatch( aURL
, null );
192 } catch (com
.sun
.star
.uno
.Exception e
) {
193 log
.println("Couldn't change mode");
195 log
.println( " disposing xDrawDoc " );
196 util
.DesktopTools
.closeDoc(xDrawDoc
);
200 * Called while the <code>TestCase</code> initialization. In the
201 * implementation does nothing. Subclasses can override to initialize
202 * objects shared among all <code>TestEnvironment</code>s.
204 * @param Param test parameters
205 * @param log writer to log information while testing
207 * @see #initializeTestCase
210 protected void initialize(TestParameters Param
, PrintWriter log
) {
211 // get a soffice factory object
212 SOfficeFactory SOF
= SOfficeFactory
.getFactory( Param
.getMSF());
215 log
.println("creating a draw document");
216 xDrawDoc
= SOF
.createDrawDoc(null);
217 } catch (com
.sun
.star
.uno
.Exception e
) {
218 e
.printStackTrace( log
);
219 throw new StatusException( "Couldn't create document ", e
);