1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 package ifc.sdbc; 29 30 import java.util.Vector; 31 32 import lib.MultiMethodTest; 33 34 import com.sun.star.io.XDataInputStream; 35 import com.sun.star.io.XInputStream; 36 import com.sun.star.io.XTextInputStream; 37 import com.sun.star.sdbc.SQLException; 38 import com.sun.star.sdbc.XArray; 39 import com.sun.star.sdbc.XBlob; 40 import com.sun.star.sdbc.XClob; 41 import com.sun.star.sdbc.XRef; 42 import com.sun.star.sdbc.XRow; 43 import com.sun.star.util.Date; 44 import com.sun.star.util.DateTime; 45 import com.sun.star.util.Time; 46 47 /** 48 * Testing <code>com.sun.star.sdbc.XRow</code> 49 * interface methods : 50 * <ul> 51 * <li><code> wasNull()</code></li> 52 * <li><code> getString()</code></li> 53 * <li><code> getBoolean()</code></li> 54 * <li><code> getByte()</code></li> 55 * <li><code> getShort()</code></li> 56 * <li><code> getInt()</code></li> 57 * <li><code> getLong()</code></li> 58 * <li><code> getFloat()</code></li> 59 * <li><code> getDouble()</code></li> 60 * <li><code> getBytes()</code></li> 61 * <li><code> getDate()</code></li> 62 * <li><code> getTime()</code></li> 63 * <li><code> getTimestamp()</code></li> 64 * <li><code> getBinaryStream()</code></li> 65 * <li><code> getCharacterStream()</code></li> 66 * <li><code> getObject()</code></li> 67 * <li><code> getRef()</code></li> 68 * <li><code> getBlob()</code></li> 69 * <li><code> getClob()</code></li> 70 * <li><code> getArray()</code></li> 71 * </ul> <p> 72 * 73 * This interface is full tested in XRowUpdate interface test. Here 74 * only exceptions checked. 75 * <p> 76 * 77 * Object relations required : 78 * <ul> 79 * <li> <code>'CurrentRowData'</code> : (may be used in other 80 * interface tests) is a <code>java.util.Vector</code> object 81 * that contains column types and values in current row. Each 82 * element of vector corresponds to appropriate column (element 83 * with index 0 to column 1, 1 -> 2, etc.). <p> 84 * The following <code>XRow</code> methods correspond to classes 85 * in Vector : 86 * <ul> 87 * <li> <code>getBinaryStream</code> - 88 * <code>com.sun.star.io.XDataInputStream</code> class. </li> 89 * <li> <code>getCharacterStream</code> - 90 * <code>com.sun.star.io.XTextInputStream</code> class. </li> 91 * <li> <code>getObject</code> - 92 * <code>java.lang.Object[]</code> class, the element with 93 * index 0 must be used. </li> 94 * </ul> 95 * Other methods uses types they return (i.e. <code>java.lang.String</code> 96 * for <code>getString</code> method, <code>com.sun.star.sdbc.XRef</code> 97 * for <code>getRef</code> method). 98 * </li> 99 * </ul> 100 * @see com.sun.star.sdbc.XRaw 101 * @see ifc.sdbc._XRowUpdate 102 */ 103 public class _XRow extends MultiMethodTest { 104 105 // oObj filled by MultiMethodTest 106 public XRow oObj = null ; 107 private Vector data = null ; 108 private boolean notNullRes = true ; 109 110 /** 111 * Retrieves object relation first. 112 */ 113 public void before() { 114 data = (Vector) tEnv.getObjRelation("CurrentRowData") ; 115 } 116 117 /** 118 * Always has <b>OK</b> status. 119 */ 120 public void _wasNull() { 121 executeMethod("getString()") ; 122 executeMethod("getBoolean()") ; 123 executeMethod("getByte()") ; 124 executeMethod("getShort()") ; 125 executeMethod("getInt()") ; 126 executeMethod("getLong()") ; 127 executeMethod("getFloat()") ; 128 executeMethod("getDouble()") ; 129 executeMethod("getBytes()") ; 130 executeMethod("getDate()") ; 131 executeMethod("getTime()") ; 132 executeMethod("getTimestamp()") ; 133 executeMethod("getBinaryStream()") ; 134 executeMethod("getCharacterStream()") ; 135 executeMethod("getObject()") ; 136 executeMethod("getRef()") ; 137 executeMethod("getBlob()") ; 138 executeMethod("getClob()") ; 139 executeMethod("getArray()") ; 140 141 tRes.tested("wasNull()", notNullRes) ; 142 } 143 144 /** 145 * Has <b>OK</b> status if no exceptions occured in method call. 146 */ 147 public void _getString() { 148 boolean result = true ; 149 int col = findColumnOfType(String.class) ; 150 if (col < 0) log.println("Type not found in relation: not tested"); 151 else { 152 try { 153 String getStr = oObj.getString(col) ; 154 //result &= ((String)data.get(col - 1)).equals(getStr) ; 155 //notNullRes &= !oObj.wasNull() ; 156 } catch (SQLException e) { 157 log.println("Unexpected SQL exception:") ; 158 log.println(e) ; 159 result = false ; 160 } 161 } 162 163 tRes.tested("getString()", result) ; 164 } 165 166 /** 167 * Has <b>OK</b> status if no exceptions occured in method call. 168 */ 169 public void _getBoolean() { 170 boolean result = true ; 171 int col = findColumnOfType(Boolean.class) ; 172 if (col < 0) log.println("Type not found in relation: not tested"); 173 else { 174 try { 175 boolean getVal = oObj.getBoolean(col) ; 176 //result &= ((Boolean)data.get(col - 1)).booleanValue() == getVal ; 177 //notNullRes &= !oObj.wasNull() ; 178 } catch (SQLException e) { 179 log.println("Unexpected SQL exception:") ; 180 log.println(e) ; 181 result = false ; 182 } 183 } 184 185 tRes.tested("getBoolean()", result) ; 186 } 187 188 /** 189 * Has <b>OK</b> status if no exceptions occured in method call. 190 */ 191 public void _getByte() { 192 boolean result = true ; 193 int col = findColumnOfType(Byte.class) ; 194 if (col < 0) log.println("Type not found in relation: not tested"); 195 else { 196 try { 197 byte getVal = oObj.getByte(col) ; 198 //result &= ((Byte)data.get(col - 1)).byteValue() == getVal ; 199 //notNullRes &= !oObj.wasNull() ; 200 } catch (SQLException e) { 201 log.println("Unexpected SQL exception:") ; 202 log.println(e) ; 203 result = false ; 204 } 205 } 206 207 tRes.tested("getByte()", result) ; 208 } 209 210 /** 211 * Has <b>OK</b> status if no exceptions occured in method call. 212 */ 213 public void _getShort() { 214 boolean result = true ; 215 int col = findColumnOfType(Short.class) ; 216 if (col < 0) log.println("Type not found in relation: not tested"); 217 else { 218 try { 219 short getVal = oObj.getShort(col) ; 220 //result &= ((Short)data.get(col - 1)).shortValue() == getVal ; 221 //notNullRes &= !oObj.wasNull() ; 222 } catch (SQLException e) { 223 log.println("Unexpected SQL exception:") ; 224 log.println(e) ; 225 result = false ; 226 } 227 } 228 229 tRes.tested("getShort()", result) ; 230 } 231 232 /** 233 * Has <b>OK</b> status if no exceptions occured in method call. 234 */ 235 public void _getInt() { 236 boolean result = true ; 237 int col = findColumnOfType(Integer.class) ; 238 if (col < 0) log.println("Type not found in relation: not tested"); 239 else { 240 try { 241 int getVal = oObj.getInt(col) ; 242 } catch (SQLException e) { 243 log.println("Unexpected SQL exception:") ; 244 log.println(e) ; 245 result = false ; 246 } 247 } 248 249 tRes.tested("getInt()", result) ; 250 } 251 252 /** 253 * Has <b>OK</b> status if no exceptions occured in method call. 254 */ 255 public void _getLong() { 256 boolean result = true ; 257 int col = findColumnOfType(Long.class) ; 258 if (col < 0) log.println("Type not found in relation: not tested"); 259 else { 260 try { 261 long getVal = oObj.getLong(col) ; 262 } catch (SQLException e) { 263 log.println("Unexpected SQL exception:") ; 264 log.println(e) ; 265 result = false ; 266 } 267 } 268 269 tRes.tested("getLong()", result) ; 270 } 271 272 /** 273 * Has <b>OK</b> status if no exceptions occured in method call. 274 */ 275 public void _getFloat() { 276 boolean result = true ; 277 int col = findColumnOfType(Float.class) ; 278 if (col < 0) log.println("Type not found in relation: not tested"); 279 else { 280 try { 281 float getVal = oObj.getFloat(col) ; 282 } catch (SQLException e) { 283 log.println("Unexpected SQL exception:") ; 284 log.println(e) ; 285 result = false ; 286 } 287 } 288 289 tRes.tested("getFloat()", result) ; 290 } 291 292 /** 293 * Has <b>OK</b> status if no exceptions occured in method call. 294 */ 295 public void _getDouble() { 296 boolean result = true ; 297 int col = findColumnOfType(Double.class) ; 298 if (col < 0) log.println("Type not found in relation: not tested"); 299 else { 300 try { 301 double getVal = oObj.getDouble(col) ; 302 } catch (SQLException e) { 303 log.println("Unexpected SQL exception:") ; 304 log.println(e) ; 305 result = false ; 306 } 307 } 308 309 tRes.tested("getDouble()", result) ; 310 } 311 312 /** 313 * Has <b>OK</b> status if no exceptions occured in method call. 314 */ 315 public void _getBytes() { 316 boolean result = true ; 317 int col = findColumnOfType(byte[].class) ; 318 if (col < 0) log.println("Type not found in relation: not tested"); 319 else { 320 try { 321 byte[] getVal = oObj.getBytes(col) ; 322 } catch (SQLException e) { 323 log.println("Unexpected SQL exception:") ; 324 log.println(e) ; 325 result = false ; 326 } 327 } 328 329 tRes.tested("getBytes()", result) ; 330 } 331 332 /** 333 * Has <b>OK</b> status if no exceptions occured in method call. 334 */ 335 public void _getDate() { 336 boolean result = true ; 337 int col = findColumnOfType(Date.class) ; 338 if (col < 0) log.println("Type not found in relation: not tested"); 339 else { 340 try { 341 Date getVal = oObj.getDate(col) ; 342 } catch (SQLException e) { 343 log.println("Unexpected SQL exception:") ; 344 log.println(e) ; 345 result = false ; 346 } 347 } 348 349 tRes.tested("getDate()", result) ; 350 } 351 352 /** 353 * Has <b>OK</b> status if no exceptions occured in method call. 354 */ 355 public void _getTime() { 356 boolean result = true ; 357 int col = findColumnOfType(Time.class) ; 358 if (col < 0) log.println("Type not found in relation: not tested"); 359 else { 360 try { 361 Time getVal = oObj.getTime(col) ; 362 } catch (SQLException e) { 363 log.println("Unexpected SQL exception:") ; 364 log.println(e) ; 365 result = false ; 366 } 367 } 368 369 tRes.tested("getTime()", result) ; 370 } 371 372 /** 373 * Has <b>OK</b> status if no exceptions occured in method call. 374 */ 375 public void _getTimestamp() { 376 boolean result = true ; 377 int col = findColumnOfType(DateTime.class) ; 378 if (col < 0) log.println("Type not found in relation: not tested"); 379 else { 380 try { 381 DateTime getVal = oObj.getTimestamp(col) ; 382 } catch (SQLException e) { 383 log.println("Unexpected SQL exception:") ; 384 log.println(e) ; 385 result = false ; 386 } 387 } 388 389 tRes.tested("getTimestamp()", result) ; 390 } 391 392 /** 393 * Has <b>OK</b> status if no exceptions occured in method call. 394 */ 395 public void _getBinaryStream() { 396 boolean result = true ; 397 int col = findColumnOfType(XDataInputStream.class) ; 398 if (col < 0) log.println("Type not found in relation: not tested"); 399 else { 400 try { 401 XInputStream getVal = oObj.getBinaryStream(col) ; 402 } catch (SQLException e) { 403 log.println("Unexpected SQL exception:") ; 404 log.println(e) ; 405 result = false ; 406 } 407 } 408 409 tRes.tested("getBinaryStream()", result) ; 410 } 411 412 /** 413 * Has <b>OK</b> status if no exceptions occured in method call. 414 */ 415 public void _getCharacterStream() { 416 boolean result = true ; 417 int col = findColumnOfType(XTextInputStream.class) ; 418 if (col < 0) log.println("Type not found in relation: not tested"); 419 else { 420 try { 421 XInputStream getVal = oObj.getCharacterStream(col) ; 422 } catch (SQLException e) { 423 log.println("Unexpected SQL exception:") ; 424 log.println(e) ; 425 result = false ; 426 } 427 } 428 429 tRes.tested("getCharacterStream()", result) ; 430 } 431 432 /** 433 * Has <b>OK</b> status if no exceptions occured in method call. 434 */ 435 public void _getObject() { 436 boolean result = true ; 437 int col = findColumnOfType(Object[].class) ; 438 if (col < 0) log.println("Type not found in relation: not tested"); 439 else { 440 try { 441 Object getVal = oObj.getObject(col, null) ; 442 } catch (SQLException e) { 443 log.println("Unexpected SQL exception:") ; 444 log.println(e) ; 445 result = false ; 446 } 447 } 448 449 tRes.tested("getObject()", result) ; 450 } 451 452 /** 453 * Has <b>OK</b> status if no exceptions occured in method call. 454 */ 455 public void _getRef() { 456 boolean result = true ; 457 int col = findColumnOfType(XRef.class) ; 458 if (col < 0) log.println("Type not found in relation: not tested"); 459 else { 460 try { 461 XRef getVal = oObj.getRef(col) ; 462 } catch (SQLException e) { 463 log.println("Unexpected SQL exception:") ; 464 log.println(e) ; 465 result = false ; 466 } 467 } 468 469 tRes.tested("getRef()", result) ; 470 } 471 472 /** 473 * Has <b>OK</b> status if no exceptions occured in method call. 474 */ 475 public void _getBlob() { 476 boolean result = true ; 477 int col = findColumnOfType(XBlob.class) ; 478 if (col < 0) log.println("Type not found in relation: not tested"); 479 else { 480 try { 481 XBlob getVal = oObj.getBlob(col) ; 482 } catch (SQLException e) { 483 log.println("Unexpected SQL exception:") ; 484 log.println(e) ; 485 result = false ; 486 } 487 } 488 489 tRes.tested("getBlob()", result) ; 490 } 491 492 /** 493 * Has <b>OK</b> status if no exceptions occured in method call. 494 */ 495 public void _getClob() { 496 boolean result = true ; 497 int col = findColumnOfType(XClob.class) ; 498 if (col < 0) log.println("Type not found in relation: not tested"); 499 else { 500 try { 501 XClob getVal = oObj.getClob(col) ; 502 } catch (SQLException e) { 503 log.println("Unexpected SQL exception:") ; 504 log.println(e) ; 505 result = false ; 506 } 507 } 508 509 tRes.tested("getClob()", result) ; 510 } 511 512 /** 513 * Has <b>OK</b> status if no exceptions occured in method call. 514 */ 515 public void _getArray() { 516 boolean result = true ; 517 int col = findColumnOfType(XArray.class) ; 518 if (col < 0) log.println("Type not found in relation: not tested"); 519 else { 520 try { 521 XArray getVal = oObj.getArray(col) ; 522 } catch (SQLException e) { 523 log.println("Unexpected SQL exception:") ; 524 log.println(e) ; 525 result = false ; 526 } 527 } 528 529 tRes.tested("getArray()", result) ; 530 } 531 532 /** 533 * Finds in relation vector index of column of the appropriate 534 * type. 535 */ 536 protected int findColumnOfType(Class clz) { 537 538 for (int i = 0; i < data.size(); i++) 539 if (clz.isInstance(data.get(i))) return i + 1 ; 540 return -1 ; 541 } 542 } // finish class _XRow 543 544 545