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>
28 using namespace System
;
29 using namespace System::Diagnostics
;
30 using namespace System::Reflection
;
31 using namespace System::Threading
;
33 using namespace uno::util
;
34 using namespace unoidl::com::sun::star::uno
;
35 using namespace unoidl::com::sun::star::lang
;
36 using namespace unoidl::test::testtools::bridgetest
;
39 public __gc __interface MyInterface
44 namespace cpp_bridgetest
46 __gc
class ORecursiveCall
: public WeakBase
, public XRecursiveCall
49 void callRecursivly(XRecursiveCall
* xCall
, int nToCall
)
58 xCall
->callRecursivly(this, nToCall
);
70 public __gc
class Constants
73 static String
* STRING_TEST_CONSTANT
= new String(S
"\" paco\' chorizo\\\' \"\'");
76 public __gc
class BridgeTest
: public WeakBase
, public XMain
78 static bool compareData(Object
* val1
, Object
* val2
)
80 if (val1
== 0 && val2
== 0 || val1
== val2
)
82 if ((val1
== 0 && val2
!= 0) ||
83 (val1
!= 0 && val2
== 0) || val1
->GetType() != val2
->GetType())
87 Type
* t1
= val1
->GetType();
91 ret
= compareSequence(static_cast<Array
*>(val1
),
92 static_cast<Array
*>(val2
));
95 else if (t1
== __typeof(String
))
97 ret
= val1
->Equals(val2
);
99 // Interface implementation
100 else if (t1
->GetInterfaces()->Length
> 0 && ! t1
->IsValueType
)
105 else if ( ! t1
->IsValueType
)
107 ret
= compareStruct(val1
, val2
);
109 else if (t1
== __typeof(Any
))
113 ret
= a1
.Type
== a2
.Type
&& compareData(a1
.Value
, a2
.Value
);
115 else if (t1
->IsValueType
)
117 //Any, enum, int, bool char, float, double etc.
118 ret
= val1
->Equals(val2
);
122 Debug::Assert(false);
127 // Arrays have only one dimension
128 static bool compareSequence(Array
* ar1
, Array
* ar2
)
130 Debug::Assert(ar1
!= 0 && ar2
!= 0);
131 Type
* t1
= ar1
->GetType();
132 Type
* t2
= ar2
->GetType();
134 if (!(ar1
->Rank
== 1 && ar2
->Rank
== 1
135 && ar1
->Length
== ar2
->Length
&& t1
->GetElementType() == t2
->GetElementType()))
138 //arrays have same rank and size and element type.
139 int len
= ar1
->Length
;
141 for (int i
= 0; i
< len
; i
++)
143 if (compareData(ar1
->GetValue(i
), ar2
->GetValue(i
)) == false)
152 static bool compareStruct(Object
* val1
, Object
* val2
)
154 Debug::Assert(val1
!= 0 && val2
!= 0);
155 Type
* t1
= val1
->GetType();
156 Type
* t2
= val2
->GetType();
159 FieldInfo
* fields
[] = t1
->GetFields();
160 int cFields
= fields
->Length
;
162 for (int i
= 0; i
< cFields
; i
++)
164 Object
* fieldVal1
= fields
[i
]->GetValue(val1
);
165 Object
* fieldVal2
= fields
[i
]->GetValue(val2
);
166 if ( ! compareData(fieldVal1
, fieldVal2
))
175 static bool check( bool b
, String
* message
)
178 Console::WriteLine("{0} failed\n" , message
);
182 static bool equals(TestElement
* rData1
, TestElement
* rData2
)
184 check( rData1
->Bool
== rData2
->Bool
, "### bool does not match!" );
185 check( rData1
->Char
== rData2
->Char
, "### char does not match!" );
186 check( rData1
->Byte
== rData2
->Byte
, "### byte does not match!" );
187 check( rData1
->Short
== rData2
->Short
, "### short does not match!" );
188 check( rData1
->UShort
== rData2
->UShort
, "### unsigned short does not match!" );
189 check( rData1
->Long
== rData2
->Long
, "### long does not match!" );
190 check( rData1
->ULong
== rData2
->ULong
, "### unsigned long does not match!" );
191 check( rData1
->Hyper
== rData2
->Hyper
, "### hyper does not match!" );
192 check( rData1
->UHyper
== rData2
->UHyper
, "### unsigned hyper does not match!" );
193 check( rData1
->Float
== rData2
->Float
, "### float does not match!" );
194 check( rData1
->Double
== rData2
->Double
, "### double does not match!" );
195 check( rData1
->Enum
== rData2
->Enum
, "### enum does not match!" );
196 check( rData1
->String
== rData2
->String
, "### string does not match!" );
197 check( rData1
->Interface
== rData2
->Interface
, "### interface does not match!" );
198 check( compareData(__box(rData1
->Any
), __box(rData2
->Any
)), "### any does not match!" );
200 return (rData1
->Bool
== rData2
->Bool
&&
201 rData1
->Char
== rData2
->Char
&&
202 rData1
->Byte
== rData2
->Byte
&&
203 rData1
->Short
== rData2
->Short
&&
204 rData1
->UShort
== rData2
->UShort
&&
205 rData1
->Long
== rData2
->Long
&&
206 rData1
->ULong
== rData2
->ULong
&&
207 rData1
->Hyper
== rData2
->Hyper
&&
208 rData1
->UHyper
== rData2
->UHyper
&&
209 rData1
->Float
== rData2
->Float
&&
210 rData1
->Double
== rData2
->Double
&&
211 rData1
->Enum
== rData2
->Enum
&&
212 rData1
->String
== rData2
->String
&&
213 rData1
->Interface
== rData2
->Interface
&&
214 compareData(__box(rData1
->Any
), __box(rData2
->Any
)));
217 static void assign( TestElement
* rData
,
218 bool bBool
, Char cChar
, Byte nByte
,
219 Int16 nShort
, UInt16 nUShort
,
220 Int32 nLong
, UInt32 nULong
,
221 Int64 nHyper
, UInt64 nUHyper
,
222 float fFloat
, double fDouble
,
223 TestEnum eEnum
, String
* rStr
,
230 rData
->Short
= nShort
;
231 rData
->UShort
= nUShort
;
233 rData
->ULong
= nULong
;
234 rData
->Hyper
= nHyper
;
235 rData
->UHyper
= nUHyper
;
236 rData
->Float
= fFloat
;
237 rData
->Double
= fDouble
;
239 rData
->String
= rStr
;
240 rData
->Interface
= xTest
;
244 static void assign( TestDataElements
* rData
,
245 bool bBool
, Char cChar
, Byte nByte
,
246 Int16 nShort
, UInt16 nUShort
,
247 Int32 nLong
, UInt32 nULong
,
248 Int64 nHyper
, UInt64 nUHyper
,
249 float fFloat
, double fDouble
,
250 TestEnum eEnum
, String
* rStr
,
253 TestElement
* rSequence
[])
255 assign( static_cast<TestElement
*>(rData
),
256 bBool
, cChar
, nByte
, nShort
, nUShort
, nLong
, nULong
, nHyper
, nUHyper
, fFloat
, fDouble
,
257 eEnum
, rStr
, xTest
, rAny
);
258 rData
->Sequence
= rSequence
;
261 static bool testAny(Type
* typ
, Object
* value
, XBridgeTest
* xLBT
)
265 any
= Any(value
->GetType(), value
);
267 any
= Any(typ
, value
);
269 Any any2
= xLBT
->transportAny(any
);
270 bool ret
= compareData(__box(any
), __box(any2
));
273 Console::WriteLine("any is different after roundtrip: in {0}, out {1}\n",
274 any
.Type
->FullName
, any2
.Type
->FullName
);
281 static bool performAnyTest(XBridgeTest
* xLBT
, TestDataElements
* data
)
284 bReturn
= testAny( 0, __box(data
->Byte
), xLBT
) && bReturn
;
285 bReturn
= testAny( 0, __box(data
->Short
), xLBT
) && bReturn
;
286 bReturn
= testAny( 0, __box(data
->UShort
), xLBT
) && bReturn
;
287 bReturn
= testAny( 0, __box(data
->Long
), xLBT
) && bReturn
;
288 bReturn
= testAny( 0, __box(data
->ULong
), xLBT
) && bReturn
;
289 bReturn
= testAny( 0, __box(data
->Hyper
), xLBT
) && bReturn
;
290 bReturn
= testAny( 0, __box(data
->UHyper
), xLBT
) && bReturn
;
291 bReturn
= testAny( 0, __box(data
->Float
), xLBT
) && bReturn
;
292 bReturn
= testAny( 0, __box(data
->Double
),xLBT
) && bReturn
;
293 bReturn
= testAny( 0, __box(data
->Enum
), xLBT
) && bReturn
;
294 bReturn
= testAny( 0, data
->String
,xLBT
) && bReturn
;
295 bReturn
= testAny(__typeof(XWeak
), data
->Interface
,xLBT
) && bReturn
;
296 bReturn
= testAny(0, data
, xLBT
) && bReturn
;
300 Any a2
= xLBT
->transportAny( a1
);
301 bReturn
= compareData(__box(a2
), __box(a1
)) && bReturn
;
306 Any a2
= xLBT
->transportAny(a1
);
307 bReturn
= compareData( __box(a2
), __box(a1
)) && bReturn
;
312 static bool performSequenceOfCallTest(XBridgeTest
* xLBT
)
315 int nGlobalIndex
= 0;
316 const int nWaitTimeSpanMUSec
= 10000;
317 for( nRounds
= 0 ; nRounds
< 10 ; nRounds
++ )
319 for( i
= 0 ; i
< nRounds
; i
++ )
322 xLBT
->callOneway(nGlobalIndex
, nWaitTimeSpanMUSec
);
327 xLBT
->call(nGlobalIndex
, nWaitTimeSpanMUSec
);
330 return xLBT
->sequenceOfCallTestPassed();
336 static bool performRecursiveCallTest(XBridgeTest
* xLBT
)
338 xLBT
->startRecursiveCall(new ORecursiveCall(), 50);
339 // on failure, the test would lock up or crash
343 static bool performQueryForUnknownType(XBridgeTest
* xLBT
)
346 // test queryInterface for an unknown type
349 __try_cast
<foo::MyInterface
*>(xLBT
);
351 catch( System::InvalidCastException
*)
360 static bool performTest(XBridgeTest
* xLBT
)
362 check( xLBT
!= 0, "### no test interface!" );
366 // this data is never ever granted access to by calls other than equals(), assign()!
367 TestDataElements
* aData
= new TestDataElements(); // test against this data
369 Object
* xI
= new WeakBase();
371 Any
aAny( __typeof(Object
), xI
);
372 assign( static_cast<TestElement
*>(aData
),
373 true, '@', 17, 0x1234, 0xfedc, 0x12345678, 0xfedcba98,
374 0x123456789abcdef0, 0xfedcba9876543210,
375 17.0815f
, 3.1415926359, TestEnum::LOLA
,
376 Constants::STRING_TEST_CONSTANT
, xI
,
379 bRet
= check( aData
->Any
.Value
== xI
, "### unexpected any!" ) && bRet
;
380 bRet
= check( !(aData
->Any
.Value
!= xI
), "### unexpected any!" ) && bRet
;
382 aData
->Sequence
= new TestElement
*[2];
383 aData
->Sequence
[0] = new TestElement(
384 aData
->Bool
, aData
->Char
, aData
->Byte
, aData
->Short
,
385 aData
->UShort
, aData
->Long
, aData
->ULong
,
386 aData
->Hyper
, aData
->UHyper
, aData
->Float
,
387 aData
->Double
, aData
->Enum
, aData
->String
,
388 aData
->Interface
, aData
->Any
); //(TestElement) aData;
389 aData
->Sequence
[1] = new TestElement(); //is empty
393 // this is a manually copy of aData for first setting...
394 TestDataElements
* aSetData
= new TestDataElements
;
395 Any
aAnySet(__typeof(Object
), xI
);
396 assign( static_cast<TestElement
*>(aSetData
),
402 aData
->Long
, aData
->ULong
, aData
->Hyper
, aData
->UHyper
, aData
->Float
, aData
->Double
,
408 aSetData
->Sequence
= new TestElement
*[2];
409 aSetData
->Sequence
[0] = new TestElement(
410 aSetData
->Bool
, aSetData
->Char
, aSetData
->Byte
, aSetData
->Short
,
411 aSetData
->UShort
, aSetData
->Long
, aSetData
->ULong
,
412 aSetData
->Hyper
, aSetData
->UHyper
, aSetData
->Float
,
413 aSetData
->Double
, aSetData
->Enum
, aSetData
->String
,
414 aSetData
->Interface
, aSetData
->Any
); //TestElement) aSetData;
415 aSetData
->Sequence
[1] = new TestElement(); // empty struct
418 aSetData
->Bool
, aSetData
->Char
, aSetData
->Byte
, aSetData
->Short
, aSetData
->UShort
,
419 aSetData
->Long
, aSetData
->ULong
, aSetData
->Hyper
, aSetData
->UHyper
, aSetData
->Float
, aSetData
->Double
,
420 aSetData
->Enum
, aSetData
->String
, aSetData
->Interface
, aSetData
->Any
, aSetData
->Sequence
, aSetData
);
423 TestDataElements
* aRet
= new TestDataElements();
424 TestDataElements
* aRet2
= new TestDataElements();
426 & aRet
->Bool
, & aRet
->Char
, & aRet
->Byte
, & aRet
->Short
, & aRet
->UShort
,
427 & aRet
->Long
, & aRet
->ULong
, & aRet
->Hyper
, & aRet
->UHyper
,
428 & aRet
->Float
, & aRet
->Double
, & aRet
->Enum
, & aRet
->String
,
429 & aRet
->Interface
, & aRet
->Any
, & aRet
->Sequence
, & aRet2
);
431 bRet
= check( compareData( aData
, aRet
) && compareData( aData
, aRet2
) , "getValues test") && bRet
;
433 // set last retrieved values
434 TestDataElements
* aSV2ret
= xLBT
->setValues2(
435 & aRet
->Bool
, & aRet
->Char
, & aRet
->Byte
, & aRet
->Short
, & aRet
->UShort
,
436 & aRet
->Long
, & aRet
->ULong
, & aRet
->Hyper
, & aRet
->UHyper
, & aRet
->Float
,
437 & aRet
->Double
, & aRet
->Enum
, & aRet
->String
, & aRet
->Interface
, & aRet
->Any
,
438 & aRet
->Sequence
, & aRet2
);
440 // check inout sequence order
441 // => inout sequence parameter was switched by test objects
442 TestElement
* temp
= aRet
->Sequence
[ 0 ];
443 aRet
->Sequence
[ 0 ] = aRet
->Sequence
[ 1 ];
444 aRet
->Sequence
[ 1 ] = temp
;
447 compareData( aData
, aSV2ret
) && compareData( aData
, aRet2
),
448 "getValues2 test") && bRet
;
451 TestDataElements
* aRet
= new TestDataElements();
452 TestDataElements
* aRet2
= new TestDataElements();
453 TestDataElements
* aGVret
= xLBT
->getValues(
454 & aRet
->Bool
, & aRet
->Char
, & aRet
->Byte
, & aRet
->Short
,
455 & aRet
->UShort
, & aRet
->Long
, & aRet
->ULong
, & aRet
->Hyper
,
456 & aRet
->UHyper
, & aRet
->Float
, & aRet
->Double
, & aRet
->Enum
,
457 & aRet
->String
, & aRet
->Interface
, & aRet
->Any
, & aRet
->Sequence
,
460 bRet
= check( compareData( aData
, aRet
) && compareData( aData
, aRet2
) && compareData( aData
, aGVret
), "getValues test" ) && bRet
;
462 // set last retrieved values
463 xLBT
->Bool
= aRet
->Bool
;
464 xLBT
->Char
= aRet
->Char
;
465 xLBT
->Byte
= aRet
->Byte
;
466 xLBT
->Short
= aRet
->Short
;
467 xLBT
->UShort
= aRet
->UShort
;
468 xLBT
->Long
= aRet
->Long
;
469 xLBT
->ULong
= aRet
->ULong
;
470 xLBT
->Hyper
= aRet
->Hyper
;
471 xLBT
->UHyper
= aRet
->UHyper
;
472 xLBT
->Float
= aRet
->Float
;
473 xLBT
->Double
= aRet
->Double
;
474 xLBT
->Enum
= aRet
->Enum
;
475 xLBT
->String
= aRet
->String
;
476 xLBT
->Interface
= aRet
->Interface
;
477 xLBT
->Any
= aRet
->Any
;
478 xLBT
->Sequence
= aRet
->Sequence
;
479 xLBT
->Struct
= aRet2
;
482 TestDataElements
* aRet
= new TestDataElements();
483 TestDataElements
* aRet2
= new TestDataElements();
484 aRet
->Hyper
= xLBT
->Hyper
;
485 aRet
->UHyper
= xLBT
->UHyper
;
486 aRet
->Float
= xLBT
->Float
;
487 aRet
->Double
= xLBT
->Double
;
488 aRet
->Byte
= xLBT
->Byte
;
489 aRet
->Char
= xLBT
->Char
;
490 aRet
->Bool
= xLBT
->Bool
;
491 aRet
->Short
= xLBT
->Short
;
492 aRet
->UShort
= xLBT
->UShort
;
493 aRet
->Long
= xLBT
->Long
;
494 aRet
->ULong
= xLBT
->ULong
;
495 aRet
->Enum
= xLBT
->Enum
;
496 aRet
->String
= xLBT
->String
;
497 aRet
->Interface
= xLBT
->Interface
;
498 aRet
->Any
= xLBT
->Any
;
499 aRet
->Sequence
= xLBT
->Sequence
;
500 aRet2
= xLBT
->Struct
;
502 bRet
= check( compareData( aData
, aRet
) && compareData( aData
, aRet2
) , "struct comparison test") && bRet
;
504 bRet
= check(performSequenceTest(xLBT
), "sequence test") && bRet
;
507 bRet
= check( performAnyTest( xLBT
, aData
) , "any test" ) && bRet
;
509 // sequence of call test
510 bRet
= check( performSequenceOfCallTest( xLBT
) , "sequence of call test" ) && bRet
;
512 // recursive call test
513 bRet
= check( performRecursiveCallTest( xLBT
) , "recursive test" ) && bRet
;
515 bRet
= (compareData( aData
, aRet
) && compareData( aData
, aRet2
)) && bRet
;
517 // check setting of null reference
519 aRet
->Interface
= xLBT
->Interface
;
520 bRet
= (aRet
->Interface
== 0) && bRet
;
528 static bool performSequenceTest(XBridgeTest
* xBT
)
531 XBridgeTest2
* xBT2
= dynamic_cast<XBridgeTest2
*>(xBT
);
535 // perform sequence tests (XBridgeTest2)
536 // create the sequence which are compared with the results
537 bool arBool __gc
[] = new bool __gc
[3];
538 arBool
[0] = true; arBool
[1] = false; arBool
[2] = true;
539 Char arChar
[] = new Char
[3];
540 arChar
[0] = 'A'; arChar
[1] = 'B'; arChar
[2] = 'C';
541 Byte arByte
[] = new Byte
[3];
542 arByte
[0] = 1; arByte
[1] = 2; arByte
[2] = 0xff;
543 Int16 arShort
[] = new Int16
[3];
544 arShort
[0] = Int16::MinValue
; arShort
[1] = 1; arShort
[2] = Int16::MaxValue
;
545 UInt16 arUShort
[] = new UInt16
[3];
546 arUShort
[0] = UInt16::MinValue
; arUShort
[1] = 1; arUShort
[2] = UInt16::MaxValue
;
547 Int32 arLong
[] = new Int32
[3];
548 arLong
[0] = Int32::MinValue
; arLong
[1] = 1; arLong
[2] = Int32::MaxValue
;
549 UInt32 arULong
[] = new UInt32
[3];
550 arULong
[0] = UInt32::MinValue
; arULong
[1] = 1; arULong
[2] = UInt32::MaxValue
;
551 Int64 arHyper
[] = new Int64
[3];
552 arHyper
[0] = Int64::MinValue
; arHyper
[1] = 1; arHyper
[2] = Int64::MaxValue
;
553 UInt64 arUHyper
[] = new UInt64
[3];
554 arUHyper
[0] = UInt64::MinValue
; arUHyper
[1] = 1;
555 arUHyper
[2] = UInt64::MaxValue
;
556 Single arFloat
[] = new Single
[3];
557 arFloat
[0] = 1.1f
; arFloat
[1] = 2.2f
; arFloat
[2] = 3.3f
;
558 Double arDouble
[] = new Double
[3];
559 arDouble
[0] = 1.11; arDouble
[1] = 2.22; arDouble
[2] = 3.33;
560 String
* arString
[] = new String
*[3];
561 arString
[0] = new String("String 1");
562 arString
[1] = new String("String 2");
563 arString
[2] = new String("String 3");
565 Any arAny
[] = new Any
[3];
566 arAny
[0] = Any(true); arAny
[1] = Any(11111); arAny
[2] = Any(3.14);
567 Object
* arObject
[] = new Object
*[3];
568 arObject
[0] = new WeakBase(); arObject
[1] = new WeakBase();
569 arObject
[1] = new WeakBase();
571 Console::WriteLine(new String("cli_cpp_bridgetest: Workaround for C++ compiler bug:"
572 " using Array of Int32 instead of Array of enums w"));
573 Int32 arEnum
[] = new Int32
[3];
574 arEnum
[0] = static_cast<Int32
>(TestEnum::ONE
);
575 arEnum
[1] = static_cast<Int32
>(TestEnum::TWO
);
576 arEnum
[2] = static_cast<Int32
>(TestEnum::CHECK
);
578 TestElement
* arStruct
[] = new TestElement
*[3];
579 arStruct
[0] = new TestElement(); arStruct
[1] = new TestElement();
580 arStruct
[2] = new TestElement();
581 assign( arStruct
[0], true, '@', 17, 0x1234, 0xfedc, 0x12345678, 0xfedcba98,
582 0x123456789abcdef0, 0xfedcba9876543210, 17.0815f
, 3.1415926359,
583 TestEnum::LOLA
, Constants::STRING_TEST_CONSTANT
, arObject
[0],
584 Any( __typeof(Object
), arObject
[0]) );
585 assign( arStruct
[1], true, 'A', 17, 0x1234, 0xfedc, 0x12345678, 0xfedcba98,
586 0x123456789abcdef0, 0xfedcba9876543210, 17.0815f
, 3.1415926359,
587 TestEnum::TWO
, Constants::STRING_TEST_CONSTANT
, arObject
[1],
588 Any( __typeof(Object
), arObject
[1]) );
589 assign( arStruct
[2], true, 'B', 17, 0x1234, 0xfedc, 0x12345678, 0xfedcba98,
590 0x123456789abcdef0, 0xfedcba9876543210, 17.0815f
, 3.1415926359,
591 TestEnum::CHECK
, Constants::STRING_TEST_CONSTANT
, arObject
[2],
592 Any( __typeof(Object
), arObject
[2] ) );
594 Any seqAnyRet
[] = xBT2
->setSequenceAny(arAny
);
595 bRet
= check( compareData(seqAnyRet
, arAny
), "sequence test") && bRet
;
596 Boolean seqBoolRet
[] = xBT2
->setSequenceBool(arBool
);
597 bRet
= check( compareData(seqBoolRet
, arBool
), "sequence test") && bRet
;
598 Byte seqByteRet
[] = xBT2
->setSequenceByte(arByte
);
599 bRet
= check( compareData(seqByteRet
, arByte
), "sequence test") && bRet
;
600 Char seqCharRet
[] = xBT2
->setSequenceChar(arChar
);
601 bRet
= check( compareData(seqCharRet
, arChar
), "sequence test") && bRet
;
602 Int16 seqShortRet
[] = xBT2
->setSequenceShort(arShort
);
603 bRet
= check( compareData(seqShortRet
, arShort
), "sequence test") && bRet
;
604 Int32 seqLongRet
[] = xBT2
->setSequenceLong(arLong
);
605 bRet
= check( compareData(seqLongRet
, arLong
), "sequence test") && bRet
;
606 Int64 seqHyperRet
[] = xBT2
->setSequenceHyper(arHyper
);
607 bRet
= check( compareData(seqHyperRet
,arHyper
), "sequence test") && bRet
;
608 Single seqFloatRet
[] = xBT2
->setSequenceFloat(arFloat
);
609 bRet
= check( compareData(seqFloatRet
, arFloat
), "sequence test") && bRet
;
610 Double seqDoubleRet
[] = xBT2
->setSequenceDouble(arDouble
);
611 bRet
= check( compareData(seqDoubleRet
, arDouble
), "sequence test") && bRet
;
612 xBT2
->setSequenceEnum(arEnum
);
613 //comparing seqEnumRet with arEnum will fail since they are of different
614 //types because of workaround. arEnum is Int32[].
615 Console::WriteLine(new String("cli_cpp_bridgetest: Test omitted because "
616 "of C++ compiler bug. XBridgeTest2::setSequenceEnum(sequence<TestEnum>)"));
617 UInt16 seqUShortRet
[] = xBT2
->setSequenceUShort(arUShort
);
618 bRet
= check( compareData(seqUShortRet
, arUShort
), "sequence test") && bRet
;
619 UInt32 seqULongRet
[] = xBT2
->setSequenceULong(arULong
);
620 bRet
= check( compareData(seqULongRet
, arULong
), "sequence test") && bRet
;
621 UInt64 seqUHyperRet
[] = xBT2
->setSequenceUHyper(arUHyper
);
622 bRet
= check( compareData(seqUHyperRet
, arUHyper
), "sequence test") && bRet
;
623 Object
* seqObjectRet
[] = xBT2
->setSequenceXInterface(arObject
);
624 bRet
= check( compareData(seqObjectRet
, arObject
), "sequence test") && bRet
;
625 String
* seqStringRet
[] = xBT2
->setSequenceString(arString
);
626 bRet
= check( compareData(seqStringRet
, arString
), "sequence test") && bRet
;
627 TestElement
* seqStructRet
[] = xBT2
->setSequenceStruct(arStruct
);
628 bRet
= check( compareData(seqStructRet
, arStruct
), "sequence test") && bRet
;
631 Console::WriteLine(new String("cli_cpp_bridgetest: no test of "
632 "XBridgeTest2::setSequencesInOut and XBridgeTest2.setSequencesOut "
633 "because jagged arrays are not supported by C++ compiler"));
636 Any _arAny
[] = new Any
[0];
637 Any seqAnyRet
[] = xBT2
->setSequenceAny(_arAny
);
638 bRet
= check( compareData(seqAnyRet
, _arAny
), "sequence test") && bRet
;
639 Boolean _arBool
[] = new Boolean
[0];
640 Boolean seqBoolRet
[] = xBT2
->setSequenceBool(_arBool
);
641 bRet
= check( compareData(seqBoolRet
, _arBool
), "sequence test") && bRet
;
642 Byte _arByte
[] = new Byte
[0];
643 Byte seqByteRet
[] = xBT2
->setSequenceByte(_arByte
);
644 bRet
= check( compareData(seqByteRet
, _arByte
), "sequence test") && bRet
;
645 Char _arChar
[] = new Char
[0];
646 Char seqCharRet
[] = xBT2
->setSequenceChar(_arChar
);
647 bRet
= check( compareData(seqCharRet
, _arChar
), "sequence test") && bRet
;
648 Int16 _arShort
[] = new Int16
[0];
649 Int16 seqShortRet
[] = xBT2
->setSequenceShort(_arShort
);
650 bRet
= check( compareData(seqShortRet
, _arShort
), "sequence test") && bRet
;
651 Int32 _arLong
[] = new Int32
[0];
652 Int32 seqLongRet
[] = xBT2
->setSequenceLong(_arLong
);
653 bRet
= check( compareData(seqLongRet
, _arLong
), "sequence test") && bRet
;
654 Int64 _arHyper
[] = new Int64
[0];
655 Int64 seqHyperRet
[] = xBT2
->setSequenceHyper(_arHyper
);
656 bRet
= check( compareData(seqHyperRet
, _arHyper
), "sequence test") && bRet
;
657 Single _arFloat
[] = new Single
[0];
658 Single seqFloatRet
[] = xBT2
->setSequenceFloat(_arFloat
);
659 bRet
= check( compareData(seqFloatRet
, _arFloat
), "sequence test") && bRet
;
660 Double _arDouble
[] = new Double
[0];
661 Double seqDoubleRet
[] = xBT2
->setSequenceDouble(_arDouble
);
662 bRet
= check( compareData(seqDoubleRet
, _arDouble
), "sequence test") && bRet
;
663 TestEnum _arEnum
[] = new TestEnum
[0];
664 xBT2
->setSequenceEnum(_arEnum
);
665 UInt16 _arUShort
[] = new UInt16
[0];
666 UInt16 seqUShortRet
[] = xBT2
->setSequenceUShort(_arUShort
);
667 bRet
= check( compareData(seqUShortRet
, _arUShort
), "sequence test") && bRet
;
668 UInt32 _arULong
[] = new UInt32
[0];
669 UInt32 seqULongRet
[] = xBT2
->setSequenceULong(_arULong
);
670 bRet
= check( compareData(seqULongRet
, _arULong
), "sequence test") && bRet
;
671 UInt64 _arUHyper
[] = new UInt64
[0];
672 UInt64 seqUHyperRet
[] = xBT2
->setSequenceUHyper(_arUHyper
);
673 bRet
= check( compareData(seqUHyperRet
, _arUHyper
), "sequence test") && bRet
;
674 Object
* _arObject
[] = new Object
*[0];
675 Object
* seqObjectRet
[] = xBT2
->setSequenceXInterface(_arObject
);
676 bRet
= check( compareData(seqObjectRet
, _arObject
), "sequence test") && bRet
;
677 String
* _arString
[] = new String
*[0];
678 String
* seqStringRet
[] = xBT2
->setSequenceString(_arString
);
679 bRet
= check( compareData(seqStringRet
, _arString
), "sequence test") && bRet
;
680 TestElement
* _arStruct
[] = new TestElement
*[0];
681 TestElement
* seqStructRet
[] = xBT2
->setSequenceStruct(_arStruct
);
682 bRet
= check( compareData(seqStructRet
, _arStruct
), "sequence test") && bRet
;
687 /** Test the System::Object method on the proxy object
689 static bool testObjectMethodsImplemention(XBridgeTest
* xLBT
)
692 Object
* obj
= new Object();
693 XBridgeTestBase
* xBase
= dynamic_cast<XBridgeTestBase
*>(xLBT
);
697 ret
= xLBT
->Equals(obj
) == false;
698 ret
= xLBT
->Equals(xLBT
) && ret
;
699 ret
= Object::Equals(obj
, obj
) && ret
;
700 ret
= Object::Equals(xLBT
, xBase
) && ret
;
702 // Don't know how to verify this. Currently it is not possible to get the object id from a proxy
703 int nHash
= xLBT
->GetHashCode();
704 ret
= nHash
== xBase
->GetHashCode() && ret
;
707 // Don't know how to verify this automatically.
708 String
* s
= xLBT
->ToString();
709 ret
= (s
->Length
> 0) && ret
;
714 static bool raiseOnewayException(XBridgeTest
* xLBT
)
717 String
* sCompare
= Constants::STRING_TEST_CONSTANT
;
720 // Note : the exception may fly or not (e.g. remote scenario).
721 // When it flies, it must contain the correct elements.
722 xLBT
->raiseRuntimeExceptionOneway(sCompare
, xLBT
->Interface
);
724 catch (RuntimeException
* e
)
726 bReturn
= ( xLBT
->Interface
== e
->Context
);
732 static bool raiseException(XBridgeTest
* xLBT
)
741 xLBT
->raiseException(
742 5, Constants::STRING_TEST_CONSTANT
, xLBT
->Interface
);
744 catch (unoidl::com::sun::star::lang::IllegalArgumentException
* aExc
)
746 if (aExc
->ArgumentPosition
== 5 &&
747 aExc
->Context
== xLBT
->Interface
)
753 check( false, "### unexpected exception content!" );
756 /** it is certain, that the RuntimeException testing will fail,
758 xLBT
->RuntimeException
= 0;
761 catch (unoidl::com::sun::star::uno::RuntimeException
* rExc
)
763 if (rExc
->Context
== xLBT
->Interface
)
769 check( false, "### unexpected exception content!" );
772 /** it is certain, that the RuntimeException testing will fail, if no */
773 xLBT
->RuntimeException
= (int) 0xcafebabe;
776 catch (unoidl::com::sun::star::uno::Exception
* rExc
)
778 if (rExc
->Context
== xLBT
->Interface
)
785 check( false, "### unexpected exception content!" );
787 return (nCount
== 3);
792 static private void perform_test( XBridgeTest
* xLBT
)
795 bRet
= check( performTest( xLBT
), "standard test" ) && bRet
;
796 bRet
= check( raiseException( xLBT
) , "exception test" )&& bRet
;
797 bRet
= check( raiseOnewayException( xLBT
), "oneway exception test" ) && bRet
;
798 bRet
= check( testObjectMethodsImplemention(xLBT
), "object methods test") && bRet
;
799 bRet
= performQueryForUnknownType( xLBT
) && bRet
;
802 throw new unoidl::com::sun::star::uno::RuntimeException(
803 new String("error: test failed!"), 0);
806 XComponentContext
* m_xContext
;
809 BridgeTest( XComponentContext
* xContext
)
811 m_xContext
= xContext
;
816 int run( String
* args
[] )
820 if (args
->Length
< 1)
822 throw new RuntimeException(
823 "missing argument for bridgetest!", this );
826 m_xContext
->getServiceManager()->createInstanceWithContext(
827 args
[ 0 ], m_xContext
);
829 test_obj
= m_xContext
->getValueByName( args
[ 0 ] ).Value
;
832 "cli target bridgetest obj: {0}", test_obj
->ToString() );
833 XBridgeTest
* xTest
= __try_cast
<XBridgeTest
*>(test_obj
) ;
834 perform_test( xTest
);
835 Console::WriteLine( "\n### cli_uno C++ bridgetest succeeded." );
838 catch (unoidl::com::sun::star::uno::RuntimeException
* )
842 catch (System::Exception
* exc
)
844 System::Text::StringBuilder
* s
= new System::Text::StringBuilder();
845 s
->Append(S
"cli_cpp_bridgetest: unexpected exception occurred in XMain::run. Original exception: ");
846 s
->Append(exc
->GetType()->Name
);
847 s
->Append(S
"\n Message: ");
848 s
->Append(exc
->Message
);
849 throw new unoidl::com::sun::star::uno::RuntimeException(
857 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */