1 '*************************************************************************
3 ' DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 ' Copyright 2008 by Sun Microsystems, Inc.
7 ' OpenOffice.org - a multi-platform office productivity suite
9 ' $RCSfile: cli_vb_bridgetest.vb,v $
13 ' This file is part of OpenOffice.org.
15 ' OpenOffice.org is free software: you can redistribute it and/or modify
16 ' it under the terms of the GNU Lesser General Public License version 3
17 ' only, as published by the Free Software Foundation.
19 ' OpenOffice.org is distributed in the hope that it will be useful,
20 ' but WITHOUT ANY WARRANTY; without even the implied warranty of
21 ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 ' GNU Lesser General Public License version 3 for more details
23 ' (a copy is included in the LICENSE file that accompanied this code).
25 ' You should have received a copy of the GNU Lesser General Public License
26 ' version 3 along with OpenOffice.org. If not, see
27 ' <http://www.openoffice.org/license.html>
28 ' for a copy of the LGPLv3 License.
30 '*************************************************************************
40 imports unoidl
.com
.sun
.star
.lang
41 imports unoidl
.com
.sun
.star
.uno
42 'imports unoidl.com.sun.star.test.bridge
43 imports unoidl
.test
.testtools
.bridgetest
44 imports System
.Windows
.Forms
45 imports System
.Diagnostics
46 imports System
.Reflection
49 Friend Shared STRING_TEST_CONSTANT
As String = """ paco\' chorizo\\\' ""\'"
54 Public Interface MyInterface
58 Namespace vb_bridetest
61 Implements XRecursiveCall
63 Overridable
Sub callRecursivly(xCall
As XRecursiveCall
, nToCall
As Integer) _
64 Implements XRecursiveCall
.callRecursivly
68 xCall
.callRecursivly(Me, nToCall
)
77 Public Class BridgeTest
78 Inherits uno
.util
.WeakBase
81 Private m_xContext
As XComponentContext
83 Public Sub New( xContext
As unoidl
.com
.sun
.star
.uno
.XComponentContext
)
88 Private Shared
Function check( b
As Boolean , message
As String ) As Boolean
90 Console
.WriteLine("{0} failed\n" , message
)
95 Private Shared
Sub assign( rData
As TestElement
, bBool
As Boolean, _
96 aChar
As Char
, nByte
As Byte, nShort
As Short
, nUShort
As UInt16
, _
97 nLong
As Integer, nULong
As UInt32
, nHyper
As Long, _
98 nUHyper
As UInt64
, fFloat
As Single, fDouble
As Double, _
99 eEnum
As TestEnum
, rStr
As String, xTest
As Object, _
106 rData
.UShort
= nUShort
110 rData
.UHyper
= nUHyper
112 rData
.Double = fDouble
115 rData
.Interface
= xTest
119 Private Shared
Sub assign( rData
As TestDataElements
, bBool
As Boolean, _
120 aChar
As Char
, nByte
As Byte, nShort
As Short
, nUShort
As UInt16
, _
121 nLong
As Integer, nULong
As UInt32
, nHyper
As Long, _
122 nUHyper
As UInt64
, fFloat
As Single, fDouble
As Double, _
123 eEnum
As TestEnum
, rStr
As String, xTest
As Object, _
124 rAny
As Any
, rSequence() As TestElement
)
126 assign( DirectCast( rData
,TestElement
), _
127 bBool
, aChar
, nByte
, nShort
, nUShort
, nLong
, nULong
, nHyper
, _
128 nUHyper
, fFloat
, fDouble
, eEnum
, rStr
, xTest
, rAny
)
129 rData
.Sequence
= rSequence
132 Private Shared
Function compareData(val1
As Object, val2
As Object) As Boolean
133 If val1 Is
Nothing And val2 Is
Nothing OrElse _
137 If val1 Is
Nothing And Not(val2 Is
Nothing) OrElse _
138 Not (val1 Is
Nothing) And val2 Is
Nothing OrElse _
139 Not val1
.GetType().Equals( val2
.GetType())
143 Dim ret
As Boolean = False
144 Dim t1
As Type = val1
.GetType()
147 ret
= compareSequence(DirectCast( val1
, Array
), _
148 DirectCast( val2
, Array
))
150 ElseIf TypeOf val1 Is
String
151 ret
= DirectCast( val1
, string) = DirectCast( val2
, string)
152 ' Interface implementation
153 ElseIf t1
.GetInterfaces().Length
> 0 And Not t1
.IsValueType
156 ElseIf Not t1
.IsValueType
157 ret
= compareStruct(val1
, val2
)
158 ElseIf TypeOf val1 Is Any
159 Dim a1
As Any
= DirectCast( val1
, Any
)
160 Dim a2
As Any
= DirectCast( val2
, Any
)
161 ret
= a1
.Type.Equals( a2
.Type ) And compareData( a1
.Value
, a2
.Value
)
162 ElseIf t1
.IsValueType
163 'Any, enum, int, bool char, float, double etc.
164 ret
= val1
.Equals(val2
)
171 ' Arrays have only one dimension
172 Private Shared
Function compareSequence( ar1
As Array
, ar2
As Array
) As Boolean
173 Debug
.Assert( Not (ar1 Is
Nothing) And Not (ar2 Is
Nothing) )
174 Dim t1
As Type = ar1
.GetType()
175 Dim t2
As Type = ar2
.GetType()
177 if ( Not(ar1
.Rank
= 1 And ar2
.Rank
= 1 _
178 And ar1
.Length
= ar2
.Length
And t1
.GetElementType().Equals(t2
.GetElementType())))
181 'arrays have same rank and size and element type.
182 Dim len
As Integer = ar1
.Length
183 Dim elemType
As Type = t1
.GetElementType()
184 Dim ret
As Boolean = True
187 If (compareData(ar1
.GetValue(i
), ar2
.GetValue(i
)) = False)
196 Private Shared
Function compareStruct( val1
As Object, val2
As Object) As Boolean
197 Debug
.Assert( Not(val1 Is
Nothing) And Not(val2 Is
Nothing))
198 Dim t1
As Type = val1
.GetType()
199 Dim t2
As Type = val2
.GetType()
203 Dim fields() As FieldInfo
= t1
.GetFields()
204 Dim cFields
As Integer = fields
.Length
205 Dim ret
As Boolean = True
207 For i
= 0 To cFields
- 1
208 Dim fieldVal1
As Object = fields(i
).GetValue(val1
)
209 Dim fieldVal2
As Object = fields(i
).GetValue(val2
)
210 If Not compareData(fieldVal1
, fieldVal2
)
219 Private Shared
Function performSequenceTest(xBT
As XBridgeTest
) As Boolean
220 Dim bRet
As Boolean = True
221 'Automati cast ?? like with COM objects
222 Dim xBT2
As XBridgeTest2
224 xBT2
= DirectCast(xBT
,XBridgeTest2
)
225 Catch e
As InvalidCastException
229 ' perform sequence tests (XBridgeTest2)
230 'create the sequence which are compared with the results
231 Dim arBool() As Boolean = {True, False, True}
232 Dim arChar() As Char
= {"A"C
,"B"C
,"C"C
}
233 Dim arByte() As Byte = { 1, 2, &Hff
}
234 Dim arShort() As Short
= {Int16
.MinValue
, 1, Int16
.MaxValue
}
235 Dim arUShort() As UInt16
= {Convert
.ToUInt16(0), Convert
.ToUInt16(1), _
236 Convert
.ToUInt16(&Hffff
)}
237 Dim arLong() As Integer = {Int32
.MinValue
, 1, Int32
.MaxValue
}
238 Dim arULong() As UInt32
= {Convert
.ToUInt32(0), Convert
.ToUInt32(1), _
239 Convert
.ToUInt32(&HffffffffL
)}
240 Dim arHyper() As Long = {Int64
.MinValue
, 1, Int64
.MaxValue
}
241 Dim arUHyper() As UInt64
= {Convert
.ToUInt64(0), Convert
.ToUInt64(1), _
242 Convert
.ToUInt64(&Hffffffff5L
)}
243 Dim arFloat() As Single = {1.1f
, 2.2f
, 3.3f
}
244 Dim arDouble() As Double = {1.11, 2.22, 3.33}
245 Dim arString() As String = {"String 1", "String 2", "String 3"}
247 Dim arAny() As Any
= {New Any(True), New Any(11111), New Any(3.14)}
248 Dim arObject() As Object = {New WeakBase(), New WeakBase(), New WeakBase()}
249 Dim arEnum() As TestEnum
= {TestEnum
.ONE
, TestEnum
.TWO
, TestEnum
.CHECK
}
251 Dim arStruct() As TestElement
= {New TestElement(), New TestElement(), _
253 assign( arStruct(0), True, "@"C
, 17, &H1234
, Convert
.ToUInt16(&Hfedc
), _
254 &H12345678
, Convert
.ToUInt32(&H123456
), &H123456789abcdef0
, _
255 Convert
.ToUInt64(123456788), 17.0815F
, 3.1415926359, _
256 TestEnum
.LOLA
, CONSTANTS
.STRING_TEST_CONSTANT
, arObject(0), _
257 New Any(GetType(System
.Object), arObject(0)))
258 assign( arStruct(1), True, "A"C
, 17, &H1234
, Convert
.ToUInt16(&Hfedc
), _
259 &H12345678
, Convert
.ToUInt32(&H123456
), &H123456789abcdef0
, _
260 Convert
.ToUInt64(12345678), 17.0815F
, 3.1415926359, _
261 TestEnum
.TWO
, CONSTANTS
.STRING_TEST_CONSTANT
, arObject(1), _
262 New Any(GetType(System
.Object), arObject(1)) )
263 assign( arStruct(2), True, "B"C
, 17, &H1234
, Convert
.ToUInt16(&Hfedc
), _
264 &H12345678
, Convert
.ToUInt32(654321), &H123456789abcdef0
, _
265 Convert
.ToUInt64(87654321), 17.0815F
, 3.1415926359, _
266 TestEnum
.CHECK
, Constants
.STRING_TEST_CONSTANT
, arObject(2), _
267 New Any(GetType(System
.Object), arObject(2)))
270 Dim arLong3()()() As Integer = New Integer()()() { _
271 New Integer()(){New Integer(){1,2,3},New Integer(){4,5,6}, New Integer(){7,8,9} }, _
272 New Integer ()(){New Integer(){1,2,3},New Integer(){4,5,6}, New Integer(){7,8,9}}, _
273 New Integer()(){New Integer(){1,2,3},New Integer(){4,5,6}, New Integer(){7,8,9}}}
275 Dim seqSeqRet()() As Integer = xBT2
.setDim2(arLong3(0))
276 bRet
= check( compareData(seqSeqRet
, arLong3(0)), "sequence test") _
278 Dim seqSeqRet2()()() As Integer = xBT2
.setDim3(arLong3
)
279 bRet
= check( compareData(seqSeqRet2
, arLong3
), "sequence test") _
281 Dim seqAnyRet() As Any
= xBT2
.setSequenceAny(arAny
)
282 bRet
= check( compareData(seqAnyRet
, arAny
), "sequence test") And bRet
283 Dim seqBoolRet() As Boolean = xBT2
.setSequenceBool(arBool
)
284 bRet
= check( compareData(seqBoolRet
, arBool
), "sequence test") _
286 Dim seqByteRet() As Byte = xBT2
.setSequenceByte(arByte
)
287 bRet
= check( compareData(seqByteRet
, arByte
), "sequence test") _
289 Dim seqCharRet() As Char
= xBT2
.setSequenceChar(arChar
)
290 bRet
= check( compareData(seqCharRet
, arChar
), "sequence test") _
292 Dim seqShortRet() As Short
= xBT2
.setSequenceShort(arShort
)
293 bRet
= check( compareData(seqShortRet
, arShort
), "sequence test") _
295 Dim seqLongRet() As Integer = xBT2
.setSequenceLong(arLong
)
296 bRet
= check( compareData(seqLongRet
, arLong
), "sequence test") _
298 Dim seqHyperRet() As Long = xBT2
.setSequenceHyper(arHyper
)
299 bRet
= check( compareData(seqHyperRet
,arHyper
), "sequence test") _
301 Dim seqFloatRet() As Single = xBT2
.setSequenceFloat(arFloat
)
302 bRet
= check( compareData(seqFloatRet
, arFloat
), "sequence test") _
304 Dim seqDoubleRet() As Double= xBT2
.setSequenceDouble(arDouble
)
305 bRet
= check( compareData(seqDoubleRet
, arDouble
), "sequence test") _
307 Dim seqEnumRet() As TestEnum
= xBT2
.setSequenceEnum(arEnum
)
308 bRet
= check( compareData(seqEnumRet
, arEnum
), "sequence test") _
310 Dim seqUShortRet() As UInt16
= xBT2
.setSequenceUShort(arUShort
)
311 bRet
= check( compareData(seqUShortRet
, arUShort
), "sequence test") _
313 Dim seqULongRet() As UInt32
= xBT2
.setSequenceULong(arULong
)
314 bRet
= check( compareData(seqULongRet
, arULong
), "sequence test") _
316 Dim seqUHyperRet() As UInt64
= xBT2
.setSequenceUHyper(arUHyper
)
317 bRet
= check( compareData(seqUHyperRet
, arUHyper
), "sequence test") _
319 Dim seqObjectRet() As Object = xBT2
.setSequenceXInterface(arObject
)
320 bRet
= check( compareData(seqObjectRet
, arObject
), "sequence test") _
322 Dim seqStringRet() As String = xBT2
.setSequenceString(arString
)
323 bRet
= check( compareData(seqStringRet
, arString
), "sequence test") _
325 Dim seqStructRet() As TestElement
= xBT2
.setSequenceStruct(arStruct
)
326 bRet
= check( compareData(seqStructRet
, arStruct
), "sequence test") _
330 Dim arBoolTemp() As Boolean = DirectCast(arBool
.Clone(), Boolean())
331 Dim arCharTemp() As Char
= DirectCast(arChar
.Clone(), Char())
332 Dim arByteTemp() As Byte = DirectCast(arByte
.Clone(), Byte())
333 Dim arShortTemp() As Short
= DirectCast(arShort
.Clone(), Short())
334 Dim arUShortTemp() As UInt16
= DirectCast(arUShort
.Clone(), UInt16())
335 Dim arLongTemp() As Integer= DirectCast(arLong
.Clone(), Integer())
336 Dim arULongTemp() As UInt32
= DirectCast(arULong
.Clone(), UInt32())
337 Dim arHyperTemp() As Long = DirectCast(arHyper
.Clone(), Long())
338 Dim arUHyperTemp() As UInt64
= DirectCast(arUHyper
.Clone(), UInt64())
339 Dim arFloatTemp() As Single = DirectCast(arFloat
.Clone(), Single())
340 Dim arDoubleTemp() As Double = DirectCast(arDouble
.Clone(), Double())
341 Dim arEnumTemp() As TestEnum
= DirectCast(arEnum
.Clone(), TestEnum())
342 Dim arStringTemp() As String = DirectCast(arString
.Clone(), String())
343 Dim arObjectTemp() As Object = DirectCast(arObject
.Clone(), Object())
344 Dim arAnyTemp() As Any
= DirectCast(arAny
.Clone(), Any())
345 ' make sure this are has the same contents as arLong3(0)
346 Dim arLong2Temp()() As Integer = New Integer()(){New Integer(){1,2,3}, _
347 New Integer(){4,5,6}, New Integer(){7,8,9} }
348 ' make sure this are has the same contents as arLong3
349 Dim arLong3Temp()()() As Integer = New Integer()()(){ _
350 New Integer()(){New Integer(){1,2,3},New Integer(){4,5,6}, New Integer(){7,8,9} }, _
351 New Integer ()(){New Integer(){1,2,3},New Integer(){4,5,6}, New Integer(){7,8,9}}, _
352 New Integer()(){New Integer(){1,2,3},New Integer(){4,5,6}, New Integer(){7,8,9}}}
354 xBT2
.setSequencesInOut( arBoolTemp
, arCharTemp
, arByteTemp
, _
355 arShortTemp
, arUShortTemp
, arLongTemp
, _
356 arULongTemp
, arHyperTemp
, arUHyperTemp
, _
357 arFloatTemp
, arDoubleTemp
, arEnumTemp
, _
358 arStringTemp
, arObjectTemp
, _
359 arAnyTemp
, arLong2Temp
, arLong3Temp
)
361 compareData(arBoolTemp
, arBool
) And _
362 compareData(arCharTemp
, arChar
) And _
363 compareData(arByteTemp
, arByte
) And _
364 compareData(arShortTemp
, arShort
) And _
365 compareData(arUShortTemp
, arUShort
) And _
366 compareData(arLongTemp
, arLong
) And _
367 compareData(arULongTemp
, arULong
) And _
368 compareData(arHyperTemp
, arHyper
) And _
369 compareData(arUHyperTemp
, arUHyper
) And _
370 compareData(arFloatTemp
, arFloat
) And _
371 compareData(arDoubleTemp
, arDouble
) And _
372 compareData(arEnumTemp
, arEnum
) And _
373 compareData(arStringTemp
, arString
) And _
374 compareData(arObjectTemp
, arObject
) And _
375 compareData(arAnyTemp
, arAny
) And _
376 compareData(arLong2Temp
, arLong3(0)) And _
377 compareData(arLong3Temp
, arLong3
), "sequence test") And bRet
379 Dim arBoolOut() As Boolean
380 Dim arCharOut() As Char
381 Dim arByteOut() As Byte
382 Dim arShortOut() As Short
383 Dim arUShortOut() As UInt16
384 Dim arLongOut() As Integer
385 Dim arULongOut() As UInt32
386 Dim arHyperOut() As Long
387 Dim arUHyperOut() As UInt64
388 Dim arFloatOut() As Single
389 Dim arDoubleOut() As Double
390 Dim arEnumOut() As TestEnum
391 Dim arStringOut() As String
392 Dim arObjectOut() As Object
393 Dim arAnyOut() As Any
394 Dim arLong2Out()() As Integer
395 Dim arLong3Out()()() As Integer
397 xBT2
.setSequencesOut( arBoolOut
, arCharOut
, arByteOut
, _
398 arShortOut
, arUShortOut
, arLongOut
, _
399 arULongOut
, arHyperOut
, arUHyperOut
, _
400 arFloatOut
, arDoubleOut
, arEnumOut
, _
401 arStringOut
, arObjectOut
, arAnyOut
, _
402 arLong2Out
, arLong3Out
)
404 compareData(arBoolOut
, arBool
) And _
405 compareData(arCharOut
, arChar
) And _
406 compareData(arByteOut
, arByte
) And _
407 compareData(arShortOut
, arShort
) And _
408 compareData(arUShortOut
, arUShort
) And _
409 compareData(arLongOut
, arLong
) And _
410 compareData(arULongOut
, arULong
) And _
411 compareData(arHyperOut
, arHyper
) And _
412 compareData(arUHyperOut
, arUHyper
) And _
413 compareData(arFloatOut
, arFloat
) And _
414 compareData(arDoubleOut
, arDouble
) And _
415 compareData(arEnumOut
, arEnum
) And _
416 compareData(arStringOut
, arString
) And _
417 compareData(arObjectOut
, arObject
) And _
418 compareData(arAnyOut
, arAny
) And _
419 compareData(arLong2Out
, arLong3(0)) And _
420 compareData(arLong3Out
, arLong3
), "sequence test") And bRet
423 'test with empty sequences
424 Dim _arLong2()() As Integer = New Integer()(){}
425 seqSeqRet
= xBT2
.setDim2(_arLong2
)
426 bRet
= check( compareData(seqSeqRet
, _arLong2
), "sequence test") And bRet
427 Dim _arLong3()()() As Integer = New Integer()()(){}
428 seqSeqRet2
= xBT2
.setDim3(_arLong3
)
429 bRet
= check( compareData(seqSeqRet2
, _arLong3
), "sequence test") And bRet
430 Dim _arAny() As Any
= New Any(){}
431 seqAnyRet
= xBT2
.setSequenceAny(_arAny
)
432 bRet
= check( compareData(seqAnyRet
, _arAny
), "sequence test") And bRet
433 Dim _arBool() As Boolean = New Boolean() {}
434 seqBoolRet
= xBT2
.setSequenceBool(_arBool
)
435 bRet
= check( compareData(seqBoolRet
, _arBool
), "sequence test") And bRet
436 Dim _arByte() As Byte = New Byte() {}
437 seqByteRet
= xBT2
.setSequenceByte(_arByte
)
438 bRet
= check( compareData(seqByteRet
, _arByte
), "sequence test") And bRet
439 Dim _arChar() As Char
= New Char() {}
440 seqCharRet
= xBT2
.setSequenceChar(_arChar
)
441 bRet
= check( compareData(seqCharRet
, _arChar
), "sequence test") And bRet
442 Dim _arShort() As Short
= New Short() {}
443 seqShortRet
= xBT2
.setSequenceShort(_arShort
)
444 bRet
= check( compareData(seqShortRet
, _arShort
), "sequence test") And bRet
445 Dim _arLong() As Integer = New Integer() {}
446 seqLongRet
= xBT2
.setSequenceLong(_arLong
)
447 bRet
= check( compareData(seqLongRet
, _arLong
), "sequence test") And bRet
448 Dim _arHyper() As Long = New Long(){}
449 seqHyperRet
= xBT2
.setSequenceHyper(_arHyper
)
450 bRet
= check( compareData(seqHyperRet
, _arHyper
), "sequence test") And bRet
451 Dim _arFloat() As Single = New Single(){}
452 seqFloatRet
= xBT2
.setSequenceFloat(_arFloat
)
453 bRet
= check( compareData(seqFloatRet
, _arFloat
), "sequence test") And bRet
454 Dim _arDouble() As Double = New Double(){}
455 seqDoubleRet
= xBT2
.setSequenceDouble(_arDouble
)
456 bRet
= check( compareData(seqDoubleRet
, _arDouble
), "sequence test") And bRet
457 Dim _arEnum() As TestEnum
= New TestEnum(){}
458 seqEnumRet
= xBT2
.setSequenceEnum(_arEnum
)
459 bRet
= check( compareData(seqEnumRet
, _arEnum
), "sequence test") And bRet
460 Dim _arUShort() As UInt16
= New UInt16(){}
461 seqUShortRet
= xBT2
.setSequenceUShort(_arUShort
)
462 bRet
= check( compareData(seqUShortRet
, _arUShort
), "sequence test") And bRet
463 Dim _arULong() As UInt32
= New UInt32(){}
464 seqULongRet
= xBT2
.setSequenceULong(_arULong
)
465 bRet
= check( compareData(seqULongRet
, _arULong
), "sequence test") And bRet
466 Dim _arUHyper() As UInt64
= New UInt64(){}
467 seqUHyperRet
= xBT2
.setSequenceUHyper(_arUHyper
)
468 bRet
= check( compareData(seqUHyperRet
, _arUHyper
), "sequence test") And bRet
469 Dim _arObject() As Object = New Object(){}
470 seqObjectRet
= xBT2
.setSequenceXInterface(_arObject
)
471 bRet
= check( compareData(seqObjectRet
, _arObject
), "sequence test") And bRet
472 Dim _arString() As String = New String(){}
473 seqStringRet
= xBT2
.setSequenceString(_arString
)
474 bRet
= check( compareData(seqStringRet
, _arString
), "sequence test") And bRet
475 Dim _arStruct() As TestElement
= New TestElement(){}
476 seqStructRet
= xBT2
.setSequenceStruct(_arStruct
)
477 bRet
= check( compareData(seqStructRet
, _arStruct
), "sequence test") And bRet
481 Private Shared
Function testAny(typ
As Type, value
As Object, _
482 xLBT
As XBridgeTest
) As Boolean
486 any
= New Any(value
.GetType(), value
)
488 any
= New Any(typ
, value
)
491 Dim any2
As Any
= xLBT
.transportAny(any
)
492 Dim ret
As Boolean = compareData(any
, any2
)
494 Console
.WriteLine("any is different after roundtrip: in {0}, " _
496 any
.Type.FullName
, any2
.Type.FullName
)
501 Private Shared
Function performAnyTest(xLBT
As XBridgeTest
, _
502 data
As TestDataElements
) As Boolean
503 Dim bReturn
As Boolean = True
504 bReturn
= testAny( Nothing, data
.Byte ,xLBT
) And bReturn
505 bReturn
= testAny( Nothing, data
.Short
,xLBT
) And bReturn
506 bReturn
= testAny( Nothing, data
.UShort
,xLBT
) And bReturn
507 bReturn
= testAny( Nothing, data
.Long,xLBT
) And bReturn
508 bReturn
= testAny( Nothing, data
.ULong
,xLBT
) And bReturn
509 bReturn
= testAny( Nothing, data
.Hyper
,xLBT
) And bReturn
510 bReturn
= testAny( Nothing,data
.UHyper
,xLBT
) And bReturn
511 bReturn
= testAny( Nothing, data
.Float
,xLBT
) And bReturn
512 bReturn
= testAny( Nothing, data
.Double,xLBT
) And bReturn
513 bReturn
= testAny( Nothing, data
.Enum,xLBT
) And bReturn
514 bReturn
= testAny( Nothing, data
.String,xLBT
) And bReturn
515 bReturn
= testAny(GetType(unoidl
.com
.sun
.star
.uno
.XWeak
), _
516 data
.Interface
,xLBT
) And bReturn
517 bReturn
= testAny(Nothing, data
, xLBT
) And bReturn
519 Dim a1
As Any
= New Any(True)
520 Dim a2
As Any
= xLBT
.transportAny( a1
)
521 bReturn
= compareData(a2
, a1
) And bReturn
523 Dim a3
As Any
= New Any("A"C
)
524 Dim a4
As Any
= xLBT
.transportAny(a3
)
525 bReturn
= compareData(a4
, a3
) And bReturn
530 Private Shared
Function performSequenceOfCallTest(xLBT
As XBridgeTest
) As Boolean
532 Dim i
, nRounds
As Integer
533 Dim nGlobalIndex
As Integer = 0
534 const nWaitTimeSpanMUSec
As Integer = 10000
536 For i
= 0 To nRounds
- 1
538 xLBT
.callOneway(nGlobalIndex
, nWaitTimeSpanMUSec
)
539 nGlobalIndex
= nGlobalIndex
+ 1
543 xLBT
.call(nGlobalIndex
, nWaitTimeSpanMUSec
)
544 nGlobalIndex
= nGlobalIndex
+ 1
546 Return xLBT
.sequenceOfCallTestPassed()
549 Private Shared
Function performRecursiveCallTest(xLBT
As XBridgeTest
) As Boolean
550 xLBT
.startRecursiveCall(new ORecursiveCall(), 50)
551 ' on failure, the test would lock up or crash
556 Private Shared
Function performTest(xLBT
As XBridgeTest
) As Boolean
557 check( Not xLBT Is
Nothing, "### no test interface!" )
558 Dim bRet
As Boolean = True
562 'this data is never ever granted access to by calls other than equals(), assign()!
563 Dim aData
As New TestDataElements
' test against this data
564 Dim xI
As New WeakBase
566 Dim aAny
As New Any(GetType(System
.Object), xI
)
567 assign( DirectCast(aData
, TestElement
), _
568 True, "@"C
, 17, &H1234
, Convert
.ToUInt16(&HdcS
), &H12345678
, _
569 Convert
.ToUInt32(4294967294), _
570 &H123456789abcdef0
, Convert
.ToUInt64(14294967294), _
571 17.0815f
, 3.1415926359, TestEnum
.LOLA
, _
572 CONSTANTS
.STRING_TEST_CONSTANT
, xI
, _
575 bRet
= check( aData
.Any
.Value Is xI
, "### unexpected any!" ) And bRet
577 aData
.Sequence
= New TestElement(1){}
578 aData
.Sequence(0) = New TestElement( _
579 aData
.Bool
, aData
.Char
, aData
.Byte, aData
.Short
, _
580 aData
.UShort
, aData
.Long, aData
.ULong
, _
581 aData
.Hyper
, aData
.UHyper
, aData
.Float
, _
582 aData
.Double, aData
.Enum, aData
.String, _
583 aData
.Interface
, aData
.Any
)
584 aData
.Sequence(1) = New TestElement
'is empty
588 ' this is a manually copy of aData for first setting...
589 Dim aSetData
As New TestDataElements
590 Dim aAnySet
As New Any(GetType(System
.Object), xI
)
591 assign( DirectCast(aSetData
, TestElement
), _
592 aData
.Bool
, aData
.Char
, aData
.Byte, aData
.Short
, aData
.UShort
, _
593 aData
.Long, aData
.ULong
, aData
.Hyper
, aData
.UHyper
, aData
.Float
, _
594 aData
.Double, aData
.Enum, aData
.String, xI
, aAnySet
)
596 aSetData
.Sequence
= New TestElement(1){}
597 aSetData
.Sequence(0) = New TestElement( _
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
)
603 aSetData
.Sequence(1) = New TestElement
' empty struct
606 aSetData
.Bool
, aSetData
.Char
, aSetData
.Byte, aSetData
.Short
, _
607 aSetData
.UShort
, aSetData
.Long, aSetData
.ULong
, _
608 aSetData
.Hyper
, aSetData
.UHyper
, aSetData
.Float
, _
609 aSetData
.Double, aSetData
.Enum, aSetData
.String, _
610 aSetData
.Interface
, aSetData
.Any
, aSetData
.Sequence
, _
614 Dim aRet
As New TestDataElements
615 Dim aRet2
As New TestDataElements
617 aRet
.Bool
, aRet
.Char
, aRet
.Byte, aRet
.Short
, _
618 aRet
.UShort
, aRet
.Long, aRet
.ULong
, _
619 aRet
.Hyper
, aRet
.UHyper
, aRet
.Float
, _
620 aRet
.Double, aRet
.Enum, aRet
.String, _
621 aRet
.Interface
, aRet
.Any
, aRet
.Sequence
, _
624 bRet
= check( compareData( aData
, aRet
) And _
625 compareData( aData
, aRet2
) , "getValues test") And bRet
627 ' set last retrieved values
628 Dim aSV2ret
As TestDataElements
= xLBT
.setValues2( _
629 aRet
.Bool
, aRet
.Char
, aRet
.Byte, _
630 aRet
.Short
, aRet
.UShort
, aRet
.Long, _
631 aRet
.ULong
, aRet
.Hyper
, aRet
.UHyper
, _
632 aRet
.Float
, aRet
.Double, aRet
.Enum, _
633 aRet
.String, aRet
.Interface
, aRet
.Any
, _
634 aRet
.Sequence
, aRet2
)
636 ' check inout sequence order
637 ' => inout sequence parameter was switched by test objects
638 Dim temp
As TestElement
= aRet
.Sequence( 0 )
639 aRet
.Sequence( 0 ) = aRet
.Sequence( 1 )
640 aRet
.Sequence( 1 ) = temp
643 compareData( aData
, aSV2ret
) And compareData( aData
, aRet2
), _
644 "getValues2 test") And bRet
647 aRet
= New TestDataElements
648 aRet2
= New TestDataElements
649 Dim aGVret
As TestDataElements
= xLBT
.getValues( _
650 aRet
.Bool
, aRet
.Char
, aRet
.Byte, _
651 aRet
.Short
, aRet
.UShort
, aRet
.Long, _
652 aRet
.ULong
, aRet
.Hyper
, aRet
.UHyper
, _
653 aRet
.Float
, aRet
.Double, aRet
.Enum, _
654 aRet
.String, aRet
.Interface
, aRet
.Any
, _
655 aRet
.Sequence
, aRet2
)
657 bRet
= check( compareData( aData
, aRet
) And _
658 compareData( aData
, aRet2
) And _
659 compareData( aData
, aGVret
), "getValues test" ) And bRet
661 ' set last retrieved values
662 xLBT
.Bool
= aRet
.Bool
663 xLBT
.Char
= aRet
.Char
664 xLBT
.Byte = aRet
.Byte
665 xLBT
.Short
= aRet
.Short
666 xLBT
.UShort
= aRet
.UShort
667 xLBT
.Long = aRet
.Long
668 xLBT
.ULong
= aRet
.ULong
669 xLBT
.Hyper
= aRet
.Hyper
670 xLBT
.UHyper
= aRet
.UHyper
671 xLBT
.Float
= aRet
.Float
672 xLBT
.Double = aRet
.Double
673 xLBT
.Enum = aRet
.Enum
674 xLBT
.String = aRet
.String
675 xLBT
.Interface
= aRet
.Interface
677 xLBT
.Sequence
= aRet
.Sequence
681 aRet
= New TestDataElements
682 aRet2
= New TestDataElements
683 aRet
.Hyper
= xLBT
.Hyper
684 aRet
.UHyper
= xLBT
.UHyper
685 aRet
.Float
= xLBT
.Float
686 aRet
.Double = xLBT
.Double
687 aRet
.Byte = xLBT
.Byte
688 aRet
.Char
= xLBT
.Char
689 aRet
.Bool
= xLBT
.Bool
690 aRet
.Short
= xLBT
.Short
691 aRet
.UShort
= xLBT
.UShort
692 aRet
.Long = xLBT
.Long
693 aRet
.ULong
= xLBT
.ULong
694 aRet
.Enum = xLBT
.Enum
695 aRet
.String = xLBT
.String
696 aRet
.Interface
= xLBT
.Interface
698 aRet
.Sequence
= xLBT
.Sequence
701 bRet
= check( compareData( aData
, aRet
) And _
702 compareData( aData
, aRet2
) , "struct comparison test") _
705 bRet
= check(performSequenceTest(xLBT
), "sequence test") And bRet
708 bRet
= check( performAnyTest( xLBT
, aData
) , "any test" ) And bRet
710 'sequence of call test
711 bRet
= check( performSequenceOfCallTest( xLBT
) , _
712 "sequence of call test" ) And bRet
714 ' recursive call test
715 bRet
= check( performRecursiveCallTest( xLBT
) , "recursive test" ) _
718 bRet
= (compareData( aData
, aRet
) And compareData( aData
, aRet2
)) _
721 ' check setting of null reference
722 xLBT
.Interface
= Nothing
723 aRet
.Interface
= xLBT
.Interface
724 bRet
= (aRet
.Interface Is
Nothing) And bRet
729 Private Shared
Function raiseException(xLBT
As XBridgeTest
) As Boolean
730 Dim nCount
As Integer = 0
734 Dim aRet
As TestDataElements
= New TestDataElements
735 Dim aRet2
As TestDataElements
= New TestDataElements
736 xLBT
.raiseException( _
737 5, CONSTANTS
.STRING_TEST_CONSTANT
, xLBT
.Interface
)
738 Catch rExc
As unoidl
.com
.sun
.star
.lang
.IllegalArgumentException
739 If rExc
.ArgumentPosition
= 5 And _
740 rExc
.Context Is xLBT
.Interface
743 check( False, "### unexpected exception content!" )
746 'it is certain, that the RuntimeException testing will fail,
748 xLBT
.RuntimeException
= 0
750 Catch rExc
As unoidl
.com
.sun
.star
.uno
.RuntimeException
751 If rExc
.Context Is xLBT
.Interface
754 check( False, "### unexpected exception content!" )
756 xLBT
.RuntimeException
= CType(&Hcafebabe
, Integer)
758 Catch rExc
As unoidl
.com
.sun
.star
.uno
.Exception
759 If rExc
.Context Is xLBT
.Interface
762 check( False, "### unexpected exception content!" )
769 Private Shared
Function raiseOnewayException(xLBT
As XBridgeTest
) As Boolean
770 Dim bReturn
As Boolean= True
771 Dim sCompare
As String = CONSTANTS
.STRING_TEST_CONSTANT
773 ' Note : the exception may fly or not (e.g. remote scenario).
774 ' When it flies, it must contain the correct elements.
775 xLBT
.raiseRuntimeExceptionOneway(sCompare
, xLBT
.Interface
)
776 Catch e
As RuntimeException
777 bReturn
= xLBT
.Interface Is e
.Context
782 'Test the System::Object method on the proxy object
784 Private Shared
Function testObjectMethodsImplemention(xLBT
As XBridgeTest
) As Boolean
785 Dim ret
As Boolean = False
786 Dim obj
As Object = New Object
787 Dim xInt
As Object = DirectCast(xLBT
, Object)
788 Dim xBase
As XBridgeTestBase
= DirectCast(xLBT
, XBridgeTestBase
)
790 ret
= DirectCast(xLBT
, Object).Equals(obj
) = False
791 ret
= DirectCast(xLBT
, Object).Equals(xLBT
) And ret
792 ret
= Object.Equals(obj
, obj
) And ret
793 ret
= Object.Equals(xLBT
, xBase
) And ret
795 ' Don't know how to verify this. Currently it is not possible to get the object id from a proxy
796 Dim nHash
As Integer = DirectCast(xLBT
, Object).GetHashCode()
797 ret
= nHash
= DirectCast(xBase
, Object).GetHashCode() And ret
800 ' Don't know how to verify this automatically.
801 Dim s
As String = DirectCast(xLBT
, Object).ToString()
802 ret
= (s
.Length
> 0) And ret
806 Private Shared
Function performQueryForUnknownType(xLBT
As XBridgeTest
) As Boolean
807 Dim bRet
As Boolean = False
808 ' test queryInterface for an unknown type
810 Dim a
As foo
.MyInterface
= DirectCast(xLBT
, foo
.MyInterface
)
811 Catch e
As System
.InvalidCastException
819 Private Shared
Sub perform_test( xLBT
As XBridgeTest
)
820 Dim bRet
As Boolean = True
821 bRet
= check( performTest( xLBT
), "standard test" ) And bRet
822 bRet
= check( raiseException( xLBT
) , "exception test" ) And bRet
823 bRet
= check( raiseOnewayException( xLBT
), "oneway exception test" ) _
825 bRet
= check( testObjectMethodsImplemention(xLBT
), _
826 "object methods test") And bRet
827 bRet
= performQueryForUnknownType( xLBT
) And bRet
829 Throw
New unoidl
.com
.sun
.star
.uno
.RuntimeException( "error: test failed!", Nothing)
835 Public Overridable
Function run(args() As String) As Integer _
839 Throw
New RuntimeException( _
840 "missing argument for bridgetest!", Me )
843 Dim test_obj
As Object = _
844 m_xContext
.getServiceManager().createInstanceWithContext( _
845 args( 0 ), m_xContext
)
848 "cli target bridgetest obj: {0}", test_obj
.ToString() )
849 Dim xTest
As XBridgeTest
= DirectCast(test_obj
, XBridgeTest
)
850 perform_test( xTest
)
851 Console
.WriteLine("### cli_uno VB bridgetest succeeded.")
853 Catch e
as unoidl
.com
.sun
.star
.uno
.RuntimeException
855 Catch e
as System
.Exception
856 Throw
New unoidl
.com
.sun
.star
.uno
.RuntimeException( _
857 "cli_vb_bridgetest.vb: unexpected exception occured in XMain::run. " _
858 & "Original exception: " + e
.GetType().Name
+ "\n Message: " _
859 & e
.Message
, Nothing)