tdf#130857 qt weld: Introduce QtInstanceScrolledWindow
[LibreOffice.git] / qadevOOo / tests / java / mod / _dbaccess / TableWindowAccessibility.java
blob384edb85b47e506fb54280ae1848fd353524fbb8
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.Status;
23 import lib.StatusException;
24 import lib.TestCase;
25 import lib.TestEnvironment;
26 import lib.TestParameters;
27 import util.AccessibilityTools;
29 import com.sun.star.accessibility.AccessibleRole;
30 import com.sun.star.accessibility.XAccessible;
31 import com.sun.star.accessibility.XAccessibleComponent;
32 import com.sun.star.awt.Point;
33 import com.sun.star.awt.XWindow;
34 import com.sun.star.beans.PropertyValue;
35 import com.sun.star.beans.XPropertySet;
36 import com.sun.star.container.XNameAccess;
37 import com.sun.star.container.XNameContainer;
38 import com.sun.star.frame.XModel;
39 import com.sun.star.frame.XStorable;
40 import com.sun.star.lang.XComponent;
41 import com.sun.star.lang.XMultiServiceFactory;
42 import com.sun.star.sdb.XDocumentDataSource;
43 import com.sun.star.sdb.XQueryDefinitionsSupplier;
44 import com.sun.star.sdbc.XConnection;
45 import com.sun.star.sdbc.XIsolatedConnection;
46 import com.sun.star.sdbc.XStatement;
47 import com.sun.star.ucb.XSimpleFileAccess;
48 import com.sun.star.uno.UnoRuntime;
49 import com.sun.star.uno.XInterface;
50 import java.awt.Robot;
51 import java.awt.event.InputEvent;
52 import util.DesktopTools;
53 import util.utils;
55 /**
56 * Object implements the following interfaces :
57 * <ul>
58 * <li><code>::com::sun::star::accessibility::XAccessible</code></li>
59 * <li><code>::com::sun::star::accessibility::XAccessibleContext
60 * </code></li>
61 * <li><code>::com::sun::star::accessibility::XAccessibleEventBroadcaster
62 * </code></li>
63 * </ul>
64 * <p>
66 * @see com.sun.star.accessibility.XAccessible
67 * @see com.sun.star.accessibility.XAccessibleContext
68 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
69 * @see ifc.accessibility._XAccessible
70 * @see ifc.accessibility._XAccessibleContext
71 * @see ifc.accessibility._XAccessibleEventBroadcaster
73 public class TableWindowAccessibility extends TestCase {
74 XWindow xWindow = null;
75 String aFile = "";
76 XIsolatedConnection isolConnection = null;
77 XComponent QueryComponent = null;
78 String user = "";
79 String password = "";
81 /**
82 * Creates a new DataSource and stores it. Creates a connection and using it
83 * creates two tables in database. Creates a new query and adds it to
84 * DefinitionContainer. Opens the QueryComponent.with loadComponentFromURL
85 * and gets the object with the role PANEL and the implementation name that
86 * contains TabelViewAccessibility
88 * @param Param
89 * test parameters
90 * @param log
91 * writer to log information while testing
92 * @return
93 * @throws StatusException
94 * @see TestEnvironment
96 @Override
97 protected TestEnvironment createTestEnvironment(TestParameters Param,
98 PrintWriter log) throws Exception {
99 XInterface oObj = null;
101 Param.getMSF().createInstance("com.sun.star.sdb.DatabaseContext");
102 Object oDBSource = Param.getMSF()
103 .createInstance("com.sun.star.sdb.DataSource");
104 Object newQuery = Param.getMSF().createInstance(
105 "com.sun.star.sdb.QueryDefinition");
106 Param.getMSF().createInstance("com.sun.star.awt.Toolkit");
108 String mysqlURL = (String) Param.get("mysql.url");
110 if (mysqlURL == null) {
111 throw new StatusException(
112 Status.failed("Couldn't get 'mysql.url' from ini-file"));
115 user = (String) Param.get("jdbc.user");
116 password = (String) Param.get("jdbc.password");
118 if ((user == null) || (password == null)) {
119 throw new StatusException(
120 Status.failed("Couldn't get 'jdbc.user' or 'jdbc.password' from ini-file"));
123 PropertyValue[] info = new PropertyValue[2];
124 info[0] = new PropertyValue();
125 info[0].Name = "user";
126 info[0].Value = user;
127 info[1] = new PropertyValue();
128 info[1].Name = "password";
129 info[1].Value = password;
131 XPropertySet propSetDBSource = UnoRuntime.queryInterface(
132 XPropertySet.class, oDBSource);
134 propSetDBSource.setPropertyValue("URL", mysqlURL);
135 propSetDBSource.setPropertyValue("Info", info);
137 log.println("writing database file ...");
138 XDocumentDataSource xDDS = UnoRuntime.queryInterface(
139 XDocumentDataSource.class, oDBSource);
140 XStorable store = UnoRuntime.queryInterface(XStorable.class,
141 xDDS.getDatabaseDocument());
142 aFile = utils.getOfficeTemp(Param.getMSF()) + "TableWindow.odb";
143 log.println("... filename will be " + aFile);
144 store.storeAsURL(aFile, new PropertyValue[] {});
145 log.println("... done");
147 isolConnection = UnoRuntime.queryInterface(XIsolatedConnection.class,
148 oDBSource);
150 final String tbl_name1 = "tst_table1";
151 final String tbl_name2 = "tst_table2";
152 final String col_name1 = "id1";
153 final String col_name2 = "id2";
155 util.utils.waitForEventIdle(Param.getMSF());
156 XConnection connection = isolConnection.getIsolatedConnection(user, password);
157 XStatement statement = connection.createStatement();
158 statement.executeUpdate("drop table if exists " + tbl_name1);
159 statement.executeUpdate("drop table if exists " + tbl_name2);
160 statement.executeUpdate("create table " + tbl_name1 + " ("
161 + col_name1 + " int)");
162 statement.executeUpdate("create table " + tbl_name2 + " ("
163 + col_name2 + " int)");
165 XQueryDefinitionsSupplier querySuppl = UnoRuntime.queryInterface(
166 XQueryDefinitionsSupplier.class, oDBSource);
168 XNameAccess defContainer = querySuppl.getQueryDefinitions();
170 XPropertySet queryProp = UnoRuntime.queryInterface(XPropertySet.class,
171 newQuery);
173 final String query = "select * from " + tbl_name1 + ", " + tbl_name2
174 + " where " + tbl_name1 + "." + col_name1 + "=" + tbl_name2
175 + "." + col_name2;
176 queryProp.setPropertyValue("Command", query);
178 XNameContainer queryContainer = UnoRuntime.queryInterface(
179 XNameContainer.class, defContainer);
181 queryContainer.insertByName("Query1", newQuery);
182 store.store();
183 connection.close();
185 PropertyValue[] loadProps = new PropertyValue[3];
186 loadProps[0] = new PropertyValue();
187 loadProps[0].Name = "QueryDesignView";
188 loadProps[0].Value = Boolean.TRUE;
190 loadProps[1] = new PropertyValue();
191 loadProps[1].Name = "CurrentQuery";
192 loadProps[1].Value = "Query1";
194 loadProps[2] = new PropertyValue();
195 loadProps[2].Name = "DataSource";
196 loadProps[2].Value = oDBSource;
198 QueryComponent = DesktopTools.loadDoc(Param.getMSF(),
199 ".component:DB/QueryDesign", loadProps);
201 xWindow = UnoRuntime.queryInterface(XModel.class, QueryComponent)
202 .getCurrentController().getFrame().getContainerWindow();
204 XAccessible xRoot = AccessibilityTools.getAccessibleObject(xWindow);
206 AccessibilityTools.printAccessibleTree(log, xRoot,
207 Param.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
209 oObj = AccessibilityTools.getAccessibleObjectForRole(xRoot,
210 AccessibleRole.PANEL, "", "TableWindowAccessibility");
212 log.println("ImplementationName " + util.utils.getImplName(oObj));
214 log.println("creating TestEnvironment ... done");
216 TestEnvironment tEnv = new TestEnvironment(oObj);
218 util.utils.waitForEventIdle(Param.getMSF());
220 XAccessibleComponent accComp = UnoRuntime.queryInterface(
221 XAccessibleComponent.class, oObj);
223 final Point point = accComp.getLocationOnScreen();
225 tEnv.addObjRelation(
226 "EventProducer",
227 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
228 public void fireEvent() {
229 try {
230 Robot rob = new Robot();
231 rob.mouseMove(point.X + 2, point.Y + 7);
232 rob.mousePress(InputEvent.BUTTON1_MASK);
233 rob.mouseMove(point.X + 400, point.Y);
234 rob.mouseRelease(InputEvent.BUTTON1_MASK);
235 } catch (java.awt.AWTException e) {
236 System.out.println("desired child doesn't exist");
241 return tEnv;
242 } // finish method getTestEnvironment
245 * Closes all open documents.
247 @Override
248 protected void cleanup(TestParameters Param, PrintWriter log) {
249 try {
251 log.println("closing QueryComponent ...");
252 DesktopTools.closeDoc(QueryComponent);
253 log.println("... done");
254 XMultiServiceFactory xMSF = Param.getMSF();
255 Object sfa = xMSF
256 .createInstance("com.sun.star.comp.ucb.SimpleFileAccess");
257 XSimpleFileAccess xSFA = UnoRuntime.queryInterface(
258 XSimpleFileAccess.class, sfa);
259 log.println("deleting database file");
260 xSFA.kill(aFile);
261 log.println("Could delete file " + aFile + ": "
262 + !xSFA.exists(aFile));
263 } catch (Exception e) {
264 e.printStackTrace();