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 .
20 using System
.Diagnostics
;
21 using System
.Reflection
;
24 using unoidl
.com
.sun
.star
.uno
;
25 using unoidl
.com
.sun
.star
.lang
;
26 //using unoidl.com.sun.star.test.bridge;
27 using unoidl
.test
.testtools
.bridgetest
;
31 public interface MyInterface
38 class ORecursiveCall
: WeakBase
, XRecursiveCall
40 public void callRecursivly(XRecursiveCall xCall
, int nToCall
)
47 xCall
.callRecursivly(this, nToCall
);
55 public const string STRING_TEST_CONSTANT
= "\" paco\' chorizo\\\' \"\'";
58 public class BridgeTest
: WeakBase
, XMain
60 static bool compareData(Object val1
, Object val2
)
62 if (val1
== null && val2
== null || val1
== val2
)
64 if ((val1
== null && val2
!= null) ||
65 (val1
!= null && val2
== null) || val1
.GetType() != val2
.GetType())
69 Type t1
= val1
.GetType();
73 ret
= compareSequence((Array
) val1
, (Array
) val2
);
76 else if (t1
== typeof(string))
78 ret
= (string) val1
== (string) val2
;
80 // Interface implementation
81 else if (t1
.GetInterfaces().Length
> 0 && ! t1
.IsValueType
)
86 else if ( ! t1
.IsValueType
)
88 ret
= compareStruct(val1
, val2
);
90 else if (t1
== typeof(Any
))
94 ret
= a1
.Type
== a2
.Type
&& compareData(a1
.Value
, a2
.Value
);
96 else if (t1
.IsValueType
)
98 //Any, enum, int, bool char, float, double etc.
99 ret
= val1
.Equals(val2
);
108 // Arrays have only one dimension
109 static bool compareSequence(Array ar1
, Array ar2
)
111 Debug
.Assert(ar1
!= null && ar2
!= null);
112 Type t1
= ar1
.GetType();
113 Type t2
= ar2
.GetType();
115 if (!(ar1
.Rank
== 1 && ar2
.Rank
== 1
116 && ar1
.Length
== ar2
.Length
&& t1
.GetElementType() == t2
.GetElementType()))
119 //arrays have same rank and size and element type.
120 int len
= ar1
.Length
;
121 Type elemType
= t1
.GetElementType();
123 for (int i
= 0; i
< len
; i
++)
125 if (compareData(ar1
.GetValue(i
), ar2
.GetValue(i
)) == false)
134 static bool compareStruct(Object val1
, Object val2
)
136 Debug
.Assert(val1
!= null && val2
!= null);
137 Type t1
= val1
.GetType();
138 Type t2
= val2
.GetType();
141 FieldInfo
[] fields
= t1
.GetFields();
142 int cFields
= fields
.Length
;
144 for (int i
= 0; i
< cFields
; i
++)
146 Object fieldVal1
= fields
[i
].GetValue(val1
);
147 Object fieldVal2
= fields
[i
].GetValue(val2
);
148 if ( ! compareData(fieldVal1
, fieldVal2
))
157 static bool check( bool b
, string message
)
160 Console
.WriteLine("{0} failed\n" , message
);
164 static bool equals(TestElement rData1
, TestElement rData2
)
166 check( rData1
.Bool
== rData2
.Bool
, "### bool does not match!" );
167 check( rData1
.Char
== rData2
.Char
, "### char does not match!" );
168 check( rData1
.Byte
== rData2
.Byte
, "### byte does not match!" );
169 check( rData1
.Short
== rData2
.Short
, "### short does not match!" );
170 check( rData1
.UShort
== rData2
.UShort
, "### unsigned short does not match!" );
171 check( rData1
.Long
== rData2
.Long
, "### long does not match!" );
172 check( rData1
.ULong
== rData2
.ULong
, "### unsigned long does not match!" );
173 check( rData1
.Hyper
== rData2
.Hyper
, "### hyper does not match!" );
174 check( rData1
.UHyper
== rData2
.UHyper
, "### unsigned hyper does not match!" );
175 check( rData1
.Float
== rData2
.Float
, "### float does not match!" );
176 check( rData1
.Double
== rData2
.Double
, "### double does not match!" );
177 check( rData1
.Enum
== rData2
.Enum
, "### enum does not match!" );
178 check( rData1
.String
== rData2
.String
, "### string does not match!" );
179 check( rData1
.Byte2
== rData2
.Byte2
, "### byte2 does not match!" );
180 check( rData1
.Short2
== rData2
.Short2
, "### short2 does not match!" );
181 check( rData1
.Interface
== rData2
.Interface
, "### interface does not match!" );
182 check( compareData(rData1
.Any
, rData2
.Any
), "### any does not match!" );
184 return (rData1
.Bool
== rData2
.Bool
&&
185 rData1
.Char
== rData2
.Char
&&
186 rData1
.Byte
== rData2
.Byte
&&
187 rData1
.Short
== rData2
.Short
&&
188 rData1
.UShort
== rData2
.UShort
&&
189 rData1
.Long
== rData2
.Long
&&
190 rData1
.ULong
== rData2
.ULong
&&
191 rData1
.Hyper
== rData2
.Hyper
&&
192 rData1
.UHyper
== rData2
.UHyper
&&
193 rData1
.Float
== rData2
.Float
&&
194 rData1
.Double
== rData2
.Double
&&
195 rData1
.Enum
== rData2
.Enum
&&
196 rData1
.String
== rData2
.String
&&
197 rData1
.Byte2
== rData2
.Byte2
&&
198 rData1
.Short2
== rData2
.Short2
&&
199 rData1
.Interface
== rData2
.Interface
&&
200 compareData(rData1
.Any
, rData2
.Any
));
203 static void assign( TestElement rData
,
204 bool bBool
, char cChar
, byte nByte
,
205 short nShort
, ushort nUShort
,
206 int nLong
, uint nULong
,
207 long nHyper
, ulong nUHyper
,
208 float fFloat
, double fDouble
,
209 TestEnum eEnum
, string rStr
,
210 byte nByte2
, short nShort2
,
217 rData
.Short
= nShort
;
218 rData
.UShort
= nUShort
;
220 rData
.ULong
= nULong
;
221 rData
.Hyper
= nHyper
;
222 rData
.UHyper
= nUHyper
;
223 rData
.Float
= fFloat
;
224 rData
.Double
= fDouble
;
227 rData
.Byte2
= nByte2
;
228 rData
.Short2
= nShort2
;
229 rData
.Interface
= xTest
;
233 static void assign( TestDataElements rData
,
234 bool bBool
, char cChar
, byte nByte
,
235 short nShort
, ushort nUShort
,
236 int nLong
, uint nULong
,
237 long nHyper
, ulong nUHyper
,
238 float fFloat
, double fDouble
,
239 TestEnum eEnum
, string rStr
,
240 byte nByte2
, short nShort2
,
243 TestElement
[] rSequence
)
245 assign( (TestElement
) rData
,
246 bBool
, cChar
, nByte
, nShort
, nUShort
, nLong
, nULong
, nHyper
, nUHyper
, fFloat
, fDouble
,
247 eEnum
, rStr
, nByte2
, nShort2
, xTest
, rAny
);
248 rData
.Sequence
= rSequence
;
251 // template < class type >
252 static bool testAny(Type typ
, Object
value, XBridgeTest xLBT
)
256 any
= new Any(value.GetType(), value);
258 any
= new Any(typ
, value);
260 Any any2
= xLBT
.transportAny(any
);
262 if( ! (ret
= compareData(any
, any2
)))
264 Console
.WriteLine("any is different after roundtrip: in {0}, out {1}\n",
265 any
.Type
.FullName
, any2
.Type
.FullName
);
272 static bool performAnyTest(XBridgeTest xLBT
, TestDataElements data
)
275 bReturn
= testAny( null, data
.Byte
,xLBT
) && bReturn
;
276 bReturn
= testAny( null, data
.Short
,xLBT
) && bReturn
;
277 bReturn
= testAny( null, data
.UShort
,xLBT
) && bReturn
;
278 bReturn
= testAny( null, data
.Long
,xLBT
) && bReturn
;
279 bReturn
= testAny( null, data
.ULong
,xLBT
) && bReturn
;
280 bReturn
= testAny( null, data
.Hyper
,xLBT
) && bReturn
;
281 bReturn
= testAny( null,data
.UHyper
,xLBT
) && bReturn
;
282 bReturn
= testAny( null, data
.Float
,xLBT
) && bReturn
;
283 bReturn
= testAny( null, data
.Double
,xLBT
) && bReturn
;
284 bReturn
= testAny( null, data
.Enum
,xLBT
) && bReturn
;
285 bReturn
= testAny( null, data
.String
,xLBT
) && bReturn
;
286 bReturn
= testAny( null, data
.Byte2
,xLBT
) && bReturn
;
287 bReturn
= testAny( null, data
.Short2
,xLBT
) && bReturn
;
288 bReturn
= testAny(typeof(XWeak
), data
.Interface
,xLBT
) && bReturn
;
289 bReturn
= testAny(null, data
, xLBT
) && bReturn
;
292 Any a1
= new Any(true);
293 Any a2
= xLBT
.transportAny( a1
);
294 bReturn
= compareData(a2
, a1
) && bReturn
;
298 Any a1
= new Any('A');
299 Any a2
= xLBT
.transportAny(a1
);
300 bReturn
= compareData(a2
, a1
) && bReturn
;
305 static bool performSequenceOfCallTest(XBridgeTest xLBT
)
308 int nGlobalIndex
= 0;
309 const int nWaitTimeSpanMUSec
= 10000;
310 for( nRounds
= 0 ; nRounds
< 10 ; nRounds
++ )
312 for( i
= 0 ; i
< nRounds
; i
++ )
315 xLBT
.callOneway(nGlobalIndex
, nWaitTimeSpanMUSec
);
320 xLBT
.call(nGlobalIndex
, nWaitTimeSpanMUSec
);
323 return xLBT
.sequenceOfCallTestPassed();
329 static bool performRecursiveCallTest(XBridgeTest xLBT
)
331 xLBT
.startRecursiveCall(new ORecursiveCall(), 50);
332 // on failure, the test would lock up or crash
336 static bool performQueryForUnknownType(XBridgeTest xLBT
)
339 // test queryInterface for an unknown type
342 foo
.MyInterface a
= (foo
.MyInterface
) xLBT
;
344 catch( System
.InvalidCastException
)
353 bool performTest(XBridgeTest xLBT
)
355 check( xLBT
!= null, "### no test interface!" );
360 // this data is never ever granted access to by calls other than equals(), assign()!
361 TestDataElements aData
= new TestDataElements(); // test against this data
363 Object xI
= new WeakBase();
365 Any aAny
= new Any( typeof(Object
), xI
);
366 assign( (TestElement
)aData
,
367 true, '@', 17, 0x1234, 0xfedc, 0x12345678, 0xfedcba98,
368 0x123456789abcdef0, 0xfedcba9876543210,
369 17.0815f
, 3.1415926359, TestEnum
.LOLA
,
370 Constants
.STRING_TEST_CONSTANT
, xI
,
373 bRet
= check( aData
.Any
.Value
== xI
, "### unexpected any!" ) && bRet
;
374 bRet
= check( !(aData
.Any
.Value
!= xI
), "### unexpected any!" ) && bRet
;
376 aData
.Sequence
= new TestElement
[2];
377 aData
.Sequence
[0] = new TestElement(
378 aData
.Bool
, aData
.Char
, aData
.Byte
, aData
.Short
,
379 aData
.UShort
, aData
.Long
, aData
.ULong
,
380 aData
.Hyper
, aData
.UHyper
, aData
.Float
,
381 aData
.Double
, aData
.Enum
, aData
.String
,
382 aData
.Byte2
, aData
.Short2
,
383 aData
.Interface
, aData
.Any
); //(TestElement) aData;
384 aData
.Sequence
[1] = new TestElement(); //is empty
388 // this is a manually copy of aData for first setting...
389 TestDataElements aSetData
= new TestDataElements();
390 Any aAnySet
= new Any(typeof(Object
), xI
);
391 assign( (TestElement
)aSetData
,
392 aData
.Bool
, aData
.Char
, aData
.Byte
, aData
.Short
, aData
.UShort
,
393 aData
.Long
, aData
.ULong
, aData
.Hyper
, aData
.UHyper
, aData
.Float
, aData
.Double
,
394 aData
.Enum
, aData
.String
, aData
.Byte2
, aData
.Short2
, xI
,
397 aSetData
.Sequence
= new TestElement
[2];
398 aSetData
.Sequence
[0] = new TestElement(
399 aSetData
.Bool
, aSetData
.Char
, aSetData
.Byte
, aSetData
.Short
,
400 aSetData
.UShort
, aSetData
.Long
, aSetData
.ULong
,
401 aSetData
.Hyper
, aSetData
.UHyper
, aSetData
.Float
,
402 aSetData
.Double
, aSetData
.Enum
, aSetData
.String
,
403 aSetData
.Byte2
, aSetData
.Short2
,
404 aSetData
.Interface
, aSetData
.Any
); //TestElement) aSetData;
405 aSetData
.Sequence
[1] = new TestElement(); // empty struct
429 TestDataElements aRet
= new TestDataElements();
430 TestDataElements aRet2
= new TestDataElements();
452 bRet
= check( compareData( aData
, aRet
) && compareData( aData
, aRet2
) , "getValues test") && bRet
;
454 // set last retrieved values
455 TestDataElements aSV2ret
= xLBT
.setValues2(
476 // check inout sequence order
477 // => inout sequence parameter was switched by test objects
478 TestElement temp
= aRet
.Sequence
[ 0 ];
479 aRet
.Sequence
[ 0 ] = aRet
.Sequence
[ 1 ];
480 aRet
.Sequence
[ 1 ] = temp
;
483 compareData( aData
, aSV2ret
) && compareData( aData
, aRet2
),
484 "getValues2 test") && bRet
;
487 TestDataElements aRet
= new TestDataElements();
488 TestDataElements aRet2
= new TestDataElements();
489 TestDataElements aGVret
= xLBT
.getValues(
510 bRet
= check( compareData( aData
, aRet
) && compareData( aData
, aRet2
) && compareData( aData
, aGVret
), "getValues test" ) && bRet
;
512 // set last retrieved values
513 xLBT
.Bool
= aRet
.Bool
;
514 xLBT
.Char
= aRet
.Char
;
515 xLBT
.Byte
= aRet
.Byte
;
516 xLBT
.Short
= aRet
.Short
;
517 xLBT
.UShort
= aRet
.UShort
;
518 xLBT
.Long
= aRet
.Long
;
519 xLBT
.ULong
= aRet
.ULong
;
520 xLBT
.Hyper
= aRet
.Hyper
;
521 xLBT
.UHyper
= aRet
.UHyper
;
522 xLBT
.Float
= aRet
.Float
;
523 xLBT
.Double
= aRet
.Double
;
524 xLBT
.Enum
= aRet
.Enum
;
525 xLBT
.String
= aRet
.String
;
526 xLBT
.Byte2
= aRet
.Byte2
;
527 xLBT
.Short2
= aRet
.Short2
;
528 xLBT
.Interface
= aRet
.Interface
;
530 xLBT
.Sequence
= aRet
.Sequence
;
534 TestDataElements aRet
= new TestDataElements();
535 TestDataElements aRet2
= new TestDataElements();
536 aRet
.Hyper
= xLBT
.Hyper
;
537 aRet
.UHyper
= xLBT
.UHyper
;
538 aRet
.Float
= xLBT
.Float
;
539 aRet
.Double
= xLBT
.Double
;
540 aRet
.Byte
= xLBT
.Byte
;
541 aRet
.Char
= xLBT
.Char
;
542 aRet
.Bool
= xLBT
.Bool
;
543 aRet
.Short
= xLBT
.Short
;
544 aRet
.UShort
= xLBT
.UShort
;
545 aRet
.Long
= xLBT
.Long
;
546 aRet
.ULong
= xLBT
.ULong
;
547 aRet
.Enum
= xLBT
.Enum
;
548 aRet
.String
= xLBT
.String
;
549 aRet
.Byte2
= xLBT
.Byte2
;
550 aRet
.Short2
= xLBT
.Short2
;
551 aRet
.Interface
= xLBT
.Interface
;
553 aRet
.Sequence
= xLBT
.Sequence
;
556 bRet
= check( compareData( aData
, aRet
) && compareData( aData
, aRet2
) , "struct comparison test") && bRet
;
558 bRet
= check(performSequenceTest(xLBT
), "sequence test") && bRet
;
561 bRet
= check( performAnyTest( xLBT
, aData
) , "any test" ) && bRet
;
563 // sequence of call test
564 bRet
= check( performSequenceOfCallTest( xLBT
) , "sequence of call test" ) && bRet
;
566 // recursive call test
567 bRet
= check( performRecursiveCallTest( xLBT
) , "recursive test" ) && bRet
;
569 bRet
= (compareData( aData
, aRet
) && compareData( aData
, aRet2
)) && bRet
;
571 // check setting of null reference
572 xLBT
.Interface
= null;
573 aRet
.Interface
= xLBT
.Interface
;
574 bRet
= (aRet
.Interface
== null) && bRet
;
577 // Test extended attributes that raise exceptions:
579 int i
= xLBT
.RaiseAttr1
;
580 bRet
&= check(false, "getRaiseAttr1 did not throw");
581 } catch (RuntimeException
)
584 catch (System
.Exception
) {
585 bRet
&= check(false, "getRaiseAttr1 threw wrong type");
589 bRet
&= check(false, "setRaiseAttr1 did not throw");
590 } catch (IllegalArgumentException
) {
591 } catch (System
.Exception
) {
592 bRet
&= check(false, "setRaiseAttr1 threw wrong type");
595 int i
= xLBT
.RaiseAttr2
;
596 bRet
&= check(false, "getRaiseAttr2 did not throw");
597 } catch (IllegalArgumentException
) {
598 } catch (System
.Exception
) {
599 bRet
&= check(false, "getRaiseAttr2 threw wrong type");
602 // Test instantiated polymorphic struct types:
604 TestPolyStruct poly
= new TestPolyStruct(true);
606 (bool) xLBT
.transportPolyBoolean(poly
).member
,
607 "transportPolyBoolean");
608 poly
= new TestPolyStruct(12345L);
609 xLBT
.transportPolyHyper(ref poly
);
610 bRet
&= check((long)poly
.member
== 12345L, "transportPolyUnsignedHyper");
612 Any
[] seq
= { new Any(33), new Any("ABC")}
;
613 poly
= new TestPolyStruct(seq
);
614 TestPolyStruct poly2
;
615 xLBT
.transportPolySequence(poly
, out poly2
);
617 Any
[] ar
= (Any
[]) poly2
.member
;
619 ar
.Length
== 2, "transportPolySequence, length");
622 v0
= (int) ar
[0].Value
;
623 bRet
&= check(v0
== 33, "transportPolySequence, element 0");
625 string v1
= (string) ar
[1].Value
;
628 "transportPolySequence, element 1");
629 } catch (InvalidCastException
)
631 bRet
&= check(false, "transportPolySequence");
635 //When the test object is a cli object then them member is null
636 //otherwise the bridge has provided a default value.
637 TestPolyStruct s
= xLBT
.getNullPolyLong();
638 if (s
.member
!= null)
639 bRet
&= check(((int) s
.member
) == 0, "getNullPolyLong");
641 s
= xLBT
.getNullPolyString();
642 if (s
.member
!= null)
643 bRet
&= check(((string) s
.member
).Length
== 0,
644 "getNullPolyString");
645 s
= xLBT
.getNullPolyType();
646 if (s
.member
!= null)
647 bRet
&= check(((Type
) s
.member
) == typeof(void),
649 s
= xLBT
.getNullPolyAny();
650 if (s
.member
!= null)
652 Any nullAny
= (Any
) s
.member
;
654 bRet
&= check(nullAny
.Type
== typeof(void),
657 s
= xLBT
.getNullPolySequence();
658 if (s
.member
!= null)
659 bRet
&= check(((bool[]) s
.member
).Length
== 0,
660 "getNullPolySequence");
661 s
= xLBT
.getNullPolyEnum();
662 if (s
.member
!= null)
663 bRet
&= check(((TestEnum
) s
.member
) == TestEnum
.TEST
,
665 s
= xLBT
.getNullPolyStruct();
666 if (s
.member
!= null)
667 bRet
&= check(((TestStruct
) s
.member
).member
== 0,
668 "getNullPolyStruct");
669 s
= xLBT
.getNullPolyInterface();
670 bRet
&= check(s
.member
== null, "getNullPolyInterface");
672 s
= xLBT
.getNullPolyBadEnum();
673 bRet
&= check(((TestBadEnum
)s
.member
) == TestBadEnum
.M
, "getNullPolyBadEnum");
675 } catch(InvalidCastException
)
677 bRet
&= check(false, "getNullPolyXXX, InvalidCastException");
682 XBridgeTest2 xBT2
= xLBT
as XBridgeTest2
;
685 xBT2
.testConstructorsService(m_xContext
);
686 } catch (BadConstructorArguments
) {
693 static bool performSequenceTest(XBridgeTest xBT
)
696 XBridgeTest2 xBT2
= xBT
as XBridgeTest2
;
700 // perform sequence tests (XBridgeTest2)
701 // create the sequence which are compared with the results
702 bool[] arBool
= {true, false, true}
;
703 char[] arChar
= {'A','B','C'}
;
704 byte[] arByte
= { 1, 2, 0xff}
;
705 short[] arShort
= {Int16.MinValue, 1, Int16.MaxValue}
;
706 UInt16
[] arUShort
= {UInt16.MinValue , 1, UInt16.MaxValue}
;
707 int[] arLong
= {Int32.MinValue, 1, Int32.MaxValue}
;
708 UInt32
[] arULong
= {UInt32.MinValue, 1, UInt32.MaxValue}
;
709 long[] arHyper
= {Int64.MinValue, 1, Int64.MaxValue}
;
710 UInt64
[] arUHyper
= {UInt64.MinValue, 1, UInt64.MaxValue}
;
711 float[] arFloat
= {1.1f, 2.2f, 3.3f}
;
712 double[] arDouble
= {1.11, 2.22, 3.33}
;
713 string[] arString
= {"String 1", "String 2", "String 3"}
;
715 Any
[] arAny
= {new Any(true), new Any(11111), new Any(3.14)}
;
716 Object
[] arObject
= {new WeakBase(), new WeakBase(), new WeakBase()}
;
717 TestEnum
[] arEnum
= {TestEnum.ONE, TestEnum.TWO, TestEnum.CHECK}
;
719 TestElement
[] arStruct
= {new TestElement(), new TestElement(),
721 assign( arStruct
[0], true, '@', 17, 0x1234, 0xfedc, 0x12345678, 0xfedcba98,
722 0x123456789abcdef0, 0xfedcba9876543210, 17.0815f
, 3.1415926359,
723 TestEnum
.LOLA
, Constants
.STRING_TEST_CONSTANT
, arObject
[0],
724 new Any( typeof(Object
), arObject
[0]) );
725 assign( arStruct
[1], true, 'A', 17, 0x1234, 0xfedc, 0x12345678, 0xfedcba98,
726 0x123456789abcdef0, 0xfedcba9876543210, 17.0815f
, 3.1415926359,
727 TestEnum
.TWO
, Constants
.STRING_TEST_CONSTANT
, arObject
[1],
728 new Any( typeof(Object
), arObject
[1]) );
729 assign( arStruct
[2], true, 'B', 17, 0x1234, 0xfedc, 0x12345678, 0xfedcba98,
730 0x123456789abcdef0, 0xfedcba9876543210, 17.0815f
, 3.1415926359,
731 TestEnum
.CHECK
, Constants
.STRING_TEST_CONSTANT
, arObject
[2],
732 new Any( typeof(Object
), arObject
[2] ) );
735 int[][][] arLong3
= new int[][][]{
736 new int[][]{new int[]{1,2,3}
,new int[]{4,5,6}
, new int[]{7,8,9}
},
737 new int [][]{new int[]{1,2,3}
,new int[]{4,5,6}
, new int[]{7,8,9}}
,
738 new int[][]{new int[]{1,2,3}
,new int[]{4,5,6}
, new int[]{7,8,9}}
};
741 int[][] seqSeqRet
= xBT2
.setDim2(arLong3
[0]);
742 bRet
= check( compareData(seqSeqRet
, arLong3
[0]), "sequence test") && bRet
;
743 int[][][] seqSeqRet2
= xBT2
.setDim3(arLong3
);
744 bRet
= check( compareData(seqSeqRet2
, arLong3
), "sequence test") && bRet
;
745 Any
[] seqAnyRet
= xBT2
.setSequenceAny(arAny
);
746 bRet
= check( compareData(seqAnyRet
, arAny
), "sequence test") && bRet
;
747 bool[] seqBoolRet
= xBT2
.setSequenceBool(arBool
);
748 bRet
= check( compareData(seqBoolRet
, arBool
), "sequence test") && bRet
;
749 byte[] seqByteRet
= xBT2
.setSequenceByte(arByte
);
750 bRet
= check( compareData(seqByteRet
, arByte
), "sequence test") && bRet
;
751 char[] seqCharRet
= xBT2
.setSequenceChar(arChar
);
752 bRet
= check( compareData(seqCharRet
, arChar
), "sequence test") && bRet
;
753 short[] seqShortRet
= xBT2
.setSequenceShort(arShort
);
754 bRet
= check( compareData(seqShortRet
, arShort
), "sequence test") && bRet
;
755 int[] seqLongRet
= xBT2
.setSequenceLong(arLong
);
756 bRet
= check( compareData(seqLongRet
, arLong
), "sequence test") && bRet
;
757 long[] seqHyperRet
= xBT2
.setSequenceHyper(arHyper
);
758 bRet
= check( compareData(seqHyperRet
,arHyper
), "sequence test") && bRet
;
759 float[] seqFloatRet
= xBT2
.setSequenceFloat(arFloat
);
760 bRet
= check( compareData(seqFloatRet
, arFloat
), "sequence test") && bRet
;
761 double[] seqDoubleRet
= xBT2
.setSequenceDouble(arDouble
);
762 bRet
= check( compareData(seqDoubleRet
, arDouble
), "sequence test") && bRet
;
763 TestEnum
[] seqEnumRet
= xBT2
.setSequenceEnum(arEnum
);
764 bRet
= check( compareData(seqEnumRet
, arEnum
), "sequence test") && bRet
;
765 UInt16
[] seqUShortRet
= xBT2
.setSequenceUShort(arUShort
);
766 bRet
= check( compareData(seqUShortRet
, arUShort
), "sequence test") && bRet
;
767 UInt32
[] seqULongRet
= xBT2
.setSequenceULong(arULong
);
768 bRet
= check( compareData(seqULongRet
, arULong
), "sequence test") && bRet
;
769 UInt64
[] seqUHyperRet
= xBT2
.setSequenceUHyper(arUHyper
);
770 bRet
= check( compareData(seqUHyperRet
, arUHyper
), "sequence test") && bRet
;
771 Object
[] seqObjectRet
= xBT2
.setSequenceXInterface(arObject
);
772 bRet
= check( compareData(seqObjectRet
, arObject
), "sequence test") && bRet
;
773 string[] seqStringRet
= xBT2
.setSequenceString(arString
);
774 bRet
= check( compareData(seqStringRet
, arString
), "sequence test") && bRet
;
775 TestElement
[] seqStructRet
= xBT2
.setSequenceStruct(arStruct
);
776 bRet
= check( compareData(seqStructRet
, arStruct
), "sequence test") && bRet
;
779 bool[] arBoolTemp
= (bool[]) arBool
.Clone();
780 char[] arCharTemp
= (char[]) arChar
.Clone();
781 byte[] arByteTemp
= (byte[]) arByte
.Clone();
782 short[] arShortTemp
= (short[]) arShort
.Clone();
783 UInt16
[] arUShortTemp
= (UInt16
[]) arUShort
.Clone();
784 int[] arLongTemp
= (int[]) arLong
.Clone();
785 UInt32
[] arULongTemp
= (UInt32
[]) arULong
.Clone();
786 long[] arHyperTemp
= (long[]) arHyper
.Clone();
787 UInt64
[] arUHyperTemp
= (UInt64
[]) arUHyper
.Clone();
788 float[] arFloatTemp
= (float[]) arFloat
.Clone();
789 double[] arDoubleTemp
= (double[]) arDouble
.Clone();
790 TestEnum
[] arEnumTemp
= (TestEnum
[]) arEnum
.Clone();
791 string[] arStringTemp
= (string[]) arString
.Clone();
792 Object
[] arObjectTemp
= (Object
[]) arObject
.Clone();
793 Any
[] arAnyTemp
= (Any
[]) arAny
.Clone();
794 // make sure this are has the same contents as arLong3[0]
795 int[][] arLong2Temp
= new int[][]{new int[]{1,2,3}
,new int[]{4,5,6}
, new int[]{7,8,9}
};
796 // make sure this are has the same contents as arLong3
797 int[][][] arLong3Temp
= new int[][][]{
798 new int[][]{new int[]{1,2,3}
,new int[]{4,5,6}
, new int[]{7,8,9}
},
799 new int [][]{new int[]{1,2,3}
,new int[]{4,5,6}
, new int[]{7,8,9}}
,
800 new int[][]{new int[]{1,2,3}
,new int[]{4,5,6}
, new int[]{7,8,9}}
};
802 xBT2
.setSequencesInOut(ref arBoolTemp
, ref arCharTemp
, ref arByteTemp
,
803 ref arShortTemp
, ref arUShortTemp
, ref arLongTemp
,
804 ref arULongTemp
,ref arHyperTemp
, ref arUHyperTemp
,
805 ref arFloatTemp
,ref arDoubleTemp
, ref arEnumTemp
,
806 ref arStringTemp
, ref arObjectTemp
,
807 ref arAnyTemp
, ref arLong2Temp
, ref arLong3Temp
);
809 compareData(arBoolTemp
, arBool
) &&
810 compareData(arCharTemp
, arChar
) &&
811 compareData(arByteTemp
, arByte
) &&
812 compareData(arShortTemp
, arShort
) &&
813 compareData(arUShortTemp
, arUShort
) &&
814 compareData(arLongTemp
, arLong
) &&
815 compareData(arULongTemp
, arULong
) &&
816 compareData(arHyperTemp
, arHyper
) &&
817 compareData(arUHyperTemp
, arUHyper
) &&
818 compareData(arFloatTemp
, arFloat
) &&
819 compareData(arDoubleTemp
, arDouble
) &&
820 compareData(arEnumTemp
, arEnum
) &&
821 compareData(arStringTemp
, arString
) &&
822 compareData(arObjectTemp
, arObject
) &&
823 compareData(arAnyTemp
, arAny
) &&
824 compareData(arLong2Temp
, arLong3
[0]) &&
825 compareData(arLong3Temp
, arLong3
), "sequence test") && bRet
;
831 UInt16
[] arUShortOut
;
835 UInt64
[] arUHyperOut
;
837 double[] arDoubleOut
;
838 TestEnum
[] arEnumOut
;
839 string[] arStringOut
;
840 Object
[] arObjectOut
;
843 int[][][] arLong3Out
;
845 xBT2
.setSequencesOut(out arBoolOut
, out arCharOut
, out arByteOut
,
846 out arShortOut
, out arUShortOut
, out arLongOut
,
847 out arULongOut
, out arHyperOut
, out arUHyperOut
,
848 out arFloatOut
, out arDoubleOut
, out arEnumOut
,
849 out arStringOut
, out arObjectOut
, out arAnyOut
,
850 out arLong2Out
, out arLong3Out
);
852 compareData(arBoolOut
, arBool
) &&
853 compareData(arCharOut
, arChar
) &&
854 compareData(arByteOut
, arByte
) &&
855 compareData(arShortOut
, arShort
) &&
856 compareData(arUShortOut
, arUShort
) &&
857 compareData(arLongOut
, arLong
) &&
858 compareData(arULongOut
, arULong
) &&
859 compareData(arHyperOut
, arHyper
) &&
860 compareData(arUHyperOut
, arUHyper
) &&
861 compareData(arFloatOut
, arFloat
) &&
862 compareData(arDoubleOut
, arDouble
) &&
863 compareData(arEnumOut
, arEnum
) &&
864 compareData(arStringOut
, arString
) &&
865 compareData(arObjectOut
, arObject
) &&
866 compareData(arAnyOut
, arAny
) &&
867 compareData(arLong2Out
, arLong3
[0]) &&
868 compareData(arLong3Out
, arLong3
), "sequence test") && bRet
;
871 //test with empty sequences
872 int[][] _arLong2
= new int[0][];
873 int[][] seqSeqRet
= xBT2
.setDim2(_arLong2
);
874 bRet
= check( compareData(seqSeqRet
, _arLong2
), "sequence test") && bRet
;
875 int[][][] _arLong3
= new int[0][][];
876 int[][][] seqSeqRet2
= xBT2
.setDim3(_arLong3
);
877 bRet
= check( compareData(seqSeqRet2
, _arLong3
), "sequence test") && bRet
;
878 Any
[] _arAny
= new Any
[0];
879 Any
[] seqAnyRet
= xBT2
.setSequenceAny(_arAny
);
880 bRet
= check( compareData(seqAnyRet
, _arAny
), "sequence test") && bRet
;
881 bool[] _arBool
= new bool[0];
882 bool[] seqBoolRet
= xBT2
.setSequenceBool(_arBool
);
883 bRet
= check( compareData(seqBoolRet
, _arBool
), "sequence test") && bRet
;
884 byte[] _arByte
= new byte[0];
885 byte[] seqByteRet
= xBT2
.setSequenceByte(_arByte
);
886 bRet
= check( compareData(seqByteRet
, _arByte
), "sequence test") && bRet
;
887 char[] _arChar
= new char[0];
888 char[] seqCharRet
= xBT2
.setSequenceChar(_arChar
);
889 bRet
= check( compareData(seqCharRet
, _arChar
), "sequence test") && bRet
;
890 short[] _arShort
= new short[0];
891 short[] seqShortRet
= xBT2
.setSequenceShort(_arShort
);
892 bRet
= check( compareData(seqShortRet
, _arShort
), "sequence test") && bRet
;
893 int[] _arLong
= new int[0];
894 int[] seqLongRet
= xBT2
.setSequenceLong(_arLong
);
895 bRet
= check( compareData(seqLongRet
, _arLong
), "sequence test") && bRet
;
896 long[] _arHyper
= new long[0];
897 long[] seqHyperRet
= xBT2
.setSequenceHyper(_arHyper
);
898 bRet
= check( compareData(seqHyperRet
, _arHyper
), "sequence test") && bRet
;
899 float[] _arFloat
= new float[0];
900 float[] seqFloatRet
= xBT2
.setSequenceFloat(_arFloat
);
901 bRet
= check( compareData(seqFloatRet
, _arFloat
), "sequence test") && bRet
;
902 double[] _arDouble
= new double[0];
903 double[] seqDoubleRet
= xBT2
.setSequenceDouble(_arDouble
);
904 bRet
= check( compareData(seqDoubleRet
, _arDouble
), "sequence test") && bRet
;
905 TestEnum
[] _arEnum
= new TestEnum
[0];
906 TestEnum
[] seqEnumRet
= xBT2
.setSequenceEnum(_arEnum
);
907 bRet
= check( compareData(seqEnumRet
, _arEnum
), "sequence test") && bRet
;
908 UInt16
[] _arUShort
= new UInt16
[0];
909 UInt16
[] seqUShortRet
= xBT2
.setSequenceUShort(_arUShort
);
910 bRet
= check( compareData(seqUShortRet
, _arUShort
), "sequence test") && bRet
;
911 UInt32
[] _arULong
= new UInt32
[0];
912 UInt32
[] seqULongRet
= xBT2
.setSequenceULong(_arULong
);
913 bRet
= check( compareData(seqULongRet
, _arULong
), "sequence test") && bRet
;
914 UInt64
[] _arUHyper
= new UInt64
[0];
915 UInt64
[] seqUHyperRet
= xBT2
.setSequenceUHyper(_arUHyper
);
916 bRet
= check( compareData(seqUHyperRet
, _arUHyper
), "sequence test") && bRet
;
917 Object
[] _arObject
= new Object
[0];
918 Object
[] seqObjectRet
= xBT2
.setSequenceXInterface(_arObject
);
919 bRet
= check( compareData(seqObjectRet
, _arObject
), "sequence test") && bRet
;
920 string[] _arString
= new string[0];
921 string[] seqStringRet
= xBT2
.setSequenceString(_arString
);
922 bRet
= check( compareData(seqStringRet
, _arString
), "sequence test") && bRet
;
923 TestElement
[] _arStruct
= new TestElement
[0];
924 TestElement
[] seqStructRet
= xBT2
.setSequenceStruct(_arStruct
);
925 bRet
= check( compareData(seqStructRet
, _arStruct
), "sequence test") && bRet
;
932 /** Test the System::Object method on the proxy object
934 static bool testObjectMethodsImplementetion(XBridgeTest xLBT
)
937 Object obj
= new Object();
938 Object xInt
= (Object
) xLBT
;
939 XBridgeTestBase xBase
= xLBT
as XBridgeTestBase
;
943 ret
= xLBT
.Equals(obj
) == false;
944 ret
= xLBT
.Equals(xLBT
) && ret
;
945 ret
= Object
.Equals(obj
, obj
) && ret
;
946 ret
= Object
.Equals(xLBT
, xBase
) && ret
;
948 // Don't know how to verify this. Currently it is not possible to get the object id from a proxy
949 int nHash
= xLBT
.GetHashCode();
950 ret
= nHash
== xBase
.GetHashCode() && ret
;
953 // Don't know how to verify this automatically.
954 string s
= xLBT
.ToString();
955 ret
= (s
.Length
> 0) && ret
;
960 static bool raiseOnewayException(XBridgeTest xLBT
)
963 string sCompare
= Constants
.STRING_TEST_CONSTANT
;
966 // Note : the exception may fly or not (e.g. remote scenario).
967 // When it flies, it must contain the correct elements.
968 xLBT
.raiseRuntimeExceptionOneway(sCompare
, xLBT
.Interface
);
970 catch (RuntimeException e
)
972 bReturn
= ( xLBT
.Interface
== e
.Context
);
978 static bool raiseException(XBridgeTest xLBT
)
987 TestDataElements aRet
= new TestDataElements();
988 TestDataElements aRet2
= new TestDataElements();
990 5, Constants
.STRING_TEST_CONSTANT
, xLBT
.Interface
);
992 catch (unoidl
.com
.sun
.star
.lang
.IllegalArgumentException aExc
)
994 if (aExc
.ArgumentPosition
== 5 &&
995 aExc
.Context
== xLBT
.Interface
)
1001 check( false, "### unexpected exception content!" );
1004 /** it is certain, that the RuntimeException testing will fail,
1006 xLBT
.RuntimeException
= 0;
1009 catch (unoidl
.com
.sun
.star
.uno
.RuntimeException rExc
)
1011 if (rExc
.Context
== xLBT
.Interface
)
1017 check( false, "### unexpected exception content!" );
1020 /** it is certain, that the RuntimeException testing will fail, if no */
1023 xLBT
.RuntimeException
= (int) 0xcafebabe;
1027 catch (unoidl
.com
.sun
.star
.uno
.Exception rExc
)
1029 if (rExc
.Context
== xLBT
.Interface
)
1036 check( false, "### unexpected exception content!" );
1038 return (nCount
== 3);
1043 private void perform_test( XBridgeTest xLBT
)
1046 bRet
= check( performTest( xLBT
), "standard test" ) && bRet
;
1047 bRet
= check( raiseException( xLBT
) , "exception test" )&& bRet
;
1048 bRet
= check( raiseOnewayException( xLBT
), "oneway exception test" ) && bRet
;
1049 bRet
= check( testObjectMethodsImplementetion(xLBT
), "object methods test") && bRet
;
1050 bRet
= performQueryForUnknownType( xLBT
) && bRet
;
1053 throw new unoidl
.com
.sun
.star
.uno
.RuntimeException( "error (cli_cs_bridgetest.cs): test failed!", null);
1057 public BridgeTest( XComponentContext xContext
)
1059 m_xContext
= xContext
;
1062 private XComponentContext m_xContext
;
1064 public int run( String
[] args
)
1066 Debug
.AutoFlush
= true;
1067 // System.Diagnostics.Debugger.Launch();
1070 if (args
.Length
< 1)
1072 throw new RuntimeException(
1073 "missing argument for bridgetest!", this );
1076 m_xContext
.getServiceManager().createInstanceWithContext(
1077 args
[ 0 ], m_xContext
);
1080 "Calling object: {0}", test_obj
.ToString() );
1082 XBridgeTest xTest
= (XBridgeTest
) test_obj
;
1083 perform_test( xTest
);
1084 Console
.WriteLine( "\n### cli_uno C# bridgetest succeeded." );
1087 catch (unoidl
.com
.sun
.star
.uno
.RuntimeException
)
1091 catch (System
.Exception exc
)
1093 throw new unoidl
.com
.sun
.star
.uno
.RuntimeException(
1094 "cli_cs_bridgetest.cs: unexpected exception occurred in XMain::run. Original exception: " +
1095 exc
.GetType().Name
+ "\n Message: " + exc
.Message
, null);