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