1' Copyright 2011 Jacek Caban for CodeWeavers
2'
3' This library is free software; you can redistribute it and/or
4' modify it under the terms of the GNU Lesser General Public
5' License as published by the Free Software Foundation; either
6' version 2.1 of the License, or (at your option) any later version.
7'
8' This library is distributed in the hope that it will be useful,
9' but WITHOUT ANY WARRANTY; without even the implied warranty of
10' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11' Lesser General Public License for more details.
12'
13' You should have received a copy of the GNU Lesser General Public
14' License along with this library; if not, write to the Free Software
15' Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
16'
17
18Option Explicit
19
20Dim x
21
22Class EmptyClass
23End Class
24
25Call ok(vbSunday = 1, "vbSunday = " & vbSunday)
26Call ok(getVT(vbSunday) = "VT_I2", "getVT(vbSunday) = " & getVT(vbSunday))
27Call ok(vbMonday = 2, "vbMonday = " & vbMonday)
28Call ok(getVT(vbMonday) = "VT_I2", "getVT(vbMonday) = " & getVT(vbMonday))
29Call ok(vbTuesday = 3, "vbTuesday = " & vbTuesday)
30Call ok(getVT(vbTuesday) = "VT_I2", "getVT(vbTuesday) = " & getVT(vbTuesday))
31Call ok(vbWednesday = 4, "vbWednesday = " & vbWednesday)
32Call ok(getVT(vbWednesday) = "VT_I2", "getVT(vbWednesday) = " & getVT(vbWednesday))
33Call ok(vbThursday = 5, "vbThursday = " & vbThursday)
34Call ok(getVT(vbThursday) = "VT_I2", "getVT(vbThursday) = " & getVT(vbThursday))
35Call ok(vbFriday = 6, "vbFriday = " & vbFriday)
36Call ok(getVT(vbFriday) = "VT_I2", "getVT(vbFriday) = " & getVT(vbFriday))
37Call ok(vbSaturday = 7, "vbSaturday = " & vbSaturday)
38Call ok(getVT(vbSaturday) = "VT_I2", "getVT(vbSaturday) = " & getVT(vbSaturday))
39
40Sub TestConstant(name, val, exval)
41    Call ok(val = exval, name & " =  " & val & " expected " & exval)
42    Call ok(getVT(val) = "VT_I2*", "getVT(" & name & ") = " & getVT(val))
43End Sub
44
45Sub TestConstantI4(name, val, exval)
46    Call ok(val = exval, name & " =  " & val & " expected " & exval)
47    Call ok(getVT(val) = "VT_I4*", "getVT(" & name & ") = " & getVT(val))
48End Sub
49
50Sub TestConstantBSTR(name, val, exval)
51    Call ok(val = exval, name & " =  " & val & " expected " & exval)
52    Call ok(getVT(val) = "VT_BSTR*", "getVT(" & name & ") = " & getVT(val))
53End Sub
54
55TestConstant "vbEmpty", vbEmpty, 0
56TestConstant "vbNull", vbNull, 1
57TestConstant "vbLong", vbLong, 3
58TestConstant "vbSingle", vbSingle, 4
59TestConstant "vbDouble", vbDouble, 5
60TestConstant "vbCurrency", vbCurrency, 6
61TestConstant "vbDate", vbDate, 7
62TestConstant "vbString", vbString, 8
63TestConstant "vbObject", vbObject, 9
64TestConstant "vbError", vbError, 10
65TestConstant "vbBoolean", vbBoolean, 11
66TestConstant "vbVariant", vbVariant, 12
67TestConstant "vbDataObject", vbDataObject, 13
68TestConstant "vbDecimal", vbDecimal, 14
69TestConstant "vbByte", vbByte, 17
70TestConstant "vbArray", vbArray, 8192
71TestConstant "vbCritical", vbCritical, 16
72TestConstant "vbQuestion", vbQuestion, 32
73TestConstant "vbExclamation", vbExclamation, 48
74TestConstant "vbInformation", vbInformation, 64
75TestConstant "vbDefaultButton1", vbDefaultButton1, 0
76TestConstant "vbDefaultButton2", vbDefaultButton2, 256
77TestConstant "vbDefaultButton3", vbDefaultButton3, 512
78TestConstant "vbDefaultButton4", vbDefaultButton4, 768
79TestConstant "vbApplicationModal", vbApplicationModal, 0
80TestConstant "vbSystemModal", vbSystemModal, 4096
81TestConstant "vbUseSystem", vbUseSystem, 0
82TestConstant "vbUseSystemDayOfWeek", vbUseSystemDayOfWeek, 0
83TestConstant "vbFirstJan1", vbFirstJan1, 1
84TestConstant "vbFirstFourDays", vbFirstFourDays, 2
85TestConstant "vbFirstFullWeek", vbFirstFullWeek, 3
86TestConstant "vbTrue", vbTrue, -1
87TestConstant "vbFalse", vbFalse, 0
88TestConstantI4 "vbMsgBoxHelpButton", vbMsgBoxHelpButton, 16384
89TestConstantI4 "vbMsgBoxSetForeground", vbMsgBoxSetForeground, 65536
90TestConstantI4 "vbMsgBoxRight", vbMsgBoxRight, 524288
91TestConstantI4 "vbMsgBoxRtlReading", vbMsgBoxRtlReading, 1048576
92TestConstant "vbUseDefault", vbUseDefault, -2
93TestConstant "vbBinaryCompare", vbBinaryCompare, 0
94TestConstant "vbTextCompare", vbTextCompare, 1
95TestConstant "vbDatabaseCompare", vbDatabaseCompare, 2
96TestConstant "vbGeneralDate", vbGeneralDate, 0
97TestConstant "vbLongDate", vbLongDate, 1
98TestConstant "vbShortDate", vbShortDate, 2
99TestConstant "vbLongTime", vbLongTime, 3
100TestConstant "vbShortTime", vbShortTime, 4
101TestConstantI4 "vbObjectError", vbObjectError, &h80040000&
102TestConstantI4 "vbBlack", vbBlack, 0
103TestConstantI4 "vbBlue", vbBlue, &hff0000&
104TestConstantI4 "vbCyan", vbCyan, &hffff00&
105TestConstantI4 "vbGreen", vbGreen, &h00ff00&
106TestConstantI4 "vbMagenta", vbMagenta, &hff00ff&
107TestConstantI4 "vbRed", vbRed, &h0000ff&
108TestConstantI4 "vbWhite", vbWhite, &hffffff&
109TestConstantI4 "vbYellow", vbYellow, &h00ffff&
110TestConstantBSTR "vbCr", vbCr, Chr(13)
111TestConstantBSTR "vbCrLf", vbCrLf, Chr(13)&Chr(10)
112TestConstantBSTR "vbNewLine", vbNewLine, Chr(13)&Chr(10)
113TestConstantBSTR "vbFormFeed", vbFormFeed, Chr(12)
114TestConstantBSTR "vbLf", vbLf, Chr(10)
115TestConstantBSTR "vbNullChar", vbNullChar, Chr(0)
116TestConstantBSTR "vbNullString", vbNullString, ""
117TestConstantBSTR "vbTab", vbTab, chr(9)
118TestConstantBSTR "vbVerticalTab", vbVerticalTab, chr(11)
119
120Sub TestCStr(arg, exval)
121    dim x
122    x = CStr(arg)
123    Call ok(getVT(x) = "VT_BSTR*", "getVT(x) = " & getVT(x))
124    Call ok(x = exval, "CStr(" & arg & ") = " & x)
125End Sub
126
127TestCStr "test", "test"
128TestCStr 3, "3"
129if isEnglishLang then TestCStr 3.5, "3.5"
130if isEnglishLang then TestCStr true, "True"
131
132sub testCStrError()
133    on error resume next
134    Error.clear()
135    CStr(null)
136    call ok(Err.number = 94, "Err.number = " & Err.number)
137    if isEnglishLang then call ok(Err.source = "Microsoft VBScript runtime error", "Err.source = " & Err.source)
138    if isEnglishLang then call ok(Err.description = "Invalid use of Null", "Err.description = " & Err.description)
139end sub
140call testCStrError()
141
142Call ok(getVT(Chr(120)) = "VT_BSTR", "getVT(Chr(120)) = " & getVT(Chr(120)))
143Call ok(getVT(Chr(255)) = "VT_BSTR", "getVT(Chr(255)) = " & getVT(Chr(255)))
144Call ok(Chr(120) = "x", "Chr(120) = " & Chr(120))
145Call ok(Chr(0) <> "", "Chr(0) = """"")
146Call ok(Chr(120.5) = "x", "Chr(120.5) = " & Chr(120.5))
147Call ok(Chr(119.5) = "x", "Chr(119.5) = " & Chr(119.5))
148Call ok(Chr("120") = "x", "Chr(""120"") = " & Chr("120"))
149
150sub testChrError
151    on error resume next
152
153    if isEnglishLang then
154        call Err.clear()
155        call Chr(-1)
156        call ok(Err.number = 5, "Err.number = " & Err.number)
157        if isEnglishLang then call ok(Err.description = "Invalid procedure call or argument", "Err.description = " & Err.description)
158
159        call Err.clear()
160        call Chr(256)
161        call ok(Err.number = 5, "Err.number = " & Err.number)
162    end if
163
164    call Err.clear()
165    call Chr(65536)
166    call ok(Err.number = 5, "Err.number = " & Err.number)
167
168    call Err.clear()
169    call Chr(-32769)
170    call ok(Err.number = 5, "Err.number = " & Err.number)
171end sub
172
173call testChrError
174
175Call ok(isObject(new EmptyClass), "isObject(new EmptyClass) is not true?")
176Set x = new EmptyClass
177Call ok(isObject(x), "isObject(x) is not true?")
178Call ok(isObject(Nothing), "isObject(Nothing) is not true?")
179Call ok(not isObject(true), "isObject(true) is true?")
180Call ok(not isObject(4), "isObject(4) is true?")
181Call ok(not isObject("x"), "isObject(""x"") is true?")
182Call ok(not isObject(Null), "isObject(Null) is true?")
183
184Call ok(not isEmpty(new EmptyClass), "isEmpty(new EmptyClass) is true?")
185Set x = new EmptyClass
186Call ok(not isEmpty(x), "isEmpty(x) is true?")
187x = empty
188Call ok(isEmpty(x), "isEmpty(x) is not true?")
189Call ok(isEmpty(empty), "isEmpty(empty) is not true?")
190Call ok(not isEmpty(Nothing), "isEmpty(Nothing) is not true?")
191Call ok(not isEmpty(true), "isEmpty(true) is true?")
192Call ok(not isEmpty(4), "isEmpty(4) is true?")
193Call ok(not isEmpty("x"), "isEmpty(""x"") is true?")
194Call ok(not isEmpty(Null), "isEmpty(Null) is true?")
195
196Call ok(not isNull(new EmptyClass), "isNull(new EmptyClass) is true?")
197Set x = new EmptyClass
198Call ok(not isNull(x), "isNull(x) is true?")
199x = null
200Call ok(isNull(x), "isNull(x) is not true?")
201Call ok(not isNull(empty), "isNull(empty) is true?")
202Call ok(not isNull(Nothing), "isNull(Nothing) is true?")
203Call ok(not isNull(true), "isNull(true) is true?")
204Call ok(not isNull(4), "isNull(4) is true?")
205Call ok(not isNull("x"), "isNull(""x"") is true?")
206Call ok(isNull(Null), "isNull(Null) is not true?")
207
208Call ok(isNumeric(Empty), "isNumeric(empty) is not true?")
209Call ok(not isNumeric(Null), "isNumeric(Null) is not true?")
210Call ok(isNumeric(32767), "isNumeric(32767) is true?")
211Call ok(isNumeric(32768), "isNumeric(32768) is true?")
212Call ok(isNumeric(CSng(3242.4)), "isNumeric(CSng(3242.4)) is true?")
213Call ok(isNumeric(32768.4), "isNumeric(32768.4) is true?")
214Call ok(isNumeric(CCur(32768.4)), "isNumeric(CCur(32768.4)) is true?")
215Call ok(isNumeric("44"), "isNumeric(""44"") is true?")
216Call ok(not isNumeric("rwrf"), "isNumeric(""rwrf"") is not true?")
217Call ok(not isNumeric(Nothing), "isNumeric(Nothing) is not true?")
218Call ok(not isNumeric(New EmptyClass), "isNumeric(New EmptyClass) is not true?")
219Call ok(isNumeric(true), "isNumeric(true) is true?")
220Call ok(isNumeric(CByte(32)), "isNumeric(CByte(32)) is true?")
221Dim arr(2)
222arr(0) = 2
223arr(1) = 3
224Call ok(not isNumeric(arr), "isNumeric(arr) is not true?")
225
226Call ok(getVT(Array()) = "VT_ARRAY|VT_VARIANT", "getVT(Array()) = " & getVT(Array()))
227x = Array("a1", 2, "a3")
228Call ok(getVT(x) = "VT_ARRAY|VT_VARIANT*", "getVT(array) = " & getVT(x))
229Call ok(getVT(x(0)) = "VT_BSTR*", "getVT(array(0)) = " & getVT(x(0)))
230Call ok(x(0) = "a1", "array(0) = " & x(0))
231Call ok(getVT(x(1)) = "VT_I2*", "getVT(array(1)) = " & getVT(x(1)))
232Call ok(x(1) = 2, "array(1) = " & x(1))
233Call ok(getVT(x(2)) = "VT_BSTR*", "getVT(array(2)) = " & getVT(x(2)))
234Call ok(x(2) = "a3", "array(2) = " & x(2))
235
236Dim new_array
237new_array = x
238x(0) = "new value"
239Call ok(new_array(0) = "a1", "new_array(0) = " & new_array(0))
240
241Call ok(getVT(UBound(x)) = "VT_I4", "getVT(UBound(x)) = " & getVT(UBound(x)))
242Call ok(UBound(x) = 2, "UBound(x) = " & UBound(x))
243Call ok(getVT(UBound(x, 1)) = "VT_I4", "getVT(UBound(x, 1)) = " & getVT(UBound(x, 1)))
244Call ok(UBound(x, 1) = 2, "UBound(x) = " & UBound(x, 1))
245
246Dim arr2(2, 4)
247Call ok(UBound(arr2) = 2, "UBound(x) = " & UBound(x))
248Call ok(UBound(arr2, 1) = 2, "UBound(x) = " & UBound(x))
249Call ok(UBound(arr2, 2) = 4, "UBound(x) = " & UBound(x))
250
251sub testUBoundError()
252    on error resume next
253    call Err.clear()
254    call UBound()
255    call ok(Err.number = 450, "Err.number = " & Err.number)
256    call Err.clear()
257    call UBound(arr, 1, 2)
258    call ok(Err.number = 450, "Err.number = " & Err.number)
259    if isEnglishLang then call ok(Err.description = "Wrong number of arguments or invalid property assignment", _
260                                  "Err.description = " & Err.description)
261end sub
262call testUBoundError()
263
264Dim newObject
265Set newObject = New ValClass
266newObject.myval = 1
267Call ok(isNumeric(newObject), "isNumeric(newObject) is true?")
268newObject.myval = "test"
269Call ok(not isNumeric(newObject), "isNumeric(newObject) is not true?")
270
271Call ok(getVT(err) = "VT_DISPATCH", "getVT(err) = " & getVT(err))
272
273Sub TestHex(x, ex)
274    Call ok(hex(x) = ex, "hex(" & x & ") = " & hex(x) & " expected " & ex)
275End Sub
276
277TestHex 0, "0"
278TestHex 6, "6"
279TestHex 16, "10"
280TestHex &hdeadbeef&, "DEADBEEF"
281TestHex -1, "FFFF"
282TestHex -16, "FFF0"
283TestHex -934859845, "C8472BBB"
284TestHex empty, "0"
285TestHex "17", "11"
286TestHex 228.5, "E4"
287TestHex -32767, "8001"
288TestHex -32768, "FFFF8000"
289TestHex 2147483647.49, "7FFFFFFF"
290TestHex -2147483647.5, "80000000"
291newObject.myval = 30.5
292TestHex newObject, "1E"
293newObject.myval = "27"
294TestHex newObject, "1B"
295
296
297Call ok(getVT(hex(null)) = "VT_NULL", "getVT(hex(null)) = " & getVT(hex(null)))
298Call ok(getVT(hex(empty)) = "VT_BSTR", "getVT(hex(empty)) = " & getVT(hex(empty)))
299
300Sub TestHexError(num, err_num)
301    On Error Resume Next
302    Call Hex(num)
303    Call ok(Err.number = err_num, "Hex(" & num & ") returns error number " & Err.number & " expected " & err_num)
304End Sub
305
306TestHexError 2147483647.5, 6
307TestHexError 2147483648.51, 6
308TestHexError "test", 13
309
310Sub TestOct(x, ex, res_type)
311    Call ok(Oct(x) = ex, "Oct(" & x & ") = " & Oct(x) & " expected " & ex)
312    Call ok(getVT(Oct(x)) = res_type, "getVT(Oct(" &x & ")) = " & getVT(Oct(x)) & "expected " & res_type)
313End Sub
314
315Sub TestOctError(num, err_num)
316    On error resume next
317    Call Oct(num)
318    Call ok(Err.number = err_num, "Oct(" & num & ") error number is " & Err.number & " expected " & err_num)
319End Sub
320
321TestOct empty, "0", "VT_BSTR"
322TestOct 0, "0", "VT_BSTR"
323TestOct 9, "11", "VT_BSTR"
324TestOct "9", "11", "VT_BSTR"
325TestOct 8.5, "10", "VT_BSTR"
326TestOct 9.5, "12", "VT_BSTR"
327TestOct -1, "177777", "VT_BSTR"
328TestOct -32767, "100001", "VT_BSTR"
329TestOct -32768, "37777700000", "VT_BSTR"
330TestOct 2147483647.49, "17777777777", "VT_BSTR"
331TestOct -2147483648.5, "20000000000", "VT_BSTR"
332Call ok(getVT(Oct(null)) = "VT_NULL", "getVT(Oct(null)) = " & getVT(Oct(null)))
333newObject.myval = 5
334TestOct newObject, "5", "VT_BSTR"
335
336TestOctError 2147483647.5, 6
337TestOctError -2147483648.51, 6
338TestOctError "test", 13
339
340x = InStr(1, "abcd", "bc")
341Call ok(x = 2, "InStr returned " & x)
342
343x = InStr("abcd", "bc")
344Call ok(x = 2, "InStr returned " & x)
345Call ok(getVT(x) = "VT_I4*", "getVT(InStr) returned " & getVT(x))
346
347x = InStr("abc", "bc")
348Call ok(x = 2, "InStr returned " & x)
349
350x = InStr("abcbc", "bc")
351Call ok(x = 2, "InStr returned " & x)
352
353x = InStr("bcabc", "bc")
354Call ok(x = 1, "InStr returned " & x)
355
356x = InStr(3, "abcd", "bc")
357Call ok(x = 0, "InStr returned " & x)
358
359x = InStr("abcd", "bcx")
360Call ok(x = 0, "InStr returned " & x)
361
362x = InStr(5, "abcd", "bc")
363Call ok(x = 0, "InStr returned " & x)
364
365x = "abcd"
366x = InStr(x, "bc")
367Call ok(x = 2, "InStr returned " & x)
368
369x = InStr("abcd", null)
370Call ok(isNull(x), "InStr returned " & x)
371x = InStr(null, "abcd")
372Call ok(isNull(x), "InStr returned " & x)
373x = InStr(2, null, "abcd")
374Call ok(isNull(x), "InStr returned " & x)
375
376x = InStr(1.3, "abcd", "bc")
377Call ok(x = 2, "InStr returned " & x)
378
379x = InStr(2.3, "abcd", "bc")
380Call ok(x = 2, "InStr returned " & x)
381
382x = InStr(2.6, "abcd", "bc")
383Call ok(x = 0, "InStr returned " & x)
384
385
386x = InStrRev("bcabcd", "bc")
387Call ok(x = 4, "InStrRev returned " & x)
388Call ok(getVT(x) = "VT_I4*", "getVT(InStrRev) returned " & getVT(x))
389
390x = InStrRev("bcabcd", "bc", 6)
391Call ok(x = 4, "InStrRev returned " & x)
392
393x = InStrRev("abcd", "bcx")
394Call ok(x = 0, "InStrRev returned " & x)
395
396x = InStrRev("abcd", "bc", 3)
397Call ok(x = 2, "InStrRev returned " & x)
398
399x = InStrRev("abcd", "bc", 2)
400Call ok(x = 0, "InStrRev returned " & x)
401
402x = InStrRev("abcd", "b", 2)
403Call ok(x = 2, "InStrRev returned " & x)
404
405x = InStrRev("abcd", "bc", 5)
406Call ok(x = 0, "InStrRev returned " & x)
407
408x = InStrRev("abcd", "bc", 15)
409Call ok(x = 0, "InStrRev returned " & x)
410
411x = "abcd"
412x = InStrRev(x, "bc")
413Call ok(x = 2, "InStrRev returned " & x)
414
415x = InStrRev("abcd", "bc", 1.3)
416Call ok(x = 0, "InStrRev returned " & x)
417
418x = InStrRev("abcd", "bc", 2.3)
419Call ok(x = 0, "InStrRev returned " & x)
420
421x = InStrRev("abcd", "bc", 2.6)
422Call ok(x = 2, "InStrRev returned " & x)
423
424x = InStrRev("1234", 34)
425Call ok(x = 3, "InStrRev returned " & x)
426
427x = InStrRev(1234, 34)
428Call ok(x = 3, "InStrRev returned " & x)
429
430Sub testInStrRevError(arg1, arg2, arg3, error_num)
431    on error resume next
432    Dim x
433
434    Call Err.clear()
435    x = InStrRev(arg1, arg2, arg3)
436    Call ok(Err.number = error_num, "Err.number = " & Err.number)
437End Sub
438
439call testInStrRevError("abcd", null, 2, 94)
440call testInStrRevError(null, "abcd", 2, 94)
441call testInStrRevError("abcd", "abcd", null, 94)
442
443Sub TestMid(str, start, len, ex)
444    x = Mid(str, start, len)
445    Call ok(x = ex, "Mid(" & str & ", " & start & ", " & len & ") = " & x & " expected " & ex)
446End Sub
447
448Sub TestMid2(str, start, ex)
449    x = Mid(str, start)
450    Call ok(x = ex, "Mid(" & str & ", " & start & ") = " & x & " expected " & ex)
451End Sub
452
453TestMid "test", 2, 2, "es"
454TestMid "test", 2, 4, "est"
455TestMid "test", 1, 2, "te"
456TestMid "test", 1, 0, ""
457TestMid "test", 1, 0, ""
458TestMid "test", 5, 2, ""
459TestMid2 "test", 1, "test"
460TestMid2 "test", 2, "est"
461TestMid2 "test", 4, "t"
462TestMid2 "test", 5, ""
463
464Sub TestUCase(str, ex)
465    x = UCase(str)
466    Call ok(x = ex, "UCase(" & str & ") = " & x & " expected " & ex)
467End Sub
468
469TestUCase "test", "TEST"
470TestUCase "123aBC?", "123ABC?"
471TestUCase "", ""
472TestUCase 1, "1"
473if isEnglishLang then TestUCase true, "TRUE"
474TestUCase 0.123, doubleAsString(0.123)
475TestUCase Empty, ""
476Call ok(getVT(UCase(Null)) = "VT_NULL", "getVT(UCase(Null)) = " & getVT(UCase(Null)))
477
478Sub TestLCase(str, ex)
479    x = LCase(str)
480    Call ok(x = ex, "LCase(" & str & ") = " & x & " expected " & ex)
481End Sub
482
483TestLCase "test", "test"
484TestLCase "123aBC?", "123abc?"
485TestLCase "", ""
486TestLCase 1, "1"
487if isEnglishLang then TestLCase true, "true"
488TestLCase 0.123, doubleAsString(0.123)
489TestLCase Empty, ""
490Call ok(getVT(LCase(Null)) = "VT_NULL", "getVT(LCase(Null)) = " & getVT(LCase(Null)))
491
492Sub TestStrComp(str_left, str_right, mode, ex)
493    x = StrComp(str_left, str_right, mode)
494    Call ok(x = ex, "StrComp(" & str_left & ", " & str_right & ", " & mode & ") = " & x & " expected " & ex)
495End Sub
496
497TestStrComp "ABC",  "abc",  0, -1
498TestStrComp "abc",  "ABC",  0,  1
499TestStrComp "ABC",  "ABC",  0,  0
500TestStrComp "ABC",  "abc",  0, -1
501TestStrComp "abc",  "ABC",  0,  1
502TestStrComp "ABC",  "ABC",  0,  0
503TestStrComp "ABCD", "ABC",  0,  1
504TestStrComp "ABC",  "ABCD", 0, -1
505TestStrComp "ABC",  "abc",  1,  0
506TestStrComp "ABC",  "ABC",  1,  0
507TestStrComp "ABCD", "ABC",  1,  1
508TestStrComp "ABC",  "ABCD", 1, -1
509TestStrComp "ABC",  "ABCD", "0", -1
510TestStrComp "ABC",  "ABCD", "1", -1
511TestStrComp 1,      1,      1,  0
512TestStrComp "1",    1,      1,  0
513TestStrComp "1",    1.0,    1,  0
514TestStrComp Empty,  Empty,  1,  0
515TestStrComp Empty,  "",     1,  0
516TestStrComp Empty,  "ABC",  1,  -1
517TestStrComp "ABC",  Empty,  1,  1
518TestStrComp vbNull, vbNull, 1,  0
519TestStrComp "",     vbNull, 1,  -1
520
521sub testStrCompError()
522    on error resume next
523    call Err.clear()
524    call StrComp()
525    call ok(Err.number = 450, "Err.number = " & Err.number)
526    call Err.clear()
527    call StrComp("a", "a", 0, 1)
528    call ok(Err.number = 450, "Err.number = " & Err.number)
529end sub
530call testStrCompError()
531
532Call ok(Len("abc") = 3, "Len(abc) = " & Len("abc"))
533Call ok(Len("") = 0, "Len() = " & Len(""))
534Call ok(Len(1) = 1, "Len(1) = " & Len(1))
535Call ok(isNull(Len(null)), "Len(null) = " & Len(null))
536Call ok(Len(empty) = 0, "Len(empty) = " & Len(empty))
537Call ok(getVT(Len("abc")) = "VT_I4", "getVT(Len(abc)) = " & getVT(Len("abc")))
538
539Call ok(Space(1) = " ", "Space(1) = " & Space(1) & """")
540Call ok(Space(0) = "", "Space(0) = " & Space(0) & """")
541Call ok(Space(false) = "", "Space(false) = " & Space(false) & """")
542Call ok(Space(5) = "     ", "Space(5) = " & Space(5) & """")
543Call ok(Space(5.2) = "     ", "Space(5.2) = " & Space(5.2) & """")
544Call ok(Space(5.8) = "      ", "Space(5.8) = " & Space(5.8) & """")
545Call ok(Space(5.5) = "      ", "Space(5.5) = " & Space(5.5) & """")
546Call ok(Space(4.5) = "    ", "Space(4.5) = " & Space(4.5) & """")
547Call ok(Space(0.5) = "", "Space(0.5) = " & Space(0.5) & """")
548Call ok(Space(1.5) = "  ", "Space(1.5) = " & Space(1.5) & """")
549Call ok(Space("1") = " ", "Space(""1"") = " & Space("1") & """")
550
551Sub TestStrReverse(str, ex)
552    Call ok(StrReverse(str) = ex, "StrReverse(" & str & ") = " & StrReverse(str))
553End Sub
554
555TestStrReverse "test", "tset"
556TestStrReverse "", ""
557TestStrReverse 123, "321"
558if isEnglishLang then TestStrReverse true, "eurT"
559
560Sub TestLeft(str, len, ex)
561    Call ok(Left(str, len) = ex, "Left(" & str & ", " & len & ") = " & Left(str, len))
562End Sub
563
564TestLeft "test", 2, "te"
565TestLeft "test", 5, "test"
566TestLeft "test", 0, ""
567TestLeft 123, 2, "12"
568TestLeft "123456", 1.5, "12"
569TestLeft "123456", 2.5, "12"
570TestLeft "test", "2", "te"
571if isEnglishLang then TestLeft true, 2, "Tr"
572
573Sub TestRight(str, len, ex)
574    Call ok(Right(str, len) = ex, "Right(" & str & ", " & len & ") = " & Right(str, len))
575End Sub
576
577TestRight "test", 2, "st"
578TestRight "test", 5, "test"
579TestRight "test", 0, ""
580TestRight 123, 2, "23"
581if isEnglishLang then TestRight true, 2, "ue"
582
583Sub TestTrim(str, exstr)
584    Call ok(Trim(str) = exstr, "Trim(" & str & ") = " & Trim(str))
585End Sub
586
587TestTrim "   test    ", "test"
588TestTrim "test    ", "test"
589TestTrim "   test", "test"
590TestTrim "test", "test"
591TestTrim "", ""
592TestTrim 123, "123"
593if isEnglishLang then TestTrim true, "True"
594
595Sub TestLTrim(str, exstr)
596    Call ok(LTrim(str) = exstr, "LTrim(" & str & ") = " & LTrim(str))
597End Sub
598
599TestLTrim "   test    ", "test    "
600TestLTrim "test    ", "test    "
601TestLTrim "   test", "test"
602TestLTrim "test", "test"
603TestLTrim "", ""
604TestLTrim 123, "123"
605if isEnglishLang then TestLTrim true, "True"
606
607Sub TestRound(val, exval, vt)
608    Call ok(Round(val) = exval, "Round(" & val & ") = " & Round(val))
609    Call ok(getVT(Round(val)) = vt, "getVT(Round(" & val & ")) = " & getVT(Round(val)))
610End Sub
611
612Sub TestRTrim(str, exstr)
613    Call ok(RTrim(str) = exstr, "RTrim(" & str & ") = " & RTrim(str))
614End Sub
615
616TestRTrim "   test    ", "   test"
617TestRTrim "test    ", "test"
618TestRTrim "   test", "   test"
619TestRTrim "test", "test"
620TestRTrim "", ""
621TestRTrim 123, "123"
622if isEnglishLang then TestRTrim true, "True"
623
624TestRound 3, 3, "VT_I2"
625TestRound 3.3, 3, "VT_R8"
626TestRound 3.8, 4, "VT_R8"
627TestRound 3.5, 4, "VT_R8"
628TestRound -3.3, -3, "VT_R8"
629TestRound -3.5, -4, "VT_R8"
630TestRound "2", 2, "VT_R8"
631TestRound true, true, "VT_BOOL"
632TestRound false, false, "VT_BOOL"
633
634if isEnglishLang then
635    Call ok(WeekDayName(1) = "Sunday", "WeekDayName(1) = " & WeekDayName(1))
636    Call ok(WeekDayName(3) = "Tuesday", "WeekDayName(3) = " & WeekDayName(3))
637    Call ok(WeekDayName(7) = "Saturday", "WeekDayName(7) = " & WeekDayName(7))
638    Call ok(WeekDayName(1.1) = "Sunday", "WeekDayName(1.1) = " & WeekDayName(1.1))
639    Call ok(WeekDayName(1, false) = "Sunday", "WeekDayName(1, false) = " & WeekDayName(1, false))
640    Call ok(WeekDayName(1, true) = "Sun", "WeekDayName(1, true) = " & WeekDayName(1, true))
641    Call ok(WeekDayName(1, 10) = "Sun", "WeekDayName(1, 10) = " & WeekDayName(1, 10))
642    Call ok(WeekDayName(1, true, 2) = "Mon", "WeekDayName(1, true, 2) = " & WeekDayName(1, true, 2))
643    Call ok(WeekDayName(1, true, 2.5) = "Mon", "WeekDayName(1, true, 2.5) = " & WeekDayName(1, true, 2.5))
644    Call ok(WeekDayName(1, true, 1.5) = "Mon", "WeekDayName(1, true, 1.5) = " & WeekDayName(1, true, 1.5))
645    Call ok(WeekDayName(1, true, 7) = "Sat", "WeekDayName(1, true, 7) = " & WeekDayName(1, true, 7))
646    Call ok(WeekDayName(1, true, 7.1) = "Sat", "WeekDayName(1, true, 7.1) = " & WeekDayName(1, true, 7.1))
647
648    Call ok(MonthName(1) = "January", "MonthName(1) = " & MonthName(1))
649    Call ok(MonthName(12) = "December", "MonthName(12) = " & MonthName(12))
650    Call ok(MonthName(1, 0) = "January", "MonthName(1, 0) = " & MonthName(1, 0))
651    Call ok(MonthName(12, false) = "December", "MonthName(12, false) = " & MonthName(12, false))
652    Call ok(MonthName(1, 10) = "Jan", "MonthName(1, 10) = " & MonthName(1, 10))
653    Call ok(MonthName(12, true) = "Dec", "MonthName(12, true) = " & MonthName(12, true))
654end if
655
656Call ok(WeekDayName(1, true, 0) = WeekDayName(1, true, firstDayOfWeek), _
657        "WeekDayName(1, true, 0) = " & WeekDayName(1, true, 0))
658
659Call ok(getVT(Now()) = "VT_DATE", "getVT(Now()) = " & getVT(Now()))
660
661Call ok(vbOKOnly = 0, "vbOKOnly = " & vbOKOnly)
662Call ok(getVT(vbOKOnly) = "VT_I2", "getVT(vbOKOnly) = " & getVT(vbOKOnly))
663Call ok(vbOKCancel = 1, "vbOKCancel = " & vbOKCancel)
664Call ok(getVT(vbOKCancel) = "VT_I2", "getVT(vbOKCancel) = " & getVT(vbOKCancel))
665Call ok(vbAbortRetryIgnore = 2, "vbAbortRetryIgnore = " & vbAbortRetryIgnore)
666Call ok(getVT(vbAbortRetryIgnore) = "VT_I2", "getVT(vbAbortRetryIgnore) = " & getVT(vbAbortRetryIgnore))
667Call ok(vbYesNoCancel = 3, "vbYesNoCancel = " & vbYesNoCancel)
668Call ok(getVT(vbYesNoCancel) = "VT_I2", "getVT(vbYesNoCancel) = " & getVT(vbYesNoCancel))
669Call ok(vbYesNo = 4, "vbYesNo = " & vbYesNo)
670Call ok(getVT(vbYesNo) = "VT_I2", "getVT(vbYesNo) = " & getVT(vbYesNo))
671Call ok(vbRetryCancel = 5, "vbRetryCancel = " & vbRetryCancel)
672Call ok(getVT(vbRetryCancel) = "VT_I2", "getVT(vbRetryCancel) = " & getVT(vbRetryCancel))
673
674Call ok(vbOK = 1, "vbOK = " & vbOK)
675Call ok(getVT(vbOK) = "VT_I2", "getVT(vbOK) = " & getVT(vbOK))
676Call ok(vbCancel = 2, "vbCancel = " & vbCancel)
677Call ok(getVT(vbCancel) = "VT_I2", "getVT(vbCancel) = " & getVT(vbCancel))
678Call ok(vbAbort = 3, "vbAbort = " & vbAbort)
679Call ok(getVT(vbAbort) = "VT_I2", "getVT(vbAbort) = " & getVT(vbAbort))
680Call ok(vbRetry = 4, "vbRetry = " & vbRetry)
681Call ok(getVT(vbRetry) = "VT_I2", "getVT(vbRetry) = " & getVT(vbRetry))
682Call ok(vbIgnore = 5, "vbIgnore = " & vbIgnore)
683Call ok(getVT(vbIgnore) = "VT_I2", "getVT(vbIgnore) = " & getVT(vbIgnore))
684Call ok(vbYes = 6, "vbYes = " & vbYes)
685Call ok(getVT(vbYes) = "VT_I2", "getVT(vbYes) = " & getVT(vbYes))
686Call ok(vbNo = 7, "vbNo = " & vbNo)
687Call ok(getVT(vbNo) = "VT_I2", "getVT(vbNo) = " & getVT(vbNo))
688
689Call ok(CInt(-36.75) = -37, "CInt(-36.75) = " & CInt(-36.75))
690Call ok(getVT(CInt(-36.75)) = "VT_I2", "getVT(CInt(-36.75)) = " & getVT(CInt(-36.75)))
691Call ok(CInt(-36.50) = -36, "CInt(-36.50) = " & CInt(-36.50))
692Call ok(getVT(CInt(-36.50)) = "VT_I2", "getVT(CInt(-36.50)) = " & getVT(CInt(-36.50)))
693Call ok(CInt(-36.25) = -36, "CInt(-36.25) = " & CInt(-36.25))
694Call ok(getVT(CInt(-36.25)) = "VT_I2", "getVT(CInt(-36.25)) = " & getVT(CInt(-36.25)))
695Call ok(CInt(-36) = -36, "CInt(-36) = " & CInt(-36))
696Call ok(getVT(CInt(-36)) = "VT_I2", "getVT(CInt(-36)) = " & getVT(CInt(-36)))
697Call ok(CInt(0) = 0, "CInt(0) = " & CInt(0))
698Call ok(getVT(CInt(0)) = "VT_I2", "getVT(CInt(0)) = " & getVT(CInt(0)))
699Call ok(CInt(0.0) = 0, "CInt(0.0) = " & CInt(0))
700Call ok(getVT(CInt(0.0)) = "VT_I2", "getVT(CInt(0.0)) = " & getVT(CInt(0.0)))
701Call ok(CInt(0.5) = 0, "CInt(0.5) = " & CInt(0))
702Call ok(getVT(CInt(0.5)) = "VT_I2", "getVT(CInt(0.5)) = " & getVT(CInt(0.5)))
703Call ok(CInt(36) = 36, "CInt(36) = " & CInt(36))
704Call ok(getVT(CInt(36)) = "VT_I2", "getVT(CInt(36)) = " & getVT(CInt(36)))
705Call ok(CInt(36.25) = 36, "CInt(36.25) = " & CInt(36.25))
706Call ok(getVT(CInt(36.25)) = "VT_I2", "getVT(CInt(36.25)) = " & getVT(CInt(36.25)))
707Call ok(CInt(36.50) = 36, "CInt(36.50) = " & CInt(36.50))
708Call ok(getVT(CInt(36.50)) = "VT_I2", "getVT(CInt(36.50)) = " & getVT(CInt(36.50)))
709Call ok(CInt(36.75) = 37, "CInt(36.75) = " & CInt(36.75))
710Call ok(getVT(CInt(36.75)) = "VT_I2", "getVT(CInt(36.75)) = " & getVT(CInt(36.75)))
711
712
713Call ok(CBool(5) = true, "CBool(5) = " & CBool(5))
714Call ok(getVT(CBool(5)) = "VT_BOOL", "getVT(CBool(5)) = " & getVT(CBool(5)))
715Call ok(CBool(0) = false, "CBool(0) = " & CBool(0))
716Call ok(getVT(CBool(0)) = "VT_BOOL", "getVT(CBool(0)) = " & getVT(CBool(0)))
717Call ok(CBool(-5) = true, "CBool(-5) = " & CBool(-5))
718Call ok(getVT(CBool(-5)) = "VT_BOOL", "getVT(CBool(-5)) = " & getVT(CBool(-5)))
719
720Sub testCBoolError(strings, error_num)
721    on error resume next
722
723    Call Err.clear()
724    Call CBool(strings)
725    Call ok(Err.number = error_num, "Err.number = " & Err.number)
726End Sub
727
728Class ValClass
729    Public myval
730
731    Public default Property Get defprop
732        defprop = myval
733    End Property
734End Class
735
736Dim MyObject
737Set MyObject = New ValClass
738
739Call ok(CBool(Empty) = False, "CBool(Empty) = " & CBool(Empty))
740Call ok(getVT(CBool(Empty)) = "VT_BOOL", "getVT(CBool(Empty)) = " & getVT(CBool(Empty)))
741Call ok(CBool(1) = True, "CBool(1) = " & CBool(1))
742Call ok(getVT(CBool(1)) = "VT_BOOL", "getVT(CBool(1)) = " & getVT(CBool(1)))
743Call ok(CBool(0) = False, "CBool(0) = " & CBool(0))
744Call ok(getVT(CBool(0)) = "VT_BOOL", "getVT(CBool(0)) = " & getVT(CBool(0)))
745Call ok(CBool(-0.56) = True, "CBool(-0.56) = " & CBool(-0.56))
746Call ok(getVT(CBool(-0.56)) = "VT_BOOL", "getVT(CBool(-0.56)) = " & getVT(CBool(-0.56)))
747Call testCBoolError("", 13)
748Call ok(CBool("0") = False, "CBool(""0"") = " & CBool("0"))
749Call ok(getVT(CBool("0")) = "VT_BOOL", "getVT(CBool(""0"")) = " & getVT(CBool("0")))
750If isEnglishLang Then
751    Call ok(CBool("0.1") = True, "CBool(""0.1"") = " & CBool("0.1"))
752    Call ok(getVT(CBool("0.1")) = "VT_BOOL", "getVT(CBool(""0.1"")) = " & getVT(CBool("0.1")))
753End If
754    Call ok(CBool("true") = True, "CBool(""true"") = " & CBool("true"))
755Call ok(getVT(CBool("true")) = "VT_BOOL", "getVT(CBool(""true"")) = " & getVT(CBool("true")))
756Call ok(CBool("false") = False, "CBool(""false"") = " & CBool("false"))
757Call ok(getVT(CBool("false")) = "VT_BOOL", "getVT(CBool(""false"")) = " & getVT(CBool("false")))
758Call ok(CBool("TRUE") = True, "CBool(""TRUE"") = " & CBool("TRUE"))
759Call ok(getVT(CBool("TRUE")) = "VT_BOOL", "getVT(CBool(""TRUE"")) = " & getVT(CBool("TRUE")))
760Call ok(CBool("FALSE") = False, "CBool(""FALSE"") = " & CBool("FALSE"))
761Call ok(getVT(CBool("FALSE")) = "VT_BOOL", "getVT(CBool(""FALSE"")) = " & getVT(CBool("FALSE")))
762Call ok(CBool("#TRUE#") = True, "CBool(""#TRUE#"") = " & CBool("#TRUE#"))
763Call ok(getVT(CBool("#TRUE#")) = "VT_BOOL", "getVT(CBool(""#TRUE#"")) = " & getVT(CBool("#TRUE#")))
764Call ok(CBool("#FALSE#") = False, "CBool(""#FALSE#"") = " & CBool("#FALSE#"))
765Call ok(getVT(CBool("#FALSE#")) = "VT_BOOL", "getVT(CBool(""#FALSE#"")) = " & getVT(CBool("#FALSE#")))
766Call ok(CBool(MyObject) = False, "CBool(MyObject) = " & CBool(MyObject))
767Call ok(getVT(CBool(MyObject)) = "VT_BOOL", "getVT(CBool(MyObject)) = " & getVT(CBool(MyObject)))
768MyObject.myval = 1
769Call ok(CBool(MyObject) = True, "CBool(MyObject) = " & CBool(MyObject))
770Call ok(getVT(CBool(MyObject)) = "VT_BOOL", "getVT(CBool(MyObject)) = " & getVT(CBool(MyObject)))
771MyObject.myval = 0
772Call ok(CBool(MyObject) = False, "CBool(MyObject) = " & CBool(MyObject))
773Call ok(getVT(CBool(MyObject)) = "VT_BOOL", "getVT(CBool(MyObject)) = " & getVT(CBool(MyObject)))
774
775Sub testCByteError(strings, error_num1,error_num2)
776    on error resume next
777    Dim x
778
779    Call Err.clear()
780    x = CByte(strings)
781    Call ok(Err.number = error_num1, "Err.number = " & Err.number)
782
783    Call Err.clear()
784    Call CByte(strings)
785    Call ok(Err.number = error_num2, "Err.number = " & Err.number)
786End Sub
787
788Call ok(CByte(Empty) = 0, "CByte(Empty) = " & CByte(Empty))
789Call ok(getVT(CByte(Empty)) = "VT_UI1", "getVT(CByte(Empty)) = " & getVT(CByte(Empty)))
790Call ok(CByte(255) = 255, "CByte(255) = " & CByte(255))
791Call ok(getVT(CByte(255)) = "VT_UI1", "getVT(CByte(255)) = " & getVT(CByte(255)))
792Call ok(CByte(255.49) = 255, "CByte(255.49) = " & CByte(255.49))
793Call ok(getVT(CByte(255.49)) = "VT_UI1", "getVT(CByte(255.49)) = " & getVT(CByte(255.49)))
794Call testCByteError(1, 0, 458)
795Call testCByteError("", 13, 13)
796Call testCByteError("-1", 6, 6)
797Call testCByteError("258", 6, 6)
798Call testCByteError("TRUE", 13, 13)
799Call testCByteError("FALSE", 13, 13)
800Call testCByteError("#TRue#", 13, 13)
801Call testCByteError("#fAlSE#", 13, 13)
802If isEnglishLang Then
803    Call ok(CByte("-0.5") = 0, "CByte(""-0.5"") = " & CByte("-0.5"))
804    Call ok(getVT(CByte("-0.5")) = "VT_UI1", "getVT(CByte(""-0.5"")) = " & getVT(CByte("-0.5")))
805End If
806Call ok(CByte(True) = 255, "CByte(True) = " & CByte(True))
807Call ok(getVT(CByte(True)) = "VT_UI1", "getVT(CByte(True)) = " & getVT(CByte(True)))
808Call ok(CByte(False) = 0, "CByte(False) = " & CByte(False))
809Call ok(getVT(CByte(False)) = "VT_UI1", "getVT(CByte(False)) = " & getVT(CByte(False)))
810Call ok(CByte(MyObject) = 0, "CByte(MyObject) = " & CByte(MyObject))
811Call ok(getVT(CByte(MyObject)) = "VT_UI1", "getVT(CByte(MyObject)) = " & getVT(CByte(MyObject)))
812MyObject.myval = 1
813Call ok(CByte(MyObject) = 1, "CByte(MyObject) = " & CByte(MyObject))
814Call ok(getVT(CByte(MyObject)) = "VT_UI1", "getVT(CByte(MyObject)) = " & getVT(CByte(MyObject)))
815MyObject.myval = 0
816Call ok(CByte(MyObject) = 0, "CByte(MyObject) = " & CByte(MyObject))
817Call ok(getVT(CByte(MyObject)) = "VT_UI1", "getVT(CByte(MyObject)) = " & getVT(CByte(MyObject)))
818
819Sub testCCurError(strings, error_num1, error_num2)
820    on error resume next
821    Dim x
822
823    Call Err.clear()
824    x = CCur(strings)
825    Call ok(Err.number = error_num1, "Err.number = " & Err.number)
826
827    Call Err.clear()
828    Call CCur(strings)
829    Call ok(Err.number = error_num2, "Err.number = " & Err.number)
830End Sub
831
832Call ok(CCur(Empty) = 0, "CCur(Empty) = " & CCur(Empty))
833Call ok(getVT(CCur(Empty)) = "VT_CY", "getVT(CCur(Empty)) = " & getVT(CCur(Empty)))
834Call ok(CCur(-32768) = -32768, "CCur(-32768) = " & CCur(-32768))
835Call ok(getVT(CCur(-32768)) = "VT_CY", "getVT(CCur(-32768)) = " & getVT(CCur(-32768)))
836Call ok(CCur(32768) = 32768, "CCur(32768) = " & CCur(32768))
837Call ok(getVT(CCur(32768)) = "VT_CY", "getVT(CCur(32768)) = " & getVT(CCur(32768)))
838Call ok(CCur(0.000149) = 0.0001, "CCur(0.000149) = " & CCur(0.000149))
839Call ok(getVT(CCur(0.000149)) = "VT_CY", "getVT(CCur(0.000149)) = " & getVT(CCur(0.000149)))
840Call ok(CCur(2147483647.99) = 2147483647.99, "CCur(2147483647.99) = " & CCur(2147483647.99))
841Call ok(getVT(CCur(2147483647.99)) = "VT_CY", "getVT(CCur(2147483647.99)) = " & getVT(CCur(2147483647.99)))
842Call ok(CCur("-1") = -1, "CCur(""-1"") = " & CCur("-1"))
843Call ok(getVT(CCur("-1")) = "VT_CY", "getVT(CCur(""-1"")) = " & getVT(CCur("-1")))
844If isEnglishLang Then
845    Call ok(CCur("-0.5") = -0.5, "CCur(""-0.5"") = " & CCur("-0.5"))
846    Call ok(getVT(CCur("-0.5")) = "VT_CY", "getVT(CCur(""-0.5"")) = " & getVT(CCur("-0.5")))
847End If
848Call testCCurError("", 13, 13)
849Call testCCurError("-1", 0, 458)
850Call testCCurError("TRUE", 13, 13)
851Call testCCurError("FALSE", 13, 13)
852Call testCCurError("#TRue#", 13, 13)
853Call testCCurError("#fAlSE#", 13, 13)
854Call testCCurError(1, 0, 458)
855Call ok(CCur(True) = -1, "CCur(True) = " & CCur(True))
856Call ok(getVT(CCur(True)) = "VT_CY", "getVT(CCur(True)) = " & getVT(CCur(True)))
857Call ok(CCur(False) = 0, "CCur(False) = " & CCur(False))
858Call ok(getVT(CCur(False)) = "VT_CY", "getVT(CCur(False)) = " & getVT(CCur(False)))
859MyObject.myval = 0.1
860Call ok(CCur(MyObject) = 0.1, "CCur(MyObject) = " & CCur(MyObject))
861Call ok(getVT(CCur(MyObject)) = "VT_CY", "getVT(CCur(MyObject)) = " & getVT(CCur(MyObject)))
862MyObject.myval = 0
863Call ok(CCur(MyObject) = 0, "CCur(MyObject) = " & CCur(MyObject))
864Call ok(getVT(CCur(MyObject)) = "VT_CY", "getVT(CCur(MyObject)) = " & getVT(CCur(MyObject)))
865
866Sub testCDblError(strings, error_num1, error_num2)
867    on error resume next
868    Dim x
869
870    Call Err.clear()
871    x = CDbl(strings)
872    Call ok(Err.number = error_num1, "Err.number = " & Err.number)
873
874    Call Err.clear()
875    Call CDbl(strings)
876    Call ok(Err.number = error_num2, "Err.number = " & Err.number)
877End Sub
878
879Call ok(CDbl(Empty) = 0, "CDbl(Empty) = " & CDbl(Empty))
880Call ok(getVT(CDbl(Empty)) = "VT_R8", "getVT(CDbl(Empty)) = " & getVT(CDbl(Empty)))
881Call ok(CDbl(CByte(0)) = 0, "CDbl(CByte(0)) = " & CDbl(CByte(0)))
882Call ok(getVT(CDbl(CCur(0))) = "VT_R8", "getVT(CDbl(CCur(0))) = " & getVT(CDbl(CCur(0))))
883Call ok(CDbl(CCur(0)) = 0, "CDbl(CCur(0)) = " & CDbl(CCur(0)))
884Call ok(getVT(CDbl(CCur(0))) = "VT_R8", "getVT(CDbl(CCur(0))) = " & getVT(CDbl(CCur(0))))
885Call ok(CDbl(0) = 0, "CDbl(0) = " & CDbl(0))
886Call ok(getVT(CDbl(0)) = "VT_R8", "getVT(CDbl(0)) = " & getVT(CDbl(0)))
887Call ok(CDbl(32768) = 32768, "CDbl(32768) = " & CDbl(32768))
888Call ok(getVT(CDbl(32768)) = "VT_R8", "getVT(CDbl(32768)) = " & getVT(CDbl(32768)))
889Call ok(CDbl(0.001 * 0.001) = 0.000001, "CDbl(0.001 * 0.001) = " & CDbl(0.001 * 0.001))
890Call ok(getVT(CDbl(0.001 * 0.001)) = "VT_R8", "getVT(CDbl(0.001 * 0.001)) = " & getVT(CDbl(0.001 * 0.001)))
891Call ok(CDbl("-1") = -1, "CDbl(""-1"") = " & CDbl("-1"))
892Call ok(getVT(CDbl("-1")) = "VT_R8", "getVT(CDbl(""-1"")) = " & getVT(CDbl("-1")))
893If isEnglishLang Then
894    Call ok(CDbl("-0.5") = -0.5, "CDbl(""-0.5"") = " & CDbl("-0.5"))
895    Call ok(getVT(CDbl("-0.5")) = "VT_R8", "getVT(CDbl(""-0.5"")) = " & getVT(CDbl("-0.5")))
896End If
897Call testCDblError("", 13, 13)
898Call testCDblError("TRUE", 13, 13)
899Call testCDblError("FALSE", 13, 13)
900Call testCDblError("#TRue#", 13, 13)
901Call testCDblError("#fAlSE#", 13, 13)
902Call testCDblError(1, 0, 458)
903Call ok(CDbl(True) = -1, "CDbl(True) = " & CDbl(True))
904Call ok(getVT(CDbl(True)) = "VT_R8", "getVT(CDbl(True)) = " & getVT(CDbl(True)))
905Call ok(CDbl(False) = 0, "CDbl(False) = " & CDbl(False))
906Call ok(getVT(CDbl(False)) = "VT_R8", "getVT(CDbl(False)) = " & getVT(CDbl(False)))
907MyObject.myval = 0.1
908Call ok(CDbl(MyObject) = 0.1, "CDbl(MyObject) = " & CDbl(MyObject))
909Call ok(getVT(CDbl(MyObject)) = "VT_R8", "getVT(CDbl(MyObject)) = " & getVT(CDbl(MyObject)))
910MyObject.myval = 0
911Call ok(CDbl(MyObject) = 0, "CDbl(MyObject) = " & CDbl(MyObject))
912Call ok(getVT(CDbl(MyObject)) = "VT_R8", "getVT(CDbl(MyObject)) = " & getVT(CDbl(MyObject)))
913
914Sub testCLngError(strings, error_num1, error_num2)
915    on error resume next
916    Dim x
917
918    Call Err.clear()
919    x = CLng(strings)
920    Call ok(Err.number = error_num1, "Err.number = " & Err.number)
921
922    Call Err.clear()
923    Call CLng(strings)
924    Call ok(Err.number = error_num2, "Err.number = " & Err.number)
925End Sub
926
927Call ok(CLng(Empty) = 0, "CLng(Empty) = " & CLng(Empty))
928Call ok(getVT(CLng(Empty)) = "VT_I4", "getVT(CLng(Empty)) = " & getVT(CLng(Empty)))
929Call ok(CLng(CByte(0)) = 0, "CLng(CByte(0)) = " & CLng(CByte(0)))
930Call ok(getVT(CLng(CCur(0))) = "VT_I4", "getVT(CLng(CCur(0))) = " & getVT(CLng(CCur(0))))
931Call ok(CLng(CCur(0)) = 0, "CLng(CCur(0)) = " & CLng(CCur(0)))
932Call ok(getVT(CLng(CCur(0))) = "VT_I4", "getVT(CLng(CCur(0))) = " & getVT(CLng(CCur(0))))
933Call ok(CLng(0) = 0, "CLng(0) = " & CLng(0))
934Call ok(getVT(CLng(0)) = "VT_I4", "getVT(CLng(0)) = " & getVT(CLng(0)))
935Call ok(CLng(0.49) = 0, "CLng(0.49) = " & CLng(0.49))
936Call ok(getVT(CLng(0.49)) = "VT_I4", "getVT(CLng(0.49)) = " & getVT(CLng(0.49)))
937Call ok(CLng(0.5) = 0, "CLng(0.5) = " & CLng(0.5))
938Call ok(getVT(CLng(0.5)) = "VT_I4", "getVT(CLng(0.5)) = " & getVT(CLng(0.5)))
939Call ok(CLng(0.51) = 1, "CLng(0.51) = " & CLng(0.51))
940Call ok(getVT(CLng(0.51)) = "VT_I4", "getVT(CLng(0.51)) = " & getVT(CLng(0.51)))
941Call ok(CLng(1.49) = 1, "CLng(1.49) = " & CLng(1.49))
942Call ok(getVT(CLng(1.49)) = "VT_I4", "getVT(CLng(1.49)) = " & getVT(CLng(1.49)))
943Call ok(CLng(1.5) = 2, "CLng(1.5) = " & CLng(1.5))
944Call ok(getVT(CLng(1.5)) = "VT_I4", "getVT(CLng(1.5)) = " & getVT(CLng(1.5)))
945Call ok(CLng(1.51) = 2, "CLng(1.51) = " & CLng(1.51))
946Call ok(getVT(CLng(1.51)) = "VT_I4", "getVT(CLng(1.51)) = " & getVT(CLng(1.51)))
947Call ok(CLng("-1") = -1, "CLng(""-1"") = " & CLng("-1"))
948Call ok(getVT(CLng("-1")) = "VT_I4", "getVT(CLng(""-1"")) = " & getVT(CLng("-1")))
949If isEnglishLang Then
950    Call ok(CLng("-0.5") = 0, "CLng(""-0.5"") = " & CLng("-0.5"))
951    Call ok(getVT(CLng("-0.5")) = "VT_I4", "getVT(CLng(""-0.5"")) = " & getVT(CLng("-0.5")))
952End If
953Call testCLngError("", 13, 13)
954Call testCLngError("TRUE", 13, 13)
955Call testCLngError("FALSE", 13, 13)
956Call testCLngError("#TRue#", 13, 13)
957Call testCLngError("#fAlSE#", 13, 13)
958Call testCLngError(1, 0, 458)
959Call ok(CLng(True) = -1, "CLng(True) = " & CLng(True))
960Call ok(getVT(CLng(True)) = "VT_I4", "getVT(CLng(True)) = " & getVT(CLng(True)))
961Call ok(CLng(False) = 0, "CLng(False) = " & CLng(False))
962Call ok(getVT(CLng(False)) = "VT_I4", "getVT(CLng(False)) = " & getVT(CLng(False)))
963MyObject.myval = 1
964Call ok(CLng(MyObject) = 1, "CLng(MyObject) = " & CLng(MyObject))
965Call ok(getVT(CLng(MyObject)) = "VT_I4", "getVT(CLng(MyObject)) = " & getVT(CLng(MyObject)))
966MyObject.myval = 0
967Call ok(CLng(MyObject) = 0, "CLng(MyObject) = " & CLng(MyObject))
968Call ok(getVT(CLng(MyObject)) = "VT_I4", "getVT(CLng(MyObject)) = " & getVT(CLng(MyObject)))
969
970Sub testCIntError(strings, error_num1, error_num2)
971    on error resume next
972    Dim x
973
974    Call Err.clear()
975    x = CInt(strings)
976    Call ok(Err.number = error_num1, "Err.number = " & Err.number)
977
978    Call Err.clear()
979    Call CInt(strings)
980    Call ok(Err.number = error_num2, "Err.number = " & Err.number)
981End Sub
982
983Call ok(CInt(Empty) = 0, "CInt(Empty) = " & CInt(Empty))
984Call ok(getVT(CInt(Empty)) = "VT_I2", "getVT(CInt(Empty)) = " & getVT(CInt(Empty)))
985Call ok(CInt(CByte(0)) = 0, "CInt(CByte(0)) = " & CInt(CByte(0)))
986Call ok(getVT(CInt(CByte(0))) = "VT_I2", "getVT(CInt(CByte(0))) = " & getVT(CInt(CByte(0))))
987Call ok(CInt(CCur(0)) = 0, "CInt(CCur(0)) = " & CInt(CCur(0)))
988Call ok(getVT(CInt(CCur(0))) = "VT_I2", "getVT(CInt(CCur(0))) = " & getVT(CInt(CCur(0))))
989Call ok(CInt(0.49) = 0, "CInt(0.49) = " & CInt(0.49))
990Call ok(getVT(CInt(0.49)) = "VT_I2", "getVT(CInt(0.49)) = " & getVT(CInt(0.49)))
991Call ok(CInt(0.5) = 0, "CInt(0.5) = " & CInt(0.5))
992Call ok(getVT(CInt(0.5)) = "VT_I2", "getVT(CInt(0.5)) = " & getVT(CInt(0.5)))
993Call ok(CInt(0.51) = 1, "CInt(0.51) = " & CInt(0.51))
994Call ok(getVT(CInt(0.51)) = "VT_I2", "getVT(CInt(0.51)) = " & getVT(CInt(0.51)))
995Call ok(CInt(1.49) = 1, "CInt(0.49) = " & CInt(0.49))
996Call ok(getVT(CInt(0.49)) = "VT_I2", "getVT(CInt(0.49)) = " & getVT(CInt(0.49)))
997Call ok(CInt(1.5) = 2, "CInt(1.5) = " & CInt(1.5))
998Call ok(getVT(CInt(1.5)) = "VT_I2", "getVT(CInt(1.5)) = " & getVT(CInt(1.5)))
999Call ok(CInt(1.51) = 2, "CInt(1.51) = " & CInt(1.51))
1000Call ok(getVT(CInt(1.51)) = "VT_I2", "getVT(CInt(1.51)) = " & getVT(CInt(1.51)))
1001Call ok(CInt("-1") = -1, "CInt(""-1"") = " & CInt("-1"))
1002Call ok(getVT(CInt("-1")) = "VT_I2", "getVT(CInt(""-1"")) = " & getVT(CInt("-1")))
1003If isEnglishLang Then
1004    Call ok(CInt("-0.5") = 0, "CInt(""-0.5"") = " & CInt("-0.5"))
1005    Call ok(getVT(CInt("-0.5")) = "VT_I2", "getVT(CInt(""-0.5"")) = " & getVT(CInt("-0.5")))
1006End If
1007Call testCIntError("", 13, 13)
1008Call testCIntError("-1", 0, 458)
1009Call testCIntError("TRUE", 13, 13)
1010Call testCIntError("FALSE", 13, 13)
1011Call testCIntError("#TRue#", 13, 13)
1012Call testCIntError("#fAlSE#", 13, 13)
1013Call testCIntError(1, 0, 458)
1014Call testCIntError(32767.49, 0, 458)
1015Call testCIntError(32767.5, 6, 6)
1016Call testCIntError(-32768.5, 0, 458)
1017Call testCIntError(-32768.51, 6, 6)
1018Call ok(CInt(True) = -1, "CInt(True) = " & CInt(True))
1019Call ok(getVT(CInt(True)) = "VT_I2", "getVT(CInt(True)) = " & getVT(CInt(True)))
1020Call ok(CInt(False) = 0, "CInt(False) = " & CInt(False))
1021Call ok(getVT(CInt(False)) = "VT_I2", "getVT(CInt(False)) = " & getVT(CInt(False)))
1022MyObject.myval = 2.5
1023Call ok(CInt(MyObject) = 2, "CInt(MyObject) = " & CInt(MyObject))
1024Call ok(getVT(CInt(MyObject)) = "VT_I2", "getVT(CInt(MyObject)) = " & getVT(CInt(MyObject)))
1025MyObject.myval = 1.5
1026Call ok(CInt(MyObject) = 2, "CInt(MyObject) = " & CInt(MyObject))
1027Call ok(getVT(CInt(MyObject)) = "VT_I2", "getVT(CInt(MyObject)) = " & getVT(CInt(MyObject)))
1028
1029Sub testCSngError(strings, error_num1, error_num2)
1030    on error resume next
1031    Dim x
1032
1033    Call Err.clear()
1034    x = CSng(strings)
1035    Call ok(Err.number = error_num1, "Err.number = " & Err.number)
1036
1037    Call Err.clear()
1038    Call CSng(strings)
1039    Call ok(Err.number = error_num2, "Err.number = " & Err.number)
1040End Sub
1041
1042Call ok(CSng(Empty) = 0, "CSng(Empty) = " & CSng(Empty))
1043Call ok(getVT(CSng(Empty)) = "VT_R4", "getVT(CSng(Empty)) = " & getVT(CSng(Empty)))
1044Call ok(CSng(CByte(0)) = 0, "CSng(CByte(0)) = " & CSng(CByte(0)))
1045Call ok(getVT(CSng(CCur(0))) = "VT_R4", "getVT(CSng(CCur(0))) = " & getVT(CSng(CCur(0))))
1046Call ok(CSng(CCur(0)) = 0, "CSng(CCur(0)) = " & CSng(CCur(0)))
1047Call ok(getVT(CSng(CCur(0))) = "VT_R4", "getVT(CSng(CCur(0))) = " & getVT(CSng(CCur(0))))
1048Call ok(CSng(0) = 0, "CSng(0) = " & CSng(0))
1049Call ok(getVT(CSng(0)) = "VT_R4", "getVT(CSng(0)) = " & getVT(CSng(0)))
1050Call ok(CSng(32768) = 32768, "CSng(32768) = " & CSng(32768))
1051Call ok(getVT(CSng(32768)) = "VT_R4", "getVT(CSng(32768)) = " & getVT(CSng(32768)))
1052Call ok(CSng(0.001 * 0.001) = 0.000001, "CSng(0.001 * 0.001) = " & CSng(0.001 * 0.001))
1053Call ok(getVT(CSng(0.001 * 0.001)) = "VT_R4", "getVT(CSng(0.001 * 0.001)) = " & getVT(CSng(0.001 * 0.001)))
1054Call ok(CSng("-1") = -1, "CSng(""-1"") = " & CSng("-1"))
1055Call ok(getVT(CSng("-1")) = "VT_R4", "getVT(CSng(""-1"")) = " & getVT(CSng("-1")))
1056If isEnglishLang Then
1057    Call ok(CSng("-0.5") = -0.5, "CSng(""-0.5"") = " & CSng("-0.5"))
1058    Call ok(getVT(CSng("-0.5")) = "VT_R4", "getVT(CSng(""-0.5"")) = " & getVT(CSng("-0.5")))
1059End If
1060Call testCSngError("", 13, 13)
1061Call testCSngError("TRUE", 13, 13)
1062Call testCSngError("FALSE", 13, 13)
1063Call testCSngError("#TRue#", 13, 13)
1064Call testCSngError("#fAlSE#", 13, 13)
1065Call testCSngError(1, 0, 458)
1066Call ok(CSng(True) = -1, "CSng(True) = " & CSng(True))
1067Call ok(getVT(CSng(True)) = "VT_R4", "getVT(CSng(True)) = " & getVT(CSng(True)))
1068Call ok(CSng(False) = 0, "CSng(False) = " & CSng(False))
1069Call ok(getVT(CSng(False)) = "VT_R4", "getVT(CSng(False)) = " & getVT(CSng(False)))
1070MyObject.myval = 0.1
1071Call ok(CSng(MyObject) = 0.1, "CSng(MyObject) = " & CSng(MyObject))
1072Call ok(getVT(CSng(MyObject)) = "VT_R4", "getVT(CSng(MyObject)) = " & getVT(CSng(MyObject)))
1073MyObject.myval = 0
1074Call ok(CSng(MyObject) = 0, "CSng(MyObject) = " & CSng(MyObject))
1075Call ok(getVT(CSng(MyObject)) = "VT_R4", "getVT(CSng(MyObject)) = " & getVT(CSng(MyObject)))
1076
1077Call ok(TypeName(Empty) = "Empty", "TypeName(MyEmpty) = " & TypeName(Empty))
1078Call ok(getVT(TypeName(Empty)) = "VT_BSTR", "getVT(TypeName(Empty)) = " & getVT(TypeName(Empty)))
1079Call ok(TypeName(Null) = "Null", "TypeName(Null) = " & TypeName(Null))
1080Call ok(getVT(TypeName(Null)) = "VT_BSTR", "getVT(TypeName(Null)) = " & getVT(TypeName(Null)))
1081Call ok(TypeName(CByte(255)) = "Byte", "TypeName(CByte(255)) = " & TypeName(CByte(255)))
1082Call ok(getVT(TypeName(CByte(255))) = "VT_BSTR", "getVT(TypeName(CByte(255))) = " & getVT(TypeName(CByte(255))))
1083Call ok(TypeName(255) = "Integer", "TypeName(255) = " & TypeName(255))
1084Call ok(getVT(TypeName(255)) = "VT_BSTR", "getVT(TypeName(255)) = " & getVT(TypeName(255)))
1085Call ok(TypeName(32768) = "Long", "TypeName(32768) = " & TypeName(32768))
1086Call ok(getVT(TypeName(32768)) = "VT_BSTR", "getVT(TypeName(32768)) = " & getVT(TypeName(32768)))
1087Call ok(TypeName(CSng(0.5)) = "Single", "TypeName(CSng(0.5)) = " & TypeName(CSng(0.5)))
1088Call ok(getVT(TypeName(CSng(0.5))) = "VT_BSTR", "getVT(TypeName(CSng(0.5))) = " & getVT(TypeName(CSng(0.5))))
1089Call ok(TypeName(-0.5) = "Double", "TypeName(-0.5) = " & TypeName(-0.5))
1090Call ok(getVT(TypeName(-0.5)) = "VT_BSTR", "getVT(TypeName(-0.5)) = " & getVT(TypeName(-0.5)))
1091Call ok(TypeName(CCur(0.5)) = "Currency", "TypeName(CCur(0.5)) = " & TypeName(CCur(0.5)))
1092Call ok(getVT(TypeName(CCur(0.5))) = "VT_BSTR", "getVT(TypeName(CCur(0.5))) = " & getVT(TypeName(CCur(0.5))))
1093Call ok(TypeName(CStr(0.5)) = "String", "TypeName(CStr(0.5)) = " & TypeName(CStr(0.5)))
1094Call ok(getVT(TypeName(CStr(0.5))) = "VT_BSTR", "getVT(TypeName(CStr(0.5))) = " & getVT(TypeName(CStr(0.5))))
1095Call ok(TypeName(True) = "Boolean", "TypeName(True) = " & TypeName(True))
1096Call ok(getVT(TypeName(True)) = "VT_BSTR", "getVT(TypeName(True)) = " & getVT(TypeName(True)))
1097
1098Call ok(VarType(Empty) = vbEmpty, "VarType(Empty) = " & VarType(Empty))
1099Call ok(getVT(VarType(Empty)) = "VT_I2", "getVT(VarType(Empty)) = " & getVT(VarType(Empty)))
1100Call ok(VarType(Null) = vbNull, "VarType(Null) = " & VarType(Null))
1101Call ok(getVT(VarType(Null)) = "VT_I2", "getVT(VarType(Null)) = " & getVT(VarType(Null)))
1102Call ok(VarType(255) = vbInteger, "VarType(255) = " & VarType(255))
1103Call ok(getVT(VarType(255)) = "VT_I2", "getVT(VarType(255)) = " & getVT(VarType(255)))
1104set x = new EmptyClass
1105Call ok(VarType(x) = vbObject, "VarType(x) = " & VarType(x))
1106Call ok(getVT(VarType(x)) = "VT_I2", "getVT(VarType(x)) = " & getVT(VarType(x)))
1107Call ok(VarType(32768) = vbLong, "VarType(32768) = " & VarType(32768))
1108Call ok(getVT(VarType(32768)) = "VT_I2", "getVT(VarType(32768)) = " & getVT(VarType(32768)))
1109Call ok(VarType(CSng(0.5)) = vbSingle, "VarType(CSng(0.5)) = " & VarType(CSng(0.5)))
1110Call ok(getVT(VarType(CSng(0.5))) = "VT_I2", "getVT(VarType(CSng(0.5))) = " & getVT(VarType(CSng(0.5))))
1111Call ok(VarType(-0.5) = vbDouble, "VarType(-0.5) = " & VarType(-0.5))
1112Call ok(getVT(VarType(-0.5)) = "VT_I2", "getVT(VarType(-0.5)) = " & getVT(VarType(-0.5)))
1113Call ok(VarType(CCur(0.5)) = vbCurrency, "VarType(CCur(0.5)) = " & VarType(CCur(0.5)))
1114Call ok(getVT(VarType(CCur(0.5))) = "VT_I2", "getVT(VarType(CCur(0.5))) = " & getVT(VarType(CCur(0.5))))
1115Call ok(VarType(CStr(0.5)) = vbString, "VarType(CStr(0.5)) = " & VarType(CStr(0.5)))
1116Call ok(getVT(VarType(CStr(0.5))) = "VT_I2", "getVT(VarType(CStr(0.5))) = " & getVT(VarType(CStr(0.5))))
1117Call ok(VarType(CBool(0.5)) = vbBoolean, "VarType(CBool(0.5)) = " & VarType(CBool(0.5)))
1118Call ok(getVT(VarType(CBool(0.5))) = "VT_I2", "getVT(VarType(CBool(0.5))) = " & getVT(VarType(CBool(0.5))))
1119Call ok(VarType(CByte(255)) = vbByte, "VarType(CByte(255)) = " & VarType(CByte(255)))
1120Call ok(getVT(VarType(CByte(255))) = "VT_I2", "getVT(VarType(CByte(255))) = " & getVT(VarType(CByte(255))))
1121Call ok(VarType(arr) = (vbArray or vbVariant), "VarType(arr) = " & VarType(arr))
1122Call ok(getVT(VarType(arr)) = "VT_I2", "getVT(VarType(arr)) = " & getVT(VarType(arr)))
1123
1124Call ok(Sgn(Empty) = 0, "Sgn(MyEmpty) = " & Sgn(Empty))
1125Call ok(getVT(Sgn(Empty)) = "VT_I2", "getVT(Sgn(MyEmpty)) = " & getVT(Sgn(Empty)))
1126Call ok(Sgn(0) = 0, "Sgn(0) = " & Sgn(0))
1127Call ok(getVT(Sgn(0)) = "VT_I2", "getVT(Sgn(0)) = " & getVT(Sgn(0)))
1128Call ok(Sgn(-32769) = -1, "Sgn(-32769) = " & Sgn(-32769))
1129Call ok(getVT(Sgn(-32769)) = "VT_I2", "getVT(Sgn(-32769)) = " & getVT(Sgn(-32769)))
1130Call ok(Sgn(CSng(-0.5)) = -1, "Sgn(CSng(-0.5)) = " & Sgn(CSng(-0.5)))
1131Call ok(getVT(Sgn(CSng(-0.5))) = "VT_I2", "getVT(Sgn(CSng(-0.5))) = " & getVT(Sgn(CSng(-0.5))))
1132Call ok(Sgn(0.5) = 1, "Sgn(0.5) = " & Sgn(0.5))
1133Call ok(getVT(Sgn(0.5)) = "VT_I2", "getVT(Sgn(0.5)) = " & getVT(Sgn(0.5)))
1134Call ok(Sgn(CCur(-1)) = -1, "Sgn(CCur(-1)) = " & Sgn(CCur(-1)))
1135Call ok(getVT(Sgn(CCur(-1))) = "VT_I2", "getVT(Sgn(CCur(-1))) = " & getVT(Sgn(CCur(-1))))
1136Call ok(Sgn(CStr(-1)) = -1, "Sgn(CStr(-1)) = " & Sgn(CStr(-1)))
1137Call ok(getVT(Sgn(CStr(-1))) = "VT_I2", "getVT(Sgn(CStr(-1))) = " & getVT(Sgn(CStr(-1))))
1138Call ok(Sgn(False) = 0, "Sgn(False) = " & Sgn(False))
1139Call ok(getVT(Sgn(False)) = "VT_I2", "getVT(Sgn(False)) = " & getVT(Sgn(False)))
1140Call ok(Sgn(True) = -1, "Sgn(True) = " & Sgn(True))
1141Call ok(getVT(Sgn(True)) = "VT_I2", "getVT(Sgn(True)) = " & getVT(Sgn(True)))
1142Call ok(Sgn(CByte(1)) = 1, "Sgn(CByte(1)) = " & Sgn(CByte(1)))
1143Call ok(getVT(Sgn(CByte(1))) ="VT_I2", "getVT(Sgn(CByte(1))) = " & getVT(Sgn(CByte(1))))
1144
1145Sub testSgnError(strings, error_num)
1146    on error resume next
1147
1148    Call Err.clear()
1149    Call Sgn(strings)
1150    Call ok(Err.number = error_num, "Err.number = " & Err.number)
1151End Sub
1152
1153Call testSgnError(Null, 94)
1154
1155Call ok(Abs(Empty) = 0, "Abs(Empty) = " & Abs(Empty))
1156Call ok(getVT(Abs(Empty)) = "VT_I2", "getVT(Abs(Empty)) = " & getVT(Abs(Empty)))
1157Call ok(IsNull(Abs(Null)), "Is Abs(Null) not Null?")
1158Call ok(getVT(Abs(Null)) = "VT_NULL", "getVT(Abs(Null)) = " & getVT(Abs(Null)))
1159Call ok(Abs(0) = 0, "Abs(0) = " & Abs(0))
1160Call ok(getVT(Abs(0)) = "VT_I2", "getVT(Abs(0)) = " & getVT(Abs(0)))
1161Call ok(Abs(-32769) = 32769, "Abs(-32769) = " & Abs(-32769))
1162Call ok(getVT(Abs(-32769)) = "VT_I4", "getVT(Abs(-32769)) = " & getVT(Abs(-32769)))
1163Call ok(Abs(CSng(-0.5)) = 0.5, "Abs(CSng(-0.5)) = " & Abs(CSng(-0.5)))
1164Call ok(getVT(Abs(CSng(-0.5))) = "VT_R4", "getVT(Abs(CSng(-0.5))) = " & getVT(Abs(CSng(-0.5))))
1165Call ok(Abs(0.5) = 0.5, "Abs(0.5) = " & Abs(0.5))
1166Call ok(getVT(Abs(0.5)) = "VT_R8", "getVT(Abs(0.5)) = " & getVT(Abs(0.5)))
1167Call ok(Abs(CCur(-1)) = 1, "Abs(CCur(-1)) = " & Abs(CCur(-1)))
1168Call ok(getVT(Abs(CCur(-1))) = "VT_CY", "getVT(Abs(CCur(-1))) = " & getVT(Abs(CCur(-1))))
1169Call ok(Abs("-1") = 1, "Abs(""-1"") = " & Abs("-1"))
1170Call ok(getVT(Abs("-1")) = "VT_R8", "getVT(Abs(""-1"")) = " & getVT(Abs("-1")))
1171Call ok(Abs(False) = 0, "Abs(False) = " & Abs(False))
1172Call ok(getVT(Abs(False)) = "VT_I2", "getVT(Abs(False)) = " & getVT(Abs(False)))
1173Call ok(Abs(True) = 1, "Abs(True) = " & Abs(True))
1174Call ok(getVT(Abs(True)) = "VT_I2", "getVT(Abs(True)) = " & getVT(Abs(True)))
1175Call ok(Abs(CByte(1)) = 1, "Abs(CByte(1)) = " & Abs(CByte(1)))
1176Call ok(getVT(Abs(CByte(1))) = "VT_UI1", "getVT(Abs(CByte(1))) = " & getVT(Abs(CByte(1))))
1177
1178Sub testAbsError(strings, error_num1, error_num2)
1179    on error resume next
1180    Dim x
1181
1182    Call Err.clear()
1183    x = Abs(strings)
1184    Call ok(Err.number = error_num1, "Err.number1 = " & Err.number)
1185
1186    Call Err.clear()
1187    Call Abs(strings)
1188    Call ok(Err.number = error_num2, "Err.number2 = " & Err.number)
1189End Sub
1190
1191Call testAbsError("strings", 13, 13)
1192Call testAbsError(-4, 0, 0)
1193
1194Call ok(ScriptEngine = "VBScript", "Is scriptengine not VBScript?")
1195Call ok(getVT(ScriptEngine) = "VT_BSTR", "getVT(ScriptEngine) = " & getVT(ScriptEngine))
1196
1197Call ok(getVT(ScriptEngineBuildVersion) = "VT_I4", "getVT(ScriptEngineBuildVersion) = " & getVT(ScriptEngineBuildVersion))
1198
1199Call ok(getVT(ScriptEngineMajorVersion) = "VT_I4", "getVT(ScriptEngineMajorVersion) = " & getVT(ScriptEngineMajorVersion))
1200
1201Call ok(getVT(ScriptEngineMinorVersion) = "VT_I4", "getVT(ScriptEngineMinorVersion) = " & getVT(ScriptEngineMinorVersion))
1202
1203Call ok(Fix(Empty) = 0, "Fix(Empty) = " & Fix(Empty))
1204Call ok(getVT(Fix(Empty)) = "VT_I2", "getVT(Fix(Empty)) = " & getVT(Fix(Empty)))
1205Call ok(Fix(CCur(-0.99)) = 0, "Fix(CCur(-0.99)) = " & Fix(CCur(-0.99)))
1206Call ok(getVT(Fix(CCur(-0.99))) = "VT_CY", "getVT(Fix(CCur(-0.99))) = " & getVT(Fix(CCur(-0.99))))
1207Call ok(Fix(1.99) = 1, "Fix(1.99) = " & Fix(1.99))
1208Call ok(getVT(Fix(1.99)) = "VT_R8", "getVT(Fix(1.99)) = " & getVT(Fix(1.99)))
1209Call ok(Fix(-1.99) = -1, "Fix(-1.99) = " & Fix(-1.99))
1210Call ok(getVT(Fix(-1.99)) = "VT_R8", "getVT(Fix(-1.99)) = " & getVT(Fix(-1.99)))
1211If isEnglishLang Then
1212    Call ok(Fix("1.99") = 1, "Fix(""1.99"") = " & Fix("1.99"))
1213    Call ok(getVT(Fix("1.99")) = "VT_R8", "getVT(Fix(""1.99"")) = " & getVT(Fix("1.99")))
1214    Call ok(Fix("-1.99") = -1, "Fix(""-1.99"") = " & Fix("-1.99"))
1215    Call ok(getVT(Fix("-1.99")) = "VT_R8", "getVT(Fix(""-1.99"")) = " & getVT(Fix("-1.99")))
1216End If
1217Call ok(Fix(True) = -1, "Fix(True) = " & Fix(True))
1218Call ok(getVT(Fix(True)) = "VT_I2", "getVT(Fix(True)) = " & getVT(Fix(True)))
1219Call ok(Fix(False) = 0, "Fix(False) = " & Fix(False))
1220Call ok(getVT(Fix(False)) = "VT_I2", "getVT(Fix(False)) = " & getVT(Fix(False)))
1221MyObject.myval = 2.5
1222Call ok(Fix(MyObject) = 2, "Fix(MyObject) = " & Fix(MyObject))
1223Call ok(getVT(Fix(MyObject)) = "VT_R8", "getVT(Fix(MyObject)) = " & getVT(Fix(MyObject)))
1224MyObject.myval = -2.5
1225Call ok(Fix(MyObject) = -2, "Fix(MyObject) = " & Fix(MyObject))
1226Call ok(getVT(Fix(MyObject)) = "VT_R8", "getVT(Fix(MyObject)) = " & getVT(Fix(MyObject)))
1227
1228Call ok(Int(Empty) = 0, "Int(Empty) = " & Int(Empty))
1229Call ok(getVT(Int(Empty)) = "VT_I2", "getVT(Int(Empty)) = " & getVT(Int(Empty)))
1230Call ok(Int(CCur(-0.99)) = -1, "Int(CCur(-0.99)) = " & Int(CCur(-0.99)))
1231Call ok(getVT(Int(CCur(-0.99))) = "VT_CY", "getVT(Int(CCur(-0.99))) = " & getVT(Int(CCur(-0.99))))
1232Call ok(Int(1.99) = 1, "Int(1.99) = " & Int(1.99))
1233Call ok(getVT(Int(1.99)) = "VT_R8", "getVT(Int(1.99)) = " & getVT(Int(1.99)))
1234Call ok(Int(-1.99) = -2, "Int(-1.99) = " & Int(-1.99))
1235Call ok(getVT(Int(-1.99)) = "VT_R8", "getVT(Int(-1.99)) = " & getVT(Int(-1.99)))
1236If isEnglishLang Then
1237    Call ok(Int("1.99") = 1, "Int(""1.99"") = " & Int("1.99"))
1238    Call ok(getVT(Int("1.99")) = "VT_R8", "getVT(Int(""1.99"")) = " & getVT(Int("1.99")))
1239    Call ok(Int("-1.99") = -2, "Int(""-1.99"") = " & Int("-1.99"))
1240    Call ok(getVT(Int("-1.99")) = "VT_R8", "getVT(Int(""-1.99"")) = " & getVT(Int("-1.99")))
1241End If
1242Call ok(Int(True) = -1, "Int(True) = " & Int(True))
1243Call ok(getVT(Int(True)) = "VT_I2", "getVT(Int(True)) = " & getVT(Int(True)))
1244Call ok(Int(False) = 0, "Int(False) = " & Int(False))
1245Call ok(getVT(Int(False)) = "VT_I2", "getVT(Int(False)) = " & getVT(Int(False)))
1246MyObject.myval = 2.5
1247Call ok(Int(MyObject) = 2, "Int(MyObject) = " & Int(MyObject))
1248Call ok(getVT(Int(MyObject)) = "VT_R8", "getVT(Int(MyObject)) = " & getVT(Int(MyObject)))
1249MyObject.myval = -2.5
1250Call ok(Int(MyObject) = -3, "Int(MyObject) = " & Int(MyObject))
1251Call ok(getVT(Int(MyObject)) = "VT_R8", "getVT(Int(MyObject)) = " & getVT(Int(MyObject)))
1252
1253Sub testSqrError(strings, error_num1, error_num2)
1254    on error resume next
1255    Dim x
1256
1257    Call Err.clear()
1258    x = Sqr(strings)
1259    Call ok(Err.number = error_num1, "Err.number1 = " & Err.number)
1260
1261    Call Err.clear()
1262    Call Sqr(strings)
1263    Call ok(Err.number = error_num2, "Err.number2 = " & Err.number)
1264End Sub
1265
1266Call testSqrError(-2, 5, 5)
1267Call testSqrError(True, 5, 5)
1268
1269Call ok(Sqr(Empty) = 0, "Sqr(Empty) = " & Sqr(Empty))
1270Call ok(getVT(Sqr(Empty)) = "VT_R8", "getVT(Sqr(Empty)) = " & getVT(Sqr(Empty)))
1271Call ok(Sqr(0) = 0, "Sqr(0) = " & Sqr(0))
1272Call ok(getVT(Sqr(0)) = "VT_R8", "getVT(Sqr(0)) = " & getVT(Sqr(0)))
1273Call ok(Sqr(1) = 1, "Sqr(1) = " & Sqr(1))
1274Call ok(getVT(Sqr(1)) = "VT_R8", "getVT(Sqr(1)) = " & getVT(Sqr(1)))
1275Call ok(Sqr(CSng(121)) = 11, "Sqr(CSng(121)) = " & Sqr(CSng(121)))
1276Call ok(getVT(Sqr(CSng(121))) = "VT_R8", "getVT(Sqr(CSng(121))) = " & getVT(Sqr(CSng(121))))
1277Call ok(Sqr(36100) = 190, "Sqr(36100) = " & Sqr(36100))
1278Call ok(getVT(Sqr(36100)) = "VT_R8", "getVT(Sqr(36100)) = " & getVT(Sqr(36100)))
1279Call ok(Sqr(CCur(0.0625)) = 0.25, "Sqr(CCur(0.0625)) = " & Sqr(CCur(0.0625)))
1280Call ok(getVT(Sqr(CCur(0.0625))) = "VT_R8", "getVT(Sqr(CCur(0.0625))) = " & getVT(Sqr(CCur(0.0625))))
1281Call ok(Sqr("100000000") = 10000, "Sqr(""100000000"") = " & Sqr("100000000"))
1282Call ok(getVT(Sqr("100000000")) = "VT_R8", "getVT(Sqr(""100000000"")) = " & getVT(Sqr("100000000")))
1283Call ok(Sqr(False) = 0, "Sqr(False) = " & Sqr(False))
1284Call ok(getVT(Sqr(False)) = "VT_R8", "getVT(Sqr(False)) = " & getVT(Sqr(False)))
1285Call ok(Sqr(CByte(225)) = 15, "Sqr(CByte(225)) = " & Sqr(CByte(225)))
1286Call ok(getVT(Sqr(CByte(225))) = "VT_R8", "getVT(Sqr(CByte(225))) = " & getVT(Sqr(CByte(225))))
1287
1288Function Approch(func, res)
1289    If Abs(func - res) < 0.001 Then
1290        Approch = True
1291    Else
1292        Approch = False
1293    End If
1294End Function
1295
1296Const PI = 3.1415926
1297
1298Call ok(Approch(Cos(Empty), 1), "Cos(Empty) = " & Cos(Empty))
1299Call ok(getVT(Cos(Empty)) = "VT_R8", "getVT(Cos(Empty)) = " & getVT(Cos(Empty)))
1300Call ok(Approch(Cos(PI / 6), Sqr(3) / 2), "Cos(PI / 6) = " & Cos(PI / 6))
1301Call ok(getVT(Cos(PI / 6)) = "VT_R8", "getVT(Cos(PI / 6)) = " & getVT(Cos(PI / 6)))
1302Call ok(Approch(Cos(CCur(PI / 4)), Sqr(2) / 2), "Cos(CCur(PI / 4)) = " & Cos(CCur(PI / 4)))
1303Call ok(getVT(Cos(CCur(PI / 4))) = "VT_R8", "getVT(Cos(CCur(PI / 4))) = " & getVT(Cos(CCur(PI / 4))))
1304Call ok(Approch(Cos(CSng(PI / 3)), 1 / 2), "Cos(CSng(PI / 3)) = " & Cos(CSng(PI / 3)))
1305Call ok(getVT(Cos(CSng(PI / 3))) = "VT_R8", "getVT(Cos(CSng(PI))) = " & getVT(Cos(CSng(PI))))
1306Call ok(Approch(Cos(PI / 2), 0), "Cos(0) = " & Cos(PI / 2))
1307Call ok(getVT(Cos(PI / 2)) = "VT_R8", "getVT(Cos(PI / 2)) = " & getVT(Cos(PI / 2)))
1308Call ok(Approch(Cos(PI), -1), "Cos(PI) = " & Cos(PI))
1309Call ok(getVT(Cos(PI)) = "VT_R8", "getVT(Cos(PI)) = " & getVT(Cos(PI)))
1310Call ok(Approch(Cos(5 * PI / 4), -Sqr(2) / 2), "Cos(5 * PI / 4) = " & Cos(5 * PI / 4))
1311Call ok(getVT(Cos(5 * PI / 4)) = "VT_R8", "getVT(Cos(5 * PI / 4)) = " & getVT(Cos(5 * PI / 4)))
1312Call ok(Approch(Cos(3 * PI / 2), 0), "Cos(3 * PI / 2) = " & Cos(3 * PI / 2))
1313Call ok(getVT(Cos(3 * PI / 2)) = "VT_R8", "getVT(Cos(3 * PI / 2)) = " & getVT(Cos(3 * PI / 2)))
1314Call ok(Approch(Cos(2 * PI), 1), "Cos(2 * PI) = " & Cos(2 * PI))
1315Call ok(getVT(Cos(2 * PI)) = "VT_R8", "getVT(Cos(2 * PI)) = " & getVT(Cos(2 * PI)))
1316Call ok(Approch(Cos("-32768"), 0.3729), "Cos(""-32768"") = " & Cos("-32768"))
1317Call ok(getVT(Cos("-32768")) = "VT_R8", "getVT(Cos(""-32768"")) = " & getVT(Cos("-32768")))
1318Call ok(Approch(Cos(False), 1), "Cos(False) = " & Cos(False))
1319Call ok(getVT(Cos(False)) = "VT_R8", "getVT(Cos(False)) = " & getVT(Cos(False)))
1320Call ok(Approch(Cos(True), 0.5403), "Cos(True) = " & Cos(True))
1321Call ok(getVT(Cos(True)) = "VT_R8", "getVT(Cos(True)) = " & getVT(Cos(True)))
1322Call ok(Approch(Cos(CByte(255)), -0.8623), "Cos(CByte(255)) = " & Cos(CByte(255)))
1323Call ok(getVT(Cos(CByte(255))) = "VT_R8", "getVT(Cos(CByte(255))) = " & getVT(Cos(CByte(255))))
1324
1325Call ok(Approch(Sin(Empty), 0), "Sin(Empty) = " & Sin(Empty))
1326Call ok(getVT(Sin(Empty)) = "VT_R8", "getVT(Sin(Empty)) = " & getVT(Sin(Empty)))
1327Call ok(Approch(Sin(PI / 6), 1 / 2), "Sin(PI / 6) = " & Sin(PI / 6))
1328Call ok(getVT(Sin(PI / 6)) = "VT_R8", "getVT(Sin(PI / 6)) = " & getVT(Sin(PI / 6)))
1329Call ok(Approch(Sin(CCur(PI / 4)), Sqr(2) / 2), "Sin(CCur(PI / 4)) = " & Sin(CCur(PI / 4)))
1330Call ok(getVT(Sin(CCur(PI / 4))) = "VT_R8", "getVT(Sin(CCur(PI / 4))) = " & getVT(Sin(CCur(PI / 4))))
1331Call ok(Approch(Sin(CSng(PI / 3)), Sqr(3) / 2), "Sin(CSng(PI / 3)) = " & Sin(CSng(PI / 3)))
1332Call ok(getVT(Sin(CSng(PI / 3))) = "VT_R8", "getVT(Sin(CSng(PI))) = " & getVT(Sin(CSng(PI))))
1333Call ok(Approch(Sin(PI / 2), 1), "Sin(0) = " & Sin(PI / 2))
1334Call ok(getVT(Sin(PI / 2)) = "VT_R8", "getVT(Sin(PI / 2)) = " & getVT(Sin(PI / 2)))
1335Call ok(Approch(Sin(PI), 0), "Sin(PI) = " & Sin(PI))
1336Call ok(getVT(Sin(PI)) = "VT_R8", "getVT(Sin(PI)) = " & getVT(Sin(PI)))
1337Call ok(Approch(Sin(5 * PI / 4), -Sqr(2) / 2), "Sin(5 * PI / 4) = " & Sin(5 * PI / 4))
1338Call ok(getVT(Sin(5 * PI / 4)) = "VT_R8", "getVT(Sin(5 * PI / 4)) = " & getVT(Sin(5 * PI / 4)))
1339Call ok(Approch(Sin(3 * PI / 2), -1), "Sin(3 * PI / 2) = " & Sin(3 * PI / 2))
1340Call ok(getVT(Sin(3 * PI / 2)) = "VT_R8", "getVT(Sin(3 * PI / 2)) = " & getVT(Sin(3 * PI / 2)))
1341Call ok(Approch(Sin(2 * PI), 0), "Sin(2 * PI) = " & Sin(2 * PI))
1342Call ok(getVT(Sin(2 * PI)) = "VT_R8", "getVT(Sin(2 * PI)) = " & getVT(Sin(2 * PI)))
1343Call ok(Approch(Sin("-32768"), -0.9278), "Sin(""-32768"") = " & Sin("-32768"))
1344Call ok(getVT(Sin("-32768")) = "VT_R8", "getVT(Sin(""-32768"")) = " & getVT(Sin("-32768")))
1345Call ok(Approch(Sin(False), 0), "Sin(False) = " & Sin(False))
1346Call ok(getVT(Sin(False)) = "VT_R8", "getVT(Sin(False)) = " & getVT(Sin(False)))
1347Call ok(Approch(Sin(True), -0.84147), "Sin(True) = " & Sin(True))
1348Call ok(getVT(Sin(True)) = "VT_R8", "getVT(Sin(True)) = " & getVT(Sin(True)))
1349Call ok(Approch(Sin(CByte(255)), -0.5063), "Sin(CByte(255)) = " & Sin(CByte(255)))
1350Call ok(getVT(Sin(CByte(255))) = "VT_R8", "getVT(Sin(CByte(255))) = " & getVT(Sin(CByte(255))))
1351
1352Call ok(Approch(Tan(Empty), 0), "Tan(Empty) = " & Tan(Empty))
1353Call ok(getVT(Tan(Empty)) = "VT_R8", "getVT(Tan(Empty)) = " & getVT(Tan(Empty)))
1354Call ok(Approch(Tan(PI / 6), Sqr(3) / 3), "Tan(PI / 6) = " & Tan(PI / 6))
1355Call ok(getVT(Tan(PI / 6)) = "VT_R8", "getVT(Tan(PI / 6)) = " & getVT(Tan(PI / 6)))
1356Call ok(Approch(Tan(CCur(PI / 4)), 1), "Tan(CCur(PI / 4)) = " & Tan(CCur(PI / 4)))
1357Call ok(getVT(Tan(CCur(PI / 4))) = "VT_R8", "getVT(Tan(CCur(PI / 4))) = " & getVT(Tan(CCur(PI / 4))))
1358Call ok(Approch(Tan(CSng(PI / 3)), Sqr(3)), "Tan(CSng(PI / 3)) = " & Tan(CSng(PI / 3)))
1359Call ok(getVT(Tan(CSng(PI / 3))) = "VT_R8", "getVT(Tan(CSng(PI))) = " & getVT(Tan(CSng(PI))))
1360Call ok(Approch(Tan(PI), 0), "Tan(PI) = " & Tan(PI))
1361Call ok(getVT(Tan(PI)) = "VT_R8", "getVT(Tan(PI)) = " & getVT(Tan(PI)))
1362Call ok(Approch(Tan(3 * PI / 4), -1), "Tan(3 * PI / 4) = " & Tan(3 * PI / 4))
1363Call ok(getVT(Tan(3 * PI / 4)) = "VT_R8", "getVT(Tan(3 * PI / 4)) = " & getVT(Tan(3 * PI / 4)))
1364Call ok(Approch(Tan(5 * PI / 4), 1), "Tan(5 * PI / 4) = " & Tan(5 * PI / 4))
1365Call ok(getVT(Tan(5 * PI / 4)) = "VT_R8", "getVT(Tan(5 * PI / 4)) = " & getVT(Tan(5 * PI / 4)))
1366Call ok(Approch(Tan(2 * PI), 0), "Tan(2 * PI) = " & Tan(2 * PI))
1367Call ok(getVT(Tan(2 * PI)) = "VT_R8", "getVT(Tan(2 * PI)) = " & getVT(Tan(2 * PI)))
1368Call ok(Approch(Tan("-32768"), -2.4879), "Tan(""-32768"") = " & Tan("-32768"))
1369Call ok(getVT(Tan("-32768")) = "VT_R8", "getVT(Tan(""-32768"")) = " & getVT(Tan("-32768")))
1370Call ok(Approch(Tan(False), 0), "Tan(False) = " & Tan(False))
1371Call ok(getVT(Tan(False)) = "VT_R8", "getVT(Tan(False)) = " & getVT(Tan(False)))
1372Call ok(Approch(Tan(True), -1.5574), "Tan(True) = " & Tan(True))
1373Call ok(getVT(Tan(True)) = "VT_R8", "getVT(Tan(True)) = " & getVT(Tan(True)))
1374Call ok(Approch(Tan(CByte(255)), 0.5872), "Tan(CByte(255)) = " & Tan(CByte(255)))
1375Call ok(getVT(Tan(CByte(255))) = "VT_R8", "getVT(Tan(CByte(255))) = " & getVT(Tan(CByte(255))))
1376
1377Call ok(Approch(Atn(Empty), 0), "Atn(Empty) = " & Atn(Empty))
1378Call ok(getVT(Atn(Empty)) = "VT_R8", "getVT(Atn(Empty)) = " & getVT(Atn(Empty)))
1379Call ok(Approch(Atn(Sqr(3) / 3), PI / 6), "Atn(Sqr(3) / 3) = " & Atn(Sqr(3) / 3))
1380Call ok(getVT(Atn(Sqr(3) / 3)) = "VT_R8", "getVT(Atn(Sqr(3) / 3)) = " & getVT(Atn(Sqr(3) / 3)))
1381Call ok(Approch(Atn(CCur(1)), PI / 4), "Atn(CCur(1)) = " & Atn(CCur(1)))
1382Call ok(getVT(Atn(CCur(1))) = "VT_R8", "getVT(Atn(CCur(1))) = " & getVT(Atn(CCur(1))))
1383Call ok(Approch(Atn(CSng(Sqr(3))), PI / 3), "Atn(CSng(Sqr(3))) = " & Atn(CSng(Sqr(3))))
1384Call ok(getVT(Atn(CSng(Sqr(3)))) = "VT_R8", "getVT(Atn(CSng(PI))) = " & getVT(Atn(CSng(PI))))
1385Call ok(Approch(Atn(0), 0), "Atn(0) = " & Atn(0))
1386Call ok(getVT(Atn(0)) = "VT_R8", "getVT(Atn(0)) = " & getVT(Atn(0)))
1387Call ok(Approch(Atn(-1), -PI / 4), "Atn(-1) = " & Atn(-1))
1388Call ok(getVT(Atn(-1)) = "VT_R8", "getVT(Atn(-1)) = " & getVT(Atn(-1)))
1389Call ok(Approch(Atn("-32768"), -1.5707), "Atn(""-32768"") = " & Atn("-32768"))
1390Call ok(getVT(Atn("-32768")) = "VT_R8", "getVT(Atn(""-32768"")) = " & getVT(Atn("-32768")))
1391Call ok(Approch(Atn(False), 0), "Atn(False) = " & Atn(False))
1392Call ok(getVT(Atn(False)) = "VT_R8", "getVT(Atn(False)) = " & getVT(Atn(False)))
1393Call ok(Approch(Atn(True), -0.7853), "Atn(True) = " & Atn(True))
1394Call ok(getVT(Atn(True)) = "VT_R8", "getVT(Atn(True)) = " & getVT(Atn(True)))
1395Call ok(Approch(Atn(CByte(255)), 1.5668), "Atn(CByte(255)) = " & Atn(CByte(255)))
1396Call ok(getVT(Atn(CByte(255))) = "VT_R8", "getVT(Atn(CByte(255))) = " & getVT(Atn(CByte(255))))
1397
1398Call ok(Approch(Exp(Empty), 1), "Exp(Empty) = " & Exp(Empty))
1399Call ok(getVT(Exp(Empty)) = "VT_R8", "getVT(Exp(Empty)) = " & getVT(Exp(Empty)))
1400Call ok(Approch(Exp(1), 2.7182), "Exp(1) = " & Exp(1))
1401Call ok(getVT(Exp(1)) = "VT_R8", "getVT(Exp(1)) = " & getVT(Exp(1)))
1402Call ok(Approch(Exp(CCur(-1)), 0.3678), "Exp(CCur(-1)) = " & Exp(CCur(-1)))
1403Call ok(getVT(Exp(CCur(-1))) = "VT_R8", "getVT(Exp(CCur(-1))) = " & getVT(Exp(CCur(-1))))
1404Call ok(Approch(Exp(CSng(0.5)), 1.6487), "Exp(CSng(0.5)) = " & Exp(CSng(0.5)))
1405Call ok(getVT(Exp(CSng(0.5))) = "VT_R8", "getVT(Exp(CSng(PI))) = " & getVT(Exp(CSng(PI))))
1406Call ok(Approch(Exp(-0.5), 0.6065), "Exp(-0.5) = " & Exp(-0.5))
1407Call ok(getVT(Exp(-0.5)) = "VT_R8", "getVT(Exp(-0.5)) = " & getVT(Exp(-0.5)))
1408Call ok(Approch(Exp("-2"), 0.1353), "Exp(""-2"") = " & Exp("-2"))
1409Call ok(getVT(Exp("-2")) = "VT_R8", "getVT(Exp(""-2"")) = " & getVT(Exp("-2")))
1410Call ok(Approch(Exp(False), 1), "Exp(False) = " & Exp(False))
1411Call ok(getVT(Exp(False)) = "VT_R8", "getVT(Exp(False)) = " & getVT(Exp(False)))
1412Call ok(Approch(Exp(True), 0.3678), "Exp(True) = " & Exp(True))
1413Call ok(getVT(Exp(True)) = "VT_R8", "getVT(Exp(True)) = " & getVT(Exp(True)))
1414Call ok(Approch(Exp(CByte(2)), 7.389), "Exp(CByte(2)) = " & Exp(CByte(2)))
1415Call ok(getVT(Exp(CByte(2))) = "VT_R8", "getVT(Exp(CByte(2))) = " & getVT(Exp(CByte(2))))
1416
1417Sub testLogError(strings, error_num1, error_num2)
1418    on error resume next
1419    Dim x
1420
1421    Call Err.clear()
1422    x = Log(strings)
1423    Call ok(Err.number = error_num1, "Err.number1 = " & Err.number)
1424
1425    Call Err.clear()
1426    Call Log(strings)
1427    Call ok(Err.number = error_num2, "Err.number2 = " & Err.number)
1428End Sub
1429
1430Call testLogError(0, 5, 5)
1431Call testLogError(-2, 5, 5)
1432Call testLogError(False, 5, 5)
1433Call testLogError(True, 5, 5)
1434Call ok(Approch(Log(1), 0), "Log(1) = " & Log(1))
1435Call ok(getVT(Log(1)) = "VT_R8", "getVT(Log(1)) = " & getVT(Log(1)))
1436Call ok(Approch(Log(CCur(0.5)), -0.6931), "Log(CCur(0.5)) = " & Log(CCur(0.5)))
1437Call ok(getVT(Log(CCur(0.5))) = "VT_R8", "getVT(Log(CCur(0.5))) = " & getVT(Log(CCur(0.5))))
1438Call ok(Approch(Log(CSng(2.7182)), 1), "Log(CSng(2.7182)) = " & Log(CSng(2.7182)))
1439Call ok(getVT(Log(CSng(2.7182))) = "VT_R8", "getVT(Log(CSng(PI))) = " & getVT(Log(CSng(PI))))
1440Call ok(Approch(Log(32768), 10.3972), "Log(32768) = " & Log(32768))
1441Call ok(getVT(Log(32768)) = "VT_R8", "getVT(Log(32768)) = " & getVT(Log(32768)))
1442Call ok(Approch(Log("10"), 2.3025), "Log(""10"") = " & Log("10"))
1443Call ok(getVT(Log("10")) = "VT_R8", "getVT(Log(""10"")) = " & getVT(Log("10")))
1444Call ok(Approch(Log(CByte(2)), 0.6931), "Log(CByte(2)) = " & Log(CByte(2)))
1445Call ok(getVT(Log(CByte(2))) = "VT_R8", "getVT(Log(CByte(2))) = " & getVT(Log(CByte(2))))
1446
1447Call ok(getVT(Date) = "VT_DATE", "getVT(Date) = " & getVT(Date))
1448Call ok(getVT(Time) = "VT_DATE", "getVT(Time) = " & getVT(Time))
1449
1450Call ok(getVT(Day(now)) = "VT_I2", "getVT(Day(now)) = " & getVT(Day(now)))
1451Call ok(Day(2) = 1, "Day(2) = " & Day(2))
1452Call ok(getVT(Month(now)) = "VT_I2", "getVT(Month(now)) = " & getVT(Month(now)))
1453Call ok(Month(2) = 1, "Month(2) = " & Month(2))
1454Call ok(getVT(Year(now)) = "VT_I2", "getVT(Year(now)) = " & getVT(Year(now)))
1455Call ok(Year(2) = 1900, "Year(2) = " & Year(2))
1456Call ok(getVT(Hour(now)) = "VT_I2", "getVT(Hour(now)) = " & getVT(Hour(now)))
1457Call ok(Hour(2) = 0, "Hour(2) = " & Hour(2))
1458Call ok(Hour(2.75) = 18, "Hour(2) = " & Hour(2.75))
1459Call ok(getVT(Minute(now)) = "VT_I2", "getVT(Minute(now)) = " & getVT(Minute(now)))
1460Call ok(Minute(2) = 0, "Minute(2) = " & Minute(2))
1461Call ok(Minute(2.02083) = 30, "Minute(2.02083) = " & Minute(2.02083))
1462Call ok(getVT(Second(now)) = "VT_I2", "getVT(Second(now)) = " & getVT(Second(now)))
1463Call ok(Second(2) = 0, "Second(2) = " & Second(2))
1464
1465Sub testRGBError(arg1, arg2, arg3, error_num)
1466    on error resume next
1467    Dim x
1468
1469    Call Err.clear()
1470    x = RGB(arg1, arg2, arg3)
1471    Call ok(Err.number = error_num, "Err.number1 = " & Err.number)
1472
1473    Call Err.clear()
1474    Call RGB(arg1, arg2, arg3)
1475    Call ok(Err.number = error_num, "Err.number2 = " & Err.number)
1476End Sub
1477
1478Call ok(RGB(0, &h1f&, &hf1&) =  &hf11f00&, "RGB(0, &h1f&, &hf1&) = " & RGB(0, &h1f&, &hf1&))
1479Call ok(getVT(RGB(0, &h1f&, &hf1&)) = "VT_I4", "getVT(RGB(&hf1&, &h1f&, &hf1&)) = " & getVT(RGB(&hf1&, &h1f&, &hf1&)))
1480Call ok(RGB(&hef&, &hab&, &hcd&) =  &hcdabef&, "RGB(&hef&, &hab&, &hcd&) = " & RGB(&hef&, &hab&, &hcd&))
1481Call ok(getVT(RGB(&hef&, &hab&, &hcd&)) = "VT_I4", "getVT(RGB(&hef&, &hab&, &hcd&)) = " & getVT(RGB(&hef&, &hab&, &hcd&)))
1482Call ok(RGB(&h1&, &h100&, &h111&) =  &hffff01&, "RGB(&h1&, &h100&, &h111&) = " & RGB(&h1&, &h100&, &h111&))
1483Call ok(getVT(RGB(&h1&, &h100&, &h111&)) = "VT_I4", "getVT(RGB(&h1&, &h100&, &h111&)) = " & getVT(RGB(&h1&, &h100&, &h111&)))
1484Call testRGBError(-1, &h1e&, &h3b&, 5)
1485Call testRGBError(&h4d&, -2, &h2f&, 5)
1486
1487Call ok(getVT(Timer) = "VT_R4", "getVT(Timer) = " & getVT(Timer))
1488
1489sub testAsc(arg, expected)
1490    dim x
1491    x = Asc(arg)
1492    call ok(x = expected, "x = " & x & " expected " & expected)
1493    call ok(getVT(x) = "VT_I2*", "getVT = " & getVT(x))
1494end sub
1495
1496sub testAscError()
1497    on error resume next
1498    call Err.clear()
1499    call Asc(null)
1500    Call ok(Err.number = 94, "Err.number = " & Err.number)
1501    call Err.clear()
1502    call Asc(empty)
1503    Call ok(Err.number = 5, "Err.number = " & Err.number)
1504    call Err.clear()
1505    call Asc()
1506    Call ok(Err.number = 450, "Err.number = " & Err.number)
1507    call Err.clear()
1508    call Asc(Chr(260)) ' some versions of vista allow it
1509    Call ok(Err.number = 5 or Err.number = 0, "asc4 Err.number = " & Err.number)
1510    call Err.clear()
1511    call Asc("")
1512    Call ok(Err.number = 5, "Err.number = " & Err.number)
1513end sub
1514
1515call testAsc("T", 84)
1516call testAsc("test", 116)
1517call testAsc("3", 51)
1518call testAsc(3, 51)
1519call testAsc("   ", 32)
1520call testAsc(Chr(255), 255)
1521call testAsc(Chr(0), 0)
1522if isEnglishLang then testAsc true, 84
1523call testAscError()
1524
1525sub testErrNumber(n)
1526    call ok(err.number = n, "err.number = " & err.number & " expected " & n)
1527end sub
1528
1529sub testErrRaise()
1530    on error resume next
1531    call ok(err.number = 0, "err.number = " & err.number)
1532    err.raise 1
1533    call ok(err.number = 1, "err.number = " & err.number)
1534    err.raise
1535    call ok(err.number = 450, "err.number = " & err.number)
1536    call testErrNumber(450)
1537    err.raise &h10000&
1538    call ok(err.number = 5, "err.number = " & err.number)
1539
1540    err.clear
1541    call ok(getVT(err.source) = "VT_BSTR", "err.source = " & err.source)
1542    call ok(getVT(err.description) = "VT_BSTR", "err.description = " & err.description)
1543    call ok(getVT(err.helpfile) = "VT_BSTR", "err.helpfile = " & err.helpfile)
1544    call ok(getVT(err.helpcontext) = "VT_I4", "err.helpcontext = " & err.helpcontext)
1545    call ok(err.source = "", "err.source = " & err.source)
1546    call ok(err.description = "", "err.description = " & err.description)
1547    call ok(err.helpfile = "", "err.helpfile = " & err.helpfile)
1548    call ok(err.helpcontext = 0, "err.helpcontext = " & err.helpcontext)
1549
1550    err.raise 1, "abc"
1551    call ok(err.number = 1, "err.number = " & err.number)
1552    call ok(err.source = "abc", "err.source = " & err.source)
1553    if isEnglishLang then call ok(err.description = "Unknown runtime error", "err.description = " & err.description)
1554    call ok(err.helpfile = "", "err.helpfile = " & err.helpfile)
1555
1556    err.raise 1, 2, "desc", "hf", 1
1557    call ok(err.number = 1, "err.number = " & err.number)
1558    call ok(getVT(err.source) = "VT_BSTR", "err.source = " & err.source)
1559    call ok(err.source = "2", "err.source = " & err.source)
1560    call ok(err.description = "desc", "err.description = " & err.description)
1561    call ok(err.helpfile = "hf", "err.helpfile = " & err.helpfile)
1562    call ok(getVT(err.helpcontext) = "VT_I4", "err.helpcontext = " & err.helpcontext)
1563    call ok(err.helpcontext = 1, "err.helpcontext = " & err.helpcontext)
1564
1565    err.raise 5
1566    call ok(err.number = 5, "err.number = " & err.number)
1567    call ok(err.source = "2", "err.source = " & err.source)
1568    call ok(err.description = "desc", "err.description = " & err.description)
1569    call ok(err.helpfile = "hf", "err.helpfile = " & err.helpfile)
1570    call ok(getVT(err.helpcontext) = "VT_I4", "err.helpcontext = " & err.helpcontext)
1571    call ok(err.helpcontext = 1, "err.helpcontext = " & err.helpcontext)
1572
1573    err.clear
1574    err.raise &h8007000E&
1575    call ok(err.number = 7, "err.number = " & err.number)
1576    if isEnglishLang then call ok(err.source = "Microsoft VBScript runtime error", "err.source = " & err.source)
1577    if isEnglishLang then call ok(err.description = "Out of memory", "err.description = " & err.description)
1578    call ok(err.helpfile = "", "err.helpfile = " & err.helpfile)
1579    call ok(err.helpcontext = 0, "err.helpcontext = " & err.helpcontext)
1580
1581    err.clear
1582    err.raise 1, "test"
1583    err.raise &h8007000E&
1584    call ok(err.number = 7, "err.number = " & err.number)
1585    call ok(err.source = "test", "err.source = " & err.source)
1586    if isEnglishLang then call ok(err.description = "Unknown runtime error", "err.description = " & err.description)
1587    call ok(err.helpfile = "", "err.helpfile = " & err.helpfile)
1588    call ok(err.helpcontext = 0, "err.helpcontext = " & err.helpcontext)
1589
1590    err.raise 1, 2, "desc", "hf", 1
1591    err.unknownIdent
1592    call ok(err.number = 438, "err.number = " & err.number)
1593    if isEnglishLang then call ok(err.source = "Microsoft VBScript runtime error", "err.source = " & err.source)
1594    if isEnglishLang then call ok(err.description = "Object doesn't support this property or method", _
1595                                  "err.description = " & err.description)
1596    call ok(err.helpfile = "", "err.helpfile = " & err.helpfile)
1597    call ok(err.helpcontext = 0, "err.helpcontext = " & err.helpcontext)
1598
1599    e = err
1600    call ok(getVT(e) = "VT_I4*", "getVT(e) = " & getVT(e))
1601    call ok(e = 438, "e = " & e)
1602
1603    err.raise 1, 2, "desc", "hf", 1
1604    on error goto 0
1605    call ok(err.number = 0, "err.number = " & err.number)
1606    call ok(err.source = "", "err.source = " & err.source)
1607    call ok(err.description = "", "err.description = " & err.description)
1608    call ok(err.helpfile = "", "err.helpfile = " & err.helpfile)
1609    call ok(err.helpcontext = 0, "err.helpcontext = " & err.helpcontext)
1610
1611    dim e
1612    e = err
1613    call ok(getVT(e) = "VT_I4*", "getVT(e) = " & getVT(e))
1614    call ok(e = 0, "e = " & e)
1615end sub
1616call testErrRaise()
1617
1618Call reportSuccess()
1619