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
);
280 static bool performAnyTest(XBridgeTest
* xLBT
, TestDataElements
* data
)
283 bReturn
= testAny( 0, __box(data
->Byte
), xLBT
) && bReturn
;
284 bReturn
= testAny( 0, __box(data
->Short
), xLBT
) && bReturn
;
285 bReturn
= testAny( 0, __box(data
->UShort
), xLBT
) && bReturn
;
286 bReturn
= testAny( 0, __box(data
->Long
), xLBT
) && bReturn
;
287 bReturn
= testAny( 0, __box(data
->ULong
), xLBT
) && bReturn
;
288 bReturn
= testAny( 0, __box(data
->Hyper
), xLBT
) && bReturn
;
289 bReturn
= testAny( 0, __box(data
->UHyper
), xLBT
) && bReturn
;
290 bReturn
= testAny( 0, __box(data
->Float
), xLBT
) && bReturn
;
291 bReturn
= testAny( 0, __box(data
->Double
),xLBT
) && bReturn
;
292 bReturn
= testAny( 0, __box(data
->Enum
), xLBT
) && bReturn
;
293 bReturn
= testAny( 0, data
->String
,xLBT
) && bReturn
;
294 bReturn
= testAny(__typeof(XWeak
), data
->Interface
,xLBT
) && bReturn
;
295 bReturn
= testAny(0, data
, xLBT
) && bReturn
;
299 Any a2
= xLBT
->transportAny( a1
);
300 bReturn
= compareData(__box(a2
), __box(a1
)) && bReturn
;
305 Any a2
= xLBT
->transportAny(a1
);
306 bReturn
= compareData( __box(a2
), __box(a1
)) && bReturn
;
311 static bool performSequenceOfCallTest(XBridgeTest
* xLBT
)
314 int nGlobalIndex
= 0;
315 const int nWaitTimeSpanMUSec
= 10000;
316 for( nRounds
= 0 ; nRounds
< 10 ; nRounds
++ )
318 for( i
= 0 ; i
< nRounds
; i
++ )
321 xLBT
->callOneway(nGlobalIndex
, nWaitTimeSpanMUSec
);
326 xLBT
->call(nGlobalIndex
, nWaitTimeSpanMUSec
);
329 return xLBT
->sequenceOfCallTestPassed();
333 static bool performRecursiveCallTest(XBridgeTest
* xLBT
)
335 xLBT
->startRecursiveCall(new ORecursiveCall(), 50);
336 // on failure, the test would lock up or crash
340 static bool performQueryForUnknownType(XBridgeTest
* xLBT
)
343 // test queryInterface for an unknown type
346 __try_cast
<foo::MyInterface
*>(xLBT
);
348 catch( System::InvalidCastException
*)
357 static bool performTest(XBridgeTest
* xLBT
)
359 check( xLBT
!= 0, "### no test interface!" );
363 // this data is never ever granted access to by calls other than equals(), assign()!
364 TestDataElements
* aData
= new TestDataElements(); // test against this data
366 Object
* xI
= new WeakBase();
368 Any
aAny( __typeof(Object
), xI
);
369 assign( static_cast<TestElement
*>(aData
),
370 true, '@', 17, 0x1234, 0xfedc, 0x12345678, 0xfedcba98,
371 0x123456789abcdef0, 0xfedcba9876543210,
372 17.0815f
, 3.1415926359, TestEnum::LOLA
,
373 Constants::STRING_TEST_CONSTANT
, xI
,
376 bRet
= check( aData
->Any
.Value
== xI
, "### unexpected any!" ) && bRet
;
377 bRet
= check( !(aData
->Any
.Value
!= xI
), "### unexpected any!" ) && bRet
;
379 aData
->Sequence
= new TestElement
*[2];
380 aData
->Sequence
[0] = new TestElement(
381 aData
->Bool
, aData
->Char
, aData
->Byte
, aData
->Short
,
382 aData
->UShort
, aData
->Long
, aData
->ULong
,
383 aData
->Hyper
, aData
->UHyper
, aData
->Float
,
384 aData
->Double
, aData
->Enum
, aData
->String
,
385 aData
->Interface
, aData
->Any
); //(TestElement) aData;
386 aData
->Sequence
[1] = new TestElement(); //is empty
390 // this is a manually copy of aData for first setting...
391 TestDataElements
* aSetData
= new TestDataElements
;
392 Any
aAnySet(__typeof(Object
), xI
);
393 assign( static_cast<TestElement
*>(aSetData
),
399 aData
->Long
, aData
->ULong
, aData
->Hyper
, aData
->UHyper
, aData
->Float
, aData
->Double
,
405 aSetData
->Sequence
= new TestElement
*[2];
406 aSetData
->Sequence
[0] = new TestElement(
407 aSetData
->Bool
, aSetData
->Char
, aSetData
->Byte
, aSetData
->Short
,
408 aSetData
->UShort
, aSetData
->Long
, aSetData
->ULong
,
409 aSetData
->Hyper
, aSetData
->UHyper
, aSetData
->Float
,
410 aSetData
->Double
, aSetData
->Enum
, aSetData
->String
,
411 aSetData
->Interface
, aSetData
->Any
); //TestElement) aSetData;
412 aSetData
->Sequence
[1] = new TestElement(); // empty struct
415 aSetData
->Bool
, aSetData
->Char
, aSetData
->Byte
, aSetData
->Short
, aSetData
->UShort
,
416 aSetData
->Long
, aSetData
->ULong
, aSetData
->Hyper
, aSetData
->UHyper
, aSetData
->Float
, aSetData
->Double
,
417 aSetData
->Enum
, aSetData
->String
, aSetData
->Interface
, aSetData
->Any
, aSetData
->Sequence
, aSetData
);
420 TestDataElements
* aRet
= new TestDataElements();
421 TestDataElements
* aRet2
= new TestDataElements();
423 & aRet
->Bool
, & aRet
->Char
, & aRet
->Byte
, & aRet
->Short
, & aRet
->UShort
,
424 & aRet
->Long
, & aRet
->ULong
, & aRet
->Hyper
, & aRet
->UHyper
,
425 & aRet
->Float
, & aRet
->Double
, & aRet
->Enum
, & aRet
->String
,
426 & aRet
->Interface
, & aRet
->Any
, & aRet
->Sequence
, & aRet2
);
428 bRet
= check( compareData( aData
, aRet
) && compareData( aData
, aRet2
) , "getValues test") && bRet
;
430 // set last retrieved values
431 TestDataElements
* aSV2ret
= xLBT
->setValues2(
432 & aRet
->Bool
, & aRet
->Char
, & aRet
->Byte
, & aRet
->Short
, & aRet
->UShort
,
433 & aRet
->Long
, & aRet
->ULong
, & aRet
->Hyper
, & aRet
->UHyper
, & aRet
->Float
,
434 & aRet
->Double
, & aRet
->Enum
, & aRet
->String
, & aRet
->Interface
, & aRet
->Any
,
435 & aRet
->Sequence
, & aRet2
);
437 // check inout sequence order
438 // => inout sequence parameter was switched by test objects
439 TestElement
* temp
= aRet
->Sequence
[ 0 ];
440 aRet
->Sequence
[ 0 ] = aRet
->Sequence
[ 1 ];
441 aRet
->Sequence
[ 1 ] = temp
;
444 compareData( aData
, aSV2ret
) && compareData( aData
, aRet2
),
445 "getValues2 test") && bRet
;
448 TestDataElements
* aRet
= new TestDataElements();
449 TestDataElements
* aRet2
= new TestDataElements();
450 TestDataElements
* aGVret
= xLBT
->getValues(
451 & aRet
->Bool
, & aRet
->Char
, & aRet
->Byte
, & aRet
->Short
,
452 & aRet
->UShort
, & aRet
->Long
, & aRet
->ULong
, & aRet
->Hyper
,
453 & aRet
->UHyper
, & aRet
->Float
, & aRet
->Double
, & aRet
->Enum
,
454 & aRet
->String
, & aRet
->Interface
, & aRet
->Any
, & aRet
->Sequence
,
457 bRet
= check( compareData( aData
, aRet
) && compareData( aData
, aRet2
) && compareData( aData
, aGVret
), "getValues test" ) && bRet
;
459 // set last retrieved values
460 xLBT
->Bool
= aRet
->Bool
;
461 xLBT
->Char
= aRet
->Char
;
462 xLBT
->Byte
= aRet
->Byte
;
463 xLBT
->Short
= aRet
->Short
;
464 xLBT
->UShort
= aRet
->UShort
;
465 xLBT
->Long
= aRet
->Long
;
466 xLBT
->ULong
= aRet
->ULong
;
467 xLBT
->Hyper
= aRet
->Hyper
;
468 xLBT
->UHyper
= aRet
->UHyper
;
469 xLBT
->Float
= aRet
->Float
;
470 xLBT
->Double
= aRet
->Double
;
471 xLBT
->Enum
= aRet
->Enum
;
472 xLBT
->String
= aRet
->String
;
473 xLBT
->Interface
= aRet
->Interface
;
474 xLBT
->Any
= aRet
->Any
;
475 xLBT
->Sequence
= aRet
->Sequence
;
476 xLBT
->Struct
= aRet2
;
479 TestDataElements
* aRet
= new TestDataElements();
480 TestDataElements
* aRet2
= new TestDataElements();
481 aRet
->Hyper
= xLBT
->Hyper
;
482 aRet
->UHyper
= xLBT
->UHyper
;
483 aRet
->Float
= xLBT
->Float
;
484 aRet
->Double
= xLBT
->Double
;
485 aRet
->Byte
= xLBT
->Byte
;
486 aRet
->Char
= xLBT
->Char
;
487 aRet
->Bool
= xLBT
->Bool
;
488 aRet
->Short
= xLBT
->Short
;
489 aRet
->UShort
= xLBT
->UShort
;
490 aRet
->Long
= xLBT
->Long
;
491 aRet
->ULong
= xLBT
->ULong
;
492 aRet
->Enum
= xLBT
->Enum
;
493 aRet
->String
= xLBT
->String
;
494 aRet
->Interface
= xLBT
->Interface
;
495 aRet
->Any
= xLBT
->Any
;
496 aRet
->Sequence
= xLBT
->Sequence
;
497 aRet2
= xLBT
->Struct
;
499 bRet
= check( compareData( aData
, aRet
) && compareData( aData
, aRet2
) , "struct comparison test") && bRet
;
501 bRet
= check(performSequenceTest(xLBT
), "sequence test") && bRet
;
504 bRet
= check( performAnyTest( xLBT
, aData
) , "any test" ) && bRet
;
506 // sequence of call test
507 bRet
= check( performSequenceOfCallTest( xLBT
) , "sequence of call test" ) && bRet
;
509 // recursive call test
510 bRet
= check( performRecursiveCallTest( xLBT
) , "recursive test" ) && bRet
;
512 bRet
= (compareData( aData
, aRet
) && compareData( aData
, aRet2
)) && bRet
;
514 // check setting of null reference
516 aRet
->Interface
= xLBT
->Interface
;
517 bRet
= (aRet
->Interface
== 0) && bRet
;
525 static bool performSequenceTest(XBridgeTest
* xBT
)
528 XBridgeTest2
* xBT2
= dynamic_cast<XBridgeTest2
*>(xBT
);
532 // perform sequence tests (XBridgeTest2)
533 // create the sequence which are compared with the results
534 bool arBool __gc
[] = new bool __gc
[3];
535 arBool
[0] = true; arBool
[1] = false; arBool
[2] = true;
536 Char arChar
[] = new Char
[3];
537 arChar
[0] = 'A'; arChar
[1] = 'B'; arChar
[2] = 'C';
538 Byte arByte
[] = new Byte
[3];
539 arByte
[0] = 1; arByte
[1] = 2; arByte
[2] = 0xff;
540 Int16 arShort
[] = new Int16
[3];
541 arShort
[0] = Int16::MinValue
; arShort
[1] = 1; arShort
[2] = Int16::MaxValue
;
542 UInt16 arUShort
[] = new UInt16
[3];
543 arUShort
[0] = UInt16::MinValue
; arUShort
[1] = 1; arUShort
[2] = UInt16::MaxValue
;
544 Int32 arLong
[] = new Int32
[3];
545 arLong
[0] = Int32::MinValue
; arLong
[1] = 1; arLong
[2] = Int32::MaxValue
;
546 UInt32 arULong
[] = new UInt32
[3];
547 arULong
[0] = UInt32::MinValue
; arULong
[1] = 1; arULong
[2] = UInt32::MaxValue
;
548 Int64 arHyper
[] = new Int64
[3];
549 arHyper
[0] = Int64::MinValue
; arHyper
[1] = 1; arHyper
[2] = Int64::MaxValue
;
550 UInt64 arUHyper
[] = new UInt64
[3];
551 arUHyper
[0] = UInt64::MinValue
; arUHyper
[1] = 1;
552 arUHyper
[2] = UInt64::MaxValue
;
553 Single arFloat
[] = new Single
[3];
554 arFloat
[0] = 1.1f
; arFloat
[1] = 2.2f
; arFloat
[2] = 3.3f
;
555 Double arDouble
[] = new Double
[3];
556 arDouble
[0] = 1.11; arDouble
[1] = 2.22; arDouble
[2] = 3.33;
557 String
* arString
[] = new String
*[3];
558 arString
[0] = new String("String 1");
559 arString
[1] = new String("String 2");
560 arString
[2] = new String("String 3");
562 Any arAny
[] = new Any
[3];
563 arAny
[0] = Any(true); arAny
[1] = Any(11111); arAny
[2] = Any(3.14);
564 Object
* arObject
[] = new Object
*[3];
565 arObject
[0] = new WeakBase(); arObject
[1] = new WeakBase();
566 arObject
[1] = new WeakBase();
568 Console::WriteLine(new String("cli_cpp_bridgetest: Workaround for C++ compiler bug:"
569 " using Array of Int32 instead of Array of enums w"));
570 Int32 arEnum
[] = new Int32
[3];
571 arEnum
[0] = static_cast<Int32
>(TestEnum::ONE
);
572 arEnum
[1] = static_cast<Int32
>(TestEnum::TWO
);
573 arEnum
[2] = static_cast<Int32
>(TestEnum::CHECK
);
575 TestElement
* arStruct
[] = new TestElement
*[3];
576 arStruct
[0] = new TestElement(); arStruct
[1] = new TestElement();
577 arStruct
[2] = new TestElement();
578 assign( arStruct
[0], true, '@', 17, 0x1234, 0xfedc, 0x12345678, 0xfedcba98,
579 0x123456789abcdef0, 0xfedcba9876543210, 17.0815f
, 3.1415926359,
580 TestEnum::LOLA
, Constants::STRING_TEST_CONSTANT
, arObject
[0],
581 Any( __typeof(Object
), arObject
[0]) );
582 assign( arStruct
[1], true, 'A', 17, 0x1234, 0xfedc, 0x12345678, 0xfedcba98,
583 0x123456789abcdef0, 0xfedcba9876543210, 17.0815f
, 3.1415926359,
584 TestEnum::TWO
, Constants::STRING_TEST_CONSTANT
, arObject
[1],
585 Any( __typeof(Object
), arObject
[1]) );
586 assign( arStruct
[2], true, 'B', 17, 0x1234, 0xfedc, 0x12345678, 0xfedcba98,
587 0x123456789abcdef0, 0xfedcba9876543210, 17.0815f
, 3.1415926359,
588 TestEnum::CHECK
, Constants::STRING_TEST_CONSTANT
, arObject
[2],
589 Any( __typeof(Object
), arObject
[2] ) );
591 Any seqAnyRet
[] = xBT2
->setSequenceAny(arAny
);
592 bRet
= check( compareData(seqAnyRet
, arAny
), "sequence test") && bRet
;
593 Boolean seqBoolRet
[] = xBT2
->setSequenceBool(arBool
);
594 bRet
= check( compareData(seqBoolRet
, arBool
), "sequence test") && bRet
;
595 Byte seqByteRet
[] = xBT2
->setSequenceByte(arByte
);
596 bRet
= check( compareData(seqByteRet
, arByte
), "sequence test") && bRet
;
597 Char seqCharRet
[] = xBT2
->setSequenceChar(arChar
);
598 bRet
= check( compareData(seqCharRet
, arChar
), "sequence test") && bRet
;
599 Int16 seqShortRet
[] = xBT2
->setSequenceShort(arShort
);
600 bRet
= check( compareData(seqShortRet
, arShort
), "sequence test") && bRet
;
601 Int32 seqLongRet
[] = xBT2
->setSequenceLong(arLong
);
602 bRet
= check( compareData(seqLongRet
, arLong
), "sequence test") && bRet
;
603 Int64 seqHyperRet
[] = xBT2
->setSequenceHyper(arHyper
);
604 bRet
= check( compareData(seqHyperRet
,arHyper
), "sequence test") && bRet
;
605 Single seqFloatRet
[] = xBT2
->setSequenceFloat(arFloat
);
606 bRet
= check( compareData(seqFloatRet
, arFloat
), "sequence test") && bRet
;
607 Double seqDoubleRet
[] = xBT2
->setSequenceDouble(arDouble
);
608 bRet
= check( compareData(seqDoubleRet
, arDouble
), "sequence test") && bRet
;
609 xBT2
->setSequenceEnum(arEnum
);
610 //comparing seqEnumRet with arEnum will fail since they are of different
611 //types because of workaround. arEnum is Int32[].
612 Console::WriteLine(new String("cli_cpp_bridgetest: Test omitted because "
613 "of C++ compiler bug. XBridgeTest2::setSequenceEnum(sequence<TestEnum>)"));
614 UInt16 seqUShortRet
[] = xBT2
->setSequenceUShort(arUShort
);
615 bRet
= check( compareData(seqUShortRet
, arUShort
), "sequence test") && bRet
;
616 UInt32 seqULongRet
[] = xBT2
->setSequenceULong(arULong
);
617 bRet
= check( compareData(seqULongRet
, arULong
), "sequence test") && bRet
;
618 UInt64 seqUHyperRet
[] = xBT2
->setSequenceUHyper(arUHyper
);
619 bRet
= check( compareData(seqUHyperRet
, arUHyper
), "sequence test") && bRet
;
620 Object
* seqObjectRet
[] = xBT2
->setSequenceXInterface(arObject
);
621 bRet
= check( compareData(seqObjectRet
, arObject
), "sequence test") && bRet
;
622 String
* seqStringRet
[] = xBT2
->setSequenceString(arString
);
623 bRet
= check( compareData(seqStringRet
, arString
), "sequence test") && bRet
;
624 TestElement
* seqStructRet
[] = xBT2
->setSequenceStruct(arStruct
);
625 bRet
= check( compareData(seqStructRet
, arStruct
), "sequence test") && bRet
;
628 Console::WriteLine(new String("cli_cpp_bridgetest: no test of "
629 "XBridgeTest2::setSequencesInOut and XBridgeTest2.setSequencesOut "
630 "because jagged arrays are not supported by C++ compiler"));
633 Any _arAny
[] = new Any
[0];
634 Any seqAnyRet
[] = xBT2
->setSequenceAny(_arAny
);
635 bRet
= check( compareData(seqAnyRet
, _arAny
), "sequence test") && bRet
;
636 Boolean _arBool
[] = new Boolean
[0];
637 Boolean seqBoolRet
[] = xBT2
->setSequenceBool(_arBool
);
638 bRet
= check( compareData(seqBoolRet
, _arBool
), "sequence test") && bRet
;
639 Byte _arByte
[] = new Byte
[0];
640 Byte seqByteRet
[] = xBT2
->setSequenceByte(_arByte
);
641 bRet
= check( compareData(seqByteRet
, _arByte
), "sequence test") && bRet
;
642 Char _arChar
[] = new Char
[0];
643 Char seqCharRet
[] = xBT2
->setSequenceChar(_arChar
);
644 bRet
= check( compareData(seqCharRet
, _arChar
), "sequence test") && bRet
;
645 Int16 _arShort
[] = new Int16
[0];
646 Int16 seqShortRet
[] = xBT2
->setSequenceShort(_arShort
);
647 bRet
= check( compareData(seqShortRet
, _arShort
), "sequence test") && bRet
;
648 Int32 _arLong
[] = new Int32
[0];
649 Int32 seqLongRet
[] = xBT2
->setSequenceLong(_arLong
);
650 bRet
= check( compareData(seqLongRet
, _arLong
), "sequence test") && bRet
;
651 Int64 _arHyper
[] = new Int64
[0];
652 Int64 seqHyperRet
[] = xBT2
->setSequenceHyper(_arHyper
);
653 bRet
= check( compareData(seqHyperRet
, _arHyper
), "sequence test") && bRet
;
654 Single _arFloat
[] = new Single
[0];
655 Single seqFloatRet
[] = xBT2
->setSequenceFloat(_arFloat
);
656 bRet
= check( compareData(seqFloatRet
, _arFloat
), "sequence test") && bRet
;
657 Double _arDouble
[] = new Double
[0];
658 Double seqDoubleRet
[] = xBT2
->setSequenceDouble(_arDouble
);
659 bRet
= check( compareData(seqDoubleRet
, _arDouble
), "sequence test") && bRet
;
660 TestEnum _arEnum
[] = new TestEnum
[0];
661 xBT2
->setSequenceEnum(_arEnum
);
662 UInt16 _arUShort
[] = new UInt16
[0];
663 UInt16 seqUShortRet
[] = xBT2
->setSequenceUShort(_arUShort
);
664 bRet
= check( compareData(seqUShortRet
, _arUShort
), "sequence test") && bRet
;
665 UInt32 _arULong
[] = new UInt32
[0];
666 UInt32 seqULongRet
[] = xBT2
->setSequenceULong(_arULong
);
667 bRet
= check( compareData(seqULongRet
, _arULong
), "sequence test") && bRet
;
668 UInt64 _arUHyper
[] = new UInt64
[0];
669 UInt64 seqUHyperRet
[] = xBT2
->setSequenceUHyper(_arUHyper
);
670 bRet
= check( compareData(seqUHyperRet
, _arUHyper
), "sequence test") && bRet
;
671 Object
* _arObject
[] = new Object
*[0];
672 Object
* seqObjectRet
[] = xBT2
->setSequenceXInterface(_arObject
);
673 bRet
= check( compareData(seqObjectRet
, _arObject
), "sequence test") && bRet
;
674 String
* _arString
[] = new String
*[0];
675 String
* seqStringRet
[] = xBT2
->setSequenceString(_arString
);
676 bRet
= check( compareData(seqStringRet
, _arString
), "sequence test") && bRet
;
677 TestElement
* _arStruct
[] = new TestElement
*[0];
678 TestElement
* seqStructRet
[] = xBT2
->setSequenceStruct(_arStruct
);
679 bRet
= check( compareData(seqStructRet
, _arStruct
), "sequence test") && bRet
;
684 /** Test the System::Object method on the proxy object
686 static bool testObjectMethodsImplemention(XBridgeTest
* xLBT
)
689 Object
* obj
= new Object();
690 XBridgeTestBase
* xBase
= dynamic_cast<XBridgeTestBase
*>(xLBT
);
694 ret
= xLBT
->Equals(obj
) == false;
695 ret
= xLBT
->Equals(xLBT
) && ret
;
696 ret
= Object::Equals(obj
, obj
) && ret
;
697 ret
= Object::Equals(xLBT
, xBase
) && ret
;
699 // Don't know how to verify this. Currently it is not possible to get the object id from a proxy
700 int nHash
= xLBT
->GetHashCode();
701 ret
= nHash
== xBase
->GetHashCode() && ret
;
704 // Don't know how to verify this automatically.
705 String
* s
= xLBT
->ToString();
706 ret
= (s
->Length
> 0) && ret
;
711 static bool raiseOnewayException(XBridgeTest
* xLBT
)
714 String
* sCompare
= Constants::STRING_TEST_CONSTANT
;
717 // Note : the exception may fly or not (e.g. remote scenario).
718 // When it flies, it must contain the correct elements.
719 xLBT
->raiseRuntimeExceptionOneway(sCompare
, xLBT
->Interface
);
721 catch (RuntimeException
* e
)
723 bReturn
= ( xLBT
->Interface
== e
->Context
);
729 static bool raiseException(XBridgeTest
* xLBT
)
738 xLBT
->raiseException(
739 5, Constants::STRING_TEST_CONSTANT
, xLBT
->Interface
);
741 catch (unoidl::com::sun::star::lang::IllegalArgumentException
* aExc
)
743 if (aExc
->ArgumentPosition
== 5 &&
744 aExc
->Context
== xLBT
->Interface
)
750 check( false, "### unexpected exception content!" );
753 /** it is certain, that the RuntimeException testing will fail,
755 xLBT
->RuntimeException
= 0;
758 catch (unoidl::com::sun::star::uno::RuntimeException
* rExc
)
760 if (rExc
->Context
== xLBT
->Interface
)
766 check( false, "### unexpected exception content!" );
769 /** it is certain, that the RuntimeException testing will fail, if no */
770 xLBT
->RuntimeException
= (int) 0xcafebabe;
773 catch (unoidl::com::sun::star::uno::Exception
* rExc
)
775 if (rExc
->Context
== xLBT
->Interface
)
782 check( false, "### unexpected exception content!" );
784 return (nCount
== 3);
789 static private void perform_test( XBridgeTest
* xLBT
)
792 bRet
= check( performTest( xLBT
), "standard test" ) && bRet
;
793 bRet
= check( raiseException( xLBT
) , "exception test" )&& bRet
;
794 bRet
= check( raiseOnewayException( xLBT
), "oneway exception test" ) && bRet
;
795 bRet
= check( testObjectMethodsImplemention(xLBT
), "object methods test") && bRet
;
796 bRet
= performQueryForUnknownType( xLBT
) && bRet
;
799 throw new unoidl::com::sun::star::uno::RuntimeException(
800 new String("error: test failed!"), 0);
803 XComponentContext
* m_xContext
;
806 explicit BridgeTest( XComponentContext
* xContext
)
808 m_xContext
= xContext
;
812 int run( String
* args
[] )
816 if (args
->Length
< 1)
818 throw new RuntimeException(
819 "missing argument for bridgetest!", this );
822 m_xContext
->getServiceManager()->createInstanceWithContext(
823 args
[ 0 ], m_xContext
);
825 test_obj
= m_xContext
->getValueByName( args
[ 0 ] ).Value
;
828 "cli target bridgetest obj: {0}", test_obj
->ToString() );
829 XBridgeTest
* xTest
= __try_cast
<XBridgeTest
*>(test_obj
) ;
830 perform_test( xTest
);
831 Console::WriteLine( "\n### cli_uno C++ bridgetest succeeded." );
834 catch (unoidl::com::sun::star::uno::RuntimeException
* )
838 catch (System::Exception
* exc
)
840 System::Text::StringBuilder
* s
= new System::Text::StringBuilder();
841 s
->Append(S
"cli_cpp_bridgetest: unexpected exception occurred in XMain::run. Original exception: ");
842 s
->Append(exc
->GetType()->Name
);
843 s
->Append(S
"\n Message: ");
844 s
->Append(exc
->Message
);
845 throw new unoidl::com::sun::star::uno::RuntimeException(
853 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */