merge the formfield patch from ooo-build
[ooovba.git] / testtools / source / bridgetest / cli / cli_cs_bridgetest.cs
blob41093c59b751aeb498b005daa034b639167fa13f
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: cli_cs_bridgetest.cs,v $
10 * $Revision: 1.10 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 using System;
32 using System.Diagnostics;
33 using System.Reflection;
34 using uno;
35 using uno.util;
36 using unoidl.com.sun.star.uno;
37 using unoidl.com.sun.star.lang;
38 //using unoidl.com.sun.star.test.bridge;
39 using unoidl.test.testtools.bridgetest;
41 namespace foo
43 public interface MyInterface
48 namespace cs_testobj
50 class ORecursiveCall: WeakBase, XRecursiveCall
52 public void callRecursivly(XRecursiveCall xCall, int nToCall)
54 lock (this)
56 if (nToCall > 0)
58 nToCall --;
59 xCall.callRecursivly(this, nToCall);
65 class Constants
67 public const string STRING_TEST_CONSTANT = "\" paco\' chorizo\\\' \"\'";
70 public class BridgeTest : WeakBase, XMain
72 static bool compareData(Object val1, Object val2)
74 if (val1 == null && val2 == null || val1 == val2)
75 return true;
76 if ((val1 == null && val2 != null) ||
77 (val1 != null && val2 == null) || val1.GetType() != val2.GetType())
78 return false;
80 bool ret = false;
81 Type t1 = val1.GetType();
82 //Sequence
83 if (t1.IsArray)
85 ret = compareSequence((Array) val1, (Array) val2);
87 //String
88 else if (t1 == typeof(string))
90 ret = (string) val1 == (string) val2;
92 // Interface implementation
93 else if (t1.GetInterfaces().Length > 0 && ! t1.IsValueType)
95 ret = val1 == val2;
97 // Struct
98 else if ( ! t1.IsValueType)
100 ret = compareStruct(val1, val2);
102 else if (t1 == typeof(Any))
104 Any a1 = (Any) val1;
105 Any a2 = (Any) val2;
106 ret = a1.Type == a2.Type && compareData(a1.Value, a2.Value);
108 else if (t1.IsValueType)
110 //Any, enum, int, bool char, float, double etc.
111 ret = val1.Equals(val2);
113 else
115 Debug.Assert(false);
117 return ret;
120 // Arrays have only one dimension
121 static bool compareSequence(Array ar1, Array ar2)
123 Debug.Assert(ar1 != null && ar2 != null);
124 Type t1 = ar1.GetType();
125 Type t2 = ar2.GetType();
127 if (!(ar1.Rank == 1 && ar2.Rank == 1
128 && ar1.Length == ar2.Length && t1.GetElementType() == t2.GetElementType()))
129 return false;
131 //arrays have same rank and size and element type.
132 int len = ar1.Length;
133 Type elemType = t1.GetElementType();
134 bool ret = true;
135 for (int i = 0; i < len; i++)
137 if (compareData(ar1.GetValue(i), ar2.GetValue(i)) == false)
139 ret = false;
140 break;
143 return ret;
146 static bool compareStruct(Object val1, Object val2)
148 Debug.Assert(val1 != null && val2 != null);
149 Type t1 = val1.GetType();
150 Type t2 = val2.GetType();
151 if (t1 != t2)
152 return false;
153 FieldInfo[] fields = t1.GetFields();
154 int cFields = fields.Length;
155 bool ret = true;
156 for (int i = 0; i < cFields; i++)
158 Object fieldVal1 = fields[i].GetValue(val1);
159 Object fieldVal2 = fields[i].GetValue(val2);
160 if ( ! compareData(fieldVal1, fieldVal2))
162 ret = false;
163 break;
166 return ret;
169 static bool check( bool b , string message )
171 if ( ! b)
172 Console.WriteLine("{0} failed\n" , message);
173 return b;
176 static bool equals(TestElement rData1, TestElement rData2)
178 check( rData1.Bool == rData2.Bool, "### bool does not match!" );
179 check( rData1.Char == rData2.Char, "### char does not match!" );
180 check( rData1.Byte == rData2.Byte, "### byte does not match!" );
181 check( rData1.Short == rData2.Short, "### short does not match!" );
182 check( rData1.UShort == rData2.UShort, "### unsigned short does not match!" );
183 check( rData1.Long == rData2.Long, "### long does not match!" );
184 check( rData1.ULong == rData2.ULong, "### unsigned long does not match!" );
185 check( rData1.Hyper == rData2.Hyper, "### hyper does not match!" );
186 check( rData1.UHyper == rData2.UHyper, "### unsigned hyper does not match!" );
187 check( rData1.Float == rData2.Float, "### float does not match!" );
188 check( rData1.Double == rData2.Double, "### double does not match!" );
189 check( rData1.Enum == rData2.Enum, "### enum does not match!" );
190 check( rData1.String == rData2.String, "### string does not match!" );
191 check( rData1.Interface == rData2.Interface, "### interface does not match!" );
192 check( compareData(rData1.Any, rData2.Any), "### any does not match!" );
194 return (rData1.Bool == rData2.Bool &&
195 rData1.Char == rData2.Char &&
196 rData1.Byte == rData2.Byte &&
197 rData1.Short == rData2.Short &&
198 rData1.UShort == rData2.UShort &&
199 rData1.Long == rData2.Long &&
200 rData1.ULong == rData2.ULong &&
201 rData1.Hyper == rData2.Hyper &&
202 rData1.UHyper == rData2.UHyper &&
203 rData1.Float == rData2.Float &&
204 rData1.Double == rData2.Double &&
205 rData1.Enum == rData2.Enum &&
206 rData1.String == rData2.String &&
207 rData1.Interface == rData2.Interface &&
208 compareData(rData1.Any, rData2.Any));
211 static void assign( TestElement rData,
212 bool bBool, char cChar, byte nByte,
213 short nShort, ushort nUShort,
214 int nLong, uint nULong,
215 long nHyper, ulong nUHyper,
216 float fFloat, double fDouble,
217 TestEnum eEnum, string rStr,
218 Object xTest,
219 Any rAny )
221 rData.Bool = bBool;
222 rData.Char = cChar;
223 rData.Byte = nByte;
224 rData.Short = nShort;
225 rData.UShort = nUShort;
226 rData.Long = nLong;
227 rData.ULong = nULong;
228 rData.Hyper = nHyper;
229 rData.UHyper = nUHyper;
230 rData.Float = fFloat;
231 rData.Double = fDouble;
232 rData.Enum = eEnum;
233 rData.String = rStr;
234 rData.Interface = xTest;
235 rData.Any = rAny;
238 static void assign( TestDataElements rData,
239 bool bBool, char cChar, byte nByte,
240 short nShort, ushort nUShort,
241 int nLong, uint nULong,
242 long nHyper, ulong nUHyper,
243 float fFloat, double fDouble,
244 TestEnum eEnum, string rStr,
245 Object xTest,
246 Any rAny,
247 TestElement[] rSequence)
249 assign( (TestElement) rData,
250 bBool, cChar, nByte, nShort, nUShort, nLong, nULong, nHyper, nUHyper, fFloat, fDouble,
251 eEnum, rStr, xTest, rAny );
252 rData.Sequence = rSequence;
255 // template < class type >
256 static bool testAny(Type typ, Object value, XBridgeTest xLBT )
258 Any any;
259 if (typ == null)
260 any = new Any(value.GetType(), value);
261 else
262 any = new Any(typ, value);
264 Any any2 = xLBT.transportAny(any);
265 bool ret;
266 if( ! (ret= compareData(any, any2)))
268 Console.WriteLine("any is different after roundtrip: in {0}, out {1}\n",
269 any.Type.FullName, any2.Type.FullName);
271 return ret;
276 static bool performAnyTest(XBridgeTest xLBT, TestDataElements data)
278 bool bReturn = true;
279 bReturn = testAny( null, data.Byte ,xLBT ) && bReturn;
280 bReturn = testAny( null, data.Short,xLBT ) && bReturn;
281 bReturn = testAny( null, data.UShort,xLBT ) && bReturn;
282 bReturn = testAny( null, data.Long,xLBT ) && bReturn;
283 bReturn = testAny( null, data.ULong,xLBT ) && bReturn;
284 bReturn = testAny( null, data.Hyper,xLBT ) && bReturn;
285 bReturn = testAny( null,data.UHyper,xLBT ) && bReturn;
286 bReturn = testAny( null, data.Float,xLBT ) && bReturn;
287 bReturn = testAny( null, data.Double,xLBT ) && bReturn;
288 bReturn = testAny( null, data.Enum,xLBT ) && bReturn;
289 bReturn = testAny( null, data.String,xLBT ) && bReturn;
290 bReturn = testAny(typeof(XWeak), data.Interface,xLBT ) && bReturn;
291 bReturn = testAny(null, data, xLBT ) && bReturn;
294 Any a1= new Any(true);
295 Any a2 = xLBT.transportAny( a1 );
296 bReturn = compareData(a2, a1) && bReturn;
300 Any a1= new Any('A');
301 Any a2 = xLBT.transportAny(a1);
302 bReturn = compareData(a2, a1) && bReturn;
304 return bReturn;
307 static bool performSequenceOfCallTest(XBridgeTest xLBT)
309 int i,nRounds;
310 int nGlobalIndex = 0;
311 const int nWaitTimeSpanMUSec = 10000;
312 for( nRounds = 0 ; nRounds < 10 ; nRounds ++ )
314 for( i = 0 ; i < nRounds ; i ++ )
316 // fire oneways
317 xLBT.callOneway(nGlobalIndex, nWaitTimeSpanMUSec);
318 nGlobalIndex++;
321 // call synchron
322 xLBT.call(nGlobalIndex, nWaitTimeSpanMUSec);
323 nGlobalIndex++;
325 return xLBT.sequenceOfCallTestPassed();
331 static bool performRecursiveCallTest(XBridgeTest xLBT)
333 xLBT.startRecursiveCall(new ORecursiveCall(), 50);
334 // on failure, the test would lock up or crash
335 return true;
338 static bool performQueryForUnknownType(XBridgeTest xLBT)
340 bool bRet = false;
341 // test queryInterface for an unknown type
344 foo.MyInterface a = (foo.MyInterface) xLBT;
346 catch( System.InvalidCastException)
348 bRet = true;
351 return bRet;
354 // //==================================================================================================
355 bool performTest(XBridgeTest xLBT)
357 check( xLBT != null, "### no test interface!" );
358 bool bRet = true;
359 if (xLBT == null)
360 return false;
362 // this data is never ever granted access to by calls other than equals(), assign()!
363 TestDataElements aData = new TestDataElements(); // test against this data
365 Object xI= new WeakBase();
367 Any aAny = new Any( typeof(Object), xI);
368 assign( (TestElement)aData,
369 true, '@', 17, 0x1234, 0xfedc, 0x12345678, 0xfedcba98,
370 0x123456789abcdef0, 0xfedcba9876543210,
371 17.0815f, 3.1415926359, TestEnum.LOLA,
372 Constants.STRING_TEST_CONSTANT, xI,
373 aAny);
375 bRet = check( aData.Any.Value == xI, "### unexpected any!" ) && bRet;
376 bRet = check( !(aData.Any.Value != xI), "### unexpected any!" ) && bRet;
378 aData.Sequence = new TestElement[2];
379 aData.Sequence[0] = new TestElement(
380 aData.Bool, aData.Char, aData.Byte, aData.Short,
381 aData.UShort, aData.Long, aData.ULong,
382 aData.Hyper, aData.UHyper, aData.Float,
383 aData.Double, aData.Enum, aData.String,
384 aData.Interface, aData.Any); //(TestElement) aData;
385 aData.Sequence[1] = new TestElement(); //is empty
387 // aData complete
389 // this is a manually copy of aData for first setting...
390 TestDataElements aSetData = new TestDataElements();
391 Any aAnySet= new Any(typeof(Object), xI);
392 assign( (TestElement)aSetData,
393 aData.Bool, aData.Char, aData.Byte, aData.Short, aData.UShort,
394 aData.Long, aData.ULong, aData.Hyper, aData.UHyper, aData.Float, aData.Double,
395 aData.Enum, aData.String, xI,
396 aAnySet);
398 aSetData.Sequence = new TestElement[2];
399 aSetData.Sequence[0] = new TestElement(
400 aSetData.Bool, aSetData.Char, aSetData.Byte, aSetData.Short,
401 aSetData.UShort, aSetData.Long, aSetData.ULong,
402 aSetData.Hyper, aSetData.UHyper, aSetData.Float,
403 aSetData.Double, aSetData.Enum, aSetData.String,
404 aSetData.Interface, aSetData.Any); //TestElement) aSetData;
405 aSetData.Sequence[1] = new TestElement(); // empty struct
407 xLBT.setValues(
408 aSetData.Bool, aSetData.Char, aSetData.Byte, aSetData.Short, aSetData.UShort,
409 aSetData.Long, aSetData.ULong, aSetData.Hyper, aSetData.UHyper, aSetData.Float, aSetData.Double,
410 aSetData.Enum, aSetData.String, aSetData.Interface, aSetData.Any, aSetData.Sequence, aSetData );
413 TestDataElements aRet = new TestDataElements();
414 TestDataElements aRet2 = new TestDataElements();
415 xLBT.getValues(
416 out aRet.Bool, out aRet.Char, out aRet.Byte, out aRet.Short, out aRet.UShort,
417 out aRet.Long, out aRet.ULong, out aRet.Hyper, out aRet.UHyper,
418 out aRet.Float, out aRet.Double, out aRet.Enum, out aRet.String,
419 out aRet.Interface, out aRet.Any, out aRet.Sequence, out aRet2 );
421 bRet = check( compareData( aData, aRet ) && compareData( aData, aRet2 ) , "getValues test") && bRet;
423 // set last retrieved values
424 TestDataElements aSV2ret = xLBT.setValues2(
425 ref aRet.Bool, ref aRet.Char, ref aRet.Byte, ref aRet.Short, ref aRet.UShort,
426 ref aRet.Long, ref aRet.ULong, ref aRet.Hyper, ref aRet.UHyper, ref aRet.Float,
427 ref aRet.Double, ref aRet.Enum, ref aRet.String, ref aRet.Interface, ref aRet.Any,
428 ref aRet.Sequence, ref aRet2 );
430 // check inout sequence order
431 // => inout sequence parameter was switched by test objects
432 TestElement temp = aRet.Sequence[ 0 ];
433 aRet.Sequence[ 0 ] = aRet.Sequence[ 1 ];
434 aRet.Sequence[ 1 ] = temp;
436 bRet = check(
437 compareData( aData, aSV2ret ) && compareData( aData, aRet2 ),
438 "getValues2 test") && bRet;
441 TestDataElements aRet = new TestDataElements();
442 TestDataElements aRet2 = new TestDataElements();
443 TestDataElements aGVret = xLBT.getValues(
444 out aRet.Bool, out aRet.Char, out aRet.Byte, out aRet.Short,
445 out aRet.UShort, out aRet.Long, out aRet.ULong, out aRet.Hyper,
446 out aRet.UHyper, out aRet.Float, out aRet.Double, out aRet.Enum,
447 out aRet.String, out aRet.Interface, out aRet.Any, out aRet.Sequence,
448 out aRet2 );
450 bRet = check( compareData( aData, aRet ) && compareData( aData, aRet2 ) && compareData( aData, aGVret ), "getValues test" ) && bRet;
452 // set last retrieved values
453 xLBT.Bool = aRet.Bool;
454 xLBT.Char = aRet.Char;
455 xLBT.Byte = aRet.Byte;
456 xLBT.Short = aRet.Short;
457 xLBT.UShort = aRet.UShort;
458 xLBT.Long = aRet.Long;
459 xLBT.ULong = aRet.ULong;
460 xLBT.Hyper = aRet.Hyper;
461 xLBT.UHyper = aRet.UHyper;
462 xLBT.Float = aRet.Float;
463 xLBT.Double = aRet.Double;
464 xLBT.Enum = aRet.Enum;
465 xLBT.String = aRet.String;
466 xLBT.Interface = aRet.Interface;
467 xLBT.Any = aRet.Any;
468 xLBT.Sequence = aRet.Sequence;
469 xLBT.Struct = aRet2;
472 TestDataElements aRet = new TestDataElements();
473 TestDataElements aRet2 = new TestDataElements();
474 aRet.Hyper = xLBT.Hyper;
475 aRet.UHyper = xLBT.UHyper;
476 aRet.Float = xLBT.Float;
477 aRet.Double = xLBT.Double;
478 aRet.Byte = xLBT.Byte;
479 aRet.Char = xLBT.Char;
480 aRet.Bool = xLBT.Bool;
481 aRet.Short = xLBT.Short;
482 aRet.UShort = xLBT.UShort;
483 aRet.Long = xLBT.Long;
484 aRet.ULong = xLBT.ULong;
485 aRet.Enum = xLBT.Enum;
486 aRet.String = xLBT.String;
487 aRet.Interface = xLBT.Interface;
488 aRet.Any = xLBT.Any;
489 aRet.Sequence = xLBT.Sequence;
490 aRet2 = xLBT.Struct;
492 bRet = check( compareData( aData, aRet ) && compareData( aData, aRet2 ) , "struct comparison test") && bRet;
494 bRet = check(performSequenceTest(xLBT), "sequence test") && bRet;
496 // any test
497 bRet = check( performAnyTest( xLBT , aData ) , "any test" ) && bRet;
499 // sequence of call test
500 bRet = check( performSequenceOfCallTest( xLBT ) , "sequence of call test" ) && bRet;
502 // recursive call test
503 bRet = check( performRecursiveCallTest( xLBT ) , "recursive test" ) && bRet;
505 bRet = (compareData( aData, aRet ) && compareData( aData, aRet2 )) && bRet ;
507 // check setting of null reference
508 xLBT.Interface = null;
509 aRet.Interface = xLBT.Interface;
510 bRet = (aRet.Interface == null) && bRet;
513 // Test extended attributes that raise exceptions:
514 try {
515 int i = xLBT.RaiseAttr1;
516 bRet &= check(false, "getRaiseAttr1 did not throw");
517 } catch (RuntimeException )
520 catch (System.Exception) {
521 bRet &= check(false, "getRaiseAttr1 threw wrong type");
523 try {
524 xLBT.RaiseAttr1 = 0;
525 bRet &= check(false, "setRaiseAttr1 did not throw");
526 } catch (IllegalArgumentException) {
527 } catch (System.Exception) {
528 bRet &= check(false, "setRaiseAttr1 threw wrong type");
530 try {
531 int i = xLBT.RaiseAttr2;
532 bRet &= check(false, "getRaiseAttr2 did not throw");
533 } catch (IllegalArgumentException ) {
534 } catch (System.Exception) {
535 bRet &= check(false, "getRaiseAttr2 threw wrong type");
538 // Test instantiated polymorphic struct types:
540 TestPolyStruct poly = new TestPolyStruct(true);
541 bRet &= check(
542 (bool) xLBT.transportPolyBoolean(poly).member,
543 "transportPolyBoolean");
544 poly = new TestPolyStruct(12345L);
545 xLBT.transportPolyHyper(ref poly);
546 bRet &= check((long)poly.member == 12345L, "transportPolyUnsignedHyper");
548 Any[] seq = { new Any(33), new Any("ABC")};
549 poly = new TestPolyStruct(seq);
550 TestPolyStruct poly2;
551 xLBT.transportPolySequence(poly, out poly2);
552 try {
553 Any[] ar = (Any[]) poly2.member;
554 bRet &= check(
555 ar.Length == 2, "transportPolySequence, length");
557 int v0;
558 v0 = (int) ar[0].Value;
559 bRet &= check(v0 == 33, "transportPolySequence, element 0");
561 string v1 = (string) ar[1].Value;
562 bRet &= check(
563 v1.Equals("ABC"),
564 "transportPolySequence, element 1");
565 } catch (InvalidCastException )
567 bRet &= check(false, "transportPolySequence");
570 try {
571 //When the test object is a cli object then them member is null
572 //otherwise the bridge has provided a default value.
573 TestPolyStruct s = xLBT.getNullPolyLong();
574 if (s.member != null)
575 bRet &= check(((int) s.member) == 0, "getNullPolyLong");
577 s = xLBT.getNullPolyString();
578 if (s.member != null)
579 bRet &= check(((string) s.member).Length == 0,
580 "getNullPolyString");
581 s = xLBT.getNullPolyType();
582 if (s.member != null)
583 bRet &= check(((Type) s.member) == typeof(void),
584 "getNullPolyType");
585 s = xLBT.getNullPolyAny();
586 if (s.member != null)
588 Any nullAny = (Any) s.member;
589 //???
590 bRet &= check(nullAny.Type == typeof(void),
591 "getNullPolyAny");
593 s = xLBT.getNullPolySequence();
594 if (s.member != null)
595 bRet &= check(((bool[]) s.member).Length == 0,
596 "getNullPolySequence");
597 s = xLBT.getNullPolyEnum();
598 if (s.member != null)
599 bRet &= check(((TestEnum) s.member) == TestEnum.TEST,
600 "getNullPolyEnum");
601 s = xLBT.getNullPolyStruct();
602 if (s.member != null)
603 bRet &= check(((TestStruct) s.member).member == 0,
604 "getNullPolyStruct");
605 s = xLBT.getNullPolyInterface();
606 bRet &= check(s.member == null, "getNullPolyInterface");
608 s = xLBT.getNullPolyBadEnum();
609 bRet &= check(((TestBadEnum)s.member) == TestBadEnum.M, "getNullPolyBadEnum");
611 } catch(InvalidCastException)
613 bRet &= check(false, "getNullPolyXXX, InvalidCastException");
618 XBridgeTest2 xBT2 = xLBT as XBridgeTest2;
619 if (xBT2 != null) {
620 try {
621 xBT2.testConstructorsService(m_xContext);
622 } catch (BadConstructorArguments) {
623 bRet = false;
627 return bRet;
629 static bool performSequenceTest(XBridgeTest xBT)
631 bool bRet = true;
632 XBridgeTest2 xBT2 = xBT as XBridgeTest2;
633 if ( xBT2 == null)
634 return false;
636 // perform sequence tests (XBridgeTest2)
637 // create the sequence which are compared with the results
638 bool[] arBool = {true, false, true};
639 char[] arChar = {'A','B','C'};
640 byte[] arByte = { 1, 2, 0xff};
641 short[] arShort = {Int16.MinValue, 1, Int16.MaxValue};
642 UInt16[] arUShort = {UInt16.MinValue , 1, UInt16.MaxValue};
643 int[] arLong = {Int32.MinValue, 1, Int32.MaxValue};
644 UInt32[] arULong = {UInt32.MinValue, 1, UInt32.MaxValue};
645 long[] arHyper = {Int64.MinValue, 1, Int64.MaxValue};
646 UInt64[] arUHyper = {UInt64.MinValue, 1, UInt64.MaxValue};
647 float[] arFloat = {1.1f, 2.2f, 3.3f};
648 double[] arDouble = {1.11, 2.22, 3.33};
649 string[] arString = {"String 1", "String 2", "String 3"};
651 Any[] arAny = {new Any(true), new Any(11111), new Any(3.14)};
652 Object[] arObject = {new WeakBase(), new WeakBase(), new WeakBase()};
653 TestEnum[] arEnum = {TestEnum.ONE, TestEnum.TWO, TestEnum.CHECK};
655 TestElement[] arStruct = {new TestElement(), new TestElement(),
656 new TestElement()};
657 assign( arStruct[0], true, '@', 17, 0x1234, 0xfedc, 0x12345678, 0xfedcba98,
658 0x123456789abcdef0, 0xfedcba9876543210, 17.0815f, 3.1415926359,
659 TestEnum.LOLA, Constants.STRING_TEST_CONSTANT, arObject[0],
660 new Any( typeof(Object), arObject[0]) );
661 assign( arStruct[1], true, 'A', 17, 0x1234, 0xfedc, 0x12345678, 0xfedcba98,
662 0x123456789abcdef0, 0xfedcba9876543210, 17.0815f, 3.1415926359,
663 TestEnum.TWO, Constants.STRING_TEST_CONSTANT, arObject[1],
664 new Any( typeof(Object), arObject[1]) );
665 assign( arStruct[2], true, 'B', 17, 0x1234, 0xfedc, 0x12345678, 0xfedcba98,
666 0x123456789abcdef0, 0xfedcba9876543210, 17.0815f, 3.1415926359,
667 TestEnum.CHECK, Constants.STRING_TEST_CONSTANT, arObject[2],
668 new Any( typeof(Object), arObject[2] ) );
671 int[][][] arLong3 = new int[][][]{
672 new int[][]{new int[]{1,2,3},new int[]{4,5,6}, new int[]{7,8,9} },
673 new int [][]{new int[]{1,2,3},new int[]{4,5,6}, new int[]{7,8,9}},
674 new int[][]{new int[]{1,2,3},new int[]{4,5,6}, new int[]{7,8,9}}};
677 int[][] seqSeqRet = xBT2.setDim2(arLong3[0]);
678 bRet = check( compareData(seqSeqRet, arLong3[0]), "sequence test") && bRet;
679 int[][][] seqSeqRet2 = xBT2.setDim3(arLong3);
680 bRet = check( compareData(seqSeqRet2, arLong3), "sequence test") && bRet;
681 Any[] seqAnyRet = xBT2.setSequenceAny(arAny);
682 bRet = check( compareData(seqAnyRet, arAny), "sequence test") && bRet;
683 bool[] seqBoolRet = xBT2.setSequenceBool(arBool);
684 bRet = check( compareData(seqBoolRet, arBool), "sequence test") && bRet;
685 byte[] seqByteRet = xBT2.setSequenceByte(arByte);
686 bRet = check( compareData(seqByteRet, arByte), "sequence test") && bRet;
687 char[] seqCharRet = xBT2.setSequenceChar(arChar);
688 bRet = check( compareData(seqCharRet, arChar), "sequence test") && bRet;
689 short[] seqShortRet = xBT2.setSequenceShort(arShort);
690 bRet = check( compareData(seqShortRet, arShort), "sequence test") && bRet;
691 int[] seqLongRet = xBT2.setSequenceLong(arLong);
692 bRet = check( compareData(seqLongRet, arLong), "sequence test") && bRet;
693 long[] seqHyperRet = xBT2.setSequenceHyper(arHyper);
694 bRet = check( compareData(seqHyperRet,arHyper), "sequence test") && bRet;
695 float[] seqFloatRet = xBT2.setSequenceFloat(arFloat);
696 bRet = check( compareData(seqFloatRet, arFloat), "sequence test") && bRet;
697 double[] seqDoubleRet = xBT2.setSequenceDouble(arDouble);
698 bRet = check( compareData(seqDoubleRet, arDouble), "sequence test") && bRet;
699 TestEnum[] seqEnumRet = xBT2.setSequenceEnum(arEnum);
700 bRet = check( compareData(seqEnumRet, arEnum), "sequence test") && bRet;
701 UInt16[] seqUShortRet = xBT2.setSequenceUShort(arUShort);
702 bRet = check( compareData(seqUShortRet, arUShort), "sequence test") && bRet;
703 UInt32[] seqULongRet = xBT2.setSequenceULong(arULong);
704 bRet = check( compareData(seqULongRet, arULong), "sequence test") && bRet;
705 UInt64[] seqUHyperRet = xBT2.setSequenceUHyper(arUHyper);
706 bRet = check( compareData(seqUHyperRet, arUHyper), "sequence test") && bRet;
707 Object[] seqObjectRet = xBT2.setSequenceXInterface(arObject);
708 bRet = check( compareData(seqObjectRet, arObject), "sequence test") && bRet;
709 string[] seqStringRet = xBT2.setSequenceString(arString);
710 bRet = check( compareData(seqStringRet, arString), "sequence test") && bRet;
711 TestElement[] seqStructRet = xBT2.setSequenceStruct(arStruct);
712 bRet = check( compareData(seqStructRet, arStruct), "sequence test") && bRet;
715 bool[] arBoolTemp = (bool[]) arBool.Clone();
716 char[] arCharTemp = (char[]) arChar.Clone();
717 byte[] arByteTemp = (byte[]) arByte.Clone();
718 short[] arShortTemp = (short[]) arShort.Clone();
719 UInt16[] arUShortTemp = (UInt16[]) arUShort.Clone();
720 int[] arLongTemp = (int[]) arLong.Clone();
721 UInt32[] arULongTemp = (UInt32[]) arULong.Clone();
722 long[] arHyperTemp = (long[]) arHyper.Clone();
723 UInt64[] arUHyperTemp = (UInt64[]) arUHyper.Clone();
724 float[] arFloatTemp = (float[]) arFloat.Clone();
725 double[] arDoubleTemp = (double[]) arDouble.Clone();
726 TestEnum[] arEnumTemp = (TestEnum[]) arEnum.Clone();
727 string[] arStringTemp = (string[]) arString.Clone();
728 Object[] arObjectTemp = (Object[]) arObject.Clone();
729 Any[] arAnyTemp = (Any[]) arAny.Clone();
730 // make sure this are has the same contents as arLong3[0]
731 int[][] arLong2Temp = new int[][]{new int[]{1,2,3},new int[]{4,5,6}, new int[]{7,8,9} };
732 // make sure this are has the same contents as arLong3
733 int[][][] arLong3Temp = new int[][][]{
734 new int[][]{new int[]{1,2,3},new int[]{4,5,6}, new int[]{7,8,9} },
735 new int [][]{new int[]{1,2,3},new int[]{4,5,6}, new int[]{7,8,9}},
736 new int[][]{new int[]{1,2,3},new int[]{4,5,6}, new int[]{7,8,9}}};
738 xBT2.setSequencesInOut(ref arBoolTemp, ref arCharTemp, ref arByteTemp,
739 ref arShortTemp, ref arUShortTemp, ref arLongTemp,
740 ref arULongTemp,ref arHyperTemp, ref arUHyperTemp,
741 ref arFloatTemp,ref arDoubleTemp, ref arEnumTemp,
742 ref arStringTemp, ref arObjectTemp,
743 ref arAnyTemp, ref arLong2Temp, ref arLong3Temp);
744 bRet = check(
745 compareData(arBoolTemp, arBool) &&
746 compareData(arCharTemp , arChar) &&
747 compareData(arByteTemp , arByte) &&
748 compareData(arShortTemp , arShort) &&
749 compareData(arUShortTemp , arUShort) &&
750 compareData(arLongTemp , arLong) &&
751 compareData(arULongTemp , arULong) &&
752 compareData(arHyperTemp , arHyper) &&
753 compareData(arUHyperTemp , arUHyper) &&
754 compareData(arFloatTemp , arFloat) &&
755 compareData(arDoubleTemp , arDouble) &&
756 compareData(arEnumTemp , arEnum) &&
757 compareData(arStringTemp , arString) &&
758 compareData(arObjectTemp , arObject) &&
759 compareData(arAnyTemp , arAny) &&
760 compareData(arLong2Temp , arLong3[0]) &&
761 compareData(arLong3Temp , arLong3), "sequence test") && bRet;
763 bool[] arBoolOut;
764 char[] arCharOut;
765 byte[] arByteOut;
766 short[] arShortOut;
767 UInt16[] arUShortOut;
768 int[] arLongOut;
769 UInt32[] arULongOut;
770 long[] arHyperOut;
771 UInt64[] arUHyperOut;
772 float[] arFloatOut;
773 double[] arDoubleOut;
774 TestEnum[] arEnumOut;
775 string[] arStringOut;
776 Object[] arObjectOut;
777 Any[] arAnyOut;
778 int[][] arLong2Out;
779 int[][][] arLong3Out;
781 xBT2.setSequencesOut(out arBoolOut, out arCharOut, out arByteOut,
782 out arShortOut, out arUShortOut, out arLongOut,
783 out arULongOut, out arHyperOut, out arUHyperOut,
784 out arFloatOut, out arDoubleOut, out arEnumOut,
785 out arStringOut, out arObjectOut, out arAnyOut,
786 out arLong2Out, out arLong3Out);
787 bRet = check(
788 compareData(arBoolOut, arBool) &&
789 compareData(arCharOut, arChar) &&
790 compareData(arByteOut, arByte) &&
791 compareData(arShortOut, arShort) &&
792 compareData(arUShortOut, arUShort) &&
793 compareData(arLongOut, arLong) &&
794 compareData(arULongOut, arULong) &&
795 compareData(arHyperOut, arHyper) &&
796 compareData(arUHyperOut, arUHyper) &&
797 compareData(arFloatOut, arFloat) &&
798 compareData(arDoubleOut, arDouble) &&
799 compareData(arEnumOut, arEnum) &&
800 compareData(arStringOut, arString) &&
801 compareData(arObjectOut, arObject) &&
802 compareData(arAnyOut, arAny) &&
803 compareData(arLong2Out, arLong3[0]) &&
804 compareData(arLong3Out, arLong3), "sequence test") && bRet;
807 //test with empty sequences
808 int[][] _arLong2 = new int[0][];
809 int[][] seqSeqRet = xBT2.setDim2(_arLong2);
810 bRet = check( compareData(seqSeqRet, _arLong2), "sequence test") && bRet;
811 int[][][] _arLong3 = new int[0][][];
812 int[][][] seqSeqRet2 = xBT2.setDim3(_arLong3);
813 bRet = check( compareData(seqSeqRet2, _arLong3), "sequence test") && bRet;
814 Any[] _arAny = new Any[0];
815 Any[] seqAnyRet = xBT2.setSequenceAny(_arAny);
816 bRet = check( compareData(seqAnyRet, _arAny), "sequence test") && bRet;
817 bool[] _arBool = new bool[0];
818 bool[] seqBoolRet = xBT2.setSequenceBool(_arBool);
819 bRet = check( compareData(seqBoolRet, _arBool), "sequence test") && bRet;
820 byte[] _arByte = new byte[0];
821 byte[] seqByteRet = xBT2.setSequenceByte(_arByte);
822 bRet = check( compareData(seqByteRet, _arByte), "sequence test") && bRet;
823 char[] _arChar = new char[0];
824 char[] seqCharRet = xBT2.setSequenceChar(_arChar);
825 bRet = check( compareData(seqCharRet, _arChar), "sequence test") && bRet;
826 short[] _arShort = new short[0];
827 short[] seqShortRet = xBT2.setSequenceShort(_arShort);
828 bRet = check( compareData(seqShortRet, _arShort), "sequence test") && bRet;
829 int[] _arLong = new int[0];
830 int[] seqLongRet = xBT2.setSequenceLong(_arLong);
831 bRet = check( compareData(seqLongRet, _arLong), "sequence test") && bRet;
832 long[] _arHyper = new long[0];
833 long[] seqHyperRet = xBT2.setSequenceHyper(_arHyper);
834 bRet = check( compareData(seqHyperRet, _arHyper), "sequence test") && bRet;
835 float[] _arFloat = new float[0];
836 float[] seqFloatRet = xBT2.setSequenceFloat(_arFloat);
837 bRet = check( compareData(seqFloatRet, _arFloat), "sequence test") && bRet;
838 double[] _arDouble = new double[0];
839 double[] seqDoubleRet = xBT2.setSequenceDouble(_arDouble);
840 bRet = check( compareData(seqDoubleRet, _arDouble), "sequence test") && bRet;
841 TestEnum[] _arEnum = new TestEnum[0];
842 TestEnum[] seqEnumRet = xBT2.setSequenceEnum(_arEnum);
843 bRet = check( compareData(seqEnumRet, _arEnum), "sequence test") && bRet;
844 UInt16[] _arUShort = new UInt16[0];
845 UInt16[] seqUShortRet = xBT2.setSequenceUShort(_arUShort);
846 bRet = check( compareData(seqUShortRet, _arUShort), "sequence test") && bRet;
847 UInt32[] _arULong = new UInt32[0];
848 UInt32[] seqULongRet = xBT2.setSequenceULong(_arULong);
849 bRet = check( compareData(seqULongRet, _arULong), "sequence test") && bRet;
850 UInt64[] _arUHyper = new UInt64[0];
851 UInt64[] seqUHyperRet = xBT2.setSequenceUHyper(_arUHyper);
852 bRet = check( compareData(seqUHyperRet, _arUHyper), "sequence test") && bRet;
853 Object[] _arObject = new Object[0];
854 Object[] seqObjectRet = xBT2.setSequenceXInterface(_arObject);
855 bRet = check( compareData(seqObjectRet, _arObject), "sequence test") && bRet;
856 string[] _arString = new string[0];
857 string[] seqStringRet = xBT2.setSequenceString(_arString);
858 bRet = check( compareData(seqStringRet, _arString), "sequence test") && bRet;
859 TestElement[] _arStruct = new TestElement[0];
860 TestElement[] seqStructRet = xBT2.setSequenceStruct(_arStruct);
861 bRet = check( compareData(seqStructRet, _arStruct), "sequence test") && bRet;
866 return bRet;
868 /** Test the System::Object method on the proxy object
870 static bool testObjectMethodsImplemention(XBridgeTest xLBT)
872 bool ret = false;
873 Object obj = new Object();
874 Object xInt = (Object) xLBT;
875 XBridgeTestBase xBase = xLBT as XBridgeTestBase;
876 if (xBase == null)
877 return false;
878 // Object.Equals
879 ret = xLBT.Equals(obj) == false;
880 ret = xLBT.Equals(xLBT) && ret;
881 ret = Object.Equals(obj, obj) && ret;
882 ret = Object.Equals(xLBT, xBase) && ret;
883 //Object.GetHashCode
884 // Don't know how to verify this. Currently it is not possible to get the object id from a proxy
885 int nHash = xLBT.GetHashCode();
886 ret = nHash == xBase.GetHashCode() && ret;
888 //Object.ToString
889 // Don't know how to verify this automatically.
890 string s = xLBT.ToString();
891 ret = (s.Length > 0) && ret;
892 return ret;
896 static bool raiseOnewayException(XBridgeTest xLBT)
898 bool bReturn = true;
899 string sCompare = Constants.STRING_TEST_CONSTANT;
902 // Note : the exception may fly or not (e.g. remote scenario).
903 // When it flies, it must contain the correct elements.
904 xLBT.raiseRuntimeExceptionOneway(sCompare, xLBT.Interface );
906 catch (RuntimeException e )
908 bReturn = ( xLBT.Interface == e.Context );
910 return bReturn;
913 // //==================================================================================================
914 static bool raiseException(XBridgeTest xLBT )
916 int nCount = 0;
923 TestDataElements aRet = new TestDataElements();
924 TestDataElements aRet2 = new TestDataElements();
925 xLBT.raiseException(
926 5, Constants.STRING_TEST_CONSTANT, xLBT.Interface );
928 catch (unoidl.com.sun.star.lang.IllegalArgumentException aExc)
930 if (aExc.ArgumentPosition == 5 &&
931 aExc.Context == xLBT.Interface)
933 ++nCount;
935 else
937 check( false, "### unexpected exception content!" );
940 /** it is certain, that the RuntimeException testing will fail,
941 if no */
942 xLBT.RuntimeException = 0;
945 catch (unoidl.com.sun.star.uno.RuntimeException rExc)
947 if (rExc.Context == xLBT.Interface )
949 ++nCount;
951 else
953 check( false, "### unexpected exception content!" );
956 /** it is certain, that the RuntimeException testing will fail, if no */
957 unchecked
959 xLBT.RuntimeException = (int) 0xcafebabe;
963 catch (unoidl.com.sun.star.uno.Exception rExc)
965 if (rExc.Context == xLBT.Interface)
967 ++nCount;
969 else
972 check( false, "### unexpected exception content!" );
974 return (nCount == 3);
976 return false;
979 private void perform_test( XBridgeTest xLBT )
981 bool bRet= true;;
982 bRet = check( performTest( xLBT ), "standard test" ) && bRet;
983 bRet = check( raiseException( xLBT ) , "exception test" )&& bRet;
984 bRet = check( raiseOnewayException( xLBT ), "oneway exception test" ) && bRet;
985 bRet = check( testObjectMethodsImplemention(xLBT), "object methods test") && bRet;
986 bRet = performQueryForUnknownType( xLBT ) && bRet;
987 if ( ! bRet)
989 throw new unoidl.com.sun.star.uno.RuntimeException( "error (cli_cs_bridgetest.cs): test failed!", null);
993 public BridgeTest( XComponentContext xContext )
995 m_xContext = xContext;
998 private XComponentContext m_xContext;
1000 public int run( String [] args )
1002 Debug.AutoFlush = true;
1003 // System.Diagnostics.Debugger.Launch();
1006 if (args.Length < 1)
1008 throw new RuntimeException(
1009 "missing argument for bridgetest!", this );
1011 Object test_obj =
1012 m_xContext.getServiceManager().createInstanceWithContext(
1013 args[ 0 ], m_xContext );
1015 Debug.WriteLine(
1016 "Calling object: {0}", test_obj.ToString() );
1018 XBridgeTest xTest = (XBridgeTest) test_obj ;
1019 perform_test( xTest );
1020 Console.WriteLine( "\n### cli_uno C# bridgetest succeeded." );
1021 return 0;
1023 catch (unoidl.com.sun.star.uno.RuntimeException)
1025 throw;
1027 catch (System.Exception exc)
1029 throw new unoidl.com.sun.star.uno.RuntimeException(
1030 "cli_cs_bridgetest.cs: unexpected exception occured in XMain::run. Original exception: " +
1031 exc.GetType().Name + "\n Message: " + exc.Message , null);