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