1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
23 #using <cli_basetypes.dll>
24 #using <cli_uretypes.dll>
26 #using <cli_types_bridgetest.dll>
29 using namespace System
;
30 using namespace System::Diagnostics
;
31 using namespace System::Reflection
;
32 using namespace System::Threading
;
34 using namespace uno::util
;
35 using namespace unoidl::com::sun::star::uno
;
36 using namespace unoidl::com::sun::star::lang
;
37 using namespace unoidl::test::testtools::bridgetest
;
40 public __gc __interface MyInterface
45 namespace cpp_bridgetest
47 __gc
class ORecursiveCall
: public WeakBase
, public XRecursiveCall
50 void callRecursivly(XRecursiveCall
* xCall
, int nToCall
)
59 xCall
->callRecursivly(this, nToCall
);
71 public __gc
class Constants
74 static String
* STRING_TEST_CONSTANT
= new String(S
"\" paco\' chorizo\\\' \"\'");
77 public __gc
class BridgeTest
: public WeakBase
, public XMain
79 static bool compareData(Object
* val1
, Object
* val2
)
81 if (val1
== 0 && val2
== 0 || val1
== val2
)
83 if ((val1
== 0 && val2
!= 0) ||
84 (val1
!= 0 && val2
== 0) || val1
->GetType() != val2
->GetType())
88 Type
* t1
= val1
->GetType();
92 ret
= compareSequence(static_cast<Array
*>(val1
),
93 static_cast<Array
*>(val2
));
96 else if (t1
== __typeof(String
))
98 ret
= val1
->Equals(val2
);
100 // Interface implementation
101 else if (t1
->GetInterfaces()->Length
> 0 && ! t1
->IsValueType
)
106 else if ( ! t1
->IsValueType
)
108 ret
= compareStruct(val1
, val2
);
110 else if (t1
== __typeof(Any
))
114 ret
= a1
.Type
== a2
.Type
&& compareData(a1
.Value
, a2
.Value
);
118 //Any, enum, int, bool char, float, double etc.
119 ret
= val1
->Equals(val2
);
124 // Arrays have only one dimension
125 static bool compareSequence(Array
* ar1
, Array
* ar2
)
127 Debug::Assert(ar1
!= 0 && ar2
!= 0);
128 Type
* t1
= ar1
->GetType();
129 Type
* t2
= ar2
->GetType();
131 if (!(ar1
->Rank
== 1 && ar2
->Rank
== 1
132 && ar1
->Length
== ar2
->Length
&& t1
->GetElementType() == t2
->GetElementType()))
135 //arrays have same rank and size and element type.
136 int len
= ar1
->Length
;
138 for (int i
= 0; i
< len
; i
++)
140 if (compareData(ar1
->GetValue(i
), ar2
->GetValue(i
)) == false)
149 static bool compareStruct(Object
* val1
, Object
* val2
)
151 Debug::Assert(val1
!= 0 && val2
!= 0);
152 Type
* t1
= val1
->GetType();
153 Type
* t2
= val2
->GetType();
156 FieldInfo
* fields
[] = t1
->GetFields();
157 int cFields
= fields
->Length
;
159 for (int i
= 0; i
< cFields
; i
++)
161 Object
* fieldVal1
= fields
[i
]->GetValue(val1
);
162 Object
* fieldVal2
= fields
[i
]->GetValue(val2
);
163 if ( ! compareData(fieldVal1
, fieldVal2
))
172 static bool check( bool b
, String
* message
)
175 Console::WriteLine("{0} failed\n" , message
);
179 static bool equals(TestElement
* rData1
, TestElement
* rData2
)
181 check( rData1
->Bool
== rData2
->Bool
, "### bool does not match!" );
182 check( rData1
->Char
== rData2
->Char
, "### char does not match!" );
183 check( rData1
->Byte
== rData2
->Byte
, "### byte does not match!" );
184 check( rData1
->Short
== rData2
->Short
, "### short does not match!" );
185 check( rData1
->UShort
== rData2
->UShort
, "### unsigned short does not match!" );
186 check( rData1
->Long
== rData2
->Long
, "### long does not match!" );
187 check( rData1
->ULong
== rData2
->ULong
, "### unsigned long does not match!" );
188 check( rData1
->Hyper
== rData2
->Hyper
, "### hyper does not match!" );
189 check( rData1
->UHyper
== rData2
->UHyper
, "### unsigned hyper does not match!" );
190 check( rData1
->Float
== rData2
->Float
, "### float does not match!" );
191 check( rData1
->Double
== rData2
->Double
, "### double does not match!" );
192 check( rData1
->Enum
== rData2
->Enum
, "### enum does not match!" );
193 check( rData1
->String
== rData2
->String
, "### string does not match!" );
194 check( rData1
->Byte2
== rData2
->Byte2
, "### byte2 does not match!" );
195 check( rData1
->Short2
== rData2
->Short2
, "### short2 does not match!" );
196 check( rData1
->Interface
== rData2
->Interface
, "### interface does not match!" );
197 check( compareData(__box(rData1
->Any
), __box(rData2
->Any
)), "### any does not match!" );
199 return (rData1
->Bool
== rData2
->Bool
&&
200 rData1
->Char
== rData2
->Char
&&
201 rData1
->Byte
== rData2
->Byte
&&
202 rData1
->Short
== rData2
->Short
&&
203 rData1
->UShort
== rData2
->UShort
&&
204 rData1
->Long
== rData2
->Long
&&
205 rData1
->ULong
== rData2
->ULong
&&
206 rData1
->Hyper
== rData2
->Hyper
&&
207 rData1
->UHyper
== rData2
->UHyper
&&
208 rData1
->Float
== rData2
->Float
&&
209 rData1
->Double
== rData2
->Double
&&
210 rData1
->Enum
== rData2
->Enum
&&
211 rData1
->String
== rData2
->String
&&
212 rData1
->Byte2
== rData2
->Byte2
&&
213 rData1
->Short2
== rData2
->Short2
&&
214 rData1
->Interface
== rData2
->Interface
&&
215 compareData(__box(rData1
->Any
), __box(rData2
->Any
)));
218 static void assign( TestElement
* rData
,
219 bool bBool
, Char cChar
, Byte nByte
,
220 Int16 nShort
, UInt16 nUShort
,
221 Int32 nLong
, UInt32 nULong
,
222 Int64 nHyper
, UInt64 nUHyper
,
223 float fFloat
, double fDouble
,
224 TestEnum eEnum
, String
* rStr
,
225 Byte nByte2
, Int16 nShort2
,
232 rData
->Short
= nShort
;
233 rData
->UShort
= nUShort
;
235 rData
->ULong
= nULong
;
236 rData
->Hyper
= nHyper
;
237 rData
->UHyper
= nUHyper
;
238 rData
->Float
= fFloat
;
239 rData
->Double
= fDouble
;
241 rData
->String
= rStr
;
242 rData
->Byte2
= nByte2
;
243 rData
->Short2
= nShort2
;
244 rData
->Interface
= xTest
;
248 static void assign( TestDataElements
* rData
,
249 bool bBool
, Char cChar
, Byte nByte
,
250 Int16 nShort
, UInt16 nUShort
,
251 Int32 nLong
, UInt32 nULong
,
252 Int64 nHyper
, UInt64 nUHyper
,
253 float fFloat
, double fDouble
,
254 TestEnum eEnum
, String
* rStr
,
255 Byte nByte2
, Int16 nShort2
,
258 TestElement
* rSequence
[])
260 assign( static_cast<TestElement
*>(rData
),
261 bBool
, cChar
, nByte
, nShort
, nUShort
, nLong
, nULong
, nHyper
, nUHyper
, fFloat
, fDouble
,
262 eEnum
, rStr
, nByte2
, nShort2
, xTest
, rAny
);
263 rData
->Sequence
= rSequence
;
266 static bool testAny(Type
* typ
, Object
* value
, XBridgeTest
* xLBT
)
270 any
= Any(value
->GetType(), value
);
272 any
= Any(typ
, value
);
274 Any any2
= xLBT
->transportAny(any
);
275 bool ret
= compareData(__box(any
), __box(any2
));
278 Console::WriteLine("any is different after roundtrip: in {0}, out {1}\n",
279 any
.Type
->FullName
, any2
.Type
->FullName
);
285 static bool performAnyTest(XBridgeTest
* xLBT
, TestDataElements
* data
)
288 bReturn
= testAny( 0, __box(data
->Byte
), xLBT
) && bReturn
;
289 bReturn
= testAny( 0, __box(data
->Short
), xLBT
) && bReturn
;
290 bReturn
= testAny( 0, __box(data
->UShort
), xLBT
) && bReturn
;
291 bReturn
= testAny( 0, __box(data
->Long
), xLBT
) && bReturn
;
292 bReturn
= testAny( 0, __box(data
->ULong
), xLBT
) && bReturn
;
293 bReturn
= testAny( 0, __box(data
->Hyper
), xLBT
) && bReturn
;
294 bReturn
= testAny( 0, __box(data
->UHyper
), xLBT
) && bReturn
;
295 bReturn
= testAny( 0, __box(data
->Float
), xLBT
) && bReturn
;
296 bReturn
= testAny( 0, __box(data
->Double
),xLBT
) && bReturn
;
297 bReturn
= testAny( 0, __box(data
->Enum
), xLBT
) && bReturn
;
298 bReturn
= testAny( 0, data
->String
,xLBT
) && bReturn
;
299 bReturn
= testAny( 0, data
->Byte2
,xLBT
) && bReturn
;
300 bReturn
= testAny( 0, data
->Short2
,xLBT
) && bReturn
;
301 bReturn
= testAny(__typeof(XWeak
), data
->Interface
,xLBT
) && bReturn
;
302 bReturn
= testAny(0, data
, xLBT
) && bReturn
;
306 Any a2
= xLBT
->transportAny( a1
);
307 bReturn
= compareData(__box(a2
), __box(a1
)) && bReturn
;
312 Any a2
= xLBT
->transportAny(a1
);
313 bReturn
= compareData( __box(a2
), __box(a1
)) && bReturn
;
318 static bool performSequenceOfCallTest(XBridgeTest
* xLBT
)
321 int nGlobalIndex
= 0;
322 const int nWaitTimeSpanMUSec
= 10000;
323 for( nRounds
= 0 ; nRounds
< 10 ; nRounds
++ )
325 for( i
= 0 ; i
< nRounds
; i
++ )
328 xLBT
->callOneway(nGlobalIndex
, nWaitTimeSpanMUSec
);
333 xLBT
->call(nGlobalIndex
, nWaitTimeSpanMUSec
);
336 return xLBT
->sequenceOfCallTestPassed();
340 static bool performRecursiveCallTest(XBridgeTest
* xLBT
)
342 xLBT
->startRecursiveCall(new ORecursiveCall(), 50);
343 // on failure, the test would lock up or crash
347 static bool performQueryForUnknownType(XBridgeTest
* xLBT
)
350 // test queryInterface for an unknown type
353 __try_cast
<foo::MyInterface
*>(xLBT
);
355 catch( System::InvalidCastException
*)
364 static bool performTest(XBridgeTest
* xLBT
)
366 check( xLBT
!= 0, "### no test interface!" );
370 // this data is never ever granted access to by calls other than equals(), assign()!
371 TestDataElements
* aData
= new TestDataElements(); // test against this data
373 Object
* xI
= new WeakBase();
375 Any
aAny( __typeof(Object
), xI
);
376 assign( static_cast<TestElement
*>(aData
),
377 true, '@', 17, 0x1234, 0xfedc, 0x12345678, 0xfedcba98,
378 0x123456789abcdef0, 0xfedcba9876543210,
379 17.0815f
, M_PI
, TestEnum::LOLA
,
380 Constants::STRING_TEST_CONSTANT
, xI
,
383 bRet
= check( aData
->Any
.Value
== xI
, "### unexpected any!" ) && bRet
;
384 bRet
= check( !(aData
->Any
.Value
!= xI
), "### unexpected any!" ) && bRet
;
386 aData
->Sequence
= new TestElement
*[2];
387 aData
->Sequence
[0] = new TestElement(
388 aData
->Bool
, aData
->Char
, aData
->Byte
, aData
->Short
,
389 aData
->UShort
, aData
->Long
, aData
->ULong
,
390 aData
->Hyper
, aData
->UHyper
, aData
->Float
,
391 aData
->Double
, aData
->Enum
, aData
->String
,
392 aData
->Byte2
, aData
->Short2
,
393 aData
->Interface
, aData
->Any
); //(TestElement) aData;
394 aData
->Sequence
[1] = new TestElement(); //is empty
398 // this is a manually copy of aData for first setting...
399 TestDataElements
* aSetData
= new TestDataElements
;
400 Any
aAnySet(__typeof(Object
), xI
);
401 assign( static_cast<TestElement
*>(aSetData
),
407 aData
->Long
, aData
->ULong
, aData
->Hyper
, aData
->UHyper
, aData
->Float
, aData
->Double
,
415 aSetData
->Sequence
= new TestElement
*[2];
416 aSetData
->Sequence
[0] = new TestElement(
417 aSetData
->Bool
, aSetData
->Char
, aSetData
->Byte
, aSetData
->Short
,
418 aSetData
->UShort
, aSetData
->Long
, aSetData
->ULong
,
419 aSetData
->Hyper
, aSetData
->UHyper
, aSetData
->Float
,
420 aSetData
->Double
, aSetData
->Enum
, aSetData
->String
,
421 aSetData
->Byte2
, aSetData
->Short2
,
422 aSetData
->Interface
, aSetData
->Any
); //TestElement) aSetData;
423 aSetData
->Sequence
[1] = new TestElement(); // empty struct
447 TestDataElements
* aRet
= new TestDataElements();
448 TestDataElements
* aRet2
= new TestDataElements();
470 bRet
= check( compareData( aData
, aRet
) && compareData( aData
, aRet2
) , "getValues test") && bRet
;
472 // set last retrieved values
473 TestDataElements
* aSV2ret
= xLBT
->setValues2(
494 // check inout sequence order
495 // => inout sequence parameter was switched by test objects
496 TestElement
* temp
= aRet
->Sequence
[ 0 ];
497 aRet
->Sequence
[ 0 ] = aRet
->Sequence
[ 1 ];
498 aRet
->Sequence
[ 1 ] = temp
;
501 compareData( aData
, aSV2ret
) && compareData( aData
, aRet2
),
502 "getValues2 test") && bRet
;
505 TestDataElements
* aRet
= new TestDataElements();
506 TestDataElements
* aRet2
= new TestDataElements();
507 TestDataElements
* aGVret
= xLBT
->getValues(
528 bRet
= check( compareData( aData
, aRet
) && compareData( aData
, aRet2
) && compareData( aData
, aGVret
), "getValues test" ) && bRet
;
530 // set last retrieved values
531 xLBT
->Bool
= aRet
->Bool
;
532 xLBT
->Char
= aRet
->Char
;
533 xLBT
->Byte
= aRet
->Byte
;
534 xLBT
->Short
= aRet
->Short
;
535 xLBT
->UShort
= aRet
->UShort
;
536 xLBT
->Long
= aRet
->Long
;
537 xLBT
->ULong
= aRet
->ULong
;
538 xLBT
->Hyper
= aRet
->Hyper
;
539 xLBT
->UHyper
= aRet
->UHyper
;
540 xLBT
->Float
= aRet
->Float
;
541 xLBT
->Double
= aRet
->Double
;
542 xLBT
->Enum
= aRet
->Enum
;
543 xLBT
->String
= aRet
->String
;
544 xLBT
->Byte2
= aRet
->Byte2
;
545 xLBT
->Short2
= aRet
->Short2
;
546 xLBT
->Interface
= aRet
->Interface
;
547 xLBT
->Any
= aRet
->Any
;
548 xLBT
->Sequence
= aRet
->Sequence
;
549 xLBT
->Struct
= aRet2
;
552 TestDataElements
* aRet
= new TestDataElements();
553 TestDataElements
* aRet2
= new TestDataElements();
554 aRet
->Hyper
= xLBT
->Hyper
;
555 aRet
->UHyper
= xLBT
->UHyper
;
556 aRet
->Float
= xLBT
->Float
;
557 aRet
->Double
= xLBT
->Double
;
558 aRet
->Byte
= xLBT
->Byte
;
559 aRet
->Char
= xLBT
->Char
;
560 aRet
->Bool
= xLBT
->Bool
;
561 aRet
->Short
= xLBT
->Short
;
562 aRet
->UShort
= xLBT
->UShort
;
563 aRet
->Long
= xLBT
->Long
;
564 aRet
->ULong
= xLBT
->ULong
;
565 aRet
->Enum
= xLBT
->Enum
;
566 aRet
->String
= xLBT
->String
;
567 aRet
->Byte2
= xLBT
->Byte2
;
568 aRet
->Short2
= xLBT
->Short2
;
569 aRet
->Interface
= xLBT
->Interface
;
570 aRet
->Any
= xLBT
->Any
;
571 aRet
->Sequence
= xLBT
->Sequence
;
572 aRet2
= xLBT
->Struct
;
574 bRet
= check( compareData( aData
, aRet
) && compareData( aData
, aRet2
) , "struct comparison test") && bRet
;
576 bRet
= check(performSequenceTest(xLBT
), "sequence test") && bRet
;
579 bRet
= check( performAnyTest( xLBT
, aData
) , "any test" ) && bRet
;
581 // sequence of call test
582 bRet
= check( performSequenceOfCallTest( xLBT
) , "sequence of call test" ) && bRet
;
584 // recursive call test
585 bRet
= check( performRecursiveCallTest( xLBT
) , "recursive test" ) && bRet
;
587 bRet
= (compareData( aData
, aRet
) && compareData( aData
, aRet2
)) && bRet
;
589 // check setting of null reference
591 aRet
->Interface
= xLBT
->Interface
;
592 bRet
= (aRet
->Interface
== 0) && bRet
;
600 static bool performSequenceTest(XBridgeTest
* xBT
)
603 XBridgeTest2
* xBT2
= dynamic_cast<XBridgeTest2
*>(xBT
);
607 // perform sequence tests (XBridgeTest2)
608 // create the sequence which are compared with the results
609 bool arBool __gc
[] = new bool __gc
[3];
610 arBool
[0] = true; arBool
[1] = false; arBool
[2] = true;
611 Char arChar
[] = new Char
[3];
612 arChar
[0] = 'A'; arChar
[1] = 'B'; arChar
[2] = 'C';
613 Byte arByte
[] = new Byte
[3];
614 arByte
[0] = 1; arByte
[1] = 2; arByte
[2] = 0xff;
615 Int16 arShort
[] = new Int16
[3];
616 arShort
[0] = Int16::MinValue
; arShort
[1] = 1; arShort
[2] = Int16::MaxValue
;
617 UInt16 arUShort
[] = new UInt16
[3];
618 arUShort
[0] = UInt16::MinValue
; arUShort
[1] = 1; arUShort
[2] = UInt16::MaxValue
;
619 Int32 arLong
[] = new Int32
[3];
620 arLong
[0] = Int32::MinValue
; arLong
[1] = 1; arLong
[2] = Int32::MaxValue
;
621 UInt32 arULong
[] = new UInt32
[3];
622 arULong
[0] = UInt32::MinValue
; arULong
[1] = 1; arULong
[2] = UInt32::MaxValue
;
623 Int64 arHyper
[] = new Int64
[3];
624 arHyper
[0] = Int64::MinValue
; arHyper
[1] = 1; arHyper
[2] = Int64::MaxValue
;
625 UInt64 arUHyper
[] = new UInt64
[3];
626 arUHyper
[0] = UInt64::MinValue
; arUHyper
[1] = 1;
627 arUHyper
[2] = UInt64::MaxValue
;
628 Single arFloat
[] = new Single
[3];
629 arFloat
[0] = 1.1f
; arFloat
[1] = 2.2f
; arFloat
[2] = 3.3f
;
630 Double arDouble
[] = new Double
[3];
631 arDouble
[0] = 1.11; arDouble
[1] = 2.22; arDouble
[2] = 3.33;
632 String
* arString
[] = new String
*[3];
633 arString
[0] = new String("String 1");
634 arString
[1] = new String("String 2");
635 arString
[2] = new String("String 3");
637 Any arAny
[] = new Any
[3];
638 arAny
[0] = Any(true); arAny
[1] = Any(11111); arAny
[2] = Any(3.14);
639 Object
* arObject
[] = new Object
*[3];
640 arObject
[0] = new WeakBase(); arObject
[1] = new WeakBase();
641 arObject
[1] = new WeakBase();
643 Console::WriteLine(new String("cli_cpp_bridgetest: Workaround for C++ compiler bug:"
644 " using Array of Int32 instead of Array of enums w"));
645 Int32 arEnum
[] = new Int32
[3];
646 arEnum
[0] = static_cast<Int32
>(TestEnum::ONE
);
647 arEnum
[1] = static_cast<Int32
>(TestEnum::TWO
);
648 arEnum
[2] = static_cast<Int32
>(TestEnum::CHECK
);
650 TestElement
* arStruct
[] = new TestElement
*[3];
651 arStruct
[0] = new TestElement(); arStruct
[1] = new TestElement();
652 arStruct
[2] = new TestElement();
653 assign( arStruct
[0], true, '@', 17, 0x1234, 0xfedc, 0x12345678, 0xfedcba98,
654 0x123456789abcdef0, 0xfedcba9876543210, 17.0815f
, M_PI
,
655 TestEnum::LOLA
, Constants::STRING_TEST_CONSTANT
, 18, 0x5678, arObject
[0],
656 Any( __typeof(Object
), arObject
[0]) );
657 assign( arStruct
[1], true, 'A', 17, 0x1234, 0xfedc, 0x12345678, 0xfedcba98,
658 0x123456789abcdef0, 0xfedcba9876543210, 17.0815f
, M_PI
,
659 TestEnum::TWO
, Constants::STRING_TEST_CONSTANT
, 18, 0x5678, arObject
[1],
660 Any( __typeof(Object
), arObject
[1]) );
661 assign( arStruct
[2], true, 'B', 17, 0x1234, 0xfedc, 0x12345678, 0xfedcba98,
662 0x123456789abcdef0, 0xfedcba9876543210, 17.0815f
, M_PI
,
663 TestEnum::CHECK
, Constants::STRING_TEST_CONSTANT
, 18, 0x5678, arObject
[2],
664 Any( __typeof(Object
), arObject
[2] ) );
666 Any seqAnyRet
[] = xBT2
->setSequenceAny(arAny
);
667 bRet
= check( compareData(seqAnyRet
, arAny
), "sequence test") && bRet
;
668 Boolean seqBoolRet
[] = xBT2
->setSequenceBool(arBool
);
669 bRet
= check( compareData(seqBoolRet
, arBool
), "sequence test") && bRet
;
670 Byte seqByteRet
[] = xBT2
->setSequenceByte(arByte
);
671 bRet
= check( compareData(seqByteRet
, arByte
), "sequence test") && bRet
;
672 Char seqCharRet
[] = xBT2
->setSequenceChar(arChar
);
673 bRet
= check( compareData(seqCharRet
, arChar
), "sequence test") && bRet
;
674 Int16 seqShortRet
[] = xBT2
->setSequenceShort(arShort
);
675 bRet
= check( compareData(seqShortRet
, arShort
), "sequence test") && bRet
;
676 Int32 seqLongRet
[] = xBT2
->setSequenceLong(arLong
);
677 bRet
= check( compareData(seqLongRet
, arLong
), "sequence test") && bRet
;
678 Int64 seqHyperRet
[] = xBT2
->setSequenceHyper(arHyper
);
679 bRet
= check( compareData(seqHyperRet
,arHyper
), "sequence test") && bRet
;
680 Single seqFloatRet
[] = xBT2
->setSequenceFloat(arFloat
);
681 bRet
= check( compareData(seqFloatRet
, arFloat
), "sequence test") && bRet
;
682 Double seqDoubleRet
[] = xBT2
->setSequenceDouble(arDouble
);
683 bRet
= check( compareData(seqDoubleRet
, arDouble
), "sequence test") && bRet
;
684 xBT2
->setSequenceEnum(arEnum
);
685 //comparing seqEnumRet with arEnum will fail since they are of different
686 //types because of workaround. arEnum is Int32[].
687 Console::WriteLine(new String("cli_cpp_bridgetest: Test omitted because "
688 "of C++ compiler bug. XBridgeTest2::setSequenceEnum(sequence<TestEnum>)"));
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 Console::WriteLine(new String("cli_cpp_bridgetest: no test of "
704 "XBridgeTest2::setSequencesInOut and XBridgeTest2.setSequencesOut "
705 "because jagged arrays are not supported by C++ compiler"));
708 Any _arAny
[] = new Any
[0];
709 Any seqAnyRet
[] = xBT2
->setSequenceAny(_arAny
);
710 bRet
= check( compareData(seqAnyRet
, _arAny
), "sequence test") && bRet
;
711 Boolean _arBool
[] = new Boolean
[0];
712 Boolean seqBoolRet
[] = xBT2
->setSequenceBool(_arBool
);
713 bRet
= check( compareData(seqBoolRet
, _arBool
), "sequence test") && bRet
;
714 Byte _arByte
[] = new Byte
[0];
715 Byte seqByteRet
[] = xBT2
->setSequenceByte(_arByte
);
716 bRet
= check( compareData(seqByteRet
, _arByte
), "sequence test") && bRet
;
717 Char _arChar
[] = new Char
[0];
718 Char seqCharRet
[] = xBT2
->setSequenceChar(_arChar
);
719 bRet
= check( compareData(seqCharRet
, _arChar
), "sequence test") && bRet
;
720 Int16 _arShort
[] = new Int16
[0];
721 Int16 seqShortRet
[] = xBT2
->setSequenceShort(_arShort
);
722 bRet
= check( compareData(seqShortRet
, _arShort
), "sequence test") && bRet
;
723 Int32 _arLong
[] = new Int32
[0];
724 Int32 seqLongRet
[] = xBT2
->setSequenceLong(_arLong
);
725 bRet
= check( compareData(seqLongRet
, _arLong
), "sequence test") && bRet
;
726 Int64 _arHyper
[] = new Int64
[0];
727 Int64 seqHyperRet
[] = xBT2
->setSequenceHyper(_arHyper
);
728 bRet
= check( compareData(seqHyperRet
, _arHyper
), "sequence test") && bRet
;
729 Single _arFloat
[] = new Single
[0];
730 Single seqFloatRet
[] = xBT2
->setSequenceFloat(_arFloat
);
731 bRet
= check( compareData(seqFloatRet
, _arFloat
), "sequence test") && bRet
;
732 Double _arDouble
[] = new Double
[0];
733 Double seqDoubleRet
[] = xBT2
->setSequenceDouble(_arDouble
);
734 bRet
= check( compareData(seqDoubleRet
, _arDouble
), "sequence test") && bRet
;
735 TestEnum _arEnum
[] = new TestEnum
[0];
736 xBT2
->setSequenceEnum(_arEnum
);
737 UInt16 _arUShort
[] = new UInt16
[0];
738 UInt16 seqUShortRet
[] = xBT2
->setSequenceUShort(_arUShort
);
739 bRet
= check( compareData(seqUShortRet
, _arUShort
), "sequence test") && bRet
;
740 UInt32 _arULong
[] = new UInt32
[0];
741 UInt32 seqULongRet
[] = xBT2
->setSequenceULong(_arULong
);
742 bRet
= check( compareData(seqULongRet
, _arULong
), "sequence test") && bRet
;
743 UInt64 _arUHyper
[] = new UInt64
[0];
744 UInt64 seqUHyperRet
[] = xBT2
->setSequenceUHyper(_arUHyper
);
745 bRet
= check( compareData(seqUHyperRet
, _arUHyper
), "sequence test") && bRet
;
746 Object
* _arObject
[] = new Object
*[0];
747 Object
* seqObjectRet
[] = xBT2
->setSequenceXInterface(_arObject
);
748 bRet
= check( compareData(seqObjectRet
, _arObject
), "sequence test") && bRet
;
749 String
* _arString
[] = new String
*[0];
750 String
* seqStringRet
[] = xBT2
->setSequenceString(_arString
);
751 bRet
= check( compareData(seqStringRet
, _arString
), "sequence test") && bRet
;
752 TestElement
* _arStruct
[] = new TestElement
*[0];
753 TestElement
* seqStructRet
[] = xBT2
->setSequenceStruct(_arStruct
);
754 bRet
= check( compareData(seqStructRet
, _arStruct
), "sequence test") && bRet
;
759 /** Test the System::Object method on the proxy object
761 static bool testObjectMethodsImplementation(XBridgeTest
* xLBT
)
764 Object
* obj
= new Object();
765 XBridgeTestBase
* xBase
= dynamic_cast<XBridgeTestBase
*>(xLBT
);
769 ret
= xLBT
->Equals(obj
) == false;
770 ret
= xLBT
->Equals(xLBT
) && ret
;
771 ret
= Object::Equals(obj
, obj
) && ret
;
772 ret
= Object::Equals(xLBT
, xBase
) && ret
;
774 // Don't know how to verify this. Currently it is not possible to get the object id from a proxy
775 int nHash
= xLBT
->GetHashCode();
776 ret
= nHash
== xBase
->GetHashCode() && ret
;
779 // Don't know how to verify this automatically.
780 String
* s
= xLBT
->ToString();
781 ret
= (s
->Length
> 0) && ret
;
786 static bool raiseOnewayException(XBridgeTest
* xLBT
)
789 String
* sCompare
= Constants::STRING_TEST_CONSTANT
;
792 // Note : the exception may fly or not (e.g. remote scenario).
793 // When it flies, it must contain the correct elements.
794 xLBT
->raiseRuntimeExceptionOneway(sCompare
, xLBT
->Interface
);
796 catch (RuntimeException
* e
)
798 bReturn
= ( xLBT
->Interface
== e
->Context
);
804 static bool raiseException(XBridgeTest
* xLBT
)
813 xLBT
->raiseException(
814 5, Constants::STRING_TEST_CONSTANT
, xLBT
->Interface
);
816 catch (unoidl::com::sun::star::lang::IllegalArgumentException
* aExc
)
818 if (aExc
->ArgumentPosition
== 5 &&
819 aExc
->Context
== xLBT
->Interface
)
825 check( false, "### unexpected exception content!" );
828 /** it is certain, that the RuntimeException testing will fail,
830 xLBT
->RuntimeException
= 0;
833 catch (unoidl::com::sun::star::uno::RuntimeException
* rExc
)
835 if (rExc
->Context
== xLBT
->Interface
)
841 check( false, "### unexpected exception content!" );
844 /** it is certain, that the RuntimeException testing will fail, if no */
845 xLBT
->RuntimeException
= (int) 0xcafebabe;
848 catch (unoidl::com::sun::star::uno::Exception
* rExc
)
850 if (rExc
->Context
== xLBT
->Interface
)
857 check( false, "### unexpected exception content!" );
859 return (nCount
== 3);
864 static private void perform_test( XBridgeTest
* xLBT
)
867 bRet
= check( performTest( xLBT
), "standard test" ) && bRet
;
868 bRet
= check( raiseException( xLBT
) , "exception test" )&& bRet
;
869 bRet
= check( raiseOnewayException( xLBT
), "oneway exception test" ) && bRet
;
870 bRet
= check( testObjectMethodsImplementation(xLBT
), "object methods test") && bRet
;
871 bRet
= performQueryForUnknownType( xLBT
) && bRet
;
874 throw new unoidl::com::sun::star::uno::RuntimeException(
875 new String("error: test failed!"), 0);
878 XComponentContext
* m_xContext
;
881 explicit BridgeTest( XComponentContext
* xContext
)
883 m_xContext
= xContext
;
887 int run( String
* args
[] )
891 if (args
->Length
< 1)
893 throw new RuntimeException(
894 "missing argument for bridgetest!", this );
897 m_xContext
->getServiceManager()->createInstanceWithContext(
898 args
[ 0 ], m_xContext
);
900 test_obj
= m_xContext
->getValueByName( args
[ 0 ] ).Value
;
903 "cli target bridgetest obj: {0}", test_obj
->ToString() );
904 XBridgeTest
* xTest
= __try_cast
<XBridgeTest
*>(test_obj
) ;
905 perform_test( xTest
);
906 Console::WriteLine( "\n### cli_uno C++ bridgetest succeeded." );
909 catch (unoidl::com::sun::star::uno::RuntimeException
* )
913 catch (System::Exception
* exc
)
915 System::Text::StringBuilder
* s
= new System::Text::StringBuilder();
916 s
->Append(S
"cli_cpp_bridgetest: unexpected exception occurred in XMain::run. Original exception: ");
917 s
->Append(exc
->GetType()->Name
);
918 s
->Append(S
"\n Message: ");
919 s
->Append(exc
->Message
);
920 throw new unoidl::com::sun::star::uno::RuntimeException(
928 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */