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