vbscript: Allow property getters to take arguments.
[wine.git] / dlls / vbscript / tests / lang.vbs
blobc24ffa6d7b65497623e1125a1929f1fcdf604c19
2 ' Copyright 2011 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 dim x, y, z
22 Dim obj
24 call ok(true, "true is not true?")
25 ok true, "true is not true?"
26 call ok((true), "true is not true?")
28 ok not false, "not false but not true?"
29 ok not not true, "not not true but not true?"
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")
50 x = "xx"
51 Call ok(x = "xx", "x = " & x & " expected ""xx""")
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")
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")
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))
96 Call ok(isNullDisp(nothing), "nothing is not nulldisp?")
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))
105 if(isEnglishLang) then
106 Call ok("" & true = "True", """"" & true = " & true)
107 Call ok(true & false = "TrueFalse", "true & false = " & (true & false))
108 end if
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))
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")
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?")
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))
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?")
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")
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")
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))
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))
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))
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))
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))
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))
196 x =_
201 x = 3
203 if true then y = true : x = y
204 ok x, "x is false"
206 x = true : if false then x = false
207 ok x, "x is false, if false called?"
209 if not false then x = true
210 ok x, "x is false, if not false not called?"
212 if not false then x = "test" : x = true
213 ok x, "x is false, if not false not called?"
215 if false then x = y : call ok(false, "if false .. : called")
217 if false then x = y : call ok(false, "if false .. : called") else x = "else"
218 Call ok(x = "else", "else not called?")
220 if true then x = y else y = x : Call ok(false, "in else?")
222 if false then :
224 if false then x = y : if true then call ok(false, "embedded if called")
226 if false then x=1 else x=2 end if
228 x = false
229 if false then x = true : x = true
230 Call ok(x = false, "x <> false")
232 if false then
233 ok false, "if false called"
234 end if
236 x = true
237 if x then
238 x = false
239 end if
240 Call ok(not x, "x is false, if not evaluated?")
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?")
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?")
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?")
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?")
280 x = false
281 if 1 then x = true
282 Call ok(x, "if 1 not run?")
284 x = false
285 if &h10000& then x = true
286 Call ok(x, "if &h10000& not run?")
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")
298 if false then
299 ' empty body
300 end if
302 if false then
303 x = false
304 elseif true then
305 ' empty body
306 end if
308 if false then
309 x = false
310 else
311 ' empty body
312 end if
314 while false
315 wend
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")
327 do while false
328 loop
330 do while true
331 exit do
332 ok false, "exit do didn't work"
333 loop
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")
345 do until true
346 loop
348 do until false
349 exit do
350 ok false, "exit do didn't work"
351 loop
353 x = false
355 if x then exit do
356 x = true
357 loop
358 call ok(x, "x is false after do..loop?")
360 x = false
361 y = false
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")
371 loop until true
374 exit do
375 ok false, "exit do didn't work"
376 loop until false
378 x = false
379 y = false
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")
389 loop while false
392 exit do
393 ok false, "exit do didn't work"
394 loop while true
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)
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)
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)
415 y = "for4:"
416 for x = 5 to 4
417 y = y & " " & x
418 next
419 Call ok(y = "for4:", "y = " & y)
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)
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)
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)
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)
450 for x = 1.5 to 1
451 Call ok(false, "for..to called when unexpected")
452 next
454 for x = 1 to 100
455 exit for
456 Call ok(false, "exit for not escaped the loop?")
457 next
459 do while true
460 for x = 1 to 100
461 exit do
462 next
463 loop
465 if null then call ok(false, "if null evaluated")
467 while null
468 call ok(false, "while null evaluated")
469 wend
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))
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)
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))
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")
521 x = false
522 select case 3
523 case 3
524 x = true
525 end select
526 Call ok(x, "wrong case")
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")
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")
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
554 select case 0
555 end select
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")
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")
573 if false then
574 Sub testsub
575 x = true
576 End Sub
577 end if
579 x = false
580 Call testsub
581 Call ok(x, "x is false, testsub not called?")
583 Sub SubSetTrue(v)
584 Call ok(not v, "v is not true")
585 v = true
586 End Sub
588 x = false
589 SubSetTrue x
590 Call ok(x, "x was not set by SubSetTrue")
592 SubSetTrue false
593 Call ok(not false, "false is no longer false?")
595 Sub SubSetTrue2(ByRef v)
596 Call ok(not v, "v is not true")
597 v = true
598 End Sub
600 x = false
601 SubSetTrue2 x
602 Call ok(x, "x was not set by SubSetTrue")
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
610 x = false
611 Call TestSubArgVal(x)
612 Call ok(not x, "x is true after TestSubArgVal call?")
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
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
629 Call TestSubExit(true)
631 Sub TestSubExit2
632 for x = 1 to 100
633 Exit Sub
634 next
635 End Sub
636 Call TestSubExit2
638 TestSubMultiArgs 1, 2, 3, 4, 5
639 Call TestSubMultiArgs(1, 2, 3, 4, 5)
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
648 x = true
649 y = true
650 Call TestSubLocalVal
651 Call ok(x, "global x is not true?")
653 Public Sub TestPublicSub
654 End Sub
655 Call TestPublicSub
657 Private Sub TestPrivateSub
658 End Sub
659 Call TestPrivateSub
661 if false then
662 Function testfunc
663 x = true
664 End Function
665 end if
667 x = false
668 Call TestFunc
669 Call ok(x, "x is false, testfunc not called?")
671 Function FuncSetTrue(v)
672 Call ok(not v, "v is not true")
673 v = true
674 End Function
676 x = false
677 FuncSetTrue x
678 Call ok(x, "x was not set by FuncSetTrue")
680 FuncSetTrue false
681 Call ok(not false, "false is no longer false?")
683 Function FuncSetTrue2(ByRef v)
684 Call ok(not v, "v is not true")
685 v = true
686 End Function
688 x = false
689 FuncSetTrue2 x
690 Call ok(x, "x was not set by FuncSetTrue")
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
698 x = false
699 Call TestFuncArgVal(x)
700 Call ok(not x, "x is true after TestFuncArgVal call?")
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
710 TestFuncMultiArgs 1, 2, 3, 4, 5
711 Call TestFuncMultiArgs(1, 2, 3, 4, 5)
713 Function TestFuncLocalVal
714 x = false
715 Call ok(not x, "local x is not false?")
716 Dim x
717 End Function
719 x = true
720 y = true
721 Call TestFuncLocalVal
722 Call ok(x, "global x is not true?")
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
731 Call TestFuncExit(true)
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
742 Call TestFuncExit2(true)
744 Sub SubParseTest
745 End Sub : x = false
746 Call SubParseTest
748 Function FuncParseTest
749 End Function : x = false
751 Function ReturnTrue
752 ReturnTrue = false
753 ReturnTrue = true
754 End Function
756 Call ok(ReturnTrue(), "ReturnTrue returned false?")
758 Function SetVal(ByRef x, ByVal v)
759 x = v
760 SetVal = x
761 Exit Function
762 End Function
764 x = false
765 ok SetVal(x, true), "SetVal returned false?"
766 Call ok(x, "x is not set to true by SetVal?")
768 Public Function TestPublicFunc
769 End Function
770 Call TestPublicFunc
772 Private Function TestPrivateFunc
773 End Function
774 Call TestPrivateFunc
776 ' Stop has an effect only in debugging mode
777 Stop
779 set x = testObj
780 Call ok(getVT(x) = "VT_DISPATCH*", "getVT(x=testObj) = " & getVT(x))
782 Set obj = New EmptyClass
783 Call ok(getVT(obj) = "VT_DISPATCH*", "getVT(obj) = " & getVT(obj))
785 Class EmptyClass
786 End Class
788 Set x = obj
789 Call ok(getVT(x) = "VT_DISPATCH*", "getVT(x) = " & getVT(x))
791 Class TestClass
792 Public publicProp
794 Private privateProp
796 Public Function publicFunction()
797 privateSub()
798 publicFunction = 4
799 End Function
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
808 Public Default Property Get DefValGet
809 DefValGet = privateProp
810 funcCalled = "GetDefVal"
811 End Property
813 Public Property Let DefValGet(x)
814 End Property
816 Public publicProp2
818 Public Sub publicSub
819 End Sub
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
828 Public Property Set gsProp(val)
829 funcCalled = "gsProp set"
830 exit property
831 Call ok(false, "exit property not returned?")
832 End Property
834 Public Sub setPrivateProp(x)
835 privateProp = x
836 End Sub
838 Function getPrivateProp
839 getPrivateProp = privateProp
840 End Function
842 Private Sub privateSub
843 End Sub
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
853 Property Get gsGetProp(x)
854 gsGetProp = x
855 End Property
856 End Class
858 Call testDisp(new testClass)
860 Set obj = New TestClass
862 Call ok(obj.publicFunction = 4, "obj.publicFunction = " & obj.publicFunction)
863 Call ok(obj.publicFunction() = 4, "obj.publicFunction() = " & obj.publicFunction())
865 obj.publicSub()
866 Call obj.publicSub
867 Call obj.publicFunction()
869 Call ok(getVT(obj.publicProp) = "VT_EMPTY", "getVT(obj.publicProp) = " & getVT(obj.publicProp))
870 obj.publicProp = 3
871 Call ok(getVT(obj.publicProp) = "VT_I2", "getVT(obj.publicProp) = " & getVT(obj.publicProp))
872 Call ok(obj.publicProp = 3, "obj.publicProp = " & obj.publicProp)
873 obj.publicProp() = 3
875 Call ok(obj.getPrivateProp() = true, "obj.getPrivateProp() = " & obj.getPrivateProp())
876 Call obj.setPrivateProp(6)
877 Call ok(obj.getPrivateProp = 6, "obj.getPrivateProp = " & obj.getPrivateProp)
879 Dim funcCalled
880 funcCalled = ""
881 Call ok(obj.gsProp = 6, "obj.gsProp = " & obj.gsProp)
882 Call ok(funcCalled = "gsProp get", "funcCalled = " & funcCalled)
883 obj.gsProp = 3
884 Call ok(funcCalled = "gsProp let", "funcCalled = " & funcCalled)
885 Call ok(obj.getPrivateProp = 3, "obj.getPrivateProp = " & obj.getPrivateProp)
886 Set obj.gsProp = New testclass
887 Call ok(funcCalled = "gsProp set", "funcCalled = " & funcCalled)
889 x = obj
890 Call ok(x = 3, "(x = obj) = " & x)
891 Call ok(funcCalled = "GetDefVal", "funcCalled = " & funcCalled)
892 funcCalled = ""
893 Call ok(obj = 3, "(x = obj) = " & obj)
894 Call ok(funcCalled = "GetDefVal", "funcCalled = " & funcCalled)
896 Call obj.Class_Initialize
897 Call ok(obj.getPrivateProp() = true, "obj.getPrivateProp() = " & obj.getPrivateProp())
899 x = (New testclass).publicProp
901 Class TermTest
902 Public Sub Class_Terminate()
903 funcCalled = "terminate"
904 End Sub
905 End Class
907 Set obj = New TermTest
908 funcCalled = ""
909 Set obj = Nothing
910 Call ok(funcCalled = "terminate", "funcCalled = " & funcCalled)
912 Set obj = New TermTest
913 funcCalled = ""
914 Call obj.Class_Terminate
915 Call ok(funcCalled = "terminate", "funcCalled = " & funcCalled)
916 funcCalled = ""
917 Set obj = Nothing
918 Call ok(funcCalled = "terminate", "funcCalled = " & funcCalled)
920 Call (New testclass).publicSub()
921 Call (New testclass).publicSub
923 class PropTest
924 property get prop0()
925 prop0 = 1
926 end property
928 property get prop1(x)
929 prop1 = x+1
930 end property
932 property get prop2(x, y)
933 prop2 = x+y
934 end property
935 end class
937 set obj = new PropTest
939 call ok(obj.prop0 = 1, "obj.prop0 = " & obj.prop0)
940 call ok(obj.prop1(3) = 4, "obj.prop1(3) = " & obj.prop1(3))
941 call ok(obj.prop2(3,4) = 7, "obj.prop2(3,4) = " & obj.prop2(3,4))
942 call obj.prop0()
943 call obj.prop1(2)
944 call obj.prop2(3,4)
946 x = "following ':' is correct syntax" :
947 x = "following ':' is correct syntax" :: :
948 :: x = "also correct syntax"
949 rem another ugly way for comments
950 x = "rem as simplestatement" : rem rem comment
953 Set obj = new EmptyClass
954 Set x = obj
955 Set y = new EmptyClass
957 Call ok(obj is x, "obj is not x")
958 Call ok(x is obj, "x is not obj")
959 Call ok(not (obj is y), "obj is not y")
960 Call ok(not obj is y, "obj is not y")
961 Call ok(not (x is Nothing), "x is 1")
962 Call ok(Nothing is Nothing, "Nothing is not Nothing")
963 Call ok(x is obj and true, "x is obj and true is false")
965 Class TestMe
966 Public Sub Test(MyMe)
967 Call ok(Me is MyMe, "Me is not MyMe")
968 End Sub
969 End Class
971 Set obj = New TestMe
972 Call obj.test(obj)
974 Call ok(getVT(test) = "VT_DISPATCH", "getVT(test) = " & getVT(test))
975 Call ok(Me is Test, "Me is not Test")
977 Const c1 = 1, c2 = 2, c3 = -3
978 Call ok(c1 = 1, "c1 = " & c1)
979 Call ok(getVT(c1) = "VT_I2", "getVT(c1) = " & getVT(c1))
980 Call ok(c3 = -3, "c3 = " & c3)
981 Call ok(getVT(c3) = "VT_I2", "getVT(c3) = " & getVT(c3))
983 Const cb = True, cs = "test", cnull = null
984 Call ok(cb, "cb = " & cb)
985 Call ok(getVT(cb) = "VT_BOOL", "getVT(cb) = " & getVT(cb))
986 Call ok(cs = "test", "cs = " & cs)
987 Call ok(getVT(cs) = "VT_BSTR", "getVT(cs) = " & getVT(cs))
988 Call ok(isNull(cnull), "cnull = " & cnull)
989 Call ok(getVT(cnull) = "VT_NULL", "getVT(cnull) = " & getVT(cnull))
991 if false then Const conststr = "str"
992 Call ok(conststr = "str", "conststr = " & conststr)
993 Call ok(getVT(conststr) = "VT_BSTR", "getVT(conststr) = " & getVT(conststr))
994 Call ok(conststr = "str", "conststr = " & conststr)
996 Sub ConstTestSub
997 Const funcconst = 1
998 Call ok(c1 = 1, "c1 = " & c1)
999 Call ok(funcconst = 1, "funcconst = " & funcconst)
1000 End Sub
1002 Call ConstTestSub
1003 Dim funcconst
1005 ' Property may be used as an identifier (although it's a keyword)
1006 Sub TestProperty
1007 Dim Property
1008 PROPERTY = true
1009 Call ok(property, "property = " & property)
1011 for property = 1 to 2
1012 next
1013 End Sub
1015 Call TestProperty
1017 Class Property
1018 Public Sub Property()
1019 End Sub
1021 Sub Test(byref property)
1022 End Sub
1023 End Class
1025 Class Property2
1026 Function Property()
1027 End Function
1029 Sub Test(property)
1030 End Sub
1032 Sub Test2(byval property)
1033 End Sub
1034 End Class
1036 ' Array tests
1038 Call ok(getVT(arr) = "VT_EMPTY*", "getVT(arr) = " & getVT(arr))
1040 Dim arr(3)
1041 Dim arr2(4,3), arr3(5,4,3), arr0(0), noarr()
1043 Call ok(getVT(arr) = "VT_ARRAY|VT_BYREF|VT_VARIANT*", "getVT(arr) = " & getVT(arr))
1044 Call ok(getVT(arr2) = "VT_ARRAY|VT_BYREF|VT_VARIANT*", "getVT(arr2) = " & getVT(arr2))
1045 Call ok(getVT(arr0) = "VT_ARRAY|VT_BYREF|VT_VARIANT*", "getVT(arr0) = " & getVT(arr0))
1046 Call ok(getVT(noarr) = "VT_ARRAY|VT_BYREF|VT_VARIANT*", "getVT(noarr) = " & getVT(noarr))
1048 Call testArray(1, arr)
1049 Call testArray(2, arr2)
1050 Call testArray(3, arr3)
1051 Call testArray(0, arr0)
1052 Call testArray(-1, noarr)
1054 Call ok(getVT(arr(1)) = "VT_EMPTY*", "getVT(arr(1)) = " & getVT(arr(1)))
1055 Call ok(getVT(arr2(1,2)) = "VT_EMPTY*", "getVT(arr2(1,2)) = " & getVT(arr2(1,2)))
1056 Call ok(getVT(arr3(1,2,2)) = "VT_EMPTY*", "getVT(arr3(1,2,3)) = " & getVT(arr3(1,2,2)))
1057 Call ok(getVT(arr(0)) = "VT_EMPTY*", "getVT(arr(0)) = " & getVT(arr(0)))
1058 Call ok(getVT(arr(3)) = "VT_EMPTY*", "getVT(arr(3)) = " & getVT(arr(3)))
1059 Call ok(getVT(arr0(0)) = "VT_EMPTY*", "getVT(arr0(0)) = " & getVT(arr0(0)))
1061 arr(2) = 3
1062 Call ok(arr(2) = 3, "arr(2) = " & arr(2))
1063 Call ok(getVT(arr(2)) = "VT_I2*", "getVT(arr(2)) = " & getVT(arr(2)))
1065 arr3(3,2,1) = 1
1066 arr3(1,2,3) = 2
1067 Call ok(arr3(3,2,1) = 1, "arr3(3,2,1) = " & arr3(3,2,1))
1068 Call ok(arr3(1,2,3) = 2, "arr3(1,2,3) = " & arr3(1,2,3))
1070 x = arr3
1071 Call ok(x(3,2,1) = 1, "x(3,2,1) = " & x(3,2,1))
1073 Function getarr()
1074 Dim arr(3)
1075 arr(2) = 2
1076 getarr = arr
1077 arr(3) = 3
1078 End Function
1080 x = getarr()
1081 Call ok(getVT(x) = "VT_ARRAY|VT_VARIANT*", "getVT(x) = " & getVT(x))
1082 Call ok(x(2) = 2, "x(2) = " & x(2))
1083 Call ok(getVT(x(3)) = "VT_EMPTY*", "getVT(x(3)) = " & getVT(x(3)))
1085 x(1) = 1
1086 Call ok(x(1) = 1, "x(1) = " & x(1))
1087 x = getarr()
1088 Call ok(getVT(x(1)) = "VT_EMPTY*", "getVT(x(1)) = " & getVT(x(1)))
1089 Call ok(x(2) = 2, "x(2) = " & x(2))
1091 x(1) = 1
1092 y = x
1093 x(1) = 2
1094 Call ok(y(1) = 1, "y(1) = " & y(1))
1096 for x=1 to 1
1097 Dim forarr(3)
1098 if x=1 then
1099 Call ok(getVT(forarr(1)) = "VT_EMPTY*", "getVT(forarr(1)) = " & getVT(forarr(1)))
1100 else
1101 Call ok(forarr(1) = x, "forarr(1) = " & forarr(1))
1102 end if
1103 forarr(1) = x+1
1104 next
1107 Call ok(forarr(x) = 2, "forarr(x) = " & forarr(x))
1109 Class ArrClass
1110 Dim classarr(3)
1111 Dim classnoarr()
1112 Dim var
1114 Private Sub Class_Initialize
1115 Call ok(getVT(classarr) = "VT_ARRAY|VT_BYREF|VT_VARIANT*", "getVT(classarr) = " & getVT(classarr))
1116 Call testArray(-1, classnoarr)
1117 classarr(0) = 1
1118 classarr(1) = 2
1119 classarr(2) = 3
1120 classarr(3) = 4
1121 End Sub
1123 Public Sub testVarVT
1124 Call ok(getVT(var) = "VT_ARRAY|VT_VARIANT*", "getVT(var) = " & getVT(var))
1125 End Sub
1126 End Class
1128 Set obj = new ArrClass
1129 Call ok(getVT(obj.classarr) = "VT_ARRAY|VT_VARIANT", "getVT(obj.classarr) = " & getVT(obj.classarr))
1130 'todo_wine Call ok(obj.classarr(1) = 2, "obj.classarr(1) = " & obj.classarr(1))
1132 obj.var = arr
1133 Call ok(getVT(obj.var) = "VT_ARRAY|VT_VARIANT", "getVT(obj.var) = " & getVT(obj.var))
1134 Call obj.testVarVT
1136 Sub arrarg(byref refarr, byval valarr, byref refarr2, byval valarr2)
1137 Call ok(getVT(refarr) = "VT_ARRAY|VT_BYREF|VT_VARIANT*", "getVT(refarr) = " & getVT(refarr))
1138 Call ok(getVT(valarr) = "VT_ARRAY|VT_VARIANT*", "getVT(valarr) = " & getVT(valarr))
1139 Call ok(getVT(refarr2) = "VT_ARRAY|VT_VARIANT*", "getVT(refarr2) = " & getVT(refarr2))
1140 Call ok(getVT(valarr2) = "VT_ARRAY|VT_VARIANT*", "getVT(valarr2) = " & getVT(valarr2))
1141 End Sub
1143 Call arrarg(arr, arr, obj.classarr, obj.classarr)
1145 Sub arrarg2(byref refarr(), byval valarr(), byref refarr2(), byval valarr2())
1146 Call ok(getVT(refarr) = "VT_ARRAY|VT_BYREF|VT_VARIANT*", "getVT(refarr) = " & getVT(refarr))
1147 Call ok(getVT(valarr) = "VT_ARRAY|VT_VARIANT*", "getVT(valarr) = " & getVT(valarr))
1148 Call ok(getVT(refarr2) = "VT_ARRAY|VT_VARIANT*", "getVT(refarr2) = " & getVT(refarr2))
1149 Call ok(getVT(valarr2) = "VT_ARRAY|VT_VARIANT*", "getVT(valarr2) = " & getVT(valarr2))
1150 End Sub
1152 Call arrarg2(arr, arr, obj.classarr, obj.classarr)
1154 Sub testarrarg(arg(), vt)
1155 Call ok(getVT(arg) = vt, "getVT() = " & getVT(arg) & " expected " & vt)
1156 End Sub
1158 Call testarrarg(1, "VT_I2*")
1159 Call testarrarg(false, "VT_BOOL*")
1160 Call testarrarg(Empty, "VT_EMPTY*")
1162 ' It's allowed to declare non-builtin RegExp class...
1163 class RegExp
1164 public property get Global()
1165 Call ok(false, "Global called")
1166 Global = "fail"
1167 end property
1168 end class
1170 ' ...but there is no way to use it because builtin instance is always created
1171 set x = new RegExp
1172 Call ok(x.Global = false, "x.Global = " & x.Global)
1174 reportSuccess()