1<?xml version="1.0" encoding="UTF-8"?> 2<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd"> 3<script:module xmlns:script="http://openoffice.org/2000/script" script:name="sdbc_XRowUpdate" script:language="StarBasic"> 4 5 6'************************************************************************* 7' 8' DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 9' 10' Copyright 2000, 2010 Oracle and/or its affiliates. 11' 12' OpenOffice.org - a multi-platform office productivity suite 13' 14' This file is part of OpenOffice.org. 15' 16' OpenOffice.org is free software: you can redistribute it and/or modify 17' it under the terms of the GNU Lesser General Public License version 3 18' only, as published by the Free Software Foundation. 19' 20' OpenOffice.org is distributed in the hope that it will be useful, 21' but WITHOUT ANY WARRANTY; without even the implied warranty of 22' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 23' GNU Lesser General Public License version 3 for more details 24' (a copy is included in the LICENSE file that accompanied this code). 25' 26' You should have received a copy of the GNU Lesser General Public License 27' version 3 along with OpenOffice.org. If not, see 28' <http://www.openoffice.org/license.html> 29' for a copy of the LGPLv3 License. 30' 31'************************************************************************* 32'************************************************************************* 33 34 35 36' Be sure that all variables are dimensioned: 37option explicit 38 39'************************************************************************* 40' This Interface/Service test depends on the following GLOBAL variables, 41' which must be specified in the object creation: 42 43' - Global rowTypes As Variant 44' must be an array of Strings with description of column types 45' - Global rowTypesCol As Variant 46' corresponding column numbers 47 48'************************************************************************* 49 50 51 52 53 54 55Sub RunTest() 56 57'************************************************************************* 58' INTERFACE: 59' com.sun.star.sdbc.XRowUpdate 60'************************************************************************* 61On Error Goto ErrHndl 62 Dim bOK As Boolean, bNullOK As Boolean 63 Dim i As Integer 64 Dim getV As Variant, newV As Variant, resV As Variant 65 Dim colType As String 66 67 if NOT hasUnoInterfaces(oObj, "com.sun.star.sdbc.XRow") then 68 Out.Log("The interface com.sun.star.sdbc.XRow isn't supported by the component.") 69 Out.Log("The test must be upgraded !!!") 70 exit Sub 71 end if 72 73 Test.RecreateObj() 74 75 bNullOK = true 76 77 Test.StartMethod("updateBoolean()") 78 colType = "boolean" 79 i = findColumn(colType) 80 if i >= 0 then 81 bOK = true 82 getV = oObj.getBoolean(i+1) 83 newV = NOT getV 84 oObj.updateBoolean(i+1, newV) 85 resV = oObj.getBoolean(i+1) 86 Out.Log("Was: " + getv + ", New: " + newV + ", Res: " + resV) 87 bOK = bOK AND (resV = newV) 88 Test.MethodTested("updateBoolean()", bOK) 89 90 oObj.updateNull(i+1) 91 oObj.getBoolean(i+1) 92 bNullOK = bNullOK AND oObj.wasNull() 93 else 94 Out.Log("!!! Column of type '" + colType + "' is not found. No test performed.") 95 Out.Log("Nevertheless status is OK") 96 Test.MethodTested("updateBoolean()", true) 97 end if 98 99 Test.StartMethod("updateByte()") 100 colType = "byte" 101 i = findColumn(colType) 102 if i >= 0 then 103 bOK = true 104 getV = oObj.getByte(i+1) 105 newV = getV + 1 106 oObj.updateByte(i+1, newV) 107 resV = oObj.getByte(i+1) 108 Out.Log("Was: " + getv + ", New: " + newV + ", Res: " + resV) 109 bOK = bOK AND (resV = newV) 110 Test.MethodTested("updateByte()", bOK) 111 112 oObj.updateNull(i+1) 113 oObj.getByte(i+1) 114 bNullOK = bNullOK AND oObj.wasNull() 115 else 116 Out.Log("!!! Column of type '" + colType + "' is not found. No test performed.") 117 Out.Log("Nevertheless status is OK") 118 Test.MethodTested("updateByte()", true) 119 end if 120 121 Test.StartMethod("updateShort()") 122 colType = "short" 123 i = findColumn(colType) 124 if i >= 0 then 125 bOK = true 126 getV = oObj.getShort(i+1) 127 newV = getV + 1 128 oObj.updateShort(i+1, newV) 129 resV = oObj.getShort(i+1) 130 Out.Log("Was: " + getv + ", New: " + newV + ", Res: " + resV) 131 bOK = bOK AND (resV = newV) 132 Test.MethodTested("updateShort()", bOK) 133 134 oObj.updateNull(i+1) 135 oObj.getShort(i+1) 136 bNullOK = bNullOK AND oObj.wasNull() 137 else 138 Out.Log("!!! Column of type '" + colType + "' is not found. No test performed.") 139 Out.Log("Nevertheless status is OK") 140 Test.MethodTested("updateShort()", true) 141 end if 142 143 Test.StartMethod("updateInt()") 144 colType = "int" 145 i = findColumn(colType) 146 if i >= 0 then 147 bOK = true 148 getV = oObj.getInt(i+1) 149 newV = getV + 1 150 oObj.updateInt(i+1, newV) 151 resV = oObj.getInt(i+1) 152 Out.Log("Was: " + getv + ", New: " + newV + ", Res: " + resV) 153 bOK = bOK AND (resV = newV) 154 Test.MethodTested("updateInt()", bOK) 155 156 oObj.updateNull(i+1) 157 oObj.getInt(i+1) 158 bNullOK = bNullOK AND oObj.wasNull() 159 else 160 Out.Log("!!! Column of type '" + colType + "' is not found. No test performed.") 161 Out.Log("Nevertheless status is OK") 162 Test.MethodTested("updateInt()", true) 163 end if 164 165 Test.StartMethod("updateLong()") 166 colType = "long" 167 i = findColumn(colType) 168 if i >= 0 then 169 bOK = true 170 getV = oObj.getLong(i+1) 171 newV = getV + 1 172 oObj.updateLong(i+1, newV) 173 resV = oObj.getLong(i+1) 174 Out.Log("Was: " + getv + ", New: " + newV + ", Res: " + resV) 175 bOK = bOK AND (resV = newV) 176 Test.MethodTested("updateLong()", bOK) 177 178 oObj.updateNull(i+1) 179 oObj.getLong(i+1) 180 bNullOK = bNullOK AND oObj.wasNull() 181 else 182 Out.Log("!!! Column of type '" + colType + "' is not found. No test performed.") 183 Out.Log("Nevertheless status is OK") 184 Test.MethodTested("updateLong()", true) 185 end if 186 187 Test.StartMethod("updateFloat()") 188 colType = "float" 189 i = findColumn(colType) 190 if i >= 0 then 191 bOK = true 192 getV = oObj.getFloat(i+1) 193 newV = getV + 1.3 194 oObj.updateFloat(i+1, newV) 195 resV = oObj.getFloat(i+1) 196 Out.Log("Was: " + getv + ", New: " + newV + ", Res: " + resV) 197 bOK = bOK AND (resV = newV) 198 Test.MethodTested("updateFloat()", bOK) 199 200 oObj.updateNull(i+1) 201 oObj.getFloat(i+1) 202 bNullOK = bNullOK AND oObj.wasNull() 203 else 204 Out.Log("!!! Column of type '" + colType + "' is not found. No test performed.") 205 Out.Log("Nevertheless status is OK") 206 Test.MethodTested("updateFloat()", true) 207 end if 208 209 Test.StartMethod("updateDouble()") 210 colType = "double" 211 i = findColumn(colType) 212 if i >= 0 then 213 bOK = true 214 getV = oObj.getDouble(i+1) 215 newV = getV + 1.5 216 oObj.updateDouble(i+1, newV) 217 resV = oObj.getDouble(i+1) 218 Out.Log("Was: " + getv + ", New: " + newV + ", Res: " + resV) 219 bOK = bOK AND (resV = newV) 220 Test.MethodTested("updateDouble()", bOK) 221 222 oObj.updateNull(i+1) 223 oObj.getDouble(i+1) 224 bNullOK = bNullOK AND oObj.wasNull() 225 else 226 Out.Log("!!! Column of type '" + colType + "' is not found. No test performed.") 227 Out.Log("Nevertheless status is OK") 228 Test.MethodTested("updateDouble()", true) 229 end if 230 231 Test.StartMethod("updateString()") 232 colType = "string" 233 i = findColumn(colType) 234 if i >= 0 then 235 bOK = true 236 getV = oObj.getString(i+1) 237 newV = "_" + getV 238 oObj.updateString(i+1, newV) 239 resV = oObj.getString(i+1) 240 Out.Log("Was: '" + getv + "', New: '" + newV + "', Res: '" + resV + "'") 241 bOK = bOK AND (resV = newV) 242 Test.MethodTested("updateString()", bOK) 243 244 oObj.updateNull(i+1) 245 oObj.getString(i+1) 246 bNullOK = bNullOK AND oObj.wasNull() 247 else 248 Out.Log("!!! Column of type '" + colType + "' is not found. No test performed.") 249 Out.Log("Nevertheless status is OK") 250 Test.MethodTested("updateString()", true) 251 end if 252 253 Test.StartMethod("updateBytes()") 254 colType = "bytes" 255 i = findColumn(colType) 256 if i >= 0 then 257 bOK = true 258 getV = oObj.getBytes(i+1) 259 260 if (oObj.wasNull() OR ubound(getV()) < 0) then 261 newV = Array(1,2,3) 262 else 263 newV = getV 264 newV(0) = newV(0) + 1 265 end if 266 267 oObj.updateBytes(i+1, newV) 268 resV = oObj.getBytes(i+1) 269 270 Out.Log("Was: " + getv(0) + ", New: " + newV(0) + ", Res: " + resV(0)) 271 bOK = bOK AND (resV(0) = newV(0)) 272 Test.MethodTested("updateBytes()", bOK) 273 274 oObj.updateNull(i+1) 275 oObj.getBytes(i+1) 276 bNullOK = bNullOK AND oObj.wasNull() 277 else 278 Out.Log("!!! Column of type '" + colType + "' is not found. No test performed.") 279 Out.Log("Nevertheless status is OK") 280 Test.MethodTested("updateBytes()", true) 281 end if 282 283 284 Dim dat As com.sun.star.util.Date 285 Test.StartMethod("updateDate()") 286 colType = "date" 287 i = findColumn(colType) 288 if i >= 0 then 289 bOK = true 290 getV = oObj.getDate(i+1) 291 if (oObj.wasNull() OR isNull(getV)) then 292 newV = dat 293 else 294 newV = getV 295 newV.Year = newV.Year + 1 296 end if 297 298 oObj.updateDate(i+1, newV) 299 resV = oObj.getDate(i+1) 300 Out.Log("Was: '" + getv.Year + "', New: '" + newV.Year + "', Res: '" + resV.Year + "'") 301 bOK = bOK AND (resV.Year = newV.Year) 302 Test.MethodTested("updateDate()", bOK) 303 304 oObj.updateNull(i+1) 305 oObj.getDate(i+1) 306 bNullOK = bNullOK AND oObj.wasNull() 307 else 308 Out.Log("!!! Column of type '" + colType + "' is not found. No test performed.") 309 Out.Log("Nevertheless status is OK") 310 Test.MethodTested("updateDate()", true) 311 end if 312 313 Dim tim As com.sun.star.util.Time 314 Test.StartMethod("updateTime()") 315 colType = "time" 316 i = findColumn(colType) 317 if i >= 0 then 318 bOK = true 319 getV = oObj.getTime(i+1) 320 if (oObj.wasNull() OR isNull(getV)) then 321 newV = tim 322 else 323 newV = getV 324 newV.Seconds = newV.Seconds + 1 325 end if 326 327 oObj.updateTime(i+1, newV) 328 resV = oObj.getTime(i+1) 329 Out.Log("Was: '" + getv.Seconds + "', New: '" + newV.Seconds + "', Res: '" + resV.Seconds + "'") 330 bOK = bOK AND (resV.Seconds = newV.Seconds) 331 Test.MethodTested("updateTime()", bOK) 332 333 oObj.updateNull(i+1) 334 oObj.getTime(i+1) 335 bNullOK = bNullOK AND oObj.wasNull() 336 else 337 Out.Log("!!! Column of type '" + colType + "' is not found. No test performed.") 338 Out.Log("Nevertheless status is OK") 339 Test.MethodTested("updateTime()", true) 340 end if 341 342 Dim dattm As com.sun.star.util.DateTime 343 Test.StartMethod("updateTimestamp()") 344 colType = "timestamp" 345 i = findColumn(colType) 346 if i >= 0 then 347 bOK = true 348 getV = oObj.getTimestamp(i+1) 349 if (oObj.wasNull() OR isNull(getV)) then 350 newV = dattm 351 else 352 newV = getV 353 newV.Year = newV.Year + 1 354 end if 355 356 oObj.updateTimestamp(i+1, newV) 357 resV = oObj.getTimestamp(i+1) 358 Out.Log("Was: '" + getv.Year + "', New: '" + newV.Year + "', Res: '" + resV.Year + "'") 359 bOK = bOK AND (resV.Year = newV.Year) 360 Test.MethodTested("updateTimestamp()", bOK) 361 362 oObj.updateNull(i+1) 363 oObj.getTimestamp(i+1) 364 bNullOK = bNullOK AND oObj.wasNull() 365 else 366 Out.Log("!!! Column of type '" + colType + "' is not found. No test performed.") 367 Out.Log("Nevertheless status is OK") 368 Test.MethodTested("updateTimestamp()", true) 369 end if 370 371 Dim bytes As Variant, nBytes As Long 372 Test.StartMethod("updateCharacterStream()") 373 colType = "characterstream" 374 i = findColumn(colType) 375 if i >= 0 then 376 bOK = true 377 newV = createUnoService("com.sun.star.io.Pipe") 378 newV.writeBytes(Array(123, 234)) 379 oObj.updateCharacterStream(i+1, newV) 380 resV = oObj.getCharacterStream(i+1) 381 'Out.Log("Was: '" + getv + "', New: '" + newV + "', Res: '" + resV + "'") 382 bOK = bOK AND NOT oObj.wasNull() AND NOT isNull(resV) 383 384 if bOK then 385 Out.Log("Testing further ...") 386 nBytes = resV.readBytes(bytes, 2) 387 bOK = bOK AND (nBytes = 2) AND (bytes(0) = 123) AND (bytes(1) = 234) 388 end if 389 390 Test.MethodTested("updateCharacterStream()", bOK) 391 392 oObj.updateNull(i+1) 393 oObj.getCharacterStream(i+1) 394 bNullOK = bNullOK AND oObj.wasNull() 395 else 396 Out.Log("!!! Column of type '" + colType + "' is not found. No test performed.") 397 Out.Log("Nevertheless status is OK") 398 Test.MethodTested("updateCharacterStream()", true) 399 end if 400 401 Test.StartMethod("updateBinaryStream()") 402 colType = "binarystream" 403 i = findColumn(colType) 404 if i >= 0 then 405 bOK = true 406 newV = createUnoService("com.sun.star.io.Pipe") 407 newV.writeBytes(Array(123, 234)) 408 oObj.updateBinaryStream(i+1, newV) 409 resV = oObj.getBinaryStream(i+1) 410 'Out.Log("Was: '" + getv + "', New: '" + newV + "', Res: '" + resV + "'") 411 bOK = bOK AND NOT oObj.wasNull() AND NOT isNull(resV) 412 413 if bOK then 414 Out.Log("Testing further ...") 415 nBytes = resV.readBytes(bytes, 2) 416 bOK = bOK AND (nBytes = 2) AND (bytes(0) = 123) AND (bytes(1) = 234) 417 end if 418 419 Test.MethodTested("updateBinaryStream()", bOK) 420 421 oObj.updateNull(i+1) 422 oObj.getBinaryStream(i+1) 423 bNullOK = bNullOK AND oObj.wasNull() 424 else 425 Out.Log("!!! Column of type '" + colType + "' is not found. No test performed.") 426 Out.Log("Nevertheless status is OK") 427 Test.MethodTested("updateBinaryStream()", true) 428 end if 429 430 Test.StartMethod("updateObject()") 431 colType = "object" 432 i = findColumn(colType) 433 if i >= 0 then 434 bOK = true 435 getV = oObj.getObject(i+1) 436 if (NOT hasUnoInterfaces(getV, "com.sun.star.io.XInputStream")) then 437 newV = createUnoService("com.sun.star.io.DataInputStream") 438 else 439 newV = createUnoService("com.sun.star.io.DataOutputStream") 440 end if 441 442 oObj.updateObject(i+1, newV) 443 resV = oObj.getObject(i+1) 444 445 bOK = bOK AND (hasUnoInterfaces(newV, "com.sun.star.io.XInputStream") = _ 446 hasUnoInterfaces(resV, "com.sun.star.io.XInputStream")) AND _ 447 (hasUnoInterfaces(newV, "com.sun.star.io.XOutputStream") = _ 448 hasUnoInterfaces(resV, "com.sun.star.io.XOutputStream")) 449 450 Test.MethodTested("updateObject()", bOK) 451 452 oObj.updateNull(i+1) 453 oObj.getObject(i+1) 454 bNullOK = bNullOK AND oObj.wasNull() 455 else 456 Out.Log("!!! Column of type '" + colType + "' is not found. No test performed.") 457 Out.Log("Nevertheless status is OK") 458 Test.MethodTested("updateObject()", true) 459 end if 460 461 Test.StartMethod("updateNumericObject()") 462 colType = "numericobject" 463 i = findColumn(colType) 464 if i >= 0 then 465 bOK = true 466 getV = oObj.getNumericObject(i+1) 467 if (NOT hasUnoInterfaces(getV, "com.sun.star.io.XInputStream")) then 468 newV = createUnoService("com.sun.star.io.DataInputStream") 469 else 470 newV = createUnoService("com.sun.star.io.DataOutputStream") 471 end if 472 473 oObj.updateNumericObject(i+1, newV, 0) 474 resV = oObj.getNumericObject(i+1) 475 476 bOK = bOK AND (hasUnoInterfaces(newV, "com.sun.star.io.XInputStream") = _ 477 hasUnoInterfaces(resV, "com.sun.star.io.XInputStream")) AND _ 478 (hasUnoInterfaces(newV, "com.sun.star.io.XOutputStream") = _ 479 hasUnoInterfaces(resV, "com.sun.star.io.XOutputStream")) 480 481 Test.MethodTested("updateNumericObject()", bOK) 482 483 oObj.updateNull(i+1) 484 oObj.getNumericObject(i+1) 485 bNullOK = bNullOK AND oObj.wasNull() 486 else 487 Out.Log("!!! Column of type '" + colType + "' is not found. No test performed.") 488 Out.Log("Nevertheless status is OK") 489 Test.MethodTested("updateNumericObject()", true) 490 end if 491 492 Test.StartMethod("updateNull()") 493 Test.MethodTested("updateNull()", bNullOK) 494 495Exit Sub 496ErrHndl: 497 Test.Exception() 498 bOK = false 499 resume next 500End Sub 501 502Function findColumn(cType As String) As Integer 503 Dim i As Integer 504 505 for i = lbound(rowTypes()) to ubound(rowTypes()) 506 if rowTypes(i) = cType then 507 findColumn() = rowTypesCol(i) - 1 508 exit function 509 end if 510 next i 511 512 findColumn() = -1 513End function 514</script:module> 515