2 rem This file is part of the LibreOffice project.
4 rem This Source Code Form is subject to the terms of the Mozilla Public
5 rem License, v. 2.0. If a copy of the MPL was not distributed with this
6 rem file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 rem This file incorporates work covered by the following license notice:
10 rem Licensed to the Apache Software Foundation (ASF) under one or more
11 rem contributor license agreements. See the NOTICE file distributed
12 rem with this work for additional information regarding copyright
13 rem ownership. The ASF licenses this file to you under the Apache
14 rem License, Version 2.0 (the "License"); you may not use this file
15 rem except in compliance with the License. You may obtain a copy of
16 rem the License at http://www.apache.org/licenses/LICENSE-2.0 .
23 COMPATIBILITYMODE(true)
26 MsgBox
"Test Failed!!!"
28 MsgBox
"Test Succeeded"
33 Function runtest() As Integer
34 Dim inBool
As Boolean, inBool2
As Boolean, outBool
As Boolean
35 Dim inByte
As Integer, inByte2
As Integer
36 Dim inShort
As Integer, inShort2
As Integer
37 Dim inLong
As Long, inLong2
As Long, inLong3
As Long, inLong4
As Long
38 Dim inString
As String, inString2
As String
39 Dim inFloat
As Single, inFloat2
As Single
40 Dim inDouble
As Double, inDouble2
As Double
41 Dim inVariant
, inVariant2
43 Dim inDate
As Date,inDate2
As Date, outDate
As Date
44 Dim inCurrency
As Currency, inCurrency2
As Currency, outCurrency
As Currency
45 Dim inSCode
As New com
.sun
.star
.bridge
.oleautomation
.SCode
46 Dim inSCode2
As New com
.sun
.star
.bridge
.oleautomation
.SCode
47 Dim inDecimal
As Variant, inDecimal2
As Variant, outDecimal
As Variant
48 Dim inrefDecimal
As Variant, outrefDecimal
As Variant
49 Dim outSCode
As New com
.sun
.star
.bridge
.oleautomation
.SCode
50 Dim outByte
As Integer
51 Dim outShort
As Integer
52 Dim outLong
, outLong2
As Long
53 Dim outString
As String
54 Dim outFloat
As Single
55 Dim outDouble
As Double
57 'bug #109936 causes an errOr when outObject is used As out param
58 Dim inObject
As Object, inObject2
As Object, outObject
As Object
59 Dim objNOTHING
As Object
60 Dim inUnknown
As Object, inUnknown2
As Object, outUnknown
As Object
62 Dim inArray
, outArray
, outArray2
64 Dim arString(1) As String
65 arString(0)= "String one"
66 arString(1)= "String two"
69 factory
= createUnoService("com.sun.star.bridge.OleObjectFactory")
71 obj
= factory
.createInstance("AxTestComponents.Basic")
74 objFoo
= factory
.createInstance("AxTestComponents.Foo")
77 'in parameter -------------------------------------------------------------------
82 inString
= "Hello World"
87 inCurrency
= 12345.6789
88 inSCode
.Value
= &h80020004
89 inDecimal
= CDec("-9223372036854775808") 'lowest int64
95 obj
.inString(inString
)
97 obj
.inDouble(inDouble
)
98 obj
.inVariant(inVariant
)
99 'obj.prpString= "a string property"
101 obj
.inArray(arString())
103 obj
.inCurrency(inCurrency
)
105 obj
.inUnknown(objFoo
)
106 obj
.inDecimal(inDecimal
)
108 'out parameter -------------------------------------------------------------------------
114 obj
.outShort(outShort
)
118 obj
.outFloat(outFloat
)
120 obj
.outDouble(outDouble
)
122 obj
.outString(outString
)
124 obj
.outVariant(outVariant
)
126 obj
.outObject(outObject
)
128 obj
.outArray(outArray
)
130 obj
.outCurrency(outCurrency
)
131 obj
.outSCode(outSCode
)
132 obj
.outUnknown(outUnknown
)
133 obj
.outDecimal(outDecimal
)
136 If inBool
<> outBool
Or inByte
<> outByte
Or inShort
<> outShort
Or inLong
<> outLong
Or _
137 inFloat
<> outFloat
Or inDouble
<> outDouble
Or inString
<> outString
Or _
138 inVariant
<> outVariant
Or NOT equalUnoObjects(obj
, outObject
) Or NOT _
139 equalArrays(arString(), outArray()) Or inDate
<> outDate
Or inCurrency
<> outCurrency
Or _
140 inSCode
.Value
<> outSCode
.Value
Or Not equalUnoObjects(objFoo
, outUnknown
) Or _
141 inDecimal
<> outDecimal
Then
147 'in-out parameter -------------------------------------------------------------
148 'implementation of inout methods returns the previously set value in out param
151 obj
.inoutBool(inBool2
)
153 obj
.inoutBool(outBool
)
156 obj
.inoutByte(inByte2
)
158 obj
.inoutByte(outByte
)
161 obj
.inShort(inShort2
)
163 obj
.inoutShort(outShort
)
166 obj
.inoutLong(inLong2
)
168 obj
.inoutLong(outLong
)
171 obj
.inoutFloat(inFloat2
)
173 obj
.inoutFloat(outFloat
)
176 obj
.inoutDouble(inDouble2
)
178 obj
.inoutDouble(outDouble
)
181 obj
.inoutString(inString2
)
183 obj
.inoutString(outString
)
185 inVariant2
= inVariant
186 obj
.inoutVariant(inVariant2
)
188 obj
.inoutVariant(outVariant
)
189 inObject
= factory
.createInstance("AxTestComponents.Basic")
191 obj
.inoutObject(inObject2
)
193 obj
.inoutObject(outObject
)
196 obj
.inoutArray(inAr2
)
198 obj
.outArray(outArray())
201 obj
.inoutDate(inDate2
)
203 obj
.inoutDate(outDate
)
204 inCurrency
= 1234.5678
205 inCurrency2
= inCurrency
206 obj
.inoutCurrency(inCurrency2
)
208 obj
.inoutCurrency(outCurrency
)
209 inSCode
.Value
= &h80020004
211 obj
.inoutSCode(inSCode2
)
213 obj
.inoutSCode(outSCode
)
215 inUnknown2
= inUnknown
216 obj
.inoutUnknown(inUnknown2
)
218 obj
.inoutUnknown(outUnknown
)
219 inDecimal
= CDec("18446744073709551615") 'highest positive value of unsigned int64
220 inDecimal2
= inDecimal
221 obj
.inoutDecimal(inDecimal2
)
223 obj
.inoutDecimal(outDecimal
)
225 If inBool
<> outBool
Or inByte
<> outByte
Or inShort
<> outShort
Or inLong
<> outLong
Or _
226 inFloat
<> outFloat
Or inDouble
<> outDouble
Or inString
<> outString
Or _
227 inVariant
<> outVariant
Or NOT equalUnoObjects(inObject
, outObject
) Or _
228 NOT equalArrays(inAr
, outArray
) Or inDate
<> outDate
Or inCurrency
<> outCurrency
Or _
229 inSCode
.Value
<> outSCode
.Value
Or Not equalUnoObjects(inUnknown
, outUnknown
) Or _
230 inDecimal
<> outDecimal
Then
235 'properties -------------------------------------------------------------------------
239 outBool
= obj
.prpBool
246 obj
.prpShort
= inShort
247 outShort
= obj
.prpShort
254 obj
.prpFloat
= inFloat
255 outFloat
= obj
.prpFloat
258 obj
.prpDouble
= inDouble
259 outDouble
= obj
.prpDouble
262 obj
.prpString
= inString
263 outString
= obj
.prpString
265 outObject
= objNOTHING
266 obj
.prpObject
= inObject
267 outObject
= obj
.prpObject
270 obj
.prpVariant
= inVariant
271 outVariant
= obj
.prpVariant
274 obj
.prpArray
= inArray()
275 outArray
= obj
.prpArray
279 outDate
= obj
.prpDate
280 inCurrency
= 1234.5678
282 obj
.prpCurrency
= inCurrency
283 outCurrency
= obj
.prpCurrency
284 inSCode
.Value
= &h80020004
286 obj
.prpSCode
= inSCode
287 outSCode
= obj
.prpSCode
290 obj
.prpUnknown
= inUnknown
291 outUnknown
= obj
.prpUnknown
292 inDecimal
= CDec("18446744073709551615")' highest unsigned int64
294 obj
.prpDecimal
= inDecimal
295 outDecimal
= obj
.prpDecimal
297 If inBool
<> outBool
Or inByte
<> outByte
Or inShort
<> outShort
Or inLong
<> outLong
Or _
298 inFloat
<> outFloat
Or inDouble
<> outDouble
Or inString
<> outString
Or _
299 inVariant
<> outVariant
Or NOT equalUnoObjects(inObject
, outObject
) Or _
300 NOT equalArrays(inArray
, outArray
) Or inDate
<> outDate
Or inCurrency
<> outCurrency
Or _
301 inSCode
.Value
<> outSCode
.Value
Or Not equalUnoObjects(inUnknown
, outUnknown
) Or _
302 inDecimal
<> outDecimal
Then
307 ' ref parameter ------------------------------------------------------------------------
312 obj
.inrefLong(inLong
)
317 obj
.inrefVariant(inVariant
)
318 obj
.outVariant(outVariant
)
319 If inLong
<> outLong
Or inVariant
<> outVariant
Then
325 obj
.prprefLong
= inLong
326 outLong
= obj
.prprefLong
328 obj
.prprefVariant
= inVariant
329 outVariant
= obj
.prprefVariant
330 If inLong
<> outLong
Or inVariant
<> outVariant
Then
336 'vararg --------------------------------------------------------------------------------
340 obj
.varargfunc1(inLong
)
343 obj
.varargfunc2(outLong
, outArray
)
344 If inLong
<> outLong
Then
348 len1
= UBound(outArray
) - LBound(outArray
) +1
354 obj
.varargfunc1(inLong
, inLong2
, inLong3
)
355 obj
.varargfunc2(outLong
, outArray
)
356 len1
= UBound(outArray
) - LBound(outArray
) +1
357 If len1
<> 2 Or outArray(0) <> inLong2
Or outArray(1) <> inLong3
Then
363 'defaultvalue ---------------------------------------------------------------------------
368 'defaults are: 1, 2, 4
369 'The third parameter is a VARIANT with a default value of 4. COM gives it the type BSTR
371 obj
.defaultvalue2(inLong
, inFloat
, inVariant
)
372 If inLong
<> 1 Or inFloat
<> 2 Or inVariant
<> "4" Then
382 obj
.defaultvalue1(inLong
, inFloat
)
383 obj
.defaultvalue2(inLong
, inFloat
, inVariant
)
384 If inLong
<> inLong2
Or inFloat
<> inFloat2
Or inVariant
<> "4" Then
389 'optional parameters ----------------------------------------------------------------
392 obj
.optional1(inLong
)
393 obj
.optional2(outLong
)
394 If inLong
<> outLong
Then
401 obj
.optional1(inLong
, inLong2
)
402 obj
.optional2(outLong
, outLong2
)
403 If inLong
<> outLong
AND inLong2
<> outLong2
Then
410 obj
.optional1(inLong
, inLong2
)
411 obj
.optional1(inLong
)
412 obj
.optional2(outLong
, outLong2
)
413 If inLong
<> outLong
AND inLong2
<> outLong2
Then
423 obj
.optional3(inLong
, inLong2
)
424 obj
.optional4(outLong
, outLong2
) 'outLong = 10, outLong2 = 100
425 If inLong
<> outLong
AND inLong2
<> outLong2
Then
433 obj
.optional4(inLong
, inLong
)
436 obj
.optional5(outLong
, outLong2
)
437 If inLong3
<> outLong
AND inLong4
<> outLong2
Then
444 obj
.optional3(inLong
)
445 obj
.optional4(outLong
)
446 If inLong
<> outLong
Then
453 obj
.optional4(inLong
)
454 obj
.optional5(outLong
)
455 If inLong2
<> outLong
Then
460 'named arguments-------------------------------------------------------------------------
461 'all args As named args, different order
462 obj
.optional6(0, 0, 0, 0)
467 obj
.optional6(val4
:= inLong4
, val3
:=inLong3
, val2
:=inLong2
, val1
:= inLong
)
474 obj
.optional7(outLong
, outLong2
, outLong3
, outLong4
)
475 If inLong
<> outLong
Or inLong2
<> outLong2 _
476 Or inLong3
<> outLong3
Or inLong4
<> outLong4
Then
481 'mixed positional and named args with omitted args
482 Dim scode_paramNotFound
As New com
.sun
.star
.bridge
.oleautomation
.SCode
483 scode_paramNotFound
.Value
= &h80020004
485 obj
.optional6(0, 0, 0, 0)
486 'val1 and val3 will be DISP_E_PARAMNOTFOUND
487 obj
.optional6(, inLong2
, val4
:=inLong4
)
488 Dim outSCode1
, outSCode2
489 obj
.optional7(outSCode
, outLong2
, outSCode2
, outLong4
)
490 If outSCode
.Value
<> scode_paramNotFound
.Value
Or inLong2
<> outLong2 _
491 Or outSCode2
.Value
<> scode_paramNotFound
.Value
Or inLong4
<> outLong4
Then
496 'mixed positional and named args with omitted args as out -args
501 obj
.optional6(inLong
, inLong2
, inLong3
, inLong4
)
504 obj
.optional7(,outLong2
, val3
:= outLong3
)
505 If inLong2
<> outLong2
Or inLong3
<> outLong3
Then
510 'test properties with additional arguments ------------------------------------
517 obj
.prpMultiArg1(0,0) = 0
518 'obj.prpMultiArg1 = 0
519 obj
.prpMultiArg1(inLong
,inLong2
) = inLong3
520 outLong3
= obj
.prpMultiArg1(outLong
, outLong2
)
521 If outLong
<> 10 Or outLong2
<> 02 Or outLong3
<> 30 Then
528 obj
.prpMultiArg1(0,0) = 0
529 obj
.prpMultiArg1(1) = 3
530 outLong2
= obj
.prpMultiArg1(outLong
)
531 If outLong
<> 1 Or outLong2
<> 3 Then
538 obj
.prpMultiArg1(0,0) = 0
539 obj
.prpMultiArg1(val2
:= 1) = 3
540 outLong2
= obj
.prpMultiArg1(val2
:=outLong
)
541 If outLong
<> 1 Or outLong2
<> 3 Then
548 obj
.prpMultiArg2(0) = 0
549 outLong
= obj
.prpMultiArg2GetValues(outLong
, outLong2
)
550 If outLong
<> 0 Or outLong2
<> 0 Then
558 obj
.prpMultiArg2(1) = 2
559 obj
.prpMultiArg2GetValues(outLong
, outLong2
)
560 If outLong
<> 1 Or outLong2
<> 2 Then
567 ' other tests ------------------------------------------------------------------
568 obj
.inObject(NOTHING)
570 'bridge should return an XInterface any with null pointer
571 'A basic errOr should occur if this is not the case
572 obj
.outObject(outObject
)
574 If Not IsNull(outObject
) Then
578 'Decimal passed by reference
579 inrefDecimal
= CDec("9223372036854775807") 'highest positive value of int64
580 obj
.inrefDecimal(inrefDecimal
)
582 obj
.outDecimal(outrefDecimal
)
583 If inrefDecimal
<> outrefDecimal
Then
588 ' Test Automation object with dual interfaces ------------------------------------
589 dim dispatcher
as object
590 dim oExplorer
as object
591 dispatcher
= createUnoService("com.sun.star.bridge.OleObjectFactory")
592 oExplorer
= dispatcher
.createInstance("InternetExplorer.Application")
593 If Not IsNull(oExplorer
) Then
594 oExplorer
.visible
= true
595 oExplorer
.Navigate2("http://www.openoffice.org")
597 MsgBox("Could not perform test with Internet Explorer!")
603 'One dimensional arrays with simple types.
604 'lower bound must be 0
605 Function equalArrays(ar1
, ar2
)
608 len1
= UBound(ar1
) - LBound(ar1
) + 1
609 len2
= UBound(ar2
) - LBound(ar2
) + 1
615 FOr counter
= 0 To len1
- 1
616 If ar1(counter
) <> ar2(counter
) Then