summaryrefslogtreecommitdiffstats
path: root/testtools/source/bridgetest/cli/cli_vb_bridgetest.vb
blob: 9b55cad6ee16fd4946bed0499290a55b13ea3b41 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
'
' This file is part of the LibreOffice project.
'
' This Source Code Form is subject to the terms of the Mozilla Public
' License, v. 2.0. If a copy of the MPL was not distributed with this
' file, You can obtain one at http://mozilla.org/MPL/2.0/.
'
' This file incorporates work covered by the following license notice:
'
'   Licensed to the Apache Software Foundation (ASF) under one or more
'   contributor license agreements. See the NOTICE file distributed
'   with this work for additional information regarding copyright
'   ownership. The ASF licenses this file to you under the Apache
'   License, Version 2.0 (the "License"); you may not use this file
'   except in compliance with the License. You may obtain a copy of
'   the License at http://www.apache.org/licenses/LICENSE-2.0 .
'

Option Explicit On
Option Strict On

imports System
imports uno
imports uno.util
imports unoidl.com.sun.star.lang
imports unoidl.com.sun.star.uno
'imports unoidl.com.sun.star.test.bridge
imports unoidl.test.testtools.bridgetest
imports System.Windows.Forms
imports System.Diagnostics
imports System.Reflection

Class CONSTANTS
Friend Shared STRING_TEST_CONSTANT As String  = """ paco\' chorizo\\\' ""\'"
End Class

Namespace foo

    Public Interface MyInterface
    End Interface
End Namespace

Namespace vb_bridetest
Class ORecursiveCall
    Inherits WeakBase
    Implements XRecursiveCall
    
    Overridable Sub callRecursivly(xCall As XRecursiveCall, nToCall As Integer) _
    Implements XRecursiveCall.callRecursivly
		SyncLock Me
            If nToCall > 0
                nToCall = nToCall - 1
                xCall.callRecursivly(Me, nToCall)
            End If
       End SyncLock    
    End Sub
End Class
        



Public Class BridgeTest
       Inherits uno.util.WeakBase
       Implements XMain

    Private m_xContext As XComponentContext

    Public Sub New( xContext As unoidl.com.sun.star.uno.XComponentContext )
        mybase.New()
        m_xContext = xContext
    End Sub

    Private Shared Function check( b As Boolean , message As String  ) As Boolean
        If Not b
            Console.WriteLine("{0} failed\n" , message)
        End If
        Return b
    End Function

    Private Shared Sub assign( rData As TestElement, bBool As Boolean, _
			aChar As Char, nByte As Byte, nShort As Short, nUShort As UInt16, _
					nLong As Integer, nULong As UInt32, nHyper As Long, _
                    nUHyper As UInt64, fFloat As Single, fDouble As Double, _
					eEnum As TestEnum, rStr As String, xTest As Object, _
					rAny As Any)

    	rData.Bool = bBool
	    rData.Char = aChar
	    rData.Byte = nByte
	    rData.Short = nShort
	    rData.UShort = nUShort
	    rData.Long = nLong
	    rData.ULong = nULong
	    rData.Hyper = nHyper
	    rData.UHyper = nUHyper
	    rData.Float = fFloat
	    rData.Double = fDouble
	    rData.Enum = eEnum
	    rData.String = rStr
	    rData.Interface = xTest
	    rData.Any = rAny
    End Sub

    Private Shared Sub assign( rData As TestDataElements, bBool As Boolean, _
            aChar As Char, nByte As Byte, nShort As Short, nUShort As UInt16, _
			nLong As Integer, nULong As UInt32, nHyper As Long, _
            nUHyper As UInt64, fFloat As Single, fDouble As Double, _
    		eEnum As TestEnum, rStr As String, xTest As Object, _
			rAny As Any, rSequence() As TestElement)

    	assign( DirectCast( rData,TestElement), _
			bBool, aChar, nByte, nShort, nUShort, nLong, nULong, nHyper, _
            nUHyper, fFloat, fDouble, eEnum, rStr, xTest, rAny )
	    rData.Sequence = rSequence
    End Sub

	Private Shared Function compareData(val1 As Object, val2 As Object) As Boolean	
		If val1 Is Nothing And val2 Is Nothing OrElse _
            val1 Is val2
			Return True
        End If
		If  val1 Is Nothing And Not(val2 Is Nothing)  OrElse _
		    Not (val1 Is Nothing) And val2 Is Nothing OrElse _
            Not val1.GetType().Equals( val2.GetType())
			Return False
		End If			

		Dim ret As Boolean = False
		Dim t1 As Type = val1.GetType()
        'Sequence
		If t1.IsArray()
			ret = compareSequence(DirectCast( val1, Array), _
                  DirectCast( val2, Array))
		'String
		ElseIf TypeOf val1 Is String
			ret = DirectCast( val1, string) = DirectCast( val2, string)
		' Interface implementation
		ElseIf t1.GetInterfaces().Length > 0 And Not t1.IsValueType
			ret = val1 Is val2
		' Struct	
		ElseIf  Not t1.IsValueType
			ret = compareStruct(val1, val2)
		ElseIf TypeOf val1 Is Any
			Dim a1 As Any = DirectCast( val1, Any)
			Dim a2 As Any = DirectCast( val2, Any)
			ret = a1.Type.Equals( a2.Type ) And compareData( a1.Value, a2.Value )
		ElseIf t1.IsValueType
			'Any, enum, int, bool char, float, double etc.
			ret = val1.Equals(val2)
		Else
			Debug.Assert(False)
		End If
		Return ret
	End Function

	' Arrays have only one dimension
	Private Shared Function compareSequence( ar1 As Array, ar2 As Array) As Boolean
		Debug.Assert( Not (ar1 Is Nothing) And Not (ar2 Is Nothing) )
		Dim t1 As Type  = ar1.GetType()
		Dim t2 As Type  = ar2.GetType()
		
		if ( Not(ar1.Rank = 1 And ar2.Rank = 1 _
			And ar1.Length = ar2.Length And t1.GetElementType().Equals(t2.GetElementType())))
			return False
        End If
		'arrays have same rank and size and element type.
		Dim len As Integer  = ar1.Length
		Dim elemType As Type = t1.GetElementType()
		Dim ret As Boolean = True
        Dim i As Integer
		For i = 0 To len - 1
			If (compareData(ar1.GetValue(i), ar2.GetValue(i)) = False)
				ret = False
				Exit For
			End If
		Next i
		
        Return ret
	End Function

	Private Shared Function compareStruct( val1 As Object, val2 As Object) As Boolean
		Debug.Assert( Not(val1 Is Nothing) And Not(val2 Is Nothing))
		Dim t1 As Type = val1.GetType()
		Dim t2 As Type = val2.GetType()
		If Not t1.Equals(t2)
			Return False
        End If
		Dim fields() As FieldInfo = t1.GetFields()
		Dim cFields As Integer = fields.Length
		Dim ret As Boolean = True
        Dim i As Integer
		For i = 0 To cFields - 1
			Dim fieldVal1 As Object = fields(i).GetValue(val1)
			Dim fieldVal2 As Object = fields(i).GetValue(val2)
			If Not compareData(fieldVal1, fieldVal2)
				ret = False
				Exit For
			End If
		Next i
		Return ret
	End Function


    Private Shared Function performSequenceTest(xBT As XBridgeTest) As Boolean
        Dim bRet As Boolean = True
        'Automati cast ?? like with COM objects
        Dim xBT2 As XBridgeTest2 
        Try
            xBT2 = DirectCast(xBT,XBridgeTest2)
        Catch e As InvalidCastException
            Return False
        End Try

        ' perform sequence tests (XBridgeTest2)
        'create the sequence which are compared with the results
        Dim arBool() As Boolean = {True, False, True}
        Dim arChar() As Char = {"A"C,"B"C,"C"C}
        Dim arByte() As Byte = { 1,  2,  &Hff}
        Dim arShort() As Short = {Int16.MinValue, 1,  Int16.MaxValue}
        Dim arUShort() As UInt16 = {Convert.ToUInt16(0), Convert.ToUInt16(1), _
                                    Convert.ToUInt16(&Hffff)}
        Dim arLong() As Integer = {Int32.MinValue, 1, Int32.MaxValue}
        Dim arULong() As UInt32 = {Convert.ToUInt32(0), Convert.ToUInt32(1), _
                                   Convert.ToUInt32(&HffffffffL)}
        Dim arHyper() As Long = {Int64.MinValue, 1, Int64.MaxValue}
        Dim arUHyper() As UInt64 = {Convert.ToUInt64(0), Convert.ToUInt64(1), _
                                    Convert.ToUInt64(&Hffffffff5L)}
        Dim arFloat() As Single = {1.1f, 2.2f, 3.3f}
        Dim arDouble() As Double = {1.11, 2.22, 3.33}
        Dim arString() As String = {"String 1", "String 2", "String 3"}

        Dim arAny() As Any = {New Any(True), New Any(11111), New Any(3.14)}
        Dim arObject() As Object = {New WeakBase(), New WeakBase(), New WeakBase()}
        Dim arEnum() As TestEnum = {TestEnum.ONE, TestEnum.TWO, TestEnum.CHECK}

        Dim arStruct() As TestElement = {New TestElement(), New TestElement(), _
                               New TestElement()}
        assign( arStruct(0), True, "@"C, 17, &H1234, Convert.ToUInt16(&Hfedc), _
            &H12345678, Convert.ToUInt32(&H123456), &H123456789abcdef0, _
            Convert.ToUInt64(123456788), 17.0815F, 3.1415926359, _
            TestEnum.LOLA, CONSTANTS.STRING_TEST_CONSTANT, arObject(0), _
            New Any(GetType(System.Object), arObject(0)))
        assign( arStruct(1), True, "A"C, 17, &H1234, Convert.ToUInt16(&Hfedc), _
            &H12345678, Convert.ToUInt32(&H123456), &H123456789abcdef0, _
            Convert.ToUInt64(12345678), 17.0815F, 3.1415926359, _
            TestEnum.TWO, CONSTANTS.STRING_TEST_CONSTANT, arObject(1), _
            New Any(GetType(System.Object), arObject(1)) )
        assign( arStruct(2), True, "B"C, 17, &H1234, Convert.ToUInt16(&Hfedc), _ 
            &H12345678, Convert.ToUInt32(654321), &H123456789abcdef0, _
            Convert.ToUInt64(87654321), 17.0815F, 3.1415926359, _ 
            TestEnum.CHECK, Constants.STRING_TEST_CONSTANT, arObject(2), _
            New Any(GetType(System.Object), arObject(2)))

    
        Dim arLong3()()() As Integer = New Integer()()() { _
        New Integer()(){New Integer(){1,2,3},New Integer(){4,5,6}, New Integer(){7,8,9} }, _
        New Integer ()(){New Integer(){1,2,3},New Integer(){4,5,6}, New Integer(){7,8,9}}, _
        New Integer()(){New Integer(){1,2,3},New Integer(){4,5,6}, New Integer(){7,8,9}}}

        Dim seqSeqRet()() As Integer = xBT2.setDim2(arLong3(0))
        bRet = check( compareData(seqSeqRet, arLong3(0)), "sequence test") _
               And bRet
        Dim seqSeqRet2()()() As Integer = xBT2.setDim3(arLong3)
        bRet = check( compareData(seqSeqRet2, arLong3), "sequence test") _
               And bRet
        Dim seqAnyRet() As Any = xBT2.setSequenceAny(arAny)
        bRet = check( compareData(seqAnyRet, arAny), "sequence test") And bRet
        Dim seqBoolRet() As Boolean = xBT2.setSequenceBool(arBool)
        bRet = check( compareData(seqBoolRet, arBool), "sequence test") _
               And bRet
        Dim seqByteRet() As Byte = xBT2.setSequenceByte(arByte)
        bRet = check( compareData(seqByteRet, arByte), "sequence test") _
               And bRet
        Dim seqCharRet() As Char = xBT2.setSequenceChar(arChar)
        bRet = check( compareData(seqCharRet, arChar), "sequence test") _
                   And bRet
        Dim seqShortRet() As Short = xBT2.setSequenceShort(arShort)
        bRet = check( compareData(seqShortRet, arShort), "sequence test") _
               And bRet
        Dim seqLongRet() As Integer = xBT2.setSequenceLong(arLong)
        bRet = check( compareData(seqLongRet, arLong), "sequence test") _
                   And bRet
        Dim seqHyperRet() As Long = xBT2.setSequenceHyper(arHyper)
        bRet = check( compareData(seqHyperRet,arHyper), "sequence test") _
               And bRet
        Dim seqFloatRet() As Single = xBT2.setSequenceFloat(arFloat)
        bRet = check( compareData(seqFloatRet, arFloat), "sequence test") _ 
               And bRet
        Dim seqDoubleRet() As Double= xBT2.setSequenceDouble(arDouble)
        bRet = check( compareData(seqDoubleRet, arDouble), "sequence test") _
               And bRet
        Dim seqEnumRet() As TestEnum = xBT2.setSequenceEnum(arEnum)
        bRet = check( compareData(seqEnumRet, arEnum), "sequence test") _
               And bRet
        Dim seqUShortRet() As UInt16 = xBT2.setSequenceUShort(arUShort)
        bRet = check( compareData(seqUShortRet, arUShort), "sequence test") _ 
               And bRet
        Dim seqULongRet() As UInt32 = xBT2.setSequenceULong(arULong)
        bRet = check( compareData(seqULongRet, arULong), "sequence test") _
               And bRet
        Dim seqUHyperRet() As UInt64 = xBT2.setSequenceUHyper(arUHyper)
        bRet = check( compareData(seqUHyperRet, arUHyper), "sequence test") _
               And bRet
        Dim seqObjectRet() As Object = xBT2.setSequenceXInterface(arObject)
        bRet = check( compareData(seqObjectRet, arObject), "sequence test") _
               And bRet
        Dim seqStringRet() As String = xBT2.setSequenceString(arString)
        bRet = check( compareData(seqStringRet, arString), "sequence test") _
               And bRet
        Dim seqStructRet() As TestElement = xBT2.setSequenceStruct(arStruct)
        bRet = check( compareData(seqStructRet, arStruct), "sequence test") _
               And bRet
    
    
        Dim arBoolTemp() As Boolean = DirectCast(arBool.Clone(), Boolean())
        Dim arCharTemp() As Char = DirectCast(arChar.Clone(), Char())
        Dim arByteTemp() As Byte = DirectCast(arByte.Clone(), Byte())
        Dim arShortTemp() As Short = DirectCast(arShort.Clone(), Short())
        Dim arUShortTemp() As UInt16 = DirectCast(arUShort.Clone(), UInt16())
        Dim arLongTemp() As Integer= DirectCast(arLong.Clone(), Integer())
        Dim arULongTemp() As UInt32 =  DirectCast(arULong.Clone(), UInt32())
        Dim arHyperTemp() As Long = DirectCast(arHyper.Clone(), Long())
        Dim arUHyperTemp() As UInt64 = DirectCast(arUHyper.Clone(), UInt64())
        Dim arFloatTemp() As Single = DirectCast(arFloat.Clone(), Single())
        Dim arDoubleTemp() As Double = DirectCast(arDouble.Clone(), Double())
        Dim arEnumTemp() As TestEnum = DirectCast(arEnum.Clone(), TestEnum())
        Dim arStringTemp() As String = DirectCast(arString.Clone(), String())
        Dim arObjectTemp() As Object = DirectCast(arObject.Clone(), Object())
        Dim arAnyTemp() As Any = DirectCast(arAny.Clone(), Any())
        ' make sure this are has the same contents as arLong3(0)
        Dim arLong2Temp()() As Integer = New Integer()(){New Integer(){1,2,3}, _
                                         New Integer(){4,5,6}, New Integer(){7,8,9} }
        ' make sure this are has the same contents as arLong3
        Dim arLong3Temp()()() As Integer = New Integer()()(){ _
            New Integer()(){New Integer(){1,2,3},New Integer(){4,5,6}, New Integer(){7,8,9} }, _ 
            New Integer ()(){New Integer(){1,2,3},New Integer(){4,5,6}, New Integer(){7,8,9}}, _
            New Integer()(){New Integer(){1,2,3},New Integer(){4,5,6}, New Integer(){7,8,9}}}
        
        xBT2.setSequencesInOut( arBoolTemp, arCharTemp,  arByteTemp, _
                            arShortTemp,  arUShortTemp,  arLongTemp, _
                            arULongTemp, arHyperTemp,  arUHyperTemp, _
                            arFloatTemp, arDoubleTemp,  arEnumTemp, _
                            arStringTemp,   arObjectTemp, _
                             arAnyTemp,  arLong2Temp,  arLong3Temp)
        bRet = check( _
            compareData(arBoolTemp, arBool) And _
            compareData(arCharTemp , arChar) And _
            compareData(arByteTemp , arByte) And _
            compareData(arShortTemp , arShort) And _
            compareData(arUShortTemp , arUShort) And _
            compareData(arLongTemp , arLong) And _
            compareData(arULongTemp , arULong) And _
            compareData(arHyperTemp , arHyper) And _ 
            compareData(arUHyperTemp , arUHyper) And _
            compareData(arFloatTemp , arFloat) And _
            compareData(arDoubleTemp , arDouble) And _
            compareData(arEnumTemp , arEnum) And _
            compareData(arStringTemp , arString) And _
            compareData(arObjectTemp , arObject) And _
            compareData(arAnyTemp , arAny) And _ 
            compareData(arLong2Temp , arLong3(0)) And _
            compareData(arLong3Temp , arLong3), "sequence test") And bRet
        
        Dim arBoolOut() As Boolean
        Dim arCharOut() As Char
        Dim arByteOut() As Byte
        Dim arShortOut() As Short
        Dim arUShortOut() As UInt16
        Dim arLongOut() As Integer
        Dim arULongOut() As UInt32
        Dim arHyperOut() As Long
        Dim arUHyperOut() As UInt64
        Dim arFloatOut() As Single
        Dim arDoubleOut() As Double
        Dim arEnumOut() As TestEnum
        Dim arStringOut() As String
        Dim arObjectOut() As Object
        Dim arAnyOut() As Any
        Dim arLong2Out()() As Integer
        Dim arLong3Out()()() As Integer

        xBT2.setSequencesOut( arBoolOut,  arCharOut,  arByteOut, _ 
                             arShortOut,  arUShortOut,  arLongOut, _
                             arULongOut,  arHyperOut,  arUHyperOut, _
                             arFloatOut,  arDoubleOut,  arEnumOut, _
                             arStringOut,  arObjectOut,  arAnyOut, _
                             arLong2Out,  arLong3Out)
        bRet = check( _
            compareData(arBoolOut, arBool) And _
            compareData(arCharOut, arChar) And _
            compareData(arByteOut, arByte) And _
            compareData(arShortOut, arShort) And _
            compareData(arUShortOut, arUShort) And _
            compareData(arLongOut, arLong) And _
            compareData(arULongOut, arULong) And _
            compareData(arHyperOut, arHyper) And _
            compareData(arUHyperOut, arUHyper) And _
            compareData(arFloatOut, arFloat) And _
            compareData(arDoubleOut, arDouble) And _
            compareData(arEnumOut, arEnum) And _
            compareData(arStringOut, arString) And _
            compareData(arObjectOut, arObject) And _
            compareData(arAnyOut, arAny) And _
            compareData(arLong2Out, arLong3(0)) And _
            compareData(arLong3Out, arLong3), "sequence test") And bRet
        
        
        'test with empty sequences
        Dim _arLong2()() As Integer = New Integer()(){}
        seqSeqRet = xBT2.setDim2(_arLong2)
        bRet = check( compareData(seqSeqRet, _arLong2), "sequence test") And bRet
        Dim _arLong3()()() As Integer = New Integer()()(){}
        seqSeqRet2 = xBT2.setDim3(_arLong3)
        bRet = check( compareData(seqSeqRet2, _arLong3), "sequence test") And bRet
        Dim _arAny() As Any = New Any(){}
        seqAnyRet = xBT2.setSequenceAny(_arAny)
        bRet = check( compareData(seqAnyRet, _arAny), "sequence test") And bRet
        Dim _arBool() As Boolean = New Boolean() {}
        seqBoolRet = xBT2.setSequenceBool(_arBool)
        bRet = check( compareData(seqBoolRet, _arBool), "sequence test") And bRet
        Dim _arByte() As Byte = New Byte() {}
        seqByteRet = xBT2.setSequenceByte(_arByte)
        bRet = check( compareData(seqByteRet, _arByte), "sequence test") And bRet
        Dim _arChar() As Char = New Char() {}
        seqCharRet  = xBT2.setSequenceChar(_arChar)
        bRet = check( compareData(seqCharRet, _arChar), "sequence test") And bRet
        Dim _arShort() As Short = New Short() {}
        seqShortRet = xBT2.setSequenceShort(_arShort)
        bRet = check( compareData(seqShortRet, _arShort), "sequence test") And bRet
        Dim _arLong() As Integer = New Integer() {}
        seqLongRet = xBT2.setSequenceLong(_arLong)
        bRet = check( compareData(seqLongRet, _arLong), "sequence test") And bRet
        Dim _arHyper() As Long = New Long(){}
        seqHyperRet = xBT2.setSequenceHyper(_arHyper)
        bRet = check( compareData(seqHyperRet, _arHyper), "sequence test") And bRet
        Dim _arFloat() As Single = New Single(){}
        seqFloatRet = xBT2.setSequenceFloat(_arFloat)
        bRet = check( compareData(seqFloatRet, _arFloat), "sequence test") And bRet
        Dim _arDouble() As Double = New Double(){}
        seqDoubleRet = xBT2.setSequenceDouble(_arDouble)
        bRet = check( compareData(seqDoubleRet, _arDouble), "sequence test") And bRet
        Dim _arEnum() As TestEnum = New TestEnum(){}
        seqEnumRet = xBT2.setSequenceEnum(_arEnum)
        bRet = check( compareData(seqEnumRet, _arEnum), "sequence test") And bRet
        Dim  _arUShort() As UInt16 = New UInt16(){}
        seqUShortRet = xBT2.setSequenceUShort(_arUShort)
        bRet = check( compareData(seqUShortRet, _arUShort), "sequence test") And bRet
        Dim _arULong() As UInt32 = New UInt32(){}
        seqULongRet = xBT2.setSequenceULong(_arULong)
        bRet = check( compareData(seqULongRet, _arULong), "sequence test") And bRet
        Dim  _arUHyper() As UInt64 = New UInt64(){}
        seqUHyperRet = xBT2.setSequenceUHyper(_arUHyper)
        bRet = check( compareData(seqUHyperRet, _arUHyper), "sequence test") And bRet
        Dim _arObject() As Object = New Object(){}
        seqObjectRet = xBT2.setSequenceXInterface(_arObject)
        bRet = check( compareData(seqObjectRet, _arObject), "sequence test") And bRet
        Dim _arString() As String = New String(){}
        seqStringRet = xBT2.setSequenceString(_arString)
        bRet = check( compareData(seqStringRet, _arString), "sequence test") And bRet
        Dim _arStruct() As TestElement = New TestElement(){}
        seqStructRet = xBT2.setSequenceStruct(_arStruct)
        bRet = check( compareData(seqStructRet, _arStruct), "sequence test") And bRet
        Return bRet
    End Function

    Private Shared Function testAny(typ As Type, value As  Object, _
                                    xLBT As  XBridgeTest ) As Boolean
   
	    Dim any As Any
	    If (typ Is Nothing)
		    any = New Any(value.GetType(), value)
	    Else
		    any = New Any(typ, value)
        End If

	    Dim any2 As Any = xLBT.transportAny(any)
	    Dim ret As Boolean = compareData(any, any2)
	    If ret = False
            Console.WriteLine("any is different after roundtrip: in {0}, " _
                              & "out {1}\n", _
                            any.Type.FullName, any2.Type.FullName)
        End If
	    Return ret
    End Function

    Private Shared Function performAnyTest(xLBT As XBridgeTest, _
                                           data As TestDataElements) As Boolean
        Dim bReturn As Boolean = True
	    bReturn = testAny( Nothing, data.Byte ,xLBT ) And bReturn
	    bReturn = testAny( Nothing, data.Short,xLBT ) And bReturn
	    bReturn = testAny(  Nothing, data.UShort,xLBT ) And bReturn
	    bReturn = testAny(  Nothing, data.Long,xLBT ) And bReturn
	    bReturn = testAny(  Nothing, data.ULong,xLBT ) And bReturn
	    bReturn = testAny(  Nothing, data.Hyper,xLBT ) And bReturn
	    bReturn = testAny(  Nothing,data.UHyper,xLBT ) And bReturn
	    bReturn = testAny( Nothing, data.Float,xLBT ) And bReturn
	    bReturn = testAny( Nothing, data.Double,xLBT ) And bReturn
	    bReturn = testAny( Nothing, data.Enum,xLBT ) And bReturn
	    bReturn = testAny( Nothing, data.String,xLBT ) And bReturn
	    bReturn = testAny(GetType(unoidl.com.sun.star.uno.XWeak), _
                     data.Interface,xLBT ) And bReturn
	    bReturn = testAny(Nothing, data, xLBT ) And bReturn

        Dim a1 As Any = New Any(True)
        Dim a2 As Any = xLBT.transportAny( a1 )
	    bReturn = compareData(a2, a1) And bReturn
	
        Dim a3 As Any = New Any("A"C)
	    Dim a4 As Any = xLBT.transportAny(a3)
	    bReturn = compareData(a4, a3) And bReturn
	
	    Return bReturn 
    End Function

    Private Shared Function performSequenceOfCallTest(xLBT As XBridgeTest) As Boolean
    
	    Dim i, nRounds As Integer
	    Dim nGlobalIndex As Integer = 0
	    const nWaitTimeSpanMUSec As Integer = 10000
	    For nRounds = 0 To 9   
		    For i = 0 To  nRounds - 1 
			    ' fire oneways
			    xLBT.callOneway(nGlobalIndex, nWaitTimeSpanMUSec)
			    nGlobalIndex = nGlobalIndex + 1
		    Next

		    ' call synchron
		    xLBT.call(nGlobalIndex, nWaitTimeSpanMUSec)
		    nGlobalIndex = nGlobalIndex + 1
	    Next 
 	    Return xLBT.sequenceOfCallTestPassed()
    End Function

    Private Shared Function performRecursiveCallTest(xLBT As XBridgeTest) As Boolean  
	    xLBT.startRecursiveCall(new ORecursiveCall(), 50)
	    ' on failure, the test would lock up or crash
	    Return True
    End Function


    Private Shared Function performTest(xLBT As XBridgeTest) As Boolean
	    check( Not xLBT Is Nothing, "### no test interface!" )
        Dim bRet As Boolean = True
	    If xLBT Is Nothing
            Return False
        End If
		'this data is never ever granted access to by calls other than equals(), assign()!
		Dim aData As New TestDataElements' test against this data
		Dim xI As New WeakBase

        Dim aAny As New Any(GetType(System.Object), xI)
		assign( DirectCast(aData, TestElement), _
			True, "@"C, 17, &H1234, Convert.ToUInt16(&HdcS), &H12345678, _
            Convert.ToUInt32(4294967294), _
			&H123456789abcdef0, Convert.ToUInt64(14294967294), _
			17.0815f, 3.1415926359, TestEnum.LOLA, _
			CONSTANTS.STRING_TEST_CONSTANT, xI, _
			aAny)

		bRet = check( aData.Any.Value Is xI, "### unexpected any!" ) And bRet
		
		aData.Sequence = New TestElement(1){}
        aData.Sequence(0) = New TestElement( _
			aData.Bool, aData.Char, aData.Byte, aData.Short, _
			aData.UShort, aData.Long, aData.ULong, _
			aData.Hyper, aData.UHyper, aData.Float, _
			aData.Double, aData.Enum, aData.String, _
			aData.Interface, aData.Any)
        aData.Sequence(1) = New TestElement 'is empty
        
		' aData complete
		'
		' this is a manually copy of aData for first setting...
		Dim aSetData As New TestDataElements
		Dim aAnySet As New Any(GetType(System.Object), xI)
		assign( DirectCast(aSetData, TestElement), _
				aData.Bool, aData.Char, aData.Byte, aData.Short, aData.UShort, _
				aData.Long, aData.ULong, aData.Hyper, aData.UHyper, aData.Float, _
                aData.Double, aData.Enum, aData.String, xI, aAnySet)
		
		aSetData.Sequence = New TestElement(1){}
        aSetData.Sequence(0) = New TestElement( _
			aSetData.Bool, aSetData.Char, aSetData.Byte, aSetData.Short, _
			aSetData.UShort, aSetData.Long, aSetData.ULong, _
			aSetData.Hyper, aSetData.UHyper, aSetData.Float, _
			aSetData.Double, aSetData.Enum, aSetData.String, _
			aSetData.Interface, aSetData.Any)
        aSetData.Sequence(1) = New TestElement ' empty struct

		xLBT.setValues( _
				aSetData.Bool, aSetData.Char, aSetData.Byte, aSetData.Short, _
                aSetData.UShort, aSetData.Long, aSetData.ULong, _
                aSetData.Hyper, aSetData.UHyper, aSetData.Float, _
                aSetData.Double, aSetData.Enum, aSetData.String, _
                aSetData.Interface, aSetData.Any, aSetData.Sequence, _
                aSetData )
		
		
		Dim aRet As New TestDataElements
        Dim aRet2 As New TestDataElements
		xLBT.getValues( _
			aRet.Bool, aRet.Char, aRet.Byte, aRet.Short, _
            aRet.UShort, aRet.Long, aRet.ULong, _
            aRet.Hyper, aRet.UHyper, aRet.Float, _
            aRet.Double, aRet.Enum, aRet.String, _
            aRet.Interface, aRet.Any, aRet.Sequence, _
            aRet2 )
		
		bRet = check( compareData( aData, aRet ) And _
                      compareData( aData, aRet2 ) , "getValues test") And bRet
        
		' set last retrieved values
		Dim  aSV2ret As TestDataElements= xLBT.setValues2( _
			aRet.Bool, aRet.Char, aRet.Byte, _
            aRet.Short, aRet.UShort, aRet.Long, _
            aRet.ULong, aRet.Hyper, aRet.UHyper, _
            aRet.Float, aRet.Double, aRet.Enum, _
            aRet.String, aRet.Interface, aRet.Any, _
            aRet.Sequence, aRet2 )
		
        ' check inout sequence order
        ' => inout sequence parameter was switched by test objects
		Dim temp As TestElement = aRet.Sequence( 0 )
        aRet.Sequence( 0 ) = aRet.Sequence( 1 )
        aRet.Sequence( 1 ) = temp
        
		bRet = check( _
            compareData( aData, aSV2ret ) And compareData( aData, aRet2 ), _
            "getValues2 test") And bRet
		
		
		aRet = New TestDataElements
        aRet2 = New TestDataElements
		Dim  aGVret As TestDataElements= xLBT.getValues( _
			aRet.Bool, aRet.Char, aRet.Byte, _ 
            aRet.Short, aRet.UShort, aRet.Long, _
            aRet.ULong, aRet.Hyper, aRet.UHyper, _
            aRet.Float, aRet.Double, aRet.Enum, _
            aRet.String, aRet.Interface, aRet.Any, _
            aRet.Sequence, aRet2 )
		
		bRet = check( compareData( aData, aRet ) And _
                      compareData( aData, aRet2 ) And _ 
                      compareData( aData, aGVret ), "getValues test" ) And bRet
		
		' set last retrieved values
		xLBT.Bool = aRet.Bool
		xLBT.Char = aRet.Char
		xLBT.Byte = aRet.Byte
		xLBT.Short = aRet.Short
		xLBT.UShort = aRet.UShort
        xLBT.Long = aRet.Long
		xLBT.ULong = aRet.ULong
		xLBT.Hyper = aRet.Hyper
		xLBT.UHyper = aRet.UHyper
		xLBT.Float = aRet.Float
		xLBT.Double = aRet.Double
		xLBT.Enum = aRet.Enum
		xLBT.String = aRet.String
		xLBT.Interface = aRet.Interface
		xLBT.Any = aRet.Any
		xLBT.Sequence = aRet.Sequence
		xLBT.Struct = aRet2
		
		
		aRet = New TestDataElements
        aRet2 = New TestDataElements
		aRet.Hyper = xLBT.Hyper
		aRet.UHyper = xLBT.UHyper
		aRet.Float = xLBT.Float
		aRet.Double = xLBT.Double
		aRet.Byte = xLBT.Byte
		aRet.Char = xLBT.Char
		aRet.Bool = xLBT.Bool
		aRet.Short = xLBT.Short
		aRet.UShort = xLBT.UShort
		aRet.Long = xLBT.Long
		aRet.ULong = xLBT.ULong
		aRet.Enum = xLBT.Enum
		aRet.String = xLBT.String
		aRet.Interface = xLBT.Interface
		aRet.Any = xLBT.Any
		aRet.Sequence = xLBT.Sequence
		aRet2 = xLBT.Struct
		
		bRet = check( compareData( aData, aRet ) And _
                      compareData( aData, aRet2 ) , "struct comparison test") _
                     And bRet

		bRet = check(performSequenceTest(xLBT), "sequence test") And bRet

		' any test
		bRet = check( performAnyTest( xLBT , aData ) , "any test" ) And bRet

		'sequence of call test
		bRet = check( performSequenceOfCallTest( xLBT ) , _
                      "sequence of call test" ) And bRet

		' recursive call test
		bRet = check( performRecursiveCallTest( xLBT ) , "recursive test" ) _
                And bRet
		
		bRet = (compareData( aData, aRet ) And compareData( aData, aRet2 )) _
                And bRet 

        ' check setting of null reference
        xLBT.Interface = Nothing
        aRet.Interface = xLBT.Interface
        bRet = (aRet.Interface Is Nothing) And bRet
        
        Return bRet
    End Function

    Private Shared Function raiseException(xLBT As XBridgeTest) As Boolean
	    Dim nCount As Integer = 0
	    Try
		    Try
			    Try
				    Dim aRet As TestDataElements = New TestDataElements
                    Dim aRet2 As TestDataElements = New TestDataElements
				    xLBT.raiseException( _
					    5, CONSTANTS.STRING_TEST_CONSTANT, xLBT.Interface )
			    Catch  rExc As unoidl.com.sun.star.lang.IllegalArgumentException
				    If rExc.ArgumentPosition = 5 And _
                        rExc.Context Is xLBT.Interface
					    nCount = nCount + 1
				    Else
					    check( False, "### unexpected exception content!" )
				    End If
    				
				    'it is certain, that the RuntimeException testing will fail,
                    '    if no 
				    xLBT.RuntimeException = 0
			    End Try
		    Catch rExc As unoidl.com.sun.star.uno.RuntimeException
			    If rExc.Context Is xLBT.Interface
			       nCount = nCount + 1
			    Else
				    check( False, "### unexpected exception content!" )
			    End If
                xLBT.RuntimeException = CType(&Hcafebabe, Integer)
    	    End Try
	    Catch rExc As unoidl.com.sun.star.uno.Exception
		    If rExc.Context Is xLBT.Interface
		        nCount = nCount + 1
		    Else
			    check( False, "### unexpected exception content!" )
            End If
		    Return nCount = 3
	    End Try
        Return False
    End Function

    Private Shared Function raiseOnewayException(xLBT As XBridgeTest) As Boolean
        Dim bReturn As Boolean= True
	    Dim sCompare As String = CONSTANTS.STRING_TEST_CONSTANT
	    Try
		    ' Note : the exception may fly or not (e.g. remote scenario).
		    '        When it flies, it must contain the correct elements.
		    xLBT.raiseRuntimeExceptionOneway(sCompare, xLBT.Interface )
	    Catch e As RuntimeException
		    bReturn =  xLBT.Interface Is e.Context
	    End Try
        Return bReturn
    End Function

    'Test the System::Object method on the proxy object
    '
    Private Shared Function testObjectMethodsImplemention(xLBT As XBridgeTest) As Boolean
        Dim ret As Boolean = False
        Dim obj As Object = New Object
	    Dim xInt As Object = DirectCast(xLBT, Object) 
	    Dim xBase As XBridgeTestBase = DirectCast(xLBT, XBridgeTestBase)
	    ' Object.Equals
	    ret = DirectCast(xLBT, Object).Equals(obj) = False
	    ret = DirectCast(xLBT, Object).Equals(xLBT) And ret
	    ret = Object.Equals(obj, obj) And ret
	    ret = Object.Equals(xLBT, xBase) And ret
	    'Object.GetHashCode
	    ' Don't know how to verify this. Currently it is not possible to get the object id from a proxy
	    Dim nHash As Integer = DirectCast(xLBT, Object).GetHashCode()
	    ret = nHash = DirectCast(xBase, Object).GetHashCode() And ret

	    'Object.ToString
        ' Don't know how to verify this automatically.
	    Dim s As String = DirectCast(xLBT, Object).ToString()
        ret = (s.Length > 0) And ret
        Return ret
    End Function

    Private Shared Function performQueryForUnknownType(xLBT As XBridgeTest) As Boolean
        Dim bRet As Boolean = False
        ' test queryInterface for an unknown type 
        Try
            Dim a As foo.MyInterface = DirectCast(xLBT, foo.MyInterface)
        Catch e As System.InvalidCastException
            bRet = True
        End Try

        Return bRet
    End Function


    Private Shared Sub perform_test( xLBT As XBridgeTest)
        Dim bRet As Boolean = True
        bRet = check( performTest( xLBT ), "standard test" ) And bRet
        bRet = check( raiseException( xLBT ) , "exception test" ) And bRet
        bRet = check( raiseOnewayException( xLBT ), "oneway exception test" ) _
               And bRet
        bRet = check( testObjectMethodsImplemention(xLBT), _ 
               "object methods test") And bRet
        bRet = performQueryForUnknownType( xLBT ) And bRet
        If  Not bRet
            Throw New unoidl.com.sun.star.uno.RuntimeException( "error: test failed!", Nothing)
        End If
    End Sub       


    
    Public Overridable Function run(args() As String) As Integer _
	   Implements XMain.run
        Try
            If (args.Length < 1)
                Throw New RuntimeException( _
                    "missing argument for bridgetest!", Me )
            End If
           
            Dim test_obj As Object = _
                m_xContext.getServiceManager().createInstanceWithContext( _
                    args( 0 ), m_xContext )

            Debug.WriteLine( _
                "cli target bridgetest obj: {0}", test_obj.ToString() )
            Dim xTest As XBridgeTest = DirectCast(test_obj, XBridgeTest) 
            perform_test( xTest )
            Console.WriteLine("### cli_uno VB bridgetest succeeded.")
            return 0
	Catch e as unoidl.com.sun.star.uno.RuntimeException
	     Throw 
        Catch e as System.Exception 
	      Throw New unoidl.com.sun.star.uno.RuntimeException( _
		    "cli_vb_bridgetest.vb: unexpected exception occurred in XMain::run. " _
		    & "Original exception: " + e.GetType().Name + "\n Message: " _
		    & e.Message , Nothing)

        End Try
    End Function

End Class

End Namespace