[BRANCHES]
[reactos.git] / rostests / winetests / vbscript / lang.vbs
1 '
2 ' Copyright 2011 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 dim x, y, z
22 Dim obj
23
24 call ok(true, "true is not true?")
25 ok true, "true is not true?"
26 call ok((true), "true is not true?")
27
28 ok not false, "not false but not true?"
29 ok not not true, "not not true but not true?"
30
31 Call ok(true = true, "true = true is false")
32 Call ok(false = false, "false = false is false")
33 Call ok(not (true = false), "true = false is true")
34 Call ok("x" = "x", """x"" = ""x"" is false")
35 Call ok(empty = empty, "empty = empty is false")
36 Call ok(empty = "", "empty = """" is false")
37 Call ok(0 = 0.0, "0 <> 0.0")
38 Call ok(16 = &h10&, "16 <> &h10&")
39 Call ok(010 = 10, "010 <> 10")
40 Call ok(10. = 10, "10. <> 10")
41 Call ok(&hffFFffFF& = -1, "&hffFFffFF& <> -1")
42 Call ok(&hffFFffFF& = -1, "&hffFFffFF& <> -1")
43 Call ok(--1 = 1, "--1 = " & --1)
44 Call ok(-empty = 0, "-empty = " & (-empty))
45 Call ok(true = -1, "! true = -1")
46 Call ok(false = 0, "false <> 0")
47 Call ok(&hff = 255, "&hff <> 255")
48 Call ok(&Hff = 255, "&Hff <> 255")
49
50 x = "xx"
51 Call ok(x = "xx", "x = " & x & " expected ""xx""")
52
53 Call ok(true <> false, "true <> false is false")
54 Call ok(not (true <> true), "true <> true is true")
55 Call ok(not ("x" <> "x"), """x"" <> ""x"" is true")
56 Call ok(not (empty <> empty), "empty <> empty is true")
57 Call ok(x <> "x", "x = ""x""")
58 Call ok("true" <> true, """true"" = true is true")
59
60 Call ok("" = true = false, """"" = true = false is false")
61 Call ok(not(false = true = ""), "false = true = """" is true")
62 Call ok(not (false = false <> false = false), "false = false <> false = false is true")
63 Call ok(not ("" <> false = false), """"" <> false = false is true")
64
65 Call ok(getVT(false) = "VT_BOOL", "getVT(false) is not VT_BOOL")
66 Call ok(getVT(true) = "VT_BOOL", "getVT(true) is not VT_BOOL")
67 Call ok(getVT("") = "VT_BSTR", "getVT("""") is not VT_BSTR")
68 Call ok(getVT("test") = "VT_BSTR", "getVT(""test"") is not VT_BSTR")
69 Call ok(getVT(Empty) = "VT_EMPTY", "getVT(Empty) is not VT_EMPTY")
70 Call ok(getVT(null) = "VT_NULL", "getVT(null) is not VT_NULL")
71 Call ok(getVT(0) = "VT_I2", "getVT(0) is not VT_I2")
72 Call ok(getVT(1) = "VT_I2", "getVT(1) is not VT_I2")
73 Call ok(getVT(0.5) = "VT_R8", "getVT(0.5) is not VT_R8")
74 Call ok(getVT(0.0) = "VT_R8", "getVT(0.0) is not VT_R8")
75 Call ok(getVT(2147483647) = "VT_I4", "getVT(2147483647) is not VT_I4")
76 Call ok(getVT(2147483648) = "VT_R8", "getVT(2147483648) is not VT_R8")
77 Call ok(getVT(&h10&) = "VT_I2", "getVT(&h10&) is not VT_I2")
78 Call ok(getVT(&h10000&) = "VT_I4", "getVT(&h10000&) is not VT_I4")
79 Call ok(getVT(&H10000&) = "VT_I4", "getVT(&H10000&) is not VT_I4")
80 Call ok(getVT(&hffFFffFF&) = "VT_I2", "getVT(&hffFFffFF&) is not VT_I2")
81 Call ok(getVT(1 & 100000) = "VT_BSTR", "getVT(1 & 100000) is not VT_BSTR")
82 Call ok(getVT(-empty) = "VT_I2", "getVT(-empty) = " & getVT(-empty))
83 Call ok(getVT(-null) = "VT_NULL", "getVT(-null) = " & getVT(-null))
84 Call ok(getVT(y) = "VT_EMPTY*", "getVT(y) = " & getVT(y))
85 Call ok(getVT(nothing) = "VT_DISPATCH", "getVT(nothing) = " & getVT(nothing))
86 set x = nothing
87 Call ok(getVT(x) = "VT_DISPATCH*", "getVT(x=nothing) = " & getVT(x))
88 x = true
89 Call ok(getVT(x) = "VT_BOOL*", "getVT(x) = " & getVT(x))
90 Call ok(getVT(false or true) = "VT_BOOL", "getVT(false) is not VT_BOOL")
91 x = "x"
92 Call ok(getVT(x) = "VT_BSTR*", "getVT(x) is not VT_BSTR*")
93 x = 0.0
94 Call ok(getVT(x) = "VT_R8*", "getVT(x) = " & getVT(x))
95
96 Call ok(isNullDisp(nothing), "nothing is not nulldisp?")
97
98 x = "xx"
99 Call ok("ab" & "cd" = "abcd", """ab"" & ""cd"" <> ""abcd""")
100 Call ok("ab " & null = "ab ", """ab"" & null = " & ("ab " & null))
101 Call ok("ab " & empty = "ab ", """ab"" & empty = " & ("ab " & empty))
102 Call ok(1 & 100000 = "1100000", "1 & 100000 = " & (1 & 100000))
103 Call ok("ab" & x = "abxx", """ab"" & x = " & ("ab"&x))
104
105 if(isEnglishLang) then
106 Call ok("" & true = "True", """"" & true = " & true)
107 Call ok(true & false = "TrueFalse", "true & false = " & (true & false))
108 end if
109
110 call ok(true and true, "true and true is not true")
111 call ok(true and not false, "true and not false is not true")
112 call ok(not (false and true), "not (false and true) is not true")
113 call ok(getVT(null and true) = "VT_NULL", "getVT(null and true) = " & getVT(null and true))
114
115 call ok(false or true, "false or uie is false?")
116 call ok(not (false or false), "false or false is not false?")
117 call ok(false and false or true, "false and false or true is false?")
118 call ok(true or false and false, "true or false and false is false?")
119 call ok(null or true, "null or true is false")
120
121 call ok(true xor false, "true xor false is false?")
122 call ok(not (false xor false), "false xor false is true?")
123 call ok(not (true or false xor true), "true or false xor true is true?")
124 call ok(not (true xor false or true), "true xor false or true is true?")
125
126 call ok(false eqv false, "false does not equal false?")
127 call ok(not (false eqv true), "false equals true?")
128 call ok(getVT(false eqv null) = "VT_NULL", "getVT(false eqv null) = " & getVT(false eqv null))
129
130 call ok(true imp true, "true does not imp true?")
131 call ok(false imp false, "false does not imp false?")
132 call ok(not (true imp false), "true imp false?")
133 call ok(false imp null, "false imp null is false?")
134
135 Call ok(2 >= 1, "! 2 >= 1")
136 Call ok(2 >= 2, "! 2 >= 2")
137 Call ok(not(true >= 2), "true >= 2 ?")
138 Call ok(2 > 1, "! 2 > 1")
139 Call ok(false > true, "! false < true")
140 Call ok(0 > true, "! 0 > true")
141 Call ok(not (true > 0), "true > 0")
142 Call ok(not (0 > 1 = 1), "0 > 1 = 1")
143 Call ok(1 < 2, "! 1 < 2")
144 Call ok(1 = 1 < 0, "! 1 = 1 < 0")
145 Call ok(1 <= 2, "! 1 <= 2")
146 Call ok(2 <= 2, "! 2 <= 2")
147
148 Call ok(isNull(0 = null), "'(0 = null)' is not null")
149 Call ok(isNull(null = 1), "'(null = 1)' is not null")
150 Call ok(isNull(0 > null), "'(0 > null)' is not null")
151 Call ok(isNull(null > 1), "'(null > 1)' is not null")
152 Call ok(isNull(0 < null), "'(0 < null)' is not null")
153 Call ok(isNull(null < 1), "'(null < 1)' is not null")
154 Call ok(isNull(0 <> null), "'(0 <> null)' is not null")
155 Call ok(isNull(null <> 1), "'(null <> 1)' is not null")
156 Call ok(isNull(0 >= null), "'(0 >= null)' is not null")
157 Call ok(isNull(null >= 1), "'(null >= 1)' is not null")
158 Call ok(isNull(0 <= null), "'(0 <= null)' is not null")
159 Call ok(isNull(null <= 1), "'(null <= 1)' is not null")
160
161 x = 3
162 Call ok(2+2 = 4, "2+2 = " & (2+2))
163 Call ok(false + 6 + true = 5, "false + 6 + true <> 5")
164 Call ok(getVT(2+null) = "VT_NULL", "getVT(2+null) = " & getVT(2+null))
165 Call ok(2+empty = 2, "2+empty = " & (2+empty))
166 Call ok(x+x = 6, "x+x = " & (x+x))
167
168 Call ok(5-1 = 4, "5-1 = " & (5-1))
169 Call ok(3+5-true = 9, "3+5-true <> 9")
170 Call ok(getVT(2-null) = "VT_NULL", "getVT(2-null) = " & getVT(2-null))
171 Call ok(2-empty = 2, "2-empty = " & (2-empty))
172 Call ok(2-x = -1, "2-x = " & (2-x))
173
174 Call ok(9 Mod 6 = 3, "9 Mod 6 = " & (9 Mod 6))
175 Call ok(11.6 Mod 5.5 = False, "11.6 Mod 5.5 = " & (11.6 Mod 5.5 = 0.6))
176 Call ok(7 Mod 4+2 = 5, "7 Mod 4+2 <> 5")
177 Call ok(getVT(2 mod null) = "VT_NULL", "getVT(2 mod null) = " & getVT(2 mod null))
178 Call ok(getVT(null mod 2) = "VT_NULL", "getVT(null mod 2) = " & getVT(null mod 2))
179 'FIXME: Call ok(empty mod 2 = 0, "empty mod 2 = " & (empty mod 2))
180
181 Call ok(5 \ 2 = 2, "5 \ 2 = " & (5\2))
182 Call ok(4.6 \ 1.5 = 2, "4.6 \ 1.5 = " & (4.6\1.5))
183 Call ok(4.6 \ 1.49 = 5, "4.6 \ 1.49 = " & (4.6\1.49))
184 Call ok(2+3\4 = 2, "2+3\4 = " & (2+3\4))
185
186 Call ok(2*3 = 6, "2*3 = " & (2*3))
187 Call ok(3/2 = 1.5, "3/2 = " & (3/2))
188 Call ok(5\4/2 = 2, "5\4/2 = " & (5\2/1))
189 Call ok(12/3\2 = 2, "12/3\2 = " & (12/3\2))
190
191 Call ok(2^3 = 8, "2^3 = " & (2^3))
192 Call ok(2^3^2 = 64, "2^3^2 = " & (2^3^2))
193 Call ok(-3^2 = 9, "-3^2 = " & (-3^2))
194 Call ok(2*3^2 = 18, "2*3^2 = " & (2*3^2))
195
196 x =_
197 3
198 x _
199 = 3
200
201 x = 3
202
203 if true then y = true : x = y
204 ok x, "x is false"
205
206 x = true : if false then x = false
207 ok x, "x is false, if false called?"
208
209 if not false then x = true
210 ok x, "x is false, if not false not called?"
211
212 if not false then x = "test" : x = true
213 ok x, "x is false, if not false not called?"
214
215 if false then x = y : call ok(false, "if false .. : called")
216
217 if false then x = y : call ok(false, "if false .. : called") else x = "else"
218 Call ok(x = "else", "else not called?")
219
220 if true then x = y else y = x : Call ok(false, "in else?")
221
222 if false then :
223
224 if false then x = y : if true then call ok(false, "embedded if called")
225
226 if false then x=1 else x=2 end if
227
228 x = false
229 if false then x = true : x = true
230 Call ok(x = false, "x <> false")
231
232 if false then
233 ok false, "if false called"
234 end if
235
236 x = true
237 if x then
238 x = false
239 end if
240 Call ok(not x, "x is false, if not evaluated?")
241
242 x = false
243 If false Then
244 Call ok(false, "inside if false")
245 Else
246 x = true
247 End If
248 Call ok(x, "else not called?")
249
250 x = false
251 If false Then
252 Call ok(false, "inside if false")
253 ElseIf not True Then
254 Call ok(false, "inside elseif not true")
255 Else
256 x = true
257 End If
258 Call ok(x, "else not called?")
259
260 x = false
261 If false Then
262 Call ok(false, "inside if false")
263 x = 1
264 y = 10+x
265 ElseIf not False Then
266 x = true
267 Else
268 Call ok(false, "inside else not true")
269 End If
270 Call ok(x, "elseif not called?")
271
272 x = false
273 If false Then
274 Call ok(false, "inside if false")
275 ElseIf not False Then
276 x = true
277 End If
278 Call ok(x, "elseif not called?")
279
280 x = false
281 if 1 then x = true
282 Call ok(x, "if 1 not run?")
283
284 x = false
285 if &h10000& then x = true
286 Call ok(x, "if &h10000& not run?")
287
288 x = false
289 y = false
290 while not (x and y)
291 if x then
292 y = true
293 end if
294 x = true
295 wend
296 call ok((x and y), "x or y is false after while")
297
298 if false then
299 ' empty body
300 end if
301
302 if false then
303 x = false
304 elseif true then
305 ' empty body
306 end if
307
308 if false then
309 x = false
310 else
311 ' empty body
312 end if
313
314 while false
315 wend
316
317 x = false
318 y = false
319 do while not (x and y)
320 if x then
321 y = true
322 end if
323 x = true
324 loop
325 call ok((x and y), "x or y is false after while")
326
327 do while false
328 loop
329
330 do while true
331 exit do
332 ok false, "exit do didn't work"
333 loop
334
335 x = false
336 y = false
337 do until x and y
338 if x then
339 y = true
340 end if
341 x = true
342 loop
343 call ok((x and y), "x or y is false after do until")
344
345 do until true
346 loop
347
348 do until false
349 exit do
350 ok false, "exit do didn't work"
351 loop
352
353 x = false
354 do
355 if x then exit do
356 x = true
357 loop
358 call ok(x, "x is false after do..loop?")
359
360 x = false
361 y = false
362 do
363 if x then
364 y = true
365 end if
366 x = true
367 loop until x and y
368 call ok((x and y), "x or y is false after while")
369
370 do
371 loop until true
372
373 do
374 exit do
375 ok false, "exit do didn't work"
376 loop until false
377
378 x = false
379 y = false
380 do
381 if x then
382 y = true
383 end if
384 x = true
385 loop while not (x and y)
386 call ok((x and y), "x or y is false after while")
387
388 do
389 loop while false
390
391 do
392 exit do
393 ok false, "exit do didn't work"
394 loop while true
395
396 y = "for1:"
397 for x = 5 to 8
398 y = y & " " & x
399 next
400 Call ok(y = "for1: 5 6 7 8", "y = " & y)
401
402 y = "for2:"
403 for x = 5 to 8 step 2
404 y = y & " " & x
405 next
406 Call ok(y = "for2: 5 7", "y = " & y)
407
408 y = "for3:"
409 x = 2
410 for x = x+3 to 8
411 y = y & " " & x
412 next
413 Call ok(y = "for3: 5 6 7 8", "y = " & y)
414
415 y = "for4:"
416 for x = 5 to 4
417 y = y & " " & x
418 next
419 Call ok(y = "for4:", "y = " & y)
420
421 y = "for5:"
422 for x = 5 to 3 step true
423 y = y & " " & x
424 next
425 Call ok(y = "for5: 5 4 3", "y = " & y)
426
427 y = "for6:"
428 z = 4
429 for x = 5 to z step 3-4
430 y = y & " " & x
431 z = 0
432 next
433 Call ok(y = "for6: 5 4", "y = " & y)
434
435 y = "for7:"
436 z = 1
437 for x = 5 to 8 step z
438 y = y & " " & x
439 z = 2
440 next
441 Call ok(y = "for7: 5 6 7 8", "y = " & y)
442
443 y = "for8:"
444 for x = 5 to 8
445 y = y & " " & x
446 x = x+1
447 next
448 Call ok(y = "for8: 5 7", "y = " & y)
449
450 for x = 1.5 to 1
451 Call ok(false, "for..to called when unexpected")
452 next
453
454 for x = 1 to 100
455 exit for
456 Call ok(false, "exit for not escaped the loop?")
457 next
458
459 do while true
460 for x = 1 to 100
461 exit do
462 next
463 loop
464
465 if null then call ok(false, "if null evaluated")
466
467 while null
468 call ok(false, "while null evaluated")
469 wend
470
471 Call collectionObj.reset()
472 y = 0
473 x = 10
474 for each x in collectionObj
475 y = y+1
476 Call ok(x = y, "x <> y")
477 next
478 Call ok(y = 3, "y = " & y)
479 Call ok(getVT(x) = "VT_EMPTY*", "getVT(x) = " & getVT(x))
480
481 Call collectionObj.reset()
482 y = false
483 for each x in collectionObj
484 if x = 2 then exit for
485 y = 1
486 next
487 Call ok(y = 1, "y = " & y)
488 Call ok(x = 2, "x = " & x)
489
490 Set obj = collectionObj
491 Call obj.reset()
492 y = 0
493 x = 10
494 for each x in obj
495 y = y+1
496 Call ok(x = y, "x <> y")
497 next
498 Call ok(y = 3, "y = " & y)
499 Call ok(getVT(x) = "VT_EMPTY*", "getVT(x) = " & getVT(x))
500
501 x = false
502 select case 3
503 case 2
504 Call ok(false, "unexpected case")
505 case 2
506 Call ok(false, "unexpected case")
507 case 4
508 Call ok(false, "unexpected case")
509 case "test"
510 case "another case"
511 Call ok(false, "unexpected case")
512 case 0, false, 2+1, 10
513 x = true
514 case ok(false, "unexpected case")
515 Call ok(false, "unexpected case")
516 case else
517 Call ok(false, "unexpected case")
518 end select
519 Call ok(x, "wrong case")
520
521 x = false
522 select case 3
523 case 3
524 x = true
525 end select
526 Call ok(x, "wrong case")
527
528 x = false
529 select case 2+2
530 case 3
531 Call ok(false, "unexpected case")
532 case else
533 x = true
534 end select
535 Call ok(x, "wrong case")
536
537 y = "3"
538 x = false
539 select case y
540 case "3"
541 x = true
542 case 3
543 Call ok(false, "unexpected case")
544 end select
545 Call ok(x, "wrong case")
546
547 select case 0
548 case 1
549 Call ok(false, "unexpected case")
550 case "2"
551 Call ok(false, "unexpected case")
552 end select
553
554 select case 0
555 end select
556
557 x = false
558 select case 2
559 case 3,1,2,4: x = true
560 case 5,6,7
561 Call ok(false, "unexpected case")
562 end select
563 Call ok(x, "wrong case")
564
565 x = false
566 select case 2: case 5,6,7: Call ok(false, "unexpected case")
567 case 2,1,2,4
568 x = true
569 case else: Call ok(false, "unexpected case else")
570 end select
571 Call ok(x, "wrong case")
572
573 if false then
574 Sub testsub
575 x = true
576 End Sub
577 end if
578
579 x = false
580 Call testsub
581 Call ok(x, "x is false, testsub not called?")
582
583 Sub SubSetTrue(v)
584 Call ok(not v, "v is not true")
585 v = true
586 End Sub
587
588 x = false
589 SubSetTrue x
590 Call ok(x, "x was not set by SubSetTrue")
591
592 SubSetTrue false
593 Call ok(not false, "false is no longer false?")
594
595 Sub SubSetTrue2(ByRef v)
596 Call ok(not v, "v is not true")
597 v = true
598 End Sub
599
600 x = false
601 SubSetTrue2 x
602 Call ok(x, "x was not set by SubSetTrue")
603
604 Sub TestSubArgVal(ByVal v)
605 Call ok(not v, "v is not false")
606 v = true
607 Call ok(v, "v is not true?")
608 End Sub
609
610 x = false
611 Call TestSubArgVal(x)
612 Call ok(not x, "x is true after TestSubArgVal call?")
613
614 Sub TestSubMultiArgs(a,b,c,d,e)
615 Call ok(a=1, "a = " & a)
616 Call ok(b=2, "b = " & b)
617 Call ok(c=3, "c = " & c)
618 Call ok(d=4, "d = " & d)
619 Call ok(e=5, "e = " & e)
620 End Sub
621
622 Sub TestSubExit(ByRef a)
623 If a Then
624 Exit Sub
625 End If
626 Call ok(false, "Exit Sub not called?")
627 End Sub
628
629 Call TestSubExit(true)
630
631 Sub TestSubExit2
632 for x = 1 to 100
633 Exit Sub
634 next
635 End Sub
636 Call TestSubExit2
637
638 TestSubMultiArgs 1, 2, 3, 4, 5
639 Call TestSubMultiArgs(1, 2, 3, 4, 5)
640
641 Sub TestSubLocalVal
642 x = false
643 Call ok(not x, "local x is not false?")
644 Dim x
645 Dim a,b, c
646 End Sub
647
648 x = true
649 y = true
650 Call TestSubLocalVal
651 Call ok(x, "global x is not true?")
652
653 Public Sub TestPublicSub
654 End Sub
655 Call TestPublicSub
656
657 Private Sub TestPrivateSub
658 End Sub
659 Call TestPrivateSub
660
661 if false then
662 Function testfunc
663 x = true
664 End Function
665 end if
666
667 x = false
668 Call TestFunc
669 Call ok(x, "x is false, testfunc not called?")
670
671 Function FuncSetTrue(v)
672 Call ok(not v, "v is not true")
673 v = true
674 End Function
675
676 x = false
677 FuncSetTrue x
678 Call ok(x, "x was not set by FuncSetTrue")
679
680 FuncSetTrue false
681 Call ok(not false, "false is no longer false?")
682
683 Function FuncSetTrue2(ByRef v)
684 Call ok(not v, "v is not true")
685 v = true
686 End Function
687
688 x = false
689 FuncSetTrue2 x
690 Call ok(x, "x was not set by FuncSetTrue")
691
692 Function TestFuncArgVal(ByVal v)
693 Call ok(not v, "v is not false")
694 v = true
695 Call ok(v, "v is not true?")
696 End Function
697
698 x = false
699 Call TestFuncArgVal(x)
700 Call ok(not x, "x is true after TestFuncArgVal call?")
701
702 Function TestFuncMultiArgs(a,b,c,d,e)
703 Call ok(a=1, "a = " & a)
704 Call ok(b=2, "b = " & b)
705 Call ok(c=3, "c = " & c)
706 Call ok(d=4, "d = " & d)
707 Call ok(e=5, "e = " & e)
708 End Function
709
710 TestFuncMultiArgs 1, 2, 3, 4, 5
711 Call TestFuncMultiArgs(1, 2, 3, 4, 5)
712
713 Function TestFuncLocalVal
714 x = false
715 Call ok(not x, "local x is not false?")
716 Dim x
717 End Function
718
719 x = true
720 y = true
721 Call TestFuncLocalVal
722 Call ok(x, "global x is not true?")
723
724 Function TestFuncExit(ByRef a)
725 If a Then
726 Exit Function
727 End If
728 Call ok(false, "Exit Function not called?")
729 End Function
730
731 Call TestFuncExit(true)
732
733 Function TestFuncExit2(ByRef a)
734 For x = 1 to 100
735 For y = 1 to 100
736 Exit Function
737 Next
738 Next
739 Call ok(false, "Exit Function not called?")
740 End Function
741
742 Call TestFuncExit2(true)
743
744 Sub SubParseTest
745 End Sub : x = false
746 Call SubParseTest
747
748 Function FuncParseTest
749 End Function : x = false
750
751 Function ReturnTrue
752 ReturnTrue = false
753 ReturnTrue = true
754 End Function
755
756 Call ok(ReturnTrue(), "ReturnTrue returned false?")
757
758 Function SetVal(ByRef x, ByVal v)
759 x = v
760 SetVal = x
761 Exit Function
762 End Function
763
764 x = false
765 ok SetVal(x, true), "SetVal returned false?"
766 Call ok(x, "x is not set to true by SetVal?")
767
768 Public Function TestPublicFunc
769 End Function
770 Call TestPublicFunc
771
772 Private Function TestPrivateFunc
773 End Function
774 Call TestPrivateFunc
775
776 ' Stop has an effect only in debugging mode
777 Stop
778
779 set x = testObj
780 Call ok(getVT(x) = "VT_DISPATCH*", "getVT(x=testObj) = " & getVT(x))
781
782 Set obj = New EmptyClass
783 Call ok(getVT(obj) = "VT_DISPATCH*", "getVT(obj) = " & getVT(obj))
784
785 Class EmptyClass
786 End Class
787
788 Set x = obj
789 Call ok(getVT(x) = "VT_DISPATCH*", "getVT(x) = " & getVT(x))
790
791 Class TestClass
792 Public publicProp
793
794 Private privateProp
795
796 Public Function publicFunction()
797 privateSub()
798 publicFunction = 4
799 End Function
800
801 Public Property Get gsProp()
802 gsProp = privateProp
803 funcCalled = "gsProp get"
804 exit property
805 Call ok(false, "exit property not returned?")
806 End Property
807
808 Public Default Property Get DefValGet
809 DefValGet = privateProp
810 funcCalled = "GetDefVal"
811 End Property
812
813 Public Property Let DefValGet(x)
814 End Property
815
816 Public publicProp2
817
818 Public Sub publicSub
819 End Sub
820
821 Public Property Let gsProp(val)
822 privateProp = val
823 funcCalled = "gsProp let"
824 exit property
825 Call ok(false, "exit property not returned?")
826 End Property
827
828 Public Property Set gsProp(val)
829 funcCalled = "gsProp set"
830 exit property
831 Call ok(false, "exit property not returned?")
832 End Property
833
834 Public Sub setPrivateProp(x)
835 privateProp = x
836 End Sub
837
838 Function getPrivateProp
839 getPrivateProp = privateProp
840 End Function
841
842 Private Sub privateSub
843 End Sub
844
845 Public Sub Class_Initialize
846 publicProp2 = 2
847 privateProp = true
848 Call ok(getVT(privateProp) = "VT_BOOL*", "getVT(privateProp) = " & getVT(privateProp))
849 Call ok(getVT(publicProp2) = "VT_I2*", "getVT(publicProp2) = " & getVT(publicProp2))
850 Call ok(getVT(Me.publicProp2) = "VT_I2", "getVT(Me.publicProp2) = " & getVT(Me.publicProp2))
851 End Sub
852 End Class
853
854 Call testDisp(new testClass)
855
856 Set obj = New TestClass
857
858 Call ok(obj.publicFunction = 4, "obj.publicFunction = " & obj.publicFunction)
859 Call ok(obj.publicFunction() = 4, "obj.publicFunction() = " & obj.publicFunction())
860
861 obj.publicSub()
862 Call obj.publicSub
863 Call obj.publicFunction()
864
865 Call ok(getVT(obj.publicProp) = "VT_EMPTY", "getVT(obj.publicProp) = " & getVT(obj.publicProp))
866 obj.publicProp = 3
867 Call ok(getVT(obj.publicProp) = "VT_I2", "getVT(obj.publicProp) = " & getVT(obj.publicProp))
868 Call ok(obj.publicProp = 3, "obj.publicProp = " & obj.publicProp)
869 obj.publicProp() = 3
870
871 Call ok(obj.getPrivateProp() = true, "obj.getPrivateProp() = " & obj.getPrivateProp())
872 Call obj.setPrivateProp(6)
873 Call ok(obj.getPrivateProp = 6, "obj.getPrivateProp = " & obj.getPrivateProp)
874
875 Dim funcCalled
876 funcCalled = ""
877 Call ok(obj.gsProp = 6, "obj.gsProp = " & obj.gsProp)
878 Call ok(funcCalled = "gsProp get", "funcCalled = " & funcCalled)
879 obj.gsProp = 3
880 Call ok(funcCalled = "gsProp let", "funcCalled = " & funcCalled)
881 Call ok(obj.getPrivateProp = 3, "obj.getPrivateProp = " & obj.getPrivateProp)
882 Set obj.gsProp = New testclass
883 Call ok(funcCalled = "gsProp set", "funcCalled = " & funcCalled)
884
885 x = obj
886 Call ok(x = 3, "(x = obj) = " & x)
887 Call ok(funcCalled = "GetDefVal", "funcCalled = " & funcCalled)
888 funcCalled = ""
889 Call ok(obj = 3, "(x = obj) = " & obj)
890 Call ok(funcCalled = "GetDefVal", "funcCalled = " & funcCalled)
891
892 Call obj.Class_Initialize
893 Call ok(obj.getPrivateProp() = true, "obj.getPrivateProp() = " & obj.getPrivateProp())
894
895 x = (New testclass).publicProp
896
897 Class TermTest
898 Public Sub Class_Terminate()
899 funcCalled = "terminate"
900 End Sub
901 End Class
902
903 Set obj = New TermTest
904 funcCalled = ""
905 Set obj = Nothing
906 Call ok(funcCalled = "terminate", "funcCalled = " & funcCalled)
907
908 Set obj = New TermTest
909 funcCalled = ""
910 Call obj.Class_Terminate
911 Call ok(funcCalled = "terminate", "funcCalled = " & funcCalled)
912 funcCalled = ""
913 Set obj = Nothing
914 Call ok(funcCalled = "terminate", "funcCalled = " & funcCalled)
915
916 Call (New testclass).publicSub()
917 Call (New testclass).publicSub
918
919 x = "following ':' is correct syntax" :
920 x = "following ':' is correct syntax" :: :
921 :: x = "also correct syntax"
922 rem another ugly way for comments
923 x = "rem as simplestatement" : rem rem comment
924 :
925
926 Set obj = new EmptyClass
927 Set x = obj
928 Set y = new EmptyClass
929
930 Call ok(obj is x, "obj is not x")
931 Call ok(x is obj, "x is not obj")
932 Call ok(not (obj is y), "obj is not y")
933 Call ok(not obj is y, "obj is not y")
934 Call ok(not (x is Nothing), "x is 1")
935 Call ok(Nothing is Nothing, "Nothing is not Nothing")
936 Call ok(x is obj and true, "x is obj and true is false")
937
938 Class TestMe
939 Public Sub Test(MyMe)
940 Call ok(Me is MyMe, "Me is not MyMe")
941 End Sub
942 End Class
943
944 Set obj = New TestMe
945 Call obj.test(obj)
946
947 Call ok(getVT(test) = "VT_DISPATCH", "getVT(test) = " & getVT(test))
948 Call ok(Me is Test, "Me is not Test")
949
950 Const c1 = 1, c2 = 2, c3 = -3
951 Call ok(c1 = 1, "c1 = " & c1)
952 Call ok(getVT(c1) = "VT_I2", "getVT(c1) = " & getVT(c1))
953 Call ok(c3 = -3, "c3 = " & c3)
954 Call ok(getVT(c3) = "VT_I2", "getVT(c3) = " & getVT(c3))
955
956 Const cb = True, cs = "test", cnull = null
957 Call ok(cb, "cb = " & cb)
958 Call ok(getVT(cb) = "VT_BOOL", "getVT(cb) = " & getVT(cb))
959 Call ok(cs = "test", "cs = " & cs)
960 Call ok(getVT(cs) = "VT_BSTR", "getVT(cs) = " & getVT(cs))
961 Call ok(isNull(cnull), "cnull = " & cnull)
962 Call ok(getVT(cnull) = "VT_NULL", "getVT(cnull) = " & getVT(cnull))
963
964 if false then Const conststr = "str"
965 Call ok(conststr = "str", "conststr = " & conststr)
966 Call ok(getVT(conststr) = "VT_BSTR", "getVT(conststr) = " & getVT(conststr))
967 Call ok(conststr = "str", "conststr = " & conststr)
968
969 Sub ConstTestSub
970 Const funcconst = 1
971 Call ok(c1 = 1, "c1 = " & c1)
972 Call ok(funcconst = 1, "funcconst = " & funcconst)
973 End Sub
974
975 Call ConstTestSub
976 Dim funcconst
977
978 ' Property may be used as an identifier (although it's a keyword)
979 Sub TestProperty
980 Dim Property
981 PROPERTY = true
982 Call ok(property, "property = " & property)
983
984 for property = 1 to 2
985 next
986 End Sub
987
988 Call TestProperty
989
990 Class Property
991 Public Sub Property()
992 End Sub
993
994 Sub Test(byref property)
995 End Sub
996 End Class
997
998 Class Property2
999 Function Property()
1000 End Function
1001
1002 Sub Test(property)
1003 End Sub
1004
1005 Sub Test2(byval property)
1006 End Sub
1007 End Class
1008
1009 ' Array tests
1010
1011 Call ok(getVT(arr) = "VT_EMPTY*", "getVT(arr) = " & getVT(arr))
1012
1013 Dim arr(3)
1014 Dim arr2(4,3), arr3(5,4,3), arr0(0), noarr()
1015
1016 Call ok(getVT(arr) = "VT_ARRAY|VT_BYREF|VT_VARIANT*", "getVT(arr) = " & getVT(arr))
1017 Call ok(getVT(arr2) = "VT_ARRAY|VT_BYREF|VT_VARIANT*", "getVT(arr2) = " & getVT(arr2))
1018 Call ok(getVT(arr0) = "VT_ARRAY|VT_BYREF|VT_VARIANT*", "getVT(arr0) = " & getVT(arr0))
1019 Call ok(getVT(noarr) = "VT_ARRAY|VT_BYREF|VT_VARIANT*", "getVT(noarr) = " & getVT(noarr))
1020
1021 Call testArray(1, arr)
1022 Call testArray(2, arr2)
1023 Call testArray(3, arr3)
1024 Call testArray(0, arr0)
1025 Call testArray(-1, noarr)
1026
1027 Call ok(getVT(arr(1)) = "VT_EMPTY*", "getVT(arr(1)) = " & getVT(arr(1)))
1028 Call ok(getVT(arr2(1,2)) = "VT_EMPTY*", "getVT(arr2(1,2)) = " & getVT(arr2(1,2)))
1029 Call ok(getVT(arr3(1,2,2)) = "VT_EMPTY*", "getVT(arr3(1,2,3)) = " & getVT(arr3(1,2,2)))
1030 Call ok(getVT(arr(0)) = "VT_EMPTY*", "getVT(arr(0)) = " & getVT(arr(0)))
1031 Call ok(getVT(arr(3)) = "VT_EMPTY*", "getVT(arr(3)) = " & getVT(arr(3)))
1032 Call ok(getVT(arr0(0)) = "VT_EMPTY*", "getVT(arr0(0)) = " & getVT(arr0(0)))
1033
1034 arr(2) = 3
1035 Call ok(arr(2) = 3, "arr(2) = " & arr(2))
1036 Call ok(getVT(arr(2)) = "VT_I2*", "getVT(arr(2)) = " & getVT(arr(2)))
1037
1038 arr3(3,2,1) = 1
1039 arr3(1,2,3) = 2
1040 Call ok(arr3(3,2,1) = 1, "arr3(3,2,1) = " & arr3(3,2,1))
1041 Call ok(arr3(1,2,3) = 2, "arr3(1,2,3) = " & arr3(1,2,3))
1042
1043 x = arr3
1044 Call ok(x(3,2,1) = 1, "x(3,2,1) = " & x(3,2,1))
1045
1046 Function getarr()
1047 Dim arr(3)
1048 arr(2) = 2
1049 getarr = arr
1050 arr(3) = 3
1051 End Function
1052
1053 x = getarr()
1054 Call ok(getVT(x) = "VT_ARRAY|VT_VARIANT*", "getVT(x) = " & getVT(x))
1055 Call ok(x(2) = 2, "x(2) = " & x(2))
1056 Call ok(getVT(x(3)) = "VT_EMPTY*", "getVT(x(3)) = " & getVT(x(3)))
1057
1058 x(1) = 1
1059 Call ok(x(1) = 1, "x(1) = " & x(1))
1060 x = getarr()
1061 Call ok(getVT(x(1)) = "VT_EMPTY*", "getVT(x(1)) = " & getVT(x(1)))
1062 Call ok(x(2) = 2, "x(2) = " & x(2))
1063
1064 x(1) = 1
1065 y = x
1066 x(1) = 2
1067 Call ok(y(1) = 1, "y(1) = " & y(1))
1068
1069 for x=1 to 1
1070 Dim forarr(3)
1071 if x=1 then
1072 Call ok(getVT(forarr(1)) = "VT_EMPTY*", "getVT(forarr(1)) = " & getVT(forarr(1)))
1073 else
1074 Call ok(forarr(1) = x, "forarr(1) = " & forarr(1))
1075 end if
1076 forarr(1) = x+1
1077 next
1078
1079 x=1
1080 Call ok(forarr(x) = 2, "forarr(x) = " & forarr(x))
1081
1082 Class ArrClass
1083 Dim classarr(3)
1084 Dim classnoarr()
1085 Dim var
1086
1087 Private Sub Class_Initialize
1088 Call ok(getVT(classarr) = "VT_ARRAY|VT_BYREF|VT_VARIANT*", "getVT(classarr) = " & getVT(classarr))
1089 Call testArray(-1, classnoarr)
1090 classarr(0) = 1
1091 classarr(1) = 2
1092 classarr(2) = 3
1093 classarr(3) = 4
1094 End Sub
1095
1096 Public Sub testVarVT
1097 Call ok(getVT(var) = "VT_ARRAY|VT_VARIANT*", "getVT(var) = " & getVT(var))
1098 End Sub
1099 End Class
1100
1101 Set obj = new ArrClass
1102 Call ok(getVT(obj.classarr) = "VT_ARRAY|VT_VARIANT", "getVT(obj.classarr) = " & getVT(obj.classarr))
1103 'todo_wine Call ok(obj.classarr(1) = 2, "obj.classarr(1) = " & obj.classarr(1))
1104
1105 obj.var = arr
1106 Call ok(getVT(obj.var) = "VT_ARRAY|VT_VARIANT", "getVT(obj.var) = " & getVT(obj.var))
1107 Call obj.testVarVT
1108
1109 Sub arrarg(byref refarr, byval valarr, byref refarr2, byval valarr2)
1110 Call ok(getVT(refarr) = "VT_ARRAY|VT_BYREF|VT_VARIANT*", "getVT(refarr) = " & getVT(refarr))
1111 Call ok(getVT(valarr) = "VT_ARRAY|VT_VARIANT*", "getVT(valarr) = " & getVT(valarr))
1112 Call ok(getVT(refarr2) = "VT_ARRAY|VT_VARIANT*", "getVT(refarr2) = " & getVT(refarr2))
1113 Call ok(getVT(valarr2) = "VT_ARRAY|VT_VARIANT*", "getVT(valarr2) = " & getVT(valarr2))
1114 End Sub
1115
1116 Call arrarg(arr, arr, obj.classarr, obj.classarr)
1117
1118 Sub arrarg2(byref refarr(), byval valarr(), byref refarr2(), byval valarr2())
1119 Call ok(getVT(refarr) = "VT_ARRAY|VT_BYREF|VT_VARIANT*", "getVT(refarr) = " & getVT(refarr))
1120 Call ok(getVT(valarr) = "VT_ARRAY|VT_VARIANT*", "getVT(valarr) = " & getVT(valarr))
1121 Call ok(getVT(refarr2) = "VT_ARRAY|VT_VARIANT*", "getVT(refarr2) = " & getVT(refarr2))
1122 Call ok(getVT(valarr2) = "VT_ARRAY|VT_VARIANT*", "getVT(valarr2) = " & getVT(valarr2))
1123 End Sub
1124
1125 Call arrarg2(arr, arr, obj.classarr, obj.classarr)
1126
1127 Sub testarrarg(arg(), vt)
1128 Call ok(getVT(arg) = vt, "getVT() = " & getVT(arg) & " expected " & vt)
1129 End Sub
1130
1131 Call testarrarg(1, "VT_I2*")
1132 Call testarrarg(false, "VT_BOOL*")
1133 Call testarrarg(Empty, "VT_EMPTY*")
1134
1135 ' It's allowed to declare non-builtin RegExp class...
1136 class RegExp
1137 public property get Global()
1138 Call ok(false, "Global called")
1139 Global = "fail"
1140 end property
1141 end class
1142
1143 ' ...but there is no way to use it because builtin instance is always created
1144 set x = new RegExp
1145 Call ok(x.Global = false, "x.Global = " & x.Global)
1146
1147 reportSuccess()