Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / qadevOOo / tests / java / ifc / sdbc / _XParameters.java
blob062c6819dcb064b71cf01c88ba736ba121f1f8b8
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 package ifc.sdbc;
30 import java.util.Vector;
32 import lib.MultiMethodTest;
33 import lib.Status;
35 import com.sun.star.io.XDataInputStream;
36 import com.sun.star.io.XInputStream;
37 import com.sun.star.io.XTextInputStream;
38 import com.sun.star.lang.XMultiServiceFactory;
39 import com.sun.star.sdbc.DataType;
40 import com.sun.star.sdbc.SQLException;
41 import com.sun.star.sdbc.XParameters;
42 import com.sun.star.uno.UnoRuntime;
43 import com.sun.star.util.Date;
44 import com.sun.star.util.DateTime;
45 import com.sun.star.util.Time;
47 /**
48 /**
49 * Testing <code>com.sun.star.sdbc.XParameters</code>
50 * interface methods :
51 * <ul>
52 * <li><code> setNull()</code></li>
53 * <li><code> setObjectNull()</code></li>
54 * <li><code> setBoolean()</code></li>
55 * <li><code> setByte()</code></li>
56 * <li><code> setShort()</code></li>
57 * <li><code> setInt()</code></li>
58 * <li><code> setLong()</code></li>
59 * <li><code> setFloat()</code></li>
60 * <li><code> setDouble()</code></li>
61 * <li><code> setString()</code></li>
62 * <li><code> setBytes()</code></li>
63 * <li><code> setDate()</code></li>
64 * <li><code> setTime()</code></li>
65 * <li><code> setTimestamp()</code></li>
66 * <li><code> setBinaryStream()</code></li>
67 * <li><code> setCharacterStream()</code></li>
68 * <li><code> setObject()</code></li>
69 * <li><code> setObjectWithInfo()</code></li>
70 * <li><code> setRef()</code></li>
71 * <li><code> setBlob()</code></li>
72 * <li><code> setClob()</code></li>
73 * <li><code> setArray()</code></li>
74 * <li><code> clearParameters()</code></li>
75 * </ul> <p>
76 * Object relations required :
77 * <ul>
78 * <li> <code>'XParameters.ParamValues'</code> : is a
79 * <code>java.util.Vector</code> object
80 * that contains parameter types and values of the statement. Each
81 * element of vector corresponds to appropriate parameter (element
82 * with index 0 to parameter #1, 1 -> #2, etc.). <p>
83 * The following <code>XParameters</code> methods correspond to classes
84 * in Vector :
85 * <ul>
86 * <li> <code>setBinaryStream</code> -
87 * <code>com.sun.star.io.XDataInputStream</code> class. </li>
88 * <li> <code>setCharacterStream</code> -
89 * <code>com.sun.star.io.XTextInputStream</code> class. </li>
90 * <li> <code>setObject</code> -
91 * <code>java.lang.Object[]</code> class, the element with
92 * index 0 must be used. </li>
93 * </ul>
94 * Other methods uses types of their arguments (i.e.
95 * <code>java.lang.String</code>
96 * for <code>setString</code> method, <code>com.sun.star.sdbc.XRef</code>
97 * for <code>setRef</code> method).
98 * </li>
99 * </ul>
100 * @see com.sun.star.sdbc.XParameters
102 public class _XParameters extends MultiMethodTest {
104 // oObj filled by MultiMethodTest
105 public XParameters oObj = null ;
107 private Vector data = null ;
110 * Gets object relation
112 public void before() {
113 data = (Vector) tEnv.getObjRelation("XParameters.ParamValues") ;
114 if (data == null) {
115 log.println("!!! Relation not found !!!") ;
120 * Sets String parameter (if exists) to SQL NULL value. <p>
121 * Has OK status if no exceptions occurred.
123 public void _setNull() {
124 boolean result = true ;
125 int idx = findParamOfType(String.class) ;
126 if (idx < 0) log.println("Type not found in relation: not tested");
127 else {
128 try {
129 oObj.setNull(idx, DataType.VARCHAR) ;
130 } catch (SQLException e) {
131 log.println("Unexpected SQL exception:") ;
132 log.println(e) ;
133 result = false ;
137 tRes.tested("setNull()", result) ;
140 public void _setObjectNull() {
142 !!! TO DO !!!
144 tRes.tested("setObjectNull()", Status.skipped(true)) ;
148 * Sets String parameter (if exists) to new value. <p>
149 * Has OK status if no exceptions occurred.
151 public void _setString() {
152 boolean result = true ;
153 int idx = findParamOfType(String.class) ;
154 if (idx < 0) log.println("Type not found in relation: not tested");
155 else {
156 try {
157 oObj.setString(idx, "XParameters") ;
158 } catch (SQLException e) {
159 log.println("Unexpected SQL exception:") ;
160 log.println(e) ;
161 result = false ;
165 tRes.tested("setString()", result) ;
169 * Sets parameter (if exists) to new value. <p>
170 * Has OK status if no exceptions occurred.
172 public void _setBoolean() {
173 boolean result = true ;
174 int idx = findParamOfType(Boolean.class) ;
175 if (idx < 0) log.println("Type not found in relation: not tested");
176 else {
177 try {
178 oObj.setBoolean(idx, true) ;
179 } catch (SQLException e) {
180 log.println("Unexpected SQL exception:") ;
181 log.println(e) ;
182 result = false ;
186 tRes.tested("setBoolean()", result) ;
190 * Sets parameter (if exists) to new value. <p>
191 * Has OK status if no exceptions occurred.
193 public void _setByte() {
194 boolean result = true ;
195 int idx = findParamOfType(Byte.class) ;
196 if (idx < 0) log.println("Type not found in relation: not tested");
197 else {
198 try {
199 oObj.setByte(idx, (byte)122) ;
200 } catch (SQLException e) {
201 log.println("Unexpected SQL exception:") ;
202 log.println(e) ;
203 result = false ;
207 tRes.tested("setByte()", result) ;
211 * Sets parameter (if exists) to new value. <p>
212 * Has OK status if no exceptions occurred.
214 public void _setShort() {
215 boolean result = true ;
216 int idx = findParamOfType(Short.class) ;
217 if (idx < 0) log.println("Type not found in relation: not tested");
218 else {
219 try {
220 oObj.setShort(idx, (short)133) ;
221 } catch (SQLException e) {
222 log.println("Unexpected SQL exception:") ;
223 log.println(e) ;
224 result = false ;
228 tRes.tested("setShort()", result) ;
232 * Sets parameter (if exists) to new value. <p>
233 * Has OK status if no exceptions occurred.
235 public void _setInt() {
236 boolean result = true ;
237 int idx = findParamOfType(Integer.class) ;
238 if (idx < 0) log.println("Type not found in relation: not tested");
239 else {
240 try {
241 oObj.setInt(idx, 13300) ;
242 } catch (SQLException e) {
243 log.println("Unexpected SQL exception:") ;
244 log.println(e) ;
245 result = false ;
249 tRes.tested("setInt()", result) ;
253 * Sets parameter (if exists) to new value. <p>
254 * Has OK status if no exceptions occurred.
256 public void _setLong() {
257 boolean result = true ;
258 int idx = findParamOfType(Long.class) ;
259 if (idx < 0) log.println("Type not found in relation: not tested");
260 else {
261 try {
262 oObj.setLong(idx, 13362453) ;
263 } catch (SQLException e) {
264 log.println("Unexpected SQL exception:") ;
265 log.println(e) ;
266 result = false ;
270 tRes.tested("setLong()", result) ;
274 * Sets parameter (if exists) to new value. <p>
275 * Has OK status if no exceptions occurred.
277 public void _setFloat() {
278 boolean result = true ;
279 int idx = findParamOfType(Float.class) ;
280 if (idx < 0) log.println("Type not found in relation: not tested");
281 else {
282 try {
283 oObj.setFloat(idx, (float)133.55) ;
284 } catch (SQLException e) {
285 log.println("Unexpected SQL exception:") ;
286 log.println(e) ;
287 result = false ;
291 tRes.tested("setFloat()", result) ;
295 * Sets parameter (if exists) to new value. <p>
296 * Has OK status if no exceptions occurred.
298 public void _setDouble() {
299 boolean result = true ;
300 int idx = findParamOfType(Double.class) ;
301 if (idx < 0) log.println("Type not found in relation: not tested");
302 else {
303 try {
304 oObj.setDouble(idx, 133) ;
305 } catch (SQLException e) {
306 log.println("Unexpected SQL exception:") ;
307 log.println(e) ;
308 result = false ;
312 tRes.tested("setDouble()", result) ;
316 * Sets parameter (if exists) to new value. <p>
317 * Has OK status if no exceptions occurred.
319 public void _setBytes() {
320 boolean result = true ;
321 int idx = findParamOfType(byte[].class) ;
322 if (idx < 0) log.println("Type not found in relation: not tested");
323 else {
324 try {
325 oObj.setBytes(idx, new byte[] {5}) ;
326 } catch (SQLException e) {
327 log.println("Unexpected SQL exception:") ;
328 log.println(e) ;
329 result = false ;
333 tRes.tested("setBytes()", result) ;
337 * Sets parameter (if exists) to new value. <p>
338 * Has OK status if no exceptions occurred.
340 public void _setDate() {
341 boolean result = true ;
342 int idx = findParamOfType(Date.class) ;
343 if (idx < 0) log.println("Type not found in relation: not tested");
344 else {
345 try {
346 oObj.setDate(
347 idx, new Date ((short)19, (short)01, (short)1979)) ;
348 } catch (SQLException e) {
349 log.println("Unexpected SQL exception:") ;
350 log.println(e) ;
351 result = false ;
355 tRes.tested("setDate()", result) ;
359 * Sets parameter (if exists) to new value. <p>
360 * Has OK status if no exceptions occurred.
362 public void _setTime() {
363 boolean result = true ;
364 int idx = findParamOfType(Time.class) ;
365 if (idx < 0) log.println("Type not found in relation: not tested");
366 else {
367 try {
368 oObj.setTime(
369 idx, new Time((short)1,(short)2,(short)3,(short)44)) ;
370 } catch (SQLException e) {
371 log.println("Unexpected SQL exception:") ;
372 log.println(e) ;
373 result = false ;
377 tRes.tested("setTime()", result) ;
381 * Sets parameter (if exists) to new value. <p>
382 * Has OK status if no exceptions occurred.
384 public void _setTimestamp() {
385 boolean result = true ;
386 int idx = findParamOfType(DateTime.class) ;
387 if (idx < 0) log.println("Type not found in relation: not tested");
388 else {
389 try {
390 oObj.setTimestamp(idx, new DateTime((short)1,(short)2,(short)3,
391 (short)4, (short)19, (short)01, (short)1979)) ;
392 } catch (SQLException e) {
393 log.println("Unexpected SQL exception:") ;
394 log.println(e) ;
395 result = false ;
399 tRes.tested("setTimestamp()", result) ;
403 * Sets parameter (if exists) to new value. <p>
404 * Has OK status if no exceptions occurred.
406 public void _setBinaryStream() {
407 boolean result = true ;
408 int idx = findParamOfType(XDataInputStream.class) ;
409 if (idx < 0) log.println("Type not found in relation: not tested");
410 else {
411 try {
412 Object oStream = ((XMultiServiceFactory)tParam.getMSF()).
413 createInstance("com.sun.star.io.DataInputStream") ;
414 XInputStream xStream = (XInputStream)UnoRuntime.queryInterface
415 (XInputStream.class, oStream);
417 oObj.setBinaryStream(idx, xStream, 2) ;
418 } catch (SQLException e) {
419 log.println("Unexpected SQL exception:") ;
420 log.println(e) ;
421 result = false ;
422 } catch (com.sun.star.uno.Exception e) {
423 log.println("Unexpected exception:") ;
424 log.println(e) ;
425 result = false ;
429 tRes.tested("setBinaryStream()", result) ;
433 * Sets parameter (if exists) to new value. <p>
434 * Has OK status if no exceptions occurred.
436 public void _setCharacterStream() {
437 boolean result = true ;
438 int idx = findParamOfType(XTextInputStream.class) ;
439 if (idx < 0) log.println("Type not found in relation: not tested");
440 else {
441 try {
442 Object oStream = ((XMultiServiceFactory)tParam.getMSF())
443 .createInstance("com.sun.star.io.TextInputStream") ;
444 XInputStream xStream = (XInputStream)UnoRuntime.queryInterface
445 (XInputStream.class, oStream);
447 oObj.setCharacterStream(idx, xStream, 2) ;
448 } catch (SQLException e) {
449 log.println("Unexpected SQL exception:") ;
450 log.println(e) ;
451 result = false ;
452 } catch (com.sun.star.uno.Exception e) {
453 log.println("Unexpected exception:") ;
454 log.println(e) ;
455 result = false ;
459 tRes.tested("setCharacterStream()", result) ;
463 * Sets parameter (if exists) to new value. <p>
464 * Has OK status if no exceptions occurred.
466 public void _setObject() {
467 boolean result = true ;
468 int idx = findParamOfType(Object[].class) ;
469 if (idx < 0) log.println("Type not found in relation: not tested");
470 else {
471 try {
472 Object obj = ((XMultiServiceFactory)tParam.getMSF()).
473 createInstance("com.sun.star.io.Pipe") ;
475 oObj.setObject(idx, obj) ;
476 } catch (SQLException e) {
477 log.println("Unexpected SQL exception:") ;
478 log.println(e) ;
479 result = false ;
480 } catch (com.sun.star.uno.Exception e) {
481 log.println("Unexpected exception:") ;
482 log.println(e) ;
483 result = false ;
487 tRes.tested("setObject()", result) ;
491 * Sets parameter (if exists) to new value. <p>
492 * Has OK status if no exceptions occurred.
494 public void _setObjectWithInfo() {
495 boolean result = true ;
496 int idx = findParamOfType(Object[].class) ;
497 if (idx < 0) log.println("Type not found in relation: not tested");
498 else {
499 try {
500 Object obj = ((XMultiServiceFactory)tParam.getMSF()).
501 createInstance("com.sun.star.io.Pipe") ;
503 oObj.setObjectWithInfo(idx, obj, DataType.OBJECT, 0) ;
504 } catch (SQLException e) {
505 log.println("Unexpected SQL exception:") ;
506 log.println(e) ;
507 result = false ;
508 } catch (com.sun.star.uno.Exception e) {
509 log.println("Unexpected exception:") ;
510 log.println(e) ;
511 result = false ;
515 tRes.tested("setObjectWithInfo()", result) ;
518 public void _setRef() {
520 !!! TO DO !!!
522 tRes.tested("setRef()", Status.skipped(true)) ;
524 public void _setBlob() {
526 !!! TO DO !!!
528 tRes.tested("setBlob()", Status.skipped(true)) ;
530 public void _setClob() {
532 !!! TO DO !!!
534 tRes.tested("setClob()", Status.skipped(true)) ;
536 public void _setArray() {
538 !!! TO DO !!!
540 tRes.tested("setArray()", Status.skipped(true)) ;
544 * Calls method. <p>
545 * Has OK status if no exceptions occurred.
547 public void _clearParameters() {
548 boolean result = true ;
549 try {
550 oObj.clearParameters() ;
551 } catch (SQLException e) {
552 log.println("Unexpected SQL exception:") ;
553 log.println(e) ;
554 result = false ;
557 tRes.tested("clearParameters()", result) ;
562 * Finds in relation vector index of parameter of the appropriate
563 * type.
565 private int findParamOfType(Class clz) {
567 for (int i = 0; i < data.size(); i++)
568 if (clz.isInstance(data.get(i))) return i + 1 ;
569 return -1 ;
572 } // finish class _XParameters