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
23 call ok(true, "true is not true?")
24 ok true, "true is not true?"
25 call ok((true), "true is not true?")
27 ok not false, "not false but not true?"
28 ok not not true, "not not true but not true?"
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 Call ok(true = -1, "! true = -1")
45 Call ok(false = 0, "false <> 0")
46 Call ok(&hff = 255, "&hff <> 255")
47 Call ok(&Hff = 255, "&Hff <> 255")
50 Call ok(x = "xx", "x = " & x & " expected ""xx""")
52 Call ok(true <> false, "true <> false is false")
53 Call ok(not (true <> true), "true <> true is true")
54 Call ok(not ("x" <> "x"), """x"" <> ""x"" is true")
55 Call ok(not (empty <> empty), "empty <> empty is true")
56 Call ok(x <> "x", "x = ""x""")
57 Call ok("true" <> true, """true"" = true is true")
59 Call ok("" = true = false, """"" = true = false is false")
60 Call ok(not(false = true = ""), "false = true = """" is true")
61 Call ok(not (false = false <> false = false), "false = false <> false = false is true")
62 Call ok(not ("" <> false = false), """"" <> false = false is true")
64 Call ok(getVT(false) = "VT_BOOL", "getVT(false) is not VT_BOOL")
65 Call ok(getVT(true) = "VT_BOOL", "getVT(true) is not VT_BOOL")
66 Call ok(getVT("") = "VT_BSTR", "getVT("""") is not VT_BSTR")
67 Call ok(getVT("test") = "VT_BSTR", "getVT(""test"") is not VT_BSTR")
68 Call ok(getVT(Empty) = "VT_EMPTY", "getVT(Empty) is not VT_EMPTY")
69 Call ok(getVT(null) = "VT_NULL", "getVT(null) is not VT_NULL")
70 Call ok(getVT(0) = "VT_I2", "getVT(0) is not VT_I2")
71 Call ok(getVT(1) = "VT_I2", "getVT(1) is not VT_I2")
72 Call ok(getVT(0.5) = "VT_R8", "getVT(0.5) is not VT_R8")
73 Call ok(getVT(0.0) = "VT_R8", "getVT(0.0) is not VT_R8")
74 Call ok(getVT(2147483647) = "VT_I4", "getVT(2147483647) is not VT_I4")
75 Call ok(getVT(2147483648) = "VT_R8", "getVT(2147483648) is not VT_R8")
76 Call ok(getVT(&h10&) = "VT_I2", "getVT(&h10&) is not VT_I2")
77 Call ok(getVT(&h10000&) = "VT_I4", "getVT(&h10000&) is not VT_I4")
78 Call ok(getVT(&H10000&) = "VT_I4", "getVT(&H10000&) is not VT_I4")
79 Call ok(getVT(&hffFFffFF&) = "VT_I2", "getVT(&hffFFffFF&) is not VT_I2")
80 Call ok(getVT(1 & 100000) = "VT_BSTR", "getVT(1 & 100000) is not VT_BSTR")
81 Call ok(getVT(-empty) = "VT_I2", "getVT(-empty) = " & getVT(-empty))
82 Call ok(getVT(-null) = "VT_NULL", "getVT(-null) = " & getVT(-null))
83 Call ok(getVT(y) = "VT_EMPTY*", "getVT(y) = " & getVT(y))
84 Call ok(getVT(nothing) = "VT_DISPATCH", "getVT(nothing) = " & getVT(nothing))
86 Call ok(getVT(x) = "VT_DISPATCH*", "getVT(x=nothing) = " & getVT(x))
88 Call ok(getVT(x) = "VT_BOOL*", "getVT(x) = " & getVT(x))
89 Call ok(getVT(false or true) = "VT_BOOL", "getVT(false) is not VT_BOOL")
91 Call ok(getVT(x) = "VT_BSTR*", "getVT(x) is not VT_BSTR*")
93 Call ok(getVT(x) = "VT_R8*", "getVT(x) = " & getVT(x))
95 Call ok(isNullDisp(nothing), "nothing is not nulldisp?")
98 Call ok("ab" & "cd" = "abcd", """ab"" & ""cd"" <> ""abcd""")
99 Call ok("ab " & null = "ab ", """ab"" & null = " & ("ab " & null))
100 Call ok("ab " & empty = "ab ", """ab"" & empty = " & ("ab " & empty))
101 Call ok(1 & 100000 = "1100000", "1 & 100000 = " & (1 & 100000))
102 Call ok("ab" & x = "abxx", """ab"" & x = " & ("ab"&x))
104 if(isEnglishLang) then
105 Call ok("" & true = "True", """"" & true = " & true)
106 Call ok(true & false = "TrueFalse", "true & false = " & (true & false))
109 call ok(true and true, "true and true is not true")
110 call ok(true and not false, "true and not false is not true")
111 call ok(not (false and true), "not (false and true) is not true")
112 call ok(getVT(null and true) = "VT_NULL", "getVT(null and true) = " & getVT(null and true))
114 call ok(false or true, "false or uie is false?")
115 call ok(not (false or false), "false or false is not false?")
116 call ok(false and false or true, "false and false or true is false?")
117 call ok(true or false and false, "true or false and false is false?")
118 call ok(null or true, "null or true is false")
120 call ok(true xor false, "true xor false is false?")
121 call ok(not (false xor false), "false xor false is true?")
122 call ok(not (true or false xor true), "true or false xor true is true?")
123 call ok(not (true xor false or true), "true xor false or true is true?")
125 call ok(false eqv false, "false does not equal false?")
126 call ok(not (false eqv true), "false equals true?")
127 call ok(getVT(false eqv null) = "VT_NULL", "getVT(false eqv null) = " & getVT(false eqv null))
129 call ok(true imp true, "true does not imp true?")
130 call ok(false imp false, "false does not imp false?")
131 call ok(not (true imp false), "true imp false?")
132 call ok(false imp null, "false imp null is false?")
134 Call ok(2 >= 1, "! 2 >= 1")
135 Call ok(2 >= 2, "! 2 >= 2")
136 Call ok(not(true >= 2), "true >= 2 ?")
137 Call ok(2 > 1, "! 2 > 1")
138 Call ok(false > true, "! false < true")
139 Call ok(0 > true, "! 0 > true")
140 Call ok(not (true > 0), "true > 0")
141 Call ok(not (0 > 1 = 1), "0 > 1 = 1")
142 Call ok(1 < 2, "! 1 < 2")
143 Call ok(1 = 1 < 0, "! 1 = 1 < 0")
144 Call ok(1 <= 2, "! 1 <= 2")
145 Call ok(2 <= 2, "! 2 <= 2")
147 Call ok(isNull(0 = null), "'(0 = null)' is not null")
148 Call ok(isNull(null = 1), "'(null = 1)' is not null")
149 Call ok(isNull(0 > null), "'(0 > null)' is not null")
150 Call ok(isNull(null > 1), "'(null > 1)' is not null")
151 Call ok(isNull(0 < null), "'(0 < null)' is not null")
152 Call ok(isNull(null < 1), "'(null < 1)' is not null")
153 Call ok(isNull(0 <> null), "'(0 <> null)' is not null")
154 Call ok(isNull(null <> 1), "'(null <> 1)' is not null")
155 Call ok(isNull(0 >= null), "'(0 >= null)' is not null")
156 Call ok(isNull(null >= 1), "'(null >= 1)' is not null")
157 Call ok(isNull(0 <= null), "'(0 <= null)' is not null")
158 Call ok(isNull(null <= 1), "'(null <= 1)' is not null")
161 Call ok(2+2 = 4, "2+2 = " & (2+2))
162 Call ok(false + 6 + true = 5, "false + 6 + true <> 5")
163 Call ok(getVT(2+null) = "VT_NULL", "getVT(2+null) = " & getVT(2+null))
164 Call ok(2+empty = 2, "2+empty = " & (2+empty))
165 Call ok(x+x = 6, "x+x = " & (x+x))
167 Call ok(5-1 = 4, "5-1 = " & (5-1))
168 Call ok(3+5-true = 9, "3+5-true <> 9")
169 Call ok(getVT(2-null) = "VT_NULL", "getVT(2-null) = " & getVT(2-null))
170 Call ok(2-empty = 2, "2-empty = " & (2-empty))
171 Call ok(2-x = -1, "2-x = " & (2-x))
173 Call ok(9 Mod 6 = 3, "9 Mod 6 = " & (9 Mod 6))
174 Call ok(11.6 Mod 5.5 = False, "11.6 Mod 5.5 = " & (11.6 Mod 5.5 = 0.6))
175 Call ok(7 Mod 4+2 = 5, "7 Mod 4+2 <> 5")
176 Call ok(getVT(2 mod null) = "VT_NULL", "getVT(2 mod null) = " & getVT(2 mod null))
177 Call ok(getVT(null mod 2) = "VT_NULL", "getVT(null mod 2) = " & getVT(null mod 2))
178 'FIXME: Call ok(empty mod 2 = 0, "empty mod 2 = " & (empty mod 2))
180 Call ok(5 \ 2 = 2, "5 \ 2 = " & (5\2))
181 Call ok(4.6 \ 1.5 = 2, "4.6 \ 1.5 = " & (4.6\1.5))
182 Call ok(4.6 \ 1.49 = 5, "4.6 \ 1.49 = " & (4.6\1.49))
183 Call ok(2+3\4 = 2, "2+3\4 = " & (2+3\4))
185 Call ok(2*3 = 6, "2*3 = " & (2*3))
186 Call ok(3/2 = 1.5, "3/2 = " & (3/2))
187 Call ok(5\4/2 = 2, "5\4/2 = " & (5\2/1))
188 Call ok(12/3\2 = 2, "12/3\2 = " & (12/3\2))
190 Call ok(2^3 = 8, "2^3 = " & (2^3))
191 Call ok(2^3^2 = 64, "2^3^2 = " & (2^3^2))
192 Call ok(-3^2 = 9, "-3^2 = " & (-3^2))
193 Call ok(2*3^2 = 18, "2*3^2 = " & (2*3^2))
202 if true then y = true : x = y
205 x = true : if false then x = false
206 ok x, "x is false, if false called?"
208 if not false then x = true
209 ok x, "x is false, if not false not called?"
211 if not false then x = "test" : x = true
212 ok x, "x is false, if not false not called?"
214 if false then x = y : call ok(false, "if false .. : called")
216 if false then x = y : call ok(false, "if false .. : called") else x = "else"
217 Call ok(x = "else", "else not called?")
219 if true then x = y else y = x : Call ok(false, "in else?")
223 if false then x = y : if true then call ok(false, "embedded if called")
225 if false then x=1 else x=2 end if
228 ok false, "if false called"
235 Call ok(not x, "x is false, if not evaluated?")
239 Call ok(false, "inside if false")
243 Call ok(x, "else not called?")
247 Call ok(false, "inside if false")
249 Call ok(false, "inside elseif not true")
253 Call ok(x, "else not called?")
257 Call ok(false, "inside if false")
260 ElseIf not False Then
263 Call ok(false, "inside else not true")
265 Call ok(x, "elseif not called?")
269 Call ok(false, "inside if false")
270 ElseIf not False Then
273 Call ok(x, "elseif not called?")
277 Call ok(x, "if 1 not run?")
280 if &h10000& then x = true
281 Call ok(x, "if &h10000& not run?")
291 call ok((x and y), "x or y is false after while")
298 do while not (x and y)
304 call ok((x and y), "x or y is false after while")
311 ok false, "exit do didn't work"
322 call ok((x and y), "x or y is false after do until")
329 ok false, "exit do didn't work"
340 call ok((x and y), "x or y is false after while")
347 ok false, "exit do didn't work"
357 loop while not (x and y)
358 call ok((x and y), "x or y is false after while")
365 ok false, "exit do didn't work"
372 Call ok(y = "for1: 5 6 7 8", "y = " & y)
375 for x = 5 to 8 step 2
378 Call ok(y = "for2: 5 7", "y = " & y)
385 Call ok(y = "for3: 5 6 7 8", "y = " & y)
391 Call ok(y = "for4:", "y = " & y)
394 for x = 5 to 3 step true
397 Call ok(y = "for5: 5 4 3", "y = " & y)
401 for x = 5 to z step 3-4
405 Call ok(y = "for6: 5 4", "y = " & y)
409 for x = 5 to 8 step z
413 Call ok(y = "for7: 5 6 7 8", "y = " & y)
420 Call ok(y = "for8: 5 7", "y = " & y)
423 Call ok(false, "for..to called when unexpected")
428 Call ok(false, "exit for not escaped the loop?")
437 if null then call ok(false, "if null evaluated")
440 call ok(false, "while null evaluated")
443 Call collectionObj.reset()
446 for each x in collectionObj
448 Call ok(x = y, "x <> y")
450 Call ok(y = 3, "y = " & y)
451 Call ok(getVT(x) = "VT_EMPTY*", "getVT(x) = " & getVT(x))
453 Call collectionObj.reset()
455 for each x in collectionObj
456 if x = 2 then exit for
459 Call ok(y = 1, "y = " & y)
460 Call ok(x = 2, "x = " & x)
465 Call ok(false, "unexpected case")
467 Call ok(false, "unexpected case")
469 Call ok(false, "unexpected case")
472 Call ok(false, "unexpected case")
473 case 0, false, 2+1, 10
475 case ok(false, "unexpected case")
476 Call ok(false, "unexpected case")
478 Call ok(false, "unexpected case")
480 Call ok(x, "wrong case")
487 Call ok(x, "wrong case")
492 Call ok(false, "unexpected case")
496 Call ok(x, "wrong case")
504 Call ok(false, "unexpected case")
506 Call ok(x, "wrong case")
510 Call ok(false, "unexpected case")
512 Call ok(false, "unexpected case")
526 Call ok(x, "x is false, testsub not called?")
529 Call ok(not v, "v is not true")
535 Call ok(x, "x was not set by SubSetTrue")
538 Call ok(not false, "false is no longer false?")
540 Sub SubSetTrue2(ByRef v)
541 Call ok(not v, "v is not true")
547 Call ok(x, "x was not set by SubSetTrue")
549 Sub TestSubArgVal(ByVal v)
550 Call ok(not v, "v is not false")
552 Call ok(v, "v is not true?")
556 Call TestSubArgVal(x)
557 Call ok(not x, "x is true after TestSubArgVal call?")
559 Sub TestSubMultiArgs(a,b,c,d,e)
560 Call ok(a=1, "a = " & a)
561 Call ok(b=2, "b = " & b)
562 Call ok(c=3, "c = " & c)
563 Call ok(d=4, "d = " & d)
564 Call ok(e=5, "e = " & e)
567 Sub TestSubExit(ByRef a)
571 Call ok(false, "Exit Sub not called?")
574 Call TestSubExit(true)
583 TestSubMultiArgs 1, 2, 3, 4, 5
584 Call TestSubMultiArgs(1, 2, 3, 4, 5)
588 Call ok(not x, "local x is not false?")
596 Call ok(x, "global x is not true?")
598 Public Sub TestPublicSub
602 Private Sub TestPrivateSub
614 Call ok(x, "x is false, testfunc not called?")
616 Function FuncSetTrue(v)
617 Call ok(not v, "v is not true")
623 Call ok(x, "x was not set by FuncSetTrue")
626 Call ok(not false, "false is no longer false?")
628 Function FuncSetTrue2(ByRef v)
629 Call ok(not v, "v is not true")
635 Call ok(x, "x was not set by FuncSetTrue")
637 Function TestFuncArgVal(ByVal v)
638 Call ok(not v, "v is not false")
640 Call ok(v, "v is not true?")
644 Call TestFuncArgVal(x)
645 Call ok(not x, "x is true after TestFuncArgVal call?")
647 Function TestFuncMultiArgs(a,b,c,d,e)
648 Call ok(a=1, "a = " & a)
649 Call ok(b=2, "b = " & b)
650 Call ok(c=3, "c = " & c)
651 Call ok(d=4, "d = " & d)
652 Call ok(e=5, "e = " & e)
655 TestFuncMultiArgs 1, 2, 3, 4, 5
656 Call TestFuncMultiArgs(1, 2, 3, 4, 5)
658 Function TestFuncLocalVal
660 Call ok(not x, "local x is not false?")
666 Call TestFuncLocalVal
667 Call ok(x, "global x is not true?")
669 Function TestFuncExit(ByRef a)
673 Call ok(false, "Exit Function not called?")
676 Call TestFuncExit(true)
678 Function TestFuncExit2(ByRef a)
684 Call ok(false, "Exit Function not called?")
687 Call TestFuncExit2(true)
693 Function FuncParseTest
694 End Function : x = false
701 Call ok(ReturnTrue(), "ReturnTrue returned false?")
703 Function SetVal(ByRef x, ByVal v)
710 ok SetVal(x, true), "SetVal returned false?"
711 Call ok(x, "x is not set to true by SetVal?")
713 Public Function TestPublicFunc
717 Private Function TestPrivateFunc
721 ' Stop has an effect only in debugging mode
725 Call ok(getVT(x) = "VT_DISPATCH*", "getVT(x=testObj) = " & getVT(x))
728 Set obj = New EmptyClass
729 Call ok(getVT(obj) = "VT_DISPATCH*", "getVT(obj) = " & getVT(obj))
735 Call ok(getVT(x) = "VT_DISPATCH*", "getVT(x) = " & getVT(x))
742 Public Function publicFunction()
747 Public Property Get gsProp()
749 funcCalled = "gsProp get"
751 Call ok(false, "exit property not returned?")
754 Public Default Property Get DefValGet
755 DefValGet = privateProp
756 funcCalled = "GetDefVal"
759 Public Property Let DefValGet(x)
767 Public Property Let gsProp(val)
769 funcCalled = "gsProp let"
771 Call ok(false, "exit property not returned?")
774 Public Property Set gsProp(val)
775 funcCalled = "gsProp set"
777 Call ok(false, "exit property not returned?")
780 Public Sub setPrivateProp(x)
784 Function getPrivateProp
785 getPrivateProp = privateProp
788 Private Sub privateSub
791 Public Sub Class_Initialize
797 Call testDisp(new testClass)
799 Set obj = New TestClass
801 Call ok(obj.publicFunction = 4, "obj.publicFunction = " & obj.publicFunction)
802 Call ok(obj.publicFunction() = 4, "obj.publicFunction() = " & obj.publicFunction())
806 Call obj.publicFunction()
808 Call ok(getVT(obj.publicProp) = "VT_EMPTY", "getVT(obj.publicProp) = " & getVT(obj.publicProp))
810 Call ok(obj.publicProp = 3, "obj.publicProp = " & obj.publicProp)
813 Call ok(obj.getPrivateProp() = true, "obj.getPrivateProp() = " & obj.getPrivateProp())
814 Call obj.setPrivateProp(6)
815 Call ok(obj.getPrivateProp = 6, "obj.getPrivateProp = " & obj.getPrivateProp)
819 Call ok(obj.gsProp = 6, "obj.gsProp = " & obj.gsProp)
820 Call ok(funcCalled = "gsProp get", "funcCalled = " & funcCalled)
822 Call ok(funcCalled = "gsProp let", "funcCalled = " & funcCalled)
823 Call ok(obj.getPrivateProp = 3, "obj.getPrivateProp = " & obj.getPrivateProp)
824 Set obj.gsProp = New testclass
825 Call ok(funcCalled = "gsProp set", "funcCalled = " & funcCalled)
828 Call ok(x = 3, "(x = obj) = " & x)
829 Call ok(funcCalled = "GetDefVal", "funcCalled = " & funcCalled)
831 Call ok(obj = 3, "(x = obj) = " & obj)
832 Call ok(funcCalled = "GetDefVal", "funcCalled = " & funcCalled)
834 Call obj.Class_Initialize
835 Call ok(obj.getPrivateProp() = true, "obj.getPrivateProp() = " & obj.getPrivateProp())
837 x = (New testclass).publicProp
840 Public Sub Class_Terminate()
841 funcCalled = "terminate"
845 Set obj = New TermTest
848 Call ok(funcCalled = "terminate", "funcCalled = " & funcCalled)
850 Set obj = New TermTest
852 Call obj.Class_Terminate
853 Call ok(funcCalled = "terminate", "funcCalled = " & funcCalled)
856 Call ok(funcCalled = "terminate", "funcCalled = " & funcCalled)
858 Call (New testclass).publicSub()
859 Call (New testclass).publicSub
861 x = "following ':' is correct syntax" :
862 x = "following ':' is correct syntax" :: :
863 :: x = "also correct syntax"
864 rem another ugly way for comments
865 x = "rem as simplestatement" : rem rem comment
868 Set obj = new EmptyClass
870 Set y = new EmptyClass
872 Call ok(obj is x, "obj is not x")
873 Call ok(x is obj, "x is not obj")
874 Call ok(not (obj is y), "obj is not y")
875 Call ok(not obj is y, "obj is not y")
876 Call ok(not (x is Nothing), "x is 1")
877 Call ok(Nothing is Nothing, "Nothing is not Nothing")
878 Call ok(x is obj and true, "x is obj and true is false")
881 Public Sub Test(MyMe)
882 Call ok(Me is MyMe, "Me is not MyMe")
889 Call ok(getVT(test) = "VT_DISPATCH", "getVT(test) = " & getVT(test))
890 Call ok(Me is Test, "Me is not Test")
893 Call ok(c1 = 1, "c1 = " & c1)
894 Call ok(getVT(c1) = "VT_I2", "getVT(c1) = " & getVT(c1))
896 if false then Const conststr = "str"
897 Call ok(conststr = "str", "conststr = " & conststr)
898 Call ok(getVT(conststr) = "VT_BSTR", "getVT(conststr) = " & getVT(conststr))
899 Call ok(conststr = "str", "conststr = " & conststr)
903 Call ok(c1 = 1, "c1 = " & c1)
904 Call ok(funcconst = 1, "funcconst = " & funcconst)
910 ' Property may be used as an identifier (although it's a keyword)
914 Call ok(property, "property = " & property)
916 for property = 1 to 2
923 Public Sub Property()
926 Sub Test(byref property)
938 Sub Test2(byval property)