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