Avoid potential negative array index access to cached text.
[LibreOffice.git] / qadevOOo / tests / java / ifc / sdbc / _XRow.java
blobe1babb0760b6403ff223bd828edd909938212889
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 @SuppressWarnings("unchecked")
104 @Override
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");
143 else {
144 try {
145 oObj.getString(col);
146 } catch (SQLException e) {
147 log.println("Unexpected SQL exception:") ;
148 log.println(e) ;
149 result = false ;
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");
163 else {
164 try {
165 oObj.getBoolean(col);
166 } catch (SQLException e) {
167 log.println("Unexpected SQL exception:") ;
168 log.println(e) ;
169 result = false ;
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");
183 else {
184 try {
185 oObj.getByte(col);
186 } catch (SQLException e) {
187 log.println("Unexpected SQL exception:") ;
188 log.println(e) ;
189 result = false ;
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");
203 else {
204 try {
205 oObj.getShort(col);
206 } catch (SQLException e) {
207 log.println("Unexpected SQL exception:") ;
208 log.println(e) ;
209 result = false ;
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");
223 else {
224 try {
225 oObj.getInt(col);
226 } catch (SQLException e) {
227 log.println("Unexpected SQL exception:") ;
228 log.println(e) ;
229 result = false ;
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");
243 else {
244 try {
245 oObj.getLong(col);
246 } catch (SQLException e) {
247 log.println("Unexpected SQL exception:") ;
248 log.println(e) ;
249 result = false ;
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");
263 else {
264 try {
265 oObj.getFloat(col);
266 } catch (SQLException e) {
267 log.println("Unexpected SQL exception:") ;
268 log.println(e) ;
269 result = false ;
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");
283 else {
284 try {
285 oObj.getDouble(col);
286 } catch (SQLException e) {
287 log.println("Unexpected SQL exception:") ;
288 log.println(e) ;
289 result = false ;
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");
303 else {
304 try {
305 oObj.getBytes(col);
306 } catch (SQLException e) {
307 log.println("Unexpected SQL exception:") ;
308 log.println(e) ;
309 result = false ;
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");
323 else {
324 try {
325 oObj.getDate(col);
326 } catch (SQLException e) {
327 log.println("Unexpected SQL exception:") ;
328 log.println(e) ;
329 result = false ;
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");
343 else {
344 try {
345 oObj.getTime(col);
346 } catch (SQLException e) {
347 log.println("Unexpected SQL exception:") ;
348 log.println(e) ;
349 result = false ;
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");
363 else {
364 try {
365 oObj.getTimestamp(col);
366 } catch (SQLException e) {
367 log.println("Unexpected SQL exception:") ;
368 log.println(e) ;
369 result = false ;
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");
383 else {
384 try {
385 oObj.getBinaryStream(col);
386 } catch (SQLException e) {
387 log.println("Unexpected SQL exception:") ;
388 log.println(e) ;
389 result = false ;
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");
403 else {
404 try {
405 oObj.getCharacterStream(col);
406 } catch (SQLException e) {
407 log.println("Unexpected SQL exception:") ;
408 log.println(e) ;
409 result = false ;
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");
423 else {
424 try {
425 oObj.getObject(col, null);
426 } catch (SQLException e) {
427 log.println("Unexpected SQL exception:") ;
428 log.println(e) ;
429 result = false ;
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");
443 else {
444 try {
445 oObj.getRef(col);
446 } catch (SQLException e) {
447 log.println("Unexpected SQL exception:") ;
448 log.println(e) ;
449 result = false ;
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");
463 else {
464 try {
465 oObj.getBlob(col);
466 } catch (SQLException e) {
467 log.println("Unexpected SQL exception:") ;
468 log.println(e) ;
469 result = false ;
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");
483 else {
484 try {
485 oObj.getClob(col);
486 } catch (SQLException e) {
487 log.println("Unexpected SQL exception:") ;
488 log.println(e) ;
489 result = false ;
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");
503 else {
504 try {
505 oObj.getArray(col);
506 } catch (SQLException e) {
507 log.println("Unexpected SQL exception:") ;
508 log.println(e) ;
509 result = false ;
513 tRes.tested("getArray()", result) ;
517 * Finds in relation vector index of column of the appropriate
518 * type.
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 ;
524 return -1 ;
526 } // finish class _XRow