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 .
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
;
38 * Testing <code>com.sun.star.sdbc.XRow</code>
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>
63 * This interface is full tested in XRowUpdate interface test. Here
64 * only exceptions checked.
67 * Object relations required :
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
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>
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).
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.
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");
145 } catch (SQLException e
) {
146 log
.println("Unexpected SQL exception:") ;
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");
164 oObj
.getBoolean(col
);
165 } catch (SQLException e
) {
166 log
.println("Unexpected SQL exception:") ;
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");
185 } catch (SQLException e
) {
186 log
.println("Unexpected SQL exception:") ;
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");
205 } catch (SQLException e
) {
206 log
.println("Unexpected SQL exception:") ;
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");
225 } catch (SQLException e
) {
226 log
.println("Unexpected SQL exception:") ;
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");
245 } catch (SQLException e
) {
246 log
.println("Unexpected SQL exception:") ;
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");
265 } catch (SQLException e
) {
266 log
.println("Unexpected SQL exception:") ;
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");
285 } catch (SQLException e
) {
286 log
.println("Unexpected SQL exception:") ;
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");
305 } catch (SQLException e
) {
306 log
.println("Unexpected SQL exception:") ;
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");
325 } catch (SQLException e
) {
326 log
.println("Unexpected SQL exception:") ;
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");
345 } catch (SQLException e
) {
346 log
.println("Unexpected SQL exception:") ;
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");
364 oObj
.getTimestamp(col
);
365 } catch (SQLException e
) {
366 log
.println("Unexpected SQL exception:") ;
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");
384 oObj
.getBinaryStream(col
);
385 } catch (SQLException e
) {
386 log
.println("Unexpected SQL exception:") ;
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");
404 oObj
.getCharacterStream(col
);
405 } catch (SQLException e
) {
406 log
.println("Unexpected SQL exception:") ;
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");
424 oObj
.getObject(col
, null);
425 } catch (SQLException e
) {
426 log
.println("Unexpected SQL exception:") ;
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");
445 } catch (SQLException e
) {
446 log
.println("Unexpected SQL exception:") ;
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");
465 } catch (SQLException e
) {
466 log
.println("Unexpected SQL exception:") ;
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");
485 } catch (SQLException e
) {
486 log
.println("Unexpected SQL exception:") ;
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");
505 } catch (SQLException e
) {
506 log
.println("Unexpected SQL exception:") ;
512 tRes
.tested("getArray()", result
) ;
516 * Finds in relation vector index of column of the appropriate
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 ;
525 } // finish class _XRow