Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / mod / _svtools / AccessibleBrowseBox.java
blobbc34cc9c0f86ee74861e929564a9cea4d3e5c686
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 java.io.PrintWriter;
22 import lib.StatusException;
23 import lib.TestCase;
24 import lib.TestEnvironment;
25 import lib.TestParameters;
26 import util.AccessibilityTools;
27 import util.DesktopTools;
28 import util.SOfficeFactory;
30 import com.sun.star.accessibility.AccessibleRole;
31 import com.sun.star.accessibility.XAccessible;
32 import com.sun.star.awt.XWindow;
33 import com.sun.star.beans.PropertyValue;
34 import com.sun.star.frame.XController;
35 import com.sun.star.frame.XDesktop;
36 import com.sun.star.frame.XDispatch;
37 import com.sun.star.frame.XDispatchProvider;
38 import com.sun.star.frame.XFrame;
39 import com.sun.star.frame.XModel;
40 import com.sun.star.text.XTextDocument;
41 import com.sun.star.uno.UnoRuntime;
42 import com.sun.star.uno.XInterface;
43 import com.sun.star.util.URL;
44 import com.sun.star.view.XSelectionSupplier;
46 public class AccessibleBrowseBox extends TestCase {
48 static XDesktop the_Desk;
49 static XTextDocument xTextDoc;
51 /**
52 * Creates the Desktop service (<code>com.sun.star.frame.Desktop</code>).
54 @Override
55 protected void initialize(TestParameters Param, PrintWriter log) {
56 the_Desk = UnoRuntime.queryInterface(
57 XDesktop.class, DesktopTools.createDesktop(Param.getMSF()));
60 /**
61 * Disposes the document, if exists, created in
62 * <code>createTestEnvironment</code> method.
64 @Override
65 protected void cleanup(TestParameters Param, PrintWriter log) {
67 log.println("disposing xTextDoc");
69 if (xTextDoc != null) {
70 xTextDoc.dispose();
74 /**
75 * Called to create an instance of <code>TestEnvironment</code> with an
76 * object to test and related objects. Subclasses should implement this
77 * method to provide the implementation and related objects. The method is
78 * called from <code>getTestEnvironment()</code>.
80 * @param tParam test parameters
81 * @param log writer to log information while testing
83 * @see TestEnvironment
84 * @see #getTestEnvironment
86 @Override
87 protected TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) {
89 log.println("creating a test environment");
91 if (xTextDoc != null) {
92 xTextDoc.dispose(); // get a soffice factory object
94 SOfficeFactory SOF = SOfficeFactory.getFactory(tParam.getMSF());
96 try {
97 log.println("creating a text document");
98 xTextDoc = SOF.createTextDoc(null);
99 } catch (com.sun.star.uno.Exception e) {
100 // Some exception occurs.FAILED
101 e.printStackTrace(log);
102 throw new StatusException("Couldn't create document", e);
105 util.utils.pause(5000);
107 XModel aModel1 = UnoRuntime.queryInterface(XModel.class, xTextDoc);
109 XController secondController = aModel1.getCurrentController();
112 XDispatchProvider aProv = UnoRuntime.queryInterface(XDispatchProvider.class,
113 secondController);
115 XDispatch getting = null;
117 log.println("opening DatasourceBrowser");
118 URL the_url = new URL();
119 the_url.Complete = ".component:DB/DataSourceBrowser";
120 getting = aProv.queryDispatch(the_url, "_beamer", 12);
121 PropertyValue[] noArgs = new PropertyValue[0];
122 getting.dispatch(the_url, noArgs);
124 util.utils.pause(5000);
126 XFrame the_frame1 = the_Desk.getCurrentFrame();
128 if (the_frame1 == null) {
129 log.println("Current frame was not found !!!");
132 XFrame the_frame2 = the_frame1.findFrame("_beamer", 4);
134 the_frame2.setName("DatasourceBrowser");
136 XInterface oObj = null;
138 final XSelectionSupplier xSelect = UnoRuntime.queryInterface(
139 XSelectionSupplier.class, the_frame2.getController());
141 PropertyValue[] params = new PropertyValue[]{new PropertyValue(), new PropertyValue(), new PropertyValue()};
142 params[0].Name = "DataSourceName";
143 params[0].Value = "Bibliography";
144 params[1].Name = "CommandType";
145 params[1].Value = Integer.valueOf(com.sun.star.sdb.CommandType.TABLE);
146 params[2].Name = "Command";
147 params[2].Value = "biblio";
149 final PropertyValue[] fParams = params;
151 util.utils.pause(5000);
153 XWindow xWindow = secondController.getFrame().getContainerWindow();
155 XAccessible xRoot = AccessibilityTools.getAccessibleObject(xWindow);
157 AccessibilityTools.printAccessibleTree(log, xRoot, tParam.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
159 oObj = AccessibilityTools.getAccessibleObjectForRole(xRoot, AccessibleRole.PANEL, "", "AccessibleBrowseBox");
161 log.println("ImplementationName: " + util.utils.getImplName(oObj));
163 TestEnvironment tEnv = new TestEnvironment(oObj);
166 tEnv.addObjRelation("EventProducer",
167 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
169 public void fireEvent() {
170 try {
171 xSelect.select(fParams);
172 } catch (com.sun.star.lang.IllegalArgumentException e) {
173 e.printStackTrace();
178 return tEnv;