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
;
24 import lib
.TestEnvironment
;
25 import lib
.TestParameters
;
26 import util
.AccessibilityTools
;
27 import util
.DrawTools
;
28 import util
.SOfficeFactory
;
31 import com
.sun
.star
.accessibility
.AccessibleRole
;
32 import com
.sun
.star
.accessibility
.XAccessible
;
33 import com
.sun
.star
.awt
.XExtendedToolkit
;
34 import com
.sun
.star
.awt
.XWindow
;
35 import com
.sun
.star
.beans
.XPropertySet
;
36 import com
.sun
.star
.drawing
.XShape
;
37 import com
.sun
.star
.frame
.XController
;
38 import com
.sun
.star
.frame
.XDispatch
;
39 import com
.sun
.star
.frame
.XDispatchProvider
;
40 import com
.sun
.star
.frame
.XModel
;
41 import com
.sun
.star
.lang
.XComponent
;
42 import com
.sun
.star
.uno
.UnoRuntime
;
43 import com
.sun
.star
.uno
.XInterface
;
44 import com
.sun
.star
.util
.URL
;
45 import com
.sun
.star
.util
.XURLTransformer
;
46 import com
.sun
.star
.view
.XSelectionSupplier
;
48 public class SvxGraphCtrlAccessibleContext
extends TestCase
{
50 static XComponent xDrawDoc
= null;
53 * Called to create an instance of <code>TestEnvironment</code>
54 * with an object to test and related objects.
55 * Switches the document to Print Preview mode.
56 * Obtains accessible object for the page view.
58 * @param Param test parameters
59 * @param log writer to log information while testing
61 * @see TestEnvironment
62 * @see #getTestEnvironment
65 protected TestEnvironment
createTestEnvironment(
66 TestParameters Param
, PrintWriter log
) throws Exception
{
68 XInterface oObj
= null;
71 XModel aModel
= UnoRuntime
.queryInterface(XModel
.class, xDrawDoc
);
73 XController xController
= aModel
.getCurrentController();
75 SOfficeFactory SOF
= SOfficeFactory
.getFactory( Param
.getMSF());
76 final XShape oShape
= SOF
.createShape(xDrawDoc
,
77 5000,5000,1500,1000,"GraphicObject");
80 DrawTools
.getShapes(DrawTools
.getDrawPage(xDrawDoc
,0)).add(oShape
);
82 XPropertySet shapeProps
= UnoRuntime
.queryInterface(XPropertySet
.class, oShape
);
84 String url
= util
.utils
.getFullTestURL("space-metal.jpg");
86 log
.println("Inserting Graphic: "+url
);
89 shapeProps
.setPropertyValue("GraphicURL", url
);
90 } catch (com
.sun
.star
.beans
.UnknownPropertyException upe
) {
91 log
.println("Property GraphicURL is unknown");
92 } catch (com
.sun
.star
.beans
.PropertyVetoException pve
) {
93 log
.println("Property GraphicURL is read only");
94 } catch (com
.sun
.star
.lang
.IllegalArgumentException iae
) {
95 log
.println("Property GraphicURL tried to set to illegal argument");
96 } catch (com
.sun
.star
.lang
.WrappedTargetException wte
) {
97 log
.println("Wrapped Target Exception was thrown while setting Property GraphicURL");
101 //Opening ImageMapDialog
103 String aSlotID
= ".uno:ImageMapDialog";
104 XDispatchProvider xDispProv
= UnoRuntime
.queryInterface( XDispatchProvider
.class, xController
);
105 XURLTransformer xParser
= UnoRuntime
.queryInterface(XURLTransformer
.class,
106 Param
.getMSF().createInstance("com.sun.star.util.URLTransformer"));
107 // Because it's an in/out parameter we must use an array of URL objects.
108 URL
[] aParseURL
= new URL
[1];
109 aParseURL
[0] = new URL();
110 aParseURL
[0].Complete
= aSlotID
;
111 xParser
.parseStrict(aParseURL
);
112 URL aURL
= aParseURL
[0];
113 XDispatch xDispatcher
= xDispProv
.queryDispatch( aURL
,"",0);
114 if( xDispatcher
!= null )
115 xDispatcher
.dispatch( aURL
, null );
117 } catch (com
.sun
.star
.uno
.Exception e
) {
118 log
.println("Couldn't change mode");
122 oObj
= (XInterface
) Param
.getMSF().createInstance
123 ("com.sun.star.awt.Toolkit") ;
125 XExtendedToolkit tk
= UnoRuntime
.queryInterface(XExtendedToolkit
.class,oObj
);
127 XWindow xWindow
= UnoRuntime
.queryInterface(XWindow
.class,tk
.getActiveTopWindow());
129 XAccessible xRoot
= AccessibilityTools
.getAccessibleObject(xWindow
);
131 AccessibilityTools
.printAccessibleTree(log
, xRoot
, Param
.getBool(util
.PropertyName
.DEBUG_IS_ACTIVE
));
133 oObj
= AccessibilityTools
.getAccessibleObjectForRole(xRoot
, AccessibleRole
.PANEL
);
135 log
.println("ImplementationName " + utils
.getImplName(oObj
));
137 TestEnvironment tEnv
= new TestEnvironment(oObj
);
139 //selecting the inserted shape
140 final XSelectionSupplier SelSupp
= UnoRuntime
.queryInterface(XSelectionSupplier
.class,xController
);
142 tEnv
.addObjRelation("EventProducer",
143 new ifc
.accessibility
._XAccessibleEventBroadcaster
.EventProducer() {
144 public void fireEvent() {
146 SelSupp
.select(oShape
);
147 } catch (com
.sun
.star
.lang
.IllegalArgumentException iae
) {
148 System
.out
.println("Couldn't select shape");
158 * Called while disposing a <code>TestEnvironment</code>.
159 * Disposes text document.
160 * @param Param test parameters
161 * @param log writer to log information while testing
164 protected void cleanup( TestParameters Param
, PrintWriter log
) {
166 XModel aModel
= UnoRuntime
.queryInterface(XModel
.class, xDrawDoc
);
168 XController xController
= aModel
.getCurrentController();
170 //Closing ImageMapDialog
172 String aSlotID
= "slot:10371";
173 XDispatchProvider xDispProv
= UnoRuntime
.queryInterface( XDispatchProvider
.class, xController
);
174 XURLTransformer xParser
= UnoRuntime
.queryInterface(XURLTransformer
.class,
175 Param
.getMSF().createInstance("com.sun.star.util.URLTransformer"));
176 // Because it's an in/out parameter we must use an array of URL objects.
177 URL
[] aParseURL
= new URL
[1];
178 aParseURL
[0] = new URL();
179 aParseURL
[0].Complete
= aSlotID
;
180 xParser
.parseStrict(aParseURL
);
181 URL aURL
= aParseURL
[0];
182 XDispatch xDispatcher
= xDispProv
.queryDispatch( aURL
,"",0);
183 if( xDispatcher
!= null )
184 xDispatcher
.dispatch( aURL
, null );
185 } catch (com
.sun
.star
.uno
.Exception e
) {
186 log
.println("Couldn't change mode");
188 log
.println( " disposing xDrawDoc " );
189 util
.DesktopTools
.closeDoc(xDrawDoc
);
193 * Called while the <code>TestCase</code> initialization. In the
194 * implementation does nothing. Subclasses can override to initialize
195 * objects shared among all <code>TestEnvironment</code>s.
197 * @param Param test parameters
198 * @param log writer to log information while testing
200 * @see #initializeTestCase
203 protected void initialize(TestParameters Param
, PrintWriter log
) throws Exception
{
204 // get a soffice factory object
205 SOfficeFactory SOF
= SOfficeFactory
.getFactory( Param
.getMSF());
206 log
.println("creating a draw document");
207 xDrawDoc
= SOF
.createDrawDoc(null);