summaryrefslogtreecommitdiff
path: root/qadevOOo/tests/basic/ifc/sdbc/XRowUpdate/sdbc_XRowUpdate.xba
blob: 03dab0a3ccbf4d5ba46b237d1622cf9e89fd75fb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
<script:module xmlns:script="http://openoffice.org/2000/script" script:name="sdbc_XRowUpdate" script:language="StarBasic">


'*************************************************************************
'
' DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
' 
' Copyright 2000, 2010 Oracle and/or its affiliates.
'
' OpenOffice.org - a multi-platform office productivity suite
'
' This file is part of OpenOffice.org.
'
' OpenOffice.org is free software: you can redistribute it and/or modify
' it under the terms of the GNU Lesser General Public License version 3
' only, as published by the Free Software Foundation.
'
' OpenOffice.org is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
' GNU Lesser General Public License version 3 for more details
' (a copy is included in the LICENSE file that accompanied this code).
'
' You should have received a copy of the GNU Lesser General Public License
' version 3 along with OpenOffice.org.  If not, see
' <http://www.openoffice.org/license.html>
' for a copy of the LGPLv3 License.
'
'*************************************************************************
'*************************************************************************



' Be sure that all variables are dimensioned:
option explicit

'*************************************************************************
' This Interface/Service test depends on the following GLOBAL variables,
' which must be specified in the object creation:

'     - Global rowTypes As Variant
'       must be an array of Strings with description of column types
'     - Global rowTypesCol As Variant
'       corresponding column numbers

'*************************************************************************






Sub RunTest()

'*************************************************************************
' INTERFACE: 
' com.sun.star.sdbc.XRowUpdate
'*************************************************************************
On Error Goto ErrHndl
    Dim bOK As Boolean, bNullOK As Boolean
    Dim i As Integer
    Dim getV As Variant, newV As Variant, resV As Variant
    Dim colType As String

    if NOT hasUnoInterfaces(oObj, "com.sun.star.sdbc.XRow") then
        Out.Log("The interface com.sun.star.sdbc.XRow isn't supported by the component.")
        Out.Log("The test must be upgraded !!!")
        exit Sub
    end if
    
    Test.RecreateObj()

    bNullOK = true

    Test.StartMethod("updateBoolean()")
    colType = "boolean"
    i = findColumn(colType)
    if i >= 0 then 
        bOK = true
        getV = oObj.getBoolean(i+1)
        newV = NOT getV
        oObj.updateBoolean(i+1, newV)
        resV = oObj.getBoolean(i+1)
        Out.Log("Was: " + getv + ", New: " + newV + ", Res: " + resV)
        bOK = bOK AND (resV = newV)
        Test.MethodTested("updateBoolean()", bOK)

        oObj.updateNull(i+1)
        oObj.getBoolean(i+1)
        bNullOK = bNullOK AND oObj.wasNull()
    else
        Out.Log("!!! Column of type '" + colType + "' is not found. No test performed.")
        Out.Log("Nevertheless status is OK")
        Test.MethodTested("updateBoolean()", true)
    end if 
            
    Test.StartMethod("updateByte()")
    colType = "byte"
    i = findColumn(colType)
    if i >= 0 then 
        bOK = true
        getV = oObj.getByte(i+1)
        newV = getV + 1
        oObj.updateByte(i+1, newV)
        resV = oObj.getByte(i+1)
        Out.Log("Was: " + getv + ", New: " + newV + ", Res: " + resV)
        bOK = bOK AND (resV = newV)
        Test.MethodTested("updateByte()", bOK)

        oObj.updateNull(i+1)
        oObj.getByte(i+1)
        bNullOK = bNullOK AND oObj.wasNull()
    else
        Out.Log("!!! Column of type '" + colType + "' is not found. No test performed.")
        Out.Log("Nevertheless status is OK")
        Test.MethodTested("updateByte()", true)
    end if 

    Test.StartMethod("updateShort()")
    colType = "short"
    i = findColumn(colType)
    if i >= 0 then 
        bOK = true
        getV = oObj.getShort(i+1)
        newV = getV + 1
        oObj.updateShort(i+1, newV)
        resV = oObj.getShort(i+1)
        Out.Log("Was: " + getv + ", New: " + newV + ", Res: " + resV)
        bOK = bOK AND (resV = newV)
        Test.MethodTested("updateShort()", bOK)

        oObj.updateNull(i+1)
        oObj.getShort(i+1)
        bNullOK = bNullOK AND oObj.wasNull()
    else
        Out.Log("!!! Column of type '" + colType + "' is not found. No test performed.")
        Out.Log("Nevertheless status is OK")
        Test.MethodTested("updateShort()", true)
    end if 

    Test.StartMethod("updateInt()")
    colType = "int"
    i = findColumn(colType)
    if i >= 0 then 
        bOK = true
        getV = oObj.getInt(i+1)
        newV = getV + 1
        oObj.updateInt(i+1, newV)
        resV = oObj.getInt(i+1)
        Out.Log("Was: " + getv + ", New: " + newV + ", Res: " + resV)
        bOK = bOK AND (resV = newV)
        Test.MethodTested("updateInt()", bOK)

        oObj.updateNull(i+1)
        oObj.getInt(i+1)
        bNullOK = bNullOK AND oObj.wasNull()
    else
        Out.Log("!!! Column of type '" + colType + "' is not found. No test performed.")
        Out.Log("Nevertheless status is OK")
        Test.MethodTested("updateInt()", true)
    end if 
        
    Test.StartMethod("updateLong()")
    colType = "long"
    i = findColumn(colType)
    if i >= 0 then 
        bOK = true
        getV = oObj.getLong(i+1)
        newV = getV + 1
        oObj.updateLong(i+1, newV)
        resV = oObj.getLong(i+1)
        Out.Log("Was: " + getv + ", New: " + newV + ", Res: " + resV)
        bOK = bOK AND (resV = newV)
        Test.MethodTested("updateLong()", bOK)

        oObj.updateNull(i+1)
        oObj.getLong(i+1)
        bNullOK = bNullOK AND oObj.wasNull()
    else
        Out.Log("!!! Column of type '" + colType + "' is not found. No test performed.")
        Out.Log("Nevertheless status is OK")
        Test.MethodTested("updateLong()", true)
    end if 

    Test.StartMethod("updateFloat()")
    colType = "float"
    i = findColumn(colType)
    if i >= 0 then 
        bOK = true
        getV = oObj.getFloat(i+1)
        newV = getV + 1.3
        oObj.updateFloat(i+1, newV)
        resV = oObj.getFloat(i+1)
        Out.Log("Was: " + getv + ", New: " + newV + ", Res: " + resV)
        bOK = bOK AND (resV = newV)
        Test.MethodTested("updateFloat()", bOK)

        oObj.updateNull(i+1)
        oObj.getFloat(i+1)
        bNullOK = bNullOK AND oObj.wasNull()
    else
        Out.Log("!!! Column of type '" + colType + "' is not found. No test performed.")
        Out.Log("Nevertheless status is OK")
        Test.MethodTested("updateFloat()", true)
    end if 

    Test.StartMethod("updateDouble()")
    colType = "double"
    i = findColumn(colType)
    if i >= 0 then 
        bOK = true
        getV = oObj.getDouble(i+1)
        newV = getV + 1.5
        oObj.updateDouble(i+1, newV)
        resV = oObj.getDouble(i+1)
        Out.Log("Was: " + getv + ", New: " + newV + ", Res: " + resV)
        bOK = bOK AND (resV = newV)
        Test.MethodTested("updateDouble()", bOK)

        oObj.updateNull(i+1)
        oObj.getDouble(i+1)
        bNullOK = bNullOK AND oObj.wasNull()
    else
        Out.Log("!!! Column of type '" + colType + "' is not found. No test performed.")
        Out.Log("Nevertheless status is OK")
        Test.MethodTested("updateDouble()", true)
    end if 

    Test.StartMethod("updateString()")
    colType = "string"
    i = findColumn(colType)
    if i >= 0 then 
        bOK = true
        getV = oObj.getString(i+1)
        newV = "_" + getV
        oObj.updateString(i+1, newV)
        resV = oObj.getString(i+1)
        Out.Log("Was: '" + getv + "', New: '" + newV + "', Res: '" + resV + "'")
        bOK = bOK AND (resV = newV)
        Test.MethodTested("updateString()", bOK)

        oObj.updateNull(i+1)
        oObj.getString(i+1)
        bNullOK = bNullOK AND oObj.wasNull()
    else
        Out.Log("!!! Column of type '" + colType + "' is not found. No test performed.")
        Out.Log("Nevertheless status is OK")
        Test.MethodTested("updateString()", true)
    end if 

    Test.StartMethod("updateBytes()")
    colType = "bytes"
    i = findColumn(colType)
    if i >= 0 then 
        bOK = true
        getV = oObj.getBytes(i+1)
        
        if (oObj.wasNull() OR ubound(getV()) &lt; 0) then
            newV = Array(1,2,3)
        else
            newV = getV
            newV(0) = newV(0) + 1
        end if
        
        oObj.updateBytes(i+1, newV)
        resV = oObj.getBytes(i+1)

        Out.Log("Was: " + getv(0) + ", New: " + newV(0) + ", Res: " + resV(0))
        bOK = bOK AND (resV(0) = newV(0))
        Test.MethodTested("updateBytes()", bOK)

        oObj.updateNull(i+1)
        oObj.getBytes(i+1)
        bNullOK = bNullOK AND oObj.wasNull()
    else
        Out.Log("!!! Column of type '" + colType + "' is not found. No test performed.")
        Out.Log("Nevertheless status is OK")
        Test.MethodTested("updateBytes()", true)
    end if 


    Dim dat As com.sun.star.util.Date
    Test.StartMethod("updateDate()")
    colType = "date"
    i = findColumn(colType)
    if i >= 0 then 
        bOK = true
        getV = oObj.getDate(i+1)
        if (oObj.wasNull() OR isNull(getV)) then
            newV = dat
        else
            newV = getV
            newV.Year = newV.Year + 1
        end if
        
        oObj.updateDate(i+1, newV)
        resV = oObj.getDate(i+1)
        Out.Log("Was: '" + getv.Year + "', New: '" + newV.Year + "', Res: '" + resV.Year + "'")
        bOK = bOK AND (resV.Year = newV.Year)
        Test.MethodTested("updateDate()", bOK)

        oObj.updateNull(i+1)
        oObj.getDate(i+1)
        bNullOK = bNullOK AND oObj.wasNull()
    else
        Out.Log("!!! Column of type '" + colType + "' is not found. No test performed.")
        Out.Log("Nevertheless status is OK")
        Test.MethodTested("updateDate()", true)
    end if 

    Dim tim As com.sun.star.util.Time
    Test.StartMethod("updateTime()")
    colType = "time"
    i = findColumn(colType)
    if i >= 0 then 
        bOK = true
        getV = oObj.getTime(i+1)
        if (oObj.wasNull() OR isNull(getV)) then
            newV = tim
        else
            newV = getV
            newV.Seconds = newV.Seconds + 1
        end if
        
        oObj.updateTime(i+1, newV)
        resV = oObj.getTime(i+1)
        Out.Log("Was: '" + getv.Seconds + "', New: '" + newV.Seconds + "', Res: '" + resV.Seconds + "'")
        bOK = bOK AND (resV.Seconds = newV.Seconds)
        Test.MethodTested("updateTime()", bOK)

        oObj.updateNull(i+1)
        oObj.getTime(i+1)
        bNullOK = bNullOK AND oObj.wasNull()
    else
        Out.Log("!!! Column of type '" + colType + "' is not found. No test performed.")
        Out.Log("Nevertheless status is OK")
        Test.MethodTested("updateTime()", true)
    end if 

    Dim dattm As com.sun.star.util.DateTime
    Test.StartMethod("updateTimestamp()")
    colType = "timestamp"
    i = findColumn(colType)
    if i >= 0 then 
        bOK = true
        getV = oObj.getTimestamp(i+1)
        if (oObj.wasNull() OR isNull(getV)) then
            newV = dattm
        else
            newV = getV
            newV.Year = newV.Year + 1
        end if
        
        oObj.updateTimestamp(i+1, newV)
        resV = oObj.getTimestamp(i+1)
        Out.Log("Was: '" + getv.Year + "', New: '" + newV.Year + "', Res: '" + resV.Year + "'")
        bOK = bOK AND (resV.Year = newV.Year)
        Test.MethodTested("updateTimestamp()", bOK)

        oObj.updateNull(i+1)
        oObj.getTimestamp(i+1)
        bNullOK = bNullOK AND oObj.wasNull()
    else
        Out.Log("!!! Column of type '" + colType + "' is not found. No test performed.")
        Out.Log("Nevertheless status is OK")
        Test.MethodTested("updateTimestamp()", true)
    end if 

    Dim bytes As Variant, nBytes As Long
    Test.StartMethod("updateCharacterStream()")
    colType = "characterstream"
    i = findColumn(colType)
    if i >= 0 then 
        bOK = true
        newV = createUnoService("com.sun.star.io.Pipe")
        newV.writeBytes(Array(123, 234))
        oObj.updateCharacterStream(i+1, newV)
        resV = oObj.getCharacterStream(i+1)
        'Out.Log("Was: '" + getv + "', New: '" + newV + "', Res: '" + resV + "'")
        bOK = bOK AND NOT oObj.wasNull() AND NOT isNull(resV)
        
        if bOK then
            Out.Log("Testing further ...")
            nBytes = resV.readBytes(bytes, 2)
            bOK = bOK AND (nBytes = 2) AND (bytes(0) = 123) AND (bytes(1) = 234)
        end if

        Test.MethodTested("updateCharacterStream()", bOK)

        oObj.updateNull(i+1)
        oObj.getCharacterStream(i+1)
        bNullOK = bNullOK AND oObj.wasNull()
    else
        Out.Log("!!! Column of type '" + colType + "' is not found. No test performed.")
        Out.Log("Nevertheless status is OK")
        Test.MethodTested("updateCharacterStream()", true)
    end if 

    Test.StartMethod("updateBinaryStream()")
    colType = "binarystream"
    i = findColumn(colType)
    if i >= 0 then 
        bOK = true
        newV = createUnoService("com.sun.star.io.Pipe")
        newV.writeBytes(Array(123, 234))
        oObj.updateBinaryStream(i+1, newV)
        resV = oObj.getBinaryStream(i+1)
        'Out.Log("Was: '" + getv + "', New: '" + newV + "', Res: '" + resV + "'")
        bOK = bOK AND NOT oObj.wasNull() AND NOT isNull(resV)
        
        if bOK then
            Out.Log("Testing further ...")
            nBytes = resV.readBytes(bytes, 2)
            bOK = bOK AND (nBytes = 2) AND (bytes(0) = 123) AND (bytes(1) = 234)
        end if

        Test.MethodTested("updateBinaryStream()", bOK)

        oObj.updateNull(i+1)
        oObj.getBinaryStream(i+1)
        bNullOK = bNullOK AND oObj.wasNull()
    else
        Out.Log("!!! Column of type '" + colType + "' is not found. No test performed.")
        Out.Log("Nevertheless status is OK")
        Test.MethodTested("updateBinaryStream()", true)
    end if 

    Test.StartMethod("updateObject()")
    colType = "object"
    i = findColumn(colType)
    if i >= 0 then 
        bOK = true
        getV = oObj.getObject(i+1)
        if (NOT hasUnoInterfaces(getV, "com.sun.star.io.XInputStream")) then
            newV = createUnoService("com.sun.star.io.DataInputStream")
        else
            newV = createUnoService("com.sun.star.io.DataOutputStream")
        end if
        
        oObj.updateObject(i+1, newV)
        resV = oObj.getObject(i+1)
        
        bOK = bOK AND (hasUnoInterfaces(newV, "com.sun.star.io.XInputStream") = _
                       hasUnoInterfaces(resV, "com.sun.star.io.XInputStream")) AND _
                      (hasUnoInterfaces(newV, "com.sun.star.io.XOutputStream") = _
                       hasUnoInterfaces(resV, "com.sun.star.io.XOutputStream"))
                       
        Test.MethodTested("updateObject()", bOK)

        oObj.updateNull(i+1)
        oObj.getObject(i+1)
        bNullOK = bNullOK AND oObj.wasNull()
    else
        Out.Log("!!! Column of type '" + colType + "' is not found. No test performed.")
        Out.Log("Nevertheless status is OK")
        Test.MethodTested("updateObject()", true)
    end if 

    Test.StartMethod("updateNumericObject()")
    colType = "numericobject"
    i = findColumn(colType)
    if i >= 0 then 
        bOK = true
        getV = oObj.getNumericObject(i+1)
        if (NOT hasUnoInterfaces(getV, "com.sun.star.io.XInputStream")) then
            newV = createUnoService("com.sun.star.io.DataInputStream")
        else
            newV = createUnoService("com.sun.star.io.DataOutputStream")
        end if
        
        oObj.updateNumericObject(i+1, newV, 0)
        resV = oObj.getNumericObject(i+1)
        
        bOK = bOK AND (hasUnoInterfaces(newV, "com.sun.star.io.XInputStream") = _
                       hasUnoInterfaces(resV, "com.sun.star.io.XInputStream")) AND _
                      (hasUnoInterfaces(newV, "com.sun.star.io.XOutputStream") = _
                       hasUnoInterfaces(resV, "com.sun.star.io.XOutputStream"))
                       
        Test.MethodTested("updateNumericObject()", bOK)

        oObj.updateNull(i+1)
        oObj.getNumericObject(i+1)
        bNullOK = bNullOK AND oObj.wasNull()
    else
        Out.Log("!!! Column of type '" + colType + "' is not found. No test performed.")
        Out.Log("Nevertheless status is OK")
        Test.MethodTested("updateNumericObject()", true)
    end if 
            
    Test.StartMethod("updateNull()")
    Test.MethodTested("updateNull()", bNullOK)

Exit Sub
ErrHndl:
    Test.Exception()
    bOK = false
    resume next
End Sub

Function findColumn(cType As String) As Integer
    Dim i As Integer
    
    for i = lbound(rowTypes()) to ubound(rowTypes())
        if rowTypes(i) = cType then
            findColumn() = rowTypesCol(i) - 1
            exit function
        end if    
    next i
    
    findColumn() = -1 
End function
</script:module>