Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / ifc / sdbc / _XParameters.java
blob4284931fefee1cfdf71f38f6dbc3d3a045c989dd
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 .
19 package ifc.sdbc;
21 import java.util.List;
23 import lib.MultiMethodTest;
24 import lib.Status;
26 import com.sun.star.io.XDataInputStream;
27 import com.sun.star.io.XInputStream;
28 import com.sun.star.io.XTextInputStream;
29 import com.sun.star.sdbc.DataType;
30 import com.sun.star.sdbc.SQLException;
31 import com.sun.star.sdbc.XParameters;
32 import com.sun.star.uno.UnoRuntime;
33 import com.sun.star.util.Date;
34 import com.sun.star.util.DateTime;
35 import com.sun.star.util.Time;
37 /**
38 /**
39 * Testing <code>com.sun.star.sdbc.XParameters</code>
40 * interface methods :
41 * <ul>
42 * <li><code> setNull()</code></li>
43 * <li><code> setObjectNull()</code></li>
44 * <li><code> setBoolean()</code></li>
45 * <li><code> setByte()</code></li>
46 * <li><code> setShort()</code></li>
47 * <li><code> setInt()</code></li>
48 * <li><code> setLong()</code></li>
49 * <li><code> setFloat()</code></li>
50 * <li><code> setDouble()</code></li>
51 * <li><code> setString()</code></li>
52 * <li><code> setBytes()</code></li>
53 * <li><code> setDate()</code></li>
54 * <li><code> setTime()</code></li>
55 * <li><code> setTimestamp()</code></li>
56 * <li><code> setBinaryStream()</code></li>
57 * <li><code> setCharacterStream()</code></li>
58 * <li><code> setObject()</code></li>
59 * <li><code> setObjectWithInfo()</code></li>
60 * <li><code> setRef()</code></li>
61 * <li><code> setBlob()</code></li>
62 * <li><code> setClob()</code></li>
63 * <li><code> setArray()</code></li>
64 * <li><code> clearParameters()</code></li>
65 * </ul> <p>
66 * Object relations required :
67 * <ul>
68 * <li> <code>'XParameters.ParamValues'</code> : is a
69 * <code>java.util.Vector</code> object
70 * that contains parameter types and values of the statement. Each
71 * element of vector corresponds to appropriate parameter (element
72 * with index 0 to parameter #1, 1 -> #2, etc.). <p>
73 * The following <code>XParameters</code> methods correspond to classes
74 * in Vector :
75 * <ul>
76 * <li> <code>setBinaryStream</code> -
77 * <code>com.sun.star.io.XDataInputStream</code> class. </li>
78 * <li> <code>setCharacterStream</code> -
79 * <code>com.sun.star.io.XTextInputStream</code> class. </li>
80 * <li> <code>setObject</code> -
81 * <code>java.lang.Object[]</code> class, the element with
82 * index 0 must be used. </li>
83 * </ul>
84 * Other methods uses types of their arguments (i.e.
85 * <code>String</code>
86 * for <code>setString</code> method, <code>com.sun.star.sdbc.XRef</code>
87 * for <code>setRef</code> method).
88 * </li>
89 * </ul>
90 * @see com.sun.star.sdbc.XParameters
92 public class _XParameters extends MultiMethodTest {
94 // oObj filled by MultiMethodTest
95 public XParameters oObj = null ;
97 private List<Object> data = null ;
99 /**
100 * Gets object relation
102 @Override
103 public void before() {
104 data = (List<Object>) tEnv.getObjRelation("XParameters.ParamValues") ;
105 if (data == null) {
106 log.println("!!! Relation not found !!!") ;
111 * Sets String parameter (if exists) to SQL NULL value. <p>
112 * Has OK status if no exceptions occurred.
114 public void _setNull() {
115 boolean result = true ;
116 int idx = findParamOfType(String.class) ;
117 if (idx < 0) log.println("Type not found in relation: not tested");
118 else {
119 try {
120 oObj.setNull(idx, DataType.VARCHAR) ;
121 } catch (SQLException e) {
122 log.println("Unexpected SQL exception:") ;
123 log.println(e) ;
124 result = false ;
128 tRes.tested("setNull()", result) ;
131 public void _setObjectNull() {
133 !!! TO DO !!!
135 tRes.tested("setObjectNull()", Status.skipped(true)) ;
139 * Sets String parameter (if exists) to new value. <p>
140 * Has OK status if no exceptions occurred.
142 public void _setString() {
143 boolean result = true ;
144 int idx = findParamOfType(String.class) ;
145 if (idx < 0) log.println("Type not found in relation: not tested");
146 else {
147 try {
148 oObj.setString(idx, "XParameters") ;
149 } catch (SQLException e) {
150 log.println("Unexpected SQL exception:") ;
151 log.println(e) ;
152 result = false ;
156 tRes.tested("setString()", result) ;
160 * Sets parameter (if exists) to new value. <p>
161 * Has OK status if no exceptions occurred.
163 public void _setBoolean() {
164 boolean result = true ;
165 int idx = findParamOfType(Boolean.class) ;
166 if (idx < 0) log.println("Type not found in relation: not tested");
167 else {
168 try {
169 oObj.setBoolean(idx, true) ;
170 } catch (SQLException e) {
171 log.println("Unexpected SQL exception:") ;
172 log.println(e) ;
173 result = false ;
177 tRes.tested("setBoolean()", result) ;
181 * Sets parameter (if exists) to new value. <p>
182 * Has OK status if no exceptions occurred.
184 public void _setByte() {
185 boolean result = true ;
186 int idx = findParamOfType(Byte.class) ;
187 if (idx < 0) log.println("Type not found in relation: not tested");
188 else {
189 try {
190 oObj.setByte(idx, (byte)122) ;
191 } catch (SQLException e) {
192 log.println("Unexpected SQL exception:") ;
193 log.println(e) ;
194 result = false ;
198 tRes.tested("setByte()", result) ;
202 * Sets parameter (if exists) to new value. <p>
203 * Has OK status if no exceptions occurred.
205 public void _setShort() {
206 boolean result = true ;
207 int idx = findParamOfType(Short.class) ;
208 if (idx < 0) log.println("Type not found in relation: not tested");
209 else {
210 try {
211 oObj.setShort(idx, (short)133) ;
212 } catch (SQLException e) {
213 log.println("Unexpected SQL exception:") ;
214 log.println(e) ;
215 result = false ;
219 tRes.tested("setShort()", result) ;
223 * Sets parameter (if exists) to new value. <p>
224 * Has OK status if no exceptions occurred.
226 public void _setInt() {
227 boolean result = true ;
228 int idx = findParamOfType(Integer.class) ;
229 if (idx < 0) log.println("Type not found in relation: not tested");
230 else {
231 try {
232 oObj.setInt(idx, 13300) ;
233 } catch (SQLException e) {
234 log.println("Unexpected SQL exception:") ;
235 log.println(e) ;
236 result = false ;
240 tRes.tested("setInt()", result) ;
244 * Sets parameter (if exists) to new value. <p>
245 * Has OK status if no exceptions occurred.
247 public void _setLong() {
248 boolean result = true ;
249 int idx = findParamOfType(Long.class) ;
250 if (idx < 0) log.println("Type not found in relation: not tested");
251 else {
252 try {
253 oObj.setLong(idx, 13362453) ;
254 } catch (SQLException e) {
255 log.println("Unexpected SQL exception:") ;
256 log.println(e) ;
257 result = false ;
261 tRes.tested("setLong()", result) ;
265 * Sets parameter (if exists) to new value. <p>
266 * Has OK status if no exceptions occurred.
268 public void _setFloat() {
269 boolean result = true ;
270 int idx = findParamOfType(Float.class) ;
271 if (idx < 0) log.println("Type not found in relation: not tested");
272 else {
273 try {
274 oObj.setFloat(idx, (float)133.55) ;
275 } catch (SQLException e) {
276 log.println("Unexpected SQL exception:") ;
277 log.println(e) ;
278 result = false ;
282 tRes.tested("setFloat()", result) ;
286 * Sets parameter (if exists) to new value. <p>
287 * Has OK status if no exceptions occurred.
289 public void _setDouble() {
290 boolean result = true ;
291 int idx = findParamOfType(Double.class) ;
292 if (idx < 0) log.println("Type not found in relation: not tested");
293 else {
294 try {
295 oObj.setDouble(idx, 133) ;
296 } catch (SQLException e) {
297 log.println("Unexpected SQL exception:") ;
298 log.println(e) ;
299 result = false ;
303 tRes.tested("setDouble()", result) ;
307 * Sets parameter (if exists) to new value. <p>
308 * Has OK status if no exceptions occurred.
310 public void _setBytes() {
311 boolean result = true ;
312 int idx = findParamOfType(byte[].class) ;
313 if (idx < 0) log.println("Type not found in relation: not tested");
314 else {
315 try {
316 oObj.setBytes(idx, new byte[] {5}) ;
317 } catch (SQLException e) {
318 log.println("Unexpected SQL exception:") ;
319 log.println(e) ;
320 result = false ;
324 tRes.tested("setBytes()", result) ;
328 * Sets parameter (if exists) to new value. <p>
329 * Has OK status if no exceptions occurred.
331 public void _setDate() {
332 boolean result = true ;
333 int idx = findParamOfType(Date.class) ;
334 if (idx < 0) log.println("Type not found in relation: not tested");
335 else {
336 try {
337 oObj.setDate(
338 idx, new Date ((short)19, (short)1, (short)1979)) ;
339 } catch (SQLException e) {
340 log.println("Unexpected SQL exception:") ;
341 log.println(e) ;
342 result = false ;
346 tRes.tested("setDate()", result) ;
350 * Sets parameter (if exists) to new value. <p>
351 * Has OK status if no exceptions occurred.
353 public void _setTime() {
354 boolean result = true ;
355 int idx = findParamOfType(Time.class) ;
356 if (idx < 0) log.println("Type not found in relation: not tested");
357 else {
358 try {
359 oObj.setTime(
360 idx, new Time((short)1,(short)2,(short)3,(short)44, false));
361 } catch (SQLException e) {
362 log.println("Unexpected SQL exception:") ;
363 log.println(e) ;
364 result = false ;
368 tRes.tested("setTime()", result) ;
372 * Sets parameter (if exists) to new value. <p>
373 * Has OK status if no exceptions occurred.
375 public void _setTimestamp() {
376 boolean result = true ;
377 int idx = findParamOfType(DateTime.class) ;
378 if (idx < 0) log.println("Type not found in relation: not tested");
379 else {
380 try {
381 oObj.setTimestamp(idx, new DateTime((short)1,(short)2,(short)3,
382 (short)4, (short)19, (short)1, (short)1979, false)) ;
383 } catch (SQLException e) {
384 log.println("Unexpected SQL exception:") ;
385 log.println(e) ;
386 result = false ;
390 tRes.tested("setTimestamp()", result) ;
394 * Sets parameter (if exists) to new value. <p>
395 * Has OK status if no exceptions occurred.
397 public void _setBinaryStream() {
398 boolean result = true ;
399 int idx = findParamOfType(XDataInputStream.class) ;
400 if (idx < 0) log.println("Type not found in relation: not tested");
401 else {
402 try {
403 Object oStream = tParam.getMSF().
404 createInstance("com.sun.star.io.DataInputStream") ;
405 XInputStream xStream = UnoRuntime.queryInterface
406 (XInputStream.class, oStream);
408 oObj.setBinaryStream(idx, xStream, 2) ;
409 } catch (SQLException e) {
410 log.println("Unexpected SQL exception:") ;
411 log.println(e) ;
412 result = false ;
413 } catch (com.sun.star.uno.Exception e) {
414 log.println("Unexpected exception:") ;
415 log.println(e) ;
416 result = false ;
420 tRes.tested("setBinaryStream()", result) ;
424 * Sets parameter (if exists) to new value. <p>
425 * Has OK status if no exceptions occurred.
427 public void _setCharacterStream() {
428 boolean result = true ;
429 int idx = findParamOfType(XTextInputStream.class) ;
430 if (idx < 0) log.println("Type not found in relation: not tested");
431 else {
432 try {
433 Object oStream = tParam.getMSF()
434 .createInstance("com.sun.star.io.TextInputStream") ;
435 XInputStream xStream = UnoRuntime.queryInterface
436 (XInputStream.class, oStream);
438 oObj.setCharacterStream(idx, xStream, 2) ;
439 } catch (SQLException e) {
440 log.println("Unexpected SQL exception:") ;
441 log.println(e) ;
442 result = false ;
443 } catch (com.sun.star.uno.Exception e) {
444 log.println("Unexpected exception:") ;
445 log.println(e) ;
446 result = false ;
450 tRes.tested("setCharacterStream()", result) ;
454 * Sets parameter (if exists) to new value. <p>
455 * Has OK status if no exceptions occurred.
457 public void _setObject() {
458 boolean result = true ;
459 int idx = findParamOfType(Object[].class) ;
460 if (idx < 0) log.println("Type not found in relation: not tested");
461 else {
462 try {
463 Object obj = tParam.getMSF().
464 createInstance("com.sun.star.io.Pipe") ;
466 oObj.setObject(idx, obj) ;
467 } catch (SQLException e) {
468 log.println("Unexpected SQL exception:") ;
469 log.println(e) ;
470 result = false ;
471 } catch (com.sun.star.uno.Exception e) {
472 log.println("Unexpected exception:") ;
473 log.println(e) ;
474 result = false ;
478 tRes.tested("setObject()", result) ;
482 * Sets parameter (if exists) to new value. <p>
483 * Has OK status if no exceptions occurred.
485 public void _setObjectWithInfo() {
486 boolean result = true ;
487 int idx = findParamOfType(Object[].class) ;
488 if (idx < 0) log.println("Type not found in relation: not tested");
489 else {
490 try {
491 Object obj = tParam.getMSF().
492 createInstance("com.sun.star.io.Pipe") ;
494 oObj.setObjectWithInfo(idx, obj, DataType.OBJECT, 0) ;
495 } catch (SQLException e) {
496 log.println("Unexpected SQL exception:") ;
497 log.println(e) ;
498 result = false ;
499 } catch (com.sun.star.uno.Exception e) {
500 log.println("Unexpected exception:") ;
501 log.println(e) ;
502 result = false ;
506 tRes.tested("setObjectWithInfo()", result) ;
509 public void _setRef() {
511 !!! TO DO !!!
513 tRes.tested("setRef()", Status.skipped(true)) ;
515 public void _setBlob() {
517 !!! TO DO !!!
519 tRes.tested("setBlob()", Status.skipped(true)) ;
521 public void _setClob() {
523 !!! TO DO !!!
525 tRes.tested("setClob()", Status.skipped(true)) ;
527 public void _setArray() {
529 !!! TO DO !!!
531 tRes.tested("setArray()", Status.skipped(true)) ;
535 * Calls method. <p>
536 * Has OK status if no exceptions occurred.
538 public void _clearParameters() {
539 boolean result = true ;
540 try {
541 oObj.clearParameters() ;
542 } catch (SQLException e) {
543 log.println("Unexpected SQL exception:") ;
544 log.println(e) ;
545 result = false ;
548 tRes.tested("clearParameters()", result) ;
553 * Finds in relation vector index of parameter of the appropriate
554 * type.
556 private int findParamOfType(Class<?> clz) {
557 for (int i = 0; i < data.size(); i++)
558 if (clz.isInstance(data.get(i))) return i + 1 ;
559 return -1 ;
562 } // finish class _XParameters