tdf#130857 qt weld: Introduce QtInstanceScrolledWindow
[LibreOffice.git] / qadevOOo / tests / java / mod / _dbaccess / ODatasourceBrowser.java
blob1ccccf5329dcaaa4aca545f587dbf979be0cf9e0
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._dbaccess;
20 import java.io.PrintWriter;
22 import lib.TestCase;
23 import lib.TestEnvironment;
24 import lib.TestParameters;
25 import util.DesktopTools;
26 import util.FormTools;
27 import util.SOfficeFactory;
28 import util.WriterTools;
30 import com.sun.star.awt.XControl;
31 import com.sun.star.awt.XControlModel;
32 import com.sun.star.awt.XWindow;
33 import com.sun.star.beans.PropertyValue;
34 import com.sun.star.drawing.XControlShape;
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;
46 import com.sun.star.util.XCloseable;
47 import com.sun.star.view.XControlAccess;
50 /**
51 * Test for object which is represented by service
52 * <code>com.sun.star.sdb.DataSourceBrowser</code>. <p>
53 * Object implements the following interfaces :
54 * <ul>
55 * <li> <code>com::sun::star::container::XChild</code></li>
56 * <li> <code>com::sun::star::lang::XInitialization</code></li>
57 * <li> <code>com::sun::star::util::XModifyBroadcaster</code></li>
58 * <li> <code>com::sun::star::awt::XTabController</code></li>
59 * <li> <code>com::sun::star::form::XFormController</code></li>
60 * <li> <code>com::sun::star::container::XElementAccess</code></li>
61 * <li> <code>com::sun::star::frame::XDispatchProvider</code></li>
62 * <li> <code>com::sun::star::container::XEnumerationAccess</code></li>
63 * <li> <code>com::sun::star::frame::XController</code></li>
64 * <li> <code>com::sun::star::lang::XComponent</code></li>
65 * </ul> <p>
66 * This object test <b> is NOT </b> designed to be run in several
67 * threads concurrently.
69 * @see com.sun.star.container.XChild
70 * @see com.sun.star.lang.XInitialization
71 * @see com.sun.star.util.XModifyBroadcaster
72 * @see com.sun.star.awt.XTabController
73 * @see com.sun.star.form.XFormController
74 * @see com.sun.star.container.XElementAccess
75 * @see com.sun.star.frame.XDispatchProvider
76 * @see com.sun.star.container.XEnumerationAccess
77 * @see com.sun.star.frame.XController
78 * @see com.sun.star.lang.XComponent
79 * @see ifc.container._XChild
80 * @see ifc.lang._XInitialization
81 * @see ifc.util._XModifyBroadcaster
82 * @see ifc.awt._XTabController
83 * @see ifc.form._XFormController
84 * @see ifc.container._XElementAccess
85 * @see ifc.frame._XDispatchProvider
86 * @see ifc.container._XEnumerationAccess
87 * @see ifc.frame._XController
88 * @see ifc.lang._XComponent
90 public class ODatasourceBrowser extends TestCase {
91 XDesktop xDesktop;
92 XTextDocument xTextDoc;
94 /**
95 * Creates the Desktop service (<code>com.sun.star.frame.Desktop</code>).
97 @Override
98 protected void initialize(TestParameters Param, PrintWriter log) {
99 xDesktop = DesktopTools.createDesktop(Param.getMSF());
100 System.setProperty("hideMe", "false");
104 * Disposes the document, if exists, created in
105 * <code>createTestEnvironment</code> method.
107 @Override
108 protected void cleanup(TestParameters Param, PrintWriter log) {
109 log.println("disposing xTextDoc");
110 System.setProperty("hideMe", "true");
112 if (xTextDoc != null) {
113 log.println(" disposing xTextDoc ");
115 try {
116 XCloseable closer = UnoRuntime.queryInterface(
117 XCloseable.class, xTextDoc);
118 closer.close(true);
119 } catch (com.sun.star.util.CloseVetoException e) {
120 log.println("couldn't close document");
121 } catch (com.sun.star.lang.DisposedException e) {
122 log.println("couldn't close document");
128 * Creating a TestEnvironment for the interfaces to be tested.
130 * Creates a new text document disposing the old one if it was
131 * created. Using <code>Desktop</code> service get the frame
132 * of the document and with its help creates
133 * <code>DataSourceBrowser</code> dispatching the URL
134 * <code>'.component:DB/DataSourceBrowser'</code>. The
135 * component for testing is the controller of the
136 * <code>Browser</code> and it's got by searching its
137 * frame with the help of TextDocument frame, and obtaining
138 * the frame's controller. <p>
140 * <b>Note</b>: after creating the text document a short
141 * pause is needed to give a possibility to a frame to be
142 * created for the document. Else
143 * <code>Desktop.getCurrentFrame()</code> method can return
144 * <code>null</code> value. <p>
146 * Object relations created :
147 * <ul>
148 * <li> <code>'XDispatchProvider.URL'</code> for
149 * {@link ifc.frame._XDispatchProvider} </li>
150 * <li> <code>'SecondModel'</code> for
151 * {@link ifc.frame._XController} : the model of
152 * the TextDocument. </li>
153 * <li> <code>'otherWindow'</code> for
154 * {@link ifc.frame._XController} : the window of
155 * the added shape. </li>
156 * <li> <code>'SecondController'</code> for
157 * {@link ifc.frame._XController} : the controller of
158 * the TextDocument. </li>
159 * <li> <code>'HasViewData'</code> for
160 * {@link ifc.frame._XController} : the
161 * <code>DataSourceBrowser</code> has no view data. </li>
162 * <li> <code>'XInitialization.args'</code> for
163 * {@link ifc.lang._XInitialization} : the arguments for
164 * the initialization</li>
165 * </ul>
167 * @see com.sun.star.frame.Desktop
168 * @see com.sun.star.frame.XModel
169 * @see com.sun.star.frame.XFrame
170 * @see com.sun.star.frame.XController
171 * @see com.sun.star.frame.XDispatchProvider
173 @Override
174 protected TestEnvironment createTestEnvironment(TestParameters Param,
175 PrintWriter log) throws Exception {
176 log.println("creating a test environment");
178 if (xTextDoc != null) {
179 log.println(" disposing xTextDoc ");
181 try {
182 XCloseable closer = UnoRuntime.queryInterface(
183 XCloseable.class, xTextDoc);
184 closer.close(true);
185 } catch (com.sun.star.util.CloseVetoException e) {
186 log.println("couldn't close document");
187 } catch (com.sun.star.lang.DisposedException e) {
188 log.println("couldn't close document");
192 // get a soffice factory object
193 SOfficeFactory SOF = SOfficeFactory.getFactory(Param.getMSF());
195 log.println("creating a text document");
196 xTextDoc = SOF.createTextDoc(null);
198 util.utils.waitForEventIdle(Param.getMSF());
200 XModel aModel1 = UnoRuntime.queryInterface(XModel.class,
201 xTextDoc);
203 XController secondController = aModel1.getCurrentController();
205 XFrame the_frame1 = xDesktop.getCurrentFrame();
207 if (the_frame1 == null) {
208 log.println("Current frame was not found !!!");
211 XDispatchProvider aProv = UnoRuntime.queryInterface(
212 XDispatchProvider.class, the_frame1);
214 XDispatch getting = null;
216 log.println("opening DatasourceBrowser");
218 URL the_url = new URL();
219 the_url.Complete = ".component:DB/DataSourceBrowser";
220 getting = aProv.queryDispatch(the_url, "_beamer", 12);
222 PropertyValue[] noArgs = new PropertyValue[0];
223 getting.dispatch(the_url, noArgs);
225 XFrame the_frame2 = the_frame1.findFrame("_beamer", 4);
227 the_frame2.setName("DatasourceBrowser");
229 XInterface oObj = the_frame2.getController();
231 Object[] params = new Object[3];
232 PropertyValue param1 = new PropertyValue();
233 param1.Name = "DataSourceName";
234 param1.Value = "Bibliography";
235 params[0] = param1;
237 PropertyValue param2 = new PropertyValue();
238 param2.Name = "CommandType";
239 param2.Value = Integer.valueOf(com.sun.star.sdb.CommandType.TABLE);
240 params[1] = param2;
242 PropertyValue param3 = new PropertyValue();
243 param3.Name = "Command";
244 param3.Value = "biblio";
245 params[2] = param3;
247 XInitialization xInit = UnoRuntime.queryInterface(
248 XInitialization.class, oObj);
249 xInit.initialize(params);
251 util.utils.waitForEventIdle(Param.getMSF());
253 XControlShape aShape = FormTools.createControlShape(xTextDoc, 3000,
254 4500, 15000, 10000,
255 "CommandButton");
256 WriterTools.getDrawPage(xTextDoc).add(aShape);
258 XControlModel shapeModel = aShape.getControl();
260 XControlAccess xCtrlAccess = UnoRuntime.queryInterface(
261 XControlAccess.class,
262 secondController);
263 XControl xCtrl = null;
265 try {
266 xCtrl = xCtrlAccess.getControl(shapeModel);
267 } catch (com.sun.star.uno.Exception e) {
268 // Some exception occurs.FAILED
269 e.printStackTrace(log);
272 XWindow docWindow = UnoRuntime.queryInterface(XWindow.class,
273 xCtrl);
274 log.println("creating a new environment for ODatasourceBrowser object");
276 TestEnvironment tEnv = new TestEnvironment(oObj);
279 //Adding ObjRelations for XInitialization
280 tEnv.addObjRelation("XInitialization.args", params);
283 //Adding ObjRelations for XController
284 tEnv.addObjRelation("Frame", the_frame1);
285 tEnv.addObjRelation("SecondModel", aModel1);
286 tEnv.addObjRelation("otherWindow", docWindow);
287 tEnv.addObjRelation("SecondController", secondController);
288 tEnv.addObjRelation("HasViewData", Boolean.FALSE);
291 //Adding relation for XDispatchProvider
292 tEnv.addObjRelation("XDispatchProvider.URL",
293 ".uno:DataSourceBrowser/FormLetter");
295 return tEnv;
296 } // finish method getTestEnvironment
297 } // finish class oDatasourceBrowser