1 /* 2 * This file is part of the LibreOffice project. 3 * 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/. 7 * 8 * This file incorporates work covered by the following license notice: 9 * 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 . 17 */ 18 19 package ifc.sdbc; 20 21 import java.util.List; 22 23 import lib.MultiMethodTest; 24 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; 36 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> 62 * 63 * This interface is full tested in XRowUpdate interface test. Here 64 * only exceptions checked. 65 * <p> 66 * 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 92 */ 93 public class _XRow extends MultiMethodTest { 94 95 // oObj filled by MultiMethodTest 96 public XRow oObj = null ; 97 private List<Object> data = null ; 98 private static final boolean notNullRes = true; 99 100 /** 101 * Retrieves object relation first. 102 */ 103 @Override before()104 public void before() { 105 data = (List<Object>) tEnv.getObjRelation("CurrentRowData") ; 106 } 107 108 /** 109 * Always has <b>OK</b> status. 110 */ _wasNull()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()") ; 131 132 tRes.tested("wasNull()", notNullRes) ; 133 } 134 135 /** 136 * Has <b>OK</b> status if no exceptions occurred in method call. 137 */ _getString()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 ; 149 } 150 } 151 152 tRes.tested("getString()", result) ; 153 } 154 155 /** 156 * Has <b>OK</b> status if no exceptions occurred in method call. 157 */ _getBoolean()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 ; 169 } 170 } 171 172 tRes.tested("getBoolean()", result) ; 173 } 174 175 /** 176 * Has <b>OK</b> status if no exceptions occurred in method call. 177 */ _getByte()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 ; 189 } 190 } 191 192 tRes.tested("getByte()", result) ; 193 } 194 195 /** 196 * Has <b>OK</b> status if no exceptions occurred in method call. 197 */ _getShort()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 ; 209 } 210 } 211 212 tRes.tested("getShort()", result) ; 213 } 214 215 /** 216 * Has <b>OK</b> status if no exceptions occurred in method call. 217 */ _getInt()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 ; 229 } 230 } 231 232 tRes.tested("getInt()", result) ; 233 } 234 235 /** 236 * Has <b>OK</b> status if no exceptions occurred in method call. 237 */ _getLong()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 ; 249 } 250 } 251 252 tRes.tested("getLong()", result) ; 253 } 254 255 /** 256 * Has <b>OK</b> status if no exceptions occurred in method call. 257 */ _getFloat()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 ; 269 } 270 } 271 272 tRes.tested("getFloat()", result) ; 273 } 274 275 /** 276 * Has <b>OK</b> status if no exceptions occurred in method call. 277 */ _getDouble()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 ; 289 } 290 } 291 292 tRes.tested("getDouble()", result) ; 293 } 294 295 /** 296 * Has <b>OK</b> status if no exceptions occurred in method call. 297 */ _getBytes()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 ; 309 } 310 } 311 312 tRes.tested("getBytes()", result) ; 313 } 314 315 /** 316 * Has <b>OK</b> status if no exceptions occurred in method call. 317 */ _getDate()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 ; 329 } 330 } 331 332 tRes.tested("getDate()", result) ; 333 } 334 335 /** 336 * Has <b>OK</b> status if no exceptions occurred in method call. 337 */ _getTime()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 ; 349 } 350 } 351 352 tRes.tested("getTime()", result) ; 353 } 354 355 /** 356 * Has <b>OK</b> status if no exceptions occurred in method call. 357 */ _getTimestamp()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 ; 369 } 370 } 371 372 tRes.tested("getTimestamp()", result) ; 373 } 374 375 /** 376 * Has <b>OK</b> status if no exceptions occurred in method call. 377 */ _getBinaryStream()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 ; 389 } 390 } 391 392 tRes.tested("getBinaryStream()", result) ; 393 } 394 395 /** 396 * Has <b>OK</b> status if no exceptions occurred in method call. 397 */ _getCharacterStream()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 ; 409 } 410 } 411 412 tRes.tested("getCharacterStream()", result) ; 413 } 414 415 /** 416 * Has <b>OK</b> status if no exceptions occurred in method call. 417 */ _getObject()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 ; 429 } 430 } 431 432 tRes.tested("getObject()", result) ; 433 } 434 435 /** 436 * Has <b>OK</b> status if no exceptions occurred in method call. 437 */ _getRef()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 ; 449 } 450 } 451 452 tRes.tested("getRef()", result) ; 453 } 454 455 /** 456 * Has <b>OK</b> status if no exceptions occurred in method call. 457 */ _getBlob()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 ; 469 } 470 } 471 472 tRes.tested("getBlob()", result) ; 473 } 474 475 /** 476 * Has <b>OK</b> status if no exceptions occurred in method call. 477 */ _getClob()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 ; 489 } 490 } 491 492 tRes.tested("getClob()", result) ; 493 } 494 495 /** 496 * Has <b>OK</b> status if no exceptions occurred in method call. 497 */ _getArray()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 ; 509 } 510 } 511 512 tRes.tested("getArray()", result) ; 513 } 514 515 /** 516 * Finds in relation vector index of column of the appropriate 517 * type. 518 */ findColumnOfType(Class<?> clz)519 protected int findColumnOfType(Class<?> clz) { 520 521 for (int i = 0; i < data.size(); i++) 522 if (clz.isInstance(data.get(i))) return i + 1 ; 523 return -1 ; 524 } 525 } // finish class _XRow 526 527 528