Version 6.4.0.3, tag libreoffice-6.4.0.3
[LibreOffice.git] / extensions / test / ole / StarBasic_OleClient / oleclient.bas
blobe640d434d2409770ad1850621d373ad8e7792187
1 rem
2 rem This file is part of the LibreOffice project.
3 rem
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/.
7 rem
8 rem This file incorporates work covered by the following license notice:
9 rem
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 .
17 rem
19 OPTION EXPLICIT
20 OPTION COMPATIBLE
22 Sub Main
23 COMPATIBILITYMODE(true)
25 If runtest = -1 Then
26 MsgBox "Test Failed!!!"
27 Else
28 MsgBox "Test Succeeded"
29 End If
31 End Sub
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
42 Dim inAr, inAr2
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
56 Dim outVariant
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
63 Dim len1, len2
64 Dim arString(1) As String
65 arString(0)= "String one"
66 arString(1)= "String two"
68 Dim factory As Object
69 factory= createUnoService("com.sun.star.bridge.OleObjectFactory")
70 Dim obj As Object
71 obj= factory.createInstance("AxTestComponents.Basic")
73 Dim objFoo As Object
74 objFoo = factory.createInstance("AxTestComponents.Foo")
77 'in parameter -------------------------------------------------------------------
78 inBool = true
79 inByte = 10
80 inShort = 11
81 inLong = 111
82 inString = "Hello World"
83 inFloat = 3.14
84 inDouble = 3.145
85 inVariant = "bla"
86 inDate = NOW()
87 inCurrency = 12345.6789
88 inSCode.Value = &h80020004
89 inDecimal = CDec("-9223372036854775808") 'lowest int64
91 obj.inBool(inBool)
92 obj.inByte(inByte)
93 obj.inShort(inShort)
94 obj.inLong(inLong)
95 obj.inString(inString)
96 obj.inFloat(inFloat)
97 obj.inDouble(inDouble)
98 obj.inVariant(inVariant)
99 'obj.prpString= "a string property"
100 obj.inObject(obj)
101 obj.inArray(arString())
102 obj.inDate(inDate)
103 obj.inCurrency(inCurrency)
104 obj.inSCode(inSCode)
105 obj.inUnknown(objFoo)
106 obj.inDecimal(inDecimal)
108 'out parameter -------------------------------------------------------------------------
109 outBool = false
110 obj.outBool(outBool)
111 outByte = 0
112 obj.outByte(outByte)
113 outShort = 0
114 obj.outShort(outShort)
115 outLong = 0
116 obj.outLong(outLong)
117 outFloat = 0
118 obj.outFloat(outFloat)
119 outDouble = 0
120 obj.outDouble(outDouble)
121 outString = ""
122 obj.outString(outString)
123 outVariant = 0
124 obj.outVariant(outVariant)
125 outObject = NOTHING
126 obj.outObject(outObject)
127 outArray = 0
128 obj.outArray(outArray)
129 obj.outDate(outDate)
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
142 runtest = -1
143 exit Function
144 End If
147 'in-out parameter -------------------------------------------------------------
148 'implementation of inout methods returns the previously set value in out param
149 inBool = true
150 inBool2 = inBool
151 obj.inoutBool(inBool2)
152 outBool = false
153 obj.inoutBool(outBool)
154 inByte = 10
155 inByte2 = inByte
156 obj.inoutByte(inByte2)
157 outByte = 0
158 obj.inoutByte(outByte)
159 inShort = 10
160 inShort2 = inShort
161 obj.inShort(inShort2)
162 outShort = 0
163 obj.inoutShort(outShort)
164 inLong = 10
165 inLong2 = inLong
166 obj.inoutLong(inLong2)
167 outLong = 0
168 obj.inoutLong(outLong)
169 inFloat = 3.14
170 inFloat2 = inFloat
171 obj.inoutFloat(inFloat2)
172 outFloat = 0
173 obj.inoutFloat(outFloat)
174 inDouble= 3.14
175 inDouble2 = inDouble
176 obj.inoutDouble(inDouble2)
177 outDouble = 0
178 obj.inoutDouble(outDouble)
179 inString = "in"
180 inString2 = inString
181 obj.inoutString(inString2)
182 outString = ""
183 obj.inoutString(outString)
184 inVariant = "in"
185 inVariant2 = inVariant
186 obj.inoutVariant(inVariant2)
187 outVariant = 0
188 obj.inoutVariant(outVariant)
189 inObject = factory.createInstance("AxTestComponents.Basic")
190 inObject2 = inObject
191 obj.inoutObject(inObject2)
192 outObject = NOTHING
193 obj.inoutObject(outObject)
194 inAr = arString()
195 inAr2 = inAr
196 obj.inoutArray(inAr2)
197 outArray = 0
198 obj.outArray(outArray())
199 inDate = NOW()
200 inDate2 = inDate
201 obj.inoutDate(inDate2)
202 outDate = 0
203 obj.inoutDate(outDate)
204 inCurrency = 1234.5678
205 inCurrency2 = inCurrency
206 obj.inoutCurrency(inCurrency2)
207 outCurrency = 0
208 obj.inoutCurrency(outCurrency)
209 inSCode.Value = &h80020004
210 inSCode2 = inSCode
211 obj.inoutSCode(inSCode2)
212 outSCode.Value = 0
213 obj.inoutSCode(outSCode)
214 inUnknown = objFoo
215 inUnknown2 = inUnknown
216 obj.inoutUnknown(inUnknown2)
217 outUnknown = Nothing
218 obj.inoutUnknown(outUnknown)
219 inDecimal = CDec("18446744073709551615") 'highest positive value of unsigned int64
220 inDecimal2 = inDecimal
221 obj.inoutDecimal(inDecimal2)
222 outDecimal = 0
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
231 runtest = -1
232 Exit Function
233 End If
235 'properties -------------------------------------------------------------------------
236 inBool = false
237 outBool = true
238 obj.prpBool = inBool
239 outBool = obj.prpBool
240 inByte = 11
241 outByte = 0
242 obj.prpByte = inByte
243 outByte= obj.prpByte
244 inShort = 127
245 outShort = 0
246 obj.prpShort= inShort
247 outShort= obj.prpShort
248 inLong = 1000
249 outLong = 0
250 obj.prpLong = inLong
251 outLong= obj.prpLong
252 inFloat = 3.14
253 outFloat = 0
254 obj.prpFloat = inFloat
255 outFloat= obj.prpFloat
256 inDouble = 3.123
257 outDouble = 0
258 obj.prpDouble = inDouble
259 outDouble= obj.prpDouble
260 inString = "bla"
261 outString = ""
262 obj.prpString = inString
263 outString = obj.prpString
264 inObject = obj
265 outObject = objNOTHING
266 obj.prpObject = inObject
267 outObject = obj.prpObject
268 inVariant = "bla"
269 outVariant = 0
270 obj.prpVariant = inVariant
271 outVariant= obj.prpVariant
272 inArray = arString()
273 outArray = 0
274 obj.prpArray = inArray()
275 outArray= obj.prpArray
276 inDate = NOW()
277 outDate = 0
278 obj.prpDate = inDate
279 outDate = obj.prpDate
280 inCurrency = 1234.5678
281 outCurrency = 0
282 obj.prpCurrency = inCurrency
283 outCurrency = obj.prpCurrency
284 inSCode.Value = &h80020004
285 outSCode.Value = 0
286 obj.prpSCode = inSCode
287 outSCode = obj.prpSCode
288 inUnknown = objFoo
289 outUnknown= Nothing
290 obj.prpUnknown = inUnknown
291 outUnknown = obj.prpUnknown
292 inDecimal = CDec("18446744073709551615")' highest unsigned int64
293 outDecimal = 0
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
303 runtest = -1
304 Exit Function
305 End If
307 ' ref parameter ------------------------------------------------------------------------
308 obj.inLong(0)
309 inLong = 123
310 outLong = 0
311 obj.inLong(0)
312 obj.inrefLong(inLong)
313 obj.outLong(outLong)
314 inVariant = "bla"
315 outVariant = 0
316 obj.inVariant(0)
317 obj.inrefVariant(inVariant)
318 obj.outVariant(outVariant)
319 If inLong <> outLong Or inVariant <> outVariant Then
320 runtest = -1
321 Exit Function
322 End If
324 outLong = 0
325 obj.prprefLong = inLong
326 outLong = obj.prprefLong
327 outVariant = 0
328 obj.prprefVariant = inVariant
329 outVariant = obj.prprefVariant
330 If inLong <> outLong Or inVariant <> outVariant Then
331 runtest = -1
332 Exit Function
333 End If
336 'vararg --------------------------------------------------------------------------------
337 inLong=1
338 inLong2 = 2
339 inLong3 = 3
340 obj.varargfunc1(inLong)
341 outArray = 0
342 outLong = 0
343 obj.varargfunc2(outLong, outArray)
344 If inLong <> outLong Then
345 runtest = -1
346 Exit Function
347 End If
348 len1 = UBound(outArray) - LBound(outArray) +1
349 If len1 <> 0 Then
350 runtest = -1
351 Exit Function
352 End If
353 outArray = 0
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
358 runtest = -1
359 Exit Function
360 End If
363 'defaultvalue ---------------------------------------------------------------------------
364 inLong = 0
365 inFloat = 0
366 inVariant = 0
367 inVariant2 = 0
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
370 obj.defaultvalue1()
371 obj.defaultvalue2(inLong, inFloat, inVariant)
372 If inLong <> 1 Or inFloat <> 2 Or inVariant <> "4" Then
373 runtest = -1
374 Exit Function
375 End If
376 inLong = 10
377 inFloat = 11
378 inLong2 = inLong
379 inFloat2 = inFloat
380 inVariant = 0
381 inVariant = 0
382 obj.defaultvalue1(inLong, inFloat)
383 obj.defaultvalue2(inLong, inFloat, inVariant)
384 If inLong <> inLong2 Or inFloat <> inFloat2 Or inVariant <> "4" Then
385 runtest = -1
386 Exit Function
387 End If
389 'optional parameters ----------------------------------------------------------------
390 inLong = 100
391 outLong = 0
392 obj.optional1(inLong)
393 obj.optional2(outLong)
394 If inLong <> outLong Then
395 runtest = -1
396 Exit Function
397 End If
399 inLong2 = 101
400 outLong2 = 0
401 obj.optional1(inLong, inLong2)
402 obj.optional2(outLong, outLong2)
403 If inLong <> outLong AND inLong2 <> outLong2 Then
404 runtest = -1
405 Exit Function
406 End If
408 inLong2 = 101
409 outLong2 = 0
410 obj.optional1(inLong, inLong2)
411 obj.optional1(inLong)
412 obj.optional2(outLong, outLong2)
413 If inLong <> outLong AND inLong2 <> outLong2 Then
414 runtest = -1
415 Exit Function
416 End If
418 inLong = 10
419 inLong2 = 100
420 outLong = 5
421 outLong2 = 6
422 obj.optional3()
423 obj.optional3(inLong, inLong2)
424 obj.optional4(outLong, outLong2) 'outLong = 10, outLong2 = 100
425 If inLong <> outLong AND inLong2 <> outLong2 Then
426 runtest = -1
427 Exit Function
428 End If
429 inLong = 10
430 inLong2 = 100
431 inLong3 = inLong
432 inLong4 = inLong2
433 obj.optional4(inLong, inLong)
434 outLong = 0
435 outLong2 = 0
436 obj.optional5(outLong, outLong2)
437 If inLong3 <> outLong AND inLong4 <> outLong2 Then
438 runtest = -1
439 Exit Function
440 End If
442 inLong = 10
443 outLong = 5
444 obj.optional3(inLong)
445 obj.optional4(outLong)
446 If inLong <> outLong Then
447 runtest = -1
448 Exit Function
449 End If
450 inLong = 10
451 inLong2 = inLong
452 outLong = 0
453 obj.optional4(inLong)
454 obj.optional5(outLong)
455 If inLong2 <> outLong Then
456 runtest = -1
457 Exit Function
458 End If
460 'named arguments-------------------------------------------------------------------------
461 'all args As named args, different order
462 obj.optional6(0, 0, 0, 0)
463 inLong = 1
464 inLong2 = 2
465 inLong3 = 3
466 inLong4 = 4
467 obj.optional6(val4:= inLong4, val3:=inLong3, val2:=inLong2, val1:= inLong)
468 Dim outLong3 As Long
469 Dim outLong4 As Long
470 outLong = 0
471 outLong2 = 0
472 outLong3 = 0
473 outLong4 = 0
474 obj.optional7(outLong, outLong2, outLong3, outLong4)
475 If inLong <> outLong Or inLong2 <> outLong2 _
476 Or inLong3 <> outLong3 Or inLong4 <> outLong4 Then
477 runtest = -1
478 Exit Function
479 End If
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
492 runtest = -1
493 Exit Function
494 End If
496 'mixed positional and named args with omitted args as out -args
497 inLong = 1
498 inLong2 = 2
499 inLong3 = 3
500 inLong4 = 4
501 obj.optional6(inLong, inLong2, inLong3, inLong4)
502 outLong2 = 0
503 outLong3 = 0
504 obj.optional7(,outLong2, val3:= outLong3)
505 If inLong2 <> outLong2 Or inLong3 <> outLong3 Then
506 runtest = -1
507 Exit Function
508 End If
510 'test properties with additional arguments ------------------------------------
511 inLong = 10
512 inLong2 = 20
513 inLong3 = 30
514 outLong = 0
515 outLong2 = 0
516 outLong3 = 0
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
522 runtest = -1
523 Exit Function
524 End If
526 outLong = 0
527 outLong2 = 0
528 obj.prpMultiArg1(0,0) = 0
529 obj.prpMultiArg1(1) = 3
530 outLong2 = obj.prpMultiArg1(outLong)
531 If outLong <> 1 Or outLong2 <> 3 Then
532 runtest = -1
533 Exit Function
534 End If
536 outLong = 0
537 outLong2 = 0
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
542 runtest = -1
543 Exit Function
544 End If
546 outLong = -1
547 outLong2 = -1
548 obj.prpMultiArg2(0) = 0
549 outLong = obj.prpMultiArg2GetValues(outLong, outLong2)
550 If outLong <> 0 Or outLong2 <> 0 Then
551 runtest = -1
552 Exit Function
553 End If
556 outLong = 0
557 outLong2 = 0
558 obj.prpMultiArg2(1) = 2
559 obj.prpMultiArg2GetValues(outLong, outLong2)
560 If outLong <> 1 Or outLong2 <> 2 Then
561 runtest = -1
562 Exit Function
563 End If
567 ' other tests ------------------------------------------------------------------
568 obj.inObject(NOTHING)
569 outObject = 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
575 runtest = -1
576 Exit Function
577 End If
578 'Decimal passed by reference
579 inrefDecimal = CDec("9223372036854775807") 'highest positive value of int64
580 obj.inrefDecimal(inrefDecimal)
581 outrefDecimal = 0
582 obj.outDecimal(outrefDecimal)
583 If inrefDecimal <> outrefDecimal Then
584 runtest = -1
585 Exit Function
586 End If
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")
596 Else
597 MsgBox("Could not perform test with Internet Explorer!")
598 End If
601 End Function
603 'One dimensional arrays with simple types.
604 'lower bound must be 0
605 Function equalArrays(ar1, ar2)
606 Dim len1
607 Dim len2
608 len1 = UBound(ar1) - LBound(ar1) + 1
609 len2 = UBound(ar2) - LBound(ar2) + 1
610 If len1 <> len2 Then
611 equalArrays = false
612 Exit Function
613 End If
614 Dim counter
615 FOr counter = 0 To len1 - 1
616 If ar1(counter) <> ar2(counter) Then
617 equalArrays = false
618 Exit Function
619 End If
620 Next
621 equalArrays = true
622 End Function