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'  Licensed to the Apache Software Foundation (ASF) under one
9'  or more contributor license agreements.  See the NOTICE file
10'  distributed with this work for additional information
11'  regarding copyright ownership.  The ASF licenses this file
12'  to you under the Apache License, Version 2.0 (the
13'  "License"); you may not use this file except in compliance
14'  with the License.  You may obtain a copy of the License at
15'
16'    http://www.apache.org/licenses/LICENSE-2.0
17'
18'  Unless required by applicable law or agreed to in writing,
19'  software distributed under the License is distributed on an
20'  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21'  KIND, either express or implied.  See the License for the
22'  specific language governing permissions and limitations
23'  under the License.
24'
25'*************************************************************************
26
27
28
29
30
31'*************************************************************************
32' This Interface/Service test depends on the following GLOBAL variables,
33' which must be specified in the object creation:
34
35'     - Global cXResultSetFirstRecord as String
36'       Global cXResultSetLastRecord as String
37'       Global cXResultSetRecord1 as String
38'       Global cXResultSetRecord2 as String
39'       Global cXResultSet2BeforeLastRecord as String
40
41'*************************************************************************
42
43
44
45
46
47Sub RunTest()
48
49'*************************************************************************
50' INTERFACE:
51' com.sun.star.sdbc.XResultSet
52'*************************************************************************
53On Error Goto ErrHndl
54    Dim bOK As Boolean
55
56
57    Out.Log("ReCreating Object, to be sure that it is in initial state.")
58
59    Test.StartMethod("beforeFirst()")
60    Test.StartMethod("isBeforeFirst()")
61    Test.StartMethod("isFirst()")
62    Test.StartMethod("first()")
63    Test.StartMethod("next()")
64
65    Test.StartMethod("afterLast()")
66    Test.StartMethod("isAfterLast()")
67    Test.StartMethod("isLast()")
68    Test.StartMethod("last()")
69    Test.StartMethod("previous()")
70
71    Test.StartMethod("getRow()")
72
73    Dim bBeforeFirst As Boolean
74    Dim bIsBeforeFirst As Boolean
75    Dim bIsBeforeFirstLoop As Boolean
76    Dim bIsFirst As Boolean
77    Dim bFirst As Boolean
78    Dim bNext As Boolean
79    Dim bAfterLast As Boolean
80    Dim bIsAfterLast As Boolean
81    Dim bIsAfterLastLoop As Boolean
82    Dim bIsLast As Boolean
83    Dim bLast As Boolean
84    Dim bPrevious As Boolean
85    Dim bGetRow As Boolean
86    Dim bLoopError as Boolean
87
88    bLoopError = false
89    bBeforeFirst = true
90    bIsBeforeFirst = true
91    bIsFirst = true
92    bFirst = true
93    bNext = true
94    bAfterLast = true
95    bIsAfterLast = true
96    bIsLast = true
97    bLast = true
98    bPrevious = true
99    bGetRow = true
100
101    oObj.beforeFirst()
102
103    Out.Log("Initially the cursor should be before first record.")
104    Out.Log("getRow(): expected : 0, actual: " + oObj.getRow())
105    if (oObj.getRow() = 0) then
106        Out.Log("isBeforeFirst(): expected: 'true', actual '" + oObj.isBeforeFirst() + "'")
107        bIsBeforeFirst = bIsBeforeFirst AND oObj.isBeforeFirst()
108    end if
109
110    Out.Log("Go to not first record...")
111    oObj.next
112    oObj.next
113    Out.Log("isBeforeFirst(): expected: 'false', actual '" + oObj.isBeforeFirst() + "'")
114    bIsBeforeFirst = bIsBeforeFirst AND NOT oObj.isBeforeFirst()
115
116    Out.Log("Go to before first record...")
117    oObj.beforeFirst()
118    Out.Log("isBeforeFirst(): expected: 'true', actual '" + oObj.isBeforeFirst() + "'")
119    bBeforeFirst = bBeforeFirst AND oObj.isBeforeFirst()
120    bIsBeforeFirst = bIsBeforeFirst AND oObj.isBeforeFirst()
121
122    Out.Log("Go to previous position")
123    oObj.previous()
124    Out.Log("isBeforeFirst(): expected: 'true', actual '" + oObj.isBeforeFirst() + "'")
125    bIsBeforeFirst = bIsBeforeFirst AND oObj.isBeforeFirst()
126    bPrevious = bPrevious AND oObj.isBeforeFirst()
127
128    Out.Log("Go to first record...")
129    oObj.first()
130    Out.Log("isBeforeFirst(): expected: 'false', actual '" + oObj.isBeforeFirst() + "'")
131    bIsBeforeFirst = bIsBeforeFirst AND NOT oObj.isBeforeFirst()
132    Out.Log("isFirst(): expected: 'true', actual '" + oObj.isFirst() + "'")
133    bIsFirst = bIsFirst AND oObj.isFirst()
134    Out.Log("getRow(): expected : 1, actual: " + oObj.getRow())
135    bIsFirst = bIsFirst AND oObj.getRow() = 1
136    Out.Log("RowDsc should contain " + cXResultSetFirstRecord)
137    Out.Log("RowDsc is '" + oObj.getString(1) + "'")
138    bFirst = bFirst AND inStr(1, oObj.getString(1), cXResultSetFirstRecord)
139
140    Out.Log("Go to previous position")
141    oObj.previous()
142    Out.Log("isBeforeFirst(): expected: 'true', actual '" + oObj.isBeforeFirst() + "'")
143    bIsBeforeFirst = bIsBeforeFirst AND oObj.isBeforeFirst()
144    bPrevious = bPrevious AND oObj.isBeforeFirst()
145    Out.Log("isFirst(): expected: 'false', actual '" + oObj.isFirst() + "'")
146    bIsFirst = bIsFirst AND NOT oObj.isFirst()
147
148    Out.Log("Go to beforeFirst()")
149    oObj.beforeFirst()
150    Out.Log("Iterate through all records form first to last")
151    Dim n As Integer
152    n = 0
153    bLoopError = false
154    bIsAfterLastLoop = oObj.isAfterLast()
155    while (n &lt; 1000 AND NOT bIsAfterLastLoop)
156        oObj.next()
157        n = n + 1
158        bIsAfterLastLoop = oObj.isAfterLast()
159        if bLoopError then
160            bLoopError = false
161            n = 1000
162        end if
163    wend
164
165    Out.Log("IsAfterLast(): expected: 'true', actual '" + oObj.IsAfterLast() + "'")
166    bIsAfterLast = bIsAfterLast AND oObj.isAfterLast()
167    Out.Log("IsLast(): expected: 'false', actual '" + oObj.IsLast() + "'")
168    bIsLast = bIsLast AND NOT oObj.isLast()
169    Out.Log("Amount of records is " + n)
170    Out.Log("Trying to go to next record")
171    oObj.next()
172    Out.Log("IsAfterLast(): expected: 'true', actual '" + oObj.IsAfterLast() + "'")
173    bIsAfterLast = bIsAfterLast AND oObj.isAfterLast()
174
175    Out.Log("Go to previous position.")
176    oObj.previous()
177    Out.Log("IsLast(): expected: 'true', actual '" + oObj.IsLast() + "'")
178    bIsLast = bIsLast AND oObj.isLast()
179    Out.Log("RowDsc should contain " + cXResultSetLastRecord)
180    Out.Log("RowDsc is '" + oObj.getString(1) + "'")
181    bIsLast = bIsLast AND inStr(1, oObj.getString(1), cXResultSetLastRecord)
182
183    Out.Log("Iterate through all records form last to first")
184    bLoopError = false
185    bIsBeforeFirstLoop = oObj.isBeforeFirst()
186    while (n &gt; 0 AND NOT bIsBeforeFirstLoop)
187        oObj.previous()
188        n = n - 1
189        bIsBeforeFirstLoop = oObj.isBeforeFirst()
190        if bLoopError then
191            bLoopError = false
192            n = 0
193        end if
194    wend
195
196    Out.Log("isBeforeFirst(): expected: 'true', actual '" + oObj.isBeforeFirst() + "'")
197    bIsBeforeFirst = bIsBeforeFirst AND oObj.isBeforeFirst()
198
199    Out.Log("Trying to go to previous record")
200    oObj.previous()
201    Out.Log("isBeforeFirst(): expected: 'true', actual '" + oObj.isBeforeFirst() + "'")
202    bIsBeforeFirst = bIsBeforeFirst AND oObj.isBeforeFirst()
203
204
205    Test.MethodTested("beforeFirst()", bBeforeFirst)
206    Test.MethodTested("isBeforeFirst()", bIsBeforeFirst)
207    Test.MethodTested("isFirst()", bIsFirst)
208    Test.MethodTested("first()", bFirst)
209    Test.MethodTested("next()", bNext)
210
211    Test.MethodTested("afterLast()", bAfterLast)
212    Test.MethodTested("isAfterLast()", bIsAfterLast)
213    Test.MethodTested("isLast()", bIsLast)
214    Test.MethodTested("last()", bLast)
215    Test.MethodTested("previous()", bPrevious)
216
217    Test.MethodTested("getRow()", bGetRow)
218
219
220    Test.StartMethod("absolute()")
221    bOK = true
222    Out.Log("Go to second record")
223    oObj.absolute(2)
224    Out.Log("RowDsc should contain " + cXResultSetRecord2)
225    Out.Log("RowDsc is '" + oObj.getString(1) + "'")
226    bOK = bOK AND inStr(1, oObj.getString(1), cXResultSetRecord2)
227    Out.Log("Go to record -1")
228    oObj.absolute(-1)
229    Out.Log("RowDsc is '" + oObj.getString(1) + "'")
230    Out.Log("IsLast(): expected: 'true', actual '" + oObj.IsLast() + "'")
231    bOK = bOK AND oObj.isLast()
232    Out.Log("Go to record -2")
233    oObj.absolute(-2)
234    Out.Log("IsLast(): expected: 'false', actual '" + oObj.IsLast() + "'")
235    bOK = bOK AND NOT oObj.isLast()
236    Out.Log("RowDsc should contain " + cXResultSet2BeforeLastRecord)
237    Out.Log("RowDsc is '" + oObj.getString(1) + "'")
238    bOK = bOK AND inStr(1, oObj.getString(1), cXResultSet2BeforeLastRecord)
239    Test.MethodTested("absolute()", bOK)
240
241    Test.StartMethod("relative()")
242    bOK = true
243    Out.Log("Go to before first record")
244    oObj.beforeFirst()
245    on error goto RelativeErrHndl
246        oObj.relative(1)
247        Out.Log("Exception expected!")
248        bOK = false
249    goto ContRelative
250    RelativeErrHndl:
251        Out.Log("Expected exception.")
252
253    ContRelative:
254    On Error Goto NewErrHndl
255    Out.Log("Go to first record and relative(1)")
256    oObj.next()
257    oObj.relative(1)
258    Out.Log("RowDsc should contain " + cXResultSetRecord2)
259    Out.Log("RowDsc is '" + oObj.getString(1) + "'")
260    bOK = bOK AND inStr(1, oObj.getString(1), cXResultSetRecord2)
261    Out.Log("Go to relative(-1)")
262    oObj.relative(-1)
263    Out.Log("RowDsc should contain " + cXResultSetRecord1)
264    Out.Log("RowDsc is '" + oObj.getString(1) + "'")
265    bOK = bOK AND inStr(1, oObj.getString(1), cXResultSetRecord1)
266    Out.Log("RowDsc is '" + oObj.getString(1) + "'")
267    Test.MethodTested("relative()", bOK)
268
269    Test.StartMethod("refreshRow()")
270    bOK = true
271    oObj.refreshRow()
272    Test.MethodTested("refreshRow()", bOK)
273
274    Test.StartMethod("rowUpdated()")
275    bOK = true
276    Out.Log("rowUpdated() is " + oObj.rowUpdated())
277    bOK = bOK AND NOT oObj.rowUpdated()
278    Test.MethodTested("rowUpdated()", bOK)
279
280    Test.StartMethod("rowInserted()")
281    bOK = true
282    Out.Log("rowInserted() is " + oObj.rowInserted())
283    bOK = bOK AND NOT oObj.rowInserted()
284    Test.MethodTested("rowInserted()", bOK)
285
286    Test.StartMethod("rowDeleted()")
287    bOK = true
288    Out.Log("rowDeleted() is " + oObj.rowDeleted())
289    bOK = bOK AND NOT oObj.rowDeleted()
290    Test.MethodTested("rowDeleted()", bOK)
291
292    Test.StartMethod("getStatement()")
293    bOK = true
294    oStatement = oObj.getStatement()
295    bOK = bOK AND NOT isNULL(oStatement)
296    Test.MethodTested("getStatement()", bOK)
297
298Exit Sub
299NewErrHndl:
300ErrHndl:
301    Test.Exception()
302    bOK = false
303    bLoopError = true
304    resume next
305End Sub
306</script:module>
307