merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / mod / _forms / ODatabaseForm.java
blob63be62bf5e40b0c9e2532a6ee7b04dcddc538caa
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ODatabaseForm.java,v $
10 * $Revision: 1.10 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 package mod._forms;
32 import java.io.PrintWriter;
33 import java.util.Vector;
35 import lib.Status;
36 import lib.StatusException;
37 import lib.TestCase;
38 import lib.TestEnvironment;
39 import lib.TestParameters;
40 import util.DBTools;
41 import util.DrawTools;
42 import util.FormTools;
43 import util.WriterTools;
44 import util.utils;
46 import com.sun.star.awt.XControl;
47 import com.sun.star.awt.XControlModel;
48 import com.sun.star.beans.PropertyValue;
49 import com.sun.star.beans.XPropertySet;
50 import com.sun.star.container.XIndexAccess;
51 import com.sun.star.container.XNameContainer;
52 import com.sun.star.container.XNamed;
53 import com.sun.star.drawing.XControlShape;
54 import com.sun.star.drawing.XShape;
55 import com.sun.star.drawing.XShapes;
56 import com.sun.star.form.DatabaseParameterEvent;
57 import com.sun.star.form.XForm;
58 import com.sun.star.form.XLoadable;
59 import com.sun.star.lang.EventObject;
60 import com.sun.star.lang.XMultiServiceFactory;
61 import com.sun.star.sdb.CommandType;
62 import com.sun.star.sdb.ParametersRequest;
63 import com.sun.star.sdb.RowChangeEvent;
64 import com.sun.star.sdbc.SQLException;
65 import com.sun.star.sdbc.XConnection;
66 import com.sun.star.sdbc.XResultSet;
67 import com.sun.star.sdbc.XResultSetUpdate;
68 import com.sun.star.sdbc.XRow;
69 import com.sun.star.sdbc.XRowSet;
70 import com.sun.star.sdbc.XRowUpdate;
71 import com.sun.star.task.XInteractionRequest;
72 import com.sun.star.text.XTextDocument;
73 import com.sun.star.uno.Any;
74 import com.sun.star.uno.AnyConverter;
75 import com.sun.star.uno.Type;
76 import com.sun.star.uno.UnoRuntime;
77 import com.sun.star.uno.XInterface;
78 import com.sun.star.util.Date;
79 import com.sun.star.util.DateTime;
80 import com.sun.star.util.Time;
81 import com.sun.star.util.XCloseable;
82 import com.sun.star.view.XControlAccess;
83 import ifc.form._XDatabaseParameterBroadcaster;
84 import ifc.sdb._XCompletedExecution;
87 /**
88 * Test for object which is represented by service
89 * <code>com.sun.star.form.component.DatabaseForm</code>. <p>
91 * Object implements the following interfaces :
92 * <ul>
93 * <li> <code>com::sun::star::script::XEventAttacherManager</code></li>
94 * <li> <code>com::sun::star::container::XElementAccess</code></li>
95 * <li> <code>com::sun::star::sdbcx::ResultSet</code></li>
96 * <li> <code>com::sun::star::container::XChild</code></li>
97 * <li> <code>com::sun::star::sdbc::XResultSetUpdate</code></li>
98 * <li> <code>com::sun::star::sdb::XResultSetAccess</code></li>
99 * <li> <code>com::sun::star::form::FormComponent</code></li>
100 * <li> <code>com::sun::star::form::component::DataForm</code></li>
101 * <li> <code>com::sun::star::sdbc::XResultSetMetaDataSupplier</code></li>
102 * <li> <code>com::sun::star::container::XEnumerationAccess</code></li>
103 * <li> <code>com::sun::star::sdbcx::XDeleteRows</code></li>
104 * <li> <code>com::sun::star::sdb::RowSet</code></li>
105 * <li> <code>com::sun::star::lang::XComponent</code></li>
106 * <li> <code>com::sun::star::sdbc::XRowSet</code></li>
107 * <li> <code>com::sun::star::sdbc::XRowUpdate</code></li>
108 * <li> <code>com::sun::star::form::XLoadable</code></li>
109 * <li> <code>com::sun::star::container::XNamed</code></li>
110 * <li> <code>com::sun::star::container::XIndexReplace</code></li>
111 * <li> <code>com::sun::star::io::XPersistObject</code></li>
112 * <li> <code>com::sun::star::container::XNameReplace</code></li>
113 * <li> <code>com::sun::star::container::XIndexContainer</code></li>
114 * <li> <code>com::sun::star::container::XNameAccess</code></li>
115 * <li> <code>com::sun::star::sdbc::XParameters</code></li>
116 * <li> <code>com::sun::star::util::XCancellable</code></li>
117 * <li> <code>com::sun::star::form::XReset</code></li>
118 * <li> <code>com::sun::star::sdbc::XCloseable</code></li>
119 * <li> <code>com::sun::star::sdbcx::XColumnsSupplier</code></li>
120 * <li> <code>com::sun::star::sdb::XRowSetApproveBroadcaster</code></li>
121 * <li> <code>com::sun::star::sdbc::ResultSet</code></li>
122 * <li> <code>com::sun::star::sdbc::XResultSet</code></li>
123 * <li> <code>com::sun::star::sdbc::XRow</code></li>
124 * <li> <code>com::sun::star::sdbc::XColumnLocate</code></li>
125 * <li> <code>com::sun::star::awt::XTabControllerModel</code></li>
126 * <li> <code>com::sun::star::container::XIndexAccess</code></li>
127 * <li> <code>com::sun::star::form::XSubmit</code></li>
128 * <li> <code>com::sun::star::form::component::HTMLForm</code></li>
129 * <li> <code>com::sun::star::sdbcx::XRowLocate</code></li>
130 * <li> <code>com::sun::star::sdbc::XWarningsSupplier</code></li>
131 * <li> <code>com::sun::star::container::XNameContainer</code></li>
132 * <li> <code>com::sun::star::beans::XPropertyAccess</code></li>
133 * <li> <code>com::sun::star::beans::XPropertyContainer</code></li>
134 * <li> <code>com::sun::star::beans::XPropertySet</code></li>
135 * <li> <code>com::sun::star::sdbc::RowSet</code></li>
136 * </ul> <p>
138 * This object test <b> is NOT </b> designed to be run in several
139 * threads concurently.
140 * The following parameters in ini-file used by this test:
141 * <ul>
142 * <li><code>test.db.url</code> - URL to MySQL database.
143 * For example: <code>mysql://mercury:3306/api_current</code></li>
144 * <li><code>test.db.user</code> - user for MySQL database</li>
145 * <li><code>test.db.password</code> - password for MySQL database</li>
146 * </ul><p>
148 * @see com.sun.star.script.XEventAttacherManager
149 * @see com.sun.star.container.XElementAccess
150 * @see com.sun.star.sdbcx.ResultSet
151 * @see com.sun.star.container.XChild
152 * @see com.sun.star.sdbc.XResultSetUpdate
153 * @see com.sun.star.sdb.XResultSetAccess
154 * @see com.sun.star.form.FormComponent
155 * @see com.sun.star.form.component.DataForm
156 * @see com.sun.star.sdbc.XResultSetMetaDataSupplier
157 * @see com.sun.star.container.XEnumerationAccess
158 * @see com.sun.star.sdbcx.XDeleteRows
159 * @see com.sun.star.sdb.RowSet
160 * @see com.sun.star.lang.XComponent
161 * @see com.sun.star.sdbc.XRowSet
162 * @see com.sun.star.sdbc.XRowUpdate
163 * @see com.sun.star.form.XLoadable
164 * @see com.sun.star.container.XNamed
165 * @see com.sun.star.container.XIndexReplace
166 * @see com.sun.star.io.XPersistObject
167 * @see com.sun.star.container.XNameReplace
168 * @see com.sun.star.container.XIndexContainer
169 * @see com.sun.star.container.XNameAccess
170 * @see com.sun.star.sdbc.XParameters
171 * @see com.sun.star.util.XCancellable
172 * @see com.sun.star.form.XReset
173 * @see com.sun.star.sdbc.XCloseable
174 * @see com.sun.star.sdbcx.XColumnsSupplier
175 * @see com.sun.star.sdb.XRowSetApproveBroadcaster
176 * @see com.sun.star.sdbc.ResultSet
177 * @see com.sun.star.sdbc.XResultSet
178 * @see com.sun.star.sdbc.XRow
179 * @see com.sun.star.sdbc.XColumnLocate
180 * @see com.sun.star.awt.XTabControllerModel
181 * @see com.sun.star.container.XIndexAccess
182 * @see com.sun.star.form.XSubmit
183 * @see com.sun.star.form.component.HTMLForm
184 * @see com.sun.star.sdbcx.XRowLocate
185 * @see com.sun.star.sdbc.XWarningsSupplier
186 * @see com.sun.star.container.XNameContainer
187 * @see com.sun.star.beans.XPropertySet
188 * @see com.sun.star.sdbc.RowSet
189 * @see ifc.script._XEventAttacherManager
190 * @see ifc.container._XElementAccess
191 * @see ifc.sdbcx._ResultSet
192 * @see ifc.container._XChild
193 * @see ifc.sdbc._XResultSetUpdate
194 * @see ifc.sdb._XResultSetAccess
195 * @see ifc.form._FormComponent
196 * @see ifc.form.component._DataForm
197 * @see ifc.sdbc._XResultSetMetaDataSupplier
198 * @see ifc.container._XEnumerationAccess
199 * @see ifc.sdbcx._XDeleteRows
200 * @see ifc.sdb._RowSet
201 * @see ifc.lang._XComponent
202 * @see ifc.sdbc._XRowSet
203 * @see ifc.sdbc._XRowUpdate
204 * @see ifc.form._XLoadable
205 * @see ifc.container._XNamed
206 * @see ifc.container._XIndexReplace
207 * @see ifc.io._XPersistObject
208 * @see ifc.container._XNameReplace
209 * @see ifc.container._XIndexContainer
210 * @see ifc.container._XNameAccess
211 * @see ifc.sdbc._XParameters
212 * @see ifc.util._XCancellable
213 * @see ifc.form._XReset
214 * @see ifc.sdbc._XCloseable
215 * @see ifc.sdbcx._XColumnsSupplier
216 * @see ifc.sdb._XRowSetApproveBroadcaster
217 * @see ifc.sdbc._ResultSet
218 * @see ifc.sdbc._XResultSet
219 * @see ifc.sdbc._XRow
220 * @see ifc.sdbc._XColumnLocate
221 * @see ifc.awt._XTabControllerModel
222 * @see ifc.container._XIndexAccess
223 * @see ifc.form._XSubmit
224 * @see ifc.form.component._HTMLForm
225 * @see ifc.sdbcx._XRowLocate
226 * @see ifc.sdbc._XWarningsSupplier
227 * @see ifc.container._XNameContainer
228 * @see ifc.beans._XPropertyAccess
229 * @see ifc.beans._XPropertyContainer
230 * @see ifc.beans._XPropertySet
231 * @see ifc.sdbc._RowSet
233 public class ODatabaseForm extends TestCase {
234 protected final static String dbSourceName = "ODatabaseFormDataSource";
235 private static int uniqueSuffix = 0;
236 private static String origDB = null;
237 private static String tmpDir = null;
238 protected XTextDocument xTextDoc = null;
239 private DBTools dbTools = null;
240 String tableName = null;
241 DBTools.DataSourceInfo srcInf = null;
242 boolean isMySQLDB = false;
243 protected XConnection conn = null;
244 private Object dbSrc = null;
246 protected void initialize(TestParameters tParam, PrintWriter log) {
247 //log.println( "creating a draw document" );
248 //xTextDoc = WriterTools.createTextDoc(t((XMultiServiceFactory) Param.getMSF));
249 tmpDir = utils.getOfficeTemp(((XMultiServiceFactory) tParam.getMSF()));
251 origDB = util.utils.getFullTestDocName("TestDB/testDB.dbf");
253 dbTools = new DBTools(((XMultiServiceFactory) tParam.getMSF()));
255 // creating DataSource and registering it in DatabaseContext
256 String dbURL = (String) tParam.get("test.db.url");
257 String dbUser = (String) tParam.get("test.db.user");
258 String dbPassword = (String) tParam.get("test.db.password");
260 log.println("Creating and registering DataSource ...");
261 srcInf = dbTools.newDataSourceInfo();
263 if ((dbURL != null) && (dbUser != null) && (dbPassword != null)) {
264 isMySQLDB = true;
265 log.println("dbURL = " + dbURL);
266 log.println("dbUSER = " + dbUser);
267 log.println("dbPASSWORD = " + dbPassword);
269 //DataSource for mysql db
270 try {
271 tableName = "soffice_test_table";
272 srcInf.URL = "jdbc:" + dbURL;
273 srcInf.IsPasswordRequired = new Boolean(true);
274 srcInf.Password = dbPassword;
275 srcInf.User = dbUser;
277 PropertyValue[] propInfo = new PropertyValue[1];
278 propInfo[0] = new PropertyValue();
279 propInfo[0].Name = "JavaDriverClass";
280 // propInfo[0].Value = "org.gjt.mm.mysql.Driver";
281 propInfo[0].Value = "util.dddriver.Driver";
282 srcInf.Info = propInfo;
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("Error while object test" +
290 " initialization", e);
292 } else {
293 //DataSource for sdbc db
294 try {
295 String myDbUrl = "sdbc:dbase:" + DBTools.dirToUrl(tmpDir);
296 srcInf.URL = myDbUrl;
298 log.println("try to register '"+myDbUrl+"' as '"+dbSourceName+"'");
300 dbSrc = srcInf.getDataSourceService();
301 dbTools.reRegisterDB(dbSourceName, dbSrc);
302 } catch (com.sun.star.uno.Exception e) {
303 log.println("Error while object test initialization :");
304 e.printStackTrace(log);
305 throw new StatusException(
306 "Error while object test initialization", e);
309 String oldF = null;
310 String newF = null;
312 do {
313 tableName = "ODatabaseForm_tmp" + uniqueSuffix;
314 oldF = utils.getFullURL(origDB);
315 newF = utils.getOfficeTemp((XMultiServiceFactory) tParam.getMSF()) + tableName +
316 ".dbf";
317 } while (!utils.overwriteFile(((XMultiServiceFactory) tParam.getMSF()), oldF, newF) &&
318 (uniqueSuffix++ < 50));
323 * * creating a Testenvironment for the interfaces to be tested
325 protected synchronized TestEnvironment createTestEnvironment(TestParameters Param,
326 PrintWriter log) {
327 if (xTextDoc != null) {
328 try {
329 XCloseable closer = (XCloseable) UnoRuntime.queryInterface(
330 XCloseable.class, xTextDoc);
331 closer.close(true);
332 } catch (com.sun.star.util.CloseVetoException e) {
333 log.println("couldn't close document");
334 } catch (com.sun.star.lang.DisposedException e) {
335 log.println("couldn't close document");
338 log.println("Existing document disposed");
341 log.println("creating a text document");
342 xTextDoc = WriterTools.createTextDoc(((XMultiServiceFactory) Param.getMSF()));
344 //initialize test table
345 if (isMySQLDB) {
346 try {
347 dbTools.initTestTableUsingJDBC(tableName, srcInf);
348 } catch (java.sql.SQLException e) {
349 e.printStackTrace(log);
350 throw new StatusException(Status.failed("Couldn't " + " init test table. SQLException..."));
351 } catch (java.lang.ClassNotFoundException e) {
352 throw new StatusException(Status.failed("Couldn't " + "register mysql driver"));
356 XInterface oObj = null;
357 XShapes oShapes = null;
358 XInterface oInstance = null;
359 XConnection connection = null;
362 // creation of testobject here
363 // first we write what we are intend to do to log file
364 log.println("creating a test environment");
366 XNameContainer forms = FormTools.getForms(WriterTools.getDrawPage(
367 xTextDoc));
369 try {
370 String[] formNames = forms.getElementNames();
372 for (int i = 0; i < formNames.length; i++) {
373 log.println("Removing form '" + formNames[i] + "' ...");
374 forms.removeByName(formNames[i]);
376 } catch (com.sun.star.lang.WrappedTargetException e) {
377 e.printStackTrace(log);
378 } catch (com.sun.star.container.NoSuchElementException e) {
379 e.printStackTrace(log);
382 String[] formNames = forms.getElementNames();
383 FormTools.insertForm(xTextDoc, forms, "MyForm");
384 formNames = forms.getElementNames();
386 XLoadable formLoader = null;
388 try {
389 formLoader = FormTools.bindForm(xTextDoc, "MyForm", dbSourceName,
390 tableName);
391 } catch (com.sun.star.uno.Exception e) {
392 log.println("Cann't bind the form to source '" + dbSourceName +
393 "', table '" + tableName + "' :");
394 e.printStackTrace(log);
395 throw new StatusException("Cann't bind a form", e);
399 // DEBUG
400 log.println("Forms before adding controls : ");
401 formNames = forms.getElementNames();
403 for (int i = 0; i < formNames.length; i++) {
404 log.println(" '" + formNames[i] + "'");
407 XControlShape shape1 = null;
408 XControlShape shape2 = null;
410 try {
412 log.println("Elements in the 'MyForm' :");
414 XIndexAccess formElements1 = (XIndexAccess) UnoRuntime.queryInterface(
415 XIndexAccess.class,
416 forms.getByName("MyForm"));
418 for (int i = 0; i < formElements1.getCount(); i++) {
419 XNamed elemName = (XNamed) UnoRuntime.queryInterface(
420 XNamed.class,
421 formElements1.getByIndex(i));
422 log.println(" '" + elemName.getName() + "'");
426 // END DEBUG
427 //put something on the drawpage
428 log.println("inserting some ControlShapes");
429 oShapes = DrawTools.getShapes(WriterTools.getDrawPage(xTextDoc));
430 shape1 = FormTools.createControlShape(xTextDoc, 3000, 4500, 15000,
431 1000, "CommandButton");
432 shape2 = FormTools.createControlShape(xTextDoc, 5000, 3500, 7500,
433 5000, "TextField");
435 XControlShape shape3 = FormTools.createControlShape(xTextDoc, 2000,
436 1500, 1000,
437 1000,
438 "CheckBox");
439 oShapes.add((XShape) shape1);
440 oShapes.add((XShape) shape2);
441 oShapes.add(shape3);
442 } catch (Exception e) {
443 e.printStackTrace(log);
446 log.println("Forms after adding controls : ");
447 formNames = forms.getElementNames();
449 for (int i = 0; i < formNames.length; i++) {
450 log.println(" '" + formNames[i] + "'");
453 try {
454 log.println("Elements in the 'MyForm' :");
456 XIndexAccess formElements1 = (XIndexAccess) UnoRuntime.queryInterface(
457 XIndexAccess.class,
458 forms.getByName("MyForm"));
460 for (int i = 0; i < formElements1.getCount(); i++) {
461 XNamed elemName = (XNamed) UnoRuntime.queryInterface(
462 XNamed.class,
463 formElements1.getByIndex(i));
464 log.println(" '" + elemName.getName() + "'");
466 } catch (Exception e) {
467 e.printStackTrace(log);
470 formLoader.load();
472 try {
473 oObj = (XForm) AnyConverter.toObject(new Type(XForm.class),
474 (FormTools.getForms(
475 WriterTools.getDrawPage(
476 xTextDoc)))
477 .getByName("MyForm"));
479 XPropertySet xSetProp = (XPropertySet) UnoRuntime.queryInterface(
480 XPropertySet.class, oObj);
481 connection = (XConnection) AnyConverter.toObject(
482 new Type(XConnection.class),
483 xSetProp.getPropertyValue("ActiveConnection"));
484 } catch (com.sun.star.uno.Exception e) {
485 log.println("Couldn't get Form");
486 e.printStackTrace(log);
490 // get a control
491 oInstance = FormTools.createControl(xTextDoc, "TextField");
493 log.println("creating a new environment for drawpage object");
495 TestEnvironment tEnv = new TestEnvironment(oObj);
498 // adding relation for closing connection while environment disposing.
499 this.conn = connection;
501 // adding relation for XSubmit
502 XControlModel the_Model = shape2.getControl();
503 XControlAccess the_access = (XControlAccess) UnoRuntime.queryInterface(
504 XControlAccess.class,
505 xTextDoc.getCurrentController());
506 XControl cntrl = null;
508 //now get the OEditControl
509 try {
510 cntrl = the_access.getControl(the_Model);
511 log.println(cntrl.getClass().getName());
512 } catch (com.sun.star.container.NoSuchElementException e) {
513 log.println("Couldn't get OEditControl");
514 e.printStackTrace(log);
515 throw new StatusException("Couldn't get OEditControl", e);
518 XResultSet the_set = (XResultSet) UnoRuntime.queryInterface(
519 XResultSet.class, oObj);
521 try {
522 the_set.first();
523 } catch (SQLException e) {
524 log.println("Cann't move cursor to the first row.");
525 e.printStackTrace();
526 throw new StatusException("Can't move cursor to the first row.", e);
529 tEnv.addObjRelation("Model1", shape1.getControl());
530 tEnv.addObjRelation("Model2", shape2.getControl());
533 // adding an object for XNameReplace testing
534 log.println("adding oInstace as obj relation to environment");
535 tEnv.addObjRelation("INSTANCE", oInstance);
538 // INDEX : _XNameContainer
539 log.println("adding INDEX as obj relation to environment");
540 tEnv.addObjRelation("INDEX", "0");
543 // INDEX : _XNameReplace
544 log.println("adding NameReplaceIndex as obj relation to environment");
545 tEnv.addObjRelation("XNameReplaceINDEX", "2");
548 // INSTANCEn : _XNameContainer; _XNameReplace
549 log.println("adding INSTANCEn as obj relation to environment");
551 //XComponent xComp = (XComponent)
552 // UnoRuntime.queryInterface(XComponent.class, xDrawDoc);
553 String tc = (String) Param.get("THRCNT");
554 int THRCNT = 1;
556 if (tc != null) {
557 THRCNT = Integer.parseInt(tc);
560 for (int n = 1; n < (2 * (THRCNT + 1)); n++) {
561 log.println("adding INSTANCE" + n +
562 " as obj relation to environment");
563 tEnv.addObjRelation("INSTANCE" + n,
564 FormTools.createControl(xTextDoc, "CheckBox"));
568 // adding relation for XNameContainer
569 tEnv.addObjRelation("XNameContainer.AllowDuplicateNames", new Object());
572 // adding relation for XPersistObject
573 tEnv.addObjRelation("OBJNAME", "stardiv.one.form.component.Form");
575 if (the_set != null) {
576 log.println("The Form has a not empty ResultSet");
579 // Adding obj relation for XRowSetApproveBroadcaster test
580 final XResultSet xResSet = (XResultSet) UnoRuntime.queryInterface(
581 XResultSet.class, oObj);
582 final XResultSetUpdate xResSetUpdate = (XResultSetUpdate) UnoRuntime.queryInterface(
583 XResultSetUpdate.class,
584 oObj);
585 final XRowSet xRowSet = (XRowSet) UnoRuntime.queryInterface(
586 XRowSet.class, oObj);
587 final PrintWriter logF = log;
588 tEnv.addObjRelation("XRowSetApproveBroadcaster.ApproveChecker",
589 new ifc.sdb._XRowSetApproveBroadcaster.RowSetApproveChecker() {
590 public void moveCursor() {
591 try {
592 xResSet.beforeFirst();
593 xResSet.afterLast();
594 } catch (com.sun.star.sdbc.SQLException e) {
595 logF.println("### _XRowSetApproveBroadcaster." + "RowSetApproveChecker.moveCursor() :");
596 e.printStackTrace(logF);
600 public RowChangeEvent changeRow() {
601 try {
602 xResSet.first();
604 XRowUpdate row = (XRowUpdate) UnoRuntime.queryInterface(
605 XRowUpdate.class, xResSet);
606 row.updateString(1, "1");
607 xResSetUpdate.updateRow();
608 } catch (com.sun.star.sdbc.SQLException e) {
609 logF.println("### _XRowSetApproveBroadcaster." + "RowSetApproveChecker.changeRow() :");
610 e.printStackTrace(logF);
613 RowChangeEvent ev = new RowChangeEvent();
614 ev.Action = com.sun.star.sdb.RowChangeAction.UPDATE;
615 ev.Rows = 1;
617 return ev;
620 public void changeRowSet() {
621 try {
622 xRowSet.execute();
623 } catch (com.sun.star.sdbc.SQLException e) {
624 logF.println("### _XRowSetApproveBroadcaster." + "RowSetApproveChecker.changeRowSet() :");
625 e.printStackTrace(logF);
631 // Adding relation for XColumnLocate test
632 tEnv.addObjRelation("XColumnLocate.ColumnName", DBTools.TST_STRING_F);
634 // Adding relation for XParameters ifc test
635 Vector params = new Vector();
638 /***** statement parameter types and their initial
639 values must be added here as relation. */
640 params.add(new String("SAU99")) ;
641 params.add(new Boolean(false)) ;
642 params.add(new Byte((byte) 123)) ;
643 params.add(new Short((short) 234)) ;
644 params.add(new Integer(12345)) ;
645 params.add(new Long(23456)) ;
646 params.add(new Float(1.234)) ;
647 params.add(new Double(2.345)) ;
648 params.add(new byte[] {1, 2, 3}) ;
649 Date d = new Date();
650 d.Day = 26; d.Month = 1; d.Year = 2001;
651 params.add(d) ;
652 Time t = new Time();
653 t.Hours = 1; t.HundredthSeconds = 12; t.Minutes = 25; t.Seconds = 14;
654 params.add(t) ;
655 DateTime dt = new DateTime();
656 dt.Day = 26; dt.Month = 1; dt.Year = 2001; dt.Hours = 1;
657 dt.HundredthSeconds = 12; dt.Minutes = 25; dt.Seconds = 14;
658 params.add(dt) ;
659 tEnv.addObjRelation("XParameters.ParamValues", params);
661 // Adding relation for XCompletedExecution
662 tEnv.addObjRelation("InteractionHandlerChecker", new InteractionHandlerImpl());
664 // Adding for XWarningSupplier
665 tEnv.addObjRelation("CheckWarningsSupplier", new Boolean(isMySQLDB));
667 // Adding relation for XDatabaseParameterBroadcaster
668 tEnv.addObjRelation("ParameterListenerChecker", new ODatabaseForm.ParameterListenerImpl());
669 XPropertySet xSetProp = (XPropertySet) UnoRuntime.queryInterface
670 (XPropertySet.class, oObj) ;
671 try {
672 xSetProp.setPropertyValue("DataSourceName", dbSourceName) ;
673 if(isMySQLDB) {
674 xSetProp.setPropertyValue("Command", "SELECT Column0 FROM soffice_test_table WHERE ( ( Column0 = :param1 ) )");
676 else {
677 xSetProp.setPropertyValue("Command", "SELECT \"_TEXT\" FROM \"ODatabaseForm_tmp0\" WHERE ( ( \"_TEXT\" = :param1 ) )");
680 xSetProp.setPropertyValue("CommandType",
681 new Integer(CommandType.COMMAND)) ;
683 catch(Exception e) {
686 // Adding relation for XResultSetUpdate
687 final XRowUpdate xRowUpdate = (XRowUpdate) UnoRuntime.queryInterface(
688 XRowUpdate.class, oObj);
689 final XRow xRow = (XRow) UnoRuntime.queryInterface(XRow.class, oObj);
691 tEnv.addObjRelation("XResultSetUpdate.UpdateTester",
692 new ifc.sdbc._XResultSetUpdate.UpdateTester() {
693 String lastUpdate = null;
695 public int rowCount() throws SQLException {
696 int prevPos = xResSet.getRow();
697 xResSet.last();
699 int count = xResSet.getRow();
700 xResSet.absolute(prevPos);
702 return count;
705 public void update() throws SQLException {
706 lastUpdate = xRow.getString(1);
707 lastUpdate += "_";
708 xRowUpdate.updateString(1, lastUpdate);
711 public boolean wasUpdated() throws SQLException {
712 String getStr = xRow.getString(1);
714 return lastUpdate.equals(getStr);
717 public int currentRow() throws SQLException {
718 return xResSet.getRow();
722 // Adding relations for XRow as a Vector with all data
723 // of current row of RowSet.
725 Vector rowData = new Vector();
727 for (int i = 0; i < DBTools.TST_TABLE_VALUES[0].length; i++) {
728 rowData.add(DBTools.TST_TABLE_VALUES[0][i]);
731 tEnv.addObjRelation("CurrentRowData", rowData);
733 // Adding relation for XRowUpdate
734 XRow row = (XRow) UnoRuntime.queryInterface(XRow.class, oObj);
735 tEnv.addObjRelation("XRowUpdate.XRow", row);
738 tEnv.addObjRelation("XPropertyContainer.propertyNotRemovable", "Cycle");
740 PropertyValue propVal = new PropertyValue();
741 propVal.Name = "Name";
742 propVal.Value = "Text since XPropertyAccess";
744 tEnv.addObjRelation("XPropertyAccess.propertyToChange", propVal);
746 return tEnv;
747 } // finish method getTestEnvironment
750 * Closes connection of <code>RowSet</code> instance created.
752 protected void cleanup(TestParameters Param, PrintWriter log) {
753 log.println("closing connection...");
754 try {
755 conn.close();
756 } catch (com.sun.star.uno.Exception e) {
757 log.println("Can't close the connection");
758 e.printStackTrace(log);
759 } catch (com.sun.star.lang.DisposedException e) {
760 log.println("Connection was already closed. It's OK.");
764 log.println("closing data source...");
765 try {
766 XCloseable closer = (XCloseable) UnoRuntime.queryInterface(
767 XCloseable.class, dbSrc);
768 closer.close(true);
769 } catch (com.sun.star.util.CloseVetoException e) {
770 log.println("couldn't close data source");
771 } catch (com.sun.star.lang.DisposedException e) {
772 log.println("couldn't close data source");
776 log.println("closing document...");
778 try {
779 XCloseable closer = (XCloseable) UnoRuntime.queryInterface(
780 XCloseable.class, xTextDoc);
781 closer.close(true);
782 } catch (com.sun.star.util.CloseVetoException e) {
783 log.println("couldn't close document");
784 } catch (com.sun.star.lang.DisposedException e) {
785 log.println("couldn't close document");
788 log.println("revoking data source...");
789 try {
790 dbTools.revokeDB(dbSourceName);
791 } catch (com.sun.star.container.NoSuchElementException e){
792 } catch (com.sun.star.uno.Exception e) {
793 log.println("Error while object test cleaning up :");
794 e.printStackTrace(log);
795 throw new StatusException("Error while object test cleaning up", e);
800 * Implementation of interface _XDatabaseParameterBroadcaster.CheckParameterListener
801 * for the XDatabaseParameterBroadcaster test
802 * @see ifc.form._XDatabaseParameterBroadcaster
804 public class ParameterListenerImpl implements _XDatabaseParameterBroadcaster.CheckParameterListener {
805 boolean listenerWasCalled = false;
806 PrintWriter log = new PrintWriter(System.out);
808 /**
809 * Return true, if the listener was called, false otherwise.
810 * @return True, if any other method of the listener was called.
812 public boolean checkListener() {
813 return listenerWasCalled;
817 * Take the DataBaseParameterEvent and fill it with a meaningful value.
818 * @param e The database parameter that will be filled with a value.
819 * @return True, if the value could be filled.
821 public boolean approveParameter(DatabaseParameterEvent e) {
822 log.println("### ParameterListenerImpl: approve called.");
823 XIndexAccess params = e.Parameters;
824 int count = params.getCount();
825 try {
826 for(int i=0; i<count; i++) {
827 log.println("### _XDatabaseParameterBroadcaster.ParameterListenerImpl: Parameter "+i+": "+params.getByIndex(i));
828 XPropertySet xProp = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, params.getByIndex(i));
829 log.println("### _XDatabaseParameterBroadcaster.ParameterListenerImpl: Parameter Name: '"+xProp.getPropertyValue("Name") + "' is set to Value '1'");
830 xProp.setPropertyValue("Value", new Integer(1));
831 listenerWasCalled = true;
834 catch(Exception eI) {
835 log.println("### _XDatabaseParameterBroadcaster.ParameterListenerImpl: Exception!");
836 eI.printStackTrace(log);
837 return false;
839 return true;
843 * Dummy implemetnation. Do nothing, just log
844 * @param o Ignore.
846 public void disposing(EventObject o) {
847 log.println("### _XDatabaseParameterBroadcaster.ParameterListenerImpl: disposing");
851 * Set a log writer, so messages go to log instead of Standard.out
852 * @param log The log messages get printed to.
854 public void setLog(PrintWriter log) {
855 this.log = log;
862 * Implementation of interface _XCompletedExecution.CheckInteractionHandler
863 * for the XCompletedExecution test
864 * @see ifc.sdb._XCompletedExecution
866 public class InteractionHandlerImpl implements _XCompletedExecution.CheckInteractionHandler {
867 private boolean handlerWasUsed = false;
868 private PrintWriter log = new PrintWriter(System.out);
870 public boolean checkInteractionHandler() {
871 return handlerWasUsed;
874 public void handle(XInteractionRequest xInteractionRequest) {
875 log.println("### _XCompletedExecution.InteractionHandlerImpl: handle called.");
876 handlerWasUsed = true;
878 Object o = xInteractionRequest.getRequest();
879 ParametersRequest req = (ParametersRequest)o;
880 XIndexAccess params = req.Parameters;
881 int count = params.getCount();
882 try {
883 for(int i=0; i<count; i++) {
884 Object aObject = params.getByIndex(i);
885 Any any = (Any)aObject;
886 log.println("### _XCompletedExecution.InteractionHandlerImpl: Parameter "+i+": "+params.getByIndex(i));
887 XPropertySet xProp = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, params.getByIndex(i));
888 log.println("### _XCompletedExecution.InteractionHandlerImpl: Parameter Name: '"+xProp.getPropertyValue("Name") + "' is set to Value '1'");
889 xProp.setPropertyValue("Value", new Integer(1));
890 handlerWasUsed = true;
893 catch(Exception eI) {
894 log.println("### _XCompletedExecution.InteractionHandlerImpl: Exception!");
895 eI.printStackTrace(log);
899 public void setLog(PrintWriter log) {
900 this.log = log;
904 } // finish class ODatabaseForm