1'*************************************************************************
2'
3'  Licensed to the Apache Software Foundation (ASF) under one
4'  or more contributor license agreements.  See the NOTICE file
5'  distributed with this work for additional information
6'  regarding copyright ownership.  The ASF licenses this file
7'  to you under the Apache License, Version 2.0 (the
8'  "License"); you may not use this file except in compliance
9'  with the License.  You may obtain a copy of the License at
10'
11'    http://www.apache.org/licenses/LICENSE-2.0
12'
13'  Unless required by applicable law or agreed to in writing,
14'  software distributed under the License is distributed on an
15'  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16'  KIND, either express or implied.  See the License for the
17'  specific language governing permissions and limitations
18'  under the License.
19'
20'*************************************************************************
21
22
23
24
25
26Option Explicit On
27Option Strict On
28
29imports System
30imports uno
31imports uno.util
32imports unoidl.com.sun.star.lang
33imports unoidl.com.sun.star.uno
34'imports unoidl.com.sun.star.test.bridge
35imports unoidl.test.testtools.bridgetest
36imports System.Windows.Forms
37imports System.Diagnostics
38imports System.Reflection
39
40Class CONSTANTS
41Friend Shared STRING_TEST_CONSTANT As String  = """ paco\' chorizo\\\' ""\'"
42End Class
43
44Namespace foo
45
46    Public Interface MyInterface
47    End Interface
48End Namespace
49
50Namespace vb_bridetest
51Class ORecursiveCall
52    Inherits WeakBase
53    Implements XRecursiveCall
54
55    Overridable Sub callRecursivly(xCall As XRecursiveCall, nToCall As Integer) _
56    Implements XRecursiveCall.callRecursivly
57		SyncLock Me
58            If nToCall > 0
59                nToCall = nToCall - 1
60                xCall.callRecursivly(Me, nToCall)
61            End If
62       End SyncLock
63    End Sub
64End Class
65
66
67
68
69Public Class BridgeTest
70       Inherits uno.util.WeakBase
71       Implements XMain
72
73    Private m_xContext As XComponentContext
74
75    Public Sub New( xContext As unoidl.com.sun.star.uno.XComponentContext )
76        mybase.New()
77        m_xContext = xContext
78    End Sub
79
80    Private Shared Function check( b As Boolean , message As String  ) As Boolean
81        If Not b
82            Console.WriteLine("{0} failed\n" , message)
83        End If
84        Return b
85    End Function
86
87    Private Shared Sub assign( rData As TestElement, bBool As Boolean, _
88			aChar As Char, nByte As Byte, nShort As Short, nUShort As UInt16, _
89					nLong As Integer, nULong As UInt32, nHyper As Long, _
90                    nUHyper As UInt64, fFloat As Single, fDouble As Double, _
91					eEnum As TestEnum, rStr As String, xTest As Object, _
92					rAny As Any)
93
94    	rData.Bool = bBool
95	    rData.Char = aChar
96	    rData.Byte = nByte
97	    rData.Short = nShort
98	    rData.UShort = nUShort
99	    rData.Long = nLong
100	    rData.ULong = nULong
101	    rData.Hyper = nHyper
102	    rData.UHyper = nUHyper
103	    rData.Float = fFloat
104	    rData.Double = fDouble
105	    rData.Enum = eEnum
106	    rData.String = rStr
107	    rData.Interface = xTest
108	    rData.Any = rAny
109    End Sub
110
111    Private Shared Sub assign( rData As TestDataElements, bBool As Boolean, _
112            aChar As Char, nByte As Byte, nShort As Short, nUShort As UInt16, _
113			nLong As Integer, nULong As UInt32, nHyper As Long, _
114            nUHyper As UInt64, fFloat As Single, fDouble As Double, _
115    		eEnum As TestEnum, rStr As String, xTest As Object, _
116			rAny As Any, rSequence() As TestElement)
117
118    	assign( DirectCast( rData,TestElement), _
119			bBool, aChar, nByte, nShort, nUShort, nLong, nULong, nHyper, _
120            nUHyper, fFloat, fDouble, eEnum, rStr, xTest, rAny )
121	    rData.Sequence = rSequence
122    End Sub
123
124	Private Shared Function compareData(val1 As Object, val2 As Object) As Boolean
125		If val1 Is Nothing And val2 Is Nothing OrElse _
126            val1 Is val2
127			Return True
128        End If
129		If  val1 Is Nothing And Not(val2 Is Nothing)  OrElse _
130		    Not (val1 Is Nothing) And val2 Is Nothing OrElse _
131            Not val1.GetType().Equals( val2.GetType())
132			Return False
133		End If
134
135		Dim ret As Boolean = False
136		Dim t1 As Type = val1.GetType()
137        'Sequence
138		If t1.IsArray()
139			ret = compareSequence(DirectCast( val1, Array), _
140                  DirectCast( val2, Array))
141		'String
142		ElseIf TypeOf val1 Is String
143			ret = DirectCast( val1, string) = DirectCast( val2, string)
144		' Interface implementation
145		ElseIf t1.GetInterfaces().Length > 0 And Not t1.IsValueType
146			ret = val1 Is val2
147		' Struct
148		ElseIf  Not t1.IsValueType
149			ret = compareStruct(val1, val2)
150		ElseIf TypeOf val1 Is Any
151			Dim a1 As Any = DirectCast( val1, Any)
152			Dim a2 As Any = DirectCast( val2, Any)
153			ret = a1.Type.Equals( a2.Type ) And compareData( a1.Value, a2.Value )
154		ElseIf t1.IsValueType
155			'Any, enum, int, bool char, float, double etc.
156			ret = val1.Equals(val2)
157		Else
158			Debug.Assert(False)
159		End If
160		Return ret
161	End Function
162
163	' Arrays have only one dimension
164	Private Shared Function compareSequence( ar1 As Array, ar2 As Array) As Boolean
165		Debug.Assert( Not (ar1 Is Nothing) And Not (ar2 Is Nothing) )
166		Dim t1 As Type  = ar1.GetType()
167		Dim t2 As Type  = ar2.GetType()
168
169		if ( Not(ar1.Rank = 1 And ar2.Rank = 1 _
170			And ar1.Length = ar2.Length And t1.GetElementType().Equals(t2.GetElementType())))
171			return False
172        End If
173		'arrays have same rank and size and element type.
174		Dim len As Integer  = ar1.Length
175		Dim elemType As Type = t1.GetElementType()
176		Dim ret As Boolean = True
177        Dim i As Integer
178		For i = 0 To len - 1
179			If (compareData(ar1.GetValue(i), ar2.GetValue(i)) = False)
180				ret = False
181				Exit For
182			End If
183		Next i
184
185        Return ret
186	End Function
187
188	Private Shared Function compareStruct( val1 As Object, val2 As Object) As Boolean
189		Debug.Assert( Not(val1 Is Nothing) And Not(val2 Is Nothing))
190		Dim t1 As Type = val1.GetType()
191		Dim t2 As Type = val2.GetType()
192		If Not t1.Equals(t2)
193			Return False
194        End If
195		Dim fields() As FieldInfo = t1.GetFields()
196		Dim cFields As Integer = fields.Length
197		Dim ret As Boolean = True
198        Dim i As Integer
199		For i = 0 To cFields - 1
200			Dim fieldVal1 As Object = fields(i).GetValue(val1)
201			Dim fieldVal2 As Object = fields(i).GetValue(val2)
202			If Not compareData(fieldVal1, fieldVal2)
203				ret = False
204				Exit For
205			End If
206		Next i
207		Return ret
208	End Function
209
210
211    Private Shared Function performSequenceTest(xBT As XBridgeTest) As Boolean
212        Dim bRet As Boolean = True
213        'Automati cast ?? like with COM objects
214        Dim xBT2 As XBridgeTest2
215        Try
216            xBT2 = DirectCast(xBT,XBridgeTest2)
217        Catch e As InvalidCastException
218            Return False
219        End Try
220
221        ' perform sequence tests (XBridgeTest2)
222        'create the sequence which are compared with the results
223        Dim arBool() As Boolean = {True, False, True}
224        Dim arChar() As Char = {"A"C,"B"C,"C"C}
225        Dim arByte() As Byte = { 1,  2,  &Hff}
226        Dim arShort() As Short = {Int16.MinValue, 1,  Int16.MaxValue}
227        Dim arUShort() As UInt16 = {Convert.ToUInt16(0), Convert.ToUInt16(1), _
228                                    Convert.ToUInt16(&Hffff)}
229        Dim arLong() As Integer = {Int32.MinValue, 1, Int32.MaxValue}
230        Dim arULong() As UInt32 = {Convert.ToUInt32(0), Convert.ToUInt32(1), _
231                                   Convert.ToUInt32(&HffffffffL)}
232        Dim arHyper() As Long = {Int64.MinValue, 1, Int64.MaxValue}
233        Dim arUHyper() As UInt64 = {Convert.ToUInt64(0), Convert.ToUInt64(1), _
234                                    Convert.ToUInt64(&Hffffffff5L)}
235        Dim arFloat() As Single = {1.1f, 2.2f, 3.3f}
236        Dim arDouble() As Double = {1.11, 2.22, 3.33}
237        Dim arString() As String = {"String 1", "String 2", "String 3"}
238
239        Dim arAny() As Any = {New Any(True), New Any(11111), New Any(3.14)}
240        Dim arObject() As Object = {New WeakBase(), New WeakBase(), New WeakBase()}
241        Dim arEnum() As TestEnum = {TestEnum.ONE, TestEnum.TWO, TestEnum.CHECK}
242
243        Dim arStruct() As TestElement = {New TestElement(), New TestElement(), _
244                               New TestElement()}
245        assign( arStruct(0), True, "@"C, 17, &H1234, Convert.ToUInt16(&Hfedc), _
246            &H12345678, Convert.ToUInt32(&H123456), &H123456789abcdef0, _
247            Convert.ToUInt64(123456788), 17.0815F, 3.1415926359, _
248            TestEnum.LOLA, CONSTANTS.STRING_TEST_CONSTANT, arObject(0), _
249            New Any(GetType(System.Object), arObject(0)))
250        assign( arStruct(1), True, "A"C, 17, &H1234, Convert.ToUInt16(&Hfedc), _
251            &H12345678, Convert.ToUInt32(&H123456), &H123456789abcdef0, _
252            Convert.ToUInt64(12345678), 17.0815F, 3.1415926359, _
253            TestEnum.TWO, CONSTANTS.STRING_TEST_CONSTANT, arObject(1), _
254            New Any(GetType(System.Object), arObject(1)) )
255        assign( arStruct(2), True, "B"C, 17, &H1234, Convert.ToUInt16(&Hfedc), _
256            &H12345678, Convert.ToUInt32(654321), &H123456789abcdef0, _
257            Convert.ToUInt64(87654321), 17.0815F, 3.1415926359, _
258            TestEnum.CHECK, Constants.STRING_TEST_CONSTANT, arObject(2), _
259            New Any(GetType(System.Object), arObject(2)))
260
261
262        Dim arLong3()()() As Integer = New Integer()()() { _
263        New Integer()(){New Integer(){1,2,3},New Integer(){4,5,6}, New Integer(){7,8,9} }, _
264        New Integer ()(){New Integer(){1,2,3},New Integer(){4,5,6}, New Integer(){7,8,9}}, _
265        New Integer()(){New Integer(){1,2,3},New Integer(){4,5,6}, New Integer(){7,8,9}}}
266
267        Dim seqSeqRet()() As Integer = xBT2.setDim2(arLong3(0))
268        bRet = check( compareData(seqSeqRet, arLong3(0)), "sequence test") _
269               And bRet
270        Dim seqSeqRet2()()() As Integer = xBT2.setDim3(arLong3)
271        bRet = check( compareData(seqSeqRet2, arLong3), "sequence test") _
272               And bRet
273        Dim seqAnyRet() As Any = xBT2.setSequenceAny(arAny)
274        bRet = check( compareData(seqAnyRet, arAny), "sequence test") And bRet
275        Dim seqBoolRet() As Boolean = xBT2.setSequenceBool(arBool)
276        bRet = check( compareData(seqBoolRet, arBool), "sequence test") _
277               And bRet
278        Dim seqByteRet() As Byte = xBT2.setSequenceByte(arByte)
279        bRet = check( compareData(seqByteRet, arByte), "sequence test") _
280               And bRet
281        Dim seqCharRet() As Char = xBT2.setSequenceChar(arChar)
282        bRet = check( compareData(seqCharRet, arChar), "sequence test") _
283                   And bRet
284        Dim seqShortRet() As Short = xBT2.setSequenceShort(arShort)
285        bRet = check( compareData(seqShortRet, arShort), "sequence test") _
286               And bRet
287        Dim seqLongRet() As Integer = xBT2.setSequenceLong(arLong)
288        bRet = check( compareData(seqLongRet, arLong), "sequence test") _
289                   And bRet
290        Dim seqHyperRet() As Long = xBT2.setSequenceHyper(arHyper)
291        bRet = check( compareData(seqHyperRet,arHyper), "sequence test") _
292               And bRet
293        Dim seqFloatRet() As Single = xBT2.setSequenceFloat(arFloat)
294        bRet = check( compareData(seqFloatRet, arFloat), "sequence test") _
295               And bRet
296        Dim seqDoubleRet() As Double= xBT2.setSequenceDouble(arDouble)
297        bRet = check( compareData(seqDoubleRet, arDouble), "sequence test") _
298               And bRet
299        Dim seqEnumRet() As TestEnum = xBT2.setSequenceEnum(arEnum)
300        bRet = check( compareData(seqEnumRet, arEnum), "sequence test") _
301               And bRet
302        Dim seqUShortRet() As UInt16 = xBT2.setSequenceUShort(arUShort)
303        bRet = check( compareData(seqUShortRet, arUShort), "sequence test") _
304               And bRet
305        Dim seqULongRet() As UInt32 = xBT2.setSequenceULong(arULong)
306        bRet = check( compareData(seqULongRet, arULong), "sequence test") _
307               And bRet
308        Dim seqUHyperRet() As UInt64 = xBT2.setSequenceUHyper(arUHyper)
309        bRet = check( compareData(seqUHyperRet, arUHyper), "sequence test") _
310               And bRet
311        Dim seqObjectRet() As Object = xBT2.setSequenceXInterface(arObject)
312        bRet = check( compareData(seqObjectRet, arObject), "sequence test") _
313               And bRet
314        Dim seqStringRet() As String = xBT2.setSequenceString(arString)
315        bRet = check( compareData(seqStringRet, arString), "sequence test") _
316               And bRet
317        Dim seqStructRet() As TestElement = xBT2.setSequenceStruct(arStruct)
318        bRet = check( compareData(seqStructRet, arStruct), "sequence test") _
319               And bRet
320
321
322        Dim arBoolTemp() As Boolean = DirectCast(arBool.Clone(), Boolean())
323        Dim arCharTemp() As Char = DirectCast(arChar.Clone(), Char())
324        Dim arByteTemp() As Byte = DirectCast(arByte.Clone(), Byte())
325        Dim arShortTemp() As Short = DirectCast(arShort.Clone(), Short())
326        Dim arUShortTemp() As UInt16 = DirectCast(arUShort.Clone(), UInt16())
327        Dim arLongTemp() As Integer= DirectCast(arLong.Clone(), Integer())
328        Dim arULongTemp() As UInt32 =  DirectCast(arULong.Clone(), UInt32())
329        Dim arHyperTemp() As Long = DirectCast(arHyper.Clone(), Long())
330        Dim arUHyperTemp() As UInt64 = DirectCast(arUHyper.Clone(), UInt64())
331        Dim arFloatTemp() As Single = DirectCast(arFloat.Clone(), Single())
332        Dim arDoubleTemp() As Double = DirectCast(arDouble.Clone(), Double())
333        Dim arEnumTemp() As TestEnum = DirectCast(arEnum.Clone(), TestEnum())
334        Dim arStringTemp() As String = DirectCast(arString.Clone(), String())
335        Dim arObjectTemp() As Object = DirectCast(arObject.Clone(), Object())
336        Dim arAnyTemp() As Any = DirectCast(arAny.Clone(), Any())
337        ' make sure this are has the same contents as arLong3(0)
338        Dim arLong2Temp()() As Integer = New Integer()(){New Integer(){1,2,3}, _
339                                         New Integer(){4,5,6}, New Integer(){7,8,9} }
340        ' make sure this are has the same contents as arLong3
341        Dim arLong3Temp()()() As Integer = New Integer()()(){ _
342            New Integer()(){New Integer(){1,2,3},New Integer(){4,5,6}, New Integer(){7,8,9} }, _
343            New Integer ()(){New Integer(){1,2,3},New Integer(){4,5,6}, New Integer(){7,8,9}}, _
344            New Integer()(){New Integer(){1,2,3},New Integer(){4,5,6}, New Integer(){7,8,9}}}
345
346        xBT2.setSequencesInOut( arBoolTemp, arCharTemp,  arByteTemp, _
347                            arShortTemp,  arUShortTemp,  arLongTemp, _
348                            arULongTemp, arHyperTemp,  arUHyperTemp, _
349                            arFloatTemp, arDoubleTemp,  arEnumTemp, _
350                            arStringTemp,   arObjectTemp, _
351                             arAnyTemp,  arLong2Temp,  arLong3Temp)
352        bRet = check( _
353            compareData(arBoolTemp, arBool) And _
354            compareData(arCharTemp , arChar) And _
355            compareData(arByteTemp , arByte) And _
356            compareData(arShortTemp , arShort) And _
357            compareData(arUShortTemp , arUShort) And _
358            compareData(arLongTemp , arLong) And _
359            compareData(arULongTemp , arULong) And _
360            compareData(arHyperTemp , arHyper) And _
361            compareData(arUHyperTemp , arUHyper) And _
362            compareData(arFloatTemp , arFloat) And _
363            compareData(arDoubleTemp , arDouble) And _
364            compareData(arEnumTemp , arEnum) And _
365            compareData(arStringTemp , arString) And _
366            compareData(arObjectTemp , arObject) And _
367            compareData(arAnyTemp , arAny) And _
368            compareData(arLong2Temp , arLong3(0)) And _
369            compareData(arLong3Temp , arLong3), "sequence test") And bRet
370
371        Dim arBoolOut() As Boolean
372        Dim arCharOut() As Char
373        Dim arByteOut() As Byte
374        Dim arShortOut() As Short
375        Dim arUShortOut() As UInt16
376        Dim arLongOut() As Integer
377        Dim arULongOut() As UInt32
378        Dim arHyperOut() As Long
379        Dim arUHyperOut() As UInt64
380        Dim arFloatOut() As Single
381        Dim arDoubleOut() As Double
382        Dim arEnumOut() As TestEnum
383        Dim arStringOut() As String
384        Dim arObjectOut() As Object
385        Dim arAnyOut() As Any
386        Dim arLong2Out()() As Integer
387        Dim arLong3Out()()() As Integer
388
389        xBT2.setSequencesOut( arBoolOut,  arCharOut,  arByteOut, _
390                             arShortOut,  arUShortOut,  arLongOut, _
391                             arULongOut,  arHyperOut,  arUHyperOut, _
392                             arFloatOut,  arDoubleOut,  arEnumOut, _
393                             arStringOut,  arObjectOut,  arAnyOut, _
394                             arLong2Out,  arLong3Out)
395        bRet = check( _
396            compareData(arBoolOut, arBool) And _
397            compareData(arCharOut, arChar) And _
398            compareData(arByteOut, arByte) And _
399            compareData(arShortOut, arShort) And _
400            compareData(arUShortOut, arUShort) And _
401            compareData(arLongOut, arLong) And _
402            compareData(arULongOut, arULong) And _
403            compareData(arHyperOut, arHyper) And _
404            compareData(arUHyperOut, arUHyper) And _
405            compareData(arFloatOut, arFloat) And _
406            compareData(arDoubleOut, arDouble) And _
407            compareData(arEnumOut, arEnum) And _
408            compareData(arStringOut, arString) And _
409            compareData(arObjectOut, arObject) And _
410            compareData(arAnyOut, arAny) And _
411            compareData(arLong2Out, arLong3(0)) And _
412            compareData(arLong3Out, arLong3), "sequence test") And bRet
413
414
415        'test with empty sequences
416        Dim _arLong2()() As Integer = New Integer()(){}
417        seqSeqRet = xBT2.setDim2(_arLong2)
418        bRet = check( compareData(seqSeqRet, _arLong2), "sequence test") And bRet
419        Dim _arLong3()()() As Integer = New Integer()()(){}
420        seqSeqRet2 = xBT2.setDim3(_arLong3)
421        bRet = check( compareData(seqSeqRet2, _arLong3), "sequence test") And bRet
422        Dim _arAny() As Any = New Any(){}
423        seqAnyRet = xBT2.setSequenceAny(_arAny)
424        bRet = check( compareData(seqAnyRet, _arAny), "sequence test") And bRet
425        Dim _arBool() As Boolean = New Boolean() {}
426        seqBoolRet = xBT2.setSequenceBool(_arBool)
427        bRet = check( compareData(seqBoolRet, _arBool), "sequence test") And bRet
428        Dim _arByte() As Byte = New Byte() {}
429        seqByteRet = xBT2.setSequenceByte(_arByte)
430        bRet = check( compareData(seqByteRet, _arByte), "sequence test") And bRet
431        Dim _arChar() As Char = New Char() {}
432        seqCharRet  = xBT2.setSequenceChar(_arChar)
433        bRet = check( compareData(seqCharRet, _arChar), "sequence test") And bRet
434        Dim _arShort() As Short = New Short() {}
435        seqShortRet = xBT2.setSequenceShort(_arShort)
436        bRet = check( compareData(seqShortRet, _arShort), "sequence test") And bRet
437        Dim _arLong() As Integer = New Integer() {}
438        seqLongRet = xBT2.setSequenceLong(_arLong)
439        bRet = check( compareData(seqLongRet, _arLong), "sequence test") And bRet
440        Dim _arHyper() As Long = New Long(){}
441        seqHyperRet = xBT2.setSequenceHyper(_arHyper)
442        bRet = check( compareData(seqHyperRet, _arHyper), "sequence test") And bRet
443        Dim _arFloat() As Single = New Single(){}
444        seqFloatRet = xBT2.setSequenceFloat(_arFloat)
445        bRet = check( compareData(seqFloatRet, _arFloat), "sequence test") And bRet
446        Dim _arDouble() As Double = New Double(){}
447        seqDoubleRet = xBT2.setSequenceDouble(_arDouble)
448        bRet = check( compareData(seqDoubleRet, _arDouble), "sequence test") And bRet
449        Dim _arEnum() As TestEnum = New TestEnum(){}
450        seqEnumRet = xBT2.setSequenceEnum(_arEnum)
451        bRet = check( compareData(seqEnumRet, _arEnum), "sequence test") And bRet
452        Dim  _arUShort() As UInt16 = New UInt16(){}
453        seqUShortRet = xBT2.setSequenceUShort(_arUShort)
454        bRet = check( compareData(seqUShortRet, _arUShort), "sequence test") And bRet
455        Dim _arULong() As UInt32 = New UInt32(){}
456        seqULongRet = xBT2.setSequenceULong(_arULong)
457        bRet = check( compareData(seqULongRet, _arULong), "sequence test") And bRet
458        Dim  _arUHyper() As UInt64 = New UInt64(){}
459        seqUHyperRet = xBT2.setSequenceUHyper(_arUHyper)
460        bRet = check( compareData(seqUHyperRet, _arUHyper), "sequence test") And bRet
461        Dim _arObject() As Object = New Object(){}
462        seqObjectRet = xBT2.setSequenceXInterface(_arObject)
463        bRet = check( compareData(seqObjectRet, _arObject), "sequence test") And bRet
464        Dim _arString() As String = New String(){}
465        seqStringRet = xBT2.setSequenceString(_arString)
466        bRet = check( compareData(seqStringRet, _arString), "sequence test") And bRet
467        Dim _arStruct() As TestElement = New TestElement(){}
468        seqStructRet = xBT2.setSequenceStruct(_arStruct)
469        bRet = check( compareData(seqStructRet, _arStruct), "sequence test") And bRet
470        Return bRet
471    End Function
472
473    Private Shared Function testAny(typ As Type, value As  Object, _
474                                    xLBT As  XBridgeTest ) As Boolean
475
476	    Dim any As Any
477	    If (typ Is Nothing)
478		    any = New Any(value.GetType(), value)
479	    Else
480		    any = New Any(typ, value)
481        End If
482
483	    Dim any2 As Any = xLBT.transportAny(any)
484	    Dim ret As Boolean = compareData(any, any2)
485	    If ret = False
486            Console.WriteLine("any is different after roundtrip: in {0}, " _
487                              & "out {1}\n", _
488                            any.Type.FullName, any2.Type.FullName)
489        End If
490	    Return ret
491    End Function
492
493    Private Shared Function performAnyTest(xLBT As XBridgeTest, _
494                                           data As TestDataElements) As Boolean
495        Dim bReturn As Boolean = True
496	    bReturn = testAny( Nothing, data.Byte ,xLBT ) And bReturn
497	    bReturn = testAny( Nothing, data.Short,xLBT ) And bReturn
498	    bReturn = testAny(  Nothing, data.UShort,xLBT ) And bReturn
499	    bReturn = testAny(  Nothing, data.Long,xLBT ) And bReturn
500	    bReturn = testAny(  Nothing, data.ULong,xLBT ) And bReturn
501	    bReturn = testAny(  Nothing, data.Hyper,xLBT ) And bReturn
502	    bReturn = testAny(  Nothing,data.UHyper,xLBT ) And bReturn
503	    bReturn = testAny( Nothing, data.Float,xLBT ) And bReturn
504	    bReturn = testAny( Nothing, data.Double,xLBT ) And bReturn
505	    bReturn = testAny( Nothing, data.Enum,xLBT ) And bReturn
506	    bReturn = testAny( Nothing, data.String,xLBT ) And bReturn
507	    bReturn = testAny(GetType(unoidl.com.sun.star.uno.XWeak), _
508                     data.Interface,xLBT ) And bReturn
509	    bReturn = testAny(Nothing, data, xLBT ) And bReturn
510
511        Dim a1 As Any = New Any(True)
512        Dim a2 As Any = xLBT.transportAny( a1 )
513	    bReturn = compareData(a2, a1) And bReturn
514
515        Dim a3 As Any = New Any("A"C)
516	    Dim a4 As Any = xLBT.transportAny(a3)
517	    bReturn = compareData(a4, a3) And bReturn
518
519	    Return bReturn
520    End Function
521
522    Private Shared Function performSequenceOfCallTest(xLBT As XBridgeTest) As Boolean
523
524	    Dim i, nRounds As Integer
525	    Dim nGlobalIndex As Integer = 0
526	    const nWaitTimeSpanMUSec As Integer = 10000
527	    For nRounds = 0 To 9
528		    For i = 0 To  nRounds - 1
529			    ' fire oneways
530			    xLBT.callOneway(nGlobalIndex, nWaitTimeSpanMUSec)
531			    nGlobalIndex = nGlobalIndex + 1
532		    Next
533
534		    ' call synchron
535		    xLBT.call(nGlobalIndex, nWaitTimeSpanMUSec)
536		    nGlobalIndex = nGlobalIndex + 1
537	    Next
538 	    Return xLBT.sequenceOfCallTestPassed()
539    End Function
540
541    Private Shared Function performRecursiveCallTest(xLBT As XBridgeTest) As Boolean
542	    xLBT.startRecursiveCall(new ORecursiveCall(), 50)
543	    ' on failure, the test would lock up or crash
544	    Return True
545    End Function
546
547
548    Private Shared Function performTest(xLBT As XBridgeTest) As Boolean
549	    check( Not xLBT Is Nothing, "### no test interface!" )
550        Dim bRet As Boolean = True
551	    If xLBT Is Nothing
552            Return False
553        End If
554		'this data is never ever granted access to by calls other than equals(), assign()!
555		Dim aData As New TestDataElements' test against this data
556		Dim xI As New WeakBase
557
558        Dim aAny As New Any(GetType(System.Object), xI)
559		assign( DirectCast(aData, TestElement), _
560			True, "@"C, 17, &H1234, Convert.ToUInt16(&HdcS), &H12345678, _
561            Convert.ToUInt32(4294967294), _
562			&H123456789abcdef0, Convert.ToUInt64(14294967294), _
563			17.0815f, 3.1415926359, TestEnum.LOLA, _
564			CONSTANTS.STRING_TEST_CONSTANT, xI, _
565			aAny)
566
567		bRet = check( aData.Any.Value Is xI, "### unexpected any!" ) And bRet
568
569		aData.Sequence = New TestElement(1){}
570        aData.Sequence(0) = New TestElement( _
571			aData.Bool, aData.Char, aData.Byte, aData.Short, _
572			aData.UShort, aData.Long, aData.ULong, _
573			aData.Hyper, aData.UHyper, aData.Float, _
574			aData.Double, aData.Enum, aData.String, _
575			aData.Interface, aData.Any)
576        aData.Sequence(1) = New TestElement 'is empty
577
578		' aData complete
579		'
580		' this is a manually copy of aData for first setting...
581		Dim aSetData As New TestDataElements
582		Dim aAnySet As New Any(GetType(System.Object), xI)
583		assign( DirectCast(aSetData, TestElement), _
584				aData.Bool, aData.Char, aData.Byte, aData.Short, aData.UShort, _
585				aData.Long, aData.ULong, aData.Hyper, aData.UHyper, aData.Float, _
586                aData.Double, aData.Enum, aData.String, xI, aAnySet)
587
588		aSetData.Sequence = New TestElement(1){}
589        aSetData.Sequence(0) = New TestElement( _
590			aSetData.Bool, aSetData.Char, aSetData.Byte, aSetData.Short, _
591			aSetData.UShort, aSetData.Long, aSetData.ULong, _
592			aSetData.Hyper, aSetData.UHyper, aSetData.Float, _
593			aSetData.Double, aSetData.Enum, aSetData.String, _
594			aSetData.Interface, aSetData.Any)
595        aSetData.Sequence(1) = New TestElement ' empty struct
596
597		xLBT.setValues( _
598				aSetData.Bool, aSetData.Char, aSetData.Byte, aSetData.Short, _
599                aSetData.UShort, aSetData.Long, aSetData.ULong, _
600                aSetData.Hyper, aSetData.UHyper, aSetData.Float, _
601                aSetData.Double, aSetData.Enum, aSetData.String, _
602                aSetData.Interface, aSetData.Any, aSetData.Sequence, _
603                aSetData )
604
605
606		Dim aRet As New TestDataElements
607        Dim aRet2 As New TestDataElements
608		xLBT.getValues( _
609			aRet.Bool, aRet.Char, aRet.Byte, aRet.Short, _
610            aRet.UShort, aRet.Long, aRet.ULong, _
611            aRet.Hyper, aRet.UHyper, aRet.Float, _
612            aRet.Double, aRet.Enum, aRet.String, _
613            aRet.Interface, aRet.Any, aRet.Sequence, _
614            aRet2 )
615
616		bRet = check( compareData( aData, aRet ) And _
617                      compareData( aData, aRet2 ) , "getValues test") And bRet
618
619		' set last retrieved values
620		Dim  aSV2ret As TestDataElements= xLBT.setValues2( _
621			aRet.Bool, aRet.Char, aRet.Byte, _
622            aRet.Short, aRet.UShort, aRet.Long, _
623            aRet.ULong, aRet.Hyper, aRet.UHyper, _
624            aRet.Float, aRet.Double, aRet.Enum, _
625            aRet.String, aRet.Interface, aRet.Any, _
626            aRet.Sequence, aRet2 )
627
628        ' check inout sequence order
629        ' => inout sequence parameter was switched by test objects
630		Dim temp As TestElement = aRet.Sequence( 0 )
631        aRet.Sequence( 0 ) = aRet.Sequence( 1 )
632        aRet.Sequence( 1 ) = temp
633
634		bRet = check( _
635            compareData( aData, aSV2ret ) And compareData( aData, aRet2 ), _
636            "getValues2 test") And bRet
637
638
639		aRet = New TestDataElements
640        aRet2 = New TestDataElements
641		Dim  aGVret As TestDataElements= xLBT.getValues( _
642			aRet.Bool, aRet.Char, aRet.Byte, _
643            aRet.Short, aRet.UShort, aRet.Long, _
644            aRet.ULong, aRet.Hyper, aRet.UHyper, _
645            aRet.Float, aRet.Double, aRet.Enum, _
646            aRet.String, aRet.Interface, aRet.Any, _
647            aRet.Sequence, aRet2 )
648
649		bRet = check( compareData( aData, aRet ) And _
650                      compareData( aData, aRet2 ) And _
651                      compareData( aData, aGVret ), "getValues test" ) And bRet
652
653		' set last retrieved values
654		xLBT.Bool = aRet.Bool
655		xLBT.Char = aRet.Char
656		xLBT.Byte = aRet.Byte
657		xLBT.Short = aRet.Short
658		xLBT.UShort = aRet.UShort
659        xLBT.Long = aRet.Long
660		xLBT.ULong = aRet.ULong
661		xLBT.Hyper = aRet.Hyper
662		xLBT.UHyper = aRet.UHyper
663		xLBT.Float = aRet.Float
664		xLBT.Double = aRet.Double
665		xLBT.Enum = aRet.Enum
666		xLBT.String = aRet.String
667		xLBT.Interface = aRet.Interface
668		xLBT.Any = aRet.Any
669		xLBT.Sequence = aRet.Sequence
670		xLBT.Struct = aRet2
671
672
673		aRet = New TestDataElements
674        aRet2 = New TestDataElements
675		aRet.Hyper = xLBT.Hyper
676		aRet.UHyper = xLBT.UHyper
677		aRet.Float = xLBT.Float
678		aRet.Double = xLBT.Double
679		aRet.Byte = xLBT.Byte
680		aRet.Char = xLBT.Char
681		aRet.Bool = xLBT.Bool
682		aRet.Short = xLBT.Short
683		aRet.UShort = xLBT.UShort
684		aRet.Long = xLBT.Long
685		aRet.ULong = xLBT.ULong
686		aRet.Enum = xLBT.Enum
687		aRet.String = xLBT.String
688		aRet.Interface = xLBT.Interface
689		aRet.Any = xLBT.Any
690		aRet.Sequence = xLBT.Sequence
691		aRet2 = xLBT.Struct
692
693		bRet = check( compareData( aData, aRet ) And _
694                      compareData( aData, aRet2 ) , "struct comparison test") _
695                     And bRet
696
697		bRet = check(performSequenceTest(xLBT), "sequence test") And bRet
698
699		' any test
700		bRet = check( performAnyTest( xLBT , aData ) , "any test" ) And bRet
701
702		'sequence of call test
703		bRet = check( performSequenceOfCallTest( xLBT ) , _
704                      "sequence of call test" ) And bRet
705
706		' recursive call test
707		bRet = check( performRecursiveCallTest( xLBT ) , "recursive test" ) _
708                And bRet
709
710		bRet = (compareData( aData, aRet ) And compareData( aData, aRet2 )) _
711                And bRet
712
713        ' check setting of null reference
714        xLBT.Interface = Nothing
715        aRet.Interface = xLBT.Interface
716        bRet = (aRet.Interface Is Nothing) And bRet
717
718        Return bRet
719    End Function
720
721    Private Shared Function raiseException(xLBT As XBridgeTest) As Boolean
722	    Dim nCount As Integer = 0
723	    Try
724		    Try
725			    Try
726				    Dim aRet As TestDataElements = New TestDataElements
727                    Dim aRet2 As TestDataElements = New TestDataElements
728				    xLBT.raiseException( _
729					    5, CONSTANTS.STRING_TEST_CONSTANT, xLBT.Interface )
730			    Catch  rExc As unoidl.com.sun.star.lang.IllegalArgumentException
731				    If rExc.ArgumentPosition = 5 And _
732                        rExc.Context Is xLBT.Interface
733					    nCount = nCount + 1
734				    Else
735					    check( False, "### unexpected exception content!" )
736				    End If
737
738				    'it is certain, that the RuntimeException testing will fail,
739                    '    if no
740				    xLBT.RuntimeException = 0
741			    End Try
742		    Catch rExc As unoidl.com.sun.star.uno.RuntimeException
743			    If rExc.Context Is xLBT.Interface
744			       nCount = nCount + 1
745			    Else
746				    check( False, "### unexpected exception content!" )
747			    End If
748                xLBT.RuntimeException = CType(&Hcafebabe, Integer)
749    	    End Try
750	    Catch rExc As unoidl.com.sun.star.uno.Exception
751		    If rExc.Context Is xLBT.Interface
752		        nCount = nCount + 1
753		    Else
754			    check( False, "### unexpected exception content!" )
755            End If
756		    Return nCount = 3
757	    End Try
758        Return False
759    End Function
760
761    Private Shared Function raiseOnewayException(xLBT As XBridgeTest) As Boolean
762        Dim bReturn As Boolean= True
763	    Dim sCompare As String = CONSTANTS.STRING_TEST_CONSTANT
764	    Try
765		    ' Note : the exception may fly or not (e.g. remote scenario).
766		    '        When it flies, it must contain the correct elements.
767		    xLBT.raiseRuntimeExceptionOneway(sCompare, xLBT.Interface )
768	    Catch e As RuntimeException
769		    bReturn =  xLBT.Interface Is e.Context
770	    End Try
771        Return bReturn
772    End Function
773
774    'Test the System::Object method on the proxy object
775    '
776    Private Shared Function testObjectMethodsImplemention(xLBT As XBridgeTest) As Boolean
777        Dim ret As Boolean = False
778        Dim obj As Object = New Object
779	    Dim xInt As Object = DirectCast(xLBT, Object)
780	    Dim xBase As XBridgeTestBase = DirectCast(xLBT, XBridgeTestBase)
781	    ' Object.Equals
782	    ret = DirectCast(xLBT, Object).Equals(obj) = False
783	    ret = DirectCast(xLBT, Object).Equals(xLBT) And ret
784	    ret = Object.Equals(obj, obj) And ret
785	    ret = Object.Equals(xLBT, xBase) And ret
786	    'Object.GetHashCode
787	    ' Don't know how to verify this. Currently it is not possible to get the object id from a proxy
788	    Dim nHash As Integer = DirectCast(xLBT, Object).GetHashCode()
789	    ret = nHash = DirectCast(xBase, Object).GetHashCode() And ret
790
791	    'Object.ToString
792        ' Don't know how to verify this automatically.
793	    Dim s As String = DirectCast(xLBT, Object).ToString()
794        ret = (s.Length > 0) And ret
795        Return ret
796    End Function
797
798    Private Shared Function performQueryForUnknownType(xLBT As XBridgeTest) As Boolean
799        Dim bRet As Boolean = False
800        ' test queryInterface for an unknown type
801        Try
802            Dim a As foo.MyInterface = DirectCast(xLBT, foo.MyInterface)
803        Catch e As System.InvalidCastException
804            bRet = True
805        End Try
806
807        Return bRet
808    End Function
809
810
811    Private Shared Sub perform_test( xLBT As XBridgeTest)
812        Dim bRet As Boolean = True
813        bRet = check( performTest( xLBT ), "standard test" ) And bRet
814        bRet = check( raiseException( xLBT ) , "exception test" ) And bRet
815        bRet = check( raiseOnewayException( xLBT ), "oneway exception test" ) _
816               And bRet
817        bRet = check( testObjectMethodsImplemention(xLBT), _
818               "object methods test") And bRet
819        bRet = performQueryForUnknownType( xLBT ) And bRet
820        If  Not bRet
821            Throw New unoidl.com.sun.star.uno.RuntimeException( "error: test failed!", Nothing)
822        End If
823    End Sub
824
825
826
827    Public Overridable Function run(args() As String) As Integer _
828	   Implements XMain.run
829        Try
830            If (args.Length < 1)
831                Throw New RuntimeException( _
832                    "missing argument for bridgetest!", Me )
833            End If
834
835            Dim test_obj As Object = _
836                m_xContext.getServiceManager().createInstanceWithContext( _
837                    args( 0 ), m_xContext )
838
839            Debug.WriteLine( _
840                "cli target bridgetest obj: {0}", test_obj.ToString() )
841            Dim xTest As XBridgeTest = DirectCast(test_obj, XBridgeTest)
842            perform_test( xTest )
843            Console.WriteLine("### cli_uno VB bridgetest succeeded.")
844            return 0
845	Catch e as unoidl.com.sun.star.uno.RuntimeException
846	     Throw
847        Catch e as System.Exception
848	      Throw New unoidl.com.sun.star.uno.RuntimeException( _
849		    "cli_vb_bridgetest.vb: unexpected exception occurred in XMain::run. " _
850		    & "Original exception: " + e.GetType().Name + "\n Message: " _
851		    & e.Message , Nothing)
852
853        End Try
854    End Function
855
856End Class
857
858End Namespace
859