1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: cli_cs_testobj.cs,v $
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 ************************************************************************/
32 using System
.Diagnostics
;
33 using System
.Threading
;
34 using System
.Runtime
.CompilerServices
;
37 using unoidl
.com
.sun
.star
.uno
;
38 using unoidl
.com
.sun
.star
.lang
;
39 using unoidl
.test
.testtools
.bridgetest
;
44 class CheckFailed
: System
.Exception
{
45 public CheckFailed(string message
): base(message
) {}
48 public class BridgeTestObject
: WeakBase
, XRecursiveCall
, XBridgeTest2
50 private XComponentContext m_xContext
;
52 public BridgeTestObject( XComponentContext xContext
)
54 m_xContext
= xContext
;
56 public BridgeTestObject()
64 private ushort _ushort
;
68 private ulong _uhyper
;
70 private double _double
;
71 private String _string
;
72 private Object _xInterface
;
74 private TestEnum _testEnum
= TestEnum
.TEST
;
75 private TestElement
[] _testElements
= new TestElement
[0];
76 private TestDataElements _testDataElements
= new TestDataElements();
77 private int _nLastCallId
= 0;
78 private bool _bFirstCall
= true;
79 private bool _bSequenceOfCallTestPassed
= true;
81 private bool[] _arBool
;
82 private char[] _arChar
;
83 private byte[] _arByte
;
84 private short[]_arShort
;
85 private int[] _arLong
;
86 private long[] _arHyper
;
87 private UInt16
[] _arUShort
;
88 private UInt32
[] _arULong
;
89 private UInt64
[] _arUHyper
;
90 private string[] _arString
;
91 private float[] _arFloat
;
92 private double[] _arDouble
;
93 private TestEnum
[] _arEnum
;
94 private Object
[] _arObject
;
95 private int[][] _arLong2
;
96 private int[][][] _arLong3
;
99 // private int _raiseAttr1;
102 public void setValues(
118 TestElement
[] testElements
,
119 TestDataElements testDataElements
)
121 Debug
.WriteLine( "##### " + GetType().FullName
+ ".setValues:" + any
);
134 _testEnum
= testEnum
;
136 _xInterface
= xInterface
;
138 _testElements
= testElements
;
139 _testDataElements
= testDataElements
;
142 public TestDataElements
setValues2(
143 /*INOUT*/ref bool io_bool
,
144 /*INOUT*/ref char io_char
,
145 /*INOUT*/ref byte io_byte
,
146 /*INOUT*/ref short io_short
,
147 /*INOUT*/ref ushort io_ushort
,
148 /*INOUT*/ref int io_long
,
149 /*INOUT*/ref uint io_ulong
,
150 /*INOUT*/ref long io_hyper
,
151 /*INOUT*/ref ulong io_uhyper
,
152 /*INOUT*/ref float io_float
,
153 /*INOUT*/ref double io_double
,
154 /*INOUT*/ref TestEnum io_testEnum
,
155 /*INOUT*/ref String io_string
,
156 /*INOUT*/ref Object io_xInterface
,
157 /*INOUT*/ref Any io_any
,
158 /*INOUT*/ref TestElement
[] io_testElements
,
159 /*INOUT*/ref TestDataElements io_testDataElements
)
161 Debug
.WriteLine( "##### " + GetType().FullName
+ ".setValues2:" + io_any
);
174 _testEnum
= io_testEnum
;
176 _xInterface
= io_xInterface
;
178 _testElements
= (TestElement
[]) io_testElements
.Clone();
179 _testDataElements
= io_testDataElements
;
181 TestElement temp
= io_testElements
[ 0 ];
182 io_testElements
[ 0 ] = io_testElements
[ 1 ];
183 io_testElements
[ 1 ] = temp
;
185 return _testDataElements
;
188 public TestDataElements
getValues(
189 /*OUT*/out bool o_bool
,
190 /*OUT*/out char o_char
,
191 /*OUT*/out byte o_byte
,
192 /*OUT*/out short o_short
,
193 /*OUT*/out ushort o_ushort
,
194 /*OUT*/out int o_long
,
195 /*OUT*/out uint o_ulong
,
196 /*OUT*/out long o_hyper
,
197 /*OUT*/out ulong o_uhyper
,
198 /*OUT*/out float o_float
,
199 /*OUT*/out double o_double
,
200 /*OUT*/out TestEnum o_testEnum
,
201 /*OUT*/out String o_string
,
202 /*OUT*/out Object o_xInterface
,
203 /*OUT*/out Any o_any
,
204 /*OUT*/out TestElement
[] o_testElements
,
205 /*OUT*/out TestDataElements o_testDataElements
)
207 Debug
.WriteLine( "##### " + GetType().FullName
+ ".getValues" );
220 o_testEnum
= _testEnum
;
222 o_xInterface
= _xInterface
;
224 o_testElements
= _testElements
;
225 o_testDataElements
= _testDataElements
;
227 return _testDataElements
;
233 get { return _bool; }
234 set { _bool = value; }
238 get { return _byte; }
239 set { _byte = value; }
243 get { return _char; }
244 set { _char = value; }
248 get { return _short; }
249 set { _short = value; }
253 get { return _ushort; }
254 set { _ushort = value; }
258 get { return _long; }
259 set { _long = value; }
263 get { return _ulong; }
264 set { _ulong = value; }
268 get { return _hyper; }
269 set { _hyper = value; }
273 get { return _uhyper; }
274 set { _uhyper = value; }
278 get { return _float; }
279 set { _float = value; }
283 get { return _double; }
284 set { _double = value; }
288 get { return _testEnum; }
289 set { _testEnum = value; }
293 get { return _string; }
294 set { _string = value; }
296 public Object Interface
298 get { return _xInterface; }
299 set { _xInterface = value; }
305 Debug
.WriteLine( "##### " + GetType().FullName
+ ".Any" );
309 Debug
.WriteLine( "##### " + GetType().FullName
+ ".Any:" + value );
313 public TestElement
[] Sequence
315 get { return _testElements; }
316 set { _testElements = value; }
318 public TestDataElements Struct
320 get { return _testDataElements; }
321 set { _testDataElements = value; }
323 public Any
transportAny(Any
value)
327 public void call(int nCallId
, int nWaitMUSEC
)
329 Thread
.Sleep(nWaitMUSEC
/ 10000);
335 _bSequenceOfCallTestPassed
= _bSequenceOfCallTestPassed
&& (nCallId
> _nLastCallId
);
337 _nLastCallId
= nCallId
;
339 public void callOneway( int nCallId
, int nWaitMUSEC
)
341 Thread
.Sleep(nWaitMUSEC
/ 10000);
343 _bSequenceOfCallTestPassed
= _bSequenceOfCallTestPassed
&& (nCallId
> _nLastCallId
);
344 _nLastCallId
= nCallId
;
346 public bool sequenceOfCallTestPassed()
348 return _bSequenceOfCallTestPassed
;
350 [MethodImpl( MethodImplOptions
.Synchronized
)]
351 public void callRecursivly( XRecursiveCall xCall
, int nToCall
)
358 xCall
.callRecursivly(this , nToCall
);
362 [MethodImpl( MethodImplOptions
.Synchronized
)]
363 public void startRecursiveCall( XRecursiveCall xCall
, int nToCall
)
370 xCall
.callRecursivly( this , nToCall
);
376 public TestDataElements
raiseException(
377 short nArgumentPos
, String rMsg
, Object xContext
)
379 throw new IllegalArgumentException(rMsg
, xContext
, nArgumentPos
);
381 public void raiseRuntimeExceptionOneway( String rMsg
, Object xContext
)
383 throw new RuntimeException(rMsg
, xContext
);
386 private void dothrow( System
.Exception e
)
390 public int RuntimeException
395 dothrow( new RuntimeException(_string
, _xInterface
) );
398 catch (System
.Exception exc
)
403 set { throw new RuntimeException(_string, _xInterface); }
407 public int[][] setDim2(int[][] val
)
413 public int[][][] setDim3(int[][][] val
)
419 public Any
[] setSequenceAny(Any
[] val
)
425 public bool[] setSequenceBool(bool[] val
)
431 public byte[] setSequenceByte(byte[] val
)
437 public char[] setSequenceChar(char[] val
)
443 public short[] setSequenceShort(short[] val
)
449 public int[] setSequenceLong(int[] val
)
455 public long[] setSequenceHyper(long[] val
)
461 public float[] setSequenceFloat(float[] val
)
467 public double[] setSequenceDouble(double[] val
)
473 public TestEnum
[] setSequenceEnum(TestEnum
[] val
)
479 public UInt16
[] setSequenceUShort(UInt16
[] val
)
485 public UInt32
[] setSequenceULong(UInt32
[] val
)
491 public UInt64
[] setSequenceUHyper(UInt64
[] val
)
497 public Object
[] setSequenceXInterface(Object
[] val
)
503 public string[] setSequenceString(string[] val
)
509 public TestElement
[] setSequenceStruct(TestElement
[] val
)
515 public void setSequencesInOut(ref bool[] aSeqBoolean
,
518 ref short[] aSeqShort
,
519 ref UInt16
[] aSeqUShort
,
521 ref UInt32
[] aSeqULong
,
522 ref long[] aSeqHyper
,
523 ref UInt64
[] aSeqUHyper
,
524 ref float[] aSeqFloat
,
525 ref double[] aSeqDouble
,
526 ref TestEnum
[] aSeqTestEnum
,
527 ref string[] aSeqString
,
528 ref object[] aSeqXInterface
,
530 ref int[][] aSeqDim2
,
531 ref int[][][] aSeqDim3
)
533 _arBool
= aSeqBoolean
;
536 _arShort
= aSeqShort
;
537 _arUShort
= aSeqUShort
;
539 _arULong
= aSeqULong
;
540 _arHyper
= aSeqHyper
;
541 _arUHyper
= aSeqUHyper
;
542 _arFloat
= aSeqFloat
;
543 _arDouble
= aSeqDouble
;
544 _arEnum
= aSeqTestEnum
;
545 _arString
= aSeqString
;
546 _arObject
= aSeqXInterface
;
552 public void setSequencesOut(out bool[] aSeqBoolean
,
555 out short[] aSeqShort
,
556 out UInt16
[] aSeqUShort
,
558 out UInt32
[] aSeqULong
,
559 out long[] aSeqHyper
,
560 out UInt64
[] aSeqUHyper
,
561 out float[] aSeqFloat
,
562 out double[] aSeqDouble
,
563 out TestEnum
[] aSeqTestEnum
,
564 out string[] aSeqString
,
565 out object[] aSeqXInterface
,
567 out int[][] aSeqDim2
,
568 out int[][][] aSeqDim3
)
570 aSeqBoolean
= _arBool
;
573 aSeqShort
= _arShort
;
574 aSeqUShort
= _arUShort
;
576 aSeqULong
= _arULong
;
577 aSeqHyper
= _arHyper
;
578 aSeqUHyper
= _arUHyper
;
579 aSeqFloat
= _arFloat
;
580 aSeqDouble
= _arDouble
;
581 aSeqTestEnum
= _arEnum
;
582 aSeqString
= _arString
;
583 aSeqXInterface
= _arObject
;
590 /* Attention: Debugging this code (probably in mixed mode) may lead to exceptions
591 * which do not occur when running normally (Visual Studio 2003)
593 public void testConstructorsService(XComponentContext context
)
595 Constructors
.create1(context
,
597 0x80, // -128 in C++,
611 new byte[] { 0x80}
, // in C++ the value is compared with SAL_MIN_INT8 which is -128
612 new short[] { Int16.MinValue }
,
613 new UInt16
[] { UInt16.MaxValue }
,
614 new Int32
[] {Int32.MinValue}
,
615 new UInt32
[] { UInt32.MaxValue }
,
616 new long[] { Int64.MinValue }
,
617 new UInt64
[] { UInt64.MaxValue }
,
618 new float[] { 0.123f }
,
619 new double[] { 0.456 }
,
621 new string[] { "test" }
,
622 new Type
[] { typeof(Any) }
,
623 new Any
[] { new Any(true) }
,
624 new bool[][] { new bool[] { true }
},
625 new Any
[][] { new Any[] { new Any(true) }
},
626 new TestEnum
[] { TestEnum.TWO }
,
627 new TestStruct
[] { new TestStruct(10) }
,
628 new TestPolyStruct
[] { new TestPolyStruct(true) }
,
629 new TestPolyStruct
[] { new TestPolyStruct(new Any(true)) }
,
630 new object[] { null }
,
633 new TestPolyStruct(true),
634 new TestPolyStruct(new Any(true)),
638 Constructors
.create2(context
,
640 new Any((System
.Byte
) 0x80),
641 new Any(Int16
.MinValue
),
642 new Any(UInt16
.MaxValue
),
643 new Any(Int32
.MinValue
),
644 new Any(UInt32
.MaxValue
),
645 new Any(Int64
.MinValue
),
646 new Any(UInt64
.MaxValue
),
651 new Any(typeof(Any
)),
653 new Any(typeof(bool[]), new bool[] { true }
),
654 new Any(typeof(byte[]), new byte[] { (System.Byte) 0x80}
),
655 new Any(typeof(short[]), new short[] { Int16.MinValue }
),
656 new Any(typeof(UInt16
[]), new UInt16
[] { UInt16.MaxValue }
),
657 new Any(typeof(int[]), new int[] { Int32.MinValue }
),
658 new Any(typeof(UInt32
[]), new UInt32
[] { UInt32.MaxValue }
),
659 new Any(typeof(long[]), new long[] { Int64.MinValue }
),
660 new Any(typeof(UInt64
[]), new UInt64
[] { UInt64.MaxValue }
),
661 new Any(typeof(float[]), new float[] { 0.123f }
),
662 new Any(typeof(double[]), new double[] { 0.456 }
),
663 new Any(typeof(char[]), new char[] { 'X' }
),
664 new Any(typeof(string[]), new string[] { "test" }
),
665 new Any(typeof(Type
[]), new Type
[] { typeof(Any) }
),
666 new Any(typeof(Any
[]), new Any
[] { new Any(true) }
),
667 new Any(typeof(bool[][]), new bool[][] { new bool[] { true }
}),
669 typeof(Any
[][]), new Any
[][] { new Any[] { new Any(true) }
}),
670 new Any(typeof(TestEnum
[]), new TestEnum
[] { TestEnum.TWO }
),
672 typeof(TestStruct
[]), new TestStruct
[] { new TestStruct(10) }
),
674 PolymorphicType
.GetType(
675 typeof(TestPolyStruct
[]),
676 "unoidl.test.testtools.bridgetest.TestPolyStruct<System.Boolean>[]"),
677 new TestPolyStruct
[] { new TestPolyStruct(true) }
) ,
679 PolymorphicType
.GetType(
680 typeof(TestPolyStruct
[]),
681 "unoidl.test.testtools.bridgetest.TestPolyStruct<uno.Any>[]"),
682 new TestPolyStruct
[] { new TestPolyStruct(new Any(true)) }
),
683 new Any(typeof(object[])/*TODO*/, new object[] { null }
),
684 new Any(typeof(TestEnum
), TestEnum
.TWO
),
685 new Any(typeof(TestStruct
), new TestStruct(10)),
687 PolymorphicType
.GetType(
688 typeof(TestPolyStruct
),
689 "unoidl.test.testtools.bridgetest.TestPolyStruct<System.Boolean>"),
690 new TestPolyStruct(true)),
692 PolymorphicType
.GetType(
693 typeof(TestPolyStruct
),
694 "unoidl.test.testtools.bridgetest.TestPolyStruct<uno.Any>"),
695 new TestPolyStruct(new Any(true))),
696 new Any(typeof(object), null)
700 XMultiBase1 xMulti
= Constructors2
.create1(
702 new TestPolyStruct(typeof(int)),
703 new TestPolyStruct(new Any(true)),
704 new TestPolyStruct(true),
705 new TestPolyStruct((Byte
) 0x80),
706 new TestPolyStruct(Int16
.MinValue
),
707 new TestPolyStruct(Int32
.MinValue
),
708 new TestPolyStruct(Int64
.MinValue
),
709 new TestPolyStruct('X'),
710 new TestPolyStruct("test"),
711 new TestPolyStruct(0.123f
),
712 new TestPolyStruct(0.456d
),
713 new TestPolyStruct(new object()),
714 new TestPolyStruct(new uno
.util
.WeakComponentBase()),
715 new TestPolyStruct(TestEnum
.TWO
),
716 new TestPolyStruct(new TestPolyStruct2('X', new Any(true))),
717 new TestPolyStruct(new TestPolyStruct2(new TestPolyStruct2('X', new Any(true)), "test")),
718 new TestPolyStruct2("test", new TestPolyStruct2('X', new TestPolyStruct(new Any(true)))),
719 new TestPolyStruct2( new TestPolyStruct2('X', new Any(true)), new TestPolyStruct('X')),
720 new TestPolyStruct(new Type
[] { typeof(int)}
),
721 new TestPolyStruct(new Any
[] { new Any(true) }
),
722 new TestPolyStruct(new bool[] {true}
),
723 new TestPolyStruct(new byte[] {0x80}
),
724 new TestPolyStruct(new short[] {Int16.MinValue}
),
725 new TestPolyStruct(new int[] {Int32.MinValue}
),
726 new TestPolyStruct(new long[] {Int64.MinValue}
),
727 new TestPolyStruct(new char[] {'X'}
),
728 new TestPolyStruct(new string[] {"test"}
),
729 new TestPolyStruct(new float[] {0.123f}
),
730 new TestPolyStruct(new double[] {0.456d}
),
731 new TestPolyStruct(new object[] {new object()}
),
732 new TestPolyStruct(new unoidl
.com
.sun
.star
.lang
.XComponent
[] {new uno.util.WeakComponentBase()}
),
733 new TestPolyStruct(new TestEnum
[] {TestEnum.TWO}
),
734 new TestPolyStruct(new TestPolyStruct2
[] {new TestPolyStruct2('X', new Any[] {new Any(true)}
)}),
735 new TestPolyStruct(new TestPolyStruct2
[] {
736 new TestPolyStruct2(new TestPolyStruct('X'), new Any
[] {new Any(true)}
)}),
737 new TestPolyStruct(new int[][] { new int[] {Int32.MinValue}
}),
738 new TestPolyStruct
[]{ new TestPolyStruct(Int32.MinValue)}
,
739 new TestPolyStruct
[]{new TestPolyStruct(new TestPolyStruct2('X', new Any(true)))}
,
740 new TestPolyStruct
[]{new TestPolyStruct(new TestPolyStruct2(new TestPolyStruct2('X', new Any(true)), "test"))}
,
741 new TestPolyStruct2
[]{new TestPolyStruct2("test", new TestPolyStruct2('X', new TestPolyStruct(new Any(true))))}
,
742 new TestPolyStruct2
[]{new TestPolyStruct2(new TestPolyStruct2('X', new Any(true)),new TestPolyStruct('X'))}
,
743 new TestPolyStruct
[][]{new TestPolyStruct[]{new TestPolyStruct('X')}}
,
744 new TestPolyStruct
[][]{new TestPolyStruct[]{new TestPolyStruct(new TestPolyStruct2('X', new Any(true)))}}
,
745 new TestPolyStruct
[][]{new TestPolyStruct[] {new TestPolyStruct(new TestPolyStruct2(new TestPolyStruct2('X',new Any(true)), "test"))}}
,
746 new TestPolyStruct2
[][]{new TestPolyStruct2[]{new TestPolyStruct2("test", new TestPolyStruct2('X',new TestPolyStruct(new Any(true))))}}
,
747 new TestPolyStruct2
[][]{new TestPolyStruct2[]{new TestPolyStruct2(new TestPolyStruct2('X',new Any(true)),new TestPolyStruct('X'))}}
750 //test the returned interface
756 public XCurrentContextChecker
getCurrentContextChecker()
758 return null; //TODO: not yet tested in CLI UNO
761 public TestPolyStruct
transportPolyBoolean(/*[in]*/TestPolyStruct arg
)
766 public void transportPolyHyper(/*[in][out]*/ ref TestPolyStruct arg
)
770 public void transportPolySequence(TestPolyStruct arg1
,
771 out TestPolyStruct arg2
)
776 public TestPolyStruct
getNullPolyBadEnum()
778 return new TestPolyStruct(unoidl
.test
.testtools
.bridgetest
.TestBadEnum
.M
);
781 public TestPolyStruct
getNullPolyLong()
783 return new TestPolyStruct();
786 public TestPolyStruct
getNullPolyString()
788 return new TestPolyStruct();
791 public TestPolyStruct
getNullPolyType()
793 return new TestPolyStruct();
796 public TestPolyStruct
getNullPolyAny()
798 return new TestPolyStruct();
801 public TestPolyStruct
getNullPolySequence()
803 return new TestPolyStruct();
806 public TestPolyStruct
getNullPolyEnum()
808 return new TestPolyStruct();
811 public TestPolyStruct
getNullPolyStruct()
813 return new TestPolyStruct();
816 public TestPolyStruct
getNullPolyInterface()
818 return new TestPolyStruct();
821 public XMulti
getMulti()
823 return new testtools
.bridgetest
.cli_cs
.Multi();
826 private static void checkEqual(int value, int argument
) {
827 if (argument
!= value) {
828 throw new CheckFailed(value + " != " + argument
);
832 private static void checkEqual(double value, double argument
) {
833 if (argument
!= value) {
834 throw new CheckFailed(value + " != " + argument
);
838 private static void checkEqual(string value, string argument
) {
839 if (argument
!= value) {
840 throw new CheckFailed(value + " != " + argument
);
844 public string testMulti(XMulti multi
)
847 checkEqual(0.0, multi
.att1
);
849 checkEqual(0.1, multi
.att1
);
850 checkEqual(11 * 1, multi
.fn11(1));
851 checkEqual("12" + "abc", multi
.fn12("abc"));
852 checkEqual(21 * 2, multi
.fn21(2));
853 checkEqual("22" + "de", multi
.fn22("de"));
854 checkEqual(0.0, multi
.att3
);
856 checkEqual(0.3, multi
.att3
);
857 checkEqual(31 * 3, multi
.fn31(3));
858 checkEqual("32" + "f", multi
.fn32("f"));
859 checkEqual(33, multi
.fn33());
860 checkEqual(41 * 4, multi
.fn41(4));
861 checkEqual(61 * 6, multi
.fn61(6));
862 checkEqual("62" + "", multi
.fn62(""));
863 checkEqual(71 * 7, multi
.fn71(7));
864 checkEqual("72" + "g", multi
.fn72("g"));
865 checkEqual(73, multi
.fn73());
866 } catch (CheckFailed f
) {
872 public int RaiseAttr1
874 get { throw new RuntimeException(); }
875 set { throw new IllegalArgumentException(); }
878 public int RaiseAttr2
880 get { throw new IllegalArgumentException(); }
881 set { throw new IllegalArgumentException(); }