Merge the following revisions from kernel-fun branch:
[reactos.git] / rostests / winetests / vbscript / error.vbs
1 '
2 ' Copyright 2014 Jacek Caban for CodeWeavers
3 '
4 ' This library is free software; you can redistribute it and/or
5 ' modify it under the terms of the GNU Lesser General Public
6 ' License as published by the Free Software Foundation; either
7 ' version 2.1 of the License, or (at your option) any later version.
8 '
9 ' This library is distributed in the hope that it will be useful,
10 ' but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 ' Lesser General Public License for more details.
13 '
14 ' You should have received a copy of the GNU Lesser General Public
15 ' License along with this library; if not, write to the Free Software
16 ' Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17 '
18
19 Option Explicit
20
21 const E_TESTERROR = &h80080008&
22
23 const VB_E_FORLOOPNOTINITIALIZED = 92
24 const VB_E_OBJNOTCOLLECTION = 451
25
26 const E_NOTIMPL = &h80004001&
27 const E_NOINTERFACE = &h80004002&
28 const DISP_E_UNKNOWNINTERFACE = &h80020001&
29 const DISP_E_MEMBERNOTFOUND = &h80020003&
30 const DISP_E_PARAMNOTFOUND = &h80020004&
31 const DISP_E_TYPEMISMATCH = &h80020005&
32 const DISP_E_UNKNOWNNAME = &h80020006&
33 const DISP_E_NONAMEDARGS = &h80020007&
34 const DISP_E_BADVARTYPE = &h80020008&
35 const DISP_E_OVERFLOW = &h8002000A&
36 const DISP_E_BADINDEX = &h8002000B&
37 const DISP_E_UNKNOWNLCID = &h8002000C&
38 const DISP_E_ARRAYISLOCKED = &h8002000D&
39 const DISP_E_BADPARAMCOUNT = &h8002000E&
40 const DISP_E_PARAMNOTOPTIONAL = &h8002000F&
41 const DISP_E_NOTACOLLECTION = &h80020011&
42 const TYPE_E_DLLFUNCTIONNOTFOUND = &h8002802F&
43 const TYPE_E_TYPEMISMATCH = &h80028CA0&
44 const TYPE_E_OUTOFBOUNDS = &h80028CA1&
45 const TYPE_E_IOERROR = &h80028CA2&
46 const TYPE_E_CANTCREATETMPFILE = &h80028CA3&
47 const STG_E_FILENOTFOUND = &h80030002&
48 const STG_E_PATHNOTFOUND = &h80030003&
49 const STG_E_TOOMANYOPENFILES = &h80030004&
50 const STG_E_ACCESSDENIED = &h80030005&
51 const STG_E_INSUFFICIENTMEMORY = &h80030008&
52 const STG_E_NOMOREFILES = &h80030012&
53 const STG_E_DISKISWRITEPROTECTED = &h80030013&
54 const STG_E_WRITEFAULT = &h8003001D&
55 const STG_E_READFAULT = &h8003001E&
56 const STG_E_SHAREVIOLATION = &h80030020&
57 const STG_E_LOCKVIOLATION = &h80030021&
58 const STG_E_FILEALREADYEXISTS = &h80030050&
59 const STG_E_MEDIUMFULL = &h80030070&
60 const STG_E_INVALIDNAME = &h800300FC&
61 const STG_E_INUSE = &h80030100&
62 const STG_E_NOTCURRENT = &h80030101&
63 const STG_E_CANTSAVE = &h80030103&
64 const REGDB_E_CLASSNOTREG = &h80040154&
65 const MK_E_UNAVAILABLE = &h800401E3&
66 const MK_E_INVALIDEXTENSION = &h800401E6&
67 const MK_E_CANTOPENFILE = &h800401EA&
68 const CO_E_CLASSSTRING = &h800401F3&
69 const CO_E_APPNOTFOUND = &h800401F5&
70 const O_E_APPDIDNTREG = &h800401FE&
71 const E_ACCESSDENIED = &h80070005&
72 const E_OUTOFMEMORY = &h8007000E&
73 const E_INVALIDARG = &h80070057&
74 const RPC_S_SERVER_UNAVAILABLE = &h800706BA&
75 const CO_E_SERVER_EXEC_FAILURE = &h80080005&
76
77 call ok(Err.Number = 0, "Err.Number = " & Err.Number)
78
79 dim calledFunc
80
81 sub returnTrue
82 calledFunc = true
83 returnTrue = true
84 end sub
85
86 sub testThrow
87 on error resume next
88
89 dim x, y
90
91 call throwInt(1000)
92 call ok(Err.Number = 0, "Err.Number = " & Err.Number)
93
94 call throwInt(E_TESTERROR)
95 call ok(Err.Number = E_TESTERROR, "Err.Number = " & Err.Number)
96
97 call throwInt(1000)
98 call ok(Err.Number = E_TESTERROR, "Err.Number = " & Err.Number)
99
100 call Err.clear()
101 call ok(Err.Number = 0, "Err.Number = " & Err.Number)
102
103 x = 6
104 calledFunc = false
105 x = throwInt(E_TESTERROR) and returnTrue()
106 call ok(x = 6, "x = " & x)
107 call ok(not calledFunc, "calledFunc = " & calledFunc)
108 call ok(Err.Number = E_TESTERROR, "Err.Number = " & Err.Number)
109
110 x = false
111 call Err.clear()
112 if false and throwInt(E_TESTERROR) then
113 x = true
114 else
115 call ok(false, "unexpected if else branch on throw")
116 end if
117 call ok(x, "if branch not taken")
118 call ok(Err.Number = E_TESTERROR, "Err.Number = " & Err.Number)
119
120 x = false
121 call Err.clear()
122 if throwInt(E_TESTERROR) then x = true
123 call ok(x, "if branch not taken")
124 call ok(Err.Number = E_TESTERROR, "Err.Number = " & Err.Number)
125
126 x = false
127 call Err.clear()
128 if false then
129 call ok(false, "unexpected if else branch on throw")
130 elseif throwInt(E_TESTERROR) then
131 x = true
132 else
133 call ok(false, "unexpected if else branch on throw")
134 end if
135 call ok(x, "elseif branch not taken")
136 call ok(Err.Number = E_TESTERROR, "Err.Number = " & Err.Number)
137
138 call Err.clear()
139 if true then
140 call throwInt(E_TESTERROR)
141 else
142 call ok(false, "unexpected if else branch on throw")
143 end if
144 call ok(Err.Number = E_TESTERROR, "Err.Number = " & Err.Number)
145
146 x = false
147 call Err.clear()
148 do while throwInt(E_TESTERROR)
149 call ok(Err.Number = E_TESTERROR, "Err.Number = " & Err.Number)
150 x = true
151 exit do
152 loop
153 call ok(x, "if branch not taken")
154 call ok(Err.Number = E_TESTERROR, "Err.Number = " & Err.Number)
155
156 x = 0
157 call Err.clear()
158 do
159 x = x+1
160 call ok(Err.Number = 0, "Err.Number = " & Err.Number)
161 loop while throwInt(E_TESTERROR)
162 call ok(x = 1, "if branch not taken")
163 call ok(Err.Number = E_TESTERROR, "Err.Number = " & Err.Number)
164
165 x = 0
166 call Err.clear()
167 do
168 x = x+1
169 call ok(Err.Number = 0, "Err.Number = " & Err.Number)
170 loop until throwInt(E_TESTERROR)
171 call ok(x = 1, "if branch not taken")
172 call ok(Err.Number = E_TESTERROR, "Err.Number = " & Err.Number)
173
174 call Err.clear()
175 x = 0
176 while x < 2
177 x = x+1
178 call throwInt(E_TESTERROR)
179 wend
180 call ok(x = 2, "x = " & x)
181 call ok(Err.Number = E_TESTERROR, "Err.Number = " & Err.Number)
182
183 call Err.clear()
184 x = 2
185 y = 0
186 for each x in throwInt(E_TESTERROR)
187 call ok(Err.Number = E_TESTERROR, "Err.Number = " & Err.Number)
188 y = y+1
189 next
190 call ok(x = 2, "x = " & x)
191 call ok(y = 1, "y = " & y)
192 'todo_wine call ok(Err.Number = VB_E_OBJNOTCOLLECTION, "Err.Number = " & Err.Number)
193
194 Err.clear()
195 y = 0
196 x = 6
197 for x = throwInt(E_TESTERROR) to 100
198 call ok(Err.Number = E_TESTERROR, "Err.Number = " & Err.Number)
199 call ok(x = 6, "x = " & x)
200 y = y+1
201 next
202 call ok(y = 1, "y = " & y)
203 call ok(x = 6, "x = " & x)
204 'todo_wine call ok(Err.Number = VB_E_FORLOOPNOTINITIALIZED, "Err.Number = " & Err.Number)
205
206 Err.clear()
207 y = 0
208 x = 6
209 for x = 100 to throwInt(E_TESTERROR)
210 call ok(Err.Number = E_TESTERROR, "Err.Number = " & Err.Number)
211 'todo_wine call ok(x = 6, "x = " & x)
212 y = y+1
213 next
214 call ok(y = 1, "y = " & y)
215 'todo_wine call ok(x = 6, "x = " & x)
216 'todo_wine call ok(Err.Number = VB_E_FORLOOPNOTINITIALIZED, "Err.Number = " & Err.Number)
217
218 select case throwInt(E_TESTERROR)
219 case true
220 call ok(false, "unexpected case true")
221 case false
222 call ok(false, "unexpected case false")
223 case empty
224 call ok(false, "unexpected case empty")
225 case else
226 call ok(false, "unexpected case else")
227 end select
228 call ok(Err.Number = E_TESTERROR, "Err.Number = " & Err.Number)
229
230 x = false
231 select case false
232 case true
233 call ok(false, "unexpected case true")
234 case throwInt(E_TESTERROR)
235 x = true
236 case else
237 call ok(false, "unexpected case else")
238 end select
239 call ok(x, "case not executed")
240 call ok(Err.Number = E_TESTERROR, "Err.Number = " & Err.Number)
241
242 'Exception in non-trivial stack context
243 for x = 1 to 1
244 for each y in collectionObj
245 select case 3
246 case 1
247 call ok(false, "unexpected case")
248 case throwInt(E_TESTERROR)
249 exit for
250 case 2
251 call ok(false, "unexpected case")
252 end select
253 next
254 next
255 end sub
256
257 call testThrow
258
259 dim x
260
261 sub testOnError(resumeNext)
262 if resumeNext then
263 on error resume next
264 else
265 on error goto 0
266 end if
267 x = 1
268 throwInt(E_TESTERROR)
269 x = 2
270 call ok(Err.Number = E_TESTERROR, "Err.Number = " & Err.Number)
271 end sub
272
273 sub callTestOnError(resumeNext)
274 on error resume next
275 call testOnError(resumeNext)
276 call ok(Err.Number = E_TESTERROR, "Err.Number = " & Err.Number)
277 end sub
278
279 x = 0
280 call callTestOnError(true)
281 call ok(x = 2, "x = " & x)
282
283 x = 0
284 call callTestOnError(false)
285 call ok(x = 1, "x = " & x)
286
287 sub testOnErrorClear()
288 on error resume next
289 call ok(Err.Number = 0, "Err.Number = " & Err.Number)
290 throwInt(E_TESTERROR)
291 call ok(Err.Number = E_TESTERROR, "Err.Number = " & Err.Number)
292
293 on error goto 0
294 call ok(Err.Number = 0, "Err.Number = " & Err.Number)
295 x = "ok"
296 end sub
297
298 call testOnErrorClear()
299 call ok(x = "ok", "testOnErrorClear failed")
300
301 sub testForEachError()
302 on error resume next
303
304 dim x, y
305 y = false
306 for each x in empty
307 y = true
308 next
309 call ok(y, "for each not executed")
310 'todo_wine call ok(Err.Number = VB_E_OBJNOTCOLLECTION, "Err.Number = " & Err.Number)
311 end sub
312
313 call testForEachError()
314
315 sub testHresMap(hres, code)
316 on error resume next
317
318 call Err.Clear()
319 call throwInt(hres)
320 call ok(Err.Number = code, "throw(" & hex(hres) & ") Err.Number = " & Err.Number)
321 end sub
322
323 testHresMap E_NOTIMPL, 445
324 testHresMap E_NOINTERFACE, 430
325 testHresMap DISP_E_UNKNOWNINTERFACE, 438
326 testHresMap DISP_E_MEMBERNOTFOUND, 438
327 testHresMap DISP_E_PARAMNOTFOUND, 448
328 testHresMap DISP_E_TYPEMISMATCH, 13
329 testHresMap DISP_E_UNKNOWNNAME, 438
330 testHresMap DISP_E_NONAMEDARGS, 446
331 testHresMap DISP_E_BADVARTYPE, 458
332 testHresMap DISP_E_OVERFLOW, 6
333 testHresMap DISP_E_BADINDEX, 9
334 testHresMap DISP_E_UNKNOWNLCID, 447
335 testHresMap DISP_E_ARRAYISLOCKED, 10
336 testHresMap DISP_E_BADPARAMCOUNT, 450
337 testHresMap DISP_E_PARAMNOTOPTIONAL, 449
338 testHresMap DISP_E_NOTACOLLECTION, 451
339 testHresMap TYPE_E_DLLFUNCTIONNOTFOUND, 453
340 testHresMap TYPE_E_TYPEMISMATCH, 13
341 testHresMap TYPE_E_OUTOFBOUNDS, 9
342 testHresMap TYPE_E_IOERROR, 57
343 testHresMap TYPE_E_CANTCREATETMPFILE, 322
344 testHresMap STG_E_FILENOTFOUND, 432
345 testHresMap STG_E_PATHNOTFOUND, 76
346 testHresMap STG_E_TOOMANYOPENFILES, 67
347 testHresMap STG_E_ACCESSDENIED, 70
348 testHresMap STG_E_INSUFFICIENTMEMORY, 7
349 testHresMap STG_E_NOMOREFILES, 67
350 testHresMap STG_E_DISKISWRITEPROTECTED, 70
351 testHresMap STG_E_WRITEFAULT, 57
352 testHresMap STG_E_READFAULT, 57
353 testHresMap STG_E_SHAREVIOLATION, 75
354 testHresMap STG_E_LOCKVIOLATION, 70
355 testHresMap STG_E_FILEALREADYEXISTS, 58
356 testHresMap STG_E_MEDIUMFULL, 61
357 testHresMap STG_E_INVALIDNAME, 53
358 testHresMap STG_E_INUSE, 70
359 testHresMap STG_E_NOTCURRENT, 70
360 testHresMap STG_E_CANTSAVE, 57
361 testHresMap REGDB_E_CLASSNOTREG, 429
362 testHresMap MK_E_UNAVAILABLE, 429
363 testHresMap MK_E_INVALIDEXTENSION, 432
364 testHresMap MK_E_CANTOPENFILE, 432
365 testHresMap CO_E_CLASSSTRING, 429
366 testHresMap CO_E_APPNOTFOUND, 429
367 testHresMap O_E_APPDIDNTREG, 429
368 testHresMap E_ACCESSDENIED, 70
369 testHresMap E_OUTOFMEMORY, 7
370 testHresMap E_INVALIDARG, 5
371 testHresMap RPC_S_SERVER_UNAVAILABLE, 462
372 testHresMap CO_E_SERVER_EXEC_FAILURE, 429
373
374 sub testVBErrorCodes()
375 on error resume next
376
377 Err.clear()
378 throwInt(&h800a00aa&)
379 call ok(Err.number = 170, "Err.number = " & Err.number)
380
381 Err.clear()
382 throwInt(&h800a10aa&)
383 call ok(Err.number = 4266, "Err.number = " & Err.number)
384 end sub
385
386 call testVBErrorCodes
387
388 call reportSuccess()