tdf#130857 qt weld: Introduce QtInstanceScrolledWindow
[LibreOffice.git] / qadevOOo / tests / java / mod / _dbaccess / ConnectionLineAccessibility.java
blob3cded65a1dc62735acddf7874dd6c556096aaef0
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.awt.PosSize;
32 import com.sun.star.awt.Rectangle;
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 util.DesktopTools;
51 import util.utils;
54 /**
55 * Object implements the following interfaces :
56 * <ul>
57 * <li><code>::com::sun::star::accessibility::XAccessible</code></li>
58 * <li><code>::com::sun::star::accessibility::XAccessibleContext
59 * </code></li>
60 * <li><code>::com::sun::star::accessibility::XAccessibleEventBroadcaster
61 * </code></li>
62 * </ul><p>
63 * @see com.sun.star.accessibility.XAccessible
64 * @see com.sun.star.accessibility.XAccessibleContext
65 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
66 * @see ifc.accessibility._XAccessible
67 * @see ifc.accessibility._XAccessibleContext
68 * @see ifc.accessibility._XAccessibleEventBroadcaster
70 public class ConnectionLineAccessibility extends TestCase
72 XWindow xWindow = null;
73 String aFile = "";
74 XIsolatedConnection isolConnection = null;
75 XComponent QueryComponent = null;
76 String user = "";
77 String password="";
79 /**
80 * Creates a new DataSource and stores it.
81 * Creates a connection and using it
82 * creates two tables in database.
83 * Creates a new query and adds it to DefinitionContainer.
84 * Opens the QueryComponent.with loadComponentFromURL
85 * and gets the object with the role UNKNOWN and the implementation
86 * name that contains ConnectionLine
87 * @param Param test parameters
88 * @param log writer to log information while testing
89 * @return
90 * @throws StatusException
91 * @see TestEnvironment
93 @Override
94 protected TestEnvironment createTestEnvironment(TestParameters Param,
95 PrintWriter log) throws Exception
97 XInterface oObj = null;
99 Param.getMSF().createInstance("com.sun.star.sdb.DatabaseContext");
100 Object oDBSource = Param.getMSF().createInstance("com.sun.star.sdb.DataSource");
101 Object newQuery = Param.getMSF().createInstance("com.sun.star.sdb.QueryDefinition");
102 Param.getMSF().createInstance("com.sun.star.awt.Toolkit");
104 String mysqlURL = (String) Param.get("mysql.url");
106 if (mysqlURL == null)
108 throw new StatusException(Status.failed(
109 "Couldn't get 'mysql.url' from ini-file"));
112 user = (String) Param.get("jdbc.user");
113 password = (String) Param.get("jdbc.password");
115 if ((user == null) || (password == null))
117 throw new StatusException(Status.failed(
118 "Couldn't get 'jdbc.user' or 'jdbc.password' from ini-file"));
121 PropertyValue[] info = new PropertyValue[2];
122 info[0] = new PropertyValue();
123 info[0].Name = "user";
124 info[0].Value = user;
125 info[1] = new PropertyValue();
126 info[1].Name = "password";
127 info[1].Value = password;
129 XPropertySet propSetDBSource = UnoRuntime.queryInterface(
130 XPropertySet.class, oDBSource);
132 propSetDBSource.setPropertyValue("URL", mysqlURL);
133 propSetDBSource.setPropertyValue("Info", info);
135 log.println("writing database file ...");
136 XDocumentDataSource xDDS = UnoRuntime.queryInterface(XDocumentDataSource.class, oDBSource);
137 XStorable store = UnoRuntime.queryInterface(XStorable.class,
138 xDDS.getDatabaseDocument());
140 aFile = utils.getOfficeTemp(Param.getMSF())+"ConnectionLine.odb";
141 log.println("... filename will be "+aFile);
142 store.storeAsURL(aFile,new PropertyValue[]{});
143 log.println("... done");
145 isolConnection = UnoRuntime.queryInterface(
146 XIsolatedConnection.class,
147 oDBSource);
149 final String tbl_name1 = "tst_table1";
150 final String tbl_name2 = "tst_table2";
151 final String col_name1 = "id1";
152 final String col_name2 = "id2";
154 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,
167 oDBSource);
169 XNameAccess defContainer = querySuppl.getQueryDefinitions();
171 XPropertySet queryProp = UnoRuntime.queryInterface(
172 XPropertySet.class, newQuery);
174 final String query = "select * from " + tbl_name1 + ", " +
175 tbl_name2 + " where " + tbl_name1 + "." +
176 col_name1 + "=" + tbl_name2 + "." +
177 col_name2;
178 queryProp.setPropertyValue("Command", query);
180 XNameContainer queryContainer = UnoRuntime.queryInterface(
181 XNameContainer.class,
182 defContainer);
184 queryContainer.insertByName("Query1", newQuery);
185 store.store();
186 connection.close();
188 PropertyValue[] loadProps = new PropertyValue[3];
189 loadProps[0] = new PropertyValue();
190 loadProps[0].Name = "QueryDesignView";
191 loadProps[0].Value = Boolean.TRUE;
193 loadProps[1] = new PropertyValue();
194 loadProps[1].Name = "CurrentQuery";
195 loadProps[1].Value = "Query1";
197 loadProps[2] = new PropertyValue();
198 loadProps[2].Name = "DataSource";
199 loadProps[2].Value = oDBSource;
201 QueryComponent = DesktopTools.loadDoc(Param.getMSF(),".component:DB/QueryDesign",loadProps);
203 util.utils.waitForEventIdle(Param.getMSF());
205 xWindow = UnoRuntime.queryInterface(XModel.class, QueryComponent).
206 getCurrentController().getFrame().getContainerWindow();
208 XAccessible xRoot = AccessibilityTools.getAccessibleObject(xWindow);
210 AccessibilityTools.printAccessibleTree (log,xRoot, Param.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
212 oObj = AccessibilityTools.getAccessibleObjectForRoleIgnoreShowing(xRoot, AccessibleRole.UNKNOWN, "", "ConnectionLine");
214 log.println("ImplementationName " + util.utils.getImplName(oObj));
216 log.println("creating TestEnvironment");
218 TestEnvironment tEnv = new TestEnvironment(oObj);
220 util.utils.waitForEventIdle(Param.getMSF());
222 final XWindow queryWin = xWindow;
224 tEnv.addObjRelation("EventProducer",
225 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer()
227 public void fireEvent()
229 Rectangle rect = queryWin.getPosSize();
230 queryWin.setPosSize(rect.X, rect.Y, rect.Height-5, rect.Width-5, PosSize.POSSIZE);
234 return tEnv;
235 } // finish method getTestEnvironment
238 * Closes the DatasourceAdministration dialog and Query Dialog.
240 @Override
241 protected void cleanup(TestParameters Param, PrintWriter log)
246 log.println("closing QueryComponent ...");
247 DesktopTools.closeDoc(QueryComponent);
248 log.println("... done");
249 XMultiServiceFactory xMSF = Param.getMSF();
250 Object sfa = xMSF.createInstance("com.sun.star.comp.ucb.SimpleFileAccess");
251 XSimpleFileAccess xSFA = UnoRuntime.queryInterface(XSimpleFileAccess.class, sfa);
252 log.println("deleting database file");
253 xSFA.kill(aFile);
254 log.println("Could delete file "+aFile+": "+!xSFA.exists(aFile));
256 catch (Exception e)
258 e.printStackTrace();