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