1rem *************************************************************
2rem
3rem  Licensed to the Apache Software Foundation (ASF) under one
4rem  or more contributor license agreements.  See the NOTICE file
5rem  distributed with this work for additional information
6rem  regarding copyright ownership.  The ASF licenses this file
7rem  to you under the Apache License, Version 2.0 (the
8rem  "License"); you may not use this file except in compliance
9rem  with the License.  You may obtain a copy of the License at
10rem
11rem    http://www.apache.org/licenses/LICENSE-2.0
12rem
13rem  Unless required by applicable law or agreed to in writing,
14rem  software distributed under the License is distributed on an
15rem  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16rem  KIND, either express or implied.  See the License for the
17rem  specific language governing permissions and limitations
18rem  under the License.
19rem
20rem *************************************************************
21REM  *****  BASIC  *****
22
23
24OPTION EXPLICIT
25OPTION COMPATIBLE
26
27Sub Main
28COMPATIBILITYMODE(true)
29
30If runtest = -1 Then
31  MsgBox "Test Failed!!!"
32Else
33  MsgBox "Test Succeeded"
34End If
35
36End Sub
37
38Function runtest() As Integer
39Dim inBool As Boolean, inBool2 As Boolean, outBool As Boolean
40Dim inByte As Integer, inByte2 As Integer
41Dim inShort As Integer, inShort2 As Integer
42Dim inLong As Long, inLong2 As Long, inLong3 As Long, inLong4 As Long
43Dim inString As String, inString2 As String
44Dim inFloat As Single, inFloat2 As Single
45Dim inDouble As Double, inDouble2 As Double
46Dim inVariant, inVariant2
47Dim inAr, inAr2
48Dim inDate As Date,inDate2 As Date, outDate As Date
49Dim inCurrency As Currency, inCurrency2 As Currency, outCurrency As Currency
50Dim inSCode As New com.sun.star.bridge.oleautomation.SCode
51Dim inSCode2 As New com.sun.star.bridge.oleautomation.SCode
52Dim inDecimal As Variant, inDecimal2 As Variant, outDecimal As Variant
53Dim inrefDecimal As Variant, outrefDecimal As Variant
54Dim outSCode As New com.sun.star.bridge.oleautomation.SCode
55Dim outByte As Integer
56Dim outShort As Integer
57Dim outLong, outLong2 As Long
58Dim outString As String
59Dim outFloat As Single
60Dim outDouble As Double
61Dim outVariant
62'bug #109936 causes an errOr when outObject is used As out param
63Dim inObject As Object, inObject2 As Object, outObject As Object
64Dim objNOTHING As Object
65Dim inUnknown As Object, inUnknown2 As Object, outUnknown As Object
66
67Dim inArray, outArray, outArray2
68Dim len1, len2
69Dim arString(1) As String
70arString(0)= "String one"
71arString(1)= "String two"
72
73Dim factory As Object
74factory= createUnoService("com.sun.star.bridge.OleObjectFactory")
75Dim obj As Object
76obj= factory.createInstance("AxTestComponents.Basic")
77
78Dim objFoo As Object
79objFoo = factory.createInstance("AxTestComponents.Foo")
80
81
82'in parameter -------------------------------------------------------------------
83inBool = true
84inByte = 10
85inShort = 11
86inLong = 111
87inString = "Hello World"
88inFloat = 3.14
89inDouble = 3.145
90inVariant = "bla"
91inDate = NOW()
92inCurrency = 12345.6789
93inSCode.Value = &h80020004
94inDecimal = CDec("-9223372036854775808") 'lowest int64
95
96obj.inBool(inBool)
97obj.inByte(inByte)
98obj.inShort(inShort)
99obj.inLong(inLong)
100obj.inString(inString)
101obj.inFloat(inFloat)
102obj.inDouble(inDouble)
103obj.inVariant(inVariant)
104'obj.prpString= "a string property"
105obj.inObject(obj)
106obj.inArray(arString())
107obj.inDate(inDate)
108obj.inCurrency(inCurrency)
109obj.inSCode(inSCode)
110obj.inUnknown(objFoo)
111obj.inDecimal(inDecimal)
112
113'out parameter -------------------------------------------------------------------------
114outBool = false
115obj.outBool(outBool)
116outByte = 0
117obj.outByte(outByte)
118outShort = 0
119obj.outShort(outShort)
120outLong = 0
121obj.outLong(outLong)
122outFloat = 0
123obj.outFloat(outFloat)
124outDouble = 0
125obj.outDouble(outDouble)
126outString = ""
127obj.outString(outString)
128outVariant = 0
129obj.outVariant(outVariant)
130outObject  = NOTHING
131obj.outObject(outObject)
132outArray = 0
133obj.outArray(outArray)
134obj.outDate(outDate)
135obj.outCurrency(outCurrency)
136obj.outSCode(outSCode)
137obj.outUnknown(outUnknown)
138obj.outDecimal(outDecimal)
139
140
141If inBool <> outBool Or inByte <> outByte Or inShort <> outShort Or inLong <> outLong Or _
142   inFloat <> outFloat Or inDouble <> outDouble Or inString <> outString Or _
143   inVariant <> outVariant Or NOT equalUnoObjects(obj, outObject) Or NOT _
144   equalArrays(arString(), outArray()) Or inDate <> outDate Or inCurrency <> outCurrency Or _
145   inSCode.Value <> outSCode.Value Or Not equalUnoObjects(objFoo, outUnknown) Or _
146   inDecimal <> outDecimal Then
147   runtest = -1
148   exit Function
149End If
150
151
152'in-out parameter -------------------------------------------------------------
153'implementation of inout methods returns the previously set value in out param
154inBool = true
155inBool2 = inBool
156obj.inoutBool(inBool2)
157outBool = false
158obj.inoutBool(outBool)
159inByte = 10
160inByte2 = inByte
161obj.inoutByte(inByte2)
162outByte = 0
163obj.inoutByte(outByte)
164inShort =  10
165inShort2 = inShort
166obj.inShort(inShort2)
167outShort = 0
168obj.inoutShort(outShort)
169inLong = 10
170inLong2 = inLong
171obj.inoutLong(inLong2)
172outLong = 0
173obj.inoutLong(outLong)
174inFloat = 3.14
175inFloat2 = inFloat
176obj.inoutFloat(inFloat2)
177outFloat = 0
178obj.inoutFloat(outFloat)
179inDouble= 3.14
180inDouble2 = inDouble
181obj.inoutDouble(inDouble2)
182outDouble = 0
183obj.inoutDouble(outDouble)
184inString = "in"
185inString2 = inString
186obj.inoutString(inString2)
187outString = ""
188obj.inoutString(outString)
189inVariant = "in"
190inVariant2 = inVariant
191obj.inoutVariant(inVariant2)
192outVariant = 0
193obj.inoutVariant(outVariant)
194inObject = factory.createInstance("AxTestComponents.Basic")
195inObject2 = inObject
196obj.inoutObject(inObject2)
197outObject = NOTHING
198obj.inoutObject(outObject)
199inAr = arString()
200inAr2 = inAr
201obj.inoutArray(inAr2)
202outArray = 0
203obj.outArray(outArray())
204inDate = NOW()
205inDate2 = inDate
206obj.inoutDate(inDate2)
207outDate = 0
208obj.inoutDate(outDate)
209inCurrency = 1234.5678
210inCurrency2 = inCurrency
211obj.inoutCurrency(inCurrency2)
212outCurrency = 0
213obj.inoutCurrency(outCurrency)
214inSCode.Value = &h80020004
215inSCode2 = inSCode
216obj.inoutSCode(inSCode2)
217outSCode.Value = 0
218obj.inoutSCode(outSCode)
219inUnknown = objFoo
220inUnknown2 = inUnknown
221obj.inoutUnknown(inUnknown2)
222outUnknown = Nothing
223obj.inoutUnknown(outUnknown)
224inDecimal = CDec("18446744073709551615") 'highest positiv value of unsigne int64
225inDecimal2 = inDecimal
226obj.inoutDecimal(inDecimal2)
227outDecimal = 0
228obj.inoutDecimal(outDecimal)
229
230If inBool <> outBool Or inByte <> outByte Or inShort <> outShort Or inLong <> outLong Or _
231   inFloat <> outFloat Or inDouble <> outDouble Or inString <> outString Or _
232   inVariant <> outVariant Or NOT equalUnoObjects(inObject, outObject) Or _
233   NOT equalArrays(inAr, outArray) Or inDate <> outDate Or inCurrency <> outCurrency Or _
234   inSCode.Value <> outSCode.Value  Or Not equalUnoObjects(inUnknown, outUnknown) Or _
235   inDecimal <> outDecimal Then
236  runtest = -1
237  Exit Function
238End If
239
240'properties -------------------------------------------------------------------------
241inBool = false
242outBool = true
243obj.prpBool = inBool
244outBool = obj.prpBool
245inByte = 11
246outByte = 0
247obj.prpByte = inByte
248outByte= obj.prpByte
249inShort = 127
250outShort = 0
251obj.prpShort= inShort
252outShort= obj.prpShort
253inLong = 1000
254outLong = 0
255obj.prpLong = inLong
256outLong= obj.prpLong
257inFloat = 3.14
258outFloat = 0
259obj.prpFloat = inFloat
260outFloat= obj.prpFloat
261inDouble = 3.123
262outDouble = 0
263obj.prpDouble = inDouble
264outDouble= obj.prpDouble
265inString = "bla"
266outString = ""
267obj.prpString = inString
268outString = obj.prpString
269inObject = obj
270outObject = objNOTHING
271obj.prpObject = inObject
272outObject = obj.prpObject
273inVariant = "bla"
274outVariant = 0
275obj.prpVariant = inVariant
276outVariant= obj.prpVariant
277inArray = arString()
278outArray = 0
279obj.prpArray = inArray()
280outArray= obj.prpArray
281inDate = NOW()
282outDate = 0
283obj.prpDate = inDate
284outDate = obj.prpDate
285inCurrency = 1234.5678
286outCurrency = 0
287obj.prpCurrency = inCurrency
288outCurrency = obj.prpCurrency
289inSCode.Value = &h80020004
290outSCode.Value = 0
291obj.prpSCode = inSCode
292outSCode = obj.prpSCode
293inUnknown = objFoo
294outUnknown= Nothing
295obj.prpUnknown = inUnknown
296outUnknown = obj.prpUnknown
297inDecimal = CDec("18446744073709551615")' highest unsigned int64
298outDecimal = 0
299obj.prpDecimal = inDecimal
300outDecimal = obj.prpDecimal
301
302If inBool <> outBool Or inByte <> outByte Or inShort <> outShort Or inLong <> outLong Or _
303   inFloat <> outFloat Or inDouble <> outDouble Or inString <> outString Or _
304   inVariant <> outVariant Or NOT equalUnoObjects(inObject, outObject) Or _
305   NOT equalArrays(inArray, outArray) Or inDate <> outDate Or inCurrency <> outCurrency Or _
306   inSCode.Value <> outSCode.Value Or Not equalUnoObjects(inUnknown, outUnknown) Or _
307   inDecimal <> outDecimal Then
308  runtest = -1
309  Exit Function
310End If
311
312' ref parameter ------------------------------------------------------------------------
313obj.inLong(0)
314inLong = 123
315outLong = 0
316obj.inLong(0)
317obj.inrefLong(inLong)
318obj.outLong(outLong)
319inVariant = "bla"
320outVariant = 0
321obj.inVariant(0)
322obj.inrefVariant(inVariant)
323obj.outVariant(outVariant)
324If inLong <> outLong Or inVariant <> outVariant Then
325  runtest = -1
326  Exit Function
327End If
328
329outLong = 0
330obj.prprefLong = inLong
331outLong = obj.prprefLong
332outVariant = 0
333obj.prprefVariant = inVariant
334outVariant = obj.prprefVariant
335If inLong <> outLong Or  inVariant <> outVariant Then
336  runtest = -1
337  Exit Function
338End If
339
340
341'vararg --------------------------------------------------------------------------------
342inLong=1
343inLong2 = 2
344inLong3 = 3
345obj.varargfunc1(inLong)
346outArray = 0
347outLong = 0
348obj.varargfunc2(outLong, outArray)
349If inLong <> outLong Then
350  runtest = -1
351  Exit Function
352End If
353len1 = UBound(outArray)  - LBound(outArray) +1
354If len1 <> 0 Then
355  runtest = -1
356  Exit Function
357End If
358outArray = 0
359obj.varargfunc1(inLong, inLong2, inLong3)
360obj.varargfunc2(outLong, outArray)
361len1 = UBound(outArray) - LBound(outArray) +1
362If len1 <> 2 Or outArray(0) <> inLong2 Or outArray(1) <> inLong3 Then
363  runtest = -1
364  Exit Function
365End If
366
367
368'defaultvalue ---------------------------------------------------------------------------
369inLong = 0
370inFloat = 0
371inVariant = 0
372inVariant2 = 0
373'defaults are: 1, 2, 4
374'The third parameter is a VARIANT with a default value of 4. COM gives it the type BSTR
375obj.defaultvalue1()
376obj.defaultvalue2(inLong, inFloat, inVariant)
377If inLong <> 1 Or inFloat <> 2 Or inVariant <> "4" Then
378  runtest = -1
379  Exit Function
380End If
381inLong = 10
382inFloat = 11
383inLong2 = inLong
384inFloat2 = inFloat
385inVariant = 0
386inVariant = 0
387obj.defaultvalue1(inLong, inFloat)
388obj.defaultvalue2(inLong, inFloat, inVariant)
389If inLong <> inLong2 Or inFloat <> inFloat2 Or inVariant <> "4" Then
390  runtest = -1
391  Exit Function
392End If
393
394'optional parameters ----------------------------------------------------------------
395inLong = 100
396outLong = 0
397obj.optional1(inLong)
398obj.optional2(outLong)
399If inLong <> outLong Then
400 runtest = -1
401 Exit Function
402End If
403
404inLong2 = 101
405outLong2 = 0
406obj.optional1(inLong, inLong2)
407obj.optional2(outLong, outLong2)
408If inLong <> outLong AND inLong2 <> outLong2 Then
409 runtest = -1
410 Exit Function
411End If
412
413inLong2 = 101
414outLong2 = 0
415obj.optional1(inLong, inLong2)
416obj.optional1(inLong)
417obj.optional2(outLong, outLong2)
418If inLong <> outLong AND inLong2 <> outLong2 Then
419 runtest = -1
420 Exit Function
421End If
422
423inLong = 10
424inLong2 = 100
425outLong = 5
426outLong2 = 6
427obj.optional3()
428obj.optional3(inLong, inLong2)
429obj.optional4(outLong, outLong2) 'outLong = 10, outLong2 = 100
430If inLong <> outLong AND inLong2 <> outLong2 Then
431 runtest = -1
432 Exit Function
433End If
434inLong = 10
435inLong2 = 100
436inLong3 = inLong
437inLong4 = inLong2
438obj.optional4(inLong, inLong)
439outLong = 0
440outLong2 = 0
441obj.optional5(outLong, outLong2)
442If inLong3 <> outLong AND inLong4 <> outLong2 Then
443  runtest = -1
444  Exit Function
445End If
446
447inLong = 10
448outLong = 5
449obj.optional3(inLong)
450obj.optional4(outLong)
451If inLong <> outLong Then
452 runtest = -1
453 Exit Function
454End If
455inLong = 10
456inLong2 = inLong
457outLong = 0
458obj.optional4(inLong)
459obj.optional5(outLong)
460If inLong2 <> outLong Then
461  runtest = -1
462  Exit Function
463End If
464
465'named arguments-------------------------------------------------------------------------
466'all args As named args, different order
467obj.optional6(0, 0, 0, 0)
468inLong = 1
469inLong2 = 2
470inLong3 = 3
471inLong4 = 4
472obj.optional6(val4:= inLong4, val3:=inLong3, val2:=inLong2, val1:= inLong)
473Dim outLong3 As Long
474Dim outLong4 As Long
475outLong = 0
476outLong2 = 0
477outLong3 = 0
478outLong4 = 0
479obj.optional7(outLong, outLong2, outLong3, outLong4)
480If inLong <> outLong Or inLong2 <> outLong2 _
481	Or inLong3 <> outLong3 Or inLong4 <> outLong4 Then
482	runtest = -1
483	Exit Function
484End If
485
486'mixed positional and named args with omitted args
487Dim scode_paramNotFound As New com.sun.star.bridge.oleautomation.SCode
488scode_paramNotFound.Value = &h80020004
489
490obj.optional6(0, 0, 0, 0)
491'val1 and val3 will be DISP_E_PARAMNOTFOUND
492obj.optional6(, inLong2, val4:=inLong4)
493Dim outSCode1, outSCode2
494obj.optional7(outSCode, outLong2, outSCode2, outLong4)
495If outSCode.Value <> scode_paramNotFound.Value Or inLong2 <> outLong2 _
496	Or outSCode2.Value <> scode_paramNotFound.Value Or inLong4 <> outLong4 Then
497	runtest = -1
498	Exit Function
499End If
500
501'mixed positional and named args with omitted args as out -args
502inLong = 1
503inLong2 = 2
504inLong3 = 3
505inLong4 = 4
506obj.optional6(inLong, inLong2, inLong3, inLong4)
507outLong2 = 0
508outLong3 = 0
509obj.optional7(,outLong2, val3:= outLong3)
510If inLong2 <> outLong2 Or inLong3 <> outLong3 Then
511	runtest = -1
512	Exit Function
513End If
514
515'test properties with additional arguments ------------------------------------
516inLong = 10
517inLong2 = 20
518inLong3 = 30
519outLong = 0
520outLong2 = 0
521outLong3 = 0
522obj.prpMultiArg1(0,0) = 0
523'obj.prpMultiArg1 = 0
524obj.prpMultiArg1(inLong,inLong2) = inLong3
525outLong3 = obj.prpMultiArg1(outLong, outLong2)
526If outLong <> 10 Or outLong2 <> 02 Or outLong3 <> 30 Then
527	runtest = -1
528	Exit Function
529End If
530
531outLong = 0
532outLong2 = 0
533obj.prpMultiArg1(0,0) = 0
534obj.prpMultiArg1(1) = 3
535outLong2 = obj.prpMultiArg1(outLong)
536If outLong <> 1 Or outLong2 <> 3 Then
537	runtest = -1
538	Exit Function
539End If
540
541outLong = 0
542outLong2 = 0
543obj.prpMultiArg1(0,0) = 0
544obj.prpMultiArg1(val2:= 1) = 3
545outLong2 = obj.prpMultiArg1(val2:=outLong)
546If outLong <> 1 Or outLong2 <> 3 Then
547	runtest = -1
548	Exit Function
549End If
550
551outLong = -1
552outLong2 = -1
553obj.prpMultiArg2(0) = 0
554outLong = obj.prpMultiArg2GetValues(outLong, outLong2)
555If outLong <> 0 Or outLong2 <> 0 Then
556	runtest = -1
557	Exit Function
558End If
559
560
561outLong = 0
562outLong2 = 0
563obj.prpMultiArg2(1) = 2
564obj.prpMultiArg2GetValues(outLong, outLong2)
565If outLong <> 1 Or outLong2 <> 2 Then
566	runtest = -1
567	Exit Function
568End If
569
570
571
572' other tests ------------------------------------------------------------------
573obj.inObject(NOTHING)
574outObject = NOTHING
575'bridge should return an XInterface any with null pointer
576'A basic errOr should occur if this is not the case
577obj.outObject(outObject)
578
579If Not IsNull(outObject) Then
580	runtest = -1
581	Exit Function
582End If
583'Decimal passed by reference
584inrefDecimal = CDec("9223372036854775807") 'highest positiv value of int64
585obj.inrefDecimal(inrefDecimal)
586outrefDecimal = 0
587obj.outDecimal(outrefDecimal)
588If inrefDecimal <> outrefDecimal Then
589	runtest = -1
590	Exit Function
591End If
592
593' Test Automation object with dual interfaces ------------------------------------
594dim dispatcher as object
595dim oExplorer as object
596dispatcher = createUnoService("com.sun.star.bridge.OleObjectFactory")
597oExplorer = dispatcher.createInstance("InternetExplorer.Application")
598If Not IsNull(oExplorer) Then
599	oExplorer.visible = true
600	oExplorer.Navigate2("http://www.openoffice.org")
601Else
602	MsgBox("Could not perform test with Internet Explorer!")
603End If
604
605
606End Function
607
608'One dimensional arrays with simple types.
609'lower bound must be 0
610Function equalArrays(ar1, ar2)
611Dim len1
612Dim len2
613len1 = UBound(ar1) - LBound(ar1) + 1
614len2 = UBound(ar2) - LBound(ar2) + 1
615If len1 <> len2 Then
616  equalArrays = false
617  Exit Function
618End If
619Dim counter
620FOr counter = 0 To len1 - 1
621  If ar1(counter) <> ar2(counter) Then
622    equalArrays = false
623    Exit Function
624  End If
625Next
626equalArrays = true
627End Function
628
629
630