tdf#130857 qt weld: Introduce QtInstanceScrolledWindow
[LibreOffice.git] / qadevOOo / tests / java / mod / _forms / ODatabaseForm.java
blob66e46427f62db8679f6777ff7315a8588be0da6d
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._forms;
20 import ifc.form._XDatabaseParameterBroadcaster;
21 import ifc.sdb._XCompletedExecution;
23 import java.io.OutputStreamWriter;
24 import java.io.PrintWriter;
25 import java.io.UnsupportedEncodingException;
26 import java.util.ArrayList;
27 import lib.StatusException;
28 import lib.TestCase;
29 import lib.TestEnvironment;
30 import lib.TestParameters;
31 import util.DBTools;
32 import util.DrawTools;
33 import util.FormTools;
34 import util.WriterTools;
35 import util.utils;
37 import com.sun.star.awt.XControl;
38 import com.sun.star.awt.XControlModel;
39 import com.sun.star.beans.PropertyValue;
40 import com.sun.star.beans.XPropertySet;
41 import com.sun.star.container.XIndexAccess;
42 import com.sun.star.container.XNameContainer;
43 import com.sun.star.container.XNamed;
44 import com.sun.star.drawing.XControlShape;
45 import com.sun.star.drawing.XShapes;
46 import com.sun.star.form.DatabaseParameterEvent;
47 import com.sun.star.form.XForm;
48 import com.sun.star.form.XLoadable;
49 import com.sun.star.lang.EventObject;
50 import com.sun.star.sdb.CommandType;
51 import com.sun.star.sdb.ParametersRequest;
52 import com.sun.star.sdb.RowChangeEvent;
53 import com.sun.star.sdbc.SQLException;
54 import com.sun.star.sdbc.XConnection;
55 import com.sun.star.sdbc.XResultSet;
56 import com.sun.star.sdbc.XResultSetUpdate;
57 import com.sun.star.sdbc.XRow;
58 import com.sun.star.sdbc.XRowSet;
59 import com.sun.star.sdbc.XRowUpdate;
60 import com.sun.star.task.XInteractionRequest;
61 import com.sun.star.text.XTextDocument;
62 import com.sun.star.uno.AnyConverter;
63 import com.sun.star.uno.Type;
64 import com.sun.star.uno.UnoRuntime;
65 import com.sun.star.uno.XInterface;
66 import com.sun.star.util.Date;
67 import com.sun.star.util.DateTime;
68 import com.sun.star.util.Time;
69 import com.sun.star.util.XCloseable;
70 import com.sun.star.view.XControlAccess;
73 /**
74 * Test for object which is represented by service
75 * <code>com.sun.star.form.component.DatabaseForm</code>. <p>
77 * Object implements the following interfaces :
78 * <ul>
79 * <li> <code>com::sun::star::script::XEventAttacherManager</code></li>
80 * <li> <code>com::sun::star::container::XElementAccess</code></li>
81 * <li> <code>com::sun::star::sdbcx::ResultSet</code></li>
82 * <li> <code>com::sun::star::container::XChild</code></li>
83 * <li> <code>com::sun::star::sdbc::XResultSetUpdate</code></li>
84 * <li> <code>com::sun::star::sdb::XResultSetAccess</code></li>
85 * <li> <code>com::sun::star::form::FormComponent</code></li>
86 * <li> <code>com::sun::star::form::component::DataForm</code></li>
87 * <li> <code>com::sun::star::sdbc::XResultSetMetaDataSupplier</code></li>
88 * <li> <code>com::sun::star::container::XEnumerationAccess</code></li>
89 * <li> <code>com::sun::star::sdbcx::XDeleteRows</code></li>
90 * <li> <code>com::sun::star::sdb::RowSet</code></li>
91 * <li> <code>com::sun::star::lang::XComponent</code></li>
92 * <li> <code>com::sun::star::sdbc::XRowSet</code></li>
93 * <li> <code>com::sun::star::sdbc::XRowUpdate</code></li>
94 * <li> <code>com::sun::star::form::XLoadable</code></li>
95 * <li> <code>com::sun::star::container::XNamed</code></li>
96 * <li> <code>com::sun::star::container::XIndexReplace</code></li>
97 * <li> <code>com::sun::star::io::XPersistObject</code></li>
98 * <li> <code>com::sun::star::container::XNameReplace</code></li>
99 * <li> <code>com::sun::star::container::XIndexContainer</code></li>
100 * <li> <code>com::sun::star::container::XNameAccess</code></li>
101 * <li> <code>com::sun::star::sdbc::XParameters</code></li>
102 * <li> <code>com::sun::star::util::XCancellable</code></li>
103 * <li> <code>com::sun::star::form::XReset</code></li>
104 * <li> <code>com::sun::star::sdbc::XCloseable</code></li>
105 * <li> <code>com::sun::star::sdbcx::XColumnsSupplier</code></li>
106 * <li> <code>com::sun::star::sdb::XRowSetApproveBroadcaster</code></li>
107 * <li> <code>com::sun::star::sdbc::ResultSet</code></li>
108 * <li> <code>com::sun::star::sdbc::XResultSet</code></li>
109 * <li> <code>com::sun::star::sdbc::XRow</code></li>
110 * <li> <code>com::sun::star::sdbc::XColumnLocate</code></li>
111 * <li> <code>com::sun::star::awt::XTabControllerModel</code></li>
112 * <li> <code>com::sun::star::container::XIndexAccess</code></li>
113 * <li> <code>com::sun::star::form::XSubmit</code></li>
114 * <li> <code>com::sun::star::form::component::HTMLForm</code></li>
115 * <li> <code>com::sun::star::sdbcx::XRowLocate</code></li>
116 * <li> <code>com::sun::star::sdbc::XWarningsSupplier</code></li>
117 * <li> <code>com::sun::star::container::XNameContainer</code></li>
118 * <li> <code>com::sun::star::beans::XPropertyAccess</code></li>
119 * <li> <code>com::sun::star::beans::XPropertyContainer</code></li>
120 * <li> <code>com::sun::star::beans::XPropertySet</code></li>
121 * <li> <code>com::sun::star::sdbc::RowSet</code></li>
122 * </ul> <p>
124 * This object test <b> is NOT </b> designed to be run in several
125 * threads concurrently.
126 * The following parameters in ini-file used by this test:
127 * <ul>
128 * <li><code>test.db.url</code> - URL to MySQL database.
129 * For example: <code>mysql://mercury:3306/api_current</code></li>
130 * <li><code>test.db.user</code> - user for MySQL database</li>
131 * <li><code>test.db.password</code> - password for MySQL database</li>
132 * </ul><p>
134 * @see com.sun.star.script.XEventAttacherManager
135 * @see com.sun.star.container.XElementAccess
136 * @see com.sun.star.sdbcx.ResultSet
137 * @see com.sun.star.container.XChild
138 * @see com.sun.star.sdbc.XResultSetUpdate
139 * @see com.sun.star.sdb.XResultSetAccess
140 * @see com.sun.star.form.FormComponent
141 * @see com.sun.star.form.component.DataForm
142 * @see com.sun.star.sdbc.XResultSetMetaDataSupplier
143 * @see com.sun.star.container.XEnumerationAccess
144 * @see com.sun.star.sdbcx.XDeleteRows
145 * @see com.sun.star.sdb.RowSet
146 * @see com.sun.star.lang.XComponent
147 * @see com.sun.star.sdbc.XRowSet
148 * @see com.sun.star.sdbc.XRowUpdate
149 * @see com.sun.star.form.XLoadable
150 * @see com.sun.star.container.XNamed
151 * @see com.sun.star.container.XIndexReplace
152 * @see com.sun.star.io.XPersistObject
153 * @see com.sun.star.container.XNameReplace
154 * @see com.sun.star.container.XIndexContainer
155 * @see com.sun.star.container.XNameAccess
156 * @see com.sun.star.sdbc.XParameters
157 * @see com.sun.star.util.XCancellable
158 * @see com.sun.star.form.XReset
159 * @see com.sun.star.sdbc.XCloseable
160 * @see com.sun.star.sdbcx.XColumnsSupplier
161 * @see com.sun.star.sdb.XRowSetApproveBroadcaster
162 * @see com.sun.star.sdbc.ResultSet
163 * @see com.sun.star.sdbc.XResultSet
164 * @see com.sun.star.sdbc.XRow
165 * @see com.sun.star.sdbc.XColumnLocate
166 * @see com.sun.star.awt.XTabControllerModel
167 * @see com.sun.star.container.XIndexAccess
168 * @see com.sun.star.form.XSubmit
169 * @see com.sun.star.form.component.HTMLForm
170 * @see com.sun.star.sdbcx.XRowLocate
171 * @see com.sun.star.sdbc.XWarningsSupplier
172 * @see com.sun.star.container.XNameContainer
173 * @see com.sun.star.beans.XPropertySet
174 * @see com.sun.star.sdbc.RowSet
175 * @see ifc.script._XEventAttacherManager
176 * @see ifc.container._XElementAccess
177 * @see ifc.sdbcx._ResultSet
178 * @see ifc.container._XChild
179 * @see ifc.sdbc._XResultSetUpdate
180 * @see ifc.sdb._XResultSetAccess
181 * @see ifc.form._FormComponent
182 * @see ifc.form.component._DataForm
183 * @see ifc.sdbc._XResultSetMetaDataSupplier
184 * @see ifc.container._XEnumerationAccess
185 * @see ifc.sdbcx._XDeleteRows
186 * @see ifc.sdb._RowSet
187 * @see ifc.lang._XComponent
188 * @see ifc.sdbc._XRowSet
189 * @see ifc.sdbc._XRowUpdate
190 * @see ifc.form._XLoadable
191 * @see ifc.container._XNamed
192 * @see ifc.container._XIndexReplace
193 * @see ifc.io._XPersistObject
194 * @see ifc.container._XNameReplace
195 * @see ifc.container._XIndexContainer
196 * @see ifc.container._XNameAccess
197 * @see ifc.sdbc._XParameters
198 * @see ifc.util._XCancellable
199 * @see ifc.form._XReset
200 * @see ifc.sdbc._XCloseable
201 * @see ifc.sdbcx._XColumnsSupplier
202 * @see ifc.sdb._XRowSetApproveBroadcaster
203 * @see ifc.sdbc._ResultSet
204 * @see ifc.sdbc._XResultSet
205 * @see ifc.sdbc._XRow
206 * @see ifc.sdbc._XColumnLocate
207 * @see ifc.awt._XTabControllerModel
208 * @see ifc.container._XIndexAccess
209 * @see ifc.form._XSubmit
210 * @see ifc.form.component._HTMLForm
211 * @see ifc.sdbcx._XRowLocate
212 * @see ifc.sdbc._XWarningsSupplier
213 * @see ifc.container._XNameContainer
214 * @see ifc.beans._XPropertyAccess
215 * @see ifc.beans._XPropertyContainer
216 * @see ifc.beans._XPropertySet
217 * @see ifc.sdbc._RowSet
219 public class ODatabaseForm extends TestCase {
220 protected static final String dbSourceName = "ODatabaseFormDataSource";
221 private static int uniqueSuffix = 0;
222 private static String origDB = null;
223 private static String tmpDir = null;
224 protected XTextDocument xTextDoc = null;
225 private DBTools dbTools = null;
226 String tableName = null;
227 DBTools.DataSourceInfo srcInf = null;
228 boolean isMySQLDB = false;
229 protected XConnection conn = null;
230 private Object dbSrc = null;
232 @Override
233 protected void initialize(TestParameters tParam, PrintWriter log) throws Exception {
234 tmpDir = utils.getOfficeTemp(tParam.getMSF());
236 origDB = util.utils.getFullTestDocName("TestDB/testDB.dbf");
238 dbTools = new DBTools( tParam.getMSF() );
240 // creating DataSource and registering it in DatabaseContext
241 String dbURL = (String) tParam.get("test.db.url");
242 String dbUser = (String) tParam.get("test.db.user");
243 String dbPassword = (String) tParam.get("test.db.password");
245 log.println("Creating and registering DataSource ...");
246 srcInf = dbTools.newDataSourceInfo();
248 if ((dbURL != null) && (dbUser != null) && (dbPassword != null)) {
249 isMySQLDB = true;
250 log.println("dbURL = " + dbURL);
251 log.println("dbUSER = " + dbUser);
252 log.println("dbPASSWORD = " + dbPassword);
254 //DataSource for mysql db
255 try {
256 tableName = "soffice_test_table";
257 srcInf.URL = "jdbc:" + dbURL;
258 srcInf.IsPasswordRequired = Boolean.TRUE;
259 srcInf.Password = dbPassword;
260 srcInf.User = dbUser;
262 PropertyValue[] propInfo = new PropertyValue[1];
263 propInfo[0] = new PropertyValue();
264 propInfo[0].Name = "JavaDriverClass";
265 propInfo[0].Value = "util.dddriver.Driver";
266 srcInf.Info = propInfo;
268 dbSrc = srcInf.getDataSourceService();
269 dbTools.reRegisterDB(dbSourceName, dbSrc);
270 } catch (com.sun.star.uno.Exception e) {
271 log.println("Error while object test initialization :");
272 e.printStackTrace(log);
273 throw new StatusException("Error while object test" +
274 " initialization", e);
276 } else {
277 //DataSource for sdbc db
278 try {
279 String myDbUrl = "sdbc:dbase:" + DBTools.dirToUrl(tmpDir);
280 srcInf.URL = myDbUrl;
282 log.println("try to register '"+myDbUrl+"' as '"+dbSourceName+"'");
284 dbSrc = srcInf.getDataSourceService();
285 dbTools.reRegisterDB(dbSourceName, dbSrc);
286 } catch (com.sun.star.uno.Exception e) {
287 log.println("Error while object test initialization :");
288 e.printStackTrace(log);
289 throw new StatusException(
290 "Error while object test initialization", e);
293 String oldF = null;
294 String newF = null;
296 do {
297 tableName = "ODatabaseForm_tmp" + uniqueSuffix;
298 oldF = utils.getFullURL(origDB);
299 newF = utils.getOfficeTemp(tParam.getMSF()) + tableName +
300 ".dbf";
301 } while (!utils.tryOverwriteFile(tParam.getMSF(), oldF, newF) &&
302 (uniqueSuffix++ < 50));
307 * creating a TestEnvironment for the interfaces to be tested
309 @Override
310 protected TestEnvironment createTestEnvironment(TestParameters Param,
311 PrintWriter log) throws Exception {
312 if (xTextDoc != null) {
313 try {
314 XCloseable closer = UnoRuntime.queryInterface(
315 XCloseable.class, xTextDoc);
316 closer.close(true);
317 } catch (com.sun.star.util.CloseVetoException e) {
318 log.println("couldn't close document");
319 } catch (com.sun.star.lang.DisposedException e) {
320 log.println("couldn't close document");
323 log.println("Existing document disposed");
326 log.println("creating a text document");
327 xTextDoc = WriterTools.createTextDoc(Param.getMSF());
329 //initialize test table
330 if (isMySQLDB) {
331 dbTools.initTestTableUsingJDBC(tableName, srcInf);
334 XInterface oObj = null;
335 XShapes oShapes = null;
336 XInterface oInstance = null;
337 XConnection connection = null;
340 // creation of testobject here
341 // first we write what we are intend to do to log file
342 log.println("creating a test environment");
344 XNameContainer forms = FormTools.getForms(WriterTools.getDrawPage(
345 xTextDoc));
347 try {
348 String[] formNames = forms.getElementNames();
350 for (int i = 0; i < formNames.length; i++) {
351 log.println("Removing form '" + formNames[i] + "' ...");
352 forms.removeByName(formNames[i]);
354 } catch (com.sun.star.lang.WrappedTargetException e) {
355 e.printStackTrace(log);
356 } catch (com.sun.star.container.NoSuchElementException e) {
357 e.printStackTrace(log);
360 String[] formNames = forms.getElementNames();
361 FormTools.insertForm(xTextDoc, forms, "MyForm");
362 formNames = forms.getElementNames();
364 XLoadable formLoader = null;
366 formLoader = FormTools.bindForm(xTextDoc, "MyForm", dbSourceName,
367 tableName);
370 // DEBUG
371 log.println("Forms before adding controls : ");
372 formNames = forms.getElementNames();
374 for (int i = 0; i < formNames.length; i++) {
375 log.println(" '" + formNames[i] + "'");
378 XControlShape shape1 = null;
379 XControlShape shape2 = null;
381 try {
383 log.println("Elements in the 'MyForm' :");
385 XIndexAccess formElements1 = UnoRuntime.queryInterface(
386 XIndexAccess.class,
387 forms.getByName("MyForm"));
389 for (int i = 0; i < formElements1.getCount(); i++) {
390 XNamed elemName = UnoRuntime.queryInterface(
391 XNamed.class,
392 formElements1.getByIndex(i));
393 log.println(" '" + elemName.getName() + "'");
397 // END DEBUG
398 //put something on the drawpage
399 log.println("inserting some ControlShapes");
400 oShapes = DrawTools.getShapes(WriterTools.getDrawPage(xTextDoc));
401 shape1 = FormTools.createControlShape(xTextDoc, 3000, 4500, 15000,
402 1000, "CommandButton");
403 shape2 = FormTools.createControlShape(xTextDoc, 5000, 3500, 7500,
404 5000, "TextField");
406 XControlShape shape3 = FormTools.createControlShape(xTextDoc, 2000,
407 1500, 1000,
408 1000,
409 "CheckBox");
410 oShapes.add(shape1);
411 oShapes.add(shape2);
412 oShapes.add(shape3);
413 } catch (Exception e) {
414 e.printStackTrace(log);
417 log.println("Forms after adding controls : ");
418 formNames = forms.getElementNames();
420 for (int i = 0; i < formNames.length; i++) {
421 log.println(" '" + formNames[i] + "'");
424 try {
425 log.println("Elements in the 'MyForm' :");
427 XIndexAccess formElements1 = UnoRuntime.queryInterface(
428 XIndexAccess.class,
429 forms.getByName("MyForm"));
431 for (int i = 0; i < formElements1.getCount(); i++) {
432 XNamed elemName = UnoRuntime.queryInterface(
433 XNamed.class,
434 formElements1.getByIndex(i));
435 log.println(" '" + elemName.getName() + "'");
437 } catch (Exception e) {
438 e.printStackTrace(log);
441 formLoader.load();
443 try {
444 Object temp1 = FormTools.getForms( WriterTools.getDrawPage(xTextDoc) ).getByName("MyForm");
445 oObj = (XForm) AnyConverter.toObject(new Type(XForm.class), temp1);
447 XPropertySet xSetProp = UnoRuntime.queryInterface(
448 XPropertySet.class, oObj);
449 connection = (XConnection) AnyConverter.toObject(
450 new Type(XConnection.class),
451 xSetProp.getPropertyValue("ActiveConnection"));
452 } catch (com.sun.star.uno.Exception e) {
453 log.println("Couldn't get Form");
454 e.printStackTrace(log);
458 // get a control
459 oInstance = FormTools.createControl(xTextDoc, "TextField");
461 log.println("creating a new environment for drawpage object");
463 TestEnvironment tEnv = new TestEnvironment(oObj);
466 // adding relation for closing connection while environment disposing.
467 this.conn = connection;
469 // adding relation for XSubmit
470 XControlModel the_Model = shape2.getControl();
471 XControlAccess the_access = UnoRuntime.queryInterface(
472 XControlAccess.class,
473 xTextDoc.getCurrentController());
474 XControl cntrl = null;
476 //now get the OEditControl
477 cntrl = the_access.getControl(the_Model);
478 log.println(cntrl.getClass().getName());
480 XResultSet the_set = UnoRuntime.queryInterface(
481 XResultSet.class, oObj);
483 the_set.first();
485 tEnv.addObjRelation("Model1", shape1.getControl());
486 tEnv.addObjRelation("Model2", shape2.getControl());
489 // adding an object for XNameReplace testing
490 log.println("adding oInstance as obj relation to environment");
491 tEnv.addObjRelation("INSTANCE", oInstance);
494 // INDEX : _XNameContainer
495 log.println("adding INDEX as obj relation to environment");
496 tEnv.addObjRelation("INDEX", "0");
499 // INDEX : _XNameReplace
500 log.println("adding NameReplaceIndex as obj relation to environment");
501 tEnv.addObjRelation("XNameReplaceINDEX", "2");
504 // INSTANCEn : _XNameContainer; _XNameReplace
505 log.println("adding INSTANCEn as obj relation to environment");
507 String tc = (String) Param.get("THRCNT");
508 int THRCNT = 1;
510 if (tc != null) {
511 THRCNT = Integer.parseInt(tc);
514 for (int n = 1; n < (2 * (THRCNT + 1)); n++) {
515 log.println("adding INSTANCE" + n +
516 " as obj relation to environment");
517 tEnv.addObjRelation("INSTANCE" + n,
518 FormTools.createControl(xTextDoc, "CheckBox"));
522 // adding relation for XNameContainer
523 tEnv.addObjRelation("XNameContainer.AllowDuplicateNames", new Object());
526 // adding relation for XPersistObject
527 tEnv.addObjRelation("OBJNAME", "stardiv.one.form.component.Form");
529 // Adding obj relation for XRowSetApproveBroadcaster test
530 final XResultSet xResSet = UnoRuntime.queryInterface(
531 XResultSet.class, oObj);
532 final XResultSetUpdate xResSetUpdate = UnoRuntime.queryInterface(
533 XResultSetUpdate.class,
534 oObj);
535 final XRowSet xRowSet = UnoRuntime.queryInterface(
536 XRowSet.class, oObj);
537 final PrintWriter logF = log;
538 tEnv.addObjRelation("XRowSetApproveBroadcaster.ApproveChecker",
539 new ifc.sdb._XRowSetApproveBroadcaster.RowSetApproveChecker() {
540 public void moveCursor() {
541 try {
542 xResSet.beforeFirst();
543 xResSet.afterLast();
544 } catch (com.sun.star.sdbc.SQLException e) {
545 logF.println("### _XRowSetApproveBroadcaster." + "RowSetApproveChecker.moveCursor() :");
546 e.printStackTrace(logF);
550 public RowChangeEvent changeRow() {
551 try {
552 xResSet.first();
554 XRowUpdate row = UnoRuntime.queryInterface(
555 XRowUpdate.class, xResSet);
556 row.updateString(1, "1");
557 xResSetUpdate.updateRow();
558 } catch (com.sun.star.sdbc.SQLException e) {
559 logF.println("### _XRowSetApproveBroadcaster." + "RowSetApproveChecker.changeRow() :");
560 e.printStackTrace(logF);
563 RowChangeEvent ev = new RowChangeEvent();
564 ev.Action = com.sun.star.sdb.RowChangeAction.UPDATE;
565 ev.Rows = 1;
567 return ev;
570 public void changeRowSet() {
571 try {
572 xRowSet.execute();
573 } catch (com.sun.star.sdbc.SQLException e) {
574 logF.println("### _XRowSetApproveBroadcaster." + "RowSetApproveChecker.changeRowSet() :");
575 e.printStackTrace(logF);
581 // Adding relation for XColumnLocate test
582 tEnv.addObjRelation("XColumnLocate.ColumnName", DBTools.TST_STRING_F);
584 // Adding relation for XParameters ifc test
585 ArrayList<Object> params = new ArrayList<Object>();
588 /***** statement parameter types and their initial
589 values must be added here as relation. */
590 params.add("SAU99") ;
591 params.add(Boolean.FALSE) ;
592 params.add(Byte.valueOf((byte) 123)) ;
593 params.add(Short.valueOf((short) 234)) ;
594 params.add(Integer.valueOf(12345)) ;
595 params.add(Long.valueOf(23456)) ;
596 params.add(Float.valueOf(1.234f)) ;
597 params.add(Double.valueOf(2.345)) ;
598 params.add(new byte[] {1, 2, 3}) ;
599 Date d = new Date();
600 d.Day = 26; d.Month = 1; d.Year = 2001;
601 params.add(d) ;
602 Time t = new Time();
603 t.Hours = 1; t.NanoSeconds = 123456789; t.Minutes = 25; t.Seconds = 14;
604 params.add(t) ;
605 DateTime dt = new DateTime();
606 dt.Day = 26; dt.Month = 1; dt.Year = 2001; dt.Hours = 1;
607 dt.NanoSeconds = 123456789; dt.Minutes = 25; dt.Seconds = 14;
608 params.add(dt) ;
609 tEnv.addObjRelation("XParameters.ParamValues", params);
611 // Adding relation for XCompletedExecution
612 tEnv.addObjRelation("InteractionHandlerChecker", new InteractionHandlerImpl());
614 // Adding for XWarningSupplier
615 tEnv.addObjRelation("CheckWarningsSupplier", Boolean.valueOf(isMySQLDB));
617 // Adding relation for XDatabaseParameterBroadcaster
618 tEnv.addObjRelation("ParameterListenerChecker", new ODatabaseForm.ParameterListenerImpl());
619 XPropertySet xSetProp = UnoRuntime.queryInterface
620 (XPropertySet.class, oObj) ;
621 try {
622 xSetProp.setPropertyValue("DataSourceName", dbSourceName) ;
623 if(isMySQLDB) {
624 xSetProp.setPropertyValue("Command", "SELECT Column0 FROM soffice_test_table WHERE ( ( Column0 = :param1 ) )");
626 else {
627 xSetProp.setPropertyValue("Command", "SELECT \"_TEXT\" FROM \"ODatabaseForm_tmp0\" WHERE ( ( \"_TEXT\" = :param1 ) )");
630 xSetProp.setPropertyValue("CommandType",
631 Integer.valueOf(CommandType.COMMAND)) ;
633 catch(Exception e) {
636 // Adding relation for XResultSetUpdate
637 final XRowUpdate xRowUpdate = UnoRuntime.queryInterface(
638 XRowUpdate.class, oObj);
639 final XRow xRow = UnoRuntime.queryInterface(XRow.class, oObj);
641 tEnv.addObjRelation("XResultSetUpdate.UpdateTester",
642 new ifc.sdbc._XResultSetUpdate.UpdateTester() {
643 String lastUpdate = null;
645 public int rowCount() throws SQLException {
646 int prevPos = xResSet.getRow();
647 xResSet.last();
649 int count = xResSet.getRow();
650 xResSet.absolute(prevPos);
652 return count;
655 public void update() throws SQLException {
656 lastUpdate = xRow.getString(1);
657 lastUpdate += "_";
658 xRowUpdate.updateString(1, lastUpdate);
661 public boolean wasUpdated() throws SQLException {
662 String getStr = xRow.getString(1);
664 return lastUpdate.equals(getStr);
667 public int currentRow() throws SQLException {
668 return xResSet.getRow();
672 // Adding relations for XRow as a Vector with all data
673 // of current row of RowSet.
675 ArrayList<Object> rowData = new ArrayList<Object>();
677 for (int i = 0; i < DBTools.TST_TABLE_VALUES[0].length; i++) {
678 rowData.add(DBTools.TST_TABLE_VALUES[0][i]);
681 tEnv.addObjRelation("CurrentRowData", rowData);
683 // Adding relation for XRowUpdate
684 XRow row = UnoRuntime.queryInterface(XRow.class, oObj);
685 tEnv.addObjRelation("XRowUpdate.XRow", row);
688 tEnv.addObjRelation("XPropertyContainer.propertyNotRemovable", "Cycle");
690 PropertyValue propVal = new PropertyValue();
691 propVal.Name = "Name";
692 propVal.Value = "Text since XPropertyAccess";
694 tEnv.addObjRelation("XPropertyAccess.propertyToChange", propVal);
696 return tEnv;
697 } // finish method getTestEnvironment
700 * Closes connection of <code>RowSet</code> instance created.
702 @Override
703 protected void cleanup(TestParameters Param, PrintWriter log) {
704 log.println("closing connection...");
705 try {
706 conn.close();
707 } catch (com.sun.star.uno.Exception e) {
708 log.println("Can't close the connection");
709 e.printStackTrace(log);
710 } catch (com.sun.star.lang.DisposedException e) {
711 log.println("Connection was already closed. It's OK.");
715 log.println("closing data source...");
716 try {
717 XCloseable closer = UnoRuntime.queryInterface(
718 XCloseable.class, dbSrc);
719 closer.close(true);
720 } catch (com.sun.star.util.CloseVetoException e) {
721 log.println("couldn't close data source");
722 } catch (com.sun.star.lang.DisposedException e) {
723 log.println("couldn't close data source");
727 log.println("closing document...");
729 try {
730 XCloseable closer = UnoRuntime.queryInterface(
731 XCloseable.class, xTextDoc);
732 closer.close(true);
733 } catch (com.sun.star.util.CloseVetoException e) {
734 log.println("couldn't close document");
735 } catch (com.sun.star.lang.DisposedException e) {
736 log.println("couldn't close document");
739 log.println("revoking data source...");
740 try {
741 dbTools.revokeDB(dbSourceName);
742 } catch (com.sun.star.container.NoSuchElementException e){
743 } catch (com.sun.star.uno.Exception e) {
744 log.println("Error while object test cleaning up :");
745 e.printStackTrace(log);
746 throw new StatusException("Error while object test cleaning up", e);
751 * Implementation of interface _XDatabaseParameterBroadcaster.CheckParameterListener
752 * for the XDatabaseParameterBroadcaster test
753 * @see ifc.form._XDatabaseParameterBroadcaster
755 private static class ParameterListenerImpl implements _XDatabaseParameterBroadcaster.CheckParameterListener {
756 private boolean listenerWasCalled = false;
758 private PrintWriter log;
760 ParameterListenerImpl() throws UnsupportedEncodingException {
761 log = new PrintWriter(new OutputStreamWriter(System.out, "UTF-8"));
765 * Return true, if the listener was called, false otherwise.
766 * @return True, if any other method of the listener was called.
768 public boolean checkListener() {
769 return listenerWasCalled;
773 * Take the DataBaseParameterEvent and fill it with a meaningful value.
774 * @param e The database parameter that will be filled with a value.
775 * @return True, if the value could be filled.
777 public boolean approveParameter(DatabaseParameterEvent e) {
778 log.println("### ParameterListenerImpl: approve called.");
779 XIndexAccess params = e.Parameters;
780 int count = params.getCount();
781 try {
782 for(int i=0; i<count; i++) {
783 log.println("### _XDatabaseParameterBroadcaster.ParameterListenerImpl: Parameter "+i+": "+params.getByIndex(i));
784 XPropertySet xProp = UnoRuntime.queryInterface(XPropertySet.class, params.getByIndex(i));
785 log.println("### _XDatabaseParameterBroadcaster.ParameterListenerImpl: Parameter Name: '"+xProp.getPropertyValue("Name") + "' is set to Value '1'");
786 xProp.setPropertyValue("Value", Integer.valueOf(1));
787 listenerWasCalled = true;
790 catch(Exception eI) {
791 log.println("### _XDatabaseParameterBroadcaster.ParameterListenerImpl: Exception!");
792 eI.printStackTrace(log);
793 return false;
795 return true;
799 * Dummy implementation. Do nothing, just log
800 * @param o Ignore.
802 public void disposing(EventObject o) {
803 log.println("### _XDatabaseParameterBroadcaster.ParameterListenerImpl: disposing");
807 * Set a log writer, so messages go to log instead of Standard.out
808 * @param log The log messages get printed to.
810 public void setLog(PrintWriter log) {
811 this.log = log;
818 * Implementation of interface _XCompletedExecution.CheckInteractionHandler
819 * for the XCompletedExecution test
820 * @see ifc.sdb._XCompletedExecution
822 private static class InteractionHandlerImpl implements _XCompletedExecution.CheckInteractionHandler {
823 private boolean handlerWasUsed = false;
824 private PrintWriter log;
826 InteractionHandlerImpl() throws UnsupportedEncodingException {
827 log = new PrintWriter(new OutputStreamWriter(System.out, "UTF-8"));
830 public boolean checkInteractionHandler() {
831 return handlerWasUsed;
834 public void handle(XInteractionRequest xInteractionRequest) {
835 log.println("### _XCompletedExecution.InteractionHandlerImpl: handle called.");
836 handlerWasUsed = true;
838 Object o = xInteractionRequest.getRequest();
839 ParametersRequest req = (ParametersRequest)o;
840 XIndexAccess params = req.Parameters;
841 int count = params.getCount();
842 try {
843 for(int i=0; i<count; i++) {
844 params.getByIndex(i);
845 log.println("### _XCompletedExecution.InteractionHandlerImpl: Parameter "+i+": "+params.getByIndex(i));
846 XPropertySet xProp = UnoRuntime.queryInterface(XPropertySet.class, params.getByIndex(i));
847 log.println("### _XCompletedExecution.InteractionHandlerImpl: Parameter Name: '"+xProp.getPropertyValue("Name") + "' is set to Value '1'");
848 xProp.setPropertyValue("Value", Integer.valueOf(1));
849 handlerWasUsed = true;
852 catch(Exception eI) {
853 log.println("### _XCompletedExecution.InteractionHandlerImpl: Exception!");
854 eI.printStackTrace(log);
858 public void setLog(PrintWriter log) {
859 this.log = log;
863 } // finish class ODatabaseForm