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