bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _forms / ODatabaseForm.java
blob9c884d95720c57f9d515f949db27e2e808fc4a4d
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.PrintWriter;
24 import java.util.ArrayList;
25 import lib.Status;
26 import lib.StatusException;
27 import lib.TestCase;
28 import lib.TestEnvironment;
29 import lib.TestParameters;
30 import util.DBTools;
31 import util.DrawTools;
32 import util.FormTools;
33 import util.WriterTools;
34 import util.utils;
36 import com.sun.star.awt.XControl;
37 import com.sun.star.awt.XControlModel;
38 import com.sun.star.beans.PropertyValue;
39 import com.sun.star.beans.XPropertySet;
40 import com.sun.star.container.XIndexAccess;
41 import com.sun.star.container.XNameContainer;
42 import com.sun.star.container.XNamed;
43 import com.sun.star.drawing.XControlShape;
44 import com.sun.star.drawing.XShapes;
45 import com.sun.star.form.DatabaseParameterEvent;
46 import com.sun.star.form.XForm;
47 import com.sun.star.form.XLoadable;
48 import com.sun.star.lang.EventObject;
49 import com.sun.star.lang.XMultiServiceFactory;
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 concurently.
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 final static 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 protected void initialize(TestParameters tParam, PrintWriter log) {
233 //log.println( "creating a draw document" );
234 //xTextDoc = WriterTools.createTextDoc(t((XMultiServiceFactory) Param.getMSF));
235 tmpDir = utils.getOfficeTemp(((XMultiServiceFactory) tParam.getMSF()));
237 origDB = util.utils.getFullTestDocName("TestDB/testDB.dbf");
239 dbTools = new DBTools( (XMultiServiceFactory)tParam.getMSF(), log );
241 // creating DataSource and registering it in DatabaseContext
242 String dbURL = (String) tParam.get("test.db.url");
243 String dbUser = (String) tParam.get("test.db.user");
244 String dbPassword = (String) tParam.get("test.db.password");
246 log.println("Creating and registering DataSource ...");
247 srcInf = dbTools.newDataSourceInfo();
249 if ((dbURL != null) && (dbUser != null) && (dbPassword != null)) {
250 isMySQLDB = true;
251 log.println("dbURL = " + dbURL);
252 log.println("dbUSER = " + dbUser);
253 log.println("dbPASSWORD = " + dbPassword);
255 //DataSource for mysql db
256 try {
257 tableName = "soffice_test_table";
258 srcInf.URL = "jdbc:" + dbURL;
259 srcInf.IsPasswordRequired = new Boolean(true);
260 srcInf.Password = dbPassword;
261 srcInf.User = dbUser;
263 PropertyValue[] propInfo = new PropertyValue[1];
264 propInfo[0] = new PropertyValue();
265 propInfo[0].Name = "JavaDriverClass";
266 // propInfo[0].Value = "org.gjt.mm.mysql.Driver";
267 propInfo[0].Value = "util.dddriver.Driver";
268 srcInf.Info = propInfo;
270 dbSrc = srcInf.getDataSourceService();
271 dbTools.reRegisterDB(dbSourceName, dbSrc);
272 } catch (com.sun.star.uno.Exception e) {
273 log.println("Error while object test initialization :");
274 e.printStackTrace(log);
275 throw new StatusException("Error while object test" +
276 " initialization", e);
278 } else {
279 //DataSource for sdbc db
280 try {
281 String myDbUrl = "sdbc:dbase:" + DBTools.dirToUrl(tmpDir);
282 srcInf.URL = myDbUrl;
284 log.println("try to register '"+myDbUrl+"' as '"+dbSourceName+"'");
286 dbSrc = srcInf.getDataSourceService();
287 dbTools.reRegisterDB(dbSourceName, dbSrc);
288 } catch (com.sun.star.uno.Exception e) {
289 log.println("Error while object test initialization :");
290 e.printStackTrace(log);
291 throw new StatusException(
292 "Error while object test initialization", e);
295 String oldF = null;
296 String newF = null;
298 do {
299 tableName = "ODatabaseForm_tmp" + uniqueSuffix;
300 oldF = utils.getFullURL(origDB);
301 newF = utils.getOfficeTemp((XMultiServiceFactory) tParam.getMSF()) + tableName +
302 ".dbf";
303 } while (!utils.tryOverwriteFile(((XMultiServiceFactory) tParam.getMSF()), oldF, newF) &&
304 (uniqueSuffix++ < 50));
309 * * creating a Testenvironment for the interfaces to be tested
311 protected synchronized TestEnvironment createTestEnvironment(TestParameters Param,
312 PrintWriter log) {
313 if (xTextDoc != null) {
314 try {
315 XCloseable closer = UnoRuntime.queryInterface(
316 XCloseable.class, xTextDoc);
317 closer.close(true);
318 } catch (com.sun.star.util.CloseVetoException e) {
319 log.println("couldn't close document");
320 } catch (com.sun.star.lang.DisposedException e) {
321 log.println("couldn't close document");
324 log.println("Existing document disposed");
327 log.println("creating a text document");
328 xTextDoc = WriterTools.createTextDoc(((XMultiServiceFactory) Param.getMSF()));
330 //initialize test table
331 if (isMySQLDB) {
332 try {
333 dbTools.initTestTableUsingJDBC(tableName, srcInf);
334 } catch (java.sql.SQLException e) {
335 e.printStackTrace(log);
336 throw new StatusException(Status.failed("Couldn't " + " init test table. SQLException..."));
337 } catch (java.lang.ClassNotFoundException e) {
338 throw new StatusException(Status.failed("Couldn't " + "register mysql driver"));
342 XInterface oObj = null;
343 XShapes oShapes = null;
344 XInterface oInstance = null;
345 XConnection connection = null;
348 // creation of testobject here
349 // first we write what we are intend to do to log file
350 log.println("creating a test environment");
352 XNameContainer forms = FormTools.getForms(WriterTools.getDrawPage(
353 xTextDoc));
355 try {
356 String[] formNames = forms.getElementNames();
358 for (int i = 0; i < formNames.length; i++) {
359 log.println("Removing form '" + formNames[i] + "' ...");
360 forms.removeByName(formNames[i]);
362 } catch (com.sun.star.lang.WrappedTargetException e) {
363 e.printStackTrace(log);
364 } catch (com.sun.star.container.NoSuchElementException e) {
365 e.printStackTrace(log);
368 String[] formNames = forms.getElementNames();
369 FormTools.insertForm(xTextDoc, forms, "MyForm");
370 formNames = forms.getElementNames();
372 XLoadable formLoader = null;
374 try {
375 formLoader = FormTools.bindForm(xTextDoc, "MyForm", dbSourceName,
376 tableName);
377 } catch (com.sun.star.uno.Exception e) {
378 log.println("Cann't bind the form to source '" + dbSourceName +
379 "', table '" + tableName + "' :");
380 e.printStackTrace(log);
381 throw new StatusException("Cann't bind a form", e);
385 // DEBUG
386 log.println("Forms before adding controls : ");
387 formNames = forms.getElementNames();
389 for (int i = 0; i < formNames.length; i++) {
390 log.println(" '" + formNames[i] + "'");
393 XControlShape shape1 = null;
394 XControlShape shape2 = null;
396 try {
398 log.println("Elements in the 'MyForm' :");
400 XIndexAccess formElements1 = UnoRuntime.queryInterface(
401 XIndexAccess.class,
402 forms.getByName("MyForm"));
404 for (int i = 0; i < formElements1.getCount(); i++) {
405 XNamed elemName = UnoRuntime.queryInterface(
406 XNamed.class,
407 formElements1.getByIndex(i));
408 log.println(" '" + elemName.getName() + "'");
412 // END DEBUG
413 //put something on the drawpage
414 log.println("inserting some ControlShapes");
415 oShapes = DrawTools.getShapes(WriterTools.getDrawPage(xTextDoc));
416 shape1 = FormTools.createControlShape(xTextDoc, 3000, 4500, 15000,
417 1000, "CommandButton");
418 shape2 = FormTools.createControlShape(xTextDoc, 5000, 3500, 7500,
419 5000, "TextField");
421 XControlShape shape3 = FormTools.createControlShape(xTextDoc, 2000,
422 1500, 1000,
423 1000,
424 "CheckBox");
425 oShapes.add(shape1);
426 oShapes.add(shape2);
427 oShapes.add(shape3);
428 } catch (Exception e) {
429 e.printStackTrace(log);
432 log.println("Forms after adding controls : ");
433 formNames = forms.getElementNames();
435 for (int i = 0; i < formNames.length; i++) {
436 log.println(" '" + formNames[i] + "'");
439 try {
440 log.println("Elements in the 'MyForm' :");
442 XIndexAccess formElements1 = UnoRuntime.queryInterface(
443 XIndexAccess.class,
444 forms.getByName("MyForm"));
446 for (int i = 0; i < formElements1.getCount(); i++) {
447 XNamed elemName = UnoRuntime.queryInterface(
448 XNamed.class,
449 formElements1.getByIndex(i));
450 log.println(" '" + elemName.getName() + "'");
452 } catch (Exception e) {
453 e.printStackTrace(log);
456 formLoader.load();
458 try {
459 oObj = (XForm) AnyConverter.toObject(new Type(XForm.class),
460 (FormTools.getForms(
461 WriterTools.getDrawPage(
462 xTextDoc)))
463 .getByName("MyForm"));
465 XPropertySet xSetProp = UnoRuntime.queryInterface(
466 XPropertySet.class, oObj);
467 connection = (XConnection) AnyConverter.toObject(
468 new Type(XConnection.class),
469 xSetProp.getPropertyValue("ActiveConnection"));
470 } catch (com.sun.star.uno.Exception e) {
471 log.println("Couldn't get Form");
472 e.printStackTrace(log);
476 // get a control
477 oInstance = FormTools.createControl(xTextDoc, "TextField");
479 log.println("creating a new environment for drawpage object");
481 TestEnvironment tEnv = new TestEnvironment(oObj);
484 // adding relation for closing connection while environment disposing.
485 this.conn = connection;
487 // adding relation for XSubmit
488 XControlModel the_Model = shape2.getControl();
489 XControlAccess the_access = UnoRuntime.queryInterface(
490 XControlAccess.class,
491 xTextDoc.getCurrentController());
492 XControl cntrl = null;
494 //now get the OEditControl
495 try {
496 cntrl = the_access.getControl(the_Model);
497 log.println(cntrl.getClass().getName());
498 } catch (com.sun.star.container.NoSuchElementException e) {
499 log.println("Couldn't get OEditControl");
500 e.printStackTrace(log);
501 throw new StatusException("Couldn't get OEditControl", e);
504 XResultSet the_set = UnoRuntime.queryInterface(
505 XResultSet.class, oObj);
507 try {
508 the_set.first();
509 } catch (SQLException e) {
510 log.println("Cann't move cursor to the first row.");
511 e.printStackTrace();
512 throw new StatusException("Can't move cursor to the first row.", e);
515 tEnv.addObjRelation("Model1", shape1.getControl());
516 tEnv.addObjRelation("Model2", shape2.getControl());
519 // adding an object for XNameReplace testing
520 log.println("adding oInstace as obj relation to environment");
521 tEnv.addObjRelation("INSTANCE", oInstance);
524 // INDEX : _XNameContainer
525 log.println("adding INDEX as obj relation to environment");
526 tEnv.addObjRelation("INDEX", "0");
529 // INDEX : _XNameReplace
530 log.println("adding NameReplaceIndex as obj relation to environment");
531 tEnv.addObjRelation("XNameReplaceINDEX", "2");
534 // INSTANCEn : _XNameContainer; _XNameReplace
535 log.println("adding INSTANCEn as obj relation to environment");
537 //XComponent xComp = (XComponent)
538 // UnoRuntime.queryInterface(XComponent.class, xDrawDoc);
539 String tc = (String) Param.get("THRCNT");
540 int THRCNT = 1;
542 if (tc != null) {
543 THRCNT = Integer.parseInt(tc);
546 for (int n = 1; n < (2 * (THRCNT + 1)); n++) {
547 log.println("adding INSTANCE" + n +
548 " as obj relation to environment");
549 tEnv.addObjRelation("INSTANCE" + n,
550 FormTools.createControl(xTextDoc, "CheckBox"));
554 // adding relation for XNameContainer
555 tEnv.addObjRelation("XNameContainer.AllowDuplicateNames", new Object());
558 // adding relation for XPersistObject
559 tEnv.addObjRelation("OBJNAME", "stardiv.one.form.component.Form");
561 if (the_set != null) {
562 log.println("The Form has a not empty ResultSet");
565 // Adding obj relation for XRowSetApproveBroadcaster test
566 final XResultSet xResSet = UnoRuntime.queryInterface(
567 XResultSet.class, oObj);
568 final XResultSetUpdate xResSetUpdate = UnoRuntime.queryInterface(
569 XResultSetUpdate.class,
570 oObj);
571 final XRowSet xRowSet = UnoRuntime.queryInterface(
572 XRowSet.class, oObj);
573 final PrintWriter logF = log;
574 tEnv.addObjRelation("XRowSetApproveBroadcaster.ApproveChecker",
575 new ifc.sdb._XRowSetApproveBroadcaster.RowSetApproveChecker() {
576 public void moveCursor() {
577 try {
578 xResSet.beforeFirst();
579 xResSet.afterLast();
580 } catch (com.sun.star.sdbc.SQLException e) {
581 logF.println("### _XRowSetApproveBroadcaster." + "RowSetApproveChecker.moveCursor() :");
582 e.printStackTrace(logF);
586 public RowChangeEvent changeRow() {
587 try {
588 xResSet.first();
590 XRowUpdate row = UnoRuntime.queryInterface(
591 XRowUpdate.class, xResSet);
592 row.updateString(1, "1");
593 xResSetUpdate.updateRow();
594 } catch (com.sun.star.sdbc.SQLException e) {
595 logF.println("### _XRowSetApproveBroadcaster." + "RowSetApproveChecker.changeRow() :");
596 e.printStackTrace(logF);
599 RowChangeEvent ev = new RowChangeEvent();
600 ev.Action = com.sun.star.sdb.RowChangeAction.UPDATE;
601 ev.Rows = 1;
603 return ev;
606 public void changeRowSet() {
607 try {
608 xRowSet.execute();
609 } catch (com.sun.star.sdbc.SQLException e) {
610 logF.println("### _XRowSetApproveBroadcaster." + "RowSetApproveChecker.changeRowSet() :");
611 e.printStackTrace(logF);
617 // Adding relation for XColumnLocate test
618 tEnv.addObjRelation("XColumnLocate.ColumnName", DBTools.TST_STRING_F);
620 // Adding relation for XParameters ifc test
621 ArrayList<Object> params = new ArrayList<Object>();
624 /***** statement parameter types and their initial
625 values must be added here as relation. */
626 params.add(new String("SAU99")) ;
627 params.add(new Boolean(false)) ;
628 params.add(new Byte((byte) 123)) ;
629 params.add(new Short((short) 234)) ;
630 params.add(new Integer(12345)) ;
631 params.add(new Long(23456)) ;
632 params.add(new Float(1.234)) ;
633 params.add(new Double(2.345)) ;
634 params.add(new byte[] {1, 2, 3}) ;
635 Date d = new Date();
636 d.Day = 26; d.Month = 1; d.Year = 2001;
637 params.add(d) ;
638 Time t = new Time();
639 t.Hours = 1; t.NanoSeconds = 123456789; t.Minutes = 25; t.Seconds = 14;
640 params.add(t) ;
641 DateTime dt = new DateTime();
642 dt.Day = 26; dt.Month = 1; dt.Year = 2001; dt.Hours = 1;
643 dt.NanoSeconds = 123456789; dt.Minutes = 25; dt.Seconds = 14;
644 params.add(dt) ;
645 tEnv.addObjRelation("XParameters.ParamValues", params);
647 // Adding relation for XCompletedExecution
648 tEnv.addObjRelation("InteractionHandlerChecker", new InteractionHandlerImpl());
650 // Adding for XWarningSupplier
651 tEnv.addObjRelation("CheckWarningsSupplier", new Boolean(isMySQLDB));
653 // Adding relation for XDatabaseParameterBroadcaster
654 tEnv.addObjRelation("ParameterListenerChecker", new ODatabaseForm.ParameterListenerImpl());
655 XPropertySet xSetProp = UnoRuntime.queryInterface
656 (XPropertySet.class, oObj) ;
657 try {
658 xSetProp.setPropertyValue("DataSourceName", dbSourceName) ;
659 if(isMySQLDB) {
660 xSetProp.setPropertyValue("Command", "SELECT Column0 FROM soffice_test_table WHERE ( ( Column0 = :param1 ) )");
662 else {
663 xSetProp.setPropertyValue("Command", "SELECT \"_TEXT\" FROM \"ODatabaseForm_tmp0\" WHERE ( ( \"_TEXT\" = :param1 ) )");
666 xSetProp.setPropertyValue("CommandType",
667 new Integer(CommandType.COMMAND)) ;
669 catch(Exception e) {
672 // Adding relation for XResultSetUpdate
673 final XRowUpdate xRowUpdate = UnoRuntime.queryInterface(
674 XRowUpdate.class, oObj);
675 final XRow xRow = UnoRuntime.queryInterface(XRow.class, oObj);
677 tEnv.addObjRelation("XResultSetUpdate.UpdateTester",
678 new ifc.sdbc._XResultSetUpdate.UpdateTester() {
679 String lastUpdate = null;
681 public int rowCount() throws SQLException {
682 int prevPos = xResSet.getRow();
683 xResSet.last();
685 int count = xResSet.getRow();
686 xResSet.absolute(prevPos);
688 return count;
691 public void update() throws SQLException {
692 lastUpdate = xRow.getString(1);
693 lastUpdate += "_";
694 xRowUpdate.updateString(1, lastUpdate);
697 public boolean wasUpdated() throws SQLException {
698 String getStr = xRow.getString(1);
700 return lastUpdate.equals(getStr);
703 public int currentRow() throws SQLException {
704 return xResSet.getRow();
708 // Adding relations for XRow as a Vector with all data
709 // of current row of RowSet.
711 ArrayList<Object> rowData = new ArrayList<Object>();
713 for (int i = 0; i < DBTools.TST_TABLE_VALUES[0].length; i++) {
714 rowData.add(DBTools.TST_TABLE_VALUES[0][i]);
717 tEnv.addObjRelation("CurrentRowData", rowData);
719 // Adding relation for XRowUpdate
720 XRow row = UnoRuntime.queryInterface(XRow.class, oObj);
721 tEnv.addObjRelation("XRowUpdate.XRow", row);
724 tEnv.addObjRelation("XPropertyContainer.propertyNotRemovable", "Cycle");
726 PropertyValue propVal = new PropertyValue();
727 propVal.Name = "Name";
728 propVal.Value = "Text since XPropertyAccess";
730 tEnv.addObjRelation("XPropertyAccess.propertyToChange", propVal);
732 return tEnv;
733 } // finish method getTestEnvironment
736 * Closes connection of <code>RowSet</code> instance created.
738 protected void cleanup(TestParameters Param, PrintWriter log) {
739 log.println("closing connection...");
740 try {
741 conn.close();
742 } catch (com.sun.star.uno.Exception e) {
743 log.println("Can't close the connection");
744 e.printStackTrace(log);
745 } catch (com.sun.star.lang.DisposedException e) {
746 log.println("Connection was already closed. It's OK.");
750 log.println("closing data source...");
751 try {
752 XCloseable closer = UnoRuntime.queryInterface(
753 XCloseable.class, dbSrc);
754 closer.close(true);
755 } catch (com.sun.star.util.CloseVetoException e) {
756 log.println("couldn't close data source");
757 } catch (com.sun.star.lang.DisposedException e) {
758 log.println("couldn't close data source");
762 log.println("closing document...");
764 try {
765 XCloseable closer = UnoRuntime.queryInterface(
766 XCloseable.class, xTextDoc);
767 closer.close(true);
768 } catch (com.sun.star.util.CloseVetoException e) {
769 log.println("couldn't close document");
770 } catch (com.sun.star.lang.DisposedException e) {
771 log.println("couldn't close document");
774 log.println("revoking data source...");
775 try {
776 dbTools.revokeDB(dbSourceName);
777 } catch (com.sun.star.container.NoSuchElementException e){
778 } catch (com.sun.star.uno.Exception e) {
779 log.println("Error while object test cleaning up :");
780 e.printStackTrace(log);
781 throw new StatusException("Error while object test cleaning up", e);
786 * Implementation of interface _XDatabaseParameterBroadcaster.CheckParameterListener
787 * for the XDatabaseParameterBroadcaster test
788 * @see ifc.form._XDatabaseParameterBroadcaster
790 public class ParameterListenerImpl implements _XDatabaseParameterBroadcaster.CheckParameterListener {
791 boolean listenerWasCalled = false;
792 PrintWriter log = new PrintWriter(System.out);
795 * Return true, if the listener was called, false otherwise.
796 * @return True, if any other method of the listener was called.
798 public boolean checkListener() {
799 return listenerWasCalled;
803 * Take the DataBaseParameterEvent and fill it with a meaningful value.
804 * @param e The database parameter that will be filled with a value.
805 * @return True, if the value could be filled.
807 public boolean approveParameter(DatabaseParameterEvent e) {
808 log.println("### ParameterListenerImpl: approve called.");
809 XIndexAccess params = e.Parameters;
810 int count = params.getCount();
811 try {
812 for(int i=0; i<count; i++) {
813 log.println("### _XDatabaseParameterBroadcaster.ParameterListenerImpl: Parameter "+i+": "+params.getByIndex(i));
814 XPropertySet xProp = UnoRuntime.queryInterface(XPropertySet.class, params.getByIndex(i));
815 log.println("### _XDatabaseParameterBroadcaster.ParameterListenerImpl: Parameter Name: '"+xProp.getPropertyValue("Name") + "' is set to Value '1'");
816 xProp.setPropertyValue("Value", new Integer(1));
817 listenerWasCalled = true;
820 catch(Exception eI) {
821 log.println("### _XDatabaseParameterBroadcaster.ParameterListenerImpl: Exception!");
822 eI.printStackTrace(log);
823 return false;
825 return true;
829 * Dummy implemetnation. Do nothing, just log
830 * @param o Ignore.
832 public void disposing(EventObject o) {
833 log.println("### _XDatabaseParameterBroadcaster.ParameterListenerImpl: disposing");
837 * Set a log writer, so messages go to log instead of Standard.out
838 * @param log The log messages get printed to.
840 public void setLog(PrintWriter log) {
841 this.log = log;
848 * Implementation of interface _XCompletedExecution.CheckInteractionHandler
849 * for the XCompletedExecution test
850 * @see ifc.sdb._XCompletedExecution
852 public class InteractionHandlerImpl implements _XCompletedExecution.CheckInteractionHandler {
853 private boolean handlerWasUsed = false;
854 private PrintWriter log = new PrintWriter(System.out);
856 public boolean checkInteractionHandler() {
857 return handlerWasUsed;
860 public void handle(XInteractionRequest xInteractionRequest) {
861 log.println("### _XCompletedExecution.InteractionHandlerImpl: handle called.");
862 handlerWasUsed = true;
864 Object o = xInteractionRequest.getRequest();
865 ParametersRequest req = (ParametersRequest)o;
866 XIndexAccess params = req.Parameters;
867 int count = params.getCount();
868 try {
869 for(int i=0; i<count; i++) {
870 params.getByIndex(i);
871 log.println("### _XCompletedExecution.InteractionHandlerImpl: Parameter "+i+": "+params.getByIndex(i));
872 XPropertySet xProp = UnoRuntime.queryInterface(XPropertySet.class, params.getByIndex(i));
873 log.println("### _XCompletedExecution.InteractionHandlerImpl: Parameter Name: '"+xProp.getPropertyValue("Name") + "' is set to Value '1'");
874 xProp.setPropertyValue("Value", new Integer(1));
875 handlerWasUsed = true;
878 catch(Exception eI) {
879 log.println("### _XCompletedExecution.InteractionHandlerImpl: Exception!");
880 eI.printStackTrace(log);
884 public void setLog(PrintWriter log) {
885 this.log = log;
889 } // finish class ODatabaseForm