bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _svtools / AccessibleBrowseBoxHeaderCell.java
blob4b29b8685cfb173c83769f5c777aaf99af8a31b7
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 com.sun.star.view.XSelectionSupplier;
22 import java.io.PrintWriter;
24 import lib.StatusException;
25 import lib.TestCase;
26 import lib.TestEnvironment;
27 import lib.TestParameters;
28 import util.AccessibilityTools;
29 import util.DesktopTools;
30 import util.SOfficeFactory;
32 import com.sun.star.accessibility.AccessibleRole;
33 import com.sun.star.accessibility.XAccessible;
34 import com.sun.star.awt.XWindow;
35 import com.sun.star.beans.PropertyValue;
36 import com.sun.star.frame.XController;
37 import com.sun.star.frame.XDesktop;
38 import com.sun.star.frame.XDispatch;
39 import com.sun.star.frame.XDispatchProvider;
40 import com.sun.star.frame.XFrame;
41 import com.sun.star.frame.XModel;
42 import com.sun.star.lang.XInitialization;
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;
49 /**
50 * Test for object that implements the following interfaces :
51 * <ul>
52 * <li>
53 * <code>::com::sun::star::accessibility::XAccessibleContext
54 * </code></li>
55 * <li>
56 * <code>::com::sun::star::accessibility::XAccessibleEventBroadcaster
57 * </code></li>
58 * </ul> <p>
60 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
61 * @see com.sun.star.accessibility.XAccessibleContext
62 * @see ifc.accessibility._XAccessibleEventBroadcaster
63 * @see ifc.accessibility._XAccessibleContext
65 public class AccessibleBrowseBoxHeaderCell extends TestCase {
67 static XDesktop the_Desk;
68 static XTextDocument xTextDoc;
70 /**
71 * Creates the Desktop service (<code>com.sun.star.frame.Desktop</code>).
73 protected void initialize(TestParameters Param, PrintWriter log) {
74 the_Desk = UnoRuntime.queryInterface(
75 XDesktop.class, DesktopTools.createDesktop((XMultiServiceFactory)Param.getMSF()));
78 /**
79 * Disposes the document, if exists, created in
80 * <code>createTestEnvironment</code> method.
82 protected void cleanup( TestParameters Param, PrintWriter log) {
84 log.println("disposing xTextDoc");
86 if (xTextDoc != null) {
87 xTextDoc.dispose();
91 /**
92 * Creates a text document. Opens the DataSource browser and loads
93 * the table. Creates an instance of the service
94 * <code>com.sun.star.awt.Toolkit</code> and gets active top window.
95 * Then obtains an accessible object with the role
96 * <code>AccessibleRole.UNKNOWN</code> and with the name
97 * <code>"Identifier"</code>.
98 * Object relations created :
99 * <ul>
100 * <li> <code>'EventProducer'</code> for
101 * {@link ifc.accessibility._XAccessibleEventBroadcaster}:
102 * method <code>fireEvent()</code> is empty because object is transient
103 * </li>
104 * </ul>
106 * @param tParam test parameters
107 * @param log writer to log information while testing
109 * @see com.sun.star.awt.Toolkit
110 * @see com.sun.star.accessibility.AccessibleRole
111 * @see ifc.accessibility._XAccessibleEventBroadcaster
112 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
114 protected TestEnvironment createTestEnvironment(
115 TestParameters tParam, PrintWriter log) {
117 log.println( "creating a test environment" );
119 if (xTextDoc != null) xTextDoc.dispose();
121 // get a soffice factory object
122 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF());
124 try {
125 log.println( "creating a text document" );
126 xTextDoc = SOF.createTextDoc(null);
127 } catch ( com.sun.star.uno.Exception e ) {
128 // Some exception occurs.FAILED
129 e.printStackTrace( log );
130 throw new StatusException( "Couldn't create document", e );
133 shortWait();
135 XModel aModel1 = UnoRuntime.queryInterface(XModel.class, xTextDoc);
137 XController secondController = aModel1.getCurrentController();
139 XDispatchProvider aProv = UnoRuntime.
140 queryInterface(XDispatchProvider.class, secondController);
142 XDispatch getting = null;
144 log.println( "opening DatasourceBrowser" );
145 URL the_url = new URL();
146 the_url.Complete = ".component:DB/DataSourceBrowser";
147 getting = aProv.queryDispatch(the_url, "_beamer", 12);
148 PropertyValue[] noArgs = new PropertyValue[0];
149 getting.dispatch(the_url, noArgs);
151 shortWait();
153 XFrame the_frame1 = the_Desk.getCurrentFrame();
155 if (the_frame1 == null) {
156 log.println("Current frame was not found !!!");
159 XFrame the_frame2 = the_frame1.findFrame("_beamer", 4);
161 the_frame2.setName("DatasourceBrowser");
163 XInterface oObj = null;
165 UnoRuntime.queryInterface(
166 XInitialization.class, the_frame2.getController());
168 PropertyValue[] params = new PropertyValue[3];
169 PropertyValue param1 = new PropertyValue();
170 param1.Name = "DataSourceName";
171 param1.Value = "Bibliography";
172 params[0] = param1;
173 PropertyValue param2 = new PropertyValue();
174 param2.Name = "CommandType";
175 param2.Value = new Integer(com.sun.star.sdb.CommandType.TABLE);
176 params[1] = param2;
177 PropertyValue param3 = new PropertyValue();
178 param3.Name = "Command";
179 param3.Value = "biblio";
180 params[2] = param3;
182 XController xCont = the_frame2.getController();
184 XSelectionSupplier xSelect = UnoRuntime.queryInterface(
185 XSelectionSupplier.class, xCont);
187 try {
188 xSelect.select(params);
189 } catch (com.sun.star.lang.IllegalArgumentException ex) {
190 throw new StatusException("Could not select Biblio-Database", ex);
193 AccessibilityTools at = new AccessibilityTools();
195 XWindow xWindow = secondController.getFrame().getContainerWindow();
197 XAccessible xRoot = AccessibilityTools.getAccessibleObject(xWindow);
199 AccessibilityTools.printAccessibleTree(log, xRoot, tParam.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
201 oObj = AccessibilityTools.getAccessibleObjectForRole(xRoot,
202 AccessibleRole.ROW_HEADER);
204 log.println("ImplementationName: "+ util.utils.getImplName(oObj));
206 TestEnvironment tEnv = new TestEnvironment(oObj);
208 tEnv.addObjRelation("EventProducer",
209 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer(){
210 public void fireEvent() {
214 return tEnv;
218 * Sleeps for 0.5 sec. to allow StarOffice to react on <code>
219 * reset</code> call.
221 private void shortWait() {
222 try {
223 Thread.sleep(5000);
224 } catch (InterruptedException e) {
225 System.out.println("While waiting :" + e) ;