1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_testtools.hxx"
33 #include <osl/diagnose.h>
34 #include "osl/diagnose.hxx"
36 #include <sal/types.h>
37 #include "typelib/typedescription.hxx"
38 #include <uno/dispatcher.hxx>
39 #include "uno/mapping.hxx"
41 #include "uno/environment.hxx"
43 #include <cppuhelper/factory.hxx>
44 #include <cppuhelper/implbase2.hxx>
45 #include <cppuhelper/implbase1.hxx>
47 #include <com/sun/star/lang/XServiceInfo.hpp>
48 #include <com/sun/star/lang/XComponent.hpp>
49 #include <com/sun/star/lang/XMain.hpp>
50 #include <com/sun/star/bridge/UnoUrlResolver.hpp>
51 #include <com/sun/star/bridge/XUnoUrlResolver.hpp>
52 #include "com/sun/star/uno/RuntimeException.hpp"
53 #include "com/sun/star/uno/Type.hxx"
55 #include "test/testtools/bridgetest/BadConstructorArguments.hpp"
56 #include "test/testtools/bridgetest/TestPolyStruct.hpp"
57 #include "test/testtools/bridgetest/XBridgeTest.hpp"
58 #include "test/testtools/bridgetest/XBridgeTest2.hpp"
59 #include "test/testtools/bridgetest/XMulti.hpp"
61 #include "currentcontextchecker.hxx"
67 using namespace com::sun::star::uno
;
68 using namespace com::sun::star::lang
;
69 using namespace com::sun::star::registry
;
70 using namespace com::sun::star::bridge
;
71 using namespace test::testtools::bridgetest
;
73 #define SERVICENAME "com.sun.star.test.bridge.BridgeTest"
74 #define IMPLNAME "com.sun.star.comp.bridge.BridgeTest"
76 #define OUSTR(x) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(x) )
77 #define STRING_TEST_CONSTANT "\" paco\' chorizo\\\' \"\'"
82 Sequence
<T
> cloneSequence(const Sequence
<T
>& val
);
84 //--------------------------------------------------------------------------------------------------
85 inline static Sequence
< OUString
> getSupportedServiceNames()
87 OUString
aName( RTL_CONSTASCII_USTRINGPARAM(SERVICENAME
) );
88 return Sequence
< OUString
>( &aName
, 1 );
91 static bool check( bool b
, char const * message
)
94 fprintf( stderr
, "%s failed\n" , message
);
100 bool checkEmpty(rtl::OUString
const & string
, char const * message
) {
101 bool ok
= string
.getLength() == 0;
104 stderr
, "%s failed: %s\n", message
,
105 rtl::OUStringToOString(string
, RTL_TEXTENCODING_UTF8
).getStr());
112 //==================================================================================================
113 class TestBridgeImpl
: protected osl::DebugBase
<TestBridgeImpl
>,
114 public WeakImplHelper2
< XMain
, XServiceInfo
>
116 Reference
< XComponentContext
> m_xContext
;
119 TestBridgeImpl( const Reference
< XComponentContext
> & xContext
)
120 : m_xContext( xContext
)
122 virtual ~TestBridgeImpl()
127 virtual OUString SAL_CALL
getImplementationName() throw (RuntimeException
);
128 virtual sal_Bool SAL_CALL
supportsService( const OUString
& rServiceName
) throw (RuntimeException
);
129 virtual Sequence
< OUString
> SAL_CALL
getSupportedServiceNames() throw (RuntimeException
);
132 virtual sal_Int32 SAL_CALL
run( const Sequence
< OUString
> & rArgs
) throw (RuntimeException
);
135 //==================================================================================================
136 static sal_Bool
equals( const TestElement
& rData1
, const TestElement
& rData2
)
138 check( rData1
.Bool
== rData2
.Bool
, "### bool does not match!" );
139 check( rData1
.Char
== rData2
.Char
, "### char does not match!" );
140 check( rData1
.Byte
== rData2
.Byte
, "### byte does not match!" );
141 check( rData1
.Short
== rData2
.Short
, "### short does not match!" );
142 check( rData1
.UShort
== rData2
.UShort
, "### unsigned short does not match!" );
143 check( rData1
.Long
== rData2
.Long
, "### long does not match!" );
144 check( rData1
.ULong
== rData2
.ULong
, "### unsigned long does not match!" );
145 check( rData1
.Hyper
== rData2
.Hyper
, "### hyper does not match!" );
146 check( rData1
.UHyper
== rData2
.UHyper
, "### unsigned hyper does not match!" );
147 check( rData1
.Float
== rData2
.Float
, "### float does not match!" );
148 check( rData1
.Double
== rData2
.Double
, "### double does not match!" );
149 check( rData1
.Enum
== rData2
.Enum
, "### enum does not match!" );
150 check( rData1
.String
== rData2
.String
, "### string does not match!" );
151 check( rData1
.Interface
== rData2
.Interface
, "### interface does not match!" );
152 check( rData1
.Any
== rData2
.Any
, "### any does not match!" );
154 return (rData1
.Bool
== rData2
.Bool
&&
155 rData1
.Char
== rData2
.Char
&&
156 rData1
.Byte
== rData2
.Byte
&&
157 rData1
.Short
== rData2
.Short
&&
158 rData1
.UShort
== rData2
.UShort
&&
159 rData1
.Long
== rData2
.Long
&&
160 rData1
.ULong
== rData2
.ULong
&&
161 rData1
.Hyper
== rData2
.Hyper
&&
162 rData1
.UHyper
== rData2
.UHyper
&&
163 rData1
.Float
== rData2
.Float
&&
164 rData1
.Double
== rData2
.Double
&&
165 rData1
.Enum
== rData2
.Enum
&&
166 rData1
.String
== rData2
.String
&&
167 rData1
.Interface
== rData2
.Interface
&&
168 rData1
.Any
== rData2
.Any
);
170 //==================================================================================================
171 static sal_Bool
equals( const TestData
& rData1
, const TestData
& rData2
)
175 if ((rData1
.Sequence
== rData2
.Sequence
) &&
176 equals( (const TestElement
&)rData1
, (const TestElement
&)rData2
) &&
177 (nLen
= rData1
.Sequence
.getLength()) == rData2
.Sequence
.getLength())
179 // once again by hand sequence ==
180 const TestElement
* pElements1
= rData1
.Sequence
.getConstArray();
181 const TestElement
* pElements2
= rData2
.Sequence
.getConstArray();
184 if (! equals( pElements1
[nLen
], pElements2
[nLen
] ))
186 check( sal_False
, "### sequence element did not match!" );
194 //==================================================================================================
195 static void assign( TestElement
& rData
,
196 sal_Bool bBool
, sal_Unicode cChar
, sal_Int8 nByte
,
197 sal_Int16 nShort
, sal_uInt16 nUShort
,
198 sal_Int32 nLong
, sal_uInt32 nULong
,
199 sal_Int64 nHyper
, sal_uInt64 nUHyper
,
200 float fFloat
, double fDouble
,
201 TestEnum eEnum
, const ::rtl::OUString
& rStr
,
202 const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>& xTest
,
203 const ::com::sun::star::uno::Any
& rAny
)
208 rData
.Short
= nShort
;
209 rData
.UShort
= nUShort
;
211 rData
.ULong
= nULong
;
212 rData
.Hyper
= nHyper
;
213 rData
.UHyper
= nUHyper
;
214 rData
.Float
= fFloat
;
215 rData
.Double
= fDouble
;
218 rData
.Interface
= xTest
;
224 template < typename T
>
226 T
const & value
, Reference
< XBridgeTest
> const & xLBT
,
227 char const * typeName
= 0)
231 Any any2
= xLBT
->transportAny(any
);
235 stderr
, "any is different after roundtrip: in %s, out %s\n",
237 any
.getValueType().getTypeName(),
238 RTL_TEXTENCODING_ASCII_US
).getStr(),
240 any2
.getValueType().getTypeName(),
241 RTL_TEXTENCODING_ASCII_US
).getStr());
245 && !any2
.getValueType().getTypeName().equalsAscii(typeName
))
248 stderr
, "any has wrong type after roundtrip: %s instead of %s\n",
250 any2
.getValueType().getTypeName(),
251 RTL_TEXTENCODING_ASCII_US
).getStr(),
260 static sal_Bool
performAnyTest( const Reference
< XBridgeTest
> &xLBT
, const TestData
&data
)
263 bReturn
= testAny( data
.Byte
,xLBT
) && bReturn
;
264 bReturn
= testAny( data
.Short
,xLBT
) && bReturn
;
265 bReturn
= testAny( data
.UShort
,xLBT
) && bReturn
;
266 bReturn
= testAny( data
.Long
,xLBT
) && bReturn
;
267 bReturn
= testAny( data
.ULong
,xLBT
) && bReturn
;
268 bReturn
= testAny( data
.Hyper
,xLBT
) && bReturn
;
269 bReturn
= testAny( data
.UHyper
,xLBT
) && bReturn
;
270 bReturn
= testAny( data
.Float
,xLBT
) && bReturn
;
271 bReturn
= testAny( data
.Double
,xLBT
) && bReturn
;
272 bReturn
= testAny( data
.Enum
,xLBT
) && bReturn
;
273 bReturn
= testAny( data
.String
,xLBT
) && bReturn
;
274 bReturn
= testAny( data
.Interface
,xLBT
) && bReturn
;
275 bReturn
= testAny( data
, xLBT
) && bReturn
;
277 TestPolyStruct
< sal_Unicode
>(' '), xLBT
,
278 "test.testtools.bridgetest.TestPolyStruct<char>");
282 a
.setValue( &(data
.Bool
) , getCppuBooleanType() );
283 Any a2
= xLBT
->transportAny( a
);
284 OSL_ASSERT( a2
== a
);
288 a
.setValue( &(data
.Char
) , getCppuCharType() );
289 Any a2
= xLBT
->transportAny( a
);
290 OSL_ASSERT( a2
== a
);
296 //_______________________________________________________________________________________
297 static sal_Bool
performSequenceOfCallTest( const Reference
< XBridgeTest
> &xLBT
)
300 sal_Int32 nGlobalIndex
= 0;
301 const sal_Int32 nWaitTimeSpanMUSec
= 10000;
302 for( nRounds
= 0 ; nRounds
< 10 ; nRounds
++ )
304 for( i
= 0 ; i
< nRounds
; i
++ )
307 xLBT
->callOneway( nGlobalIndex
, nWaitTimeSpanMUSec
);
312 xLBT
->call( nGlobalIndex
, nWaitTimeSpanMUSec
);
316 return xLBT
->sequenceOfCallTestPassed();
319 class ORecursiveCall
: public WeakImplHelper1
< XRecursiveCall
>
325 void SAL_CALL
callRecursivly(
326 const ::com::sun::star::uno::Reference
< XRecursiveCall
>& xCall
,
328 throw(::com::sun::star::uno::RuntimeException
)
330 MutexGuard
guard( m_mutex
);
334 xCall
->callRecursivly( this , nToCall
);
341 //_______________________________________________________________________________________
342 static sal_Bool
performRecursiveCallTest( const Reference
< XBridgeTest
> & xLBT
)
344 xLBT
->startRecursiveCall( new ORecursiveCall
, 50 );
345 // on failure, the test would lock up or crash
349 class MyClass
: public osl::DebugBase
<MyClass
>, public OWeakObject
354 virtual void SAL_CALL
acquire() throw ();
355 virtual void SAL_CALL
release() throw ();
358 //______________________________________________________________________________
362 //______________________________________________________________________________
366 //______________________________________________________________________________
367 void MyClass::acquire() throw ()
369 OWeakObject::acquire();
371 //______________________________________________________________________________
372 void MyClass::release() throw ()
374 OWeakObject::release();
377 //==================================================================================================
378 static sal_Bool
performTest(
379 const Reference
<XComponentContext
> & xContext
,
380 const Reference
<XBridgeTest
> & xLBT
,
381 bool noCurrentContext
)
383 check(xLBT
.is(), "### no test interface!");
386 // this data is never ever granted access to by calls other than
387 // equals(), assign()!
388 TestData aData
; // test against this data
389 Reference
< XInterface
> xI(new MyClass
);
391 (TestElement
&) aData
, true, '@', 17, 0x1234, 0xFEDC, 0x12345678,
392 0xFEDCBA98, SAL_CONST_INT64(0x123456789ABCDEF0),
393 SAL_CONST_UINT64(0xFEDCBA9876543210), 17.0815f
, 3.1415926359,
394 TestEnum_LOLA
, OUSTR(STRING_TEST_CONSTANT
), xI
,
395 Any(&xI
, getCppuType((Reference
< XInterface
> const *) 0)));
396 bRet
&= check(aData
.Any
== xI
, "### unexpected any!");
397 bRet
&= check(!(aData
.Any
!= xI
), "### unexpected any!");
398 aData
.Sequence
.realloc(2);
399 aData
.Sequence
[0] = *(TestElement
const *) &aData
;
400 // aData.Sequence[1] is empty
401 // aSetData is a manually copy of aData for first setting:
404 (TestElement
&) aSetData
, aData
.Bool
, aData
.Char
, aData
.Byte
,
405 aData
.Short
, aData
.UShort
, aData
.Long
, aData
.ULong
, aData
.Hyper
,
406 aData
.UHyper
, aData
.Float
, aData
.Double
, aData
.Enum
, aData
.String
,
407 xI
, Any(&xI
, getCppuType((Reference
< XInterface
> const *) 0)));
408 aSetData
.Sequence
.realloc(2);
409 aSetData
.Sequence
[0] = *(TestElement
const *) &aSetData
;
410 // aSetData.Sequence[1] is empty
412 aSetData
.Bool
, aSetData
.Char
, aSetData
.Byte
, aSetData
.Short
,
413 aSetData
.UShort
, aSetData
.Long
, aSetData
.ULong
, aSetData
.Hyper
,
414 aSetData
.UHyper
, aSetData
.Float
, aSetData
.Double
, aSetData
.Enum
,
415 aSetData
.String
, aSetData
.Interface
, aSetData
.Any
,
416 aSetData
.Sequence
, aSetData
);
421 aRet
.Bool
, aRet
.Char
, aRet
.Byte
, aRet
.Short
, aRet
.UShort
,
422 aRet
.Long
, aRet
.ULong
, aRet
.Hyper
, aRet
.UHyper
, aRet
.Float
,
423 aRet
.Double
, aRet
.Enum
, aRet
.String
, aRet
.Interface
, aRet
.Any
,
424 aRet
.Sequence
, aRet2
);
426 equals(aData
, aRet
) && equals(aData
, aRet2
), "getValues test");
427 // Set last retrieved values:
430 aRet
.Bool
, aRet
.Char
, aRet
.Byte
, aRet
.Short
, aRet
.UShort
,
431 aRet
.Long
, aRet
.ULong
, aRet
.Hyper
, aRet
.UHyper
, aRet
.Float
,
432 aRet
.Double
, aRet
.Enum
, aRet
.String
, aRet
.Interface
,
433 aRet
.Any
, aRet
.Sequence
, aRet2
));
434 // Check inout sequence order (=> inout sequence parameter was
435 // switched by test objects):
436 TestElement
temp(aRet
.Sequence
[0]);
437 aRet
.Sequence
[0] = aRet
.Sequence
[1];
438 aRet
.Sequence
[1] = temp
;
440 equals(aData
, aSV2ret
) && equals(aData
, aRet2
),
448 aRet
.Bool
, aRet
.Char
, aRet
.Byte
, aRet
.Short
, aRet
.UShort
,
449 aRet
.Long
, aRet
.ULong
, aRet
.Hyper
, aRet
.UHyper
, aRet
.Float
,
450 aRet
.Double
, aRet
.Enum
, aRet
.String
, aRet
.Interface
,
451 aRet
.Any
, aRet
.Sequence
, aRet2
));
453 (equals(aData
, aRet
) && equals(aData
, aRet2
) &&
454 equals(aData
, aGVret
)),
456 // Set last retrieved values:
457 xLBT
->setBool(aRet
.Bool
);
458 xLBT
->setChar(aRet
.Char
);
459 xLBT
->setByte(aRet
.Byte
);
460 xLBT
->setShort(aRet
.Short
);
461 xLBT
->setUShort(aRet
.UShort
);
462 xLBT
->setLong(aRet
.Long
);
463 xLBT
->setULong(aRet
.ULong
);
464 xLBT
->setHyper(aRet
.Hyper
);
465 xLBT
->setUHyper(aRet
.UHyper
);
466 xLBT
->setFloat(aRet
.Float
);
467 xLBT
->setDouble(aRet
.Double
);
468 xLBT
->setEnum(aRet
.Enum
);
469 xLBT
->setString(aRet
.String
);
470 xLBT
->setInterface(aRet
.Interface
);
471 xLBT
->setAny(aRet
.Any
);
472 xLBT
->setSequence(aRet
.Sequence
);
473 xLBT
->setStruct(aRet2
);
477 aRet
.Hyper
= xLBT
->getHyper();
478 aRet
.UHyper
= xLBT
->getUHyper();
479 aRet
.Float
= xLBT
->getFloat();
480 aRet
.Double
= xLBT
->getDouble();
481 aRet
.Byte
= xLBT
->getByte();
482 aRet
.Char
= xLBT
->getChar();
483 aRet
.Bool
= xLBT
->getBool();
484 aRet
.Short
= xLBT
->getShort();
485 aRet
.UShort
= xLBT
->getUShort();
486 aRet
.Long
= xLBT
->getLong();
487 aRet
.ULong
= xLBT
->getULong();
488 aRet
.Enum
= xLBT
->getEnum();
489 aRet
.String
= xLBT
->getString();
490 aRet
.Interface
= xLBT
->getInterface();
491 aRet
.Any
= xLBT
->getAny();
492 aRet
.Sequence
= xLBT
->getSequence();
493 TestData
aRet2(xLBT
->getStruct());
495 equals(aData
, aRet
) && equals(aData
, aRet2
),
496 "struct comparison test");
498 SmallStruct
aIn(1, 2);
499 SmallStruct
aOut(xLBT
->echoSmallStruct(aIn
));
501 memcmp(&aIn
, &aOut
, sizeof(SmallStruct
)) == 0,
502 "small struct test");
505 MediumStruct
aIn(1, 2, 3, 4);
506 MediumStruct
aOut(xLBT
->echoMediumStruct(aIn
));
508 memcmp(&aIn
, &aOut
, sizeof(MediumStruct
)) == 0,
509 "medium struct test");
512 BigStruct
aIn(1, 2, 3, 4, 5, 6, 7, 8);
513 BigStruct
aOut(xLBT
->echoBigStruct(aIn
));
515 memcmp(&aIn
, &aOut
, sizeof(BigStruct
)) == 0,
519 AllFloats
aIn(1.1f
, 2.2f
, 3.3f
, 4.4f
);
520 AllFloats
aOut(xLBT
->echoAllFloats(aIn
));
522 memcmp(&aIn
, &aOut
, sizeof(AllFloats
)) == 0,
523 "all floats struct test");
526 sal_Int32 i2
= xLBT
->testPPCAlignment(0, 0, 0, 0, 0xBEAF);
527 bRet
&= check(i2
== 0xBEAF, "ppc-style alignment test");
529 // Test extended attributes that raise exceptions:
531 xLBT
->getRaiseAttr1();
532 bRet
&= check(false, "getRaiseAttr1 did not throw");
533 } catch (RuntimeException
&) {
535 bRet
&= check(false, "getRaiseAttr1 threw wrong type");
538 xLBT
->setRaiseAttr1(0);
539 bRet
&= check(false, "setRaiseAttr1 did not throw");
540 } catch (IllegalArgumentException
&) {
542 bRet
&= check(false, "setRaiseAttr1 threw wrong type");
545 xLBT
->getRaiseAttr2();
546 bRet
&= check(false, "getRaiseAttr2 did not throw");
547 } catch (IllegalArgumentException
&) {
549 bRet
&= check(false, "getRaiseAttr2 threw wrong type");
551 // Test instantiated polymorphic struct types:
554 (xLBT
->transportPolyBoolean(
555 TestPolyStruct
< sal_Bool
>(true)).
557 "transportPolyBoolean");
558 TestPolyStruct
< sal_Int64
> tps1(12345);
559 xLBT
->transportPolyHyper(tps1
);
560 bRet
&= check(tps1
.member
== 12345, "transportPolyHyper");
561 Sequence
< Any
> seq(2);
562 seq
[0] <<= static_cast< sal_uInt32
>(33);
563 seq
[1] <<= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ABC"));
564 TestPolyStruct
< Sequence
< Any
> > tps2(seq
);
565 TestPolyStruct
< Sequence
< Any
> > tps3
;
566 xLBT
->transportPolySequence(tps2
, tps3
);
568 tps3
.member
.getLength() == 2,
569 "transportPolySequence, length");
570 sal_uInt32 v0
= sal_uInt32();
571 tps3
.member
[0] >>= v0
;
572 bRet
&= check(v0
== 33, "transportPolySequence, element 0");
574 tps3
.member
[1] >>= v1
;
576 v1
.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("ABC")),
577 "transportPolySequence, element 1");
579 xLBT
->getNullPolyLong().member
== 0, "getNullPolyLong");
581 xLBT
->getNullPolyString().member
.getLength() == 0,
582 "getNullPolyString");
584 xLBT
->getNullPolyType().member
== Type(),
586 Any
nullAny(xLBT
->getNullPolyAny().member
);
588 (((nullAny
.getValueTypeName() ==
590 RTL_CONSTASCII_USTRINGPARAM(
591 "com.sun.star.uno.XInterface"))) &&
592 !static_cast< Reference
< XInterface
> const * >(
593 nullAny
.getValue())->is())
594 || nullAny
== Any()),
597 xLBT
->getNullPolySequence().member
.getLength() == 0,
598 "getNullPolySequence");
600 xLBT
->getNullPolyEnum().member
== TestEnum_TEST
,
603 xLBT
->getNullPolyBadEnum().member
== TestBadEnum_M
,
604 "getNullPolyBadEnum");
606 xLBT
->getNullPolyStruct().member
.member
== 0,
607 "getNullPolyStruct");
609 !xLBT
->getNullPolyInterface().member
.is(),
610 "getNullPolyInterface");
613 bRet
&= check(performAnyTest(xLBT
, aData
), "any test");
614 // Sequence of call test:
616 performSequenceOfCallTest(xLBT
), "sequence of call test");
617 // Recursive call test:
618 bRet
&= check(performRecursiveCallTest(xLBT
), "recursive test");
620 equals(aData
, aRet
) && equals(aData
, aRet2
),
621 "recursive test results");
622 // Multiple inheritance test:
624 testtools::bridgetest::testMulti(xLBT
->getMulti()),
627 xLBT
->testMulti(new testtools::bridgetest::Multi
),
632 Reference
< XBridgeTest2
> xBT2(xLBT
, UNO_QUERY
);
636 // Perform sequence tests (XBridgeTest2); create the sequence which is
637 // compared with the results:
638 sal_Bool _arBool
[] = { true, false, true };
639 sal_Unicode _arChar
[] = { 0x0065, 0x0066, 0x0067 };
640 sal_Int8 _arByte
[] = { 1, 2, -1 };
641 sal_Int16 _arShort
[] = { -0x8000, 1, 0x7FFF };
642 sal_uInt16 _arUShort
[] = { 0 , 1, 0xFFFF };
643 sal_Int32 _arLong
[] = { 0x80000000, 1, 0x7FFFFFFF };
644 sal_uInt32 _arULong
[] = { 0, 1, 0xFFFFFFFF };
645 sal_Int64 _arHyper
[] = {
646 SAL_CONST_INT64(0x8000000000000000), 1,
647 SAL_CONST_INT64(0x7FFFFFFFFFFFFFFF) };
648 sal_uInt64 _arUHyper
[] = { 0, 1, SAL_CONST_UINT64(0xFFFFFFFFFFFFFFFF) };
649 float _arFloat
[] = { 1.1f
, 2.2f
, 3.3f
};
650 double _arDouble
[] = { 1.11, 2.22, 3.33 };
651 OUString _arString
[] = {
652 OUString(RTL_CONSTASCII_USTRINGPARAM("String 1")),
653 OUString(RTL_CONSTASCII_USTRINGPARAM("String 2")),
654 OUString(RTL_CONSTASCII_USTRINGPARAM("String 3")) };
655 sal_Bool _aBool
= true;
656 sal_Int32 _aInt
= 0xBABEBABE;
657 float _aFloat
= 3.14f
;
658 Any
_any1(&_aBool
, getCppuBooleanType());
659 Any
_any2(&_aInt
, getCppuType((sal_Int32
*) 0));
660 Any
_any3(&_aFloat
, getCppuType((float *) 0));
661 Any _arAny
[] = { _any1
, _any2
, _any3
};
662 Reference
< XInterface
> _arObj
[3];
663 _arObj
[0] = new OWeakObject();
664 _arObj
[1] = new OWeakObject();
665 _arObj
[2] = new OWeakObject();
666 TestEnum _arEnum
[] = { TestEnum_ONE
, TestEnum_TWO
, TestEnum_CHECK
};
667 TestElement _arStruct
[3];
669 _arStruct
[0], true, '@', 17, 0x1234, 0xFEDC, 0x12345678, 0xFEDCBA98,
670 SAL_CONST_INT64(0x123456789ABCDEF0),
671 SAL_CONST_UINT64(0xFEDCBA9876543210), 17.0815f
, 3.1415926359,
672 TestEnum_LOLA
, OUSTR(STRING_TEST_CONSTANT
), _arObj
[0],
673 Any(&_arObj
[0], getCppuType((Reference
< XInterface
> const *) 0)));
675 _arStruct
[1], true, 'A', 17, 0x1234, 0xFEDC, 0x12345678, 0xFEDCBA98,
676 SAL_CONST_INT64(0x123456789ABCDEF0),
677 SAL_CONST_UINT64(0xFEDCBA9876543210), 17.0815f
, 3.1415926359,
678 TestEnum_TWO
, OUSTR(STRING_TEST_CONSTANT
), _arObj
[1],
679 Any(&_arObj
[1], getCppuType((Reference
< XInterface
> const *) 0)));
681 _arStruct
[2], true, 'B', 17, 0x1234, 0xFEDC, 0x12345678, 0xFEDCBA98,
682 SAL_CONST_INT64(0x123456789ABCDEF0),
683 SAL_CONST_UINT64(0xFEDCBA9876543210), 17.0815f
, 3.1415926359,
684 TestEnum_CHECK
, OUSTR(STRING_TEST_CONSTANT
), _arObj
[2],
685 Any(&_arObj
[2], getCppuType((Reference
< XInterface
> const *) 0)));
687 Sequence
<sal_Bool
> arBool(_arBool
, 3);
688 Sequence
<sal_Unicode
> arChar( _arChar
, 3);
689 Sequence
<sal_Int8
> arByte(_arByte
, 3);
690 Sequence
<sal_Int16
> arShort(_arShort
, 3);
691 Sequence
<sal_uInt16
> arUShort(_arUShort
, 3);
692 Sequence
<sal_Int32
> arLong(_arLong
, 3);
693 Sequence
<sal_uInt32
> arULong(_arULong
, 3);
694 Sequence
<sal_Int64
> arHyper(_arHyper
, 3);
695 Sequence
<sal_uInt64
> arUHyper(_arUHyper
, 3);
696 Sequence
<float> arFloat(_arFloat
, 3);
697 Sequence
<double> arDouble(_arDouble
, 3);
698 Sequence
<OUString
> arString(_arString
, 3);
699 Sequence
<Any
> arAny(_arAny
, 3);
700 Sequence
<Reference
<XInterface
> > arObject(_arObj
, 3);
701 Sequence
<TestEnum
> arEnum(_arEnum
, 3);
702 Sequence
<TestElement
> arStruct(_arStruct
, 3);
703 Sequence
<Sequence
<sal_Int32
> > _arSeqLong2
[3];
704 for (int j
= 0; j
!= 3; ++j
) {
705 Sequence
< sal_Int32
> _arSeqLong
[3];
706 for (int i
= 0; i
!= 3; ++i
) {
707 _arSeqLong
[i
] = Sequence
< sal_Int32
>(_arLong
, 3);
709 _arSeqLong2
[j
] = Sequence
< Sequence
< sal_Int32
> >(
712 Sequence
< Sequence
< Sequence
< sal_Int32
> > > arLong3(
714 Sequence
< Sequence
< sal_Int32
> > seqSeqRet(
715 xBT2
->setDim2(arLong3
[0]));
716 bRet
&= check(seqSeqRet
== arLong3
[0], "sequence test");
717 Sequence
< Sequence
< Sequence
< sal_Int32
> > > seqSeqRet2(
718 xBT2
->setDim3(arLong3
));
719 bRet
&= check(seqSeqRet2
== arLong3
, "sequence test");
720 Sequence
< Any
> seqAnyRet(xBT2
->setSequenceAny(arAny
));
721 bRet
&= check(seqAnyRet
== arAny
, "sequence test");
722 Sequence
< sal_Bool
> seqBoolRet(xBT2
->setSequenceBool(arBool
));
723 bRet
&= check(seqBoolRet
== arBool
, "sequence test");
724 Sequence
< sal_Int8
> seqByteRet(xBT2
->setSequenceByte(arByte
));
725 bRet
&= check(seqByteRet
== arByte
, "sequence test");
726 Sequence
< sal_Unicode
> seqCharRet(xBT2
->setSequenceChar(arChar
));
727 bRet
&= check(seqCharRet
== arChar
, "sequence test");
728 Sequence
< sal_Int16
> seqShortRet(xBT2
->setSequenceShort(arShort
));
729 bRet
&= check(seqShortRet
== arShort
, "sequence test");
730 Sequence
< sal_Int32
> seqLongRet(xBT2
->setSequenceLong(arLong
));
731 bRet
&= check(seqLongRet
== arLong
, "sequence test");
732 Sequence
< sal_Int64
> seqHyperRet(xBT2
->setSequenceHyper(arHyper
));
733 bRet
&= check(seqHyperRet
== arHyper
, "sequence test");
734 Sequence
< float > seqFloatRet(xBT2
->setSequenceFloat(arFloat
));
735 bRet
&= check(seqFloatRet
== arFloat
, "sequence test");
736 Sequence
< double > seqDoubleRet(xBT2
->setSequenceDouble(arDouble
));
737 bRet
&= check(seqDoubleRet
== arDouble
, "sequence test");
738 Sequence
< TestEnum
> seqEnumRet(xBT2
->setSequenceEnum(arEnum
));
739 bRet
&= check(seqEnumRet
== arEnum
, "sequence test");
740 Sequence
< sal_uInt16
> seqUShortRet(
741 xBT2
->setSequenceUShort(arUShort
));
742 bRet
&= check(seqUShortRet
== arUShort
, "sequence test");
743 Sequence
< sal_uInt32
> seqULongRet(xBT2
->setSequenceULong(arULong
));
744 bRet
&= check(seqULongRet
== arULong
, "sequence test");
745 Sequence
< sal_uInt64
> seqUHyperRet(
746 xBT2
->setSequenceUHyper(arUHyper
));
747 bRet
&= check(seqUHyperRet
== arUHyper
, "sequence test");
748 Sequence
< Reference
< XInterface
> > seqObjectRet(
749 xBT2
->setSequenceXInterface(arObject
));
750 bRet
&= check(seqObjectRet
== arObject
, "sequence test");
751 Sequence
< OUString
> seqStringRet(
752 xBT2
->setSequenceString(arString
));
753 bRet
&= check(seqStringRet
== arString
, "sequence test");
754 Sequence
< TestElement
> seqStructRet(
755 xBT2
->setSequenceStruct(arStruct
));
756 bRet
&= check(seqStructRet
== arStruct
, "sequence test");
757 Sequence
< sal_Bool
> arBoolTemp(cloneSequence(arBool
));
758 Sequence
< sal_Unicode
> arCharTemp(cloneSequence(arChar
));
759 Sequence
< sal_Int8
> arByteTemp(cloneSequence(arByte
));
760 Sequence
< sal_Int16
> arShortTemp(cloneSequence(arShort
));
761 Sequence
< sal_uInt16
> arUShortTemp(cloneSequence(arUShort
));
762 Sequence
< sal_Int32
> arLongTemp(cloneSequence(arLong
));
763 Sequence
< sal_uInt32
> arULongTemp(cloneSequence(arULong
));
764 Sequence
< sal_Int64
> arHyperTemp(cloneSequence(arHyper
));
765 Sequence
< sal_uInt64
> arUHyperTemp(cloneSequence(arUHyper
));
766 Sequence
< float > arFloatTemp(cloneSequence(arFloat
));
767 Sequence
< double > arDoubleTemp(cloneSequence(arDouble
));
768 Sequence
< TestEnum
> arEnumTemp(cloneSequence(arEnum
));
769 Sequence
< OUString
> arStringTemp(cloneSequence(arString
));
770 Sequence
< Reference
< XInterface
> > arObjectTemp(
771 cloneSequence(arObject
));
772 Sequence
< Any
> arAnyTemp(cloneSequence(arAny
));
773 Sequence
< Sequence
< sal_Int32
> > arLong2Temp(arLong3
[0]);
774 Sequence
< Sequence
< Sequence
< sal_Int32
> > > arLong3Temp(arLong3
);
775 xBT2
->setSequencesInOut(
776 arBoolTemp
, arCharTemp
, arByteTemp
, arShortTemp
, arUShortTemp
,
777 arLongTemp
,arULongTemp
, arHyperTemp
, arUHyperTemp
, arFloatTemp
,
778 arDoubleTemp
, arEnumTemp
, arStringTemp
, arObjectTemp
, arAnyTemp
,
779 arLong2Temp
, arLong3Temp
);
781 (arBoolTemp
== arBool
&& arCharTemp
== arChar
&&
782 arByteTemp
== arByte
&& arShortTemp
== arShort
&&
783 arUShortTemp
== arUShort
&& arLongTemp
== arLong
&&
784 arULongTemp
== arULong
&& arHyperTemp
== arHyper
&&
785 arUHyperTemp
== arUHyper
&& arFloatTemp
== arFloat
&&
786 arDoubleTemp
== arDouble
&& arEnumTemp
== arEnum
&&
787 arStringTemp
== arString
&& arObjectTemp
== arObject
&&
788 arAnyTemp
== arAny
&& arLong2Temp
== arLong3
[0] &&
789 arLong3Temp
== arLong3
),
791 Sequence
< sal_Bool
> arBoolOut
;
792 Sequence
< sal_Unicode
> arCharOut
;
793 Sequence
< sal_Int8
> arByteOut
;
794 Sequence
< sal_Int16
> arShortOut
;
795 Sequence
< sal_uInt16
> arUShortOut
;
796 Sequence
< sal_Int32
> arLongOut
;
797 Sequence
< sal_uInt32
> arULongOut
;
798 Sequence
< sal_Int64
> arHyperOut
;
799 Sequence
< sal_uInt64
> arUHyperOut
;
800 Sequence
< float > arFloatOut
;
801 Sequence
< double > arDoubleOut
;
802 Sequence
< TestEnum
> arEnumOut
;
803 Sequence
< OUString
> arStringOut
;
804 Sequence
< Reference
< XInterface
> > arObjectOut
;
805 Sequence
< Any
> arAnyOut
;
806 Sequence
< Sequence
< sal_Int32
> > arLong2Out
;
807 Sequence
< Sequence
< Sequence
< sal_Int32
> > > arLong3Out
;
808 xBT2
->setSequencesOut(
809 arBoolOut
, arCharOut
, arByteOut
, arShortOut
, arUShortOut
,
810 arLongOut
,arULongOut
, arHyperOut
, arUHyperOut
, arFloatOut
,
811 arDoubleOut
, arEnumOut
, arStringOut
, arObjectOut
, arAnyOut
,
812 arLong2Out
, arLong3Out
);
814 (arBoolOut
== arBool
&& arCharOut
== arChar
&&
815 arByteOut
== arByte
&& arShortOut
== arShort
&&
816 arUShortOut
== arUShort
&& arLongOut
== arLong
&&
817 arULongOut
== arULong
&& arHyperOut
== arHyper
&&
818 arUHyperOut
== arUHyper
&& arFloatOut
== arFloat
&&
819 arDoubleOut
== arDouble
&& arEnumOut
== arEnum
&&
820 arStringOut
== arString
&& arObjectOut
== arObject
&&
821 arAnyOut
== arAny
&& arLong2Out
== arLong3
[0] &&
822 arLong3Out
== arLong3
),
826 // Test with empty sequences:
827 Sequence
< Sequence
< sal_Int32
> > arLong2
;
828 Sequence
< Sequence
< sal_Int32
> > seqSeqRet(xBT2
->setDim2(arLong2
));
829 bRet
&= check(seqSeqRet
== arLong2
, "sequence test");
830 Sequence
< Sequence
< Sequence
< sal_Int32
> > > arLong3
;
831 Sequence
< Sequence
< Sequence
< sal_Int32
> > > seqSeqRet2(
832 xBT2
->setDim3(arLong3
));
833 bRet
&= check(seqSeqRet2
== arLong3
, "sequence test");
834 Sequence
< Any
> arAny
;
835 Sequence
< Any
> seqAnyRet(xBT2
->setSequenceAny(arAny
));
836 bRet
&= check(seqAnyRet
== arAny
, "sequence test");
837 Sequence
< sal_Bool
> arBool
;
838 Sequence
< sal_Bool
> seqBoolRet(xBT2
->setSequenceBool(arBool
));
839 bRet
&= check(seqBoolRet
== arBool
, "sequence test");
840 Sequence
< sal_Int8
> arByte
;
841 Sequence
< sal_Int8
> seqByteRet(xBT2
->setSequenceByte(arByte
));
842 bRet
&= check(seqByteRet
== arByte
, "sequence test");
843 Sequence
< sal_Unicode
> arChar
;
844 Sequence
< sal_Unicode
> seqCharRet(xBT2
->setSequenceChar(arChar
));
845 bRet
&= check(seqCharRet
== arChar
, "sequence test");
846 Sequence
< sal_Int16
> arShort
;
847 Sequence
< sal_Int16
> seqShortRet(xBT2
->setSequenceShort(arShort
));
848 bRet
&= check(seqShortRet
== arShort
, "sequence test");
849 Sequence
< sal_Int32
> arLong
;
850 Sequence
< sal_Int32
> seqLongRet(xBT2
->setSequenceLong(arLong
));
851 bRet
&= check(seqLongRet
== arLong
, "sequence test");
852 Sequence
< sal_Int64
> arHyper
;
853 Sequence
< sal_Int64
> seqHyperRet(xBT2
->setSequenceHyper(arHyper
));
854 bRet
&= check(seqHyperRet
== arHyper
, "sequence test");
855 Sequence
< float > arFloat
;
856 Sequence
< float > seqFloatRet(xBT2
->setSequenceFloat(arFloat
));
857 bRet
&= check(seqFloatRet
== arFloat
, "sequence test");
858 Sequence
< double > arDouble
;
859 Sequence
< double > seqDoubleRet(xBT2
->setSequenceDouble(arDouble
));
860 bRet
&= check(seqDoubleRet
== arDouble
, "sequence test");
861 Sequence
< TestEnum
> arEnum
;
862 Sequence
< TestEnum
> seqEnumRet(xBT2
->setSequenceEnum(arEnum
));
863 bRet
&= check(seqEnumRet
== arEnum
, "sequence test");
864 Sequence
< sal_uInt16
> arUShort
;
865 Sequence
< sal_uInt16
> seqUShortRet(
866 xBT2
->setSequenceUShort(arUShort
));
867 bRet
&= check(seqUShortRet
== arUShort
, "sequence test");
868 Sequence
< sal_uInt32
> arULong
;
869 Sequence
< sal_uInt32
> seqULongRet(xBT2
->setSequenceULong(arULong
));
870 bRet
&= check(seqULongRet
== arULong
, "sequence test");
871 Sequence
< sal_uInt64
> arUHyper
;
872 Sequence
< sal_uInt64
> seqUHyperRet(
873 xBT2
->setSequenceUHyper(arUHyper
));
874 bRet
&= check(seqUHyperRet
== arUHyper
, "sequence test");
875 Sequence
< Reference
< XInterface
> > arObject
;
876 Sequence
< Reference
< XInterface
> > seqObjectRet(
877 xBT2
->setSequenceXInterface(arObject
));
878 bRet
&= check(seqObjectRet
== arObject
, "sequence test");
879 Sequence
< OUString
> arString
;
880 Sequence
< OUString
> seqStringRet(
881 xBT2
->setSequenceString(arString
));
882 bRet
&= check(seqStringRet
== arString
, "sequence test");
883 Sequence
< TestElement
> arStruct
;
884 Sequence
< TestElement
> seqStructRet(
885 xBT2
->setSequenceStruct(arStruct
));
886 bRet
&= check(seqStructRet
== arStruct
, "sequence test");
888 // Issue #i60341# shows that the most interesting case is were Java
889 // calls the constructors; however, since this client is currently not
890 // available in Java, while the server is, the logic is reversed here:
892 xBT2
->testConstructorsService(xContext
);
893 } catch (BadConstructorArguments
&) {
896 if (!noCurrentContext
) {
897 if (!(new testtools::bridgetest::CurrentContextChecker
)->perform(
898 xBT2
->getCurrentContextChecker(), 0, 1))
902 if (!(new testtools::bridgetest::CurrentContextChecker
)->perform(
903 xBT2
->getCurrentContextChecker(), 0, 2))
907 if (!(new testtools::bridgetest::CurrentContextChecker
)->perform(
908 xBT2
->getCurrentContextChecker(), 1, 2))
912 if (!(new testtools::bridgetest::CurrentContextChecker
)->perform(
913 xBT2
->getCurrentContextChecker(), 1, 3))
922 static sal_Bool
raiseOnewayException( const Reference
< XBridgeTest
> & xLBT
)
924 sal_Bool bReturn
= sal_True
;
925 OUString sCompare
= OUSTR(STRING_TEST_CONSTANT
);
926 Reference
<XInterface
> const x(xLBT
->getInterface());
929 // Note : the exception may fly or not (e.g. remote scenario).
930 // When it flies, it must contain the correct elements.
931 xLBT
->raiseRuntimeExceptionOneway( sCompare
, x
);
933 catch( RuntimeException
& e
)
936 #if OSL_DEBUG_LEVEL == 0
937 // java stack traces trash Message
938 e
.Message
== sCompare
&&
940 xLBT
->getInterface() == e
.Context
&&
946 //==================================================================================================
947 static sal_Bool
raiseException( const Reference
< XBridgeTest
> & xLBT
)
949 sal_Int32 nCount
= 0;
956 TestData aRet
, aRet2
;
957 xLBT
->raiseException(
958 5, OUSTR(STRING_TEST_CONSTANT
),
959 xLBT
->getInterface() );
961 catch (IllegalArgumentException aExc
)
963 if (aExc
.ArgumentPosition
== 5 &&
964 #if OSL_DEBUG_LEVEL == 0
965 // java stack traces trash Message
966 aExc
.Message
.compareToAscii( STRING_TEST_CONSTANT
) == 0 &&
968 aExc
.Context
== xLBT
->getInterface())
971 //When we check if a new compiler still works then we must not call
972 //getRuntimeException because it uses cppu::getCaughtException which
973 //does only work if all libs are build with the same runtime.
981 check( sal_False
, "### unexpected exception content!" );
984 /** it is certain, that the RuntimeException testing will fail, if no */
985 xLBT
->getRuntimeException();
988 catch (const RuntimeException
& rExc
)
990 if (rExc
.Context
== xLBT
->getInterface()
991 #if OSL_DEBUG_LEVEL == 0
992 // java stack traces trash Message
993 && rExc
.Message
.compareToAscii( STRING_TEST_CONSTANT
) == 0
1001 check( sal_False
, "### unexpected exception content!" );
1004 /** it is certain, that the RuntimeException testing will fail, if no */
1005 xLBT
->setRuntimeException( 0xcafebabe );
1008 catch (Exception
& rExc
)
1010 if (rExc
.Context
== xLBT
->getInterface()
1011 #if OSL_DEBUG_LEVEL == 0
1012 // java stack traces trash Message
1013 && rExc
.Message
.compareToAscii( STRING_TEST_CONSTANT
) == 0
1021 check( sal_False
, "### unexpected exception content!" );
1023 return (nCount
== 3);
1028 /* Returns an acquired sequence
1030 uno_Sequence
* cloneSequence(const uno_Sequence
* val
, const Type
& type
)
1032 TypeDescription
td(type
);
1034 typelib_TypeDescription
* pTdRaw
= td
.get();
1035 typelib_IndirectTypeDescription
* pIndirectTd
=
1036 (typelib_IndirectTypeDescription
*) pTdRaw
;
1038 typelib_TypeDescription
* pTdElem
= pIndirectTd
->pType
->pType
;
1039 sal_Int8
* buf
= new sal_Int8
[pTdElem
->nSize
* val
->nElements
];
1040 sal_Int8
* pBufCur
= buf
;
1042 uno_Sequence
* retSeq
= NULL
;
1043 switch (pTdElem
->eTypeClass
)
1045 case TypeClass_SEQUENCE
:
1047 Type
_tElem(pTdElem
->pWeakRef
);
1048 for (int i
= 0; i
< val
->nElements
; i
++)
1050 uno_Sequence
* seq
= cloneSequence(
1051 *(uno_Sequence
**) (&val
->elements
+ i
* pTdElem
->nSize
),
1053 *((uno_Sequence
**) pBufCur
) = seq
;
1054 pBufCur
+= pTdElem
->nSize
;
1059 uno_type_sequence_construct(
1060 &retSeq
, type
.getTypeLibType(), (void*) val
->elements
,
1061 val
->nElements
, reinterpret_cast< uno_AcquireFunc
>(cpp_acquire
));
1069 Sequence
<T
> cloneSequence(const Sequence
<T
>& val
)
1071 Sequence
<T
> seq( cloneSequence(val
.get(), getCppuType(&val
)), SAL_NO_ACQUIRE
);
1076 inline bool makeSurrogate(
1077 Reference
< T
> & rOut
, Reference
< T
> const & rOriginal
)
1080 if (! rOriginal
.is())
1083 Environment aCppEnv_official
;
1084 Environment aUnoEnv_ano
;
1085 Environment aCppEnv_ano
;
1087 OUString
aCppEnvTypeName(
1088 RTL_CONSTASCII_USTRINGPARAM(CPPU_CURRENT_LANGUAGE_BINDING_NAME
) );
1089 OUString
aUnoEnvTypeName(
1090 RTL_CONSTASCII_USTRINGPARAM(UNO_LB_UNO
) );
1093 reinterpret_cast< uno_Environment
** >( &aCppEnv_official
),
1094 aCppEnvTypeName
.pData
, 0 );
1096 uno_createEnvironment(
1097 reinterpret_cast< uno_Environment
** >( &aCppEnv_ano
),
1098 aCppEnvTypeName
.pData
, 0 );
1099 uno_createEnvironment(
1100 reinterpret_cast< uno_Environment
** >( &aUnoEnv_ano
),
1101 aUnoEnvTypeName
.pData
, 0 );
1103 UnoInterfaceReference unoI
;
1104 Mapping
cpp2uno( aCppEnv_official
.get(), aUnoEnv_ano
.get() );
1105 Mapping
uno2cpp( aUnoEnv_ano
.get(), aCppEnv_ano
.get() );
1106 if (!cpp2uno
.is() || !uno2cpp
.is())
1108 throw RuntimeException(
1109 OUSTR("cannot get C++-UNO mappings!"),
1110 Reference
< XInterface
>() );
1112 cpp2uno
.mapInterface(
1113 reinterpret_cast< void ** >( &unoI
.m_pUnoI
),
1114 rOriginal
.get(), ::getCppuType( &rOriginal
) );
1117 throw RuntimeException(
1118 OUSTR("mapping C++ to binary UNO failed!"),
1119 Reference
< XInterface
>() );
1121 uno2cpp
.mapInterface(
1122 reinterpret_cast< void ** >( &rOut
),
1123 unoI
.get(), ::getCppuType( &rOriginal
) );
1126 throw RuntimeException(
1127 OUSTR("mapping binary UNO to C++ failed!"),
1128 Reference
< XInterface
>() );
1134 //==================================================================================================
1135 sal_Int32
TestBridgeImpl::run( const Sequence
< OUString
> & rArgs
)
1136 throw (RuntimeException
)
1141 if (! rArgs
.getLength())
1143 throw RuntimeException( OUString( RTL_CONSTASCII_USTRINGPARAM(
1144 "no test object specified!\n"
1145 "usage : ServiceName of test object | -u unourl of test object\n" ) ),
1146 Reference
< XInterface
>() );
1149 Reference
< XInterface
> xOriginal
;
1152 if( rArgs
.getLength() > 1 && 0 == rArgs
[0].compareToAscii( "-u" ) )
1162 bool noCurrentContext
= false;
1163 if (i
< rArgs
.getLength()
1164 && rArgs
[i
].equalsAsciiL(
1165 RTL_CONSTASCII_STRINGPARAM("noCurrentContext")))
1167 noCurrentContext
= true;
1170 bool stress
= false;
1171 if (i
< rArgs
.getLength()
1172 && rArgs
[i
].equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("stress")))
1179 Reference
< XInterface
> o
;
1181 o
= UnoUrlResolver::create(m_xContext
)->resolve(rArgs
[1]);
1183 o
= m_xContext
->getServiceManager()->createInstanceWithContext(
1184 rArgs
[0], m_xContext
);
1192 if (! xOriginal
.is())
1194 throw RuntimeException(
1195 OUString( RTL_CONSTASCII_USTRINGPARAM(
1196 "cannot get test object!") ),
1197 Reference
< XInterface
>() );
1199 Reference
< XBridgeTest
> xTest( xOriginal
, UNO_QUERY
);
1202 throw RuntimeException(
1203 OUString( RTL_CONSTASCII_USTRINGPARAM("test object does not implement XBridgeTest!") ),
1204 Reference
< XInterface
>() );
1207 Reference
<XBridgeTest
> xLBT
;
1208 bRet
= check( makeSurrogate( xLBT
, xTest
), "makeSurrogate" );
1210 performTest( m_xContext
, xLBT
, noCurrentContext
), "standard test" )
1212 bRet
= check( raiseException( xLBT
) , "exception test" )&& bRet
;
1213 bRet
= check( raiseOnewayException( xLBT
),
1214 "oneway exception test" ) && bRet
;
1217 throw RuntimeException(
1218 OUString( RTL_CONSTASCII_USTRINGPARAM("error: test failed!") ),
1219 Reference
< XInterface
>() );
1222 catch (Exception
& exc
)
1224 OString
cstr( OUStringToOString( exc
.Message
, RTL_TEXTENCODING_ASCII_US
) );
1225 fprintf( stderr
, "exception occured: %s\n", cstr
.getStr() );
1231 printf( "\n\n ### test succeeded!\n" );
1235 printf( "\n> ### test failed!\n" );
1242 //__________________________________________________________________________________________________
1243 OUString
TestBridgeImpl::getImplementationName()
1244 throw (RuntimeException
)
1246 return OUString( RTL_CONSTASCII_USTRINGPARAM(IMPLNAME
) );
1248 //__________________________________________________________________________________________________
1249 sal_Bool
TestBridgeImpl::supportsService( const OUString
& rServiceName
)
1250 throw (RuntimeException
)
1252 const Sequence
< OUString
> & rSNL
= getSupportedServiceNames();
1253 const OUString
* pArray
= rSNL
.getConstArray();
1254 for ( sal_Int32 nPos
= rSNL
.getLength(); nPos
--; )
1256 if (pArray
[nPos
] == rServiceName
)
1261 //__________________________________________________________________________________________________
1262 Sequence
< OUString
> TestBridgeImpl::getSupportedServiceNames()
1263 throw (RuntimeException
)
1265 return bridge_test::getSupportedServiceNames();
1270 //==================================================================================================
1271 static Reference
< XInterface
> SAL_CALL
TestBridgeImpl_create(
1272 const Reference
< XComponentContext
> & xContext
)
1274 return Reference
< XInterface
>(
1275 static_cast< OWeakObject
* >( new TestBridgeImpl( xContext
) ) );
1282 //==================================================================================================
1283 void SAL_CALL
component_getImplementationEnvironment(
1284 const sal_Char
** ppEnvTypeName
, uno_Environment
** )
1286 *ppEnvTypeName
= CPPU_CURRENT_LANGUAGE_BINDING_NAME
;
1288 //==================================================================================================
1289 void * SAL_CALL
component_getFactory(
1290 const sal_Char
* pImplName
, void * pServiceManager
, void * )
1294 if (pServiceManager
&& rtl_str_compare( pImplName
, IMPLNAME
) == 0)
1296 Reference
< XInterface
> xFactory(
1297 createSingleComponentFactory(
1298 bridge_test::TestBridgeImpl_create
,
1299 OUString( RTL_CONSTASCII_USTRINGPARAM(IMPLNAME
) ),
1300 bridge_test::getSupportedServiceNames() ) );
1304 xFactory
->acquire();
1305 pRet
= xFactory
.get();