Update ooo320-m1
[ooovba.git] / testtools / source / bridgetest / cli / cli_vb_bridgetest.vb
blob534db3ff5af72a52350630d39c7ead16489f849d
1 '*************************************************************************
3 ' DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 '
5 ' Copyright 2008 by Sun Microsystems, Inc.
7 ' OpenOffice.org - a multi-platform office productivity suite
9 ' $RCSfile: cli_vb_bridgetest.vb,v $
11 ' $Revision: 1.7 $
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 '*************************************************************************
34 Option Explicit On
35 Option Strict On
37 imports System
38 imports uno
39 imports uno.util
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
48 Class CONSTANTS
49 Friend Shared STRING_TEST_CONSTANT As String = """ paco\' chorizo\\\' ""\'"
50 End Class
52 Namespace foo
54 Public Interface MyInterface
55 End Interface
56 End Namespace
58 Namespace vb_bridetest
59 Class ORecursiveCall
60 Inherits WeakBase
61 Implements XRecursiveCall
63 Overridable Sub callRecursivly(xCall As XRecursiveCall, nToCall As Integer) _
64 Implements XRecursiveCall.callRecursivly
65 SyncLock Me
66 If nToCall > 0
67 nToCall = nToCall - 1
68 xCall.callRecursivly(Me, nToCall)
69 End If
70 End SyncLock
71 End Sub
72 End Class
77 Public Class BridgeTest
78 Inherits uno.util.WeakBase
79 Implements XMain
81 Private m_xContext As XComponentContext
83 Public Sub New( xContext As unoidl.com.sun.star.uno.XComponentContext )
84 mybase.New()
85 m_xContext = xContext
86 End Sub
88 Private Shared Function check( b As Boolean , message As String ) As Boolean
89 If Not b
90 Console.WriteLine("{0} failed\n" , message)
91 End If
92 Return b
93 End Function
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, _
100 rAny As Any)
102 rData.Bool = bBool
103 rData.Char = aChar
104 rData.Byte = nByte
105 rData.Short = nShort
106 rData.UShort = nUShort
107 rData.Long = nLong
108 rData.ULong = nULong
109 rData.Hyper = nHyper
110 rData.UHyper = nUHyper
111 rData.Float = fFloat
112 rData.Double = fDouble
113 rData.Enum = eEnum
114 rData.String = rStr
115 rData.Interface = xTest
116 rData.Any = rAny
117 End Sub
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
130 End Sub
132 Private Shared Function compareData(val1 As Object, val2 As Object) As Boolean
133 If val1 Is Nothing And val2 Is Nothing OrElse _
134 val1 Is val2
135 Return True
136 End If
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())
140 Return False
141 End If
143 Dim ret As Boolean = False
144 Dim t1 As Type = val1.GetType()
145 'Sequence
146 If t1.IsArray()
147 ret = compareSequence(DirectCast( val1, Array), _
148 DirectCast( val2, Array))
149 'String
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
154 ret = val1 Is val2
155 ' Struct
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)
165 Else
166 Debug.Assert(False)
167 End If
168 Return ret
169 End Function
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())))
179 return False
180 End If
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
185 Dim i As Integer
186 For i = 0 To len - 1
187 If (compareData(ar1.GetValue(i), ar2.GetValue(i)) = False)
188 ret = False
189 Exit For
190 End If
191 Next i
193 Return ret
194 End Function
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()
200 If Not t1.Equals(t2)
201 Return False
202 End If
203 Dim fields() As FieldInfo = t1.GetFields()
204 Dim cFields As Integer = fields.Length
205 Dim ret As Boolean = True
206 Dim i As Integer
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)
211 ret = False
212 Exit For
213 End If
214 Next i
215 Return ret
216 End Function
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
226 Return False
227 End Try
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(), _
252 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") _
277 And bRet
278 Dim seqSeqRet2()()() As Integer = xBT2.setDim3(arLong3)
279 bRet = check( compareData(seqSeqRet2, arLong3), "sequence test") _
280 And bRet
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") _
285 And bRet
286 Dim seqByteRet() As Byte = xBT2.setSequenceByte(arByte)
287 bRet = check( compareData(seqByteRet, arByte), "sequence test") _
288 And bRet
289 Dim seqCharRet() As Char = xBT2.setSequenceChar(arChar)
290 bRet = check( compareData(seqCharRet, arChar), "sequence test") _
291 And bRet
292 Dim seqShortRet() As Short = xBT2.setSequenceShort(arShort)
293 bRet = check( compareData(seqShortRet, arShort), "sequence test") _
294 And bRet
295 Dim seqLongRet() As Integer = xBT2.setSequenceLong(arLong)
296 bRet = check( compareData(seqLongRet, arLong), "sequence test") _
297 And bRet
298 Dim seqHyperRet() As Long = xBT2.setSequenceHyper(arHyper)
299 bRet = check( compareData(seqHyperRet,arHyper), "sequence test") _
300 And bRet
301 Dim seqFloatRet() As Single = xBT2.setSequenceFloat(arFloat)
302 bRet = check( compareData(seqFloatRet, arFloat), "sequence test") _
303 And bRet
304 Dim seqDoubleRet() As Double= xBT2.setSequenceDouble(arDouble)
305 bRet = check( compareData(seqDoubleRet, arDouble), "sequence test") _
306 And bRet
307 Dim seqEnumRet() As TestEnum = xBT2.setSequenceEnum(arEnum)
308 bRet = check( compareData(seqEnumRet, arEnum), "sequence test") _
309 And bRet
310 Dim seqUShortRet() As UInt16 = xBT2.setSequenceUShort(arUShort)
311 bRet = check( compareData(seqUShortRet, arUShort), "sequence test") _
312 And bRet
313 Dim seqULongRet() As UInt32 = xBT2.setSequenceULong(arULong)
314 bRet = check( compareData(seqULongRet, arULong), "sequence test") _
315 And bRet
316 Dim seqUHyperRet() As UInt64 = xBT2.setSequenceUHyper(arUHyper)
317 bRet = check( compareData(seqUHyperRet, arUHyper), "sequence test") _
318 And bRet
319 Dim seqObjectRet() As Object = xBT2.setSequenceXInterface(arObject)
320 bRet = check( compareData(seqObjectRet, arObject), "sequence test") _
321 And bRet
322 Dim seqStringRet() As String = xBT2.setSequenceString(arString)
323 bRet = check( compareData(seqStringRet, arString), "sequence test") _
324 And bRet
325 Dim seqStructRet() As TestElement = xBT2.setSequenceStruct(arStruct)
326 bRet = check( compareData(seqStructRet, arStruct), "sequence test") _
327 And bRet
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)
360 bRet = check( _
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)
403 bRet = check( _
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
478 Return bRet
479 End Function
481 Private Shared Function testAny(typ As Type, value As Object, _
482 xLBT As XBridgeTest ) As Boolean
484 Dim any As Any
485 If (typ Is Nothing)
486 any = New Any(value.GetType(), value)
487 Else
488 any = New Any(typ, value)
489 End If
491 Dim any2 As Any = xLBT.transportAny(any)
492 Dim ret As Boolean = compareData(any, any2)
493 If ret = False
494 Console.WriteLine("any is different after roundtrip: in {0}, " _
495 & "out {1}\n", _
496 any.Type.FullName, any2.Type.FullName)
497 End If
498 Return ret
499 End Function
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
527 Return bReturn
528 End Function
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
535 For nRounds = 0 To 9
536 For i = 0 To nRounds - 1
537 ' fire oneways
538 xLBT.callOneway(nGlobalIndex, nWaitTimeSpanMUSec)
539 nGlobalIndex = nGlobalIndex + 1
540 Next
542 ' call synchron
543 xLBT.call(nGlobalIndex, nWaitTimeSpanMUSec)
544 nGlobalIndex = nGlobalIndex + 1
545 Next
546 Return xLBT.sequenceOfCallTestPassed()
547 End Function
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
552 Return True
553 End Function
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
559 If xLBT Is Nothing
560 Return False
561 End If
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, _
573 aAny)
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
586 ' aData complete
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
605 xLBT.setValues( _
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, _
611 aSetData )
614 Dim aRet As New TestDataElements
615 Dim aRet2 As New TestDataElements
616 xLBT.getValues( _
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, _
622 aRet2 )
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
642 bRet = check( _
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
676 xLBT.Any = aRet.Any
677 xLBT.Sequence = aRet.Sequence
678 xLBT.Struct = aRet2
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
697 aRet.Any = xLBT.Any
698 aRet.Sequence = xLBT.Sequence
699 aRet2 = xLBT.Struct
701 bRet = check( compareData( aData, aRet ) And _
702 compareData( aData, aRet2 ) , "struct comparison test") _
703 And bRet
705 bRet = check(performSequenceTest(xLBT), "sequence test") And bRet
707 ' any test
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" ) _
716 And bRet
718 bRet = (compareData( aData, aRet ) And compareData( aData, aRet2 )) _
719 And bRet
721 ' check setting of null reference
722 xLBT.Interface = Nothing
723 aRet.Interface = xLBT.Interface
724 bRet = (aRet.Interface Is Nothing) And bRet
726 Return bRet
727 End Function
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
741 nCount = nCount + 1
742 Else
743 check( False, "### unexpected exception content!" )
744 End If
746 'it is certain, that the RuntimeException testing will fail,
747 ' if no
748 xLBT.RuntimeException = 0
749 End Try
750 Catch rExc As unoidl.com.sun.star.uno.RuntimeException
751 If rExc.Context Is xLBT.Interface
752 nCount = nCount + 1
753 Else
754 check( False, "### unexpected exception content!" )
755 End If
756 xLBT.RuntimeException = CType(&Hcafebabe, Integer)
757 End Try
758 Catch rExc As unoidl.com.sun.star.uno.Exception
759 If rExc.Context Is xLBT.Interface
760 nCount = nCount + 1
761 Else
762 check( False, "### unexpected exception content!" )
763 End If
764 Return nCount = 3
765 End Try
766 Return False
767 End Function
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
778 End Try
779 Return bReturn
780 End Function
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)
789 ' Object.Equals
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
794 'Object.GetHashCode
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
799 'Object.ToString
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
803 Return ret
804 End Function
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
812 bRet = True
813 End Try
815 Return bRet
816 End Function
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" ) _
824 And bRet
825 bRet = check( testObjectMethodsImplemention(xLBT), _
826 "object methods test") And bRet
827 bRet = performQueryForUnknownType( xLBT ) And bRet
828 If Not bRet
829 Throw New unoidl.com.sun.star.uno.RuntimeException( "error: test failed!", Nothing)
830 End If
831 End Sub
835 Public Overridable Function run(args() As String) As Integer _
836 Implements XMain.run
838 If (args.Length < 1)
839 Throw New RuntimeException( _
840 "missing argument for bridgetest!", Me )
841 End If
843 Dim test_obj As Object = _
844 m_xContext.getServiceManager().createInstanceWithContext( _
845 args( 0 ), m_xContext )
847 Debug.WriteLine( _
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.")
852 return 0
853 Catch e as unoidl.com.sun.star.uno.RuntimeException
854 Throw
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)
861 End Try
862 End Function
864 End Class
866 End Namespace