bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _svtools / AccessibleIconChoiceCtrlEntry.java
blob9936a9de0477ec35d2394c7dd3296784fd93f90a
1 /*
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 .
19 package mod._svtools;
21 import java.io.PrintWriter;
23 import lib.StatusException;
24 import lib.TestCase;
25 import lib.TestEnvironment;
26 import lib.TestParameters;
27 import util.AccessibilityTools;
28 import util.DesktopTools;
29 import util.SOfficeFactory;
31 import com.sun.star.accessibility.AccessibleRole;
32 import com.sun.star.accessibility.XAccessible;
33 import com.sun.star.accessibility.XAccessibleAction;
34 import com.sun.star.accessibility.XAccessibleContext;
35 import com.sun.star.awt.XExtendedToolkit;
36 import com.sun.star.awt.XWindow;
37 import com.sun.star.beans.PropertyValue;
38 import com.sun.star.frame.XController;
39 import com.sun.star.frame.XDesktop;
40 import com.sun.star.frame.XDispatch;
41 import com.sun.star.frame.XDispatchProvider;
42 import com.sun.star.frame.XModel;
43 import com.sun.star.lang.XMultiServiceFactory;
44 import com.sun.star.text.XTextDocument;
45 import com.sun.star.uno.UnoRuntime;
46 import com.sun.star.uno.XInterface;
47 import com.sun.star.util.URL;
48 import com.sun.star.util.XURLTransformer;
50 /**
51 * Test for object that implements the following interfaces :
52 * <ul>
53 * <li><code>
54 * ::com::sun::star::accessibility::XAccessibleContext</code></li>
55 * <li><code>
56 * ::com::sun::star::accessibility::XAccessibleEventBroadcaster
57 * </code></li>
58 * <li><code>
59 * ::com::sun::star::accessibility::XAccessibleComponent</code></li>
60 * <li><code>
61 * ::com::sun::star::accessibility::XAccessibleText</code></li>
62 * </ul> <p>
64 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
65 * @see com.sun.star.accessibility.XAccessibleContext
66 * @see com.sun.star.accessibility.XAccessibleComponent
67 * @see com.sun.star.accessibility.XAccessibleText
68 * @see ifc.accessibility._XAccessibleEventBroadcaster
69 * @see ifc.accessibility._XAccessibleContext
70 * @see ifc.accessibility._XAccessibleComponent
71 * @see ifc.accessibility._XAccessibleText
73 public class AccessibleIconChoiceCtrlEntry extends TestCase {
75 static XDesktop the_Desk;
76 static XTextDocument xTextDoc;
77 static XAccessibleAction accCloseButton = null;
79 /**
80 * Creates the Desktop service (<code>com.sun.star.frame.Desktop</code>).
82 protected void initialize(TestParameters Param, PrintWriter log) {
83 the_Desk = UnoRuntime.queryInterface(
84 XDesktop.class, DesktopTools.createDesktop((XMultiServiceFactory)Param.getMSF()));
87 /**
88 * Closes the Hyperlink dialog.
89 * Disposes the document, if exists, created in
90 * <code>createTestEnvironment</code> method.
92 protected void cleanup( TestParameters Param, PrintWriter log) {
94 log.println("closing HyperlinkDialog");
96 try {
97 if (accCloseButton != null) {
98 accCloseButton.doAccessibleAction(0);
100 } catch(com.sun.star.lang.IndexOutOfBoundsException e) {
101 e.printStackTrace(log);
104 log.println("disposing xTextDoc");
106 if (xTextDoc != null) {
107 xTextDoc.dispose();
112 * Creates a text document. Opens the Hyperlink dialog.
113 * Creates an instance of the service
114 * <code>com.sun.star.awt.Toolkit</code> and gets active top window.
115 * Then obtains an accessible object with the role
116 * <code>AccessibleRole.LABEL</code> and with the name
117 * <code>"Internet"</code>.
118 * Object relations created :
119 * <ul>
120 * <li> <code>'EventProducer'</code> for
121 * {@link ifc.accessibility._XAccessibleEventBroadcaster}:
122 * method <code>fireEvent()</code> is empty because object is transient
123 * </li>
124 * <li> <code>'XAccessibleText.Text'</code> for
125 * {@link ifc.accessibility._XAccessibleText}:
126 * the string representation of the item text
127 * </li>
128 * </ul>
130 * @param tParam test parameters
131 * @param log writer to log information while testing
133 * @see com.sun.star.awt.Toolkit
134 * @see com.sun.star.accessibility.AccessibleRole
135 * @see ifc.accessibility._XAccessibleEventBroadcaster
136 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
138 protected TestEnvironment createTestEnvironment(
139 TestParameters tParam, PrintWriter log) {
141 log.println( "creating a test environment" );
143 if (xTextDoc != null) xTextDoc.dispose();
145 // get a soffice factory object
146 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF());
148 try {
149 log.println( "creating a text document" );
150 xTextDoc = SOF.createTextDoc(null);
151 } catch ( com.sun.star.uno.Exception e ) {
152 // Some exception occurs.FAILED
153 e.printStackTrace( log );
154 throw new StatusException( "Couldn't create document", e );
157 shortWait();
159 XModel aModel1 = UnoRuntime.queryInterface(XModel.class, xTextDoc);
161 XController secondController = aModel1.getCurrentController();
163 XDispatchProvider aProv = UnoRuntime.
164 queryInterface(XDispatchProvider.class, secondController);
166 XURLTransformer urlTransf = null;
168 try {
169 XInterface transf = (XInterface)((XMultiServiceFactory)tParam.getMSF()).createInstance
170 ("com.sun.star.util.URLTransformer");
171 urlTransf = UnoRuntime.queryInterface
172 (XURLTransformer.class, transf);
173 } catch (com.sun.star.uno.Exception e) {
174 e.printStackTrace(log);
175 throw new StatusException("Couldn't create URLTransformer", e );
178 XDispatch getting = null;
179 log.println( "opening HyperlinkDialog" );
180 URL[] url = new URL[1];
181 url[0] = new URL();
182 url[0].Complete = ".uno:HyperlinkDialog";
183 urlTransf.parseStrict(url);
184 getting = aProv.queryDispatch(url[0], "", 0);
185 PropertyValue[] noArgs = new PropertyValue[0];
186 getting.dispatch(url[0], noArgs);
188 shortWait();
190 XInterface oObj = null;
191 try {
192 oObj = (XInterface) ((XMultiServiceFactory)tParam.getMSF()).createInstance
193 ("com.sun.star.awt.Toolkit") ;
194 } catch (com.sun.star.uno.Exception e) {
195 log.println("Couldn't get toolkit");
196 e.printStackTrace(log);
197 throw new StatusException("Couldn't get toolkit", e );
200 XExtendedToolkit tk = UnoRuntime.queryInterface(XExtendedToolkit.class, oObj);
202 AccessibilityTools at = new AccessibilityTools();
204 shortWait();
206 XWindow xWindow = UnoRuntime.queryInterface(XWindow.class, tk.getActiveTopWindow());
208 XAccessible xRoot = AccessibilityTools.getAccessibleObject(xWindow);
210 oObj = AccessibilityTools.getAccessibleObjectForRole(xRoot,
211 AccessibleRole.LABEL, "Internet");
213 XAccessibleContext closeButton = AccessibilityTools.getAccessibleObjectForRole(xRoot,
214 AccessibleRole.PUSH_BUTTON, "Close");
216 accCloseButton = UnoRuntime.queryInterface(XAccessibleAction.class, closeButton);
218 log.println("ImplementationName: "+ util.utils.getImplName(oObj));
220 TestEnvironment tEnv = new TestEnvironment(oObj);
222 tEnv.addObjRelation("EventProducer",
223 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer(){
224 public void fireEvent() {
228 tEnv.addObjRelation("XAccessibleText.Text", "Internet");
230 tEnv.addObjRelation("EditOnly",
231 "This method isn't supported in this dialog");
233 tEnv.addObjRelation("LimitedBounds",
234 "only delivers senseful values for getCharacterBounds(0,length-1)");
236 return tEnv;
240 * Sleeps for 0.5 sec. to allow StarOffice to react on <code>
241 * reset</code> call.
243 private void shortWait() {
244 try {
245 Thread.sleep(5000);
246 } catch (InterruptedException e) {
247 System.out.println("While waiting :" + e) ;