File: error.vbs

package info (click to toggle)
wine-development 4.2-4
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 209,180 kB
  • sloc: ansic: 2,917,742; perl: 18,943; yacc: 15,637; makefile: 9,182; objc: 6,548; lex: 4,315; python: 1,786; cpp: 1,042; sh: 771; java: 742; xml: 557; awk: 69; cs: 17
file content (389 lines) | stat: -rw-r--r-- 11,465 bytes parent folder | download | duplicates (2)
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
'
' Copyright 2014 Jacek Caban for CodeWeavers
'
' This library is free software; you can redistribute it and/or
' modify it under the terms of the GNU Lesser General Public
' License as published by the Free Software Foundation; either
' version 2.1 of the License, or (at your option) any later version.
'
' This library 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 for more details.
'
' You should have received a copy of the GNU Lesser General Public
' License along with this library; if not, write to the Free Software
' Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
'

Option Explicit

const E_TESTERROR = &h80080008&

const VB_E_FORLOOPNOTINITIALIZED = 92
const VB_E_OBJNOTCOLLECTION = 451

const E_NOTIMPL = &h80004001&
const E_NOINTERFACE = &h80004002&
const DISP_E_UNKNOWNINTERFACE = &h80020001&
const DISP_E_MEMBERNOTFOUND = &h80020003&
const DISP_E_PARAMNOTFOUND = &h80020004&
const DISP_E_TYPEMISMATCH = &h80020005&
const DISP_E_UNKNOWNNAME = &h80020006&
const DISP_E_NONAMEDARGS = &h80020007&
const DISP_E_BADVARTYPE = &h80020008&
const DISP_E_OVERFLOW = &h8002000A&
const DISP_E_BADINDEX = &h8002000B&
const DISP_E_UNKNOWNLCID = &h8002000C&
const DISP_E_ARRAYISLOCKED = &h8002000D&
const DISP_E_BADPARAMCOUNT = &h8002000E&
const DISP_E_PARAMNOTOPTIONAL = &h8002000F&
const DISP_E_NOTACOLLECTION = &h80020011&
const TYPE_E_DLLFUNCTIONNOTFOUND = &h8002802F&
const TYPE_E_TYPEMISMATCH = &h80028CA0&
const TYPE_E_OUTOFBOUNDS = &h80028CA1&
const TYPE_E_IOERROR = &h80028CA2&
const TYPE_E_CANTCREATETMPFILE = &h80028CA3&
const STG_E_FILENOTFOUND = &h80030002&
const STG_E_PATHNOTFOUND = &h80030003&
const STG_E_TOOMANYOPENFILES = &h80030004&
const STG_E_ACCESSDENIED = &h80030005&
const STG_E_INSUFFICIENTMEMORY = &h80030008&
const STG_E_NOMOREFILES = &h80030012&
const STG_E_DISKISWRITEPROTECTED = &h80030013&
const STG_E_WRITEFAULT = &h8003001D&
const STG_E_READFAULT = &h8003001E&
const STG_E_SHAREVIOLATION = &h80030020&
const STG_E_LOCKVIOLATION = &h80030021&
const STG_E_FILEALREADYEXISTS = &h80030050&
const STG_E_MEDIUMFULL = &h80030070&
const STG_E_INVALIDNAME = &h800300FC&
const STG_E_INUSE = &h80030100&
const STG_E_NOTCURRENT = &h80030101&
const STG_E_CANTSAVE = &h80030103&
const REGDB_E_CLASSNOTREG = &h80040154&
const MK_E_UNAVAILABLE = &h800401E3&
const MK_E_INVALIDEXTENSION = &h800401E6&
const MK_E_CANTOPENFILE = &h800401EA&
const CO_E_CLASSSTRING = &h800401F3&
const CO_E_APPNOTFOUND = &h800401F5&
const O_E_APPDIDNTREG = &h800401FE&
const E_ACCESSDENIED = &h80070005&
const E_OUTOFMEMORY = &h8007000E&
const E_INVALIDARG = &h80070057&
const RPC_S_SERVER_UNAVAILABLE = &h800706BA&
const CO_E_SERVER_EXEC_FAILURE = &h80080005&

call ok(Err.Number = 0, "Err.Number = " & Err.Number)
call ok(getVT(Err.Number) = "VT_I4", "getVT(Err.Number) = " & getVT(Err.Number))

dim calledFunc

sub returnTrue
    calledFunc = true
    returnTrue = true
end sub

sub testThrow
    on error resume next

    dim x, y

    call throwInt(1000)
    call ok(Err.Number = 0, "Err.Number = " & Err.Number)

    call throwInt(E_TESTERROR)
    call ok(Err.Number = E_TESTERROR, "Err.Number = " & Err.Number)

    call throwInt(1000)
    call ok(Err.Number = E_TESTERROR, "Err.Number = " & Err.Number)

    call Err.clear()
    call ok(Err.Number = 0, "Err.Number = " & Err.Number)

    x = 6
    calledFunc = false
    x = throwInt(E_TESTERROR) and returnTrue()
    call ok(x = 6, "x = " & x)
    call ok(not calledFunc, "calledFunc = " & calledFunc)
    call ok(Err.Number = E_TESTERROR, "Err.Number = " & Err.Number)

    x = false
    call Err.clear()
    if false and throwInt(E_TESTERROR) then
        x = true
    else
        call ok(false, "unexpected if else branch on throw")
    end if
    call ok(x, "if branch not taken")
    call ok(Err.Number = E_TESTERROR, "Err.Number = " & Err.Number)

    x = false
    call Err.clear()
    if throwInt(E_TESTERROR) then x = true
    call ok(x, "if branch not taken")
    call ok(Err.Number = E_TESTERROR, "Err.Number = " & Err.Number)

    x = false
    call Err.clear()
    if false then
        call ok(false, "unexpected if else branch on throw")
    elseif throwInt(E_TESTERROR) then
        x = true
    else
        call ok(false, "unexpected if else branch on throw")
    end if
    call ok(x, "elseif branch not taken")
    call ok(Err.Number = E_TESTERROR, "Err.Number = " & Err.Number)

    call Err.clear()
    if true then
        call throwInt(E_TESTERROR)
    else
        call ok(false, "unexpected if else branch on throw")
    end if
    call ok(Err.Number = E_TESTERROR, "Err.Number = " & Err.Number)

    x = false
    call Err.clear()
    do while throwInt(E_TESTERROR)
        call ok(Err.Number = E_TESTERROR, "Err.Number = " & Err.Number)
        x = true
        exit do
    loop
    call ok(x, "if branch not taken")
    call ok(Err.Number = E_TESTERROR, "Err.Number = " & Err.Number)

    x = 0
    call Err.clear()
    do
        x = x+1
        call ok(Err.Number = 0, "Err.Number = " & Err.Number)
    loop while throwInt(E_TESTERROR)
    call ok(x = 1, "if branch not taken")
    call ok(Err.Number = E_TESTERROR, "Err.Number = " & Err.Number)

    x = 0
    call Err.clear()
    do
        x = x+1
        call ok(Err.Number = 0, "Err.Number = " & Err.Number)
    loop until throwInt(E_TESTERROR)
    call ok(x = 1, "if branch not taken")
    call ok(Err.Number = E_TESTERROR, "Err.Number = " & Err.Number)

    call Err.clear()
    x = 0
    while x < 2
        x = x+1
        call throwInt(E_TESTERROR)
    wend
    call ok(x = 2, "x = " & x)
    call ok(Err.Number = E_TESTERROR, "Err.Number = " & Err.Number)

    call Err.clear()
    x = 2
    y = 0
    for each x in throwInt(E_TESTERROR)
        call ok(Err.Number = E_TESTERROR, "Err.Number = " & Err.Number)
        y = y+1
    next
    call ok(x = 2, "x = " & x)
    call ok(y = 1, "y = " & y)
    call todo_wine_ok(Err.Number = VB_E_OBJNOTCOLLECTION, "Err.Number = " & Err.Number)

    Err.clear()
    y = 0
    x = 6
    for x = throwInt(E_TESTERROR) to 100
        call ok(Err.Number = E_TESTERROR, "Err.Number = " & Err.Number)
        call ok(x = 6, "x = " & x)
        y = y+1
    next
    call ok(y = 1, "y = " & y)
    call ok(x = 6, "x = " & x)
    call todo_wine_ok(Err.Number = VB_E_FORLOOPNOTINITIALIZED, "Err.Number = " & Err.Number)

    Err.clear()
    y = 0
    x = 6
    for x = 100 to throwInt(E_TESTERROR)
        call ok(Err.Number = E_TESTERROR, "Err.Number = " & Err.Number)
        call todo_wine_ok(x = 6, "x = " & x)
        y = y+1
    next
    call ok(y = 1, "y = " & y)
    call todo_wine_ok(x = 6, "x = " & x)
    call todo_wine_ok(Err.Number = VB_E_FORLOOPNOTINITIALIZED, "Err.Number = " & Err.Number)

    select case throwInt(E_TESTERROR)
    case true
         call ok(false, "unexpected case true")
    case false
         call ok(false, "unexpected case false")
    case empty
         call ok(false, "unexpected case empty")
    case else
         call ok(false, "unexpected case else")
    end select
    call ok(Err.Number = E_TESTERROR, "Err.Number = " & Err.Number)

    x = false
    select case false
    case true
         call ok(false, "unexpected case true")
    case throwInt(E_TESTERROR)
         x = true
    case else
         call ok(false, "unexpected case else")
    end select
    call ok(x, "case not executed")
    call ok(Err.Number = E_TESTERROR, "Err.Number = " & Err.Number)

    'Exception in non-trivial stack context
    for x = 1 to 1
        for each y in collectionObj
            select case 3
            case 1
                call ok(false, "unexpected case")
            case throwInt(E_TESTERROR)
                exit for
            case 2
                call ok(false, "unexpected case")
            end select
        next
    next
end sub

call testThrow

dim x

sub testOnError(resumeNext)
    if resumeNext then
        on error resume next
    else
        on error goto 0
    end if
    x = 1
    throwInt(E_TESTERROR)
    x = 2
    call ok(Err.Number = E_TESTERROR, "Err.Number = " & Err.Number)
end sub

sub callTestOnError(resumeNext)
    on error resume next
    call testOnError(resumeNext)
    call ok(Err.Number = E_TESTERROR, "Err.Number = " & Err.Number)
end sub

x = 0
call callTestOnError(true)
call ok(x = 2, "x = " & x)

x = 0
call callTestOnError(false)
call ok(x = 1, "x = " & x)

sub testOnErrorClear()
    on error resume next
    call ok(Err.Number = 0, "Err.Number = " & Err.Number)
    throwInt(E_TESTERROR)
    call ok(Err.Number = E_TESTERROR, "Err.Number = " & Err.Number)

    on error goto 0
    call ok(Err.Number = 0, "Err.Number = " & Err.Number)
    x = "ok"
end sub

call testOnErrorClear()
call ok(x = "ok", "testOnErrorClear failed")

sub testForEachError()
    on error resume next

    dim x, y
    y = false
    for each x in empty
        y = true
    next
    call ok(y, "for each not executed")
    call todo_wine_ok(Err.Number = VB_E_OBJNOTCOLLECTION, "Err.Number = " & Err.Number)
end sub

call testForEachError()

sub testHresMap(hres, code)
    on error resume next

    call Err.Clear()
    call throwInt(hres)
    call ok(Err.Number = code, "throw(" & hex(hres) & ") Err.Number = " & Err.Number)
end sub

testHresMap E_NOTIMPL, 445
testHresMap E_NOINTERFACE, 430
testHresMap DISP_E_UNKNOWNINTERFACE, 438
testHresMap DISP_E_MEMBERNOTFOUND, 438
testHresMap DISP_E_PARAMNOTFOUND, 448
testHresMap DISP_E_TYPEMISMATCH, 13
testHresMap DISP_E_UNKNOWNNAME, 438
testHresMap DISP_E_NONAMEDARGS, 446
testHresMap DISP_E_BADVARTYPE, 458
testHresMap DISP_E_OVERFLOW, 6
testHresMap DISP_E_BADINDEX, 9
testHresMap DISP_E_UNKNOWNLCID, 447
testHresMap DISP_E_ARRAYISLOCKED, 10
testHresMap DISP_E_BADPARAMCOUNT, 450
testHresMap DISP_E_PARAMNOTOPTIONAL, 449
testHresMap DISP_E_NOTACOLLECTION, 451
testHresMap TYPE_E_DLLFUNCTIONNOTFOUND, 453
testHresMap TYPE_E_TYPEMISMATCH, 13
testHresMap TYPE_E_OUTOFBOUNDS, 9
testHresMap TYPE_E_IOERROR, 57
testHresMap TYPE_E_CANTCREATETMPFILE, 322
testHresMap STG_E_FILENOTFOUND, 432
testHresMap STG_E_PATHNOTFOUND, 76
testHresMap STG_E_TOOMANYOPENFILES, 67
testHresMap STG_E_ACCESSDENIED, 70
testHresMap STG_E_INSUFFICIENTMEMORY, 7
testHresMap STG_E_NOMOREFILES, 67
testHresMap STG_E_DISKISWRITEPROTECTED, 70
testHresMap STG_E_WRITEFAULT, 57
testHresMap STG_E_READFAULT, 57
testHresMap STG_E_SHAREVIOLATION, 75
testHresMap STG_E_LOCKVIOLATION, 70
testHresMap STG_E_FILEALREADYEXISTS, 58
testHresMap STG_E_MEDIUMFULL, 61
testHresMap STG_E_INVALIDNAME, 53
testHresMap STG_E_INUSE, 70
testHresMap STG_E_NOTCURRENT, 70
testHresMap STG_E_CANTSAVE, 57
testHresMap REGDB_E_CLASSNOTREG, 429
testHresMap MK_E_UNAVAILABLE, 429
testHresMap MK_E_INVALIDEXTENSION, 432
testHresMap MK_E_CANTOPENFILE, 432
testHresMap CO_E_CLASSSTRING, 429
testHresMap CO_E_APPNOTFOUND, 429
testHresMap O_E_APPDIDNTREG, 429
testHresMap E_ACCESSDENIED, 70
testHresMap E_OUTOFMEMORY, 7
testHresMap E_INVALIDARG, 5
testHresMap RPC_S_SERVER_UNAVAILABLE, 462
testHresMap CO_E_SERVER_EXEC_FAILURE, 429

sub testVBErrorCodes()
    on error resume next

    Err.clear()
    throwInt(&h800a00aa&)
    call ok(Err.number = 170, "Err.number = " & Err.number)

    Err.clear()
    throwInt(&h800a10aa&)
    call ok(Err.number = 4266, "Err.number = " & Err.number)
end sub

call testVBErrorCodes

call reportSuccess()