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 #include <osl/diagnose.h>
24 #include "osl/diagnose.hxx"
26 #include <sal/types.h>
27 #include "typelib/typedescription.hxx"
28 #include <uno/dispatcher.hxx>
29 #include <uno/lbnames.h>
30 #include "uno/mapping.hxx"
32 #include "uno/environment.hxx"
34 #include <cppuhelper/factory.hxx>
35 #include <cppuhelper/implbase2.hxx>
36 #include <cppuhelper/implbase1.hxx>
37 #include <cppuhelper/supportsservice.hxx>
39 #include <com/sun/star/lang/XServiceInfo.hpp>
40 #include <com/sun/star/lang/XComponent.hpp>
41 #include <com/sun/star/lang/XMain.hpp>
42 #include <com/sun/star/bridge/UnoUrlResolver.hpp>
43 #include <com/sun/star/bridge/XUnoUrlResolver.hpp>
44 #include "com/sun/star/uno/RuntimeException.hpp"
45 #include "com/sun/star/uno/Type.hxx"
47 #include "test/testtools/bridgetest/BadConstructorArguments.hpp"
48 #include "test/testtools/bridgetest/TestPolyStruct.hpp"
49 #include "test/testtools/bridgetest/XBridgeTest.hpp"
50 #include "test/testtools/bridgetest/XBridgeTest2.hpp"
51 #include "test/testtools/bridgetest/XMulti.hpp"
53 #include "currentcontextchecker.hxx"
58 using namespace com::sun::star::uno
;
59 using namespace com::sun::star::lang
;
60 using namespace com::sun::star::registry
;
61 using namespace com::sun::star::bridge
;
62 using namespace test::testtools::bridgetest
;
65 #define SERVICENAME "com.sun.star.test.bridge.BridgeTest"
66 #define IMPLNAME "com.sun.star.comp.bridge.BridgeTest"
68 #define STRING_TEST_CONSTANT "\" paco\' chorizo\\\' \"\'"
72 template<typename T
, typename U
= T
>
73 Sequence
<T
> cloneSequence(const Sequence
<T
>& val
);
76 inline static Sequence
< OUString
> getSupportedServiceNames()
78 OUString
aName( SERVICENAME
);
79 return Sequence
< OUString
>( &aName
, 1 );
82 static bool check( bool b
, char const * message
)
85 fprintf( stderr
, "%s failed\n" , message
);
91 bool checkEmpty(OUString
const & string
, char const * message
) {
92 bool ok
= string
.isEmpty();
95 stderr
, "%s failed: %s\n", message
,
96 OUStringToOString(string
, RTL_TEXTENCODING_UTF8
).getStr());
104 class TestBridgeImpl
: public osl::DebugBase
<TestBridgeImpl
>,
105 public WeakImplHelper2
< XMain
, XServiceInfo
>
107 Reference
< XComponentContext
> m_xContext
;
110 TestBridgeImpl( const Reference
< XComponentContext
> & xContext
)
111 : m_xContext( xContext
)
113 virtual ~TestBridgeImpl()
118 virtual OUString SAL_CALL
getImplementationName() throw (RuntimeException
, std::exception
) SAL_OVERRIDE
;
119 virtual sal_Bool SAL_CALL
supportsService( const OUString
& rServiceName
) throw (RuntimeException
, std::exception
) SAL_OVERRIDE
;
120 virtual Sequence
< OUString
> SAL_CALL
getSupportedServiceNames() throw (RuntimeException
, std::exception
) SAL_OVERRIDE
;
123 virtual sal_Int32 SAL_CALL
run( const Sequence
< OUString
> & rArgs
) throw (RuntimeException
, std::exception
) SAL_OVERRIDE
;
127 static bool equals( const TestElement
& rData1
, const TestElement
& rData2
)
129 check( rData1
.Bool
== rData2
.Bool
, "### bool does not match!" );
130 check( rData1
.Char
== rData2
.Char
, "### char does not match!" );
131 check( rData1
.Byte
== rData2
.Byte
, "### byte does not match!" );
132 check( rData1
.Short
== rData2
.Short
, "### short does not match!" );
133 check( rData1
.UShort
== rData2
.UShort
, "### unsigned short does not match!" );
134 check( rData1
.Long
== rData2
.Long
, "### long does not match!" );
135 check( rData1
.ULong
== rData2
.ULong
, "### unsigned long does not match!" );
136 check( rData1
.Hyper
== rData2
.Hyper
, "### hyper does not match!" );
137 check( rData1
.UHyper
== rData2
.UHyper
, "### unsigned hyper does not match!" );
138 check( rData1
.Float
== rData2
.Float
, "### float does not match!" );
139 check( rData1
.Double
== rData2
.Double
, "### double does not match!" );
140 check( rData1
.Enum
== rData2
.Enum
, "### enum does not match!" );
141 check( rData1
.String
== rData2
.String
, "### string does not match!" );
142 check( rData1
.Interface
== rData2
.Interface
, "### interface does not match!" );
143 check( rData1
.Any
== rData2
.Any
, "### any does not match!" );
145 return (rData1
.Bool
== rData2
.Bool
&&
146 rData1
.Char
== rData2
.Char
&&
147 rData1
.Byte
== rData2
.Byte
&&
148 rData1
.Short
== rData2
.Short
&&
149 rData1
.UShort
== rData2
.UShort
&&
150 rData1
.Long
== rData2
.Long
&&
151 rData1
.ULong
== rData2
.ULong
&&
152 rData1
.Hyper
== rData2
.Hyper
&&
153 rData1
.UHyper
== rData2
.UHyper
&&
154 rData1
.Float
== rData2
.Float
&&
155 rData1
.Double
== rData2
.Double
&&
156 rData1
.Enum
== rData2
.Enum
&&
157 rData1
.String
== rData2
.String
&&
158 rData1
.Interface
== rData2
.Interface
&&
159 rData1
.Any
== rData2
.Any
);
162 static bool equals( const TestData
& rData1
, const TestData
& rData2
)
166 if ((rData1
.Sequence
== rData2
.Sequence
) &&
167 equals( (const TestElement
&)rData1
, (const TestElement
&)rData2
) &&
168 (nLen
= rData1
.Sequence
.getLength()) == rData2
.Sequence
.getLength())
170 // once again by hand sequence ==
171 const TestElement
* pElements1
= rData1
.Sequence
.getConstArray();
172 const TestElement
* pElements2
= rData2
.Sequence
.getConstArray();
175 if (! equals( pElements1
[nLen
], pElements2
[nLen
] ))
177 check( false, "### sequence element did not match!" );
186 static void assign( TestElement
& rData
,
187 bool bBool
, sal_Unicode cChar
, sal_Int8 nByte
,
188 sal_Int16 nShort
, sal_uInt16 nUShort
,
189 sal_Int32 nLong
, sal_uInt32 nULong
,
190 sal_Int64 nHyper
, sal_uInt64 nUHyper
,
191 float fFloat
, double fDouble
,
192 TestEnum eEnum
, const OUString
& rStr
,
193 const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>& xTest
,
194 const ::com::sun::star::uno::Any
& rAny
)
199 rData
.Short
= nShort
;
200 rData
.UShort
= nUShort
;
202 rData
.ULong
= nULong
;
203 rData
.Hyper
= nHyper
;
204 rData
.UHyper
= nUHyper
;
205 rData
.Float
= fFloat
;
206 rData
.Double
= fDouble
;
209 rData
.Interface
= xTest
;
215 template < typename T
>
217 T
const & value
, Reference
< XBridgeTest
> const & xLBT
,
218 char const * typeName
= 0)
222 Any any2
= xLBT
->transportAny(any
);
226 stderr
, "any is different after roundtrip: in %s, out %s\n",
228 any
.getValueType().getTypeName(),
229 RTL_TEXTENCODING_ASCII_US
).getStr(),
231 any2
.getValueType().getTypeName(),
232 RTL_TEXTENCODING_ASCII_US
).getStr());
236 && !any2
.getValueType().getTypeName().equalsAscii(typeName
))
239 stderr
, "any has wrong type after roundtrip: %s instead of %s\n",
241 any2
.getValueType().getTypeName(),
242 RTL_TEXTENCODING_ASCII_US
).getStr(),
251 static bool performAnyTest( const Reference
< XBridgeTest
> &xLBT
, const TestData
&data
)
254 bReturn
= testAny( data
.Byte
,xLBT
) && bReturn
;
255 bReturn
= testAny( data
.Short
,xLBT
) && bReturn
;
256 bReturn
= testAny( data
.UShort
,xLBT
) && bReturn
;
257 bReturn
= testAny( data
.Long
,xLBT
) && bReturn
;
258 bReturn
= testAny( data
.ULong
,xLBT
) && bReturn
;
259 bReturn
= testAny( data
.Hyper
,xLBT
) && bReturn
;
260 bReturn
= testAny( data
.UHyper
,xLBT
) && bReturn
;
261 bReturn
= testAny( data
.Float
,xLBT
) && bReturn
;
262 bReturn
= testAny( data
.Double
,xLBT
) && bReturn
;
263 bReturn
= testAny( data
.Enum
,xLBT
) && bReturn
;
264 bReturn
= testAny( data
.String
,xLBT
) && bReturn
;
265 bReturn
= testAny( data
.Interface
,xLBT
) && bReturn
;
266 bReturn
= testAny( data
, xLBT
) && bReturn
;
268 TestPolyStruct
< sal_Unicode
>(' '), xLBT
,
269 "test.testtools.bridgetest.TestPolyStruct<char>");
273 a
.setValue( &(data
.Bool
) , cppu::UnoType
<bool>::get() );
274 OSL_ASSERT( xLBT
->transportAny( a
) == a
);
278 a
.setValue( &(data
.Char
) , cppu::UnoType
<cppu::UnoCharType
>::get() );
279 OSL_ASSERT( xLBT
->transportAny( a
) == a
);
286 static bool performSequenceOfCallTest( const Reference
< XBridgeTest
> &xLBT
)
289 sal_Int32 nGlobalIndex
= 0;
290 const sal_Int32 nWaitTimeSpanMUSec
= 10000;
291 for( nRounds
= 0 ; nRounds
< 10 ; nRounds
++ )
293 for( i
= 0 ; i
< nRounds
; i
++ )
296 xLBT
->callOneway( nGlobalIndex
, nWaitTimeSpanMUSec
);
301 xLBT
->call( nGlobalIndex
, nWaitTimeSpanMUSec
);
305 return xLBT
->sequenceOfCallTestPassed();
308 class ORecursiveCall
: public WeakImplHelper1
< XRecursiveCall
>
314 void SAL_CALL
callRecursivly(
315 const ::com::sun::star::uno::Reference
< XRecursiveCall
>& xCall
,
317 throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
319 MutexGuard
guard( m_mutex
);
323 xCall
->callRecursivly( this , nToCall
);
331 static bool performRecursiveCallTest( const Reference
< XBridgeTest
> & xLBT
)
333 xLBT
->startRecursiveCall( new ORecursiveCall
, 50 );
334 // on failure, the test would lock up or crash
338 class MyClass
: public osl::DebugBase
<MyClass
>, public OWeakObject
343 virtual void SAL_CALL
acquire() throw () SAL_OVERRIDE
;
344 virtual void SAL_CALL
release() throw () SAL_OVERRIDE
;
356 void MyClass::acquire() throw ()
358 OWeakObject::acquire();
361 void MyClass::release() throw ()
363 OWeakObject::release();
367 static bool performTest(
368 const Reference
<XComponentContext
> & xContext
,
369 const Reference
<XBridgeTest
> & xLBT
,
370 bool noCurrentContext
)
372 check(xLBT
.is(), "### no test interface!");
375 // this data is never ever granted access to by calls other than
376 // equals(), assign()!
377 TestData aData
; // test against this data
378 Reference
< XInterface
> xI(new MyClass
);
380 (TestElement
&) aData
, true, '@', 17, 0x1234, 0xFEDC, 0x12345678,
381 0xFEDCBA98, SAL_CONST_INT64(0x123456789ABCDEF0),
382 SAL_CONST_UINT64(0xFEDCBA9876543210), 17.0815f
, 3.1415926359,
383 TestEnum_LOLA
, STRING_TEST_CONSTANT
, xI
,
384 Any(&xI
, cppu::UnoType
<XInterface
>::get()));
385 bRet
&= check(aData
.Any
== xI
, "### unexpected any!");
386 bRet
&= check(!(aData
.Any
!= xI
), "### unexpected any!");
387 aData
.Sequence
.realloc(2);
388 aData
.Sequence
[0] = *(TestElement
const *) &aData
;
389 // aData.Sequence[1] is empty
390 // aSetData is a manually copy of aData for first setting:
393 (TestElement
&) aSetData
, aData
.Bool
, aData
.Char
, aData
.Byte
,
394 aData
.Short
, aData
.UShort
, aData
.Long
, aData
.ULong
, aData
.Hyper
,
395 aData
.UHyper
, aData
.Float
, aData
.Double
, aData
.Enum
, aData
.String
,
396 xI
, Any(&xI
, cppu::UnoType
<XInterface
>::get()));
397 aSetData
.Sequence
.realloc(2);
398 aSetData
.Sequence
[0] = *(TestElement
const *) &aSetData
;
399 // aSetData.Sequence[1] is empty
401 aSetData
.Bool
, aSetData
.Char
, aSetData
.Byte
, aSetData
.Short
,
402 aSetData
.UShort
, aSetData
.Long
, aSetData
.ULong
, aSetData
.Hyper
,
403 aSetData
.UHyper
, aSetData
.Float
, aSetData
.Double
, aSetData
.Enum
,
404 aSetData
.String
, aSetData
.Interface
, aSetData
.Any
,
405 aSetData
.Sequence
, aSetData
);
410 aRet
.Bool
, aRet
.Char
, aRet
.Byte
, aRet
.Short
, aRet
.UShort
,
411 aRet
.Long
, aRet
.ULong
, aRet
.Hyper
, aRet
.UHyper
, aRet
.Float
,
412 aRet
.Double
, aRet
.Enum
, aRet
.String
, aRet
.Interface
, aRet
.Any
,
413 aRet
.Sequence
, aRet2
);
415 equals(aData
, aRet
) && equals(aData
, aRet2
), "getValues test");
416 // Set last retrieved values:
419 aRet
.Bool
, aRet
.Char
, aRet
.Byte
, aRet
.Short
, aRet
.UShort
,
420 aRet
.Long
, aRet
.ULong
, aRet
.Hyper
, aRet
.UHyper
, aRet
.Float
,
421 aRet
.Double
, aRet
.Enum
, aRet
.String
, aRet
.Interface
,
422 aRet
.Any
, aRet
.Sequence
, aRet2
));
423 // Check inout sequence order (=> inout sequence parameter was
424 // switched by test objects):
425 TestElement
temp(aRet
.Sequence
[0]);
426 aRet
.Sequence
[0] = aRet
.Sequence
[1];
427 aRet
.Sequence
[1] = temp
;
429 equals(aData
, aSV2ret
) && equals(aData
, aRet2
),
433 TwoFloats
aIn(1.1f
, 2.2f
);
434 TwoFloats aOut
= xLBT
->echoTwoFloats(aIn
);
435 bRet
= check( memcmp(&aIn
, &aOut
, sizeof(TwoFloats
)) == 0, "two floats struct test" ) && bRet
;
438 FourFloats
aIn(3.3f
, 4.4f
, 5.5f
, 6.6f
);
439 FourFloats aOut
= xLBT
->echoFourFloats(aIn
);
440 bRet
= check( memcmp(&aIn
, &aOut
, sizeof(FourFloats
)) == 0, "four floats struct test" ) && bRet
;
443 MixedFloatAndInteger
aIn(7.7f
, 8);
444 MixedFloatAndInteger aOut
= xLBT
->echoMixedFloatAndInteger(aIn
);
445 bRet
= check( memcmp(&aIn
, &aOut
, sizeof(MixedFloatAndInteger
)) == 0, "mixed float and integer struct test" ) && bRet
;
448 ThreeByteStruct
aIn(9, 10, 11);
449 ThreeByteStruct aOut
= xLBT
->echoThreeByteStruct(aIn
);
450 bRet
= check( memcmp(&aIn
, &aOut
, sizeof(ThreeByteStruct
)) == 0, "three byte struct test" ) && bRet
;
457 aRet
.Bool
, aRet
.Char
, aRet
.Byte
, aRet
.Short
, aRet
.UShort
,
458 aRet
.Long
, aRet
.ULong
, aRet
.Hyper
, aRet
.UHyper
, aRet
.Float
,
459 aRet
.Double
, aRet
.Enum
, aRet
.String
, aRet
.Interface
,
460 aRet
.Any
, aRet
.Sequence
, aRet2
));
462 (equals(aData
, aRet
) && equals(aData
, aRet2
) &&
463 equals(aData
, aGVret
)),
465 // Set last retrieved values:
466 xLBT
->setBool(aRet
.Bool
);
467 xLBT
->setChar(aRet
.Char
);
468 xLBT
->setByte(aRet
.Byte
);
469 xLBT
->setShort(aRet
.Short
);
470 xLBT
->setUShort(aRet
.UShort
);
471 xLBT
->setLong(aRet
.Long
);
472 xLBT
->setULong(aRet
.ULong
);
473 xLBT
->setHyper(aRet
.Hyper
);
474 xLBT
->setUHyper(aRet
.UHyper
);
475 xLBT
->setFloat(aRet
.Float
);
476 xLBT
->setDouble(aRet
.Double
);
477 xLBT
->setEnum(aRet
.Enum
);
478 xLBT
->setString(aRet
.String
);
479 xLBT
->setInterface(aRet
.Interface
);
480 xLBT
->setAny(aRet
.Any
);
481 xLBT
->setSequence(aRet
.Sequence
);
482 xLBT
->setStruct(aRet2
);
486 aRet
.Hyper
= xLBT
->getHyper();
487 aRet
.UHyper
= xLBT
->getUHyper();
488 aRet
.Float
= xLBT
->getFloat();
489 aRet
.Double
= xLBT
->getDouble();
490 aRet
.Byte
= xLBT
->getByte();
491 aRet
.Char
= xLBT
->getChar();
492 aRet
.Bool
= xLBT
->getBool();
493 aRet
.Short
= xLBT
->getShort();
494 aRet
.UShort
= xLBT
->getUShort();
495 aRet
.Long
= xLBT
->getLong();
496 aRet
.ULong
= xLBT
->getULong();
497 aRet
.Enum
= xLBT
->getEnum();
498 aRet
.String
= xLBT
->getString();
499 aRet
.Interface
= xLBT
->getInterface();
500 aRet
.Any
= xLBT
->getAny();
501 aRet
.Sequence
= xLBT
->getSequence();
502 TestData
aRet2(xLBT
->getStruct());
504 equals(aData
, aRet
) && equals(aData
, aRet2
),
505 "struct comparison test");
507 SmallStruct
aIn(1, 2);
508 SmallStruct
aOut(xLBT
->echoSmallStruct(aIn
));
510 memcmp(&aIn
, &aOut
, sizeof(SmallStruct
)) == 0,
511 "small struct test");
514 MediumStruct
aIn(1, 2, 3, 4);
515 MediumStruct
aOut(xLBT
->echoMediumStruct(aIn
));
517 memcmp(&aIn
, &aOut
, sizeof(MediumStruct
)) == 0,
518 "medium struct test");
521 BigStruct
aIn(1, 2, 3, 4, 5, 6, 7, 8);
522 BigStruct
aOut(xLBT
->echoBigStruct(aIn
));
524 memcmp(&aIn
, &aOut
, sizeof(BigStruct
)) == 0,
528 sal_Int32 i2
= xLBT
->testPPCAlignment(0, 0, 0, 0, 0xBEAF);
529 bRet
&= check(i2
== 0xBEAF, "ppc-style alignment test");
532 sal_Int32 i1
= xLBT
->testPPC64Alignment(1.0, 2.0, 3.0, 0xBEAF);
533 bRet
&= check(i1
== 0xBEAF, "ppc64-style alignment test");
536 double d1
= xLBT
->testTenDoubles(0.1, 0.2, 0.3, 0.4, 0.5,
537 0.6, 0.7, 0.8, 0.9, 1.0);
538 bRet
&= check(d1
== 5.5, "armhf doubles test");
540 // Test extended attributes that raise exceptions:
542 xLBT
->getRaiseAttr1();
543 bRet
&= check(false, "getRaiseAttr1 did not throw");
544 } catch (const RuntimeException
&) {
546 bRet
&= check(false, "getRaiseAttr1 threw wrong type");
549 xLBT
->setRaiseAttr1(0);
550 bRet
&= check(false, "setRaiseAttr1 did not throw");
551 } catch (const IllegalArgumentException
&) {
553 bRet
&= check(false, "setRaiseAttr1 threw wrong type");
556 xLBT
->getRaiseAttr2();
557 bRet
&= check(false, "getRaiseAttr2 did not throw");
558 } catch (const IllegalArgumentException
&) {
560 bRet
&= check(false, "getRaiseAttr2 threw wrong type");
562 // Test instantiated polymorphic struct types:
565 (xLBT
->transportPolyBoolean(
566 TestPolyStruct
< sal_Bool
>(true)).
568 "transportPolyBoolean");
569 TestPolyStruct
< sal_Int64
> tps1(12345);
570 xLBT
->transportPolyHyper(tps1
);
571 bRet
&= check(tps1
.member
== 12345, "transportPolyHyper");
572 Sequence
< Any
> seq(2);
573 seq
[0] <<= static_cast< sal_uInt32
>(33);
574 seq
[1] <<= OUString("ABC");
575 TestPolyStruct
< Sequence
< Any
> > tps2(seq
);
576 TestPolyStruct
< Sequence
< Any
> > tps3
;
577 xLBT
->transportPolySequence(tps2
, tps3
);
579 tps3
.member
.getLength() == 2,
580 "transportPolySequence, length");
581 sal_uInt32 v0
= sal_uInt32();
582 tps3
.member
[0] >>= v0
;
583 bRet
&= check(v0
== 33, "transportPolySequence, element 0");
585 tps3
.member
[1] >>= v1
;
586 bRet
&= check( v1
== "ABC", "transportPolySequence, element 1" );
588 xLBT
->getNullPolyLong().member
== 0, "getNullPolyLong");
590 xLBT
->getNullPolyString().member
.isEmpty(),
591 "getNullPolyString");
593 xLBT
->getNullPolyType().member
== Type(),
595 Any
nullAny(xLBT
->getNullPolyAny().member
);
597 (((nullAny
.getValueTypeName() ==
598 "com.sun.star.uno.XInterface") &&
599 !static_cast< Reference
< XInterface
> const * >(
600 nullAny
.getValue())->is())
601 || nullAny
== Any()),
604 xLBT
->getNullPolySequence().member
.getLength() == 0,
605 "getNullPolySequence");
607 xLBT
->getNullPolyEnum().member
== TestEnum_TEST
,
610 xLBT
->getNullPolyBadEnum().member
== TestBadEnum_M
,
611 "getNullPolyBadEnum");
613 xLBT
->getNullPolyStruct().member
.member
== 0,
614 "getNullPolyStruct");
616 !xLBT
->getNullPolyInterface().member
.is(),
617 "getNullPolyInterface");
620 bRet
&= check(performAnyTest(xLBT
, aData
), "any test");
621 // Sequence of call test:
623 performSequenceOfCallTest(xLBT
), "sequence of call test");
624 // Recursive call test:
625 bRet
&= check(performRecursiveCallTest(xLBT
), "recursive test");
627 equals(aData
, aRet
) && equals(aData
, aRet2
),
628 "recursive test results");
629 // Multiple inheritance test:
631 testtools::bridgetest::testMulti(xLBT
->getMulti()),
634 xLBT
->testMulti(new testtools::bridgetest::Multi
),
639 Reference
< XBridgeTest2
> xBT2(xLBT
, UNO_QUERY
);
643 // Perform sequence tests (XBridgeTest2); create the sequence which is
644 // compared with the results:
645 sal_Bool _arBool
[] = { true, false, true };
646 sal_Unicode _arChar
[] = { 0x0065, 0x0066, 0x0067 };
647 sal_Int8 _arByte
[] = { 1, 2, -1 };
648 sal_Int16 _arShort
[] = { -0x8000, 1, 0x7FFF };
649 sal_uInt16 _arUShort
[] = { 0 , 1, 0xFFFF };
650 sal_Int32 _arLong
[] = {
651 static_cast< sal_Int32
>(0x80000000), 1, 0x7FFFFFFF };
652 sal_uInt32 _arULong
[] = { 0, 1, 0xFFFFFFFF };
653 sal_Int64 _arHyper
[] = {
654 static_cast< sal_Int64
>(SAL_CONST_INT64(0x8000000000000000)), 1,
655 SAL_CONST_INT64(0x7FFFFFFFFFFFFFFF) };
656 sal_uInt64 _arUHyper
[] = { 0, 1, SAL_CONST_UINT64(0xFFFFFFFFFFFFFFFF) };
657 float _arFloat
[] = { 1.1f
, 2.2f
, 3.3f
};
658 double _arDouble
[] = { 1.11, 2.22, 3.33 };
659 OUString _arString
[] = {
660 OUString("String 1"),
661 OUString("String 2"),
662 OUString("String 3") };
663 sal_Bool _aBool
= true;
664 sal_Int32 _aInt
= 0xBABEBABE;
665 float _aFloat
= 3.14f
;
666 Any
_any1(&_aBool
, cppu::UnoType
<bool>::get());
667 Any
_any2(&_aInt
, cppu::UnoType
<sal_Int32
>::get());
668 Any
_any3(&_aFloat
, cppu::UnoType
<float>::get());
669 Any _arAny
[] = { _any1
, _any2
, _any3
};
670 Reference
< XInterface
> _arObj
[3];
671 _arObj
[0] = new OWeakObject();
672 _arObj
[1] = new OWeakObject();
673 _arObj
[2] = new OWeakObject();
674 TestEnum _arEnum
[] = { TestEnum_ONE
, TestEnum_TWO
, TestEnum_CHECK
};
675 TestElement _arStruct
[3];
677 _arStruct
[0], true, '@', 17, 0x1234, 0xFEDC, 0x12345678, 0xFEDCBA98,
678 SAL_CONST_INT64(0x123456789ABCDEF0),
679 SAL_CONST_UINT64(0xFEDCBA9876543210), 17.0815f
, 3.1415926359,
680 TestEnum_LOLA
, STRING_TEST_CONSTANT
, _arObj
[0],
681 Any(&_arObj
[0], cppu::UnoType
<XInterface
>::get()));
683 _arStruct
[1], true, 'A', 17, 0x1234, 0xFEDC, 0x12345678, 0xFEDCBA98,
684 SAL_CONST_INT64(0x123456789ABCDEF0),
685 SAL_CONST_UINT64(0xFEDCBA9876543210), 17.0815f
, 3.1415926359,
686 TestEnum_TWO
, STRING_TEST_CONSTANT
, _arObj
[1],
687 Any(&_arObj
[1], cppu::UnoType
<XInterface
>::get()));
689 _arStruct
[2], true, 'B', 17, 0x1234, 0xFEDC, 0x12345678, 0xFEDCBA98,
690 SAL_CONST_INT64(0x123456789ABCDEF0),
691 SAL_CONST_UINT64(0xFEDCBA9876543210), 17.0815f
, 3.1415926359,
692 TestEnum_CHECK
, STRING_TEST_CONSTANT
, _arObj
[2],
693 Any(&_arObj
[2], cppu::UnoType
<XInterface
>::get()));
695 Sequence
<sal_Bool
> arBool(_arBool
, 3);
696 Sequence
<sal_Unicode
> arChar( _arChar
, 3);
697 Sequence
<sal_Int8
> arByte(_arByte
, 3);
698 Sequence
<sal_Int16
> arShort(_arShort
, 3);
699 Sequence
<sal_uInt16
> arUShort(_arUShort
, 3);
700 Sequence
<sal_Int32
> arLong(_arLong
, 3);
701 Sequence
<sal_uInt32
> arULong(_arULong
, 3);
702 Sequence
<sal_Int64
> arHyper(_arHyper
, 3);
703 Sequence
<sal_uInt64
> arUHyper(_arUHyper
, 3);
704 Sequence
<float> arFloat(_arFloat
, 3);
705 Sequence
<double> arDouble(_arDouble
, 3);
706 Sequence
<OUString
> arString(_arString
, 3);
707 Sequence
<Any
> arAny(_arAny
, 3);
708 Sequence
<Reference
<XInterface
> > arObject(_arObj
, 3);
709 Sequence
<TestEnum
> arEnum(_arEnum
, 3);
710 Sequence
<TestElement
> arStruct(_arStruct
, 3);
711 Sequence
<Sequence
<sal_Int32
> > _arSeqLong2
[3];
712 for (int j
= 0; j
!= 3; ++j
) {
713 Sequence
< sal_Int32
> _arSeqLong
[3];
714 for (int i
= 0; i
!= 3; ++i
) {
715 _arSeqLong
[i
] = Sequence
< sal_Int32
>(_arLong
, 3);
717 _arSeqLong2
[j
] = Sequence
< Sequence
< sal_Int32
> >(
720 Sequence
< Sequence
< Sequence
< sal_Int32
> > > arLong3(
722 Sequence
< Sequence
< sal_Int32
> > seqSeqRet(
723 xBT2
->setDim2(arLong3
[0]));
724 bRet
&= check(seqSeqRet
== arLong3
[0], "sequence test");
725 Sequence
< Sequence
< Sequence
< sal_Int32
> > > seqSeqRet2(
726 xBT2
->setDim3(arLong3
));
727 bRet
&= check(seqSeqRet2
== arLong3
, "sequence test");
728 Sequence
< Any
> seqAnyRet(xBT2
->setSequenceAny(arAny
));
729 bRet
&= check(seqAnyRet
== arAny
, "sequence test");
730 Sequence
< sal_Bool
> seqBoolRet(xBT2
->setSequenceBool(arBool
));
731 bRet
&= check(seqBoolRet
== arBool
, "sequence test");
732 Sequence
< sal_Int8
> seqByteRet(xBT2
->setSequenceByte(arByte
));
733 bRet
&= check(seqByteRet
== arByte
, "sequence test");
734 Sequence
< sal_Unicode
> seqCharRet(xBT2
->setSequenceChar(arChar
));
735 bRet
&= check(seqCharRet
== arChar
, "sequence test");
736 Sequence
< sal_Int16
> seqShortRet(xBT2
->setSequenceShort(arShort
));
737 bRet
&= check(seqShortRet
== arShort
, "sequence test");
738 Sequence
< sal_Int32
> seqLongRet(xBT2
->setSequenceLong(arLong
));
739 bRet
&= check(seqLongRet
== arLong
, "sequence test");
740 Sequence
< sal_Int64
> seqHyperRet(xBT2
->setSequenceHyper(arHyper
));
741 bRet
&= check(seqHyperRet
== arHyper
, "sequence test");
742 Sequence
< float > seqFloatRet(xBT2
->setSequenceFloat(arFloat
));
743 bRet
&= check(seqFloatRet
== arFloat
, "sequence test");
744 Sequence
< double > seqDoubleRet(xBT2
->setSequenceDouble(arDouble
));
745 bRet
&= check(seqDoubleRet
== arDouble
, "sequence test");
746 Sequence
< TestEnum
> seqEnumRet(xBT2
->setSequenceEnum(arEnum
));
747 bRet
&= check(seqEnumRet
== arEnum
, "sequence test");
748 Sequence
< sal_uInt16
> seqUShortRet(
749 xBT2
->setSequenceUShort(arUShort
));
750 bRet
&= check(seqUShortRet
== arUShort
, "sequence test");
751 Sequence
< sal_uInt32
> seqULongRet(xBT2
->setSequenceULong(arULong
));
752 bRet
&= check(seqULongRet
== arULong
, "sequence test");
753 Sequence
< sal_uInt64
> seqUHyperRet(
754 xBT2
->setSequenceUHyper(arUHyper
));
755 bRet
&= check(seqUHyperRet
== arUHyper
, "sequence test");
756 Sequence
< Reference
< XInterface
> > seqObjectRet(
757 xBT2
->setSequenceXInterface(arObject
));
758 bRet
&= check(seqObjectRet
== arObject
, "sequence test");
759 Sequence
< OUString
> seqStringRet(
760 xBT2
->setSequenceString(arString
));
761 bRet
&= check(seqStringRet
== arString
, "sequence test");
762 Sequence
< TestElement
> seqStructRet(
763 xBT2
->setSequenceStruct(arStruct
));
764 bRet
&= check(seqStructRet
== arStruct
, "sequence test");
765 Sequence
< sal_Bool
> arBoolTemp(cloneSequence(arBool
));
766 Sequence
< sal_Unicode
> arCharTemp(cloneSequence
<sal_Unicode
, cppu::UnoCharType
>(arChar
));
767 Sequence
< sal_Int8
> arByteTemp(cloneSequence(arByte
));
768 Sequence
< sal_Int16
> arShortTemp(cloneSequence(arShort
));
769 Sequence
< sal_uInt16
> arUShortTemp(cloneSequence
<sal_uInt16
, cppu::UnoUnsignedShortType
>(arUShort
));
770 Sequence
< sal_Int32
> arLongTemp(cloneSequence(arLong
));
771 Sequence
< sal_uInt32
> arULongTemp(cloneSequence(arULong
));
772 Sequence
< sal_Int64
> arHyperTemp(cloneSequence(arHyper
));
773 Sequence
< sal_uInt64
> arUHyperTemp(cloneSequence(arUHyper
));
774 Sequence
< float > arFloatTemp(cloneSequence(arFloat
));
775 Sequence
< double > arDoubleTemp(cloneSequence(arDouble
));
776 Sequence
< TestEnum
> arEnumTemp(cloneSequence(arEnum
));
777 Sequence
< OUString
> arStringTemp(cloneSequence(arString
));
778 Sequence
< Reference
< XInterface
> > arObjectTemp(
779 cloneSequence(arObject
));
780 Sequence
< Any
> arAnyTemp(cloneSequence(arAny
));
781 Sequence
< Sequence
< sal_Int32
> > arLong2Temp(arLong3
[0]);
782 Sequence
< Sequence
< Sequence
< sal_Int32
> > > arLong3Temp(arLong3
);
783 xBT2
->setSequencesInOut(
784 arBoolTemp
, arCharTemp
, arByteTemp
, arShortTemp
, arUShortTemp
,
785 arLongTemp
,arULongTemp
, arHyperTemp
, arUHyperTemp
, arFloatTemp
,
786 arDoubleTemp
, arEnumTemp
, arStringTemp
, arObjectTemp
, arAnyTemp
,
787 arLong2Temp
, arLong3Temp
);
789 (arBoolTemp
== arBool
&& arCharTemp
== arChar
&&
790 arByteTemp
== arByte
&& arShortTemp
== arShort
&&
791 arUShortTemp
== arUShort
&& arLongTemp
== arLong
&&
792 arULongTemp
== arULong
&& arHyperTemp
== arHyper
&&
793 arUHyperTemp
== arUHyper
&& arFloatTemp
== arFloat
&&
794 arDoubleTemp
== arDouble
&& arEnumTemp
== arEnum
&&
795 arStringTemp
== arString
&& arObjectTemp
== arObject
&&
796 arAnyTemp
== arAny
&& arLong2Temp
== arLong3
[0] &&
797 arLong3Temp
== arLong3
),
799 Sequence
< sal_Bool
> arBoolOut
;
800 Sequence
< sal_Unicode
> arCharOut
;
801 Sequence
< sal_Int8
> arByteOut
;
802 Sequence
< sal_Int16
> arShortOut
;
803 Sequence
< sal_uInt16
> arUShortOut
;
804 Sequence
< sal_Int32
> arLongOut
;
805 Sequence
< sal_uInt32
> arULongOut
;
806 Sequence
< sal_Int64
> arHyperOut
;
807 Sequence
< sal_uInt64
> arUHyperOut
;
808 Sequence
< float > arFloatOut
;
809 Sequence
< double > arDoubleOut
;
810 Sequence
< TestEnum
> arEnumOut
;
811 Sequence
< OUString
> arStringOut
;
812 Sequence
< Reference
< XInterface
> > arObjectOut
;
813 Sequence
< Any
> arAnyOut
;
814 Sequence
< Sequence
< sal_Int32
> > arLong2Out
;
815 Sequence
< Sequence
< Sequence
< sal_Int32
> > > arLong3Out
;
816 xBT2
->setSequencesOut(
817 arBoolOut
, arCharOut
, arByteOut
, arShortOut
, arUShortOut
,
818 arLongOut
,arULongOut
, arHyperOut
, arUHyperOut
, arFloatOut
,
819 arDoubleOut
, arEnumOut
, arStringOut
, arObjectOut
, arAnyOut
,
820 arLong2Out
, arLong3Out
);
822 (arBoolOut
== arBool
&& arCharOut
== arChar
&&
823 arByteOut
== arByte
&& arShortOut
== arShort
&&
824 arUShortOut
== arUShort
&& arLongOut
== arLong
&&
825 arULongOut
== arULong
&& arHyperOut
== arHyper
&&
826 arUHyperOut
== arUHyper
&& arFloatOut
== arFloat
&&
827 arDoubleOut
== arDouble
&& arEnumOut
== arEnum
&&
828 arStringOut
== arString
&& arObjectOut
== arObject
&&
829 arAnyOut
== arAny
&& arLong2Out
== arLong3
[0] &&
830 arLong3Out
== arLong3
),
834 // Test with empty sequences:
835 Sequence
< Sequence
< sal_Int32
> > arLong2
;
836 Sequence
< Sequence
< sal_Int32
> > seqSeqRet(xBT2
->setDim2(arLong2
));
837 bRet
&= check(seqSeqRet
== arLong2
, "sequence test");
838 Sequence
< Sequence
< Sequence
< sal_Int32
> > > arLong3
;
839 Sequence
< Sequence
< Sequence
< sal_Int32
> > > seqSeqRet2(
840 xBT2
->setDim3(arLong3
));
841 bRet
&= check(seqSeqRet2
== arLong3
, "sequence test");
842 Sequence
< Any
> arAny
;
843 Sequence
< Any
> seqAnyRet(xBT2
->setSequenceAny(arAny
));
844 bRet
&= check(seqAnyRet
== arAny
, "sequence test");
845 Sequence
< sal_Bool
> arBool
;
846 Sequence
< sal_Bool
> seqBoolRet(xBT2
->setSequenceBool(arBool
));
847 bRet
&= check(seqBoolRet
== arBool
, "sequence test");
848 Sequence
< sal_Int8
> arByte
;
849 Sequence
< sal_Int8
> seqByteRet(xBT2
->setSequenceByte(arByte
));
850 bRet
&= check(seqByteRet
== arByte
, "sequence test");
851 Sequence
< sal_Unicode
> arChar
;
852 Sequence
< sal_Unicode
> seqCharRet(xBT2
->setSequenceChar(arChar
));
853 bRet
&= check(seqCharRet
== arChar
, "sequence test");
854 Sequence
< sal_Int16
> arShort
;
855 Sequence
< sal_Int16
> seqShortRet(xBT2
->setSequenceShort(arShort
));
856 bRet
&= check(seqShortRet
== arShort
, "sequence test");
857 Sequence
< sal_Int32
> arLong
;
858 Sequence
< sal_Int32
> seqLongRet(xBT2
->setSequenceLong(arLong
));
859 bRet
&= check(seqLongRet
== arLong
, "sequence test");
860 Sequence
< sal_Int64
> arHyper
;
861 Sequence
< sal_Int64
> seqHyperRet(xBT2
->setSequenceHyper(arHyper
));
862 bRet
&= check(seqHyperRet
== arHyper
, "sequence test");
863 Sequence
< float > arFloat
;
864 Sequence
< float > seqFloatRet(xBT2
->setSequenceFloat(arFloat
));
865 bRet
&= check(seqFloatRet
== arFloat
, "sequence test");
866 Sequence
< double > arDouble
;
867 Sequence
< double > seqDoubleRet(xBT2
->setSequenceDouble(arDouble
));
868 bRet
&= check(seqDoubleRet
== arDouble
, "sequence test");
869 Sequence
< TestEnum
> arEnum
;
870 Sequence
< TestEnum
> seqEnumRet(xBT2
->setSequenceEnum(arEnum
));
871 bRet
&= check(seqEnumRet
== arEnum
, "sequence test");
872 Sequence
< sal_uInt16
> arUShort
;
873 Sequence
< sal_uInt16
> seqUShortRet(
874 xBT2
->setSequenceUShort(arUShort
));
875 bRet
&= check(seqUShortRet
== arUShort
, "sequence test");
876 Sequence
< sal_uInt32
> arULong
;
877 Sequence
< sal_uInt32
> seqULongRet(xBT2
->setSequenceULong(arULong
));
878 bRet
&= check(seqULongRet
== arULong
, "sequence test");
879 Sequence
< sal_uInt64
> arUHyper
;
880 Sequence
< sal_uInt64
> seqUHyperRet(
881 xBT2
->setSequenceUHyper(arUHyper
));
882 bRet
&= check(seqUHyperRet
== arUHyper
, "sequence test");
883 Sequence
< Reference
< XInterface
> > arObject
;
884 Sequence
< Reference
< XInterface
> > seqObjectRet(
885 xBT2
->setSequenceXInterface(arObject
));
886 bRet
&= check(seqObjectRet
== arObject
, "sequence test");
887 Sequence
< OUString
> arString
;
888 Sequence
< OUString
> seqStringRet(
889 xBT2
->setSequenceString(arString
));
890 bRet
&= check(seqStringRet
== arString
, "sequence test");
891 Sequence
< TestElement
> arStruct
;
892 Sequence
< TestElement
> seqStructRet(
893 xBT2
->setSequenceStruct(arStruct
));
894 bRet
&= check(seqStructRet
== arStruct
, "sequence test");
896 // Issue #i60341# shows that the most interesting case is were Java
897 // calls the constructors; however, since this client is currently not
898 // available in Java, while the server is, the logic is reversed here:
900 xBT2
->testConstructorsService(xContext
);
901 } catch (const BadConstructorArguments
&) {
904 if (!noCurrentContext
) {
905 if (!(new testtools::bridgetest::CurrentContextChecker
)->perform(
906 xBT2
->getCurrentContextChecker(), 0, 1))
910 if (!(new testtools::bridgetest::CurrentContextChecker
)->perform(
911 xBT2
->getCurrentContextChecker(), 0, 2))
915 if (!(new testtools::bridgetest::CurrentContextChecker
)->perform(
916 xBT2
->getCurrentContextChecker(), 1, 2))
920 if (!(new testtools::bridgetest::CurrentContextChecker
)->perform(
921 xBT2
->getCurrentContextChecker(), 1, 3))
930 static bool raiseOnewayException( const Reference
< XBridgeTest
> & xLBT
)
933 OUString sCompare
= STRING_TEST_CONSTANT
;
934 Reference
<XInterface
> const x(xLBT
->getInterface());
937 // Note : the exception may fly or not (e.g. remote scenario).
938 // When it flies, it must contain the correct elements.
939 xLBT
->raiseRuntimeExceptionOneway( sCompare
, x
);
941 catch( const RuntimeException
& e
)
944 #if OSL_DEBUG_LEVEL == 0
945 // java stack traces trash Message
946 e
.Message
== sCompare
&&
948 xLBT
->getInterface() == e
.Context
&&
955 static bool raiseException( const Reference
< XBridgeTest
> & xLBT
)
957 sal_Int32 nCount
= 0;
964 TestData aRet
, aRet2
;
965 xLBT
->raiseException(
966 5, STRING_TEST_CONSTANT
,
967 xLBT
->getInterface() );
969 catch (const IllegalArgumentException
&rExc
)
971 if (rExc
.ArgumentPosition
== 5 &&
972 #if OSL_DEBUG_LEVEL == 0
973 // java stack traces trash Message
974 rExc
.Message
.equalsAscii( STRING_TEST_CONSTANT
) &&
976 rExc
.Context
== xLBT
->getInterface())
979 //When we check if a new compiler still works then we must not call
980 //getRuntimeException because it uses cppu::getCaughtException which
981 //does only work if all libs are build with the same runtime.
989 check( false, "### unexpected exception content!" );
992 /** it is certain, that the RuntimeException testing will fail, if no */
993 xLBT
->getRuntimeException();
996 catch (const RuntimeException
& rExc
)
998 if (rExc
.Context
== xLBT
->getInterface()
999 #if OSL_DEBUG_LEVEL == 0
1000 // java stack traces trash Message
1001 && rExc
.Message
.equalsAscii( STRING_TEST_CONSTANT
)
1009 check( false, "### unexpected exception content!" );
1012 /** it is certain, that the RuntimeException testing will fail, if no */
1013 xLBT
->setRuntimeException( 0xcafebabe );
1016 catch (const Exception
& rExc
)
1018 if (rExc
.Context
== xLBT
->getInterface()
1019 #if OSL_DEBUG_LEVEL == 0
1020 // java stack traces trash Message
1021 && rExc
.Message
.equalsAscii( STRING_TEST_CONSTANT
)
1029 check( false, "### unexpected exception content!" );
1031 return (nCount
== 3);
1036 /* Returns an acquired sequence
1038 uno_Sequence
* cloneSequence(const uno_Sequence
* val
, const Type
& type
)
1040 TypeDescription
td(type
);
1042 typelib_TypeDescription
* pTdRaw
= td
.get();
1043 typelib_IndirectTypeDescription
* pIndirectTd
=
1044 reinterpret_cast<typelib_IndirectTypeDescription
*>(pTdRaw
);
1046 typelib_TypeDescription
* pTdElem
= pIndirectTd
->pType
->pType
;
1047 sal_Int8
* buf
= new sal_Int8
[pTdElem
->nSize
* val
->nElements
];
1048 sal_Int8
* pBufCur
= buf
;
1050 uno_Sequence
* retSeq
= NULL
;
1051 switch (pTdElem
->eTypeClass
)
1053 case TypeClass_SEQUENCE
:
1055 Type
_tElem(pTdElem
->pWeakRef
);
1056 for (int i
= 0; i
< val
->nElements
; i
++)
1058 sal_Int8
const *pValBuf
= reinterpret_cast<sal_Int8
const *>(&val
->elements
+ i
* pTdElem
->nSize
);
1060 uno_Sequence
* seq
= cloneSequence(
1061 reinterpret_cast<uno_Sequence
const *>(pValBuf
),
1063 *reinterpret_cast<uno_Sequence
**>(pBufCur
) = seq
;
1064 pBufCur
+= pTdElem
->nSize
;
1069 uno_type_sequence_construct(
1070 &retSeq
, type
.getTypeLibType(), (void*) val
->elements
,
1071 val
->nElements
, reinterpret_cast< uno_AcquireFunc
>(cpp_acquire
));
1078 template<typename T
, typename U
>
1079 Sequence
<T
> cloneSequence(const Sequence
<T
>& val
)
1081 Sequence
<T
> seq( cloneSequence(val
.get(), cppu::UnoType
<cppu::UnoSequenceType
<U
>>::get()), SAL_NO_ACQUIRE
);
1086 inline bool makeSurrogate(
1087 Reference
< T
> & rOut
, Reference
< T
> const & rOriginal
)
1090 if (! rOriginal
.is())
1093 Environment aCppEnv_official
;
1094 Environment aUnoEnv_ano
;
1095 Environment aCppEnv_ano
;
1097 OUString
aCppEnvTypeName(
1098 CPPU_CURRENT_LANGUAGE_BINDING_NAME
);
1099 OUString
aUnoEnvTypeName(
1103 reinterpret_cast< uno_Environment
** >( &aCppEnv_official
),
1104 aCppEnvTypeName
.pData
, 0 );
1106 uno_createEnvironment(
1107 reinterpret_cast< uno_Environment
** >( &aCppEnv_ano
),
1108 aCppEnvTypeName
.pData
, 0 );
1109 uno_createEnvironment(
1110 reinterpret_cast< uno_Environment
** >( &aUnoEnv_ano
),
1111 aUnoEnvTypeName
.pData
, 0 );
1113 UnoInterfaceReference unoI
;
1114 Mapping
cpp2uno( aCppEnv_official
.get(), aUnoEnv_ano
.get() );
1115 Mapping
uno2cpp( aUnoEnv_ano
.get(), aCppEnv_ano
.get() );
1116 if (!cpp2uno
.is() || !uno2cpp
.is())
1118 throw RuntimeException("cannot get C++-UNO mappings!" );
1120 cpp2uno
.mapInterface(
1121 reinterpret_cast< void ** >( &unoI
.m_pUnoI
),
1122 rOriginal
.get(), cppu::UnoType
<decltype(rOriginal
)>::get() );
1125 throw RuntimeException(
1126 "mapping C++ to binary UNO failed!" );
1128 uno2cpp
.mapInterface(
1129 reinterpret_cast< void ** >( &rOut
),
1130 unoI
.get(), cppu::UnoType
<decltype(rOriginal
)>::get() );
1133 throw RuntimeException(
1134 "mapping binary UNO to C++ failed!" );
1141 sal_Int32
TestBridgeImpl::run( const Sequence
< OUString
> & rArgs
)
1142 throw (RuntimeException
, std::exception
)
1147 if (! rArgs
.getLength())
1149 throw RuntimeException( "no test object specified!\n"
1150 "usage : ServiceName of test object | -u unourl of test object" );
1153 Reference
< XInterface
> xOriginal
;
1156 if( rArgs
.getLength() > 1 && rArgs
[0] == "-u" )
1166 bool noCurrentContext
= false;
1167 if ( i
< rArgs
.getLength() && rArgs
[i
] == "noCurrentContext" )
1169 noCurrentContext
= true;
1172 bool stress
= false;
1173 if ( i
< rArgs
.getLength() && rArgs
[i
] == "stress" )
1180 Reference
< XInterface
> o
;
1182 o
= UnoUrlResolver::create(m_xContext
)->resolve(rArgs
[1]);
1184 o
= m_xContext
->getServiceManager()->createInstanceWithContext(
1185 rArgs
[0], m_xContext
);
1193 if (! xOriginal
.is())
1195 throw RuntimeException( "cannot get test object!" );
1197 Reference
< XBridgeTest
> xTest( xOriginal
, UNO_QUERY
);
1200 throw RuntimeException( "test object does not implement XBridgeTest!" );
1203 Reference
<XBridgeTest
> xLBT
;
1204 bRet
= check( makeSurrogate( xLBT
, xTest
), "makeSurrogate" );
1206 performTest( m_xContext
, xLBT
, noCurrentContext
), "standard test" )
1208 bRet
= check( raiseException( xLBT
) , "exception test" )&& bRet
;
1209 bRet
= check( raiseOnewayException( xLBT
),
1210 "oneway exception test" ) && bRet
;
1213 throw RuntimeException( "error: test failed!" );
1216 catch (const Exception
& exc
)
1218 OString
cstr( OUStringToOString( exc
.Message
, RTL_TEXTENCODING_ASCII_US
) );
1219 fprintf( stderr
, "exception occurred: %s\n", cstr
.getStr() );
1223 return bRet
? 0 : 1;
1228 OUString
TestBridgeImpl::getImplementationName()
1229 throw (RuntimeException
, std::exception
)
1231 return OUString( IMPLNAME
);
1234 sal_Bool
TestBridgeImpl::supportsService( const OUString
& rServiceName
)
1235 throw (RuntimeException
, std::exception
)
1237 return cppu::supportsService(this, rServiceName
);
1240 Sequence
< OUString
> TestBridgeImpl::getSupportedServiceNames()
1241 throw (RuntimeException
, std::exception
)
1243 return bridge_test::getSupportedServiceNames();
1249 static Reference
< XInterface
> SAL_CALL
TestBridgeImpl_create(
1250 const Reference
< XComponentContext
> & xContext
)
1252 return Reference
< XInterface
>(
1253 static_cast< OWeakObject
* >( new TestBridgeImpl( xContext
) ) );
1261 SAL_DLLPUBLIC_EXPORT
void * SAL_CALL
component_getFactory(
1262 const sal_Char
* pImplName
, void * pServiceManager
,
1263 SAL_UNUSED_PARAMETER
void * )
1267 if (pServiceManager
&& rtl_str_compare( pImplName
, IMPLNAME
) == 0)
1269 Reference
< XInterface
> xFactory(
1270 createSingleComponentFactory(
1271 bridge_test::TestBridgeImpl_create
,
1272 OUString( IMPLNAME
),
1273 bridge_test::getSupportedServiceNames() ) );
1277 xFactory
->acquire();
1278 pRet
= xFactory
.get();
1286 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */