Version 6.4.0.3, tag libreoffice-6.4.0.3
[LibreOffice.git] / testtools / source / bridgetest / cli / cli_cs_bridgetest.cs
blob9d629e062c49b8f14daa9292ef68dc3fe5e6459d
1 /*
2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 using System;
20 using System.Diagnostics;
21 using System.Reflection;
22 using uno;
23 using uno.util;
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;
29 namespace foo
31 public interface MyInterface
36 namespace cs_testobj
38 class ORecursiveCall: WeakBase, XRecursiveCall
40 public void callRecursivly(XRecursiveCall xCall, int nToCall)
42 lock (this)
44 if (nToCall > 0)
46 nToCall --;
47 xCall.callRecursivly(this, nToCall);
53 class Constants
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)
63 return true;
64 if ((val1 == null && val2 != null) ||
65 (val1 != null && val2 == null) || val1.GetType() != val2.GetType())
66 return false;
68 bool ret = false;
69 Type t1 = val1.GetType();
70 //Sequence
71 if (t1.IsArray)
73 ret = compareSequence((Array) val1, (Array) val2);
75 //String
76 else if (t1 == typeof(string))
78 ret = (string) val1 == (string) val2;
80 // Interface implementation
81 else if (t1.GetInterfaces().Length > 0 && ! t1.IsValueType)
83 ret = val1 == val2;
85 // Struct
86 else if ( ! t1.IsValueType)
88 ret = compareStruct(val1, val2);
90 else if (t1 == typeof(Any))
92 Any a1 = (Any) val1;
93 Any a2 = (Any) val2;
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);
101 else
103 Debug.Assert(false);
105 return ret;
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()))
117 return false;
119 //arrays have same rank and size and element type.
120 int len = ar1.Length;
121 Type elemType = t1.GetElementType();
122 bool ret = true;
123 for (int i = 0; i < len; i++)
125 if (compareData(ar1.GetValue(i), ar2.GetValue(i)) == false)
127 ret = false;
128 break;
131 return ret;
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();
139 if (t1 != t2)
140 return false;
141 FieldInfo[] fields = t1.GetFields();
142 int cFields = fields.Length;
143 bool ret = true;
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))
150 ret = false;
151 break;
154 return ret;
157 static bool check( bool b , string message )
159 if ( ! b)
160 Console.WriteLine("{0} failed\n" , message);
161 return b;
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.Interface == rData2.Interface, "### interface does not match!" );
180 check( compareData(rData1.Any, rData2.Any), "### any does not match!" );
182 return (rData1.Bool == rData2.Bool &&
183 rData1.Char == rData2.Char &&
184 rData1.Byte == rData2.Byte &&
185 rData1.Short == rData2.Short &&
186 rData1.UShort == rData2.UShort &&
187 rData1.Long == rData2.Long &&
188 rData1.ULong == rData2.ULong &&
189 rData1.Hyper == rData2.Hyper &&
190 rData1.UHyper == rData2.UHyper &&
191 rData1.Float == rData2.Float &&
192 rData1.Double == rData2.Double &&
193 rData1.Enum == rData2.Enum &&
194 rData1.String == rData2.String &&
195 rData1.Interface == rData2.Interface &&
196 compareData(rData1.Any, rData2.Any));
199 static void assign( TestElement rData,
200 bool bBool, char cChar, byte nByte,
201 short nShort, ushort nUShort,
202 int nLong, uint nULong,
203 long nHyper, ulong nUHyper,
204 float fFloat, double fDouble,
205 TestEnum eEnum, string rStr,
206 Object xTest,
207 Any rAny )
209 rData.Bool = bBool;
210 rData.Char = cChar;
211 rData.Byte = nByte;
212 rData.Short = nShort;
213 rData.UShort = nUShort;
214 rData.Long = nLong;
215 rData.ULong = nULong;
216 rData.Hyper = nHyper;
217 rData.UHyper = nUHyper;
218 rData.Float = fFloat;
219 rData.Double = fDouble;
220 rData.Enum = eEnum;
221 rData.String = rStr;
222 rData.Interface = xTest;
223 rData.Any = rAny;
226 static void assign( TestDataElements rData,
227 bool bBool, char cChar, byte nByte,
228 short nShort, ushort nUShort,
229 int nLong, uint nULong,
230 long nHyper, ulong nUHyper,
231 float fFloat, double fDouble,
232 TestEnum eEnum, string rStr,
233 Object xTest,
234 Any rAny,
235 TestElement[] rSequence)
237 assign( (TestElement) rData,
238 bBool, cChar, nByte, nShort, nUShort, nLong, nULong, nHyper, nUHyper, fFloat, fDouble,
239 eEnum, rStr, xTest, rAny );
240 rData.Sequence = rSequence;
243 // template < class type >
244 static bool testAny(Type typ, Object value, XBridgeTest xLBT )
246 Any any;
247 if (typ == null)
248 any = new Any(value.GetType(), value);
249 else
250 any = new Any(typ, value);
252 Any any2 = xLBT.transportAny(any);
253 bool ret;
254 if( ! (ret= compareData(any, any2)))
256 Console.WriteLine("any is different after roundtrip: in {0}, out {1}\n",
257 any.Type.FullName, any2.Type.FullName);
259 return ret;
264 static bool performAnyTest(XBridgeTest xLBT, TestDataElements data)
266 bool bReturn = true;
267 bReturn = testAny( null, data.Byte ,xLBT ) && bReturn;
268 bReturn = testAny( null, data.Short,xLBT ) && bReturn;
269 bReturn = testAny( null, data.UShort,xLBT ) && bReturn;
270 bReturn = testAny( null, data.Long,xLBT ) && bReturn;
271 bReturn = testAny( null, data.ULong,xLBT ) && bReturn;
272 bReturn = testAny( null, data.Hyper,xLBT ) && bReturn;
273 bReturn = testAny( null,data.UHyper,xLBT ) && bReturn;
274 bReturn = testAny( null, data.Float,xLBT ) && bReturn;
275 bReturn = testAny( null, data.Double,xLBT ) && bReturn;
276 bReturn = testAny( null, data.Enum,xLBT ) && bReturn;
277 bReturn = testAny( null, data.String,xLBT ) && bReturn;
278 bReturn = testAny(typeof(XWeak), data.Interface,xLBT ) && bReturn;
279 bReturn = testAny(null, data, xLBT ) && bReturn;
282 Any a1= new Any(true);
283 Any a2 = xLBT.transportAny( a1 );
284 bReturn = compareData(a2, a1) && bReturn;
288 Any a1= new Any('A');
289 Any a2 = xLBT.transportAny(a1);
290 bReturn = compareData(a2, a1) && bReturn;
292 return bReturn;
295 static bool performSequenceOfCallTest(XBridgeTest xLBT)
297 int i,nRounds;
298 int nGlobalIndex = 0;
299 const int nWaitTimeSpanMUSec = 10000;
300 for( nRounds = 0 ; nRounds < 10 ; nRounds ++ )
302 for( i = 0 ; i < nRounds ; i ++ )
304 // fire oneways
305 xLBT.callOneway(nGlobalIndex, nWaitTimeSpanMUSec);
306 nGlobalIndex++;
309 // call synchron
310 xLBT.call(nGlobalIndex, nWaitTimeSpanMUSec);
311 nGlobalIndex++;
313 return xLBT.sequenceOfCallTestPassed();
319 static bool performRecursiveCallTest(XBridgeTest xLBT)
321 xLBT.startRecursiveCall(new ORecursiveCall(), 50);
322 // on failure, the test would lock up or crash
323 return true;
326 static bool performQueryForUnknownType(XBridgeTest xLBT)
328 bool bRet = false;
329 // test queryInterface for an unknown type
332 foo.MyInterface a = (foo.MyInterface) xLBT;
334 catch( System.InvalidCastException)
336 bRet = true;
339 return bRet;
343 bool performTest(XBridgeTest xLBT)
345 check( xLBT != null, "### no test interface!" );
346 bool bRet = true;
347 if (xLBT == null)
348 return false;
350 // this data is never ever granted access to by calls other than equals(), assign()!
351 TestDataElements aData = new TestDataElements(); // test against this data
353 Object xI= new WeakBase();
355 Any aAny = new Any( typeof(Object), xI);
356 assign( (TestElement)aData,
357 true, '@', 17, 0x1234, 0xfedc, 0x12345678, 0xfedcba98,
358 0x123456789abcdef0, 0xfedcba9876543210,
359 17.0815f, 3.1415926359, TestEnum.LOLA,
360 Constants.STRING_TEST_CONSTANT, xI,
361 aAny);
363 bRet = check( aData.Any.Value == xI, "### unexpected any!" ) && bRet;
364 bRet = check( !(aData.Any.Value != xI), "### unexpected any!" ) && bRet;
366 aData.Sequence = new TestElement[2];
367 aData.Sequence[0] = new TestElement(
368 aData.Bool, aData.Char, aData.Byte, aData.Short,
369 aData.UShort, aData.Long, aData.ULong,
370 aData.Hyper, aData.UHyper, aData.Float,
371 aData.Double, aData.Enum, aData.String,
372 aData.Interface, aData.Any); //(TestElement) aData;
373 aData.Sequence[1] = new TestElement(); //is empty
375 // aData complete
377 // this is a manually copy of aData for first setting...
378 TestDataElements aSetData = new TestDataElements();
379 Any aAnySet= new Any(typeof(Object), xI);
380 assign( (TestElement)aSetData,
381 aData.Bool, aData.Char, aData.Byte, aData.Short, aData.UShort,
382 aData.Long, aData.ULong, aData.Hyper, aData.UHyper, aData.Float, aData.Double,
383 aData.Enum, aData.String, xI,
384 aAnySet);
386 aSetData.Sequence = new TestElement[2];
387 aSetData.Sequence[0] = new TestElement(
388 aSetData.Bool, aSetData.Char, aSetData.Byte, aSetData.Short,
389 aSetData.UShort, aSetData.Long, aSetData.ULong,
390 aSetData.Hyper, aSetData.UHyper, aSetData.Float,
391 aSetData.Double, aSetData.Enum, aSetData.String,
392 aSetData.Interface, aSetData.Any); //TestElement) aSetData;
393 aSetData.Sequence[1] = new TestElement(); // empty struct
395 xLBT.setValues(
396 aSetData.Bool, aSetData.Char, aSetData.Byte, aSetData.Short, aSetData.UShort,
397 aSetData.Long, aSetData.ULong, aSetData.Hyper, aSetData.UHyper, aSetData.Float, aSetData.Double,
398 aSetData.Enum, aSetData.String, aSetData.Interface, aSetData.Any, aSetData.Sequence, aSetData );
401 TestDataElements aRet = new TestDataElements();
402 TestDataElements aRet2 = new TestDataElements();
403 xLBT.getValues(
404 out aRet.Bool, out aRet.Char, out aRet.Byte, out aRet.Short, out aRet.UShort,
405 out aRet.Long, out aRet.ULong, out aRet.Hyper, out aRet.UHyper,
406 out aRet.Float, out aRet.Double, out aRet.Enum, out aRet.String,
407 out aRet.Interface, out aRet.Any, out aRet.Sequence, out aRet2 );
409 bRet = check( compareData( aData, aRet ) && compareData( aData, aRet2 ) , "getValues test") && bRet;
411 // set last retrieved values
412 TestDataElements aSV2ret = xLBT.setValues2(
413 ref aRet.Bool, ref aRet.Char, ref aRet.Byte, ref aRet.Short, ref aRet.UShort,
414 ref aRet.Long, ref aRet.ULong, ref aRet.Hyper, ref aRet.UHyper, ref aRet.Float,
415 ref aRet.Double, ref aRet.Enum, ref aRet.String, ref aRet.Interface, ref aRet.Any,
416 ref aRet.Sequence, ref aRet2 );
418 // check inout sequence order
419 // => inout sequence parameter was switched by test objects
420 TestElement temp = aRet.Sequence[ 0 ];
421 aRet.Sequence[ 0 ] = aRet.Sequence[ 1 ];
422 aRet.Sequence[ 1 ] = temp;
424 bRet = check(
425 compareData( aData, aSV2ret ) && compareData( aData, aRet2 ),
426 "getValues2 test") && bRet;
429 TestDataElements aRet = new TestDataElements();
430 TestDataElements aRet2 = new TestDataElements();
431 TestDataElements aGVret = xLBT.getValues(
432 out aRet.Bool, out aRet.Char, out aRet.Byte, out aRet.Short,
433 out aRet.UShort, out aRet.Long, out aRet.ULong, out aRet.Hyper,
434 out aRet.UHyper, out aRet.Float, out aRet.Double, out aRet.Enum,
435 out aRet.String, out aRet.Interface, out aRet.Any, out aRet.Sequence,
436 out aRet2 );
438 bRet = check( compareData( aData, aRet ) && compareData( aData, aRet2 ) && compareData( aData, aGVret ), "getValues test" ) && bRet;
440 // set last retrieved values
441 xLBT.Bool = aRet.Bool;
442 xLBT.Char = aRet.Char;
443 xLBT.Byte = aRet.Byte;
444 xLBT.Short = aRet.Short;
445 xLBT.UShort = aRet.UShort;
446 xLBT.Long = aRet.Long;
447 xLBT.ULong = aRet.ULong;
448 xLBT.Hyper = aRet.Hyper;
449 xLBT.UHyper = aRet.UHyper;
450 xLBT.Float = aRet.Float;
451 xLBT.Double = aRet.Double;
452 xLBT.Enum = aRet.Enum;
453 xLBT.String = aRet.String;
454 xLBT.Interface = aRet.Interface;
455 xLBT.Any = aRet.Any;
456 xLBT.Sequence = aRet.Sequence;
457 xLBT.Struct = aRet2;
460 TestDataElements aRet = new TestDataElements();
461 TestDataElements aRet2 = new TestDataElements();
462 aRet.Hyper = xLBT.Hyper;
463 aRet.UHyper = xLBT.UHyper;
464 aRet.Float = xLBT.Float;
465 aRet.Double = xLBT.Double;
466 aRet.Byte = xLBT.Byte;
467 aRet.Char = xLBT.Char;
468 aRet.Bool = xLBT.Bool;
469 aRet.Short = xLBT.Short;
470 aRet.UShort = xLBT.UShort;
471 aRet.Long = xLBT.Long;
472 aRet.ULong = xLBT.ULong;
473 aRet.Enum = xLBT.Enum;
474 aRet.String = xLBT.String;
475 aRet.Interface = xLBT.Interface;
476 aRet.Any = xLBT.Any;
477 aRet.Sequence = xLBT.Sequence;
478 aRet2 = xLBT.Struct;
480 bRet = check( compareData( aData, aRet ) && compareData( aData, aRet2 ) , "struct comparison test") && bRet;
482 bRet = check(performSequenceTest(xLBT), "sequence test") && bRet;
484 // any test
485 bRet = check( performAnyTest( xLBT , aData ) , "any test" ) && bRet;
487 // sequence of call test
488 bRet = check( performSequenceOfCallTest( xLBT ) , "sequence of call test" ) && bRet;
490 // recursive call test
491 bRet = check( performRecursiveCallTest( xLBT ) , "recursive test" ) && bRet;
493 bRet = (compareData( aData, aRet ) && compareData( aData, aRet2 )) && bRet ;
495 // check setting of null reference
496 xLBT.Interface = null;
497 aRet.Interface = xLBT.Interface;
498 bRet = (aRet.Interface == null) && bRet;
501 // Test extended attributes that raise exceptions:
502 try {
503 int i = xLBT.RaiseAttr1;
504 bRet &= check(false, "getRaiseAttr1 did not throw");
505 } catch (RuntimeException )
508 catch (System.Exception) {
509 bRet &= check(false, "getRaiseAttr1 threw wrong type");
511 try {
512 xLBT.RaiseAttr1 = 0;
513 bRet &= check(false, "setRaiseAttr1 did not throw");
514 } catch (IllegalArgumentException) {
515 } catch (System.Exception) {
516 bRet &= check(false, "setRaiseAttr1 threw wrong type");
518 try {
519 int i = xLBT.RaiseAttr2;
520 bRet &= check(false, "getRaiseAttr2 did not throw");
521 } catch (IllegalArgumentException ) {
522 } catch (System.Exception) {
523 bRet &= check(false, "getRaiseAttr2 threw wrong type");
526 // Test instantiated polymorphic struct types:
528 TestPolyStruct poly = new TestPolyStruct(true);
529 bRet &= check(
530 (bool) xLBT.transportPolyBoolean(poly).member,
531 "transportPolyBoolean");
532 poly = new TestPolyStruct(12345L);
533 xLBT.transportPolyHyper(ref poly);
534 bRet &= check((long)poly.member == 12345L, "transportPolyUnsignedHyper");
536 Any[] seq = { new Any(33), new Any("ABC")};
537 poly = new TestPolyStruct(seq);
538 TestPolyStruct poly2;
539 xLBT.transportPolySequence(poly, out poly2);
540 try {
541 Any[] ar = (Any[]) poly2.member;
542 bRet &= check(
543 ar.Length == 2, "transportPolySequence, length");
545 int v0;
546 v0 = (int) ar[0].Value;
547 bRet &= check(v0 == 33, "transportPolySequence, element 0");
549 string v1 = (string) ar[1].Value;
550 bRet &= check(
551 v1.Equals("ABC"),
552 "transportPolySequence, element 1");
553 } catch (InvalidCastException )
555 bRet &= check(false, "transportPolySequence");
558 try {
559 //When the test object is a cli object then them member is null
560 //otherwise the bridge has provided a default value.
561 TestPolyStruct s = xLBT.getNullPolyLong();
562 if (s.member != null)
563 bRet &= check(((int) s.member) == 0, "getNullPolyLong");
565 s = xLBT.getNullPolyString();
566 if (s.member != null)
567 bRet &= check(((string) s.member).Length == 0,
568 "getNullPolyString");
569 s = xLBT.getNullPolyType();
570 if (s.member != null)
571 bRet &= check(((Type) s.member) == typeof(void),
572 "getNullPolyType");
573 s = xLBT.getNullPolyAny();
574 if (s.member != null)
576 Any nullAny = (Any) s.member;
577 //???
578 bRet &= check(nullAny.Type == typeof(void),
579 "getNullPolyAny");
581 s = xLBT.getNullPolySequence();
582 if (s.member != null)
583 bRet &= check(((bool[]) s.member).Length == 0,
584 "getNullPolySequence");
585 s = xLBT.getNullPolyEnum();
586 if (s.member != null)
587 bRet &= check(((TestEnum) s.member) == TestEnum.TEST,
588 "getNullPolyEnum");
589 s = xLBT.getNullPolyStruct();
590 if (s.member != null)
591 bRet &= check(((TestStruct) s.member).member == 0,
592 "getNullPolyStruct");
593 s = xLBT.getNullPolyInterface();
594 bRet &= check(s.member == null, "getNullPolyInterface");
596 s = xLBT.getNullPolyBadEnum();
597 bRet &= check(((TestBadEnum)s.member) == TestBadEnum.M, "getNullPolyBadEnum");
599 } catch(InvalidCastException)
601 bRet &= check(false, "getNullPolyXXX, InvalidCastException");
606 XBridgeTest2 xBT2 = xLBT as XBridgeTest2;
607 if (xBT2 != null) {
608 try {
609 xBT2.testConstructorsService(m_xContext);
610 } catch (BadConstructorArguments) {
611 bRet = false;
615 return bRet;
617 static bool performSequenceTest(XBridgeTest xBT)
619 bool bRet = true;
620 XBridgeTest2 xBT2 = xBT as XBridgeTest2;
621 if ( xBT2 == null)
622 return false;
624 // perform sequence tests (XBridgeTest2)
625 // create the sequence which are compared with the results
626 bool[] arBool = {true, false, true};
627 char[] arChar = {'A','B','C'};
628 byte[] arByte = { 1, 2, 0xff};
629 short[] arShort = {Int16.MinValue, 1, Int16.MaxValue};
630 UInt16[] arUShort = {UInt16.MinValue , 1, UInt16.MaxValue};
631 int[] arLong = {Int32.MinValue, 1, Int32.MaxValue};
632 UInt32[] arULong = {UInt32.MinValue, 1, UInt32.MaxValue};
633 long[] arHyper = {Int64.MinValue, 1, Int64.MaxValue};
634 UInt64[] arUHyper = {UInt64.MinValue, 1, UInt64.MaxValue};
635 float[] arFloat = {1.1f, 2.2f, 3.3f};
636 double[] arDouble = {1.11, 2.22, 3.33};
637 string[] arString = {"String 1", "String 2", "String 3"};
639 Any[] arAny = {new Any(true), new Any(11111), new Any(3.14)};
640 Object[] arObject = {new WeakBase(), new WeakBase(), new WeakBase()};
641 TestEnum[] arEnum = {TestEnum.ONE, TestEnum.TWO, TestEnum.CHECK};
643 TestElement[] arStruct = {new TestElement(), new TestElement(),
644 new TestElement()};
645 assign( arStruct[0], true, '@', 17, 0x1234, 0xfedc, 0x12345678, 0xfedcba98,
646 0x123456789abcdef0, 0xfedcba9876543210, 17.0815f, 3.1415926359,
647 TestEnum.LOLA, Constants.STRING_TEST_CONSTANT, arObject[0],
648 new Any( typeof(Object), arObject[0]) );
649 assign( arStruct[1], true, 'A', 17, 0x1234, 0xfedc, 0x12345678, 0xfedcba98,
650 0x123456789abcdef0, 0xfedcba9876543210, 17.0815f, 3.1415926359,
651 TestEnum.TWO, Constants.STRING_TEST_CONSTANT, arObject[1],
652 new Any( typeof(Object), arObject[1]) );
653 assign( arStruct[2], true, 'B', 17, 0x1234, 0xfedc, 0x12345678, 0xfedcba98,
654 0x123456789abcdef0, 0xfedcba9876543210, 17.0815f, 3.1415926359,
655 TestEnum.CHECK, Constants.STRING_TEST_CONSTANT, arObject[2],
656 new Any( typeof(Object), arObject[2] ) );
659 int[][][] arLong3 = new int[][][]{
660 new int[][]{new int[]{1,2,3},new int[]{4,5,6}, new int[]{7,8,9} },
661 new int [][]{new int[]{1,2,3},new int[]{4,5,6}, new int[]{7,8,9}},
662 new int[][]{new int[]{1,2,3},new int[]{4,5,6}, new int[]{7,8,9}}};
665 int[][] seqSeqRet = xBT2.setDim2(arLong3[0]);
666 bRet = check( compareData(seqSeqRet, arLong3[0]), "sequence test") && bRet;
667 int[][][] seqSeqRet2 = xBT2.setDim3(arLong3);
668 bRet = check( compareData(seqSeqRet2, arLong3), "sequence test") && bRet;
669 Any[] seqAnyRet = xBT2.setSequenceAny(arAny);
670 bRet = check( compareData(seqAnyRet, arAny), "sequence test") && bRet;
671 bool[] seqBoolRet = xBT2.setSequenceBool(arBool);
672 bRet = check( compareData(seqBoolRet, arBool), "sequence test") && bRet;
673 byte[] seqByteRet = xBT2.setSequenceByte(arByte);
674 bRet = check( compareData(seqByteRet, arByte), "sequence test") && bRet;
675 char[] seqCharRet = xBT2.setSequenceChar(arChar);
676 bRet = check( compareData(seqCharRet, arChar), "sequence test") && bRet;
677 short[] seqShortRet = xBT2.setSequenceShort(arShort);
678 bRet = check( compareData(seqShortRet, arShort), "sequence test") && bRet;
679 int[] seqLongRet = xBT2.setSequenceLong(arLong);
680 bRet = check( compareData(seqLongRet, arLong), "sequence test") && bRet;
681 long[] seqHyperRet = xBT2.setSequenceHyper(arHyper);
682 bRet = check( compareData(seqHyperRet,arHyper), "sequence test") && bRet;
683 float[] seqFloatRet = xBT2.setSequenceFloat(arFloat);
684 bRet = check( compareData(seqFloatRet, arFloat), "sequence test") && bRet;
685 double[] seqDoubleRet = xBT2.setSequenceDouble(arDouble);
686 bRet = check( compareData(seqDoubleRet, arDouble), "sequence test") && bRet;
687 TestEnum[] seqEnumRet = xBT2.setSequenceEnum(arEnum);
688 bRet = check( compareData(seqEnumRet, arEnum), "sequence test") && bRet;
689 UInt16[] seqUShortRet = xBT2.setSequenceUShort(arUShort);
690 bRet = check( compareData(seqUShortRet, arUShort), "sequence test") && bRet;
691 UInt32[] seqULongRet = xBT2.setSequenceULong(arULong);
692 bRet = check( compareData(seqULongRet, arULong), "sequence test") && bRet;
693 UInt64[] seqUHyperRet = xBT2.setSequenceUHyper(arUHyper);
694 bRet = check( compareData(seqUHyperRet, arUHyper), "sequence test") && bRet;
695 Object[] seqObjectRet = xBT2.setSequenceXInterface(arObject);
696 bRet = check( compareData(seqObjectRet, arObject), "sequence test") && bRet;
697 string[] seqStringRet = xBT2.setSequenceString(arString);
698 bRet = check( compareData(seqStringRet, arString), "sequence test") && bRet;
699 TestElement[] seqStructRet = xBT2.setSequenceStruct(arStruct);
700 bRet = check( compareData(seqStructRet, arStruct), "sequence test") && bRet;
703 bool[] arBoolTemp = (bool[]) arBool.Clone();
704 char[] arCharTemp = (char[]) arChar.Clone();
705 byte[] arByteTemp = (byte[]) arByte.Clone();
706 short[] arShortTemp = (short[]) arShort.Clone();
707 UInt16[] arUShortTemp = (UInt16[]) arUShort.Clone();
708 int[] arLongTemp = (int[]) arLong.Clone();
709 UInt32[] arULongTemp = (UInt32[]) arULong.Clone();
710 long[] arHyperTemp = (long[]) arHyper.Clone();
711 UInt64[] arUHyperTemp = (UInt64[]) arUHyper.Clone();
712 float[] arFloatTemp = (float[]) arFloat.Clone();
713 double[] arDoubleTemp = (double[]) arDouble.Clone();
714 TestEnum[] arEnumTemp = (TestEnum[]) arEnum.Clone();
715 string[] arStringTemp = (string[]) arString.Clone();
716 Object[] arObjectTemp = (Object[]) arObject.Clone();
717 Any[] arAnyTemp = (Any[]) arAny.Clone();
718 // make sure this are has the same contents as arLong3[0]
719 int[][] arLong2Temp = new int[][]{new int[]{1,2,3},new int[]{4,5,6}, new int[]{7,8,9} };
720 // make sure this are has the same contents as arLong3
721 int[][][] arLong3Temp = new int[][][]{
722 new int[][]{new int[]{1,2,3},new int[]{4,5,6}, new int[]{7,8,9} },
723 new int [][]{new int[]{1,2,3},new int[]{4,5,6}, new int[]{7,8,9}},
724 new int[][]{new int[]{1,2,3},new int[]{4,5,6}, new int[]{7,8,9}}};
726 xBT2.setSequencesInOut(ref arBoolTemp, ref arCharTemp, ref arByteTemp,
727 ref arShortTemp, ref arUShortTemp, ref arLongTemp,
728 ref arULongTemp,ref arHyperTemp, ref arUHyperTemp,
729 ref arFloatTemp,ref arDoubleTemp, ref arEnumTemp,
730 ref arStringTemp, ref arObjectTemp,
731 ref arAnyTemp, ref arLong2Temp, ref arLong3Temp);
732 bRet = check(
733 compareData(arBoolTemp, arBool) &&
734 compareData(arCharTemp , arChar) &&
735 compareData(arByteTemp , arByte) &&
736 compareData(arShortTemp , arShort) &&
737 compareData(arUShortTemp , arUShort) &&
738 compareData(arLongTemp , arLong) &&
739 compareData(arULongTemp , arULong) &&
740 compareData(arHyperTemp , arHyper) &&
741 compareData(arUHyperTemp , arUHyper) &&
742 compareData(arFloatTemp , arFloat) &&
743 compareData(arDoubleTemp , arDouble) &&
744 compareData(arEnumTemp , arEnum) &&
745 compareData(arStringTemp , arString) &&
746 compareData(arObjectTemp , arObject) &&
747 compareData(arAnyTemp , arAny) &&
748 compareData(arLong2Temp , arLong3[0]) &&
749 compareData(arLong3Temp , arLong3), "sequence test") && bRet;
751 bool[] arBoolOut;
752 char[] arCharOut;
753 byte[] arByteOut;
754 short[] arShortOut;
755 UInt16[] arUShortOut;
756 int[] arLongOut;
757 UInt32[] arULongOut;
758 long[] arHyperOut;
759 UInt64[] arUHyperOut;
760 float[] arFloatOut;
761 double[] arDoubleOut;
762 TestEnum[] arEnumOut;
763 string[] arStringOut;
764 Object[] arObjectOut;
765 Any[] arAnyOut;
766 int[][] arLong2Out;
767 int[][][] arLong3Out;
769 xBT2.setSequencesOut(out arBoolOut, out arCharOut, out arByteOut,
770 out arShortOut, out arUShortOut, out arLongOut,
771 out arULongOut, out arHyperOut, out arUHyperOut,
772 out arFloatOut, out arDoubleOut, out arEnumOut,
773 out arStringOut, out arObjectOut, out arAnyOut,
774 out arLong2Out, out arLong3Out);
775 bRet = check(
776 compareData(arBoolOut, arBool) &&
777 compareData(arCharOut, arChar) &&
778 compareData(arByteOut, arByte) &&
779 compareData(arShortOut, arShort) &&
780 compareData(arUShortOut, arUShort) &&
781 compareData(arLongOut, arLong) &&
782 compareData(arULongOut, arULong) &&
783 compareData(arHyperOut, arHyper) &&
784 compareData(arUHyperOut, arUHyper) &&
785 compareData(arFloatOut, arFloat) &&
786 compareData(arDoubleOut, arDouble) &&
787 compareData(arEnumOut, arEnum) &&
788 compareData(arStringOut, arString) &&
789 compareData(arObjectOut, arObject) &&
790 compareData(arAnyOut, arAny) &&
791 compareData(arLong2Out, arLong3[0]) &&
792 compareData(arLong3Out, arLong3), "sequence test") && bRet;
795 //test with empty sequences
796 int[][] _arLong2 = new int[0][];
797 int[][] seqSeqRet = xBT2.setDim2(_arLong2);
798 bRet = check( compareData(seqSeqRet, _arLong2), "sequence test") && bRet;
799 int[][][] _arLong3 = new int[0][][];
800 int[][][] seqSeqRet2 = xBT2.setDim3(_arLong3);
801 bRet = check( compareData(seqSeqRet2, _arLong3), "sequence test") && bRet;
802 Any[] _arAny = new Any[0];
803 Any[] seqAnyRet = xBT2.setSequenceAny(_arAny);
804 bRet = check( compareData(seqAnyRet, _arAny), "sequence test") && bRet;
805 bool[] _arBool = new bool[0];
806 bool[] seqBoolRet = xBT2.setSequenceBool(_arBool);
807 bRet = check( compareData(seqBoolRet, _arBool), "sequence test") && bRet;
808 byte[] _arByte = new byte[0];
809 byte[] seqByteRet = xBT2.setSequenceByte(_arByte);
810 bRet = check( compareData(seqByteRet, _arByte), "sequence test") && bRet;
811 char[] _arChar = new char[0];
812 char[] seqCharRet = xBT2.setSequenceChar(_arChar);
813 bRet = check( compareData(seqCharRet, _arChar), "sequence test") && bRet;
814 short[] _arShort = new short[0];
815 short[] seqShortRet = xBT2.setSequenceShort(_arShort);
816 bRet = check( compareData(seqShortRet, _arShort), "sequence test") && bRet;
817 int[] _arLong = new int[0];
818 int[] seqLongRet = xBT2.setSequenceLong(_arLong);
819 bRet = check( compareData(seqLongRet, _arLong), "sequence test") && bRet;
820 long[] _arHyper = new long[0];
821 long[] seqHyperRet = xBT2.setSequenceHyper(_arHyper);
822 bRet = check( compareData(seqHyperRet, _arHyper), "sequence test") && bRet;
823 float[] _arFloat = new float[0];
824 float[] seqFloatRet = xBT2.setSequenceFloat(_arFloat);
825 bRet = check( compareData(seqFloatRet, _arFloat), "sequence test") && bRet;
826 double[] _arDouble = new double[0];
827 double[] seqDoubleRet = xBT2.setSequenceDouble(_arDouble);
828 bRet = check( compareData(seqDoubleRet, _arDouble), "sequence test") && bRet;
829 TestEnum[] _arEnum = new TestEnum[0];
830 TestEnum[] seqEnumRet = xBT2.setSequenceEnum(_arEnum);
831 bRet = check( compareData(seqEnumRet, _arEnum), "sequence test") && bRet;
832 UInt16[] _arUShort = new UInt16[0];
833 UInt16[] seqUShortRet = xBT2.setSequenceUShort(_arUShort);
834 bRet = check( compareData(seqUShortRet, _arUShort), "sequence test") && bRet;
835 UInt32[] _arULong = new UInt32[0];
836 UInt32[] seqULongRet = xBT2.setSequenceULong(_arULong);
837 bRet = check( compareData(seqULongRet, _arULong), "sequence test") && bRet;
838 UInt64[] _arUHyper = new UInt64[0];
839 UInt64[] seqUHyperRet = xBT2.setSequenceUHyper(_arUHyper);
840 bRet = check( compareData(seqUHyperRet, _arUHyper), "sequence test") && bRet;
841 Object[] _arObject = new Object[0];
842 Object[] seqObjectRet = xBT2.setSequenceXInterface(_arObject);
843 bRet = check( compareData(seqObjectRet, _arObject), "sequence test") && bRet;
844 string[] _arString = new string[0];
845 string[] seqStringRet = xBT2.setSequenceString(_arString);
846 bRet = check( compareData(seqStringRet, _arString), "sequence test") && bRet;
847 TestElement[] _arStruct = new TestElement[0];
848 TestElement[] seqStructRet = xBT2.setSequenceStruct(_arStruct);
849 bRet = check( compareData(seqStructRet, _arStruct), "sequence test") && bRet;
854 return bRet;
856 /** Test the System::Object method on the proxy object
858 static bool testObjectMethodsImplemention(XBridgeTest xLBT)
860 bool ret = false;
861 Object obj = new Object();
862 Object xInt = (Object) xLBT;
863 XBridgeTestBase xBase = xLBT as XBridgeTestBase;
864 if (xBase == null)
865 return false;
866 // Object.Equals
867 ret = xLBT.Equals(obj) == false;
868 ret = xLBT.Equals(xLBT) && ret;
869 ret = Object.Equals(obj, obj) && ret;
870 ret = Object.Equals(xLBT, xBase) && ret;
871 //Object.GetHashCode
872 // Don't know how to verify this. Currently it is not possible to get the object id from a proxy
873 int nHash = xLBT.GetHashCode();
874 ret = nHash == xBase.GetHashCode() && ret;
876 //Object.ToString
877 // Don't know how to verify this automatically.
878 string s = xLBT.ToString();
879 ret = (s.Length > 0) && ret;
880 return ret;
884 static bool raiseOnewayException(XBridgeTest xLBT)
886 bool bReturn = true;
887 string sCompare = Constants.STRING_TEST_CONSTANT;
890 // Note : the exception may fly or not (e.g. remote scenario).
891 // When it flies, it must contain the correct elements.
892 xLBT.raiseRuntimeExceptionOneway(sCompare, xLBT.Interface );
894 catch (RuntimeException e )
896 bReturn = ( xLBT.Interface == e.Context );
898 return bReturn;
902 static bool raiseException(XBridgeTest xLBT )
904 int nCount = 0;
911 TestDataElements aRet = new TestDataElements();
912 TestDataElements aRet2 = new TestDataElements();
913 xLBT.raiseException(
914 5, Constants.STRING_TEST_CONSTANT, xLBT.Interface );
916 catch (unoidl.com.sun.star.lang.IllegalArgumentException aExc)
918 if (aExc.ArgumentPosition == 5 &&
919 aExc.Context == xLBT.Interface)
921 ++nCount;
923 else
925 check( false, "### unexpected exception content!" );
928 /** it is certain, that the RuntimeException testing will fail,
929 if no */
930 xLBT.RuntimeException = 0;
933 catch (unoidl.com.sun.star.uno.RuntimeException rExc)
935 if (rExc.Context == xLBT.Interface )
937 ++nCount;
939 else
941 check( false, "### unexpected exception content!" );
944 /** it is certain, that the RuntimeException testing will fail, if no */
945 unchecked
947 xLBT.RuntimeException = (int) 0xcafebabe;
951 catch (unoidl.com.sun.star.uno.Exception rExc)
953 if (rExc.Context == xLBT.Interface)
955 ++nCount;
957 else
960 check( false, "### unexpected exception content!" );
962 return (nCount == 3);
964 return false;
967 private void perform_test( XBridgeTest xLBT )
969 bool bRet= true;
970 bRet = check( performTest( xLBT ), "standard test" ) && bRet;
971 bRet = check( raiseException( xLBT ) , "exception test" )&& bRet;
972 bRet = check( raiseOnewayException( xLBT ), "oneway exception test" ) && bRet;
973 bRet = check( testObjectMethodsImplemention(xLBT), "object methods test") && bRet;
974 bRet = performQueryForUnknownType( xLBT ) && bRet;
975 if ( ! bRet)
977 throw new unoidl.com.sun.star.uno.RuntimeException( "error (cli_cs_bridgetest.cs): test failed!", null);
981 public BridgeTest( XComponentContext xContext )
983 m_xContext = xContext;
986 private XComponentContext m_xContext;
988 public int run( String [] args )
990 Debug.AutoFlush = true;
991 // System.Diagnostics.Debugger.Launch();
994 if (args.Length < 1)
996 throw new RuntimeException(
997 "missing argument for bridgetest!", this );
999 Object test_obj =
1000 m_xContext.getServiceManager().createInstanceWithContext(
1001 args[ 0 ], m_xContext );
1003 Debug.WriteLine(
1004 "Calling object: {0}", test_obj.ToString() );
1006 XBridgeTest xTest = (XBridgeTest) test_obj ;
1007 perform_test( xTest );
1008 Console.WriteLine( "\n### cli_uno C# bridgetest succeeded." );
1009 return 0;
1011 catch (unoidl.com.sun.star.uno.RuntimeException)
1013 throw;
1015 catch (System.Exception exc)
1017 throw new unoidl.com.sun.star.uno.RuntimeException(
1018 "cli_cs_bridgetest.cs: unexpected exception occurred in XMain::run. Original exception: " +
1019 exc.GetType().Name + "\n Message: " + exc.Message , null);