vbscript: Added interp_gt implementation.
[wine] / dlls / vbscript / tests / 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
22
23 call ok(true, "true is not true?")
24 ok true, "true is not true?"
25 call ok((true), "true is not true?")
26
27 ok not false, "not false but not true?"
28 ok not not true, "not not true but not true?"
29
30 Call ok(true = true, "true = true is false")
31 Call ok(false = false, "false = false is false")
32 Call ok(not (true = false), "true = false is true")
33 Call ok("x" = "x", """x"" = ""x"" is false")
34 Call ok(empty = empty, "empty = empty is false")
35 Call ok(empty = "", "empty = """" is false")
36 Call ok(0 = 0.0, "0 <> 0.0")
37 Call ok(16 = &h10&, "16 <> &h10&")
38 Call ok(010 = 10, "010 <> 10")
39 Call ok(10. = 10, "10. <> 10")
40 Call ok(&hffFFffFF& = -1, "&hffFFffFF& <> -1")
41 Call ok(&hffFFffFF& = -1, "&hffFFffFF& <> -1")
42 Call ok(--1 = 1, "--1 = " & --1)
43 Call ok(-empty = 0, "-empty = " & (-empty))
44
45 x = "xx"
46 Call ok(x = "xx", "x = " & x & " expected ""xx""")
47
48 Call ok(true <> false, "true <> false is false")
49 Call ok(not (true <> true), "true <> true is true")
50 Call ok(not ("x" <> "x"), """x"" <> ""x"" is true")
51 Call ok(not (empty <> empty), "empty <> empty is true")
52 Call ok(x <> "x", "x = ""x""")
53
54 Call ok(getVT(false) = "VT_BOOL", "getVT(false) is not VT_BOOL")
55 Call ok(getVT(true) = "VT_BOOL", "getVT(true) is not VT_BOOL")
56 Call ok(getVT("") = "VT_BSTR", "getVT("""") is not VT_BSTR")
57 Call ok(getVT("test") = "VT_BSTR", "getVT(""test"") is not VT_BSTR")
58 Call ok(getVT(Empty) = "VT_EMPTY", "getVT(Empty) is not VT_EMPTY")
59 Call ok(getVT(null) = "VT_NULL", "getVT(null) is not VT_NULL")
60 Call ok(getVT(0) = "VT_I2", "getVT(0) is not VT_I2")
61 Call ok(getVT(1) = "VT_I2", "getVT(1) is not VT_I2")
62 Call ok(getVT(0.5) = "VT_R8", "getVT(0.5) is not VT_R8")
63 Call ok(getVT(0.0) = "VT_R8", "getVT(0.0) is not VT_R8")
64 Call ok(getVT(2147483647) = "VT_I4", "getVT(2147483647) is not VT_I4")
65 Call ok(getVT(2147483648) = "VT_R8", "getVT(2147483648) is not VT_R8")
66 Call ok(getVT(&h10&) = "VT_I2", "getVT(&h10&) is not VT_I2")
67 Call ok(getVT(&h10000&) = "VT_I4", "getVT(&h10000&) is not VT_I4")
68 Call ok(getVT(&H10000&) = "VT_I4", "getVT(&H10000&) is not VT_I4")
69 Call ok(getVT(&hffFFffFF&) = "VT_I2", "getVT(&hffFFffFF&) is not VT_I2")
70 Call ok(getVT(1 & 100000) = "VT_BSTR", "getVT(1 & 100000) is not VT_BSTR")
71 Call ok(getVT(-empty) = "VT_I2", "getVT(-empty) = " & getVT(-empty))
72 Call ok(getVT(-null) = "VT_NULL", "getVT(-null) = " & getVT(-null))
73 Call ok(getVT(y) = "VT_EMPTY*", "getVT(y) = " & getVT(y))
74 Call ok(getVT(nothing) = "VT_DISPATCH", "getVT(nothing) = " & getVT(nothing))
75 set x = nothing
76 Call ok(getVT(x) = "VT_DISPATCH*", "getVT(x=nothing) = " & getVT(x))
77 x = true
78 Call ok(getVT(x) = "VT_BOOL*", "getVT(x) = " & getVT(x))
79
80 Call ok(isNullDisp(nothing), "nothing is not nulldisp?")
81
82 x = "xx"
83 Call ok("ab" & "cd" = "abcd", """ab"" & ""cd"" <> ""abcd""")
84 Call ok("ab " & null = "ab ", """ab"" & null = " & ("ab " & null))
85 Call ok("ab " & empty = "ab ", """ab"" & empty = " & ("ab " & empty))
86 Call ok(1 & 100000 = "1100000", "1 & 100000 = " & (1 & 100000))
87 Call ok("ab" & x = "abxx", """ab"" & x = " & ("ab"&x))
88
89 if(isEnglishLang) then
90     Call ok("" & true = "True", """"" & true = " & true)
91     Call ok(true & false = "TrueFalse", "true & false = " & (true & false))
92 end if
93
94 call ok(true and true, "true and true is not true")
95 call ok(true and not false, "true and not false is not true")
96 call ok(not (false and true), "not (false and true) is not true")
97 call ok(getVT(null and true) = "VT_NULL", "getVT(null and true) = " & getVT(null and true))
98
99 call ok(false or true, "false or uie is false?")
100 call ok(not (false or false), "false or false is not false?")
101 call ok(false and false or true, "false and false or true is false?")
102 call ok(true or false and false, "true or false and false is false?")
103 call ok(null or true, "null or true is false")
104
105 call ok(true xor false, "true xor false is false?")
106 call ok(not (false xor false), "false xor false is true?")
107 call ok(not (true or false xor true), "true or false xor true is true?")
108 call ok(not (true xor false or true), "true xor false or true is true?")
109
110 call ok(false eqv false, "false does not equal false?")
111 call ok(not (false eqv true), "false equals true?")
112 call ok(getVT(false eqv null) = "VT_NULL", "getVT(false eqv null) = " & getVT(false eqv null))
113
114 call ok(true imp true, "true does not imp true?")
115 call ok(false imp false, "false does not imp false?")
116 call ok(not (true imp false), "true imp false?")
117 call ok(false imp null, "false imp null is false?")
118
119 Call ok(2 >= 1, "! 2 >= 1")
120 Call ok(2 >= 2, "! 2 >= 2")
121 Call ok(not(true >= 2), "true >= 2 ?")
122 Call ok(2 > 1, "! 2 > 1")
123 Call ok(false > true, "! false < true")
124 Call ok(0 > true, "! 0 > true")
125 Call ok(not (true > 0), "true > 0")
126 Call ok(not (0 > 1 = 1), "0 > 1 = 1")
127
128 x = 3
129 Call ok(2+2 = 4, "2+2 = " & (2+2))
130 Call ok(false + 6 + true = 5, "false + 6 + true <> 5")
131 Call ok(getVT(2+null) = "VT_NULL", "getVT(2+null) = " & getVT(2+null))
132 Call ok(2+empty = 2, "2+empty = " & (2+empty))
133 Call ok(x+x = 6, "x+x = " & (x+x))
134
135 Call ok(5-1 = 4, "5-1 = " & (5-1))
136 Call ok(3+5-true = 9, "3+5-true <> 9")
137 Call ok(getVT(2-null) = "VT_NULL", "getVT(2-null) = " & getVT(2-null))
138 Call ok(2-empty = 2, "2-empty = " & (2-empty))
139 Call ok(2-x = -1, "2-x = " & (2-x))
140
141 Call ok(9 Mod 6 = 3, "9 Mod 6 = " & (9 Mod 6))
142 Call ok(11.6 Mod 5.5 = False, "11.6 Mod 5.5 = " & (11.6 Mod 5.5 = 0.6))
143 Call ok(7 Mod 4+2 = 5, "7 Mod 4+2 <> 5")
144 Call ok(getVT(2 mod null) = "VT_NULL", "getVT(2 mod null) = " & getVT(2 mod null))
145 Call ok(getVT(null mod 2) = "VT_NULL", "getVT(null mod 2) = " & getVT(null mod 2))
146 'FIXME: Call ok(empty mod 2 = 0, "empty mod 2 = " & (empty mod 2))
147
148 Call ok(5 \ 2 = 2, "5 \ 2 = " & (5\2))
149 Call ok(4.6 \ 1.5 = 2, "4.6 \ 1.5 = " & (4.6\1.5))
150 Call ok(4.6 \ 1.49 = 5, "4.6 \ 1.49 = " & (4.6\1.49))
151 Call ok(2+3\4 = 2, "2+3\4 = " & (2+3\4))
152
153 Call ok(2*3 = 6, "2*3 = " & (2*3))
154 Call ok(3/2 = 1.5, "3/2 = " & (3/2))
155 Call ok(5\4/2 = 2, "5\4/2 = " & (5\2/1))
156 Call ok(12/3\2 = 2, "12/3\2 = " & (12/3\2))
157
158 Call ok(2^3 = 8, "2^3 = " & (2^3))
159 Call ok(2^3^2 = 64, "2^3^2 = " & (2^3^2))
160 Call ok(-3^2 = 9, "-3^2 = " & (-3^2))
161 Call ok(2*3^2 = 18, "2*3^2 = " & (2*3^2))
162
163 if false then
164     ok false, "if false called"
165 end if
166
167 x = true
168 if x then
169     x = false
170 end if
171 Call ok(not x, "x is false, if not evaluated?")
172
173 x = false
174 If false Then
175    Call ok(false, "inside if false")
176 Else
177    x = true
178 End If
179 Call ok(x, "else not called?")
180
181 x = false
182 If false Then
183    Call ok(false, "inside if false")
184 ElseIf not True Then
185    Call ok(false, "inside elseif not true")
186 Else
187    x = true
188 End If
189 Call ok(x, "else not called?")
190
191 x = false
192 If false Then
193    Call ok(false, "inside if false")
194    x = 1
195    y = 10+x
196 ElseIf not False Then
197    x = true
198 Else
199    Call ok(false, "inside else not true")
200 End If
201 Call ok(x, "elseif not called?")
202
203 x = false
204 If false Then
205    Call ok(false, "inside if false")
206 ElseIf not False Then
207    x = true
208 End If
209 Call ok(x, "elseif not called?")
210
211 x = false
212 y = false
213 while not (x and y)
214     if x then
215         y = true
216     end if
217     x = true
218 wend
219 call ok((x and y), "x or y is false after while")
220
221 while false
222 wend
223
224 x = false
225 y = false
226 do while not (x and y)
227     if x then
228         y = true
229     end if
230     x = true
231 loop
232 call ok((x and y), "x or y is false after while")
233
234 do while false
235 loop
236
237 do while true
238     exit do
239     ok false, "exit do didn't work"
240 loop
241
242 x = false
243 y = false
244 do until x and y
245     if x then
246         y = true
247     end if
248     x = true
249 loop
250 call ok((x and y), "x or y is false after do until")
251
252 do until true
253 loop
254
255 do until false
256     exit do
257     ok false, "exit do didn't work"
258 loop
259
260 x = false
261 y = false
262 do
263     if x then
264         y = true
265     end if
266     x = true
267 loop until x and y
268 call ok((x and y), "x or y is false after while")
269
270 do
271 loop until true
272
273 do
274     exit do
275     ok false, "exit do didn't work"
276 loop until false
277
278 x = false
279 y = false
280 do
281     if x then
282         y = true
283     end if
284     x = true
285 loop while not (x and y)
286 call ok((x and y), "x or y is false after while")
287
288 do
289 loop while false
290
291 do
292     exit do
293     ok false, "exit do didn't work"
294 loop while true
295
296 if false then
297 Sub testsub
298     x = true
299 End Sub
300 end if
301
302 x = false
303 Call testsub
304 Call ok(x, "x is false, testsub not called?")
305
306 Sub SubSetTrue(v)
307     Call ok(not v, "v is not true")
308     v = true
309 End Sub
310
311 x = false
312 SubSetTrue x
313 Call ok(x, "x was not set by SubSetTrue")
314
315 SubSetTrue false
316 Call ok(not false, "false is no longer false?")
317
318 Sub SubSetTrue2(ByRef v)
319     Call ok(not v, "v is not true")
320     v = true
321 End Sub
322
323 x = false
324 SubSetTrue2 x
325 Call ok(x, "x was not set by SubSetTrue")
326
327 Sub TestSubArgVal(ByVal v)
328     Call ok(not v, "v is not false")
329     v = true
330     Call ok(v, "v is not true?")
331 End Sub
332
333 x = false
334 Call TestSubArgVal(x)
335 Call ok(not x, "x is true after TestSubArgVal call?")
336
337 Sub TestSubMultiArgs(a,b,c,d,e)
338     Call ok(a=1, "a = " & a)
339     Call ok(b=2, "b = " & b)
340     Call ok(c=3, "c = " & c)
341     Call ok(d=4, "d = " & d)
342     Call ok(e=5, "e = " & e)
343 End Sub
344
345 Sub TestSubExit(ByRef a)
346     If a Then
347         Exit Sub
348     End If
349     Call ok(false, "Exit Sub not called?")
350 End Sub
351
352 Call TestSubExit(true)
353
354 TestSubMultiArgs 1, 2, 3, 4, 5
355 Call TestSubMultiArgs(1, 2, 3, 4, 5)
356
357 Sub TestSubLocalVal
358     x = false
359     Call ok(not x, "local x is not false?")
360     Dim x
361 End Sub
362
363 x = true
364 y = true
365 Call TestSubLocalVal
366 Call ok(x, "global x is not true?")
367
368 Public Sub TestPublicSub
369 End Sub
370 Call TestPublicSub
371
372 Private Sub TestPrivateSub
373 End Sub
374 Call TestPrivateSub
375
376 if false then
377 Function testfunc
378     x = true
379 End Function
380 end if
381
382 x = false
383 Call TestFunc
384 Call ok(x, "x is false, testfunc not called?")
385
386 Function FuncSetTrue(v)
387     Call ok(not v, "v is not true")
388     v = true
389 End Function
390
391 x = false
392 FuncSetTrue x
393 Call ok(x, "x was not set by FuncSetTrue")
394
395 FuncSetTrue false
396 Call ok(not false, "false is no longer false?")
397
398 Function FuncSetTrue2(ByRef v)
399     Call ok(not v, "v is not true")
400     v = true
401 End Function
402
403 x = false
404 FuncSetTrue2 x
405 Call ok(x, "x was not set by FuncSetTrue")
406
407 Function TestFuncArgVal(ByVal v)
408     Call ok(not v, "v is not false")
409     v = true
410     Call ok(v, "v is not true?")
411 End Function
412
413 x = false
414 Call TestFuncArgVal(x)
415 Call ok(not x, "x is true after TestFuncArgVal call?")
416
417 Function TestFuncMultiArgs(a,b,c,d,e)
418     Call ok(a=1, "a = " & a)
419     Call ok(b=2, "b = " & b)
420     Call ok(c=3, "c = " & c)
421     Call ok(d=4, "d = " & d)
422     Call ok(e=5, "e = " & e)
423 End Function
424
425 TestFuncMultiArgs 1, 2, 3, 4, 5
426 Call TestFuncMultiArgs(1, 2, 3, 4, 5)
427
428 Function TestFuncLocalVal
429     x = false
430     Call ok(not x, "local x is not false?")
431     Dim x
432 End Function
433
434 x = true
435 y = true
436 Call TestFuncLocalVal
437 Call ok(x, "global x is not true?")
438
439 Function TestFuncExit(ByRef a)
440     If a Then
441         Exit Function
442     End If
443     Call ok(false, "Exit Function not called?")
444 End Function
445
446 Call TestFuncExit(true)
447
448 Function ReturnTrue
449      ReturnTrue = false
450      ReturnTrue = true
451 End Function
452
453 Call ok(ReturnTrue(), "ReturnTrue returned false?")
454
455 Function SetVal(ByRef x, ByVal v)
456     x = v
457     SetVal = x
458     Exit Function
459 End Function
460
461 x = false
462 ok SetVal(x, true), "SetVal returned false?"
463 Call ok(x, "x is not set to true by SetVal?")
464
465 Public Function TestPublicFunc
466 End Function
467 Call TestPublicFunc
468
469 Private Function TestPrivateFunc
470 End Function
471 Call TestPrivateFunc
472
473 ' Stop has an effect only in debugging mode
474 Stop
475
476 set x = testObj
477 Call ok(getVT(x) = "VT_DISPATCH*", "getVT(x=testObj) = " & getVT(x))
478
479 Dim obj
480 Set obj = New EmptyClass
481 Call ok(getVT(obj) = "VT_DISPATCH*", "getVT(obj) = " & getVT(obj))
482
483 Class EmptyClass
484 End Class
485
486 Class TestClass
487     Public publicProp
488
489     Private privateProp
490
491     Public Function publicFunction()
492         privateSub()
493         publicFunction = 4
494     End Function
495
496     Public Property Get gsProp()
497         gsProp = privateProp
498         funcCalled = "gsProp get"
499         exit property
500         Call ok(false, "exit property not returned?")
501     End Property
502
503     Public Default Property Get DefValGet
504         DefValGet = privateProp
505         funcCalled = "GetDefVal"
506     End Property
507
508     Public Property Let DefValGet(x)
509     End Property
510
511     Public publicProp2
512
513     Public Sub publicSub
514     End Sub
515
516     Public Property Let gsProp(val)
517         privateProp = val
518         funcCalled = "gsProp let"
519         exit property
520         Call ok(false, "exit property not returned?")
521     End Property
522
523     Public Property Set gsProp(val)
524         funcCalled = "gsProp set"
525         exit property
526         Call ok(false, "exit property not returned?")
527     End Property
528
529     Public Sub setPrivateProp(x)
530         privateProp = x
531     End Sub
532
533     Function getPrivateProp
534         getPrivateProp = privateProp
535     End Function
536
537     Private Sub privateSub
538     End Sub
539
540     Public Sub Class_Initialize
541         publicProp2 = 2
542         privateProp = true
543     End Sub
544 End Class
545
546 Call testDisp(new testClass)
547
548 Set obj = New TestClass
549
550 Call ok(obj.publicFunction = 4, "obj.publicFunction = " & obj.publicFunction)
551 Call ok(obj.publicFunction() = 4, "obj.publicFunction() = " & obj.publicFunction())
552
553 obj.publicSub()
554 Call obj.publicSub
555 Call obj.publicFunction()
556
557 Call ok(getVT(obj.publicProp) = "VT_EMPTY", "getVT(obj.publicProp) = " & getVT(obj.publicProp))
558 obj.publicProp = 3
559 Call ok(obj.publicProp = 3, "obj.publicProp = " & obj.publicProp)
560 obj.publicProp() = 3
561
562 Call ok(obj.getPrivateProp() = true, "obj.getPrivateProp() = " & obj.getPrivateProp())
563 Call obj.setPrivateProp(6)
564 Call ok(obj.getPrivateProp = 6, "obj.getPrivateProp = " & obj.getPrivateProp)
565
566 Dim funcCalled
567 funcCalled = ""
568 Call ok(obj.gsProp = 6, "obj.gsProp = " & obj.gsProp)
569 Call ok(funcCalled = "gsProp get", "funcCalled = " & funcCalled)
570 obj.gsProp = 3
571 Call ok(funcCalled = "gsProp let", "funcCalled = " & funcCalled)
572 Call ok(obj.getPrivateProp = 3, "obj.getPrivateProp = " & obj.getPrivateProp)
573 Set obj.gsProp = New testclass
574 Call ok(funcCalled = "gsProp set", "funcCalled = " & funcCalled)
575
576 x = obj
577 Call ok(x = 3, "(x = obj) = " & x)
578 Call ok(funcCalled = "GetDefVal", "funcCalled = " & funcCalled)
579 funcCalled = ""
580 Call ok(obj = 3, "(x = obj) = " & obj)
581 Call ok(funcCalled = "GetDefVal", "funcCalled = " & funcCalled)
582
583 Call obj.Class_Initialize
584 Call ok(obj.getPrivateProp() = true, "obj.getPrivateProp() = " & obj.getPrivateProp())
585
586 x = (New testclass).publicProp
587
588 Class TermTest
589     Public Sub Class_Terminate()
590         funcCalled = "terminate"
591     End Sub
592 End Class
593
594 Set obj = New TermTest
595 funcCalled = ""
596 Set obj = Nothing
597 Call ok(funcCalled = "terminate", "funcCalled = " & funcCalled)
598
599 Set obj = New TermTest
600 funcCalled = ""
601 Call obj.Class_Terminate
602 Call ok(funcCalled = "terminate", "funcCalled = " & funcCalled)
603 funcCalled = ""
604 Set obj = Nothing
605 Call ok(funcCalled = "terminate", "funcCalled = " & funcCalled)
606
607 reportSuccess()