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_XResultSet" 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 37'************************************************************************* 38' This Interface/Service test depends on the following GLOBAL variables, 39' which must be specified in the object creation: 40 41' - Global cXResultSetFirstRecord as String 42' Global cXResultSetLastRecord as String 43' Global cXResultSetRecord1 as String 44' Global cXResultSetRecord2 as String 45' Global cXResultSet2BeforeLastRecord as String 46 47'************************************************************************* 48 49 50 51 52 53Sub RunTest() 54 55'************************************************************************* 56' INTERFACE: 57' com.sun.star.sdbc.XResultSet 58'************************************************************************* 59On Error Goto ErrHndl 60 Dim bOK As Boolean 61 62 63 Out.Log("ReCreating Object, to be shure that it is in initial state.") 64 65 Test.StartMethod("beforeFirst()") 66 Test.StartMethod("isBeforeFirst()") 67 Test.StartMethod("isFirst()") 68 Test.StartMethod("first()") 69 Test.StartMethod("next()") 70 71 Test.StartMethod("afterLast()") 72 Test.StartMethod("isAfterLast()") 73 Test.StartMethod("isLast()") 74 Test.StartMethod("last()") 75 Test.StartMethod("previous()") 76 77 Test.StartMethod("getRow()") 78 79 Dim bBeforeFirst As Boolean 80 Dim bIsBeforeFirst As Boolean 81 Dim bIsBeforeFirstLoop As Boolean 82 Dim bIsFirst As Boolean 83 Dim bFirst As Boolean 84 Dim bNext As Boolean 85 Dim bAfterLast As Boolean 86 Dim bIsAfterLast As Boolean 87 Dim bIsAfterLastLoop As Boolean 88 Dim bIsLast As Boolean 89 Dim bLast As Boolean 90 Dim bPrevious As Boolean 91 Dim bGetRow As Boolean 92 Dim bLoopError as Boolean 93 94 bLoopError = false 95 bBeforeFirst = true 96 bIsBeforeFirst = true 97 bIsFirst = true 98 bFirst = true 99 bNext = true 100 bAfterLast = true 101 bIsAfterLast = true 102 bIsLast = true 103 bLast = true 104 bPrevious = true 105 bGetRow = true 106 107 oObj.beforeFirst() 108 109 Out.Log("Initially the cursor should be before first record.") 110 Out.Log("getRow(): expected : 0, actual: " + oObj.getRow()) 111 if (oObj.getRow() = 0) then 112 Out.Log("isBeforeFirst(): expected: 'true', actual '" + oObj.isBeforeFirst() + "'") 113 bIsBeforeFirst = bIsBeforeFirst AND oObj.isBeforeFirst() 114 end if 115 116 Out.Log("Go to not first record...") 117 oObj.next 118 oObj.next 119 Out.Log("isBeforeFirst(): expected: 'false', actual '" + oObj.isBeforeFirst() + "'") 120 bIsBeforeFirst = bIsBeforeFirst AND NOT oObj.isBeforeFirst() 121 122 Out.Log("Go to before first record...") 123 oObj.beforeFirst() 124 Out.Log("isBeforeFirst(): expected: 'true', actual '" + oObj.isBeforeFirst() + "'") 125 bBeforeFirst = bBeforeFirst AND oObj.isBeforeFirst() 126 bIsBeforeFirst = bIsBeforeFirst AND oObj.isBeforeFirst() 127 128 Out.Log("Go to previous position") 129 oObj.previous() 130 Out.Log("isBeforeFirst(): expected: 'true', actual '" + oObj.isBeforeFirst() + "'") 131 bIsBeforeFirst = bIsBeforeFirst AND oObj.isBeforeFirst() 132 bPrevious = bPrevious AND oObj.isBeforeFirst() 133 134 Out.Log("Go to first record...") 135 oObj.first() 136 Out.Log("isBeforeFirst(): expected: 'false', actual '" + oObj.isBeforeFirst() + "'") 137 bIsBeforeFirst = bIsBeforeFirst AND NOT oObj.isBeforeFirst() 138 Out.Log("isFirst(): expected: 'true', actual '" + oObj.isFirst() + "'") 139 bIsFirst = bIsFirst AND oObj.isFirst() 140 Out.Log("getRow(): expected : 1, actual: " + oObj.getRow()) 141 bIsFirst = bIsFirst AND oObj.getRow() = 1 142 Out.Log("RowDsc should contain " + cXResultSetFirstRecord) 143 Out.Log("RowDsc is '" + oObj.getString(1) + "'") 144 bFirst = bFirst AND inStr(1, oObj.getString(1), cXResultSetFirstRecord) 145 146 Out.Log("Go to previous position") 147 oObj.previous() 148 Out.Log("isBeforeFirst(): expected: 'true', actual '" + oObj.isBeforeFirst() + "'") 149 bIsBeforeFirst = bIsBeforeFirst AND oObj.isBeforeFirst() 150 bPrevious = bPrevious AND oObj.isBeforeFirst() 151 Out.Log("isFirst(): expected: 'false', actual '" + oObj.isFirst() + "'") 152 bIsFirst = bIsFirst AND NOT oObj.isFirst() 153 154 Out.Log("Go to beforeFirst()") 155 oObj.beforeFirst() 156 Out.Log("Iterate through all records form first to last") 157 Dim n As Integer 158 n = 0 159 bLoopError = false 160 bIsAfterLastLoop = oObj.isAfterLast() 161 while (n < 1000 AND NOT bIsAfterLastLoop) 162 oObj.next() 163 n = n + 1 164 bIsAfterLastLoop = oObj.isAfterLast() 165 if bLoopError then 166 bLoopError = false 167 n = 1000 168 end if 169 wend 170 171 Out.Log("IsAfterLast(): expected: 'true', actual '" + oObj.IsAfterLast() + "'") 172 bIsAfterLast = bIsAfterLast AND oObj.isAfterLast() 173 Out.Log("IsLast(): expected: 'false', actual '" + oObj.IsLast() + "'") 174 bIsLast = bIsLast AND NOT oObj.isLast() 175 Out.Log("Amount of records is " + n) 176 Out.Log("Trying to go to next record") 177 oObj.next() 178 Out.Log("IsAfterLast(): expected: 'true', actual '" + oObj.IsAfterLast() + "'") 179 bIsAfterLast = bIsAfterLast AND oObj.isAfterLast() 180 181 Out.Log("Go to previous position.") 182 oObj.previous() 183 Out.Log("IsLast(): expected: 'true', actual '" + oObj.IsLast() + "'") 184 bIsLast = bIsLast AND oObj.isLast() 185 Out.Log("RowDsc should contain " + cXResultSetLastRecord) 186 Out.Log("RowDsc is '" + oObj.getString(1) + "'") 187 bIsLast = bIsLast AND inStr(1, oObj.getString(1), cXResultSetLastRecord) 188 189 Out.Log("Iterate through all records form last to first") 190 bLoopError = false 191 bIsBeforeFirstLoop = oObj.isBeforeFirst() 192 while (n > 0 AND NOT bIsBeforeFirstLoop) 193 oObj.previous() 194 n = n - 1 195 bIsBeforeFirstLoop = oObj.isBeforeFirst() 196 if bLoopError then 197 bLoopError = false 198 n = 0 199 end if 200 wend 201 202 Out.Log("isBeforeFirst(): expected: 'true', actual '" + oObj.isBeforeFirst() + "'") 203 bIsBeforeFirst = bIsBeforeFirst AND oObj.isBeforeFirst() 204 205 Out.Log("Trying to go to previous record") 206 oObj.previous() 207 Out.Log("isBeforeFirst(): expected: 'true', actual '" + oObj.isBeforeFirst() + "'") 208 bIsBeforeFirst = bIsBeforeFirst AND oObj.isBeforeFirst() 209 210 211 Test.MethodTested("beforeFirst()", bBeforeFirst) 212 Test.MethodTested("isBeforeFirst()", bIsBeforeFirst) 213 Test.MethodTested("isFirst()", bIsFirst) 214 Test.MethodTested("first()", bFirst) 215 Test.MethodTested("next()", bNext) 216 217 Test.MethodTested("afterLast()", bAfterLast) 218 Test.MethodTested("isAfterLast()", bIsAfterLast) 219 Test.MethodTested("isLast()", bIsLast) 220 Test.MethodTested("last()", bLast) 221 Test.MethodTested("previous()", bPrevious) 222 223 Test.MethodTested("getRow()", bGetRow) 224 225 226 Test.StartMethod("absolute()") 227 bOK = true 228 Out.Log("Go to second record") 229 oObj.absolute(2) 230 Out.Log("RowDsc should contain " + cXResultSetRecord2) 231 Out.Log("RowDsc is '" + oObj.getString(1) + "'") 232 bOK = bOK AND inStr(1, oObj.getString(1), cXResultSetRecord2) 233 Out.Log("Go to record -1") 234 oObj.absolute(-1) 235 Out.Log("RowDsc is '" + oObj.getString(1) + "'") 236 Out.Log("IsLast(): expected: 'true', actual '" + oObj.IsLast() + "'") 237 bOK = bOK AND oObj.isLast() 238 Out.Log("Go to record -2") 239 oObj.absolute(-2) 240 Out.Log("IsLast(): expected: 'false', actual '" + oObj.IsLast() + "'") 241 bOK = bOK AND NOT oObj.isLast() 242 Out.Log("RowDsc should contain " + cXResultSet2BeforeLastRecord) 243 Out.Log("RowDsc is '" + oObj.getString(1) + "'") 244 bOK = bOK AND inStr(1, oObj.getString(1), cXResultSet2BeforeLastRecord) 245 Test.MethodTested("absolute()", bOK) 246 247 Test.StartMethod("relative()") 248 bOK = true 249 Out.Log("Go to before first record") 250 oObj.beforeFirst() 251 on error goto RelativeErrHndl 252 oObj.relative(1) 253 Out.Log("Exception expected!") 254 bOK = false 255 goto ContRelative 256 RelativeErrHndl: 257 Out.Log("Expected exception.") 258 259 ContRelative: 260 On Error Goto NewErrHndl 261 Out.Log("Go to first record and relative(1)") 262 oObj.next() 263 oObj.relative(1) 264 Out.Log("RowDsc should contain " + cXResultSetRecord2) 265 Out.Log("RowDsc is '" + oObj.getString(1) + "'") 266 bOK = bOK AND inStr(1, oObj.getString(1), cXResultSetRecord2) 267 Out.Log("Go to relative(-1)") 268 oObj.relative(-1) 269 Out.Log("RowDsc should contain " + cXResultSetRecord1) 270 Out.Log("RowDsc is '" + oObj.getString(1) + "'") 271 bOK = bOK AND inStr(1, oObj.getString(1), cXResultSetRecord1) 272 Out.Log("RowDsc is '" + oObj.getString(1) + "'") 273 Test.MethodTested("relative()", bOK) 274 275 Test.StartMethod("refreshRow()") 276 bOK = true 277 oObj.refreshRow() 278 Test.MethodTested("refreshRow()", bOK) 279 280 Test.StartMethod("rowUpdated()") 281 bOK = true 282 Out.Log("rowUpdated() is " + oObj.rowUpdated()) 283 bOK = bOK AND NOT oObj.rowUpdated() 284 Test.MethodTested("rowUpdated()", bOK) 285 286 Test.StartMethod("rowInserted()") 287 bOK = true 288 Out.Log("rowInserted() is " + oObj.rowInserted()) 289 bOK = bOK AND NOT oObj.rowInserted() 290 Test.MethodTested("rowInserted()", bOK) 291 292 Test.StartMethod("rowDeleted()") 293 bOK = true 294 Out.Log("rowDeleted() is " + oObj.rowDeleted()) 295 bOK = bOK AND NOT oObj.rowDeleted() 296 Test.MethodTested("rowDeleted()", bOK) 297 298 Test.StartMethod("getStatement()") 299 bOK = true 300 oStatement = oObj.getStatement() 301 bOK = bOK AND NOT isNULL(oStatement) 302 Test.MethodTested("getStatement()", bOK) 303 304Exit Sub 305NewErrHndl: 306ErrHndl: 307 Test.Exception() 308 bOK = false 309 bLoopError = true 310 resume next 311End Sub 312</script:module> 313