include/mscvpdb.h: Use flexible array members for the rest of structures.
[wine.git] / dlls / vbscript / tests / error.vbs
blob9b74dc8773e97011d40474eb64961ef685677b21
2 ' Copyright 2014 Jacek Caban for CodeWeavers
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.
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.
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
19 Option Explicit
21 const E_TESTERROR = &h80080008&
23 const VB_E_FORLOOPNOTINITIALIZED = 92
24 const VB_E_OBJNOTCOLLECTION = 451
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&
77 call ok(Err.Number = 0, "Err.Number = " & Err.Number)
78 call ok(getVT(Err.Number) = "VT_I4", "getVT(Err.Number) = " & getVT(Err.Number))
80 class emptyclass
81 end class
83 class propclass
84 public prop
85 end class
87 dim calledFunc
89 sub returnTrue
90 calledFunc = true
91 returnTrue = true
92 end sub
94 sub testThrow
95 on error resume next
97 dim x, y
99 call throwInt(1000)
100 call ok(Err.Number = 0, "Err.Number = " & Err.Number)
102 call throwInt(E_TESTERROR)
103 call ok(Err.Number = E_TESTERROR, "Err.Number = " & Err.Number)
105 call throwInt(1000)
106 call ok(Err.Number = E_TESTERROR, "Err.Number = " & Err.Number)
108 call Err.clear()
109 call ok(Err.Number = 0, "Err.Number = " & Err.Number)
111 x = 6
112 calledFunc = false
113 x = throwInt(E_TESTERROR) and returnTrue()
114 call ok(x = 6, "x = " & x)
115 call ok(not calledFunc, "calledFunc = " & calledFunc)
116 call ok(Err.Number = E_TESTERROR, "Err.Number = " & Err.Number)
118 x = false
119 call Err.clear()
120 if false and throwInt(E_TESTERROR) then
121 x = true
122 else
123 call ok(false, "unexpected if else branch on throw")
124 end if
125 call ok(x, "if branch not taken")
126 call ok(Err.Number = E_TESTERROR, "Err.Number = " & Err.Number)
128 x = false
129 call Err.clear()
130 if throwInt(E_TESTERROR) then x = true
131 call ok(x, "if branch not taken")
132 call ok(Err.Number = E_TESTERROR, "Err.Number = " & Err.Number)
134 x = false
135 call Err.clear()
136 if false then
137 call ok(false, "unexpected if else branch on throw")
138 elseif throwInt(E_TESTERROR) then
139 x = true
140 else
141 call ok(false, "unexpected if else branch on throw")
142 end if
143 call ok(x, "elseif branch not taken")
144 call ok(Err.Number = E_TESTERROR, "Err.Number = " & Err.Number)
146 call Err.clear()
147 if true then
148 call throwInt(E_TESTERROR)
149 else
150 call ok(false, "unexpected if else branch on throw")
151 end if
152 call ok(Err.Number = E_TESTERROR, "Err.Number = " & Err.Number)
154 x = false
155 call Err.clear()
156 do while throwInt(E_TESTERROR)
157 call ok(Err.Number = E_TESTERROR, "Err.Number = " & Err.Number)
158 x = true
159 exit do
160 loop
161 call ok(x, "if branch not taken")
162 call ok(Err.Number = E_TESTERROR, "Err.Number = " & Err.Number)
164 x = 0
165 call Err.clear()
167 x = x+1
168 call ok(Err.Number = 0, "Err.Number = " & Err.Number)
169 loop while throwInt(E_TESTERROR)
170 call ok(x = 1, "if branch not taken")
171 call ok(Err.Number = E_TESTERROR, "Err.Number = " & Err.Number)
173 x = 0
174 call Err.clear()
176 x = x+1
177 call ok(Err.Number = 0, "Err.Number = " & Err.Number)
178 loop until throwInt(E_TESTERROR)
179 call ok(x = 1, "if branch not taken")
180 call ok(Err.Number = E_TESTERROR, "Err.Number = " & Err.Number)
182 call Err.clear()
183 x = 0
184 while x < 2
185 x = x+1
186 call throwInt(E_TESTERROR)
187 wend
188 call ok(x = 2, "x = " & x)
189 call ok(Err.Number = E_TESTERROR, "Err.Number = " & Err.Number)
191 call Err.clear()
192 x = 2
193 y = 0
194 for each x in throwInt(E_TESTERROR)
195 call ok(Err.Number = E_TESTERROR, "Err.Number = " & Err.Number)
196 y = y+1
197 next
198 call ok(x = 2, "x = " & x)
199 call ok(y = 1, "y = " & y)
200 call todo_wine_ok(Err.Number = VB_E_OBJNOTCOLLECTION, "Err.Number = " & Err.Number)
202 Err.clear()
203 y = 0
204 x = 6
205 for x = throwInt(E_TESTERROR) to 100
206 call ok(Err.Number = E_TESTERROR, "Err.Number = " & Err.Number)
207 call ok(x = 6, "x = " & x)
208 y = y+1
209 next
210 call ok(y = 1, "y = " & y)
211 call ok(x = 6, "x = " & x)
212 call todo_wine_ok(Err.Number = VB_E_FORLOOPNOTINITIALIZED, "Err.Number = " & Err.Number)
214 Err.clear()
215 y = 0
216 x = 6
217 for x = 100 to throwInt(E_TESTERROR)
218 call ok(Err.Number = E_TESTERROR, "Err.Number = " & Err.Number)
219 call todo_wine_ok(x = 6, "x = " & x)
220 y = y+1
221 next
222 call ok(y = 1, "y = " & y)
223 call todo_wine_ok(x = 6, "x = " & x)
224 call todo_wine_ok(Err.Number = VB_E_FORLOOPNOTINITIALIZED, "Err.Number = " & Err.Number)
226 select case throwInt(E_TESTERROR)
227 case true
228 call ok(false, "unexpected case true")
229 case false
230 call ok(false, "unexpected case false")
231 case empty
232 call ok(false, "unexpected case empty")
233 case else
234 call ok(false, "unexpected case else")
235 end select
236 call ok(Err.Number = E_TESTERROR, "Err.Number = " & Err.Number)
238 x = false
239 select case false
240 case true
241 call ok(false, "unexpected case true")
242 case throwInt(E_TESTERROR)
243 x = true
244 case else
245 call ok(false, "unexpected case else")
246 end select
247 call ok(x, "case not executed")
248 call ok(Err.Number = E_TESTERROR, "Err.Number = " & Err.Number)
250 'Exception in non-trivial stack context
251 for x = 1 to 1
252 for each y in collectionObj
253 select case 3
254 case 1
255 call ok(false, "unexpected case")
256 case throwInt(E_TESTERROR)
257 exit for
258 case 2
259 call ok(false, "unexpected case")
260 end select
261 next
262 next
263 end sub
265 call testThrow
267 dim x
269 sub testOnError(resumeNext)
270 if resumeNext then
271 on error resume next
272 else
273 on error goto 0
274 end if
275 x = 1
276 throwInt(E_TESTERROR)
277 x = 2
278 call ok(Err.Number = E_TESTERROR, "Err.Number = " & Err.Number)
279 end sub
281 sub callTestOnError(resumeNext)
282 on error resume next
283 call testOnError(resumeNext)
284 call ok(Err.Number = E_TESTERROR, "Err.Number = " & Err.Number)
285 end sub
287 x = 0
288 call callTestOnError(true)
289 call ok(x = 2, "x = " & x)
291 x = 0
292 call callTestOnError(false)
293 call ok(x = 1, "x = " & x)
295 sub testOnErrorClear()
296 on error resume next
297 call ok(Err.Number = 0, "Err.Number = " & Err.Number)
298 throwInt(E_TESTERROR)
299 call ok(Err.Number = E_TESTERROR, "Err.Number = " & Err.Number)
301 on error goto 0
302 call ok(Err.Number = 0, "Err.Number = " & Err.Number)
303 x = "ok"
304 end sub
306 call testOnErrorClear()
307 call ok(x = "ok", "testOnErrorClear failed")
309 sub testForEachError()
310 on error resume next
312 dim x, y, z
313 y = false
314 z = false
315 for each x in empty
316 y = true
317 next
318 z = true
319 call ok(y, "for each not executed")
320 call ok(z, "line after next not executed")
321 call todo_wine_ok(Err.Number = VB_E_OBJNOTCOLLECTION, "Err.Number = " & Err.Number)
322 end sub
324 call testForEachError()
326 sub testWithError()
327 on error resume next
328 dim x
330 err.clear
331 x = false
332 with throwInt(E_TESTERROR)
333 ok Err.Number = E_TESTERROR, "Err.Number = " & Err.Number
334 x = true
335 end with
336 ok x, "with statement body not executed"
338 err.clear
339 x = false
340 with throwInt(E_TESTERROR)
341 x = true
342 .prop = 1
343 todo_wine_ok Err.Number = 424, "Err.Number = " & Err.Number
344 end with
345 ok x, "with statement body not executed"
347 err.clear
348 x = false
349 with empty
350 .prop = 1
351 todo_wine_ok Err.Number = 424, "Err.Number = " & Err.Number
352 x = true
353 end with
354 ok x, "with statement body not executed"
355 end sub
357 sub testWithError2()
358 on error resume next
359 dim x
361 err.clear
362 x = false
363 with new emptyclass
364 .prop = 1
365 ok Err.Number = 438, "Err.Number = " & Err.Number
366 x = true
367 end with
368 ok x, "with statement body not executed"
370 'dot expression can reference only inner-most with statement
371 err.clear
372 x = false
373 with new propclass
374 with new emptyclass
375 .prop = 1
376 ok Err.Number = 438, "Err.Number = " & Err.Number
377 x = true
378 end with
379 end with
380 ok x, "with statement body not executed"
382 err.clear
383 .prop
384 ok Err.Number = 505, "Err.Number = " & Err.Number & " description """ & err.description & """"
385 end sub
387 call testWithError()
388 call testWithError2()
390 sub testHresMap(hres, code)
391 on error resume next
393 call Err.Clear()
394 call throwInt(hres)
395 call ok(Err.Number = code, "throw(" & hex(hres) & ") Err.Number = " & Err.Number)
396 end sub
398 testHresMap E_NOTIMPL, 445
399 testHresMap E_NOINTERFACE, 430
400 testHresMap DISP_E_UNKNOWNINTERFACE, 438
401 testHresMap DISP_E_MEMBERNOTFOUND, 438
402 testHresMap DISP_E_PARAMNOTFOUND, 448
403 testHresMap DISP_E_TYPEMISMATCH, 13
404 testHresMap DISP_E_UNKNOWNNAME, 438
405 testHresMap DISP_E_NONAMEDARGS, 446
406 testHresMap DISP_E_BADVARTYPE, 458
407 testHresMap DISP_E_OVERFLOW, 6
408 testHresMap DISP_E_BADINDEX, 9
409 testHresMap DISP_E_UNKNOWNLCID, 447
410 testHresMap DISP_E_ARRAYISLOCKED, 10
411 testHresMap DISP_E_BADPARAMCOUNT, 450
412 testHresMap DISP_E_PARAMNOTOPTIONAL, 449
413 testHresMap DISP_E_NOTACOLLECTION, 451
414 testHresMap TYPE_E_DLLFUNCTIONNOTFOUND, 453
415 testHresMap TYPE_E_TYPEMISMATCH, 13
416 testHresMap TYPE_E_OUTOFBOUNDS, 9
417 testHresMap TYPE_E_IOERROR, 57
418 testHresMap TYPE_E_CANTCREATETMPFILE, 322
419 testHresMap STG_E_FILENOTFOUND, 432
420 testHresMap STG_E_PATHNOTFOUND, 76
421 testHresMap STG_E_TOOMANYOPENFILES, 67
422 testHresMap STG_E_ACCESSDENIED, 70
423 testHresMap STG_E_INSUFFICIENTMEMORY, 7
424 testHresMap STG_E_NOMOREFILES, 67
425 testHresMap STG_E_DISKISWRITEPROTECTED, 70
426 testHresMap STG_E_WRITEFAULT, 57
427 testHresMap STG_E_READFAULT, 57
428 testHresMap STG_E_SHAREVIOLATION, 75
429 testHresMap STG_E_LOCKVIOLATION, 70
430 testHresMap STG_E_FILEALREADYEXISTS, 58
431 testHresMap STG_E_MEDIUMFULL, 61
432 testHresMap STG_E_INVALIDNAME, 53
433 testHresMap STG_E_INUSE, 70
434 testHresMap STG_E_NOTCURRENT, 70
435 testHresMap STG_E_CANTSAVE, 57
436 testHresMap REGDB_E_CLASSNOTREG, 429
437 testHresMap MK_E_UNAVAILABLE, 429
438 testHresMap MK_E_INVALIDEXTENSION, 432
439 testHresMap MK_E_CANTOPENFILE, 432
440 testHresMap CO_E_CLASSSTRING, 429
441 testHresMap CO_E_APPNOTFOUND, 429
442 testHresMap O_E_APPDIDNTREG, 429
443 testHresMap E_ACCESSDENIED, 70
444 testHresMap E_OUTOFMEMORY, 7
445 testHresMap E_INVALIDARG, 5
446 testHresMap RPC_S_SERVER_UNAVAILABLE, 462
447 testHresMap CO_E_SERVER_EXEC_FAILURE, 429
449 sub testVBErrorCodes()
450 on error resume next
452 Err.clear()
453 throwInt(&h800a00aa&)
454 call ok(Err.number = 170, "Err.number = " & Err.number)
456 Err.clear()
457 throwInt(&h800a10aa&)
458 call ok(Err.number = 4266, "Err.number = " & Err.number)
459 end sub
461 call testVBErrorCodes
463 on error resume next
465 throwWithDesc
466 ok err.number = &hdeadbeef&, "err.number = " & hex(err.number)
467 ok err.description = "test", "err.description = " & err.description
468 ok err.helpcontext = 10, "err.helpcontext = " & err.helpcontext
469 ok err.helpfile = "test.chm", "err.helpfile = " & err.helpfile
471 throwWithDesc = 1
472 ok err.number = &hdeadbeef&, "err.number = " & hex(err.number)
473 ok err.description = "test", "err.description = " & err.description
474 ok err.helpcontext = 10, "err.helpcontext = " & err.helpcontext
475 ok err.helpfile = "test.chm", "err.helpfile = " & err.helpfile
477 on error goto 0
479 call reportSuccess()