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.
103 @SuppressWarnings("unchecked")
105 public void before() {
106 data
= (List
<Object
>) tEnv
.getObjRelation("CurrentRowData") ;
110 * Always has <b>OK</b> status.
112 public void _wasNull() {
113 executeMethod("getString()") ;
114 executeMethod("getBoolean()") ;
115 executeMethod("getByte()") ;
116 executeMethod("getShort()") ;
117 executeMethod("getInt()") ;
118 executeMethod("getLong()") ;
119 executeMethod("getFloat()") ;
120 executeMethod("getDouble()") ;
121 executeMethod("getBytes()") ;
122 executeMethod("getDate()") ;
123 executeMethod("getTime()") ;
124 executeMethod("getTimestamp()") ;
125 executeMethod("getBinaryStream()") ;
126 executeMethod("getCharacterStream()") ;
127 executeMethod("getObject()") ;
128 executeMethod("getRef()") ;
129 executeMethod("getBlob()") ;
130 executeMethod("getClob()") ;
131 executeMethod("getArray()") ;
133 tRes
.tested("wasNull()", notNullRes
) ;
137 * Has <b>OK</b> status if no exceptions occurred in method call.
139 public void _getString() {
140 boolean result
= true ;
141 int col
= findColumnOfType(String
.class) ;
142 if (col
< 0) log
.println("Type not found in relation: not tested");
146 } catch (SQLException e
) {
147 log
.println("Unexpected SQL exception:") ;
153 tRes
.tested("getString()", result
) ;
157 * Has <b>OK</b> status if no exceptions occurred in method call.
159 public void _getBoolean() {
160 boolean result
= true ;
161 int col
= findColumnOfType(Boolean
.class) ;
162 if (col
< 0) log
.println("Type not found in relation: not tested");
165 oObj
.getBoolean(col
);
166 } catch (SQLException e
) {
167 log
.println("Unexpected SQL exception:") ;
173 tRes
.tested("getBoolean()", result
) ;
177 * Has <b>OK</b> status if no exceptions occurred in method call.
179 public void _getByte() {
180 boolean result
= true ;
181 int col
= findColumnOfType(Byte
.class) ;
182 if (col
< 0) log
.println("Type not found in relation: not tested");
186 } catch (SQLException e
) {
187 log
.println("Unexpected SQL exception:") ;
193 tRes
.tested("getByte()", result
) ;
197 * Has <b>OK</b> status if no exceptions occurred in method call.
199 public void _getShort() {
200 boolean result
= true ;
201 int col
= findColumnOfType(Short
.class) ;
202 if (col
< 0) log
.println("Type not found in relation: not tested");
206 } catch (SQLException e
) {
207 log
.println("Unexpected SQL exception:") ;
213 tRes
.tested("getShort()", result
) ;
217 * Has <b>OK</b> status if no exceptions occurred in method call.
219 public void _getInt() {
220 boolean result
= true ;
221 int col
= findColumnOfType(Integer
.class) ;
222 if (col
< 0) log
.println("Type not found in relation: not tested");
226 } catch (SQLException e
) {
227 log
.println("Unexpected SQL exception:") ;
233 tRes
.tested("getInt()", result
) ;
237 * Has <b>OK</b> status if no exceptions occurred in method call.
239 public void _getLong() {
240 boolean result
= true ;
241 int col
= findColumnOfType(Long
.class) ;
242 if (col
< 0) log
.println("Type not found in relation: not tested");
246 } catch (SQLException e
) {
247 log
.println("Unexpected SQL exception:") ;
253 tRes
.tested("getLong()", result
) ;
257 * Has <b>OK</b> status if no exceptions occurred in method call.
259 public void _getFloat() {
260 boolean result
= true ;
261 int col
= findColumnOfType(Float
.class) ;
262 if (col
< 0) log
.println("Type not found in relation: not tested");
266 } catch (SQLException e
) {
267 log
.println("Unexpected SQL exception:") ;
273 tRes
.tested("getFloat()", result
) ;
277 * Has <b>OK</b> status if no exceptions occurred in method call.
279 public void _getDouble() {
280 boolean result
= true ;
281 int col
= findColumnOfType(Double
.class) ;
282 if (col
< 0) log
.println("Type not found in relation: not tested");
286 } catch (SQLException e
) {
287 log
.println("Unexpected SQL exception:") ;
293 tRes
.tested("getDouble()", result
) ;
297 * Has <b>OK</b> status if no exceptions occurred in method call.
299 public void _getBytes() {
300 boolean result
= true ;
301 int col
= findColumnOfType(byte[].class) ;
302 if (col
< 0) log
.println("Type not found in relation: not tested");
306 } catch (SQLException e
) {
307 log
.println("Unexpected SQL exception:") ;
313 tRes
.tested("getBytes()", result
) ;
317 * Has <b>OK</b> status if no exceptions occurred in method call.
319 public void _getDate() {
320 boolean result
= true ;
321 int col
= findColumnOfType(Date
.class) ;
322 if (col
< 0) log
.println("Type not found in relation: not tested");
326 } catch (SQLException e
) {
327 log
.println("Unexpected SQL exception:") ;
333 tRes
.tested("getDate()", result
) ;
337 * Has <b>OK</b> status if no exceptions occurred in method call.
339 public void _getTime() {
340 boolean result
= true ;
341 int col
= findColumnOfType(Time
.class) ;
342 if (col
< 0) log
.println("Type not found in relation: not tested");
346 } catch (SQLException e
) {
347 log
.println("Unexpected SQL exception:") ;
353 tRes
.tested("getTime()", result
) ;
357 * Has <b>OK</b> status if no exceptions occurred in method call.
359 public void _getTimestamp() {
360 boolean result
= true ;
361 int col
= findColumnOfType(DateTime
.class) ;
362 if (col
< 0) log
.println("Type not found in relation: not tested");
365 oObj
.getTimestamp(col
);
366 } catch (SQLException e
) {
367 log
.println("Unexpected SQL exception:") ;
373 tRes
.tested("getTimestamp()", result
) ;
377 * Has <b>OK</b> status if no exceptions occurred in method call.
379 public void _getBinaryStream() {
380 boolean result
= true ;
381 int col
= findColumnOfType(XDataInputStream
.class) ;
382 if (col
< 0) log
.println("Type not found in relation: not tested");
385 oObj
.getBinaryStream(col
);
386 } catch (SQLException e
) {
387 log
.println("Unexpected SQL exception:") ;
393 tRes
.tested("getBinaryStream()", result
) ;
397 * Has <b>OK</b> status if no exceptions occurred in method call.
399 public void _getCharacterStream() {
400 boolean result
= true ;
401 int col
= findColumnOfType(XTextInputStream
.class) ;
402 if (col
< 0) log
.println("Type not found in relation: not tested");
405 oObj
.getCharacterStream(col
);
406 } catch (SQLException e
) {
407 log
.println("Unexpected SQL exception:") ;
413 tRes
.tested("getCharacterStream()", result
) ;
417 * Has <b>OK</b> status if no exceptions occurred in method call.
419 public void _getObject() {
420 boolean result
= true ;
421 int col
= findColumnOfType(Object
[].class) ;
422 if (col
< 0) log
.println("Type not found in relation: not tested");
425 oObj
.getObject(col
, null);
426 } catch (SQLException e
) {
427 log
.println("Unexpected SQL exception:") ;
433 tRes
.tested("getObject()", result
) ;
437 * Has <b>OK</b> status if no exceptions occurred in method call.
439 public void _getRef() {
440 boolean result
= true ;
441 int col
= findColumnOfType(XRef
.class) ;
442 if (col
< 0) log
.println("Type not found in relation: not tested");
446 } catch (SQLException e
) {
447 log
.println("Unexpected SQL exception:") ;
453 tRes
.tested("getRef()", result
) ;
457 * Has <b>OK</b> status if no exceptions occurred in method call.
459 public void _getBlob() {
460 boolean result
= true ;
461 int col
= findColumnOfType(XBlob
.class) ;
462 if (col
< 0) log
.println("Type not found in relation: not tested");
466 } catch (SQLException e
) {
467 log
.println("Unexpected SQL exception:") ;
473 tRes
.tested("getBlob()", result
) ;
477 * Has <b>OK</b> status if no exceptions occurred in method call.
479 public void _getClob() {
480 boolean result
= true ;
481 int col
= findColumnOfType(XClob
.class) ;
482 if (col
< 0) log
.println("Type not found in relation: not tested");
486 } catch (SQLException e
) {
487 log
.println("Unexpected SQL exception:") ;
493 tRes
.tested("getClob()", result
) ;
497 * Has <b>OK</b> status if no exceptions occurred in method call.
499 public void _getArray() {
500 boolean result
= true ;
501 int col
= findColumnOfType(XArray
.class) ;
502 if (col
< 0) log
.println("Type not found in relation: not tested");
506 } catch (SQLException e
) {
507 log
.println("Unexpected SQL exception:") ;
513 tRes
.tested("getArray()", result
) ;
517 * Finds in relation vector index of column of the appropriate
520 protected int findColumnOfType(Class
<?
> clz
) {
522 for (int i
= 0; i
< data
.size(); i
++)
523 if (clz
.isInstance(data
.get(i
))) return i
+ 1 ;
526 } // finish class _XRow