1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
29 using System
.Diagnostics
;
30 using System
.Reflection
;
33 using unoidl
.com
.sun
.star
.uno
;
34 using unoidl
.com
.sun
.star
.lang
;
35 //using unoidl.com.sun.star.test.bridge;
36 using unoidl
.test
.testtools
.bridgetest
;
40 public interface MyInterface
47 class ORecursiveCall
: WeakBase
, XRecursiveCall
49 public void callRecursivly(XRecursiveCall xCall
, int nToCall
)
56 xCall
.callRecursivly(this, nToCall
);
64 public const string STRING_TEST_CONSTANT
= "\" paco\' chorizo\\\' \"\'";
67 public class BridgeTest
: WeakBase
, XMain
69 static bool compareData(Object val1
, Object val2
)
71 if (val1
== null && val2
== null || val1
== val2
)
73 if ((val1
== null && val2
!= null) ||
74 (val1
!= null && val2
== null) || val1
.GetType() != val2
.GetType())
78 Type t1
= val1
.GetType();
82 ret
= compareSequence((Array
) val1
, (Array
) val2
);
85 else if (t1
== typeof(string))
87 ret
= (string) val1
== (string) val2
;
89 // Interface implementation
90 else if (t1
.GetInterfaces().Length
> 0 && ! t1
.IsValueType
)
95 else if ( ! t1
.IsValueType
)
97 ret
= compareStruct(val1
, val2
);
99 else if (t1
== typeof(Any
))
103 ret
= a1
.Type
== a2
.Type
&& compareData(a1
.Value
, a2
.Value
);
105 else if (t1
.IsValueType
)
107 //Any, enum, int, bool char, float, double etc.
108 ret
= val1
.Equals(val2
);
117 // Arrays have only one dimension
118 static bool compareSequence(Array ar1
, Array ar2
)
120 Debug
.Assert(ar1
!= null && ar2
!= null);
121 Type t1
= ar1
.GetType();
122 Type t2
= ar2
.GetType();
124 if (!(ar1
.Rank
== 1 && ar2
.Rank
== 1
125 && ar1
.Length
== ar2
.Length
&& t1
.GetElementType() == t2
.GetElementType()))
128 //arrays have same rank and size and element type.
129 int len
= ar1
.Length
;
130 Type elemType
= t1
.GetElementType();
132 for (int i
= 0; i
< len
; i
++)
134 if (compareData(ar1
.GetValue(i
), ar2
.GetValue(i
)) == false)
143 static bool compareStruct(Object val1
, Object val2
)
145 Debug
.Assert(val1
!= null && val2
!= null);
146 Type t1
= val1
.GetType();
147 Type t2
= val2
.GetType();
150 FieldInfo
[] fields
= t1
.GetFields();
151 int cFields
= fields
.Length
;
153 for (int i
= 0; i
< cFields
; i
++)
155 Object fieldVal1
= fields
[i
].GetValue(val1
);
156 Object fieldVal2
= fields
[i
].GetValue(val2
);
157 if ( ! compareData(fieldVal1
, fieldVal2
))
166 static bool check( bool b
, string message
)
169 Console
.WriteLine("{0} failed\n" , message
);
173 static bool equals(TestElement rData1
, TestElement rData2
)
175 check( rData1
.Bool
== rData2
.Bool
, "### bool does not match!" );
176 check( rData1
.Char
== rData2
.Char
, "### char does not match!" );
177 check( rData1
.Byte
== rData2
.Byte
, "### byte does not match!" );
178 check( rData1
.Short
== rData2
.Short
, "### short does not match!" );
179 check( rData1
.UShort
== rData2
.UShort
, "### unsigned short does not match!" );
180 check( rData1
.Long
== rData2
.Long
, "### long does not match!" );
181 check( rData1
.ULong
== rData2
.ULong
, "### unsigned long does not match!" );
182 check( rData1
.Hyper
== rData2
.Hyper
, "### hyper does not match!" );
183 check( rData1
.UHyper
== rData2
.UHyper
, "### unsigned hyper does not match!" );
184 check( rData1
.Float
== rData2
.Float
, "### float does not match!" );
185 check( rData1
.Double
== rData2
.Double
, "### double does not match!" );
186 check( rData1
.Enum
== rData2
.Enum
, "### enum does not match!" );
187 check( rData1
.String
== rData2
.String
, "### string does not match!" );
188 check( rData1
.Interface
== rData2
.Interface
, "### interface does not match!" );
189 check( compareData(rData1
.Any
, rData2
.Any
), "### any does not match!" );
191 return (rData1
.Bool
== rData2
.Bool
&&
192 rData1
.Char
== rData2
.Char
&&
193 rData1
.Byte
== rData2
.Byte
&&
194 rData1
.Short
== rData2
.Short
&&
195 rData1
.UShort
== rData2
.UShort
&&
196 rData1
.Long
== rData2
.Long
&&
197 rData1
.ULong
== rData2
.ULong
&&
198 rData1
.Hyper
== rData2
.Hyper
&&
199 rData1
.UHyper
== rData2
.UHyper
&&
200 rData1
.Float
== rData2
.Float
&&
201 rData1
.Double
== rData2
.Double
&&
202 rData1
.Enum
== rData2
.Enum
&&
203 rData1
.String
== rData2
.String
&&
204 rData1
.Interface
== rData2
.Interface
&&
205 compareData(rData1
.Any
, rData2
.Any
));
208 static void assign( TestElement rData
,
209 bool bBool
, char cChar
, byte nByte
,
210 short nShort
, ushort nUShort
,
211 int nLong
, uint nULong
,
212 long nHyper
, ulong nUHyper
,
213 float fFloat
, double fDouble
,
214 TestEnum eEnum
, string rStr
,
221 rData
.Short
= nShort
;
222 rData
.UShort
= nUShort
;
224 rData
.ULong
= nULong
;
225 rData
.Hyper
= nHyper
;
226 rData
.UHyper
= nUHyper
;
227 rData
.Float
= fFloat
;
228 rData
.Double
= fDouble
;
231 rData
.Interface
= xTest
;
235 static void assign( TestDataElements rData
,
236 bool bBool
, char cChar
, byte nByte
,
237 short nShort
, ushort nUShort
,
238 int nLong
, uint nULong
,
239 long nHyper
, ulong nUHyper
,
240 float fFloat
, double fDouble
,
241 TestEnum eEnum
, string rStr
,
244 TestElement
[] rSequence
)
246 assign( (TestElement
) rData
,
247 bBool
, cChar
, nByte
, nShort
, nUShort
, nLong
, nULong
, nHyper
, nUHyper
, fFloat
, fDouble
,
248 eEnum
, rStr
, xTest
, rAny
);
249 rData
.Sequence
= rSequence
;
252 // template < class type >
253 static bool testAny(Type typ
, Object
value, XBridgeTest xLBT
)
257 any
= new Any(value.GetType(), value);
259 any
= new Any(typ
, value);
261 Any any2
= xLBT
.transportAny(any
);
263 if( ! (ret
= compareData(any
, any2
)))
265 Console
.WriteLine("any is different after roundtrip: in {0}, out {1}\n",
266 any
.Type
.FullName
, any2
.Type
.FullName
);
273 static bool performAnyTest(XBridgeTest xLBT
, TestDataElements data
)
276 bReturn
= testAny( null, data
.Byte
,xLBT
) && bReturn
;
277 bReturn
= testAny( null, data
.Short
,xLBT
) && bReturn
;
278 bReturn
= testAny( null, data
.UShort
,xLBT
) && bReturn
;
279 bReturn
= testAny( null, data
.Long
,xLBT
) && bReturn
;
280 bReturn
= testAny( null, data
.ULong
,xLBT
) && bReturn
;
281 bReturn
= testAny( null, data
.Hyper
,xLBT
) && bReturn
;
282 bReturn
= testAny( null,data
.UHyper
,xLBT
) && bReturn
;
283 bReturn
= testAny( null, data
.Float
,xLBT
) && bReturn
;
284 bReturn
= testAny( null, data
.Double
,xLBT
) && bReturn
;
285 bReturn
= testAny( null, data
.Enum
,xLBT
) && bReturn
;
286 bReturn
= testAny( null, data
.String
,xLBT
) && bReturn
;
287 bReturn
= testAny(typeof(XWeak
), data
.Interface
,xLBT
) && bReturn
;
288 bReturn
= testAny(null, data
, xLBT
) && bReturn
;
291 Any a1
= new Any(true);
292 Any a2
= xLBT
.transportAny( a1
);
293 bReturn
= compareData(a2
, a1
) && bReturn
;
297 Any a1
= new Any('A');
298 Any a2
= xLBT
.transportAny(a1
);
299 bReturn
= compareData(a2
, a1
) && bReturn
;
304 static bool performSequenceOfCallTest(XBridgeTest xLBT
)
307 int nGlobalIndex
= 0;
308 const int nWaitTimeSpanMUSec
= 10000;
309 for( nRounds
= 0 ; nRounds
< 10 ; nRounds
++ )
311 for( i
= 0 ; i
< nRounds
; i
++ )
314 xLBT
.callOneway(nGlobalIndex
, nWaitTimeSpanMUSec
);
319 xLBT
.call(nGlobalIndex
, nWaitTimeSpanMUSec
);
322 return xLBT
.sequenceOfCallTestPassed();
328 static bool performRecursiveCallTest(XBridgeTest xLBT
)
330 xLBT
.startRecursiveCall(new ORecursiveCall(), 50);
331 // on failure, the test would lock up or crash
335 static bool performQueryForUnknownType(XBridgeTest xLBT
)
338 // test queryInterface for an unknown type
341 foo
.MyInterface a
= (foo
.MyInterface
) xLBT
;
343 catch( System
.InvalidCastException
)
351 // //==================================================================================================
352 bool performTest(XBridgeTest xLBT
)
354 check( xLBT
!= null, "### no test interface!" );
359 // this data is never ever granted access to by calls other than equals(), assign()!
360 TestDataElements aData
= new TestDataElements(); // test against this data
362 Object xI
= new WeakBase();
364 Any aAny
= new Any( typeof(Object
), xI
);
365 assign( (TestElement
)aData
,
366 true, '@', 17, 0x1234, 0xfedc, 0x12345678, 0xfedcba98,
367 0x123456789abcdef0, 0xfedcba9876543210,
368 17.0815f
, 3.1415926359, TestEnum
.LOLA
,
369 Constants
.STRING_TEST_CONSTANT
, xI
,
372 bRet
= check( aData
.Any
.Value
== xI
, "### unexpected any!" ) && bRet
;
373 bRet
= check( !(aData
.Any
.Value
!= xI
), "### unexpected any!" ) && bRet
;
375 aData
.Sequence
= new TestElement
[2];
376 aData
.Sequence
[0] = new TestElement(
377 aData
.Bool
, aData
.Char
, aData
.Byte
, aData
.Short
,
378 aData
.UShort
, aData
.Long
, aData
.ULong
,
379 aData
.Hyper
, aData
.UHyper
, aData
.Float
,
380 aData
.Double
, aData
.Enum
, aData
.String
,
381 aData
.Interface
, aData
.Any
); //(TestElement) aData;
382 aData
.Sequence
[1] = new TestElement(); //is empty
386 // this is a manually copy of aData for first setting...
387 TestDataElements aSetData
= new TestDataElements();
388 Any aAnySet
= new Any(typeof(Object
), xI
);
389 assign( (TestElement
)aSetData
,
390 aData
.Bool
, aData
.Char
, aData
.Byte
, aData
.Short
, aData
.UShort
,
391 aData
.Long
, aData
.ULong
, aData
.Hyper
, aData
.UHyper
, aData
.Float
, aData
.Double
,
392 aData
.Enum
, aData
.String
, xI
,
395 aSetData
.Sequence
= new TestElement
[2];
396 aSetData
.Sequence
[0] = new TestElement(
397 aSetData
.Bool
, aSetData
.Char
, aSetData
.Byte
, aSetData
.Short
,
398 aSetData
.UShort
, aSetData
.Long
, aSetData
.ULong
,
399 aSetData
.Hyper
, aSetData
.UHyper
, aSetData
.Float
,
400 aSetData
.Double
, aSetData
.Enum
, aSetData
.String
,
401 aSetData
.Interface
, aSetData
.Any
); //TestElement) aSetData;
402 aSetData
.Sequence
[1] = new TestElement(); // empty struct
405 aSetData
.Bool
, aSetData
.Char
, aSetData
.Byte
, aSetData
.Short
, aSetData
.UShort
,
406 aSetData
.Long
, aSetData
.ULong
, aSetData
.Hyper
, aSetData
.UHyper
, aSetData
.Float
, aSetData
.Double
,
407 aSetData
.Enum
, aSetData
.String
, aSetData
.Interface
, aSetData
.Any
, aSetData
.Sequence
, aSetData
);
410 TestDataElements aRet
= new TestDataElements();
411 TestDataElements aRet2
= new TestDataElements();
413 out aRet
.Bool
, out aRet
.Char
, out aRet
.Byte
, out aRet
.Short
, out aRet
.UShort
,
414 out aRet
.Long
, out aRet
.ULong
, out aRet
.Hyper
, out aRet
.UHyper
,
415 out aRet
.Float
, out aRet
.Double
, out aRet
.Enum
, out aRet
.String
,
416 out aRet
.Interface
, out aRet
.Any
, out aRet
.Sequence
, out aRet2
);
418 bRet
= check( compareData( aData
, aRet
) && compareData( aData
, aRet2
) , "getValues test") && bRet
;
420 // set last retrieved values
421 TestDataElements aSV2ret
= xLBT
.setValues2(
422 ref aRet
.Bool
, ref aRet
.Char
, ref aRet
.Byte
, ref aRet
.Short
, ref aRet
.UShort
,
423 ref aRet
.Long
, ref aRet
.ULong
, ref aRet
.Hyper
, ref aRet
.UHyper
, ref aRet
.Float
,
424 ref aRet
.Double
, ref aRet
.Enum
, ref aRet
.String
, ref aRet
.Interface
, ref aRet
.Any
,
425 ref aRet
.Sequence
, ref aRet2
);
427 // check inout sequence order
428 // => inout sequence parameter was switched by test objects
429 TestElement temp
= aRet
.Sequence
[ 0 ];
430 aRet
.Sequence
[ 0 ] = aRet
.Sequence
[ 1 ];
431 aRet
.Sequence
[ 1 ] = temp
;
434 compareData( aData
, aSV2ret
) && compareData( aData
, aRet2
),
435 "getValues2 test") && bRet
;
438 TestDataElements aRet
= new TestDataElements();
439 TestDataElements aRet2
= new TestDataElements();
440 TestDataElements aGVret
= xLBT
.getValues(
441 out aRet
.Bool
, out aRet
.Char
, out aRet
.Byte
, out aRet
.Short
,
442 out aRet
.UShort
, out aRet
.Long
, out aRet
.ULong
, out aRet
.Hyper
,
443 out aRet
.UHyper
, out aRet
.Float
, out aRet
.Double
, out aRet
.Enum
,
444 out aRet
.String
, out aRet
.Interface
, out aRet
.Any
, out aRet
.Sequence
,
447 bRet
= check( compareData( aData
, aRet
) && compareData( aData
, aRet2
) && compareData( aData
, aGVret
), "getValues test" ) && bRet
;
449 // set last retrieved values
450 xLBT
.Bool
= aRet
.Bool
;
451 xLBT
.Char
= aRet
.Char
;
452 xLBT
.Byte
= aRet
.Byte
;
453 xLBT
.Short
= aRet
.Short
;
454 xLBT
.UShort
= aRet
.UShort
;
455 xLBT
.Long
= aRet
.Long
;
456 xLBT
.ULong
= aRet
.ULong
;
457 xLBT
.Hyper
= aRet
.Hyper
;
458 xLBT
.UHyper
= aRet
.UHyper
;
459 xLBT
.Float
= aRet
.Float
;
460 xLBT
.Double
= aRet
.Double
;
461 xLBT
.Enum
= aRet
.Enum
;
462 xLBT
.String
= aRet
.String
;
463 xLBT
.Interface
= aRet
.Interface
;
465 xLBT
.Sequence
= aRet
.Sequence
;
469 TestDataElements aRet
= new TestDataElements();
470 TestDataElements aRet2
= new TestDataElements();
471 aRet
.Hyper
= xLBT
.Hyper
;
472 aRet
.UHyper
= xLBT
.UHyper
;
473 aRet
.Float
= xLBT
.Float
;
474 aRet
.Double
= xLBT
.Double
;
475 aRet
.Byte
= xLBT
.Byte
;
476 aRet
.Char
= xLBT
.Char
;
477 aRet
.Bool
= xLBT
.Bool
;
478 aRet
.Short
= xLBT
.Short
;
479 aRet
.UShort
= xLBT
.UShort
;
480 aRet
.Long
= xLBT
.Long
;
481 aRet
.ULong
= xLBT
.ULong
;
482 aRet
.Enum
= xLBT
.Enum
;
483 aRet
.String
= xLBT
.String
;
484 aRet
.Interface
= xLBT
.Interface
;
486 aRet
.Sequence
= xLBT
.Sequence
;
489 bRet
= check( compareData( aData
, aRet
) && compareData( aData
, aRet2
) , "struct comparison test") && bRet
;
491 bRet
= check(performSequenceTest(xLBT
), "sequence test") && bRet
;
494 bRet
= check( performAnyTest( xLBT
, aData
) , "any test" ) && bRet
;
496 // sequence of call test
497 bRet
= check( performSequenceOfCallTest( xLBT
) , "sequence of call test" ) && bRet
;
499 // recursive call test
500 bRet
= check( performRecursiveCallTest( xLBT
) , "recursive test" ) && bRet
;
502 bRet
= (compareData( aData
, aRet
) && compareData( aData
, aRet2
)) && bRet
;
504 // check setting of null reference
505 xLBT
.Interface
= null;
506 aRet
.Interface
= xLBT
.Interface
;
507 bRet
= (aRet
.Interface
== null) && bRet
;
510 // Test extended attributes that raise exceptions:
512 int i
= xLBT
.RaiseAttr1
;
513 bRet
&= check(false, "getRaiseAttr1 did not throw");
514 } catch (RuntimeException
)
517 catch (System
.Exception
) {
518 bRet
&= check(false, "getRaiseAttr1 threw wrong type");
522 bRet
&= check(false, "setRaiseAttr1 did not throw");
523 } catch (IllegalArgumentException
) {
524 } catch (System
.Exception
) {
525 bRet
&= check(false, "setRaiseAttr1 threw wrong type");
528 int i
= xLBT
.RaiseAttr2
;
529 bRet
&= check(false, "getRaiseAttr2 did not throw");
530 } catch (IllegalArgumentException
) {
531 } catch (System
.Exception
) {
532 bRet
&= check(false, "getRaiseAttr2 threw wrong type");
535 // Test instantiated polymorphic struct types:
537 TestPolyStruct poly
= new TestPolyStruct(true);
539 (bool) xLBT
.transportPolyBoolean(poly
).member
,
540 "transportPolyBoolean");
541 poly
= new TestPolyStruct(12345L);
542 xLBT
.transportPolyHyper(ref poly
);
543 bRet
&= check((long)poly
.member
== 12345L, "transportPolyUnsignedHyper");
545 Any
[] seq
= { new Any(33), new Any("ABC")}
;
546 poly
= new TestPolyStruct(seq
);
547 TestPolyStruct poly2
;
548 xLBT
.transportPolySequence(poly
, out poly2
);
550 Any
[] ar
= (Any
[]) poly2
.member
;
552 ar
.Length
== 2, "transportPolySequence, length");
555 v0
= (int) ar
[0].Value
;
556 bRet
&= check(v0
== 33, "transportPolySequence, element 0");
558 string v1
= (string) ar
[1].Value
;
561 "transportPolySequence, element 1");
562 } catch (InvalidCastException
)
564 bRet
&= check(false, "transportPolySequence");
568 //When the test object is a cli object then them member is null
569 //otherwise the bridge has provided a default value.
570 TestPolyStruct s
= xLBT
.getNullPolyLong();
571 if (s
.member
!= null)
572 bRet
&= check(((int) s
.member
) == 0, "getNullPolyLong");
574 s
= xLBT
.getNullPolyString();
575 if (s
.member
!= null)
576 bRet
&= check(((string) s
.member
).Length
== 0,
577 "getNullPolyString");
578 s
= xLBT
.getNullPolyType();
579 if (s
.member
!= null)
580 bRet
&= check(((Type
) s
.member
) == typeof(void),
582 s
= xLBT
.getNullPolyAny();
583 if (s
.member
!= null)
585 Any nullAny
= (Any
) s
.member
;
587 bRet
&= check(nullAny
.Type
== typeof(void),
590 s
= xLBT
.getNullPolySequence();
591 if (s
.member
!= null)
592 bRet
&= check(((bool[]) s
.member
).Length
== 0,
593 "getNullPolySequence");
594 s
= xLBT
.getNullPolyEnum();
595 if (s
.member
!= null)
596 bRet
&= check(((TestEnum
) s
.member
) == TestEnum
.TEST
,
598 s
= xLBT
.getNullPolyStruct();
599 if (s
.member
!= null)
600 bRet
&= check(((TestStruct
) s
.member
).member
== 0,
601 "getNullPolyStruct");
602 s
= xLBT
.getNullPolyInterface();
603 bRet
&= check(s
.member
== null, "getNullPolyInterface");
605 s
= xLBT
.getNullPolyBadEnum();
606 bRet
&= check(((TestBadEnum
)s
.member
) == TestBadEnum
.M
, "getNullPolyBadEnum");
608 } catch(InvalidCastException
)
610 bRet
&= check(false, "getNullPolyXXX, InvalidCastException");
615 XBridgeTest2 xBT2
= xLBT
as XBridgeTest2
;
618 xBT2
.testConstructorsService(m_xContext
);
619 } catch (BadConstructorArguments
) {
626 static bool performSequenceTest(XBridgeTest xBT
)
629 XBridgeTest2 xBT2
= xBT
as XBridgeTest2
;
633 // perform sequence tests (XBridgeTest2)
634 // create the sequence which are compared with the results
635 bool[] arBool
= {true, false, true}
;
636 char[] arChar
= {'A','B','C'}
;
637 byte[] arByte
= { 1, 2, 0xff}
;
638 short[] arShort
= {Int16.MinValue, 1, Int16.MaxValue}
;
639 UInt16
[] arUShort
= {UInt16.MinValue , 1, UInt16.MaxValue}
;
640 int[] arLong
= {Int32.MinValue, 1, Int32.MaxValue}
;
641 UInt32
[] arULong
= {UInt32.MinValue, 1, UInt32.MaxValue}
;
642 long[] arHyper
= {Int64.MinValue, 1, Int64.MaxValue}
;
643 UInt64
[] arUHyper
= {UInt64.MinValue, 1, UInt64.MaxValue}
;
644 float[] arFloat
= {1.1f, 2.2f, 3.3f}
;
645 double[] arDouble
= {1.11, 2.22, 3.33}
;
646 string[] arString
= {"String 1", "String 2", "String 3"}
;
648 Any
[] arAny
= {new Any(true), new Any(11111), new Any(3.14)}
;
649 Object
[] arObject
= {new WeakBase(), new WeakBase(), new WeakBase()}
;
650 TestEnum
[] arEnum
= {TestEnum.ONE, TestEnum.TWO, TestEnum.CHECK}
;
652 TestElement
[] arStruct
= {new TestElement(), new TestElement(),
654 assign( arStruct
[0], true, '@', 17, 0x1234, 0xfedc, 0x12345678, 0xfedcba98,
655 0x123456789abcdef0, 0xfedcba9876543210, 17.0815f
, 3.1415926359,
656 TestEnum
.LOLA
, Constants
.STRING_TEST_CONSTANT
, arObject
[0],
657 new Any( typeof(Object
), arObject
[0]) );
658 assign( arStruct
[1], true, 'A', 17, 0x1234, 0xfedc, 0x12345678, 0xfedcba98,
659 0x123456789abcdef0, 0xfedcba9876543210, 17.0815f
, 3.1415926359,
660 TestEnum
.TWO
, Constants
.STRING_TEST_CONSTANT
, arObject
[1],
661 new Any( typeof(Object
), arObject
[1]) );
662 assign( arStruct
[2], true, 'B', 17, 0x1234, 0xfedc, 0x12345678, 0xfedcba98,
663 0x123456789abcdef0, 0xfedcba9876543210, 17.0815f
, 3.1415926359,
664 TestEnum
.CHECK
, Constants
.STRING_TEST_CONSTANT
, arObject
[2],
665 new Any( typeof(Object
), arObject
[2] ) );
668 int[][][] arLong3
= new int[][][]{
669 new int[][]{new int[]{1,2,3}
,new int[]{4,5,6}
, new int[]{7,8,9}
},
670 new int [][]{new int[]{1,2,3}
,new int[]{4,5,6}
, new int[]{7,8,9}}
,
671 new int[][]{new int[]{1,2,3}
,new int[]{4,5,6}
, new int[]{7,8,9}}
};
674 int[][] seqSeqRet
= xBT2
.setDim2(arLong3
[0]);
675 bRet
= check( compareData(seqSeqRet
, arLong3
[0]), "sequence test") && bRet
;
676 int[][][] seqSeqRet2
= xBT2
.setDim3(arLong3
);
677 bRet
= check( compareData(seqSeqRet2
, arLong3
), "sequence test") && bRet
;
678 Any
[] seqAnyRet
= xBT2
.setSequenceAny(arAny
);
679 bRet
= check( compareData(seqAnyRet
, arAny
), "sequence test") && bRet
;
680 bool[] seqBoolRet
= xBT2
.setSequenceBool(arBool
);
681 bRet
= check( compareData(seqBoolRet
, arBool
), "sequence test") && bRet
;
682 byte[] seqByteRet
= xBT2
.setSequenceByte(arByte
);
683 bRet
= check( compareData(seqByteRet
, arByte
), "sequence test") && bRet
;
684 char[] seqCharRet
= xBT2
.setSequenceChar(arChar
);
685 bRet
= check( compareData(seqCharRet
, arChar
), "sequence test") && bRet
;
686 short[] seqShortRet
= xBT2
.setSequenceShort(arShort
);
687 bRet
= check( compareData(seqShortRet
, arShort
), "sequence test") && bRet
;
688 int[] seqLongRet
= xBT2
.setSequenceLong(arLong
);
689 bRet
= check( compareData(seqLongRet
, arLong
), "sequence test") && bRet
;
690 long[] seqHyperRet
= xBT2
.setSequenceHyper(arHyper
);
691 bRet
= check( compareData(seqHyperRet
,arHyper
), "sequence test") && bRet
;
692 float[] seqFloatRet
= xBT2
.setSequenceFloat(arFloat
);
693 bRet
= check( compareData(seqFloatRet
, arFloat
), "sequence test") && bRet
;
694 double[] seqDoubleRet
= xBT2
.setSequenceDouble(arDouble
);
695 bRet
= check( compareData(seqDoubleRet
, arDouble
), "sequence test") && bRet
;
696 TestEnum
[] seqEnumRet
= xBT2
.setSequenceEnum(arEnum
);
697 bRet
= check( compareData(seqEnumRet
, arEnum
), "sequence test") && bRet
;
698 UInt16
[] seqUShortRet
= xBT2
.setSequenceUShort(arUShort
);
699 bRet
= check( compareData(seqUShortRet
, arUShort
), "sequence test") && bRet
;
700 UInt32
[] seqULongRet
= xBT2
.setSequenceULong(arULong
);
701 bRet
= check( compareData(seqULongRet
, arULong
), "sequence test") && bRet
;
702 UInt64
[] seqUHyperRet
= xBT2
.setSequenceUHyper(arUHyper
);
703 bRet
= check( compareData(seqUHyperRet
, arUHyper
), "sequence test") && bRet
;
704 Object
[] seqObjectRet
= xBT2
.setSequenceXInterface(arObject
);
705 bRet
= check( compareData(seqObjectRet
, arObject
), "sequence test") && bRet
;
706 string[] seqStringRet
= xBT2
.setSequenceString(arString
);
707 bRet
= check( compareData(seqStringRet
, arString
), "sequence test") && bRet
;
708 TestElement
[] seqStructRet
= xBT2
.setSequenceStruct(arStruct
);
709 bRet
= check( compareData(seqStructRet
, arStruct
), "sequence test") && bRet
;
712 bool[] arBoolTemp
= (bool[]) arBool
.Clone();
713 char[] arCharTemp
= (char[]) arChar
.Clone();
714 byte[] arByteTemp
= (byte[]) arByte
.Clone();
715 short[] arShortTemp
= (short[]) arShort
.Clone();
716 UInt16
[] arUShortTemp
= (UInt16
[]) arUShort
.Clone();
717 int[] arLongTemp
= (int[]) arLong
.Clone();
718 UInt32
[] arULongTemp
= (UInt32
[]) arULong
.Clone();
719 long[] arHyperTemp
= (long[]) arHyper
.Clone();
720 UInt64
[] arUHyperTemp
= (UInt64
[]) arUHyper
.Clone();
721 float[] arFloatTemp
= (float[]) arFloat
.Clone();
722 double[] arDoubleTemp
= (double[]) arDouble
.Clone();
723 TestEnum
[] arEnumTemp
= (TestEnum
[]) arEnum
.Clone();
724 string[] arStringTemp
= (string[]) arString
.Clone();
725 Object
[] arObjectTemp
= (Object
[]) arObject
.Clone();
726 Any
[] arAnyTemp
= (Any
[]) arAny
.Clone();
727 // make sure this are has the same contents as arLong3[0]
728 int[][] arLong2Temp
= new int[][]{new int[]{1,2,3}
,new int[]{4,5,6}
, new int[]{7,8,9}
};
729 // make sure this are has the same contents as arLong3
730 int[][][] arLong3Temp
= new int[][][]{
731 new int[][]{new int[]{1,2,3}
,new int[]{4,5,6}
, new int[]{7,8,9}
},
732 new int [][]{new int[]{1,2,3}
,new int[]{4,5,6}
, new int[]{7,8,9}}
,
733 new int[][]{new int[]{1,2,3}
,new int[]{4,5,6}
, new int[]{7,8,9}}
};
735 xBT2
.setSequencesInOut(ref arBoolTemp
, ref arCharTemp
, ref arByteTemp
,
736 ref arShortTemp
, ref arUShortTemp
, ref arLongTemp
,
737 ref arULongTemp
,ref arHyperTemp
, ref arUHyperTemp
,
738 ref arFloatTemp
,ref arDoubleTemp
, ref arEnumTemp
,
739 ref arStringTemp
, ref arObjectTemp
,
740 ref arAnyTemp
, ref arLong2Temp
, ref arLong3Temp
);
742 compareData(arBoolTemp
, arBool
) &&
743 compareData(arCharTemp
, arChar
) &&
744 compareData(arByteTemp
, arByte
) &&
745 compareData(arShortTemp
, arShort
) &&
746 compareData(arUShortTemp
, arUShort
) &&
747 compareData(arLongTemp
, arLong
) &&
748 compareData(arULongTemp
, arULong
) &&
749 compareData(arHyperTemp
, arHyper
) &&
750 compareData(arUHyperTemp
, arUHyper
) &&
751 compareData(arFloatTemp
, arFloat
) &&
752 compareData(arDoubleTemp
, arDouble
) &&
753 compareData(arEnumTemp
, arEnum
) &&
754 compareData(arStringTemp
, arString
) &&
755 compareData(arObjectTemp
, arObject
) &&
756 compareData(arAnyTemp
, arAny
) &&
757 compareData(arLong2Temp
, arLong3
[0]) &&
758 compareData(arLong3Temp
, arLong3
), "sequence test") && bRet
;
764 UInt16
[] arUShortOut
;
768 UInt64
[] arUHyperOut
;
770 double[] arDoubleOut
;
771 TestEnum
[] arEnumOut
;
772 string[] arStringOut
;
773 Object
[] arObjectOut
;
776 int[][][] arLong3Out
;
778 xBT2
.setSequencesOut(out arBoolOut
, out arCharOut
, out arByteOut
,
779 out arShortOut
, out arUShortOut
, out arLongOut
,
780 out arULongOut
, out arHyperOut
, out arUHyperOut
,
781 out arFloatOut
, out arDoubleOut
, out arEnumOut
,
782 out arStringOut
, out arObjectOut
, out arAnyOut
,
783 out arLong2Out
, out arLong3Out
);
785 compareData(arBoolOut
, arBool
) &&
786 compareData(arCharOut
, arChar
) &&
787 compareData(arByteOut
, arByte
) &&
788 compareData(arShortOut
, arShort
) &&
789 compareData(arUShortOut
, arUShort
) &&
790 compareData(arLongOut
, arLong
) &&
791 compareData(arULongOut
, arULong
) &&
792 compareData(arHyperOut
, arHyper
) &&
793 compareData(arUHyperOut
, arUHyper
) &&
794 compareData(arFloatOut
, arFloat
) &&
795 compareData(arDoubleOut
, arDouble
) &&
796 compareData(arEnumOut
, arEnum
) &&
797 compareData(arStringOut
, arString
) &&
798 compareData(arObjectOut
, arObject
) &&
799 compareData(arAnyOut
, arAny
) &&
800 compareData(arLong2Out
, arLong3
[0]) &&
801 compareData(arLong3Out
, arLong3
), "sequence test") && bRet
;
804 //test with empty sequences
805 int[][] _arLong2
= new int[0][];
806 int[][] seqSeqRet
= xBT2
.setDim2(_arLong2
);
807 bRet
= check( compareData(seqSeqRet
, _arLong2
), "sequence test") && bRet
;
808 int[][][] _arLong3
= new int[0][][];
809 int[][][] seqSeqRet2
= xBT2
.setDim3(_arLong3
);
810 bRet
= check( compareData(seqSeqRet2
, _arLong3
), "sequence test") && bRet
;
811 Any
[] _arAny
= new Any
[0];
812 Any
[] seqAnyRet
= xBT2
.setSequenceAny(_arAny
);
813 bRet
= check( compareData(seqAnyRet
, _arAny
), "sequence test") && bRet
;
814 bool[] _arBool
= new bool[0];
815 bool[] seqBoolRet
= xBT2
.setSequenceBool(_arBool
);
816 bRet
= check( compareData(seqBoolRet
, _arBool
), "sequence test") && bRet
;
817 byte[] _arByte
= new byte[0];
818 byte[] seqByteRet
= xBT2
.setSequenceByte(_arByte
);
819 bRet
= check( compareData(seqByteRet
, _arByte
), "sequence test") && bRet
;
820 char[] _arChar
= new char[0];
821 char[] seqCharRet
= xBT2
.setSequenceChar(_arChar
);
822 bRet
= check( compareData(seqCharRet
, _arChar
), "sequence test") && bRet
;
823 short[] _arShort
= new short[0];
824 short[] seqShortRet
= xBT2
.setSequenceShort(_arShort
);
825 bRet
= check( compareData(seqShortRet
, _arShort
), "sequence test") && bRet
;
826 int[] _arLong
= new int[0];
827 int[] seqLongRet
= xBT2
.setSequenceLong(_arLong
);
828 bRet
= check( compareData(seqLongRet
, _arLong
), "sequence test") && bRet
;
829 long[] _arHyper
= new long[0];
830 long[] seqHyperRet
= xBT2
.setSequenceHyper(_arHyper
);
831 bRet
= check( compareData(seqHyperRet
, _arHyper
), "sequence test") && bRet
;
832 float[] _arFloat
= new float[0];
833 float[] seqFloatRet
= xBT2
.setSequenceFloat(_arFloat
);
834 bRet
= check( compareData(seqFloatRet
, _arFloat
), "sequence test") && bRet
;
835 double[] _arDouble
= new double[0];
836 double[] seqDoubleRet
= xBT2
.setSequenceDouble(_arDouble
);
837 bRet
= check( compareData(seqDoubleRet
, _arDouble
), "sequence test") && bRet
;
838 TestEnum
[] _arEnum
= new TestEnum
[0];
839 TestEnum
[] seqEnumRet
= xBT2
.setSequenceEnum(_arEnum
);
840 bRet
= check( compareData(seqEnumRet
, _arEnum
), "sequence test") && bRet
;
841 UInt16
[] _arUShort
= new UInt16
[0];
842 UInt16
[] seqUShortRet
= xBT2
.setSequenceUShort(_arUShort
);
843 bRet
= check( compareData(seqUShortRet
, _arUShort
), "sequence test") && bRet
;
844 UInt32
[] _arULong
= new UInt32
[0];
845 UInt32
[] seqULongRet
= xBT2
.setSequenceULong(_arULong
);
846 bRet
= check( compareData(seqULongRet
, _arULong
), "sequence test") && bRet
;
847 UInt64
[] _arUHyper
= new UInt64
[0];
848 UInt64
[] seqUHyperRet
= xBT2
.setSequenceUHyper(_arUHyper
);
849 bRet
= check( compareData(seqUHyperRet
, _arUHyper
), "sequence test") && bRet
;
850 Object
[] _arObject
= new Object
[0];
851 Object
[] seqObjectRet
= xBT2
.setSequenceXInterface(_arObject
);
852 bRet
= check( compareData(seqObjectRet
, _arObject
), "sequence test") && bRet
;
853 string[] _arString
= new string[0];
854 string[] seqStringRet
= xBT2
.setSequenceString(_arString
);
855 bRet
= check( compareData(seqStringRet
, _arString
), "sequence test") && bRet
;
856 TestElement
[] _arStruct
= new TestElement
[0];
857 TestElement
[] seqStructRet
= xBT2
.setSequenceStruct(_arStruct
);
858 bRet
= check( compareData(seqStructRet
, _arStruct
), "sequence test") && bRet
;
865 /** Test the System::Object method on the proxy object
867 static bool testObjectMethodsImplemention(XBridgeTest xLBT
)
870 Object obj
= new Object();
871 Object xInt
= (Object
) xLBT
;
872 XBridgeTestBase xBase
= xLBT
as XBridgeTestBase
;
876 ret
= xLBT
.Equals(obj
) == false;
877 ret
= xLBT
.Equals(xLBT
) && ret
;
878 ret
= Object
.Equals(obj
, obj
) && ret
;
879 ret
= Object
.Equals(xLBT
, xBase
) && ret
;
881 // Don't know how to verify this. Currently it is not possible to get the object id from a proxy
882 int nHash
= xLBT
.GetHashCode();
883 ret
= nHash
== xBase
.GetHashCode() && ret
;
886 // Don't know how to verify this automatically.
887 string s
= xLBT
.ToString();
888 ret
= (s
.Length
> 0) && ret
;
893 static bool raiseOnewayException(XBridgeTest xLBT
)
896 string sCompare
= Constants
.STRING_TEST_CONSTANT
;
899 // Note : the exception may fly or not (e.g. remote scenario).
900 // When it flies, it must contain the correct elements.
901 xLBT
.raiseRuntimeExceptionOneway(sCompare
, xLBT
.Interface
);
903 catch (RuntimeException e
)
905 bReturn
= ( xLBT
.Interface
== e
.Context
);
910 // //==================================================================================================
911 static bool raiseException(XBridgeTest xLBT
)
920 TestDataElements aRet
= new TestDataElements();
921 TestDataElements aRet2
= new TestDataElements();
923 5, Constants
.STRING_TEST_CONSTANT
, xLBT
.Interface
);
925 catch (unoidl
.com
.sun
.star
.lang
.IllegalArgumentException aExc
)
927 if (aExc
.ArgumentPosition
== 5 &&
928 aExc
.Context
== xLBT
.Interface
)
934 check( false, "### unexpected exception content!" );
937 /** it is certain, that the RuntimeException testing will fail,
939 xLBT
.RuntimeException
= 0;
942 catch (unoidl
.com
.sun
.star
.uno
.RuntimeException rExc
)
944 if (rExc
.Context
== xLBT
.Interface
)
950 check( false, "### unexpected exception content!" );
953 /** it is certain, that the RuntimeException testing will fail, if no */
956 xLBT
.RuntimeException
= (int) 0xcafebabe;
960 catch (unoidl
.com
.sun
.star
.uno
.Exception rExc
)
962 if (rExc
.Context
== xLBT
.Interface
)
969 check( false, "### unexpected exception content!" );
971 return (nCount
== 3);
976 private void perform_test( XBridgeTest xLBT
)
979 bRet
= check( performTest( xLBT
), "standard test" ) && bRet
;
980 bRet
= check( raiseException( xLBT
) , "exception test" )&& bRet
;
981 bRet
= check( raiseOnewayException( xLBT
), "oneway exception test" ) && bRet
;
982 bRet
= check( testObjectMethodsImplemention(xLBT
), "object methods test") && bRet
;
983 bRet
= performQueryForUnknownType( xLBT
) && bRet
;
986 throw new unoidl
.com
.sun
.star
.uno
.RuntimeException( "error (cli_cs_bridgetest.cs): test failed!", null);
990 public BridgeTest( XComponentContext xContext
)
992 m_xContext
= xContext
;
995 private XComponentContext m_xContext
;
997 public int run( String
[] args
)
999 Debug
.AutoFlush
= true;
1000 // System.Diagnostics.Debugger.Launch();
1003 if (args
.Length
< 1)
1005 throw new RuntimeException(
1006 "missing argument for bridgetest!", this );
1009 m_xContext
.getServiceManager().createInstanceWithContext(
1010 args
[ 0 ], m_xContext
);
1013 "Calling object: {0}", test_obj
.ToString() );
1015 XBridgeTest xTest
= (XBridgeTest
) test_obj
;
1016 perform_test( xTest
);
1017 Console
.WriteLine( "\n### cli_uno C# bridgetest succeeded." );
1020 catch (unoidl
.com
.sun
.star
.uno
.RuntimeException
)
1024 catch (System
.Exception exc
)
1026 throw new unoidl
.com
.sun
.star
.uno
.RuntimeException(
1027 "cli_cs_bridgetest.cs: unexpected exception occured in XMain::run. Original exception: " +
1028 exc
.GetType().Name
+ "\n Message: " + exc
.Message
, null);