Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / ifc / sdbc / _XRow.java
blob70a60b0cf34c58ba8f969b018d0a032cb4563a2d
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;
25 import com.sun.star.io.XDataInputStream;
26 import com.sun.star.io.XTextInputStream;
27 import com.sun.star.sdbc.SQLException;
28 import com.sun.star.sdbc.XArray;
29 import com.sun.star.sdbc.XBlob;
30 import com.sun.star.sdbc.XClob;
31 import com.sun.star.sdbc.XRef;
32 import com.sun.star.sdbc.XRow;
33 import com.sun.star.util.Date;
34 import com.sun.star.util.DateTime;
35 import com.sun.star.util.Time;
37 /**
38 * Testing <code>com.sun.star.sdbc.XRow</code>
39 * interface methods :
40 * <ul>
41 * <li><code> wasNull()</code></li>
42 * <li><code> getString()</code></li>
43 * <li><code> getBoolean()</code></li>
44 * <li><code> getByte()</code></li>
45 * <li><code> getShort()</code></li>
46 * <li><code> getInt()</code></li>
47 * <li><code> getLong()</code></li>
48 * <li><code> getFloat()</code></li>
49 * <li><code> getDouble()</code></li>
50 * <li><code> getBytes()</code></li>
51 * <li><code> getDate()</code></li>
52 * <li><code> getTime()</code></li>
53 * <li><code> getTimestamp()</code></li>
54 * <li><code> getBinaryStream()</code></li>
55 * <li><code> getCharacterStream()</code></li>
56 * <li><code> getObject()</code></li>
57 * <li><code> getRef()</code></li>
58 * <li><code> getBlob()</code></li>
59 * <li><code> getClob()</code></li>
60 * <li><code> getArray()</code></li>
61 * </ul> <p>
63 * This interface is full tested in XRowUpdate interface test. Here
64 * only exceptions checked.
65 * <p>
67 * Object relations required :
68 * <ul>
69 * <li> <code>'CurrentRowData'</code> : (may be used in other
70 * interface tests) is a <code>java.util.Vector</code> object
71 * that contains column types and values in current row. Each
72 * element of vector corresponds to appropriate column (element
73 * with index 0 to column 1, 1 -> 2, etc.). <p>
74 * The following <code>XRow</code> methods correspond to classes
75 * in Vector :
76 * <ul>
77 * <li> <code>getBinaryStream</code> -
78 * <code>com.sun.star.io.XDataInputStream</code> class. </li>
79 * <li> <code>getCharacterStream</code> -
80 * <code>com.sun.star.io.XTextInputStream</code> class. </li>
81 * <li> <code>getObject</code> -
82 * <code>java.lang.Object[]</code> class, the element with
83 * index 0 must be used. </li>
84 * </ul>
85 * Other methods uses types they return (i.e. <code>String</code>
86 * for <code>getString</code> method, <code>com.sun.star.sdbc.XRef</code>
87 * for <code>getRef</code> method).
88 * </li>
89 * </ul>
90 * @see com.sun.star.sdbc.XRaw
91 * @see ifc.sdbc._XRowUpdate
93 public class _XRow extends MultiMethodTest {
95 // oObj filled by MultiMethodTest
96 public XRow oObj = null ;
97 private List<Object> data = null ;
98 private static final boolean notNullRes = true;
101 * Retrieves object relation first.
103 @Override
104 public void before() {
105 data = (List<Object>) tEnv.getObjRelation("CurrentRowData") ;
109 * Always has <b>OK</b> status.
111 public void _wasNull() {
112 executeMethod("getString()") ;
113 executeMethod("getBoolean()") ;
114 executeMethod("getByte()") ;
115 executeMethod("getShort()") ;
116 executeMethod("getInt()") ;
117 executeMethod("getLong()") ;
118 executeMethod("getFloat()") ;
119 executeMethod("getDouble()") ;
120 executeMethod("getBytes()") ;
121 executeMethod("getDate()") ;
122 executeMethod("getTime()") ;
123 executeMethod("getTimestamp()") ;
124 executeMethod("getBinaryStream()") ;
125 executeMethod("getCharacterStream()") ;
126 executeMethod("getObject()") ;
127 executeMethod("getRef()") ;
128 executeMethod("getBlob()") ;
129 executeMethod("getClob()") ;
130 executeMethod("getArray()") ;
132 tRes.tested("wasNull()", notNullRes) ;
136 * Has <b>OK</b> status if no exceptions occurred in method call.
138 public void _getString() {
139 boolean result = true ;
140 int col = findColumnOfType(String.class) ;
141 if (col < 0) log.println("Type not found in relation: not tested");
142 else {
143 try {
144 oObj.getString(col);
145 } catch (SQLException e) {
146 log.println("Unexpected SQL exception:") ;
147 log.println(e) ;
148 result = false ;
152 tRes.tested("getString()", result) ;
156 * Has <b>OK</b> status if no exceptions occurred in method call.
158 public void _getBoolean() {
159 boolean result = true ;
160 int col = findColumnOfType(Boolean.class) ;
161 if (col < 0) log.println("Type not found in relation: not tested");
162 else {
163 try {
164 oObj.getBoolean(col);
165 } catch (SQLException e) {
166 log.println("Unexpected SQL exception:") ;
167 log.println(e) ;
168 result = false ;
172 tRes.tested("getBoolean()", result) ;
176 * Has <b>OK</b> status if no exceptions occurred in method call.
178 public void _getByte() {
179 boolean result = true ;
180 int col = findColumnOfType(Byte.class) ;
181 if (col < 0) log.println("Type not found in relation: not tested");
182 else {
183 try {
184 oObj.getByte(col);
185 } catch (SQLException e) {
186 log.println("Unexpected SQL exception:") ;
187 log.println(e) ;
188 result = false ;
192 tRes.tested("getByte()", result) ;
196 * Has <b>OK</b> status if no exceptions occurred in method call.
198 public void _getShort() {
199 boolean result = true ;
200 int col = findColumnOfType(Short.class) ;
201 if (col < 0) log.println("Type not found in relation: not tested");
202 else {
203 try {
204 oObj.getShort(col);
205 } catch (SQLException e) {
206 log.println("Unexpected SQL exception:") ;
207 log.println(e) ;
208 result = false ;
212 tRes.tested("getShort()", result) ;
216 * Has <b>OK</b> status if no exceptions occurred in method call.
218 public void _getInt() {
219 boolean result = true ;
220 int col = findColumnOfType(Integer.class) ;
221 if (col < 0) log.println("Type not found in relation: not tested");
222 else {
223 try {
224 oObj.getInt(col);
225 } catch (SQLException e) {
226 log.println("Unexpected SQL exception:") ;
227 log.println(e) ;
228 result = false ;
232 tRes.tested("getInt()", result) ;
236 * Has <b>OK</b> status if no exceptions occurred in method call.
238 public void _getLong() {
239 boolean result = true ;
240 int col = findColumnOfType(Long.class) ;
241 if (col < 0) log.println("Type not found in relation: not tested");
242 else {
243 try {
244 oObj.getLong(col);
245 } catch (SQLException e) {
246 log.println("Unexpected SQL exception:") ;
247 log.println(e) ;
248 result = false ;
252 tRes.tested("getLong()", result) ;
256 * Has <b>OK</b> status if no exceptions occurred in method call.
258 public void _getFloat() {
259 boolean result = true ;
260 int col = findColumnOfType(Float.class) ;
261 if (col < 0) log.println("Type not found in relation: not tested");
262 else {
263 try {
264 oObj.getFloat(col);
265 } catch (SQLException e) {
266 log.println("Unexpected SQL exception:") ;
267 log.println(e) ;
268 result = false ;
272 tRes.tested("getFloat()", result) ;
276 * Has <b>OK</b> status if no exceptions occurred in method call.
278 public void _getDouble() {
279 boolean result = true ;
280 int col = findColumnOfType(Double.class) ;
281 if (col < 0) log.println("Type not found in relation: not tested");
282 else {
283 try {
284 oObj.getDouble(col);
285 } catch (SQLException e) {
286 log.println("Unexpected SQL exception:") ;
287 log.println(e) ;
288 result = false ;
292 tRes.tested("getDouble()", result) ;
296 * Has <b>OK</b> status if no exceptions occurred in method call.
298 public void _getBytes() {
299 boolean result = true ;
300 int col = findColumnOfType(byte[].class) ;
301 if (col < 0) log.println("Type not found in relation: not tested");
302 else {
303 try {
304 oObj.getBytes(col);
305 } catch (SQLException e) {
306 log.println("Unexpected SQL exception:") ;
307 log.println(e) ;
308 result = false ;
312 tRes.tested("getBytes()", result) ;
316 * Has <b>OK</b> status if no exceptions occurred in method call.
318 public void _getDate() {
319 boolean result = true ;
320 int col = findColumnOfType(Date.class) ;
321 if (col < 0) log.println("Type not found in relation: not tested");
322 else {
323 try {
324 oObj.getDate(col);
325 } catch (SQLException e) {
326 log.println("Unexpected SQL exception:") ;
327 log.println(e) ;
328 result = false ;
332 tRes.tested("getDate()", result) ;
336 * Has <b>OK</b> status if no exceptions occurred in method call.
338 public void _getTime() {
339 boolean result = true ;
340 int col = findColumnOfType(Time.class) ;
341 if (col < 0) log.println("Type not found in relation: not tested");
342 else {
343 try {
344 oObj.getTime(col);
345 } catch (SQLException e) {
346 log.println("Unexpected SQL exception:") ;
347 log.println(e) ;
348 result = false ;
352 tRes.tested("getTime()", result) ;
356 * Has <b>OK</b> status if no exceptions occurred in method call.
358 public void _getTimestamp() {
359 boolean result = true ;
360 int col = findColumnOfType(DateTime.class) ;
361 if (col < 0) log.println("Type not found in relation: not tested");
362 else {
363 try {
364 oObj.getTimestamp(col);
365 } catch (SQLException e) {
366 log.println("Unexpected SQL exception:") ;
367 log.println(e) ;
368 result = false ;
372 tRes.tested("getTimestamp()", result) ;
376 * Has <b>OK</b> status if no exceptions occurred in method call.
378 public void _getBinaryStream() {
379 boolean result = true ;
380 int col = findColumnOfType(XDataInputStream.class) ;
381 if (col < 0) log.println("Type not found in relation: not tested");
382 else {
383 try {
384 oObj.getBinaryStream(col);
385 } catch (SQLException e) {
386 log.println("Unexpected SQL exception:") ;
387 log.println(e) ;
388 result = false ;
392 tRes.tested("getBinaryStream()", result) ;
396 * Has <b>OK</b> status if no exceptions occurred in method call.
398 public void _getCharacterStream() {
399 boolean result = true ;
400 int col = findColumnOfType(XTextInputStream.class) ;
401 if (col < 0) log.println("Type not found in relation: not tested");
402 else {
403 try {
404 oObj.getCharacterStream(col);
405 } catch (SQLException e) {
406 log.println("Unexpected SQL exception:") ;
407 log.println(e) ;
408 result = false ;
412 tRes.tested("getCharacterStream()", result) ;
416 * Has <b>OK</b> status if no exceptions occurred in method call.
418 public void _getObject() {
419 boolean result = true ;
420 int col = findColumnOfType(Object[].class) ;
421 if (col < 0) log.println("Type not found in relation: not tested");
422 else {
423 try {
424 oObj.getObject(col, null);
425 } catch (SQLException e) {
426 log.println("Unexpected SQL exception:") ;
427 log.println(e) ;
428 result = false ;
432 tRes.tested("getObject()", result) ;
436 * Has <b>OK</b> status if no exceptions occurred in method call.
438 public void _getRef() {
439 boolean result = true ;
440 int col = findColumnOfType(XRef.class) ;
441 if (col < 0) log.println("Type not found in relation: not tested");
442 else {
443 try {
444 oObj.getRef(col);
445 } catch (SQLException e) {
446 log.println("Unexpected SQL exception:") ;
447 log.println(e) ;
448 result = false ;
452 tRes.tested("getRef()", result) ;
456 * Has <b>OK</b> status if no exceptions occurred in method call.
458 public void _getBlob() {
459 boolean result = true ;
460 int col = findColumnOfType(XBlob.class) ;
461 if (col < 0) log.println("Type not found in relation: not tested");
462 else {
463 try {
464 oObj.getBlob(col);
465 } catch (SQLException e) {
466 log.println("Unexpected SQL exception:") ;
467 log.println(e) ;
468 result = false ;
472 tRes.tested("getBlob()", result) ;
476 * Has <b>OK</b> status if no exceptions occurred in method call.
478 public void _getClob() {
479 boolean result = true ;
480 int col = findColumnOfType(XClob.class) ;
481 if (col < 0) log.println("Type not found in relation: not tested");
482 else {
483 try {
484 oObj.getClob(col);
485 } catch (SQLException e) {
486 log.println("Unexpected SQL exception:") ;
487 log.println(e) ;
488 result = false ;
492 tRes.tested("getClob()", result) ;
496 * Has <b>OK</b> status if no exceptions occurred in method call.
498 public void _getArray() {
499 boolean result = true ;
500 int col = findColumnOfType(XArray.class) ;
501 if (col < 0) log.println("Type not found in relation: not tested");
502 else {
503 try {
504 oObj.getArray(col);
505 } catch (SQLException e) {
506 log.println("Unexpected SQL exception:") ;
507 log.println(e) ;
508 result = false ;
512 tRes.tested("getArray()", result) ;
516 * Finds in relation vector index of column of the appropriate
517 * type.
519 protected int findColumnOfType(Class<?> clz) {
521 for (int i = 0; i < data.size(); i++)
522 if (clz.isInstance(data.get(i))) return i + 1 ;
523 return -1 ;
525 } // finish class _XRow