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
.Threading
;
22 using System
.Runtime
.CompilerServices
;
25 using unoidl
.com
.sun
.star
.uno
;
26 using unoidl
.com
.sun
.star
.lang
;
27 using unoidl
.test
.testtools
.bridgetest
;
32 class CheckFailed
: System
.Exception
{
33 public CheckFailed(string message
): base(message
) {}
36 public class BridgeTestObject
: WeakBase
, XRecursiveCall
, XBridgeTest2
38 private XComponentContext m_xContext
;
40 public BridgeTestObject( XComponentContext xContext
)
42 m_xContext
= xContext
;
44 public BridgeTestObject()
52 private ushort _ushort
;
56 private ulong _uhyper
;
58 private double _double
;
59 private String _string
;
60 private Object _xInterface
;
62 private TestEnum _testEnum
= TestEnum
.TEST
;
63 private TestElement
[] _testElements
= new TestElement
[0];
64 private TestDataElements _testDataElements
= new TestDataElements();
65 private int _nLastCallId
= 0;
66 private bool _bFirstCall
= true;
67 private bool _bSequenceOfCallTestPassed
= true;
69 private bool[] _arBool
;
70 private char[] _arChar
;
71 private byte[] _arByte
;
72 private short[]_arShort
;
73 private int[] _arLong
;
74 private long[] _arHyper
;
75 private UInt16
[] _arUShort
;
76 private UInt32
[] _arULong
;
77 private UInt64
[] _arUHyper
;
78 private string[] _arString
;
79 private float[] _arFloat
;
80 private double[] _arDouble
;
81 private TestEnum
[] _arEnum
;
82 private Object
[] _arObject
;
83 private int[][] _arLong2
;
84 private int[][][] _arLong3
;
87 // private int _raiseAttr1;
90 public void setValues(
106 TestElement
[] testElements
,
107 TestDataElements testDataElements
)
109 Debug
.WriteLine( "##### " + GetType().FullName
+ ".setValues:" + any
);
122 _testEnum
= testEnum
;
124 _xInterface
= xInterface
;
126 _testElements
= testElements
;
127 _testDataElements
= testDataElements
;
130 public TestDataElements
setValues2(
131 /*INOUT*/ref bool io_bool
,
132 /*INOUT*/ref char io_char
,
133 /*INOUT*/ref byte io_byte
,
134 /*INOUT*/ref short io_short
,
135 /*INOUT*/ref ushort io_ushort
,
136 /*INOUT*/ref int io_long
,
137 /*INOUT*/ref uint io_ulong
,
138 /*INOUT*/ref long io_hyper
,
139 /*INOUT*/ref ulong io_uhyper
,
140 /*INOUT*/ref float io_float
,
141 /*INOUT*/ref double io_double
,
142 /*INOUT*/ref TestEnum io_testEnum
,
143 /*INOUT*/ref String io_string
,
144 /*INOUT*/ref Object io_xInterface
,
145 /*INOUT*/ref Any io_any
,
146 /*INOUT*/ref TestElement
[] io_testElements
,
147 /*INOUT*/ref TestDataElements io_testDataElements
)
149 Debug
.WriteLine( "##### " + GetType().FullName
+ ".setValues2:" + io_any
);
162 _testEnum
= io_testEnum
;
164 _xInterface
= io_xInterface
;
166 _testElements
= (TestElement
[]) io_testElements
.Clone();
167 _testDataElements
= io_testDataElements
;
169 TestElement temp
= io_testElements
[ 0 ];
170 io_testElements
[ 0 ] = io_testElements
[ 1 ];
171 io_testElements
[ 1 ] = temp
;
173 return _testDataElements
;
176 public TestDataElements
getValues(
177 /*OUT*/out bool o_bool
,
178 /*OUT*/out char o_char
,
179 /*OUT*/out byte o_byte
,
180 /*OUT*/out short o_short
,
181 /*OUT*/out ushort o_ushort
,
182 /*OUT*/out int o_long
,
183 /*OUT*/out uint o_ulong
,
184 /*OUT*/out long o_hyper
,
185 /*OUT*/out ulong o_uhyper
,
186 /*OUT*/out float o_float
,
187 /*OUT*/out double o_double
,
188 /*OUT*/out TestEnum o_testEnum
,
189 /*OUT*/out String o_string
,
190 /*OUT*/out Object o_xInterface
,
191 /*OUT*/out Any o_any
,
192 /*OUT*/out TestElement
[] o_testElements
,
193 /*OUT*/out TestDataElements o_testDataElements
)
195 Debug
.WriteLine( "##### " + GetType().FullName
+ ".getValues" );
208 o_testEnum
= _testEnum
;
210 o_xInterface
= _xInterface
;
212 o_testElements
= _testElements
;
213 o_testDataElements
= _testDataElements
;
215 return _testDataElements
;
218 public SmallStruct
echoSmallStruct(/*[in]*/SmallStruct arg
)
223 public MediumStruct
echoMediumStruct(/*[in]*/MediumStruct arg
)
228 public BigStruct
echoBigStruct(/*[in]*/BigStruct arg
)
233 public TwoFloats
echoTwoFloats(/*[in]*/TwoFloats arg
)
238 public FourFloats
echoFourFloats(/*[in]*/FourFloats arg
)
243 public MixedFloatAndInteger
echoMixedFloatAndInteger(/*[in]*/MixedFloatAndInteger arg
)
248 public ThreeByteStruct
echoThreeByteStruct(/*[in]*/ThreeByteStruct arg
)
253 public int testPPCAlignment( long l1
, long l2
, int i1
, long l3
, int i2
)
258 public int testPPC64Alignment( double d1
, double d2
, double d3
, int i1
)
263 public double testTenDoubles( double d1
, double d2
, double d3
, double d4
, double d5
, double d6
, double d7
, double d8
, double d9
, double d10
)
265 return d1
+ d2
+ d3
+ d4
+ d5
+ d6
+ d7
+ d8
+ d9
+ d10
;
271 get { return _bool; }
272 set { _bool = value; }
276 get { return _byte; }
277 set { _byte = value; }
281 get { return _char; }
282 set { _char = value; }
286 get { return _short; }
287 set { _short = value; }
291 get { return _ushort; }
292 set { _ushort = value; }
296 get { return _long; }
297 set { _long = value; }
301 get { return _ulong; }
302 set { _ulong = value; }
306 get { return _hyper; }
307 set { _hyper = value; }
311 get { return _uhyper; }
312 set { _uhyper = value; }
316 get { return _float; }
317 set { _float = value; }
321 get { return _double; }
322 set { _double = value; }
326 get { return _testEnum; }
327 set { _testEnum = value; }
331 get { return _string; }
332 set { _string = value; }
334 public Object Interface
336 get { return _xInterface; }
337 set { _xInterface = value; }
343 Debug
.WriteLine( "##### " + GetType().FullName
+ ".Any" );
347 Debug
.WriteLine( "##### " + GetType().FullName
+ ".Any:" + value );
351 public TestElement
[] Sequence
353 get { return _testElements; }
354 set { _testElements = value; }
356 public TestDataElements Struct
358 get { return _testDataElements; }
359 set { _testDataElements = value; }
361 public Any
transportAny(Any
value)
365 public void call(int nCallId
, int nWaitMUSEC
)
367 Thread
.Sleep(nWaitMUSEC
/ 10000);
373 _bSequenceOfCallTestPassed
= _bSequenceOfCallTestPassed
&& (nCallId
> _nLastCallId
);
375 _nLastCallId
= nCallId
;
377 public void callOneway( int nCallId
, int nWaitMUSEC
)
379 Thread
.Sleep(nWaitMUSEC
/ 10000);
381 _bSequenceOfCallTestPassed
= _bSequenceOfCallTestPassed
&& (nCallId
> _nLastCallId
);
382 _nLastCallId
= nCallId
;
384 public bool sequenceOfCallTestPassed()
386 return _bSequenceOfCallTestPassed
;
388 [MethodImpl( MethodImplOptions
.Synchronized
)]
389 public void callRecursivly( XRecursiveCall xCall
, int nToCall
)
396 xCall
.callRecursivly(this , nToCall
);
400 [MethodImpl( MethodImplOptions
.Synchronized
)]
401 public void startRecursiveCall( XRecursiveCall xCall
, int nToCall
)
408 xCall
.callRecursivly( this , nToCall
);
414 public TestDataElements
raiseException(
415 short nArgumentPos
, String rMsg
, Object xContext
)
417 throw new IllegalArgumentException(rMsg
, xContext
, nArgumentPos
);
419 public void raiseRuntimeExceptionOneway( String rMsg
, Object xContext
)
421 throw new RuntimeException(rMsg
, xContext
);
424 private void dothrow( System
.Exception e
)
428 public int RuntimeException
433 dothrow( new RuntimeException(_string
, _xInterface
) );
436 catch (System
.Exception exc
)
441 set { throw new RuntimeException(_string, _xInterface); }
445 public int[][] setDim2(int[][] val
)
451 public int[][][] setDim3(int[][][] val
)
457 public Any
[] setSequenceAny(Any
[] val
)
463 public bool[] setSequenceBool(bool[] val
)
469 public byte[] setSequenceByte(byte[] val
)
475 public char[] setSequenceChar(char[] val
)
481 public short[] setSequenceShort(short[] val
)
487 public int[] setSequenceLong(int[] val
)
493 public long[] setSequenceHyper(long[] val
)
499 public float[] setSequenceFloat(float[] val
)
505 public double[] setSequenceDouble(double[] val
)
511 public TestEnum
[] setSequenceEnum(TestEnum
[] val
)
517 public UInt16
[] setSequenceUShort(UInt16
[] val
)
523 public UInt32
[] setSequenceULong(UInt32
[] val
)
529 public UInt64
[] setSequenceUHyper(UInt64
[] val
)
535 public Object
[] setSequenceXInterface(Object
[] val
)
541 public string[] setSequenceString(string[] val
)
547 public TestElement
[] setSequenceStruct(TestElement
[] val
)
553 public void setSequencesInOut(ref bool[] aSeqBoolean
,
556 ref short[] aSeqShort
,
557 ref UInt16
[] aSeqUShort
,
559 ref UInt32
[] aSeqULong
,
560 ref long[] aSeqHyper
,
561 ref UInt64
[] aSeqUHyper
,
562 ref float[] aSeqFloat
,
563 ref double[] aSeqDouble
,
564 ref TestEnum
[] aSeqTestEnum
,
565 ref string[] aSeqString
,
566 ref object[] aSeqXInterface
,
568 ref int[][] aSeqDim2
,
569 ref int[][][] aSeqDim3
)
571 _arBool
= aSeqBoolean
;
574 _arShort
= aSeqShort
;
575 _arUShort
= aSeqUShort
;
577 _arULong
= aSeqULong
;
578 _arHyper
= aSeqHyper
;
579 _arUHyper
= aSeqUHyper
;
580 _arFloat
= aSeqFloat
;
581 _arDouble
= aSeqDouble
;
582 _arEnum
= aSeqTestEnum
;
583 _arString
= aSeqString
;
584 _arObject
= aSeqXInterface
;
590 public void setSequencesOut(out bool[] aSeqBoolean
,
593 out short[] aSeqShort
,
594 out UInt16
[] aSeqUShort
,
596 out UInt32
[] aSeqULong
,
597 out long[] aSeqHyper
,
598 out UInt64
[] aSeqUHyper
,
599 out float[] aSeqFloat
,
600 out double[] aSeqDouble
,
601 out TestEnum
[] aSeqTestEnum
,
602 out string[] aSeqString
,
603 out object[] aSeqXInterface
,
605 out int[][] aSeqDim2
,
606 out int[][][] aSeqDim3
)
608 aSeqBoolean
= _arBool
;
611 aSeqShort
= _arShort
;
612 aSeqUShort
= _arUShort
;
614 aSeqULong
= _arULong
;
615 aSeqHyper
= _arHyper
;
616 aSeqUHyper
= _arUHyper
;
617 aSeqFloat
= _arFloat
;
618 aSeqDouble
= _arDouble
;
619 aSeqTestEnum
= _arEnum
;
620 aSeqString
= _arString
;
621 aSeqXInterface
= _arObject
;
628 /* Attention: Debugging this code (probably in mixed mode) may lead to exceptions
629 * which do not occur when running normally (Visual Studio 2003)
631 public void testConstructorsService(XComponentContext context
)
633 Constructors
.create1(context
,
635 0x80, // -128 in C++,
649 new byte[] { 0x80}
, // in C++ the value is compared with SAL_MIN_INT8 which is -128
650 new short[] { Int16.MinValue }
,
651 new UInt16
[] { UInt16.MaxValue }
,
652 new Int32
[] {Int32.MinValue}
,
653 new UInt32
[] { UInt32.MaxValue }
,
654 new long[] { Int64.MinValue }
,
655 new UInt64
[] { UInt64.MaxValue }
,
656 new float[] { 0.123f }
,
657 new double[] { 0.456 }
,
659 new string[] { "test" }
,
660 new Type
[] { typeof(Any) }
,
661 new Any
[] { new Any(true) }
,
662 new bool[][] { new bool[] { true }
},
663 new Any
[][] { new Any[] { new Any(true) }
},
664 new TestEnum
[] { TestEnum.TWO }
,
665 new TestStruct
[] { new TestStruct(10) }
,
666 new TestPolyStruct
[] { new TestPolyStruct(true) }
,
667 new TestPolyStruct
[] { new TestPolyStruct(new Any(true)) }
,
668 new object[] { null }
,
671 new TestPolyStruct(true),
672 new TestPolyStruct(new Any(true)),
676 Constructors
.create2(context
,
678 new Any((System
.Byte
) 0x80),
679 new Any(Int16
.MinValue
),
680 new Any(UInt16
.MaxValue
),
681 new Any(Int32
.MinValue
),
682 new Any(UInt32
.MaxValue
),
683 new Any(Int64
.MinValue
),
684 new Any(UInt64
.MaxValue
),
689 new Any(typeof(Any
)),
691 new Any(typeof(bool[]), new bool[] { true }
),
692 new Any(typeof(byte[]), new byte[] { (System.Byte) 0x80}
),
693 new Any(typeof(short[]), new short[] { Int16.MinValue }
),
694 new Any(typeof(UInt16
[]), new UInt16
[] { UInt16.MaxValue }
),
695 new Any(typeof(int[]), new int[] { Int32.MinValue }
),
696 new Any(typeof(UInt32
[]), new UInt32
[] { UInt32.MaxValue }
),
697 new Any(typeof(long[]), new long[] { Int64.MinValue }
),
698 new Any(typeof(UInt64
[]), new UInt64
[] { UInt64.MaxValue }
),
699 new Any(typeof(float[]), new float[] { 0.123f }
),
700 new Any(typeof(double[]), new double[] { 0.456 }
),
701 new Any(typeof(char[]), new char[] { 'X' }
),
702 new Any(typeof(string[]), new string[] { "test" }
),
703 new Any(typeof(Type
[]), new Type
[] { typeof(Any) }
),
704 new Any(typeof(Any
[]), new Any
[] { new Any(true) }
),
705 new Any(typeof(bool[][]), new bool[][] { new bool[] { true }
}),
707 typeof(Any
[][]), new Any
[][] { new Any[] { new Any(true) }
}),
708 new Any(typeof(TestEnum
[]), new TestEnum
[] { TestEnum.TWO }
),
710 typeof(TestStruct
[]), new TestStruct
[] { new TestStruct(10) }
),
712 PolymorphicType
.GetType(
713 typeof(TestPolyStruct
[]),
714 "unoidl.test.testtools.bridgetest.TestPolyStruct<System.Boolean>[]"),
715 new TestPolyStruct
[] { new TestPolyStruct(true) }
) ,
717 PolymorphicType
.GetType(
718 typeof(TestPolyStruct
[]),
719 "unoidl.test.testtools.bridgetest.TestPolyStruct<uno.Any>[]"),
720 new TestPolyStruct
[] { new TestPolyStruct(new Any(true)) }
),
721 new Any(typeof(object[])/*TODO*/, new object[] { null }
),
722 new Any(typeof(TestEnum
), TestEnum
.TWO
),
723 new Any(typeof(TestStruct
), new TestStruct(10)),
725 PolymorphicType
.GetType(
726 typeof(TestPolyStruct
),
727 "unoidl.test.testtools.bridgetest.TestPolyStruct<System.Boolean>"),
728 new TestPolyStruct(true)),
730 PolymorphicType
.GetType(
731 typeof(TestPolyStruct
),
732 "unoidl.test.testtools.bridgetest.TestPolyStruct<uno.Any>"),
733 new TestPolyStruct(new Any(true))),
734 new Any(typeof(object), null)
738 XMultiBase1 xMulti
= Constructors2
.create1(
740 new TestPolyStruct(typeof(int)),
741 new TestPolyStruct(new Any(true)),
742 new TestPolyStruct(true),
743 new TestPolyStruct((Byte
) 0x80),
744 new TestPolyStruct(Int16
.MinValue
),
745 new TestPolyStruct(Int32
.MinValue
),
746 new TestPolyStruct(Int64
.MinValue
),
747 new TestPolyStruct('X'),
748 new TestPolyStruct("test"),
749 new TestPolyStruct(0.123f
),
750 new TestPolyStruct(0.456d
),
751 new TestPolyStruct(new object()),
752 new TestPolyStruct(new uno
.util
.WeakComponentBase()),
753 new TestPolyStruct(TestEnum
.TWO
),
754 new TestPolyStruct(new TestPolyStruct2('X', new Any(true))),
755 new TestPolyStruct(new TestPolyStruct2(new TestPolyStruct2('X', new Any(true)), "test")),
756 new TestPolyStruct2("test", new TestPolyStruct2('X', new TestPolyStruct(new Any(true)))),
757 new TestPolyStruct2( new TestPolyStruct2('X', new Any(true)), new TestPolyStruct('X')),
758 new TestPolyStruct(new Type
[] { typeof(int)}
),
759 new TestPolyStruct(new Any
[] { new Any(true) }
),
760 new TestPolyStruct(new bool[] {true}
),
761 new TestPolyStruct(new byte[] {0x80}
),
762 new TestPolyStruct(new short[] {Int16.MinValue}
),
763 new TestPolyStruct(new int[] {Int32.MinValue}
),
764 new TestPolyStruct(new long[] {Int64.MinValue}
),
765 new TestPolyStruct(new char[] {'X'}
),
766 new TestPolyStruct(new string[] {"test"}
),
767 new TestPolyStruct(new float[] {0.123f}
),
768 new TestPolyStruct(new double[] {0.456d}
),
769 new TestPolyStruct(new object[] {new object()}
),
770 new TestPolyStruct(new unoidl
.com
.sun
.star
.lang
.XComponent
[] {new uno.util.WeakComponentBase()}
),
771 new TestPolyStruct(new TestEnum
[] {TestEnum.TWO}
),
772 new TestPolyStruct(new TestPolyStruct2
[] {new TestPolyStruct2('X', new Any[] {new Any(true)}
)}),
773 new TestPolyStruct(new TestPolyStruct2
[] {
774 new TestPolyStruct2(new TestPolyStruct('X'), new Any
[] {new Any(true)}
)}),
775 new TestPolyStruct(new int[][] { new int[] {Int32.MinValue}
}),
776 new TestPolyStruct
[]{ new TestPolyStruct(Int32.MinValue)}
,
777 new TestPolyStruct
[]{new TestPolyStruct(new TestPolyStruct2('X', new Any(true)))}
,
778 new TestPolyStruct
[]{new TestPolyStruct(new TestPolyStruct2(new TestPolyStruct2('X', new Any(true)), "test"))}
,
779 new TestPolyStruct2
[]{new TestPolyStruct2("test", new TestPolyStruct2('X', new TestPolyStruct(new Any(true))))}
,
780 new TestPolyStruct2
[]{new TestPolyStruct2(new TestPolyStruct2('X', new Any(true)),new TestPolyStruct('X'))}
,
781 new TestPolyStruct
[][]{new TestPolyStruct[]{new TestPolyStruct('X')}}
,
782 new TestPolyStruct
[][]{new TestPolyStruct[]{new TestPolyStruct(new TestPolyStruct2('X', new Any(true)))}}
,
783 new TestPolyStruct
[][]{new TestPolyStruct[] {new TestPolyStruct(new TestPolyStruct2(new TestPolyStruct2('X',new Any(true)), "test"))}}
,
784 new TestPolyStruct2
[][]{new TestPolyStruct2[]{new TestPolyStruct2("test", new TestPolyStruct2('X',new TestPolyStruct(new Any(true))))}}
,
785 new TestPolyStruct2
[][]{new TestPolyStruct2[]{new TestPolyStruct2(new TestPolyStruct2('X',new Any(true)),new TestPolyStruct('X'))}}
788 //test the returned interface
794 public XCurrentContextChecker
getCurrentContextChecker()
796 return null; //TODO: not yet tested in CLI UNO
799 public TestPolyStruct
transportPolyBoolean(/*[in]*/TestPolyStruct arg
)
804 public void transportPolyHyper(/*[in][out]*/ ref TestPolyStruct arg
)
808 public void transportPolySequence(TestPolyStruct arg1
,
809 out TestPolyStruct arg2
)
814 public TestPolyStruct
getNullPolyBadEnum()
816 return new TestPolyStruct(unoidl
.test
.testtools
.bridgetest
.TestBadEnum
.M
);
819 public TestPolyStruct
getNullPolyLong()
821 return new TestPolyStruct();
824 public TestPolyStruct
getNullPolyString()
826 return new TestPolyStruct();
829 public TestPolyStruct
getNullPolyType()
831 return new TestPolyStruct();
834 public TestPolyStruct
getNullPolyAny()
836 return new TestPolyStruct();
839 public TestPolyStruct
getNullPolySequence()
841 return new TestPolyStruct();
844 public TestPolyStruct
getNullPolyEnum()
846 return new TestPolyStruct();
849 public TestPolyStruct
getNullPolyStruct()
851 return new TestPolyStruct();
854 public TestPolyStruct
getNullPolyInterface()
856 return new TestPolyStruct();
859 public XMulti
getMulti()
861 return new testtools
.bridgetest
.cli_cs
.Multi();
864 private static void checkEqual(int value, int argument
) {
865 if (argument
!= value) {
866 throw new CheckFailed(value + " != " + argument
);
870 private static void checkEqual(double value, double argument
) {
871 if (argument
!= value) {
872 throw new CheckFailed(value + " != " + argument
);
876 private static void checkEqual(string value, string argument
) {
877 if (argument
!= value) {
878 throw new CheckFailed(value + " != " + argument
);
882 public string testMulti(XMulti multi
)
885 checkEqual(0.0, multi
.att1
);
887 checkEqual(0.1, multi
.att1
);
888 checkEqual(11 * 1, multi
.fn11(1));
889 checkEqual("12" + "abc", multi
.fn12("abc"));
890 checkEqual(21 * 2, multi
.fn21(2));
891 checkEqual("22" + "de", multi
.fn22("de"));
892 checkEqual(0.0, multi
.att3
);
894 checkEqual(0.3, multi
.att3
);
895 checkEqual(31 * 3, multi
.fn31(3));
896 checkEqual("32" + "f", multi
.fn32("f"));
897 checkEqual(33, multi
.fn33());
898 checkEqual(41 * 4, multi
.fn41(4));
899 checkEqual(61 * 6, multi
.fn61(6));
900 checkEqual("62" + "", multi
.fn62(""));
901 checkEqual(71 * 7, multi
.fn71(7));
902 checkEqual("72" + "g", multi
.fn72("g"));
903 checkEqual(73, multi
.fn73());
904 } catch (CheckFailed f
) {
910 public int RaiseAttr1
912 get { throw new RuntimeException(); }
913 set { throw new IllegalArgumentException(); }
916 public int RaiseAttr2
918 get { throw new IllegalArgumentException(); }
919 set { throw new IllegalArgumentException(); }