Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / mod / _svtools / AccessibleTreeListBox.java
blob40fe66ad8e7199084a48e30beedc66390224eafc
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.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.lang.XInitialization;
42 import com.sun.star.text.XTextDocument;
43 import com.sun.star.uno.UnoRuntime;
44 import com.sun.star.uno.XInterface;
45 import com.sun.star.util.URL;
47 /**
48 * Test for object that implements the following interfaces :
49 * <ul>
50 * <li><code>::com::sun::star::accessibility::XAccessibleComponent
51 * </code></li>
52 * <li><code>::com::sun::star::accessibility::XAccessibleEventBroadcaster
53 * </code></li>
54 * <li><code>::com::sun::star::accessibility::XAccessibleContext
55 * </code></li>
56 * <li><code>::com::sun::star::accessibility::XAccessibleSelection
57 * </code></li>
58 * </ul> <p>
60 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
61 * @see com.sun.star.accessibility.XAccessibleContext
62 * @see com.sun.star.accessibility.XAccessibleComponent
63 * @see com.sun.star.accessibility.XAccessibleSelection
64 * @see ifc.accessibility._XAccessibleEventBroadcaster
65 * @see ifc.accessibility._XAccessibleContext
66 * @see ifc.accessibility._XAccessibleComponent
67 * @see ifc.accessibility._XAccessibleSelection
69 public class AccessibleTreeListBox extends TestCase {
71 static XDesktop the_Desk;
72 static XTextDocument xTextDoc;
74 /**
75 * Creates the Desktop service (<code>com.sun.star.frame.Desktop</code>).
77 @Override
78 protected void initialize(TestParameters Param, PrintWriter log) {
79 the_Desk = UnoRuntime.queryInterface(
80 XDesktop.class, DesktopTools.createDesktop(Param.getMSF()));
83 /**
84 * Disposes the document, if exists, created in
85 * <code>createTestEnvironment</code> method.
87 @Override
88 protected void cleanup( TestParameters Param, PrintWriter log) {
90 log.println("disposing xTextDoc");
92 if (xTextDoc != null) {
93 xTextDoc.dispose();
97 /**
98 * Creates a text document. Opens the DataSource browser.
99 * Creates an instance of the service <code>com.sun.star.awt.Toolkit</code>
100 * and gets active top window. Then obtains an accessible object with
101 * the role <code>AccessibleRole.TREE</code>.
102 * Object relations created :
103 * <ul>
104 * <li> <code>'EventProducer'</code> for
105 * {@link ifc.accessibility._XAccessibleEventBroadcaster}:
106 * </li>
107 * <li> <code>'XAccessibleSelection.multiSelection'</code>
108 * of type <code>Boolean</code> for
109 * {@link ifc.accessibility._XAccessibleSelection}:
110 * indicates that component supports single selection mode.</li>
111 * </ul>
113 * @param tParam test parameters
114 * @param log writer to log information while testing
116 * @see com.sun.star.awt.Toolkit
117 * @see com.sun.star.accessibility.AccessibleRole
118 * @see ifc.accessibility._XAccessibleEventBroadcaster
119 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
121 @Override
122 protected TestEnvironment createTestEnvironment(
123 TestParameters tParam, PrintWriter log) {
125 log.println( "creating a test environment" );
127 if (xTextDoc != null) xTextDoc.dispose();
129 // get a soffice factory object
130 SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF());
132 try {
133 log.println( "creating a text document" );
134 xTextDoc = SOF.createTextDoc(null);
135 } catch ( com.sun.star.uno.Exception e ) {
136 // Some exception occurs.FAILED
137 e.printStackTrace( log );
138 throw new StatusException( "Couldn't create document", e );
141 util.utils.pause(5000);
143 XModel aModel1 = UnoRuntime.queryInterface(XModel.class, xTextDoc);
145 XController secondController = aModel1.getCurrentController();
147 XDispatchProvider aProv = UnoRuntime.
148 queryInterface(XDispatchProvider.class, secondController);
150 XDispatch getting = null;
152 log.println( "opening DatasourceBrowser" );
153 URL the_url = new URL();
154 the_url.Complete = ".component:DB/DataSourceBrowser";
155 getting = aProv.queryDispatch(the_url, "_beamer", 12);
156 PropertyValue[] noArgs = new PropertyValue[0];
157 getting.dispatch(the_url, noArgs);
159 util.utils.pause(5000);
161 XFrame the_frame1 = the_Desk.getCurrentFrame();
163 if (the_frame1 == null) {
164 log.println("Current frame was not found !!!");
167 XFrame the_frame2 = the_frame1.findFrame("_beamer", 4);
169 the_frame2.setName("DatasourceBrowser");
171 XInterface oObj = null;
173 XWindow xWindow = secondController.getFrame().getContainerWindow();
175 XAccessible xRoot = AccessibilityTools.getAccessibleObject(xWindow);
177 oObj = AccessibilityTools.getAccessibleObjectForRole(xRoot, AccessibleRole.TREE);
179 log.println("ImplementationName: "+ util.utils.getImplName(oObj));
181 TestEnvironment tEnv = new TestEnvironment(oObj);
183 final XInitialization xInit = UnoRuntime.queryInterface(
184 XInitialization.class, the_frame2.getController());
186 Object[] params = new Object[3];
187 PropertyValue param1 = new PropertyValue();
188 param1.Name = "DataSourceName";
189 param1.Value = "Bibliography";
190 params[0] = param1;
191 PropertyValue param2 = new PropertyValue();
192 param2.Name = "CommandType";
193 param2.Value = Integer.valueOf(com.sun.star.sdb.CommandType.TABLE);
194 params[1] = param2;
195 PropertyValue param3 = new PropertyValue();
196 param3.Name = "Command";
197 param3.Value = "biblio";
198 params[2] = param3;
200 final Object[] fParams = params;
202 tEnv.addObjRelation("EventProducer",
203 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer(){
204 public void fireEvent() {
205 try {
206 xInit.initialize(fParams);
207 } catch(com.sun.star.uno.Exception e) {
208 e.printStackTrace();
213 tEnv.addObjRelation("XAccessibleSelection.multiSelection",
214 Boolean.FALSE);
216 return tEnv;