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
.lang
.XMultiServiceFactory
;
44 import com
.sun
.star
.uno
.UnoRuntime
;
45 import com
.sun
.star
.uno
.XInterface
;
46 import com
.sun
.star
.util
.URL
;
47 import com
.sun
.star
.util
.XURLTransformer
;
48 import com
.sun
.star
.view
.XSelectionSupplier
;
50 public class SvxGraphCtrlAccessibleContext
extends TestCase
{
52 static XComponent xDrawDoc
= null;
55 * Called to create an instance of <code>TestEnvironment</code>
56 * with an object to test and related objects.
57 * Switches the document to Print Preview mode.
58 * Obtains accessible object for the page view.
60 * @param Param test parameters
61 * @param log writer to log information while testing
63 * @see TestEnvironment
64 * @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( (XMultiServiceFactory
)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 ((XMultiServiceFactory
)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 );
117 utils
.shortWait(Param
.getInt(util
.PropertyName
.SHORT_WAIT
));
118 } catch (com
.sun
.star
.uno
.Exception e
) {
119 log
.println("Couldn't change mode");
124 oObj
= (XInterface
) ((XMultiServiceFactory
)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 AccessibilityTools at
= new AccessibilityTools();
136 XWindow xWindow
= UnoRuntime
.queryInterface(XWindow
.class,tk
.getActiveTopWindow());
138 XAccessible xRoot
= AccessibilityTools
.getAccessibleObject(xWindow
);
140 AccessibilityTools
.printAccessibleTree(log
, xRoot
, Param
.getBool(util
.PropertyName
.DEBUG_IS_ACTIVE
));
142 oObj
= AccessibilityTools
.getAccessibleObjectForRole(xRoot
, AccessibleRole
.PANEL
);
144 log
.println("ImplementationName " + utils
.getImplName(oObj
));
146 TestEnvironment tEnv
= new TestEnvironment(oObj
);
148 //selecting the inserted shape
149 final XSelectionSupplier SelSupp
= UnoRuntime
.queryInterface(XSelectionSupplier
.class,xController
);
151 tEnv
.addObjRelation("EventProducer",
152 new ifc
.accessibility
._XAccessibleEventBroadcaster
.EventProducer() {
153 public void fireEvent() {
155 SelSupp
.select(oShape
);
156 } catch (com
.sun
.star
.lang
.IllegalArgumentException iae
) {
157 System
.out
.println("Couldn't select shape");
167 * Called while disposing a <code>TestEnvironment</code>.
168 * Disposes text document.
169 * @param Param test parameters
170 * @param log writer to log information while testing
172 protected void cleanup( TestParameters Param
, PrintWriter log
) {
174 XModel aModel
= UnoRuntime
.queryInterface(XModel
.class, xDrawDoc
);
176 XController xController
= aModel
.getCurrentController();
178 //Closing ImageMapDialog
180 String aSlotID
= "slot:10371";
181 XDispatchProvider xDispProv
= UnoRuntime
.queryInterface( XDispatchProvider
.class, xController
);
182 XURLTransformer xParser
= UnoRuntime
.queryInterface(XURLTransformer
.class,
183 ((XMultiServiceFactory
)Param
.getMSF()).createInstance("com.sun.star.util.URLTransformer"));
184 // Because it's an in/out parameter we must use an array of URL objects.
185 URL
[] aParseURL
= new URL
[1];
186 aParseURL
[0] = new URL();
187 aParseURL
[0].Complete
= aSlotID
;
188 xParser
.parseStrict(aParseURL
);
189 URL aURL
= aParseURL
[0];
190 XDispatch xDispatcher
= xDispProv
.queryDispatch( aURL
,"",0);
191 if( xDispatcher
!= null )
192 xDispatcher
.dispatch( aURL
, null );
193 } catch (com
.sun
.star
.uno
.Exception e
) {
194 log
.println("Couldn't change mode");
196 log
.println( " disposing xDrawDoc " );
197 util
.DesktopTools
.closeDoc(xDrawDoc
);
201 * Called while the <code>TestCase</code> initialization. In the
202 * implementation does nothing. Subclasses can override to initialize
203 * objects shared among all <code>TestEnvironment</code>s.
205 * @param Param test parameters
206 * @param log writer to log information while testing
208 * @see #initializeTestCase
210 protected void initialize(TestParameters Param
, PrintWriter log
) {
211 // get a soffice factory object
212 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)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
);