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