Update ooo320-m1
[ooovba.git] / qadevOOo / tests / java / ifc / sdbc / _XParameters.java
blob5dfa40f8149133ddf11a818ffc30d92f7ef1e830
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: _XParameters.java,v $
10 * $Revision: 1.5 $
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 ************************************************************************/
31 package ifc.sdbc;
33 import java.util.Vector;
35 import lib.MultiMethodTest;
36 import lib.Status;
38 import com.sun.star.io.XDataInputStream;
39 import com.sun.star.io.XInputStream;
40 import com.sun.star.io.XTextInputStream;
41 import com.sun.star.lang.XMultiServiceFactory;
42 import com.sun.star.sdbc.DataType;
43 import com.sun.star.sdbc.SQLException;
44 import com.sun.star.sdbc.XParameters;
45 import com.sun.star.uno.UnoRuntime;
46 import com.sun.star.util.Date;
47 import com.sun.star.util.DateTime;
48 import com.sun.star.util.Time;
50 /**
51 /**
52 * Testing <code>com.sun.star.sdbc.XParameters</code>
53 * interface methods :
54 * <ul>
55 * <li><code> setNull()</code></li>
56 * <li><code> setObjectNull()</code></li>
57 * <li><code> setBoolean()</code></li>
58 * <li><code> setByte()</code></li>
59 * <li><code> setShort()</code></li>
60 * <li><code> setInt()</code></li>
61 * <li><code> setLong()</code></li>
62 * <li><code> setFloat()</code></li>
63 * <li><code> setDouble()</code></li>
64 * <li><code> setString()</code></li>
65 * <li><code> setBytes()</code></li>
66 * <li><code> setDate()</code></li>
67 * <li><code> setTime()</code></li>
68 * <li><code> setTimestamp()</code></li>
69 * <li><code> setBinaryStream()</code></li>
70 * <li><code> setCharacterStream()</code></li>
71 * <li><code> setObject()</code></li>
72 * <li><code> setObjectWithInfo()</code></li>
73 * <li><code> setRef()</code></li>
74 * <li><code> setBlob()</code></li>
75 * <li><code> setClob()</code></li>
76 * <li><code> setArray()</code></li>
77 * <li><code> clearParameters()</code></li>
78 * </ul> <p>
79 * Object relations required :
80 * <ul>
81 * <li> <code>'XParameters.ParamValues'</code> : is a
82 * <code>java.util.Vector</code> object
83 * that contains parameter types and values of the statement. Each
84 * element of vector corresponds to appropriate parameter (element
85 * with index 0 to parameter #1, 1 -> #2, etc.). <p>
86 * The following <code>XParameters</code> methods correspond to classes
87 * in Vector :
88 * <ul>
89 * <li> <code>setBinaryStream</code> -
90 * <code>com.sun.star.io.XDataInputStream</code> class. </li>
91 * <li> <code>setCharacterStream</code> -
92 * <code>com.sun.star.io.XTextInputStream</code> class. </li>
93 * <li> <code>setObject</code> -
94 * <code>java.lang.Object[]</code> class, the element with
95 * index 0 must be used. </li>
96 * </ul>
97 * Other methods uses types of their arguments (i.e.
98 * <code>java.lang.String</code>
99 * for <code>setString</code> method, <code>com.sun.star.sdbc.XRef</code>
100 * for <code>setRef</code> method).
101 * </li>
102 * </ul>
103 * @see com.sun.star.sdbc.XParameters
105 public class _XParameters extends MultiMethodTest {
107 // oObj filled by MultiMethodTest
108 public XParameters oObj = null ;
110 private Vector data = null ;
113 * Gets object relation
115 public void before() {
116 data = (Vector) tEnv.getObjRelation("XParameters.ParamValues") ;
117 if (data == null) {
118 log.println("!!! Relation not found !!!") ;
123 * Sets String parameter (if exists) to SQL NULL value. <p>
124 * Has OK status if no exceptions occured.
126 public void _setNull() {
127 boolean result = true ;
128 int idx = findParamOfType(String.class) ;
129 if (idx < 0) log.println("Type not found in relation: not tested");
130 else {
131 try {
132 oObj.setNull(idx, DataType.VARCHAR) ;
133 } catch (SQLException e) {
134 log.println("Unexpected SQL exception:") ;
135 log.println(e) ;
136 result = false ;
140 tRes.tested("setNull()", result) ;
143 public void _setObjectNull() {
145 !!! TO DO !!!
147 tRes.tested("setObjectNull()", Status.skipped(true)) ;
151 * Sets String parameter (if exists) to new value. <p>
152 * Has OK status if no exceptions occured.
154 public void _setString() {
155 boolean result = true ;
156 int idx = findParamOfType(String.class) ;
157 if (idx < 0) log.println("Type not found in relation: not tested");
158 else {
159 try {
160 oObj.setString(idx, "XParameters") ;
161 } catch (SQLException e) {
162 log.println("Unexpected SQL exception:") ;
163 log.println(e) ;
164 result = false ;
168 tRes.tested("setString()", result) ;
172 * Sets parameter (if exists) to new value. <p>
173 * Has OK status if no exceptions occured.
175 public void _setBoolean() {
176 boolean result = true ;
177 int idx = findParamOfType(Boolean.class) ;
178 if (idx < 0) log.println("Type not found in relation: not tested");
179 else {
180 try {
181 oObj.setBoolean(idx, true) ;
182 } catch (SQLException e) {
183 log.println("Unexpected SQL exception:") ;
184 log.println(e) ;
185 result = false ;
189 tRes.tested("setBoolean()", result) ;
193 * Sets parameter (if exists) to new value. <p>
194 * Has OK status if no exceptions occured.
196 public void _setByte() {
197 boolean result = true ;
198 int idx = findParamOfType(Byte.class) ;
199 if (idx < 0) log.println("Type not found in relation: not tested");
200 else {
201 try {
202 oObj.setByte(idx, (byte)122) ;
203 } catch (SQLException e) {
204 log.println("Unexpected SQL exception:") ;
205 log.println(e) ;
206 result = false ;
210 tRes.tested("setByte()", result) ;
214 * Sets parameter (if exists) to new value. <p>
215 * Has OK status if no exceptions occured.
217 public void _setShort() {
218 boolean result = true ;
219 int idx = findParamOfType(Short.class) ;
220 if (idx < 0) log.println("Type not found in relation: not tested");
221 else {
222 try {
223 oObj.setShort(idx, (short)133) ;
224 } catch (SQLException e) {
225 log.println("Unexpected SQL exception:") ;
226 log.println(e) ;
227 result = false ;
231 tRes.tested("setShort()", result) ;
235 * Sets parameter (if exists) to new value. <p>
236 * Has OK status if no exceptions occured.
238 public void _setInt() {
239 boolean result = true ;
240 int idx = findParamOfType(Integer.class) ;
241 if (idx < 0) log.println("Type not found in relation: not tested");
242 else {
243 try {
244 oObj.setInt(idx, 13300) ;
245 } catch (SQLException e) {
246 log.println("Unexpected SQL exception:") ;
247 log.println(e) ;
248 result = false ;
252 tRes.tested("setInt()", result) ;
256 * Sets parameter (if exists) to new value. <p>
257 * Has OK status if no exceptions occured.
259 public void _setLong() {
260 boolean result = true ;
261 int idx = findParamOfType(Long.class) ;
262 if (idx < 0) log.println("Type not found in relation: not tested");
263 else {
264 try {
265 oObj.setLong(idx, 13362453) ;
266 } catch (SQLException e) {
267 log.println("Unexpected SQL exception:") ;
268 log.println(e) ;
269 result = false ;
273 tRes.tested("setLong()", result) ;
277 * Sets parameter (if exists) to new value. <p>
278 * Has OK status if no exceptions occured.
280 public void _setFloat() {
281 boolean result = true ;
282 int idx = findParamOfType(Float.class) ;
283 if (idx < 0) log.println("Type not found in relation: not tested");
284 else {
285 try {
286 oObj.setFloat(idx, (float)133.55) ;
287 } catch (SQLException e) {
288 log.println("Unexpected SQL exception:") ;
289 log.println(e) ;
290 result = false ;
294 tRes.tested("setFloat()", result) ;
298 * Sets parameter (if exists) to new value. <p>
299 * Has OK status if no exceptions occured.
301 public void _setDouble() {
302 boolean result = true ;
303 int idx = findParamOfType(Double.class) ;
304 if (idx < 0) log.println("Type not found in relation: not tested");
305 else {
306 try {
307 oObj.setDouble(idx, 133) ;
308 } catch (SQLException e) {
309 log.println("Unexpected SQL exception:") ;
310 log.println(e) ;
311 result = false ;
315 tRes.tested("setDouble()", result) ;
319 * Sets parameter (if exists) to new value. <p>
320 * Has OK status if no exceptions occured.
322 public void _setBytes() {
323 boolean result = true ;
324 int idx = findParamOfType(byte[].class) ;
325 if (idx < 0) log.println("Type not found in relation: not tested");
326 else {
327 try {
328 oObj.setBytes(idx, new byte[] {5}) ;
329 } catch (SQLException e) {
330 log.println("Unexpected SQL exception:") ;
331 log.println(e) ;
332 result = false ;
336 tRes.tested("setBytes()", result) ;
340 * Sets parameter (if exists) to new value. <p>
341 * Has OK status if no exceptions occured.
343 public void _setDate() {
344 boolean result = true ;
345 int idx = findParamOfType(Date.class) ;
346 if (idx < 0) log.println("Type not found in relation: not tested");
347 else {
348 try {
349 oObj.setDate(
350 idx, new Date ((short)19, (short)01, (short)1979)) ;
351 } catch (SQLException e) {
352 log.println("Unexpected SQL exception:") ;
353 log.println(e) ;
354 result = false ;
358 tRes.tested("setDate()", result) ;
362 * Sets parameter (if exists) to new value. <p>
363 * Has OK status if no exceptions occured.
365 public void _setTime() {
366 boolean result = true ;
367 int idx = findParamOfType(Time.class) ;
368 if (idx < 0) log.println("Type not found in relation: not tested");
369 else {
370 try {
371 oObj.setTime(
372 idx, new Time((short)1,(short)2,(short)3,(short)44)) ;
373 } catch (SQLException e) {
374 log.println("Unexpected SQL exception:") ;
375 log.println(e) ;
376 result = false ;
380 tRes.tested("setTime()", result) ;
384 * Sets parameter (if exists) to new value. <p>
385 * Has OK status if no exceptions occured.
387 public void _setTimestamp() {
388 boolean result = true ;
389 int idx = findParamOfType(DateTime.class) ;
390 if (idx < 0) log.println("Type not found in relation: not tested");
391 else {
392 try {
393 oObj.setTimestamp(idx, new DateTime((short)1,(short)2,(short)3,
394 (short)4, (short)19, (short)01, (short)1979)) ;
395 } catch (SQLException e) {
396 log.println("Unexpected SQL exception:") ;
397 log.println(e) ;
398 result = false ;
402 tRes.tested("setTimestamp()", result) ;
406 * Sets parameter (if exists) to new value. <p>
407 * Has OK status if no exceptions occured.
409 public void _setBinaryStream() {
410 boolean result = true ;
411 int idx = findParamOfType(XDataInputStream.class) ;
412 if (idx < 0) log.println("Type not found in relation: not tested");
413 else {
414 try {
415 Object oStream = ((XMultiServiceFactory)tParam.getMSF()).
416 createInstance("com.sun.star.io.DataInputStream") ;
417 XInputStream xStream = (XInputStream)UnoRuntime.queryInterface
418 (XInputStream.class, oStream);
420 oObj.setBinaryStream(idx, xStream, 2) ;
421 } catch (SQLException e) {
422 log.println("Unexpected SQL exception:") ;
423 log.println(e) ;
424 result = false ;
425 } catch (com.sun.star.uno.Exception e) {
426 log.println("Unexpected exception:") ;
427 log.println(e) ;
428 result = false ;
432 tRes.tested("setBinaryStream()", result) ;
436 * Sets parameter (if exists) to new value. <p>
437 * Has OK status if no exceptions occured.
439 public void _setCharacterStream() {
440 boolean result = true ;
441 int idx = findParamOfType(XTextInputStream.class) ;
442 if (idx < 0) log.println("Type not found in relation: not tested");
443 else {
444 try {
445 Object oStream = ((XMultiServiceFactory)tParam.getMSF())
446 .createInstance("com.sun.star.io.TextInputStream") ;
447 XInputStream xStream = (XInputStream)UnoRuntime.queryInterface
448 (XInputStream.class, oStream);
450 oObj.setCharacterStream(idx, xStream, 2) ;
451 } catch (SQLException e) {
452 log.println("Unexpected SQL exception:") ;
453 log.println(e) ;
454 result = false ;
455 } catch (com.sun.star.uno.Exception e) {
456 log.println("Unexpected exception:") ;
457 log.println(e) ;
458 result = false ;
462 tRes.tested("setCharacterStream()", result) ;
466 * Sets parameter (if exists) to new value. <p>
467 * Has OK status if no exceptions occured.
469 public void _setObject() {
470 boolean result = true ;
471 int idx = findParamOfType(Object[].class) ;
472 if (idx < 0) log.println("Type not found in relation: not tested");
473 else {
474 try {
475 Object obj = ((XMultiServiceFactory)tParam.getMSF()).
476 createInstance("com.sun.star.io.Pipe") ;
478 oObj.setObject(idx, obj) ;
479 } catch (SQLException e) {
480 log.println("Unexpected SQL exception:") ;
481 log.println(e) ;
482 result = false ;
483 } catch (com.sun.star.uno.Exception e) {
484 log.println("Unexpected exception:") ;
485 log.println(e) ;
486 result = false ;
490 tRes.tested("setObject()", result) ;
494 * Sets parameter (if exists) to new value. <p>
495 * Has OK status if no exceptions occured.
497 public void _setObjectWithInfo() {
498 boolean result = true ;
499 int idx = findParamOfType(Object[].class) ;
500 if (idx < 0) log.println("Type not found in relation: not tested");
501 else {
502 try {
503 Object obj = ((XMultiServiceFactory)tParam.getMSF()).
504 createInstance("com.sun.star.io.Pipe") ;
506 oObj.setObjectWithInfo(idx, obj, DataType.OBJECT, 0) ;
507 } catch (SQLException e) {
508 log.println("Unexpected SQL exception:") ;
509 log.println(e) ;
510 result = false ;
511 } catch (com.sun.star.uno.Exception e) {
512 log.println("Unexpected exception:") ;
513 log.println(e) ;
514 result = false ;
518 tRes.tested("setObjectWithInfo()", result) ;
521 public void _setRef() {
523 !!! TO DO !!!
525 tRes.tested("setRef()", Status.skipped(true)) ;
527 public void _setBlob() {
529 !!! TO DO !!!
531 tRes.tested("setBlob()", Status.skipped(true)) ;
533 public void _setClob() {
535 !!! TO DO !!!
537 tRes.tested("setClob()", Status.skipped(true)) ;
539 public void _setArray() {
541 !!! TO DO !!!
543 tRes.tested("setArray()", Status.skipped(true)) ;
547 * Calls method. <p>
548 * Has OK status if no exceptions occured.
550 public void _clearParameters() {
551 boolean result = true ;
552 try {
553 oObj.clearParameters() ;
554 } catch (SQLException e) {
555 log.println("Unexpected SQL exception:") ;
556 log.println(e) ;
557 result = false ;
560 tRes.tested("clearParameters()", result) ;
565 * Finds in relation vector index of parameter of the appropriate
566 * type.
568 private int findParamOfType(Class clz) {
570 for (int i = 0; i < data.size(); i++)
571 if (clz.isInstance(data.get(i))) return i + 1 ;
572 return -1 ;
575 } // finish class _XParameters