bump product version to 5.0.4.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _svtools / AccessibleBrowseBoxTable.java
blob6cf139093d5369182ef11080344cf6d064dc8ef1
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 .
18 package mod._svtools;
20 import com.sun.star.view.XSelectionSupplier;
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.awt.XWindow;
34 import com.sun.star.beans.PropertyValue;
35 import com.sun.star.frame.XController;
36 import com.sun.star.frame.XDesktop;
37 import com.sun.star.frame.XDispatch;
38 import com.sun.star.frame.XDispatchProvider;
39 import com.sun.star.frame.XFrame;
40 import com.sun.star.frame.XModel;
41 import com.sun.star.text.XTextDocument;
42 import com.sun.star.uno.UnoRuntime;
43 import com.sun.star.uno.XInterface;
44 import com.sun.star.util.URL;
47 /**
48 * Test for object that implements the following interfaces :
49 * <ul>
50 * <li>
51 * <code>::com::sun::star::accessibility::XAccessibleContext
52 * </code></li>
53 * <li>
54 * <code>::com::sun::star::accessibility::XAccessibleEventBroadcaster
55 * </code></li>
56 * </ul> <p>
58 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
59 * @see com.sun.star.accessibility.XAccessibleContext
60 * @see ifc.accessibility._XAccessibleEventBroadcaster
61 * @see ifc.accessibility._XAccessibleContext
63 public class AccessibleBrowseBoxTable extends TestCase {
64 static XDesktop the_Desk;
65 static XTextDocument xTextDoc;
67 /**
68 * Creates the Desktop service (<code>com.sun.star.frame.Desktop</code>).
70 @Override
71 protected void initialize(TestParameters Param, PrintWriter log) {
72 the_Desk = UnoRuntime.queryInterface(XDesktop.class,
73 DesktopTools.createDesktop(
74 Param.getMSF()));
77 /**
78 * Disposes the document, if exists, created in
79 * <code>createTestEnvironment</code> method.
81 @Override
82 protected void cleanup(TestParameters Param, PrintWriter log) {
83 log.println("disposing xTextDoc");
85 if (xTextDoc != null) {
86 xTextDoc.dispose();
90 /**
91 * Creates a text document. Opens the DataSource browser.
92 * Creates an instance of the service
93 * <code>com.sun.star.awt.Toolkit</code> and gets active top window.
94 * Then obtains an accessible object with the role
95 * <code>AccessibleRole.TABLE</code> and with the name
96 * <code>"Table"</code>.
97 * Object relations created :
98 * <ul>
99 * <li> <code>'EventProducer'</code> for
100 * {@link ifc.accessibility._XAccessibleEventBroadcaster}:
101 * method <code>fireEvent()</code> is empty because object is transient
102 * </li>
103 * </ul>
105 * @param tParam test parameters
106 * @param log writer to log information while testing
108 * @see com.sun.star.awt.Toolkit
109 * @see com.sun.star.accessibility.AccessibleRole
110 * @see ifc.accessibility._XAccessibleEventBroadcaster
111 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
113 @Override
114 protected TestEnvironment createTestEnvironment(TestParameters tParam,
115 PrintWriter log) {
116 log.println("creating a test environment");
118 if (xTextDoc != null) {
119 xTextDoc.dispose();
122 // get a soffice factory object
123 SOfficeFactory SOF = SOfficeFactory.getFactory(
124 tParam.getMSF());
126 try {
127 log.println("creating a text document");
128 xTextDoc = SOF.createTextDoc(null);
129 } catch (com.sun.star.uno.Exception e) {
130 // Some exception occurs.FAILED
131 e.printStackTrace(log);
132 throw new StatusException("Couldn't create document", e);
135 util.utils.pause(5000);
137 XModel aModel1 = UnoRuntime.queryInterface(XModel.class,
138 xTextDoc);
140 XController secondController = aModel1.getCurrentController();
142 XDispatchProvider aProv = UnoRuntime.queryInterface(
143 XDispatchProvider.class,
144 secondController);
146 XDispatch getting = null;
148 log.println("opening DatasourceBrowser");
150 URL the_url = new URL();
151 the_url.Complete = ".component:DB/DataSourceBrowser";
152 getting = aProv.queryDispatch(the_url, "_beamer", 12);
154 PropertyValue[] noArgs = new PropertyValue[0];
155 getting.dispatch(the_url, noArgs);
157 util.utils.pause(5000);
159 XFrame the_frame1 = the_Desk.getCurrentFrame();
161 if (the_frame1 == null) {
162 log.println("Current frame was not found !!!");
165 XFrame the_frame2 = the_frame1.findFrame("_beamer", 4);
166 XController xCont = the_frame2.getController();
168 the_frame2.setName("DatasourceBrowser");
170 final PropertyValue[] params = new PropertyValue[3];
171 PropertyValue param1 = new PropertyValue();
172 param1.Name = "DataSourceName";
173 param1.Value = "Bibliography";
174 params[0] = param1;
176 PropertyValue param2 = new PropertyValue();
177 param2.Name = "CommandType";
178 param2.Value = Integer.valueOf(com.sun.star.sdb.CommandType.TABLE);
179 params[1] = param2;
181 PropertyValue param3 = new PropertyValue();
182 param3.Name = "Command";
183 param3.Value = "biblio";
184 params[2] = param3;
186 final XSelectionSupplier xSelect = UnoRuntime.queryInterface(
187 XSelectionSupplier.class, xCont);
190 XInterface oObj = null;
192 XWindow xWindow = secondController.getFrame().getContainerWindow();
194 XAccessible xRoot = AccessibilityTools.getAccessibleObject(xWindow);
196 oObj = AccessibilityTools.getAccessibleObjectForRole(xRoot, AccessibleRole.TABLE,
197 "Table");
199 log.println("ImplementationName: " + util.utils.getImplName(oObj));
201 TestEnvironment tEnv = new TestEnvironment(oObj);
203 tEnv.addObjRelation("EventProducer",
204 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
205 public void fireEvent() {
206 try {
207 xSelect.select(params);
208 } catch (com.sun.star.lang.IllegalArgumentException ex) {
213 return tEnv;