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_cpp_bridgetest.cxx,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 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
31 * Copyright 2008 by Sun Microsystems, Inc.
33 * OpenOffice.org - a multi-platform office productivity suite
35 * $RCSfile: cli_cpp_bridgetest.cxx,v $
38 * This file is part of OpenOffice.org.
40 * OpenOffice.org is free software: you can redistribute it and/or modify
41 * it under the terms of the GNU Lesser General Public License version 3
42 * only, as published by the Free Software Foundation.
44 * OpenOffice.org is distributed in the hope that it will be useful,
45 * but WITHOUT ANY WARRANTY; without even the implied warranty of
46 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
47 * GNU Lesser General Public License version 3 for more details
48 * (a copy is included in the LICENSE file that accompanied this code).
50 * You should have received a copy of the GNU Lesser General Public License
51 * version 3 along with OpenOffice.org. If not, see
52 * <http://www.openoffice.org/license.html>
53 * for a copy of the LGPLv3 License.
56 ************************************************************************/
58 // MARKER(update_precomp.py): autogen include statement, do not remove
59 #include "precompiled_testtools.hxx"
63 #using <cli_basetypes.dll>
64 #using <cli_uretypes.dll>
66 #using <cli_types_bridgetest.dll>
68 using namespace System
;
69 using namespace System::Diagnostics
;
70 using namespace System::Reflection
;
71 using namespace System::Threading
;
73 using namespace uno::util
;
74 using namespace unoidl::com::sun::star::uno
;
75 using namespace unoidl::com::sun::star::lang
;
76 //using namespace unoidl::com::sun::star::test::bridge;
77 using namespace unoidl::test::testtools::bridgetest
;
80 public __gc __interface MyInterface
85 namespace cpp_bridgetest
87 __gc
class ORecursiveCall
: public WeakBase
, public XRecursiveCall
90 void callRecursivly(XRecursiveCall
* xCall
, int nToCall
)
99 xCall
->callRecursivly(this, nToCall
);
111 public __gc
class Constants
114 static String
* STRING_TEST_CONSTANT
= new String(S
"\" paco\' chorizo\\\' \"\'");
117 public __gc
class BridgeTest
: public WeakBase
, public XMain
119 static bool compareData(Object
* val1
, Object
* val2
)
121 if (val1
== 0 && val2
== 0 || val1
== val2
)
123 if ((val1
== 0 && val2
!= 0) ||
124 (val1
!= 0 && val2
== 0) || val1
->GetType() != val2
->GetType())
128 Type
* t1
= val1
->GetType();
132 ret
= compareSequence(static_cast<Array
*>(val1
),
133 static_cast<Array
*>(val2
));
136 else if (t1
== __typeof(String
))
138 ret
= val1
->Equals(val2
);
140 // Interface implementation
141 else if (t1
->GetInterfaces()->Length
> 0 && ! t1
->IsValueType
)
146 else if ( ! t1
->IsValueType
)
148 ret
= compareStruct(val1
, val2
);
150 else if (t1
== __typeof(Any
))
154 ret
= a1
.Type
== a2
.Type
&& compareData(a1
.Value
, a2
.Value
);
156 else if (t1
->IsValueType
)
158 //Any, enum, int, bool char, float, double etc.
159 ret
= val1
->Equals(val2
);
163 Debug::Assert(false);
168 // Arrays have only one dimension
169 static bool compareSequence(Array
* ar1
, Array
* ar2
)
171 Debug::Assert(ar1
!= 0 && ar2
!= 0);
172 Type
* t1
= ar1
->GetType();
173 Type
* t2
= ar2
->GetType();
175 if (!(ar1
->Rank
== 1 && ar2
->Rank
== 1
176 && ar1
->Length
== ar2
->Length
&& t1
->GetElementType() == t2
->GetElementType()))
179 //arrays have same rank and size and element type.
180 int len
= ar1
->Length
;
182 for (int i
= 0; i
< len
; i
++)
184 if (compareData(ar1
->GetValue(i
), ar2
->GetValue(i
)) == false)
193 static bool compareStruct(Object
* val1
, Object
* val2
)
195 Debug::Assert(val1
!= 0 && val2
!= 0);
196 Type
* t1
= val1
->GetType();
197 Type
* t2
= val2
->GetType();
200 FieldInfo
* fields
[] = t1
->GetFields();
201 int cFields
= fields
->Length
;
203 for (int i
= 0; i
< cFields
; i
++)
205 Object
* fieldVal1
= fields
[i
]->GetValue(val1
);
206 Object
* fieldVal2
= fields
[i
]->GetValue(val2
);
207 if ( ! compareData(fieldVal1
, fieldVal2
))
216 static bool check( bool b
, String
* message
)
219 Console::WriteLine("{0} failed\n" , message
);
223 static bool equals(TestElement
* rData1
, TestElement
* rData2
)
225 check( rData1
->Bool
== rData2
->Bool
, "### bool does not match!" );
226 check( rData1
->Char
== rData2
->Char
, "### char does not match!" );
227 check( rData1
->Byte
== rData2
->Byte
, "### byte does not match!" );
228 check( rData1
->Short
== rData2
->Short
, "### short does not match!" );
229 check( rData1
->UShort
== rData2
->UShort
, "### unsigned short does not match!" );
230 check( rData1
->Long
== rData2
->Long
, "### long does not match!" );
231 check( rData1
->ULong
== rData2
->ULong
, "### unsigned long does not match!" );
232 check( rData1
->Hyper
== rData2
->Hyper
, "### hyper does not match!" );
233 check( rData1
->UHyper
== rData2
->UHyper
, "### unsigned hyper does not match!" );
234 check( rData1
->Float
== rData2
->Float
, "### float does not match!" );
235 check( rData1
->Double
== rData2
->Double
, "### double does not match!" );
236 check( rData1
->Enum
== rData2
->Enum
, "### enum does not match!" );
237 check( rData1
->String
== rData2
->String
, "### string does not match!" );
238 check( rData1
->Interface
== rData2
->Interface
, "### interface does not match!" );
239 check( compareData(__box(rData1
->Any
), __box(rData2
->Any
)), "### any does not match!" );
241 return (rData1
->Bool
== rData2
->Bool
&&
242 rData1
->Char
== rData2
->Char
&&
243 rData1
->Byte
== rData2
->Byte
&&
244 rData1
->Short
== rData2
->Short
&&
245 rData1
->UShort
== rData2
->UShort
&&
246 rData1
->Long
== rData2
->Long
&&
247 rData1
->ULong
== rData2
->ULong
&&
248 rData1
->Hyper
== rData2
->Hyper
&&
249 rData1
->UHyper
== rData2
->UHyper
&&
250 rData1
->Float
== rData2
->Float
&&
251 rData1
->Double
== rData2
->Double
&&
252 rData1
->Enum
== rData2
->Enum
&&
253 rData1
->String
== rData2
->String
&&
254 rData1
->Interface
== rData2
->Interface
&&
255 compareData(__box(rData1
->Any
), __box(rData2
->Any
)));
258 static void assign( TestElement
* rData
,
259 bool bBool
, Char cChar
, Byte nByte
,
260 Int16 nShort
, UInt16 nUShort
,
261 Int32 nLong
, UInt32 nULong
,
262 Int64 nHyper
, UInt64 nUHyper
,
263 float fFloat
, double fDouble
,
264 TestEnum eEnum
, String
* rStr
,
271 rData
->Short
= nShort
;
272 rData
->UShort
= nUShort
;
274 rData
->ULong
= nULong
;
275 rData
->Hyper
= nHyper
;
276 rData
->UHyper
= nUHyper
;
277 rData
->Float
= fFloat
;
278 rData
->Double
= fDouble
;
280 rData
->String
= rStr
;
281 rData
->Interface
= xTest
;
285 static void assign( TestDataElements
* rData
,
286 bool bBool
, Char cChar
, Byte nByte
,
287 Int16 nShort
, UInt16 nUShort
,
288 Int32 nLong
, UInt32 nULong
,
289 Int64 nHyper
, UInt64 nUHyper
,
290 float fFloat
, double fDouble
,
291 TestEnum eEnum
, String
* rStr
,
294 TestElement
* rSequence
[])
296 assign( static_cast<TestElement
*>(rData
),
297 bBool
, cChar
, nByte
, nShort
, nUShort
, nLong
, nULong
, nHyper
, nUHyper
, fFloat
, fDouble
,
298 eEnum
, rStr
, xTest
, rAny
);
299 rData
->Sequence
= rSequence
;
302 static bool testAny(Type
* typ
, Object
* value
, XBridgeTest
* xLBT
)
306 any
= Any(value
->GetType(), value
);
308 any
= Any(typ
, value
);
310 Any any2
= xLBT
->transportAny(any
);
311 bool ret
= compareData(__box(any
), __box(any2
));
314 Console::WriteLine("any is different after roundtrip: in {0}, out {1}\n",
315 any
.Type
->FullName
, any2
.Type
->FullName
);
322 static bool performAnyTest(XBridgeTest
* xLBT
, TestDataElements
* data
)
325 bReturn
= testAny( 0, __box(data
->Byte
), xLBT
) && bReturn
;
326 bReturn
= testAny( 0, __box(data
->Short
), xLBT
) && bReturn
;
327 bReturn
= testAny( 0, __box(data
->UShort
), xLBT
) && bReturn
;
328 bReturn
= testAny( 0, __box(data
->Long
), xLBT
) && bReturn
;
329 bReturn
= testAny( 0, __box(data
->ULong
), xLBT
) && bReturn
;
330 bReturn
= testAny( 0, __box(data
->Hyper
), xLBT
) && bReturn
;
331 bReturn
= testAny( 0, __box(data
->UHyper
), xLBT
) && bReturn
;
332 bReturn
= testAny( 0, __box(data
->Float
), xLBT
) && bReturn
;
333 bReturn
= testAny( 0, __box(data
->Double
),xLBT
) && bReturn
;
334 bReturn
= testAny( 0, __box(data
->Enum
), xLBT
) && bReturn
;
335 bReturn
= testAny( 0, data
->String
,xLBT
) && bReturn
;
336 bReturn
= testAny(__typeof(XWeak
), data
->Interface
,xLBT
) && bReturn
;
337 bReturn
= testAny(0, data
, xLBT
) && bReturn
;
341 Any a2
= xLBT
->transportAny( a1
);
342 bReturn
= compareData(__box(a2
), __box(a1
)) && bReturn
;
347 Any a2
= xLBT
->transportAny(a1
);
348 bReturn
= compareData( __box(a2
), __box(a1
)) && bReturn
;
353 static bool performSequenceOfCallTest(XBridgeTest
* xLBT
)
356 int nGlobalIndex
= 0;
357 const int nWaitTimeSpanMUSec
= 10000;
358 for( nRounds
= 0 ; nRounds
< 10 ; nRounds
++ )
360 for( i
= 0 ; i
< nRounds
; i
++ )
363 xLBT
->callOneway(nGlobalIndex
, nWaitTimeSpanMUSec
);
368 xLBT
->call(nGlobalIndex
, nWaitTimeSpanMUSec
);
371 return xLBT
->sequenceOfCallTestPassed();
377 static bool performRecursiveCallTest(XBridgeTest
* xLBT
)
379 xLBT
->startRecursiveCall(new ORecursiveCall(), 50);
380 // on failure, the test would lock up or crash
384 static bool performQueryForUnknownType(XBridgeTest
* xLBT
)
387 // test queryInterface for an unknown type
390 __try_cast
<foo::MyInterface
*>(xLBT
);
392 catch( System::InvalidCastException
*)
400 // //==================================================================================================
401 static bool performTest(XBridgeTest
* xLBT
)
403 check( xLBT
!= 0, "### no test interface!" );
407 // this data is never ever granted access to by calls other than equals(), assign()!
408 TestDataElements
* aData
= new TestDataElements(); // test against this data
410 Object
* xI
= new WeakBase();
412 Any
aAny( __typeof(Object
), xI
);
413 assign( static_cast<TestElement
*>(aData
),
414 true, '@', 17, 0x1234, 0xfedc, 0x12345678, 0xfedcba98,
415 0x123456789abcdef0, 0xfedcba9876543210,
416 17.0815f
, 3.1415926359, TestEnum::LOLA
,
417 Constants::STRING_TEST_CONSTANT
, xI
,
420 bRet
= check( aData
->Any
.Value
== xI
, "### unexpected any!" ) && bRet
;
421 bRet
= check( !(aData
->Any
.Value
!= xI
), "### unexpected any!" ) && bRet
;
423 aData
->Sequence
= new TestElement
*[2];
424 aData
->Sequence
[0] = new TestElement(
425 aData
->Bool
, aData
->Char
, aData
->Byte
, aData
->Short
,
426 aData
->UShort
, aData
->Long
, aData
->ULong
,
427 aData
->Hyper
, aData
->UHyper
, aData
->Float
,
428 aData
->Double
, aData
->Enum
, aData
->String
,
429 aData
->Interface
, aData
->Any
); //(TestElement) aData;
430 aData
->Sequence
[1] = new TestElement(); //is empty
434 // this is a manually copy of aData for first setting...
435 TestDataElements
* aSetData
= new TestDataElements
;
436 Any
aAnySet(__typeof(Object
), xI
);
437 assign( static_cast<TestElement
*>(aSetData
),
443 aData
->Long
, aData
->ULong
, aData
->Hyper
, aData
->UHyper
, aData
->Float
, aData
->Double
,
449 aSetData
->Sequence
= new TestElement
*[2];
450 aSetData
->Sequence
[0] = new TestElement(
451 aSetData
->Bool
, aSetData
->Char
, aSetData
->Byte
, aSetData
->Short
,
452 aSetData
->UShort
, aSetData
->Long
, aSetData
->ULong
,
453 aSetData
->Hyper
, aSetData
->UHyper
, aSetData
->Float
,
454 aSetData
->Double
, aSetData
->Enum
, aSetData
->String
,
455 aSetData
->Interface
, aSetData
->Any
); //TestElement) aSetData;
456 aSetData
->Sequence
[1] = new TestElement(); // empty struct
459 aSetData
->Bool
, aSetData
->Char
, aSetData
->Byte
, aSetData
->Short
, aSetData
->UShort
,
460 aSetData
->Long
, aSetData
->ULong
, aSetData
->Hyper
, aSetData
->UHyper
, aSetData
->Float
, aSetData
->Double
,
461 aSetData
->Enum
, aSetData
->String
, aSetData
->Interface
, aSetData
->Any
, aSetData
->Sequence
, aSetData
);
464 TestDataElements
* aRet
= new TestDataElements();
465 TestDataElements
* aRet2
= new TestDataElements();
467 & aRet
->Bool
, & aRet
->Char
, & aRet
->Byte
, & aRet
->Short
, & aRet
->UShort
,
468 & aRet
->Long
, & aRet
->ULong
, & aRet
->Hyper
, & aRet
->UHyper
,
469 & aRet
->Float
, & aRet
->Double
, & aRet
->Enum
, & aRet
->String
,
470 & aRet
->Interface
, & aRet
->Any
, & aRet
->Sequence
, & aRet2
);
472 bRet
= check( compareData( aData
, aRet
) && compareData( aData
, aRet2
) , "getValues test") && bRet
;
474 // set last retrieved values
475 TestDataElements
* aSV2ret
= xLBT
->setValues2(
476 & aRet
->Bool
, & aRet
->Char
, & aRet
->Byte
, & aRet
->Short
, & aRet
->UShort
,
477 & aRet
->Long
, & aRet
->ULong
, & aRet
->Hyper
, & aRet
->UHyper
, & aRet
->Float
,
478 & aRet
->Double
, & aRet
->Enum
, & aRet
->String
, & aRet
->Interface
, & aRet
->Any
,
479 & aRet
->Sequence
, & aRet2
);
481 // check inout sequence order
482 // => inout sequence parameter was switched by test objects
483 TestElement
* temp
= aRet
->Sequence
[ 0 ];
484 aRet
->Sequence
[ 0 ] = aRet
->Sequence
[ 1 ];
485 aRet
->Sequence
[ 1 ] = temp
;
488 compareData( aData
, aSV2ret
) && compareData( aData
, aRet2
),
489 "getValues2 test") && bRet
;
492 TestDataElements
* aRet
= new TestDataElements();
493 TestDataElements
* aRet2
= new TestDataElements();
494 TestDataElements
* aGVret
= xLBT
->getValues(
495 & aRet
->Bool
, & aRet
->Char
, & aRet
->Byte
, & aRet
->Short
,
496 & aRet
->UShort
, & aRet
->Long
, & aRet
->ULong
, & aRet
->Hyper
,
497 & aRet
->UHyper
, & aRet
->Float
, & aRet
->Double
, & aRet
->Enum
,
498 & aRet
->String
, & aRet
->Interface
, & aRet
->Any
, & aRet
->Sequence
,
501 bRet
= check( compareData( aData
, aRet
) && compareData( aData
, aRet2
) && compareData( aData
, aGVret
), "getValues test" ) && bRet
;
503 // set last retrieved values
504 xLBT
->Bool
= aRet
->Bool
;
505 xLBT
->Char
= aRet
->Char
;
506 xLBT
->Byte
= aRet
->Byte
;
507 xLBT
->Short
= aRet
->Short
;
508 xLBT
->UShort
= aRet
->UShort
;
509 xLBT
->Long
= aRet
->Long
;
510 xLBT
->ULong
= aRet
->ULong
;
511 xLBT
->Hyper
= aRet
->Hyper
;
512 xLBT
->UHyper
= aRet
->UHyper
;
513 xLBT
->Float
= aRet
->Float
;
514 xLBT
->Double
= aRet
->Double
;
515 xLBT
->Enum
= aRet
->Enum
;
516 xLBT
->String
= aRet
->String
;
517 xLBT
->Interface
= aRet
->Interface
;
518 xLBT
->Any
= aRet
->Any
;
519 xLBT
->Sequence
= aRet
->Sequence
;
520 xLBT
->Struct
= aRet2
;
523 TestDataElements
* aRet
= new TestDataElements();
524 TestDataElements
* aRet2
= new TestDataElements();
525 aRet
->Hyper
= xLBT
->Hyper
;
526 aRet
->UHyper
= xLBT
->UHyper
;
527 aRet
->Float
= xLBT
->Float
;
528 aRet
->Double
= xLBT
->Double
;
529 aRet
->Byte
= xLBT
->Byte
;
530 aRet
->Char
= xLBT
->Char
;
531 aRet
->Bool
= xLBT
->Bool
;
532 aRet
->Short
= xLBT
->Short
;
533 aRet
->UShort
= xLBT
->UShort
;
534 aRet
->Long
= xLBT
->Long
;
535 aRet
->ULong
= xLBT
->ULong
;
536 aRet
->Enum
= xLBT
->Enum
;
537 aRet
->String
= xLBT
->String
;
538 aRet
->Interface
= xLBT
->Interface
;
539 aRet
->Any
= xLBT
->Any
;
540 aRet
->Sequence
= xLBT
->Sequence
;
541 aRet2
= xLBT
->Struct
;
543 bRet
= check( compareData( aData
, aRet
) && compareData( aData
, aRet2
) , "struct comparison test") && bRet
;
545 bRet
= check(performSequenceTest(xLBT
), "sequence test") && bRet
;
548 bRet
= check( performAnyTest( xLBT
, aData
) , "any test" ) && bRet
;
550 // sequence of call test
551 bRet
= check( performSequenceOfCallTest( xLBT
) , "sequence of call test" ) && bRet
;
553 // recursive call test
554 bRet
= check( performRecursiveCallTest( xLBT
) , "recursive test" ) && bRet
;
556 bRet
= (compareData( aData
, aRet
) && compareData( aData
, aRet2
)) && bRet
;
558 // check setting of null reference
560 aRet
->Interface
= xLBT
->Interface
;
561 bRet
= (aRet
->Interface
== 0) && bRet
;
569 static bool performSequenceTest(XBridgeTest
* xBT
)
572 XBridgeTest2
* xBT2
= dynamic_cast<XBridgeTest2
*>(xBT
);
576 // perform sequence tests (XBridgeTest2)
577 // create the sequence which are compared with the results
578 bool arBool __gc
[] = new bool __gc
[3];
579 arBool
[0] = true; arBool
[1] = false; arBool
[2] = true;
580 Char arChar
[] = new Char
[3];
581 arChar
[0] = 'A'; arChar
[1] = 'B'; arChar
[2] = 'C';
582 Byte arByte
[] = new Byte
[3];
583 arByte
[0] = 1; arByte
[1] = 2; arByte
[2] = 0xff;
584 Int16 arShort
[] = new Int16
[3];
585 arShort
[0] = Int16::MinValue
; arShort
[1] = 1; arShort
[2] = Int16::MaxValue
;
586 UInt16 arUShort
[] = new UInt16
[3];
587 arUShort
[0] = UInt16::MinValue
; arUShort
[1] = 1; arUShort
[2] = UInt16::MaxValue
;
588 Int32 arLong
[] = new Int32
[3];
589 arLong
[0] = Int32::MinValue
; arLong
[1] = 1; arLong
[2] = Int32::MaxValue
;
590 UInt32 arULong
[] = new UInt32
[3];
591 arULong
[0] = UInt32::MinValue
; arULong
[1] = 1; arULong
[2] = UInt32::MaxValue
;
592 Int64 arHyper
[] = new Int64
[3];
593 arHyper
[0] = Int64::MinValue
; arHyper
[1] = 1; arHyper
[2] = Int64::MaxValue
;
594 UInt64 arUHyper
[] = new UInt64
[3];
595 arUHyper
[0] = UInt64::MinValue
; arUHyper
[1] = 1;
596 arUHyper
[2] = UInt64::MaxValue
;
597 Single arFloat
[] = new Single
[3];
598 arFloat
[0] = 1.1f
; arFloat
[1] = 2.2f
; arFloat
[2] = 3.3f
;
599 Double arDouble
[] = new Double
[3];
600 arDouble
[0] = 1.11; arDouble
[1] = 2.22; arDouble
[2] = 3.33;
601 String
* arString
[] = new String
*[3];
602 arString
[0] = new String("String 1");
603 arString
[1] = new String("String 2");
604 arString
[2] = new String("String 3");
606 Any arAny
[] = new Any
[3];
607 arAny
[0] = Any(true); arAny
[1] = Any(11111); arAny
[2] = Any(3.14);
608 Object
* arObject
[] = new Object
*[3];
609 arObject
[0] = new WeakBase(); arObject
[1] = new WeakBase();
610 arObject
[1] = new WeakBase();
612 //TestEnum arEnum[] = new TestEnum[3];
613 //arEnum[0] = TestEnum::ONE; arEnum[1] = TestEnum::TWO;
614 //arEnum[2] = TestEnum::CHECK;
615 Console::WriteLine(new String("cli_cpp_bridgetest: Workaround for C++ compiler bug:"
616 " using Array of Int32 instead of Array of enums w"));
617 Int32 arEnum
[] = new Int32
[3];
618 arEnum
[0] = static_cast<Int32
>(TestEnum::ONE
);
619 arEnum
[1] = static_cast<Int32
>(TestEnum::TWO
);
620 arEnum
[2] = static_cast<Int32
>(TestEnum::CHECK
);
622 TestElement
* arStruct
[] = new TestElement
*[3];
623 arStruct
[0] = new TestElement(); arStruct
[1] = new TestElement();
624 arStruct
[2] = new TestElement();
625 assign( arStruct
[0], true, '@', 17, 0x1234, 0xfedc, 0x12345678, 0xfedcba98,
626 0x123456789abcdef0, 0xfedcba9876543210, 17.0815f
, 3.1415926359,
627 TestEnum::LOLA
, Constants::STRING_TEST_CONSTANT
, arObject
[0],
628 Any( __typeof(Object
), arObject
[0]) );
629 assign( arStruct
[1], true, 'A', 17, 0x1234, 0xfedc, 0x12345678, 0xfedcba98,
630 0x123456789abcdef0, 0xfedcba9876543210, 17.0815f
, 3.1415926359,
631 TestEnum::TWO
, Constants::STRING_TEST_CONSTANT
, arObject
[1],
632 Any( __typeof(Object
), arObject
[1]) );
633 assign( arStruct
[2], true, 'B', 17, 0x1234, 0xfedc, 0x12345678, 0xfedcba98,
634 0x123456789abcdef0, 0xfedcba9876543210, 17.0815f
, 3.1415926359,
635 TestEnum::CHECK
, Constants::STRING_TEST_CONSTANT
, arObject
[2],
636 Any( __typeof(Object
), arObject
[2] ) );
639 // int[][][] arLong3 = new int[][][]{
640 // new int[][]{new int[]{1,2,3},new int[]{4,5,6}, new int[]{7,8,9} },
641 // new int [][]{new int[]{1,2,3},new int[]{4,5,6}, new int[]{7,8,9}},
642 // new int[][]{new int[]{1,2,3},new int[]{4,5,6}, new int[]{7,8,9}}};
646 // Console::WriteLine(new String("cli_cpp_bridgetest:
647 // int[][] seqSeqRet = xBT2->setDim2(arLong3[0]);
648 // bRet = check( compareData(seqSeqRet, arLong3[0]), "sequence test") && bRet;
649 // int[][][] seqSeqRet2 = xBT2->setDim3(arLong3);
650 // bRet = check( compareData(seqSeqRet2, arLong3), "sequence test") && bRet;
652 Any seqAnyRet
[] = xBT2
->setSequenceAny(arAny
);
653 bRet
= check( compareData(seqAnyRet
, arAny
), "sequence test") && bRet
;
654 Boolean seqBoolRet
[] = xBT2
->setSequenceBool(arBool
);
655 bRet
= check( compareData(seqBoolRet
, arBool
), "sequence test") && bRet
;
656 Byte seqByteRet
[] = xBT2
->setSequenceByte(arByte
);
657 bRet
= check( compareData(seqByteRet
, arByte
), "sequence test") && bRet
;
658 Char seqCharRet
[] = xBT2
->setSequenceChar(arChar
);
659 bRet
= check( compareData(seqCharRet
, arChar
), "sequence test") && bRet
;
660 Int16 seqShortRet
[] = xBT2
->setSequenceShort(arShort
);
661 bRet
= check( compareData(seqShortRet
, arShort
), "sequence test") && bRet
;
662 Int32 seqLongRet
[] = xBT2
->setSequenceLong(arLong
);
663 bRet
= check( compareData(seqLongRet
, arLong
), "sequence test") && bRet
;
664 Int64 seqHyperRet
[] = xBT2
->setSequenceHyper(arHyper
);
665 bRet
= check( compareData(seqHyperRet
,arHyper
), "sequence test") && bRet
;
666 Single seqFloatRet
[] = xBT2
->setSequenceFloat(arFloat
);
667 bRet
= check( compareData(seqFloatRet
, arFloat
), "sequence test") && bRet
;
668 Double seqDoubleRet
[] = xBT2
->setSequenceDouble(arDouble
);
669 bRet
= check( compareData(seqDoubleRet
, arDouble
), "sequence test") && bRet
;
670 xBT2
->setSequenceEnum(arEnum
);
671 //comparing seqEnumRet with arEnum will fail since they are of different
672 //types because of workaround. arEnum is Int32[].
673 Console::WriteLine(new String("cli_cpp_bridgetest: Test omitted because "
674 "of C++ compiler bug. XBridgeTest2::setSequenceEnum(sequence<TestEnum>)"));
675 // bRet = check( compareData(seqEnumRet, arEnum), "sequence test") && bRet;
676 UInt16 seqUShortRet
[] = xBT2
->setSequenceUShort(arUShort
);
677 bRet
= check( compareData(seqUShortRet
, arUShort
), "sequence test") && bRet
;
678 UInt32 seqULongRet
[] = xBT2
->setSequenceULong(arULong
);
679 bRet
= check( compareData(seqULongRet
, arULong
), "sequence test") && bRet
;
680 UInt64 seqUHyperRet
[] = xBT2
->setSequenceUHyper(arUHyper
);
681 bRet
= check( compareData(seqUHyperRet
, arUHyper
), "sequence test") && bRet
;
682 Object
* seqObjectRet
[] = xBT2
->setSequenceXInterface(arObject
);
683 bRet
= check( compareData(seqObjectRet
, arObject
), "sequence test") && bRet
;
684 String
* seqStringRet
[] = xBT2
->setSequenceString(arString
);
685 bRet
= check( compareData(seqStringRet
, arString
), "sequence test") && bRet
;
686 TestElement
* seqStructRet
[] = xBT2
->setSequenceStruct(arStruct
);
687 bRet
= check( compareData(seqStructRet
, arStruct
), "sequence test") && bRet
;
690 // Boolean arBoolTemp[] = static_cast<Boolean[]>( arBool->Clone());
691 // Char arCharTemp[] = static_cast<Char[]>(arChar->Clone());
692 // Byte arByteTemp[] = static_cast<Byte[]>(arByte->Clone());
693 // Int16 arShortTemp[] = static_cast<Int16[]>(arShort->Clone());
694 // UInt16 arUShortTemp[] = static_cast<UInt16[]>(arUShort->Clone());
695 // Int32 arLongTemp[] = static_cast<Int32[]>(arLong->Clone());
696 // UInt32 arULongTemp[] = static_cast<UInt32[]>(arULong->Clone());
697 // Int64 arHyperTemp[] = static_cast<Int64[]>(arHyper->Clone());
698 // UInt64 arUHyperTemp[] = static_cast<UInt64[]>(arUHyper->Clone());
699 // Single arFloatTemp[] = static_cast<Single[]>(arFloat->Clone());
700 // Double arDoubleTemp[] = static_cast<Double[]>(arDouble->Clone());
701 // TestEnum arEnumTemp[] = static_cast<TestEnum[]>(arEnum->Clone());
702 // String* arStringTemp[] = static_cast<String*[]>(arString->Clone());
703 // Object* arObjectTemp = static_cast<Object*[]>(arObject->Clone());
704 // Any arAnyTemp[] = static_cast<Any[]>(arAny->Clone());
705 // // make sure this are has the same contents as arLong3[0]
706 // int[][] arLong2Temp = new int[][]{new int[]{1,2,3},new int[]{4,5,6}, new int[]{7,8,9} };
707 // // make sure this are has the same contents as arLong3
708 // int[][][] arLong3Temp = new int[][][]{
709 // new int[][]{new int[]{1,2,3},new int[]{4,5,6}, new int[]{7,8,9} },
710 // new int [][]{new int[]{1,2,3},new int[]{4,5,6}, new int[]{7,8,9}},
711 // new int[][]{new int[]{1,2,3},new int[]{4,5,6}, new int[]{7,8,9}}};
712 Console::WriteLine(new String("cli_cpp_bridgetest: no test of "
713 "XBridgeTest2::setSequencesInOut and XBridgeTest2.setSequencesOut "
714 "because jagged arrays are not supported by C++ compiler"));
715 // xBT2->setSequencesInOut(& arBoolTemp, & arCharTemp, & arByteTemp,
716 // & arShortTemp, & arUShortTemp, & arLongTemp,
717 // & arULongTemp,& arHyperTemp, & arUHyperTemp,
718 // & arFloatTemp,& arDoubleTemp, & arEnumTemp,
719 // & arStringTemp, & arObjectTemp,
720 // & arAnyTemp, & arLong2Temp, & arLong3Temp);
722 // compareData(arBoolTemp, arBool) &&
723 // compareData(arCharTemp , arChar) &&
724 // compareData(arByteTemp , arByte) &&
725 // compareData(arShortTemp , arShort) &&
726 // compareData(arUShortTemp , arUShort) &&
727 // compareData(arLongTemp , arLong) &&
728 // compareData(arULongTemp , arULong) &&
729 // compareData(arHyperTemp , arHyper) &&
730 // compareData(arUHyperTemp , arUHyper) &&
731 // compareData(arFloatTemp , arFloat) &&
732 // compareData(arDoubleTemp , arDouble) &&
733 // compareData(arEnumTemp , arEnum) &&
734 // compareData(arStringTemp , arString) &&
735 // compareData(arObjectTemp , arObject) &&
736 // compareData(arAnyTemp , arAny) &&
737 // compareData(arLong2Temp , arLong3[0]) &&
738 // compareData(arLong3Temp , arLong3), "sequence test") && bRet;
740 //Boolean arBoolOut[];
743 //Int16 arShortOut[];
744 //UInt16 arUShortOut[];
746 //UInt32 arULongOut[];
747 //Int64 arHyperOut[];
748 //UInt64 arUHyperOut[];
749 //Single arFloatOut[];
750 //Double arDoubleOut[];
751 //TestEnum arEnumOut[];
752 //String* arStringOut[];
753 //Object* arObjectOut[];
755 // int[][] arLong2Out;
756 // int[][][] arLong3Out;
758 // xBT2->setSequencesOut(out arBoolOut, out arCharOut, out arByteOut,
759 // out arShortOut, out arUShortOut, out arLongOut,
760 // out arULongOut, out arHyperOut, out arUHyperOut,
761 // out arFloatOut, out arDoubleOut, out arEnumOut,
762 // out arStringOut, out arObjectOut, out arAnyOut,
763 // out arLong2Out, out arLong3Out);
765 // compareData(arBoolOut, arBool) &&
766 // compareData(arCharOut, arChar) &&
767 // compareData(arByteOut, arByte) &&
768 // compareData(arShortOut, arShort) &&
769 // compareData(arUShortOut, arUShort) &&
770 // compareData(arLongOut, arLong) &&
771 // compareData(arULongOut, arULong) &&
772 // compareData(arHyperOut, arHyper) &&
773 // compareData(arUHyperOut, arUHyper) &&
774 // compareData(arFloatOut, arFloat) &&
775 // compareData(arDoubleOut, arDouble) &&
776 // compareData(arEnumOut, arEnum) &&
777 // compareData(arStringOut, arString) &&
778 // compareData(arObjectOut, arObject) &&
779 // compareData(arAnyOut, arAny) &&
780 // compareData(arLong2Out, arLong3[0]) &&
781 // compareData(arLong3Out, arLong3), "sequence test") && bRet;
784 //test with empty sequences
785 // int[][] _arLong2 = new int[0][];
786 // int[][] seqSeqRet = xBT2->setDim2(_arLong2);
787 // bRet = check( compareData(seqSeqRet, _arLong2), "sequence test") && bRet;
788 // int[][][] _arLong3 = new int[0][][];
789 // int[][][] seqSeqRet2 = xBT2->setDim3(_arLong3);
790 // bRet = check( compareData(seqSeqRet2, _arLong3), "sequence test") && bRet;
791 Any _arAny
[] = new Any
[0];
792 Any seqAnyRet
[] = xBT2
->setSequenceAny(_arAny
);
793 bRet
= check( compareData(seqAnyRet
, _arAny
), "sequence test") && bRet
;
794 Boolean _arBool
[] = new Boolean
[0];
795 Boolean seqBoolRet
[] = xBT2
->setSequenceBool(_arBool
);
796 bRet
= check( compareData(seqBoolRet
, _arBool
), "sequence test") && bRet
;
797 Byte _arByte
[] = new Byte
[0];
798 Byte seqByteRet
[] = xBT2
->setSequenceByte(_arByte
);
799 bRet
= check( compareData(seqByteRet
, _arByte
), "sequence test") && bRet
;
800 Char _arChar
[] = new Char
[0];
801 Char seqCharRet
[] = xBT2
->setSequenceChar(_arChar
);
802 bRet
= check( compareData(seqCharRet
, _arChar
), "sequence test") && bRet
;
803 Int16 _arShort
[] = new Int16
[0];
804 Int16 seqShortRet
[] = xBT2
->setSequenceShort(_arShort
);
805 bRet
= check( compareData(seqShortRet
, _arShort
), "sequence test") && bRet
;
806 Int32 _arLong
[] = new Int32
[0];
807 Int32 seqLongRet
[] = xBT2
->setSequenceLong(_arLong
);
808 bRet
= check( compareData(seqLongRet
, _arLong
), "sequence test") && bRet
;
809 Int64 _arHyper
[] = new Int64
[0];
810 Int64 seqHyperRet
[] = xBT2
->setSequenceHyper(_arHyper
);
811 bRet
= check( compareData(seqHyperRet
, _arHyper
), "sequence test") && bRet
;
812 Single _arFloat
[] = new Single
[0];
813 Single seqFloatRet
[] = xBT2
->setSequenceFloat(_arFloat
);
814 bRet
= check( compareData(seqFloatRet
, _arFloat
), "sequence test") && bRet
;
815 Double _arDouble
[] = new Double
[0];
816 Double seqDoubleRet
[] = xBT2
->setSequenceDouble(_arDouble
);
817 bRet
= check( compareData(seqDoubleRet
, _arDouble
), "sequence test") && bRet
;
818 TestEnum _arEnum
[] = new TestEnum
[0];
819 xBT2
->setSequenceEnum(_arEnum
);
820 // compiler bug: _arEnum has type System.Enum and not TestEnum
821 // bRet = check( compareData(seqEnumRet, _arEnum), "sequence test") && bRet;
822 UInt16 _arUShort
[] = new UInt16
[0];
823 UInt16 seqUShortRet
[] = xBT2
->setSequenceUShort(_arUShort
);
824 bRet
= check( compareData(seqUShortRet
, _arUShort
), "sequence test") && bRet
;
825 UInt32 _arULong
[] = new UInt32
[0];
826 UInt32 seqULongRet
[] = xBT2
->setSequenceULong(_arULong
);
827 bRet
= check( compareData(seqULongRet
, _arULong
), "sequence test") && bRet
;
828 UInt64 _arUHyper
[] = new UInt64
[0];
829 UInt64 seqUHyperRet
[] = xBT2
->setSequenceUHyper(_arUHyper
);
830 bRet
= check( compareData(seqUHyperRet
, _arUHyper
), "sequence test") && bRet
;
831 Object
* _arObject
[] = new Object
*[0];
832 Object
* seqObjectRet
[] = xBT2
->setSequenceXInterface(_arObject
);
833 bRet
= check( compareData(seqObjectRet
, _arObject
), "sequence test") && bRet
;
834 String
* _arString
[] = new String
*[0];
835 String
* seqStringRet
[] = xBT2
->setSequenceString(_arString
);
836 bRet
= check( compareData(seqStringRet
, _arString
), "sequence test") && bRet
;
837 TestElement
* _arStruct
[] = new TestElement
*[0];
838 TestElement
* seqStructRet
[] = xBT2
->setSequenceStruct(_arStruct
);
839 bRet
= check( compareData(seqStructRet
, _arStruct
), "sequence test") && bRet
;
844 /** Test the System::Object method on the proxy object
846 static bool testObjectMethodsImplemention(XBridgeTest
* xLBT
)
849 Object
* obj
= new Object();
850 XBridgeTestBase
* xBase
= dynamic_cast<XBridgeTestBase
*>(xLBT
);
854 ret
= xLBT
->Equals(obj
) == false;
855 ret
= xLBT
->Equals(xLBT
) && ret
;
856 ret
= Object::Equals(obj
, obj
) && ret
;
857 ret
= Object::Equals(xLBT
, xBase
) && ret
;
859 // Don't know how to verify this. Currently it is not possible to get the object id from a proxy
860 int nHash
= xLBT
->GetHashCode();
861 ret
= nHash
== xBase
->GetHashCode() && ret
;
864 // Don't know how to verify this automatically.
865 String
* s
= xLBT
->ToString();
866 ret
= (s
->Length
> 0) && ret
;
871 static bool raiseOnewayException(XBridgeTest
* xLBT
)
874 String
* sCompare
= Constants::STRING_TEST_CONSTANT
;
877 // Note : the exception may fly or not (e.g. remote scenario).
878 // When it flies, it must contain the correct elements.
879 xLBT
->raiseRuntimeExceptionOneway(sCompare
, xLBT
->Interface
);
881 catch (RuntimeException
* e
)
883 bReturn
= ( xLBT
->Interface
== e
->Context
);
888 // //==================================================================================================
889 static bool raiseException(XBridgeTest
* xLBT
)
898 xLBT
->raiseException(
899 5, Constants::STRING_TEST_CONSTANT
, xLBT
->Interface
);
901 catch (unoidl::com::sun::star::lang::IllegalArgumentException
* aExc
)
903 if (aExc
->ArgumentPosition
== 5 &&
904 aExc
->Context
== xLBT
->Interface
)
910 check( false, "### unexpected exception content!" );
913 /** it is certain, that the RuntimeException testing will fail,
915 xLBT
->RuntimeException
= 0;
918 catch (unoidl::com::sun::star::uno::RuntimeException
* rExc
)
920 if (rExc
->Context
== xLBT
->Interface
)
926 check( false, "### unexpected exception content!" );
929 /** it is certain, that the RuntimeException testing will fail, if no */
930 xLBT
->RuntimeException
= (int) 0xcafebabe;
933 catch (unoidl::com::sun::star::uno::Exception
* rExc
)
935 if (rExc
->Context
== xLBT
->Interface
)
942 check( false, "### unexpected exception content!" );
944 return (nCount
== 3);
949 static private void perform_test( XBridgeTest
* xLBT
)
952 bRet
= check( performTest( xLBT
), "standard test" ) && bRet
;
953 bRet
= check( raiseException( xLBT
) , "exception test" )&& bRet
;
954 bRet
= check( raiseOnewayException( xLBT
), "oneway exception test" ) && bRet
;
955 bRet
= check( testObjectMethodsImplemention(xLBT
), "object methods test") && bRet
;
956 bRet
= performQueryForUnknownType( xLBT
) && bRet
;
959 throw new unoidl::com::sun::star::uno::RuntimeException(
960 new String("error: test failed!"), 0);
963 XComponentContext
* m_xContext
;
966 BridgeTest( XComponentContext
* xContext
)
968 m_xContext
= xContext
;
973 int run( String
* args
[] )
977 if (args
->Length
< 1)
979 throw new RuntimeException(
980 "missing argument for bridgetest!", this );
983 m_xContext
->getServiceManager()->createInstanceWithContext(
984 args
[ 0 ], m_xContext
);
986 test_obj
= m_xContext
->getValueByName( args
[ 0 ] ).Value
;
989 "cli target bridgetest obj: {0}", test_obj
->ToString() );
990 XBridgeTest
* xTest
= __try_cast
<XBridgeTest
*>(test_obj
) ;
991 perform_test( xTest
);
992 Console::WriteLine( "\n### cli_uno C++ bridgetest succeeded." );
995 catch (unoidl::com::sun::star::uno::RuntimeException
* )
999 catch (System::Exception
* exc
)
1001 System::Text::StringBuilder
* s
= new System::Text::StringBuilder();
1002 s
->Append(S
"cli_cpp_bridgetest: unexpected exception occured in XMain::run. Original exception: ");
1003 s
->Append(exc
->GetType()->Name
);
1004 s
->Append(S
"\n Message: ");
1005 s
->Append(exc
->Message
);
1006 throw new unoidl::com::sun::star::uno::RuntimeException(