Update ooo320-m1
[ooovba.git] / testtools / source / bridgetest / bridgetest.cxx
blobae7e9bcbdbe54575f5278e40a523fbe5aa30d308
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: bridgetest.cxx,v $
10 * $Revision: 1.24.18.1 $
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 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_testtools.hxx"
34 #include <stdio.h>
35 #include <osl/diagnose.h>
36 #include "osl/diagnose.hxx"
37 #include <osl/time.h>
38 #include <sal/types.h>
39 #include "typelib/typedescription.hxx"
40 #include <uno/dispatcher.hxx>
41 #include "uno/mapping.hxx"
42 #include <uno/data.h>
43 #include "uno/environment.hxx"
45 #include <cppuhelper/factory.hxx>
46 #include <cppuhelper/implbase2.hxx>
47 #include <cppuhelper/implbase1.hxx>
49 #include <com/sun/star/lang/XServiceInfo.hpp>
50 #include <com/sun/star/lang/XComponent.hpp>
51 #include <com/sun/star/lang/XMain.hpp>
52 #include <com/sun/star/registry/XRegistryKey.hpp>
53 #include <com/sun/star/bridge/UnoUrlResolver.hpp>
54 #include <com/sun/star/bridge/XUnoUrlResolver.hpp>
55 #include "com/sun/star/uno/RuntimeException.hpp"
56 #include "com/sun/star/uno/Type.hxx"
58 #include "test/testtools/bridgetest/BadConstructorArguments.hpp"
59 #include "test/testtools/bridgetest/TestPolyStruct.hpp"
60 #include "test/testtools/bridgetest/XBridgeTest.hpp"
61 #include "test/testtools/bridgetest/XBridgeTest2.hpp"
62 #include "test/testtools/bridgetest/XMulti.hpp"
64 #include "currentcontextchecker.hxx"
65 #include "multi.hxx"
67 using namespace rtl;
68 using namespace osl;
69 using namespace cppu;
70 using namespace com::sun::star::uno;
71 using namespace com::sun::star::lang;
72 using namespace com::sun::star::registry;
73 using namespace com::sun::star::bridge;
74 using namespace test::testtools::bridgetest;
76 #define SERVICENAME "com.sun.star.test.bridge.BridgeTest"
77 #define IMPLNAME "com.sun.star.comp.bridge.BridgeTest"
79 #define OUSTR(x) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(x) )
80 #define STRING_TEST_CONSTANT "\" paco\' chorizo\\\' \"\'"
82 namespace bridge_test
84 template< class T>
85 Sequence<T> cloneSequence(const Sequence<T>& val);
87 //--------------------------------------------------------------------------------------------------
88 inline static Sequence< OUString > getSupportedServiceNames()
90 OUString aName( RTL_CONSTASCII_USTRINGPARAM(SERVICENAME) );
91 return Sequence< OUString >( &aName, 1 );
94 static bool check( bool b , char const * message )
96 if ( ! b )
97 fprintf( stderr, "%s failed\n" , message );
98 return b;
101 namespace {
103 bool checkEmpty(rtl::OUString const & string, char const * message) {
104 bool ok = string.getLength() == 0;
105 if (!ok) {
106 fprintf(
107 stderr, "%s failed: %s\n", message,
108 rtl::OUStringToOString(string, RTL_TEXTENCODING_UTF8).getStr());
110 return ok;
115 //==================================================================================================
116 class TestBridgeImpl : protected osl::DebugBase<TestBridgeImpl>,
117 public WeakImplHelper2< XMain, XServiceInfo >
119 Reference< XComponentContext > m_xContext;
121 public:
122 TestBridgeImpl( const Reference< XComponentContext > & xContext )
123 : m_xContext( xContext )
125 virtual ~TestBridgeImpl()
129 // XServiceInfo
130 virtual OUString SAL_CALL getImplementationName() throw (RuntimeException);
131 virtual sal_Bool SAL_CALL supportsService( const OUString & rServiceName ) throw (RuntimeException);
132 virtual Sequence< OUString > SAL_CALL getSupportedServiceNames() throw (RuntimeException);
134 // XMain
135 virtual sal_Int32 SAL_CALL run( const Sequence< OUString > & rArgs ) throw (RuntimeException);
138 //==================================================================================================
139 static sal_Bool equals( const TestElement & rData1, const TestElement & rData2 )
141 check( rData1.Bool == rData2.Bool, "### bool does not match!" );
142 check( rData1.Char == rData2.Char, "### char does not match!" );
143 check( rData1.Byte == rData2.Byte, "### byte does not match!" );
144 check( rData1.Short == rData2.Short, "### short does not match!" );
145 check( rData1.UShort == rData2.UShort, "### unsigned short does not match!" );
146 check( rData1.Long == rData2.Long, "### long does not match!" );
147 check( rData1.ULong == rData2.ULong, "### unsigned long does not match!" );
148 check( rData1.Hyper == rData2.Hyper, "### hyper does not match!" );
149 check( rData1.UHyper == rData2.UHyper, "### unsigned hyper does not match!" );
150 check( rData1.Float == rData2.Float, "### float does not match!" );
151 check( rData1.Double == rData2.Double, "### double does not match!" );
152 check( rData1.Enum == rData2.Enum, "### enum does not match!" );
153 check( rData1.String == rData2.String, "### string does not match!" );
154 check( rData1.Interface == rData2.Interface, "### interface does not match!" );
155 check( rData1.Any == rData2.Any, "### any does not match!" );
157 return (rData1.Bool == rData2.Bool &&
158 rData1.Char == rData2.Char &&
159 rData1.Byte == rData2.Byte &&
160 rData1.Short == rData2.Short &&
161 rData1.UShort == rData2.UShort &&
162 rData1.Long == rData2.Long &&
163 rData1.ULong == rData2.ULong &&
164 rData1.Hyper == rData2.Hyper &&
165 rData1.UHyper == rData2.UHyper &&
166 rData1.Float == rData2.Float &&
167 rData1.Double == rData2.Double &&
168 rData1.Enum == rData2.Enum &&
169 rData1.String == rData2.String &&
170 rData1.Interface == rData2.Interface &&
171 rData1.Any == rData2.Any);
173 //==================================================================================================
174 static sal_Bool equals( const TestData & rData1, const TestData & rData2 )
176 sal_Int32 nLen;
178 if ((rData1.Sequence == rData2.Sequence) &&
179 equals( (const TestElement &)rData1, (const TestElement &)rData2 ) &&
180 (nLen = rData1.Sequence.getLength()) == rData2.Sequence.getLength())
182 // once again by hand sequence ==
183 const TestElement * pElements1 = rData1.Sequence.getConstArray();
184 const TestElement * pElements2 = rData2.Sequence.getConstArray();
185 for ( ; nLen--; )
187 if (! equals( pElements1[nLen], pElements2[nLen] ))
189 check( sal_False, "### sequence element did not match!" );
190 return sal_False;
193 return sal_True;
195 return sal_False;
197 //==================================================================================================
198 static void assign( TestElement & rData,
199 sal_Bool bBool, sal_Unicode cChar, sal_Int8 nByte,
200 sal_Int16 nShort, sal_uInt16 nUShort,
201 sal_Int32 nLong, sal_uInt32 nULong,
202 sal_Int64 nHyper, sal_uInt64 nUHyper,
203 float fFloat, double fDouble,
204 TestEnum eEnum, const ::rtl::OUString& rStr,
205 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& xTest,
206 const ::com::sun::star::uno::Any& rAny )
208 rData.Bool = bBool;
209 rData.Char = cChar;
210 rData.Byte = nByte;
211 rData.Short = nShort;
212 rData.UShort = nUShort;
213 rData.Long = nLong;
214 rData.ULong = nULong;
215 rData.Hyper = nHyper;
216 rData.UHyper = nUHyper;
217 rData.Float = fFloat;
218 rData.Double = fDouble;
219 rData.Enum = eEnum;
220 rData.String = rStr;
221 rData.Interface = xTest;
222 rData.Any = rAny;
225 namespace {
227 template < typename T >
228 bool testAny(
229 T const & value, Reference< XBridgeTest > const & xLBT,
230 char const * typeName = 0)
232 Any any;
233 any <<= value;
234 Any any2 = xLBT->transportAny(any);
235 bool success = true;
236 if (any != any2) {
237 fprintf(
238 stderr, "any is different after roundtrip: in %s, out %s\n",
239 OUStringToOString(
240 any.getValueType().getTypeName(),
241 RTL_TEXTENCODING_ASCII_US).getStr(),
242 OUStringToOString(
243 any2.getValueType().getTypeName(),
244 RTL_TEXTENCODING_ASCII_US).getStr());
245 success = false;
247 if (typeName != 0
248 && !any2.getValueType().getTypeName().equalsAscii(typeName))
250 fprintf(
251 stderr, "any has wrong type after roundtrip: %s instead of %s\n",
252 OUStringToOString(
253 any2.getValueType().getTypeName(),
254 RTL_TEXTENCODING_ASCII_US).getStr(),
255 typeName);
256 success = false;
258 return success;
263 static sal_Bool performAnyTest( const Reference< XBridgeTest > &xLBT, const TestData &data)
265 bool bReturn = true;
266 bReturn = testAny( data.Byte ,xLBT ) && bReturn;
267 bReturn = testAny( data.Short,xLBT ) && bReturn;
268 bReturn = testAny( data.UShort,xLBT ) && bReturn;
269 bReturn = testAny( data.Long,xLBT ) && bReturn;
270 bReturn = testAny( data.ULong,xLBT ) && bReturn;
271 bReturn = testAny( data.Hyper,xLBT ) && bReturn;
272 bReturn = testAny( data.UHyper,xLBT ) && bReturn;
273 bReturn = testAny( data.Float,xLBT ) && bReturn;
274 bReturn = testAny( data.Double,xLBT ) && bReturn;
275 bReturn = testAny( data.Enum,xLBT ) && bReturn;
276 bReturn = testAny( data.String,xLBT ) && bReturn;
277 bReturn = testAny( data.Interface,xLBT ) && bReturn;
278 bReturn = testAny( data, xLBT ) && bReturn;
279 bReturn &= testAny(
280 TestPolyStruct< sal_Unicode >(' '), xLBT,
281 "test.testtools.bridgetest.TestPolyStruct<char>");
283 Any a;
285 a.setValue( &(data.Bool) , getCppuBooleanType() );
286 Any a2 = xLBT->transportAny( a );
287 OSL_ASSERT( a2 == a );
291 a.setValue( &(data.Char) , getCppuCharType() );
292 Any a2 = xLBT->transportAny( a );
293 OSL_ASSERT( a2 == a );
296 return bReturn;
299 //_______________________________________________________________________________________
300 static sal_Bool performSequenceOfCallTest( const Reference < XBridgeTest > &xLBT )
302 sal_Int32 i,nRounds;
303 sal_Int32 nGlobalIndex = 0;
304 const sal_Int32 nWaitTimeSpanMUSec = 10000;
305 for( nRounds = 0 ; nRounds < 10 ; nRounds ++ )
307 for( i = 0 ; i < nRounds ; i ++ )
309 // fire oneways
310 xLBT->callOneway( nGlobalIndex , nWaitTimeSpanMUSec );
311 nGlobalIndex ++;
314 // call synchron
315 xLBT->call( nGlobalIndex , nWaitTimeSpanMUSec );
316 nGlobalIndex ++;
319 return xLBT->sequenceOfCallTestPassed();
322 class ORecursiveCall : public WeakImplHelper1< XRecursiveCall >
324 private:
325 Mutex m_mutex;
327 public:
328 void SAL_CALL callRecursivly(
329 const ::com::sun::star::uno::Reference< XRecursiveCall >& xCall,
330 sal_Int32 nToCall )
331 throw(::com::sun::star::uno::RuntimeException)
333 MutexGuard guard( m_mutex );
334 if( nToCall )
336 nToCall --;
337 xCall->callRecursivly( this , nToCall );
344 //_______________________________________________________________________________________
345 static sal_Bool performRecursiveCallTest( const Reference < XBridgeTest > & xLBT )
347 xLBT->startRecursiveCall( new ORecursiveCall , 50 );
348 // on failure, the test would lock up or crash
349 return sal_True;
352 static sal_Bool performQueryForUnknownType( const Reference< XBridgeTest > & xLBT )
354 sal_Bool bRet = sal_True;
355 // use this when you want to test querying for unknown types
356 // currently (not supported by the java remote bridge )
358 // test queryInterface for an unknown type
359 typelib_TypeDescriptionReference *pTypeRef = 0;
360 OUString aName( RTL_CONSTASCII_USTRINGPARAM( "foo.MyInterface" ) );
361 typelib_typedescriptionreference_new(
362 &pTypeRef, typelib_TypeClass_INTERFACE, aName.pData);
365 Any a = xLBT->queryInterface( Type( pTypeRef ) );
366 bRet = check( a == Any( ), "got an foo.MyInterface, but didn't expect to get one" );
368 catch( com::sun::star::uno::RuntimeException & )
370 fprintf(
371 stderr,
372 "tried to query for an interface reference of an unknown type "
373 "but got a runtime exception. This should work for native bridges "
374 "but isn't implemented for Java remote bridge\n"
375 "Note: All subsequent tests may fail now as the remote bridge is broken\n"
376 "QueryForUnknownType" );
378 typelib_typedescriptionreference_release( pTypeRef );
380 return bRet;
383 class MyClass : public osl::DebugBase<MyClass>, public OWeakObject
385 public:
386 MyClass();
387 virtual ~MyClass();
388 virtual void SAL_CALL acquire() throw ();
389 virtual void SAL_CALL release() throw ();
392 //______________________________________________________________________________
393 MyClass::MyClass()
396 //______________________________________________________________________________
397 MyClass::~MyClass()
400 //______________________________________________________________________________
401 void MyClass::acquire() throw ()
403 OWeakObject::acquire();
405 //______________________________________________________________________________
406 void MyClass::release() throw ()
408 OWeakObject::release();
411 //==================================================================================================
412 static sal_Bool performTest(
413 const Reference<XComponentContext> & xContext,
414 const Reference<XBridgeTest > & xLBT,
415 bool noCurrentContext )
417 check( xLBT.is(), "### no test interface!" );
418 bool bRet = true;
419 if (xLBT.is())
421 // this data is never ever granted access to by calls other than equals(), assign()!
422 TestData aData; // test against this data
424 Reference<XInterface > xI( new MyClass );
426 assign( (TestElement &)aData,
427 sal_True, '@', 17, 0x1234, 0xfedc, 0x12345678, 0xfedcba98,
428 SAL_CONST_INT64(0x123456789abcdef0),
429 SAL_CONST_UINT64(0xfedcba9876543210),
430 (float)17.0815, 3.1415926359, TestEnum_LOLA,
431 OUSTR(STRING_TEST_CONSTANT), xI,
432 Any( &xI, ::getCppuType( (const Reference<XInterface > *)0 ) ) );
434 bRet = check( aData.Any == xI, "### unexpected any!" ) && bRet;
435 bRet = check( !(aData.Any != xI), "### unexpected any!" ) && bRet;
437 aData.Sequence.realloc( 2 );
438 aData.Sequence[ 0 ] = *(const TestElement *)&aData;
439 // aData.Sequence[ 1 ] is empty
441 // aData complete
442 //================================================================================
444 // this is a manually copy of aData for first setting...
445 TestData aSetData;
447 assign( (TestElement &)aSetData,
448 aData.Bool, aData.Char, aData.Byte, aData.Short, aData.UShort,
449 aData.Long, aData.ULong, aData.Hyper, aData.UHyper, aData.Float, aData.Double,
450 aData.Enum, aData.String, xI,
451 Any( &xI, ::getCppuType( (const Reference<XInterface > *)0 ) ) );
453 aSetData.Sequence.realloc( 2 );
454 aSetData.Sequence[ 0 ] = *(const TestElement *)&aSetData;
455 // aSetData.Sequence[ 1 ] is empty
457 xLBT->setValues(
458 aSetData.Bool, aSetData.Char, aSetData.Byte, aSetData.Short, aSetData.UShort,
459 aSetData.Long, aSetData.ULong, aSetData.Hyper, aSetData.UHyper, aSetData.Float, aSetData.Double,
460 aSetData.Enum, aSetData.String, aSetData.Interface, aSetData.Any, aSetData.Sequence, aSetData );
463 TestData aRet, aRet2;
464 xLBT->getValues(
465 aRet.Bool, aRet.Char, aRet.Byte, aRet.Short, aRet.UShort,
466 aRet.Long, aRet.ULong, aRet.Hyper, aRet.UHyper, aRet.Float, aRet.Double,
467 aRet.Enum, aRet.String, aRet.Interface, aRet.Any, aRet.Sequence, aRet2 );
469 bRet = check( equals( aData, aRet ) && equals( aData, aRet2 ) , "getValues test") && bRet;
471 // set last retrieved values
472 TestData aSV2ret = xLBT->setValues2(
473 aRet.Bool, aRet.Char, aRet.Byte, aRet.Short, aRet.UShort,
474 aRet.Long, aRet.ULong, aRet.Hyper, aRet.UHyper, aRet.Float, aRet.Double,
475 aRet.Enum, aRet.String, aRet.Interface, aRet.Any, aRet.Sequence, aRet2 );
476 // check inout sequence order
477 // => inout sequence parameter was switched by test objects
478 TestElement temp = aRet.Sequence[ 0 ];
479 aRet.Sequence[ 0 ] = aRet.Sequence[ 1 ];
480 aRet.Sequence[ 1 ] = temp;
482 bRet = check(
483 equals( aData, aSV2ret ) && equals( aData, aRet2 ),
484 "getValues2 test") && bRet;
487 TestData aRet, aRet2;
488 TestData aGVret = xLBT->getValues(
489 aRet.Bool, aRet.Char, aRet.Byte, aRet.Short, aRet.UShort,
490 aRet.Long, aRet.ULong, aRet.Hyper, aRet.UHyper, aRet.Float, aRet.Double,
491 aRet.Enum, aRet.String, aRet.Interface, aRet.Any, aRet.Sequence, aRet2 );
493 bRet = check( equals( aData, aRet ) && equals( aData, aRet2 ) && equals( aData, aGVret ), "getValues test" ) && bRet;
495 // set last retrieved values
496 xLBT->setBool( aRet.Bool );
497 xLBT->setChar( aRet.Char );
498 xLBT->setByte( aRet.Byte );
499 xLBT->setShort( aRet.Short );
500 xLBT->setUShort( aRet.UShort );
501 xLBT->setLong( aRet.Long );
502 xLBT->setULong( aRet.ULong );
503 xLBT->setHyper( aRet.Hyper );
504 xLBT->setUHyper( aRet.UHyper );
505 xLBT->setFloat( aRet.Float );
506 xLBT->setDouble( aRet.Double );
507 xLBT->setEnum( aRet.Enum );
508 xLBT->setString( aRet.String );
509 xLBT->setInterface( aRet.Interface );
510 xLBT->setAny( aRet.Any );
511 xLBT->setSequence( aRet.Sequence );
512 xLBT->setStruct( aRet2 );
515 TestData aRet, aRet2;
516 aRet.Hyper = xLBT->getHyper();
517 aRet.UHyper = xLBT->getUHyper();
518 aRet.Float = xLBT->getFloat();
519 aRet.Double = xLBT->getDouble();
520 aRet.Byte = xLBT->getByte();
521 aRet.Char = xLBT->getChar();
522 aRet.Bool = xLBT->getBool();
523 aRet.Short = xLBT->getShort();
524 aRet.UShort = xLBT->getUShort();
525 aRet.Long = xLBT->getLong();
526 aRet.ULong = xLBT->getULong();
527 aRet.Enum = xLBT->getEnum();
528 aRet.String = xLBT->getString();
529 aRet.Interface = xLBT->getInterface();
530 aRet.Any = xLBT->getAny();
531 aRet.Sequence = xLBT->getSequence();
532 aRet2 = xLBT->getStruct();
534 bRet = check( equals( aData, aRet ) && equals( aData, aRet2 ) , "struct comparison test") && bRet;
536 // Test extended attributes that raise exceptions:
537 try {
538 xLBT->getRaiseAttr1();
539 bRet &= check(false, "getRaiseAttr1 did not throw");
540 } catch (RuntimeException &) {
541 } catch (...) {
542 bRet &= check(false, "getRaiseAttr1 threw wrong type");
544 try {
545 xLBT->setRaiseAttr1(0);
546 bRet &= check(false, "setRaiseAttr1 did not throw");
547 } catch (IllegalArgumentException &) {
548 } catch (...) {
549 bRet &= check(false, "setRaiseAttr1 threw wrong type");
551 try {
552 xLBT->getRaiseAttr2();
553 bRet &= check(false, "getRaiseAttr2 did not throw");
554 } catch (IllegalArgumentException &) {
555 } catch (...) {
556 bRet &= check(false, "getRaiseAttr2 threw wrong type");
559 // Test instantiated polymorphic struct types:
561 bRet &= check(
562 xLBT->transportPolyBoolean(TestPolyStruct< sal_Bool >(true)).member,
563 "transportPolyBoolean");
564 TestPolyStruct< sal_Int64 > tps1(12345);
565 xLBT->transportPolyHyper(tps1);
566 bRet &= check(tps1.member == 12345, "transportPolyHyper");
567 Sequence< Any > seq(2);
568 seq[0] <<= static_cast< sal_uInt32 >(33);
569 seq[1] <<= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ABC"));
570 TestPolyStruct< Sequence< Any > > tps2(seq);
571 TestPolyStruct< Sequence< Any > > tps3;
572 xLBT->transportPolySequence(tps2, tps3);
573 bRet &= check(
574 tps3.member.getLength() == 2, "transportPolySequence, length");
575 sal_uInt32 v0 = sal_uInt32();
576 tps3.member[0] >>= v0;
577 bRet &= check(v0 == 33, "transportPolySequence, element 0");
578 rtl::OUString v1;
579 tps3.member[1] >>= v1;
580 bRet &= check(
581 v1.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("ABC")),
582 "transportPolySequence, element 1");
583 bRet &= check(xLBT->getNullPolyLong().member == 0, "getNullPolyLong");
584 bRet &= check(
585 xLBT->getNullPolyString().member.getLength() == 0,
586 "getNullPolyString");
587 bRet &= check(
588 xLBT->getNullPolyType().member == Type(), "getNullPolyType");
589 Any nullAny(xLBT->getNullPolyAny().member);
590 bRet &= check(
591 (((nullAny.getValueTypeName()
592 == rtl::OUString(
593 RTL_CONSTASCII_USTRINGPARAM("com.sun.star.uno.XInterface")))
594 && !static_cast< Reference< XInterface > const * >(
595 nullAny.getValue())->is())
596 || nullAny == Any()),
597 "getNullPolyAny");
598 bRet &= check(
599 xLBT->getNullPolySequence().member.getLength() == 0,
600 "getNullPolySequence");
601 bRet &= check(
602 xLBT->getNullPolyEnum().member == TestEnum_TEST, "getNullPolyEnum");
603 bRet &= check(
604 xLBT->getNullPolyBadEnum().member == TestBadEnum_M,
605 "getNullPolyBadEnum");
606 bRet &= check(
607 xLBT->getNullPolyStruct().member.member == 0, "getNullPolyStruct");
608 bRet &= check(
609 !xLBT->getNullPolyInterface().member.is(), "getNullPolyInterface");
612 // any test
613 bRet = check( performAnyTest( xLBT , aData ) , "any test" ) && bRet;
615 // sequence of call test
616 bRet = check( performSequenceOfCallTest( xLBT ) , "sequence of call test" ) && bRet;
618 // recursive call test
619 bRet = check( performRecursiveCallTest( xLBT ) , "recursive test" ) && bRet;
621 bRet = (equals( aData, aRet ) && equals( aData, aRet2 )) && bRet ;
623 // multiple inheritance test
624 bRet &= checkEmpty(
625 testtools::bridgetest::testMulti(xLBT->getMulti()), "remote multi");
626 bRet &= checkEmpty(
627 xLBT->testMulti(new testtools::bridgetest::Multi), "local multi");
632 Reference<XBridgeTest2> xBT2(xLBT, UNO_QUERY);
633 if ( ! xBT2.is())
634 return bRet;
636 // perform sequence tests (XBridgeTest2)
637 // create the sequence which are compared with the results
638 sal_Bool _arBool[] = {sal_True, sal_False, sal_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"))
657 sal_Bool _aBool = sal_True;
658 sal_Int32 _aInt = 0xbabebabe;
659 float _aFloat = 3.14f;
660 Any _any1(&_aBool, getCppuBooleanType());
661 Any _any2(&_aInt, getCppuType((sal_Int32*) 0));
662 Any _any3(&_aFloat, getCppuType((float*) 0));
663 Any _arAny[] = { _any1, _any2, _any3};
665 Reference<XInterface> _arObj[3];
666 _arObj[0] = new OWeakObject();
667 _arObj[1] = new OWeakObject();
668 _arObj[2] = new OWeakObject();
670 TestEnum _arEnum[] = {TestEnum_ONE, TestEnum_TWO, TestEnum_CHECK};
672 TestElement _arStruct[3];
673 assign( _arStruct[0], sal_True, '@', 17, 0x1234, 0xfedc, 0x12345678, 0xfedcba98,
674 SAL_CONST_INT64(0x123456789abcdef0),
675 SAL_CONST_UINT64(0xfedcba9876543210),
676 17.0815f, 3.1415926359,
677 TestEnum_LOLA, OUSTR(STRING_TEST_CONSTANT), _arObj[0],
678 Any( &_arObj[0], ::getCppuType( (const Reference<XInterface > *)0 ) ) );
679 assign( _arStruct[1], sal_True, 'A', 17, 0x1234, 0xfedc, 0x12345678, 0xfedcba98,
680 SAL_CONST_INT64(0x123456789abcdef0),
681 SAL_CONST_UINT64(0xfedcba9876543210),
682 17.0815f, 3.1415926359,
683 TestEnum_TWO, OUSTR(STRING_TEST_CONSTANT), _arObj[1],
684 Any( &_arObj[1], ::getCppuType( (const Reference<XInterface > *)0 ) ) );
685 assign( _arStruct[2], sal_True, 'B', 17, 0x1234, 0xfedc, 0x12345678, 0xfedcba98,
686 SAL_CONST_INT64(0x123456789abcdef0),
687 SAL_CONST_UINT64(0xfedcba9876543210),
688 17.0815f, 3.1415926359,
689 TestEnum_CHECK, OUSTR(STRING_TEST_CONSTANT), _arObj[2],
690 Any( &_arObj[2], ::getCppuType( (const Reference<XInterface > *)0 ) ) );
693 Sequence<sal_Bool> arBool(_arBool, 3);
694 Sequence<sal_Unicode> arChar( _arChar, 3);
695 Sequence<sal_Int8> arByte(_arByte, 3);
696 Sequence<sal_Int16> arShort(_arShort, 3);
697 Sequence<sal_uInt16> arUShort(_arUShort, 3);
698 Sequence<sal_Int32> arLong(_arLong, 3);
699 Sequence<sal_uInt32> arULong(_arULong, 3);
700 Sequence<sal_Int64> arHyper(_arHyper, 3);
701 Sequence<sal_uInt64> arUHyper(_arUHyper, 3);
702 Sequence<float> arFloat(_arFloat, 3);
703 Sequence<double> arDouble(_arDouble, 3);
704 Sequence<OUString> arString(_arString, 3);
705 Sequence<Any> arAny(_arAny, 3);
706 Sequence<Reference<XInterface> > arObject(_arObj, 3);
707 Sequence<TestEnum> arEnum(_arEnum, 3);
708 Sequence<TestElement> arStruct(_arStruct, 3);
709 Sequence<Sequence<sal_Int32> > _arSeqLong2[3];
710 for (int j = 0; j < 3; j++)
712 Sequence<sal_Int32> _arSeqLong[3];
713 for (int i = 0; i < 3; i++)
715 _arSeqLong[i] = Sequence<sal_Int32>(_arLong, 3);
718 _arSeqLong2[j] = Sequence< Sequence<sal_Int32> > (_arSeqLong, 3);
721 Sequence<Sequence<Sequence<sal_Int32> > > arLong3( _arSeqLong2, 3);
722 Sequence<Sequence<sal_Int32> > seqSeqRet = xBT2->setDim2(arLong3[0]);
723 bRet = check( seqSeqRet == arLong3[0], "sequence test") && bRet;
724 Sequence<Sequence<Sequence<sal_Int32> > > seqSeqRet2 = xBT2->setDim3(arLong3);
725 bRet = check( seqSeqRet2 == arLong3, "sequence test") && bRet;
726 Sequence<Any> seqAnyRet = xBT2->setSequenceAny(arAny);
727 bRet = check( seqAnyRet == arAny, "sequence test") && bRet;
728 Sequence<sal_Bool> seqBoolRet = xBT2->setSequenceBool(arBool);
729 bRet = check( seqBoolRet == arBool, "sequence test") && bRet;
730 Sequence<sal_Int8> seqByteRet = xBT2->setSequenceByte(arByte);
731 bRet = check( seqByteRet == arByte, "sequence test") && bRet;
732 Sequence<sal_Unicode> seqCharRet = xBT2->setSequenceChar(arChar);
733 bRet = check( seqCharRet == arChar, "sequence test") && bRet;
734 Sequence<sal_Int16> seqShortRet = xBT2->setSequenceShort(arShort);
735 bRet = check( seqShortRet == arShort, "sequence test") && bRet;
736 Sequence<sal_Int32> seqLongRet = xBT2->setSequenceLong(arLong);
737 bRet = check( seqLongRet == arLong, "sequence test") && bRet;
738 Sequence<sal_Int64> seqHyperRet = xBT2->setSequenceHyper(arHyper);
739 bRet = check( seqHyperRet == arHyper, "sequence test") && bRet;
740 Sequence<float> seqFloatRet = xBT2->setSequenceFloat(arFloat);
741 bRet = check( seqFloatRet == arFloat, "sequence test") && bRet;
742 Sequence<double> seqDoubleRet = xBT2->setSequenceDouble(arDouble);
743 bRet = check( seqDoubleRet == arDouble, "sequence test") && bRet;
744 Sequence<TestEnum> seqEnumRet = xBT2->setSequenceEnum(arEnum);
745 bRet = check( seqEnumRet == arEnum, "sequence test") && bRet;
746 Sequence<sal_uInt16> seqUShortRet = xBT2->setSequenceUShort(arUShort);
747 bRet = check( seqUShortRet == arUShort, "sequence test") && bRet;
748 Sequence<sal_uInt32> seqULongRet = xBT2->setSequenceULong(arULong);
749 bRet = check( seqULongRet == arULong, "sequence test") && bRet;
750 Sequence<sal_uInt64> seqUHyperRet = xBT2->setSequenceUHyper(arUHyper);
751 bRet = check( seqUHyperRet == arUHyper, "sequence test") && bRet;
752 Sequence<Reference<XInterface> > seqObjectRet = xBT2->setSequenceXInterface(arObject);
753 bRet = check( seqObjectRet == arObject, "sequence test") && bRet;
754 Sequence<OUString> seqStringRet = xBT2->setSequenceString(arString);
755 bRet = check( seqStringRet == arString, "sequence test") && bRet;
756 Sequence<TestElement> seqStructRet = xBT2->setSequenceStruct(arStruct);
757 bRet = check( seqStructRet == arStruct, "sequence test") && bRet;
759 Sequence<sal_Bool> arBoolTemp = cloneSequence(arBool);
760 Sequence<sal_Unicode> arCharTemp = cloneSequence(arChar);
761 Sequence<sal_Int8> arByteTemp = cloneSequence(arByte);
762 Sequence<sal_Int16> arShortTemp = cloneSequence(arShort);
763 Sequence<sal_uInt16> arUShortTemp = cloneSequence(arUShort);
764 Sequence<sal_Int32> arLongTemp = cloneSequence(arLong);
765 Sequence<sal_uInt32> arULongTemp = cloneSequence(arULong);
766 Sequence<sal_Int64> arHyperTemp = cloneSequence(arHyper);
767 Sequence<sal_uInt64> arUHyperTemp = cloneSequence(arUHyper);
768 Sequence<float> arFloatTemp = cloneSequence(arFloat);
769 Sequence<double> arDoubleTemp = cloneSequence(arDouble);
770 Sequence<TestEnum> arEnumTemp = cloneSequence(arEnum);
771 Sequence<OUString> arStringTemp = cloneSequence(arString);
772 Reference<XInterface> _xint;
773 Sequence<Reference<XInterface> > arObjectTemp = cloneSequence(arObject);
774 Sequence<Any> arAnyTemp = cloneSequence(arAny);
775 Sequence<Sequence<sal_Int32> > arLong2Temp(arLong3[0]);
776 Sequence<Sequence<Sequence<sal_Int32> > > arLong3Temp(arLong3);
778 xBT2->setSequencesInOut(arBoolTemp, arCharTemp, arByteTemp, arShortTemp,
779 arUShortTemp, arLongTemp,arULongTemp, arHyperTemp,
780 arUHyperTemp, arFloatTemp, arDoubleTemp,
781 arEnumTemp, arStringTemp, arObjectTemp, arAnyTemp,
782 arLong2Temp, arLong3Temp);
783 bRet = check(
784 arBoolTemp == arBool &&
785 arCharTemp == arChar &&
786 arByteTemp == arByte &&
787 arShortTemp == arShort &&
788 arUShortTemp == arUShort &&
789 arLongTemp == arLong &&
790 arULongTemp == arULong &&
791 arHyperTemp == arHyper &&
792 arUHyperTemp == arUHyper &&
793 arFloatTemp == arFloat &&
794 arDoubleTemp == arDouble &&
795 arEnumTemp == arEnum &&
796 arStringTemp == arString &&
797 arObjectTemp == arObject &&
798 arAnyTemp == arAny &&
799 arLong2Temp == arLong3[0] &&
800 arLong3Temp == arLong3, "sequence test") && bRet;
802 Sequence<sal_Bool> arBoolOut;
803 Sequence<sal_Unicode> arCharOut;
804 Sequence<sal_Int8> arByteOut;
805 Sequence<sal_Int16> arShortOut;
806 Sequence<sal_uInt16> arUShortOut;
807 Sequence<sal_Int32> arLongOut;
808 Sequence<sal_uInt32> arULongOut;
809 Sequence<sal_Int64> arHyperOut;
810 Sequence<sal_uInt64> arUHyperOut;
811 Sequence<float> arFloatOut;
812 Sequence<double> arDoubleOut;
813 Sequence<TestEnum> arEnumOut;
814 Sequence<OUString> arStringOut;
815 Sequence<Reference<XInterface> > arObjectOut;
816 Sequence<Any> arAnyOut;
817 Sequence<Sequence<sal_Int32> > arLong2Out;
818 Sequence<Sequence<Sequence<sal_Int32> > > arLong3Out;
819 xBT2->setSequencesOut(arBoolOut, arCharOut, arByteOut, arShortOut,
820 arUShortOut, arLongOut,arULongOut, arHyperOut,
821 arUHyperOut, arFloatOut, arDoubleOut,
822 arEnumOut, arStringOut, arObjectOut, arAnyOut,
823 arLong2Out, arLong3Out);
824 bRet = check(
825 arBoolOut == arBool &&
826 arCharOut == arChar &&
827 arByteOut == arByte &&
828 arShortOut == arShort &&
829 arUShortOut == arUShort &&
830 arLongOut == arLong &&
831 arULongOut == arULong &&
832 arHyperOut == arHyper &&
833 arUHyperOut == arUHyper &&
834 arFloatOut == arFloat &&
835 arDoubleOut == arDouble &&
836 arEnumOut == arEnum &&
837 arStringOut == arString &&
838 arObjectOut == arObject &&
839 arAnyOut == arAny &&
840 arLong2Out == arLong3[0] &&
841 arLong3Out == arLong3, "sequence test") && bRet;
844 //test with empty sequences
845 Sequence<Sequence<sal_Int32> > arLong2;
846 Sequence<Sequence<sal_Int32> > seqSeqRet = xBT2->setDim2(arLong2);
847 bRet = check( seqSeqRet == arLong2, "sequence test") && bRet;
848 Sequence<Sequence<Sequence<sal_Int32> > > arLong3;
849 Sequence<Sequence<Sequence<sal_Int32> > > seqSeqRet2 = xBT2->setDim3(
850 arLong3);
851 bRet = check( seqSeqRet2 == arLong3, "sequence test") && bRet;
852 Sequence<Any> arAny;
853 Sequence<Any> seqAnyRet = xBT2->setSequenceAny(arAny);
854 bRet = check( seqAnyRet == arAny, "sequence test") && bRet;
855 Sequence<sal_Bool> arBool;
856 Sequence<sal_Bool> seqBoolRet = xBT2->setSequenceBool(arBool);
857 bRet = check( seqBoolRet == arBool, "sequence test") && bRet;
858 Sequence<sal_Int8> arByte;
859 Sequence<sal_Int8> seqByteRet = xBT2->setSequenceByte(arByte);
860 bRet = check( seqByteRet == arByte, "sequence test") && bRet;
861 Sequence<sal_Unicode> arChar;
862 Sequence<sal_Unicode> seqCharRet = xBT2->setSequenceChar(arChar);
863 bRet = check( seqCharRet == arChar, "sequence test") && bRet;
864 Sequence<sal_Int16> arShort;
865 Sequence<sal_Int16> seqShortRet = xBT2->setSequenceShort(arShort);
866 bRet = check( seqShortRet == arShort, "sequence test") && bRet;
867 Sequence<sal_Int32> arLong;
868 Sequence<sal_Int32> seqLongRet = xBT2->setSequenceLong(arLong);
869 bRet = check( seqLongRet == arLong, "sequence test") && bRet;
870 Sequence<sal_Int64> arHyper;
871 Sequence<sal_Int64> seqHyperRet = xBT2->setSequenceHyper(arHyper);
872 bRet = check( seqHyperRet == arHyper, "sequence test") && bRet;
873 Sequence<float> arFloat;
874 Sequence<float> seqFloatRet = xBT2->setSequenceFloat(arFloat);
875 bRet = check( seqFloatRet == arFloat, "sequence test") && bRet;
876 Sequence<double> arDouble;
877 Sequence<double> seqDoubleRet = xBT2->setSequenceDouble(arDouble);
878 bRet = check( seqDoubleRet == arDouble, "sequence test") && bRet;
879 Sequence<TestEnum> arEnum;
880 Sequence<TestEnum> seqEnumRet = xBT2->setSequenceEnum(arEnum);
881 bRet = check( seqEnumRet == arEnum, "sequence test") && bRet;
882 Sequence<sal_uInt16> arUShort;
883 Sequence<sal_uInt16> seqUShortRet = xBT2->setSequenceUShort(arUShort);
884 bRet = check( seqUShortRet == arUShort, "sequence test") && bRet;
885 Sequence<sal_uInt32> arULong;
886 Sequence<sal_uInt32> seqULongRet = xBT2->setSequenceULong(arULong);
887 bRet = check( seqULongRet == arULong, "sequence test") && bRet;
888 Sequence<sal_uInt64> arUHyper;
889 Sequence<sal_uInt64> seqUHyperRet = xBT2->setSequenceUHyper(arUHyper);
890 bRet = check( seqUHyperRet == arUHyper, "sequence test") && bRet;
891 Sequence<Reference<XInterface> > arObject;
892 Sequence<Reference<XInterface> > seqObjectRet =
893 xBT2->setSequenceXInterface(arObject);
894 bRet = check( seqObjectRet == arObject, "sequence test") && bRet;
895 Sequence<OUString> arString;
896 Sequence<OUString> seqStringRet = xBT2->setSequenceString(arString);
897 bRet = check( seqStringRet == arString, "sequence test") && bRet;
898 Sequence<TestElement> arStruct;
899 Sequence<TestElement> seqStructRet = xBT2->setSequenceStruct(arStruct);
900 bRet = check( seqStructRet == arStruct, "sequence test") && bRet;
902 // Issue #i60341# shows that the most interesting case is were Java calls
903 // the constructors; however, since this client is currently not available
904 // in Java, while the server is, the logic is reversed here:
905 try {
906 xBT2->testConstructorsService(xContext);
907 } catch (BadConstructorArguments &) {
908 bRet = false;
910 if (!noCurrentContext) {
911 if (!(new testtools::bridgetest::CurrentContextChecker)->perform(
912 xBT2->getCurrentContextChecker(), 0, 1))
914 bRet = false;
916 if (!(new testtools::bridgetest::CurrentContextChecker)->perform(
917 xBT2->getCurrentContextChecker(), 0, 2))
919 bRet = false;
921 if (!(new testtools::bridgetest::CurrentContextChecker)->perform(
922 xBT2->getCurrentContextChecker(), 1, 2))
924 bRet = false;
926 if (!(new testtools::bridgetest::CurrentContextChecker)->perform(
927 xBT2->getCurrentContextChecker(), 1, 3))
929 bRet = false;
933 return bRet;
935 static sal_Bool raiseOnewayException( const Reference < XBridgeTest > & xLBT )
937 sal_Bool bReturn = sal_True;
938 OUString sCompare = OUSTR(STRING_TEST_CONSTANT);
939 Reference<XInterface> const x(xLBT->getInterface());
942 // Note : the exception may fly or not (e.g. remote scenario).
943 // When it flies, it must contain the correct elements.
944 xLBT->raiseRuntimeExceptionOneway( sCompare, x );
946 catch( RuntimeException & e )
948 bReturn = (
949 #if OSL_DEBUG_LEVEL == 0
950 // java stack traces trash Message
951 e.Message == sCompare &&
952 #endif
953 xLBT->getInterface() == e.Context &&
954 x == e.Context );
956 return bReturn;
959 //==================================================================================================
960 static sal_Bool raiseException( const Reference< XBridgeTest > & xLBT )
962 sal_Int32 nCount = 0;
969 TestData aRet, aRet2;
970 xLBT->raiseException(
971 5, OUSTR(STRING_TEST_CONSTANT),
972 xLBT->getInterface() );
974 catch (IllegalArgumentException aExc)
976 if (aExc.ArgumentPosition == 5 &&
977 #if OSL_DEBUG_LEVEL == 0
978 // java stack traces trash Message
979 aExc.Message.compareToAscii( STRING_TEST_CONSTANT ) == 0 &&
980 #endif
981 aExc.Context == xLBT->getInterface())
983 #ifdef COMPCHECK
984 //When we check if a new compiler still works then we must not call
985 //getRuntimeException because it uses cppu::getCaughtException which
986 //does only work if all libs are build with the same runtime.
987 return true;
988 #else
989 ++nCount;
990 #endif
992 else
994 check( sal_False, "### unexpected exception content!" );
997 /** it is certain, that the RuntimeException testing will fail, if no */
998 xLBT->getRuntimeException();
1001 catch (const RuntimeException & rExc)
1003 if (rExc.Context == xLBT->getInterface()
1004 #if OSL_DEBUG_LEVEL == 0
1005 // java stack traces trash Message
1006 && rExc.Message.compareToAscii( STRING_TEST_CONSTANT ) == 0
1007 #endif
1010 ++nCount;
1012 else
1014 check( sal_False, "### unexpected exception content!" );
1017 /** it is certain, that the RuntimeException testing will fail, if no */
1018 xLBT->setRuntimeException( 0xcafebabe );
1021 catch (Exception & rExc)
1023 if (rExc.Context == xLBT->getInterface()
1024 #if OSL_DEBUG_LEVEL == 0
1025 // java stack traces trash Message
1026 && rExc.Message.compareToAscii( STRING_TEST_CONSTANT ) == 0
1027 #endif
1030 ++nCount;
1032 else
1034 check( sal_False, "### unexpected exception content!" );
1036 return (nCount == 3);
1038 return sal_False;
1041 /* Returns an acquired sequence
1043 uno_Sequence* cloneSequence(const uno_Sequence* val, const Type& type)
1045 TypeDescription td(type);
1046 td.makeComplete();
1047 typelib_TypeDescription* pTdRaw = td.get();
1048 typelib_IndirectTypeDescription* pIndirectTd =
1049 (typelib_IndirectTypeDescription*) pTdRaw;
1051 typelib_TypeDescription* pTdElem = pIndirectTd->pType->pType;
1052 sal_Int8* buf = new sal_Int8[pTdElem->nSize * val->nElements];
1053 sal_Int8* pBufCur = buf;
1055 uno_Sequence* retSeq = NULL;
1056 switch (pTdElem->eTypeClass)
1058 case TypeClass_SEQUENCE:
1060 Type _tElem(pTdElem->pWeakRef);
1061 for (int i = 0; i < val->nElements; i++)
1063 uno_Sequence* seq = cloneSequence(
1064 *(uno_Sequence**) (&val->elements + i * pTdElem->nSize),
1065 _tElem);
1066 *((uno_Sequence**) pBufCur) = seq;
1067 pBufCur += pTdElem->nSize;
1069 break;
1071 default:
1072 uno_type_sequence_construct(
1073 &retSeq, type.getTypeLibType(), (void*) val->elements,
1074 val->nElements, reinterpret_cast< uno_AcquireFunc >(cpp_acquire));
1075 break;
1077 delete[] buf;
1078 return retSeq;
1081 template< class T>
1082 Sequence<T> cloneSequence(const Sequence<T>& val)
1084 Sequence<T> seq( cloneSequence(val.get(), getCppuType(&val)), SAL_NO_ACQUIRE);
1085 return seq;
1088 template< class T >
1089 inline bool makeSurrogate(
1090 Reference< T > & rOut, Reference< T > const & rOriginal )
1092 rOut.clear();
1093 if (! rOriginal.is())
1094 return false;
1096 Environment aCppEnv_official;
1097 Environment aUnoEnv_ano;
1098 Environment aCppEnv_ano;
1100 OUString aCppEnvTypeName(
1101 RTL_CONSTASCII_USTRINGPARAM(CPPU_CURRENT_LANGUAGE_BINDING_NAME) );
1102 OUString aUnoEnvTypeName(
1103 RTL_CONSTASCII_USTRINGPARAM(UNO_LB_UNO) );
1104 // official:
1105 uno_getEnvironment(
1106 reinterpret_cast< uno_Environment ** >( &aCppEnv_official ),
1107 aCppEnvTypeName.pData, 0 );
1108 // anonymous:
1109 uno_createEnvironment(
1110 reinterpret_cast< uno_Environment ** >( &aCppEnv_ano ),
1111 aCppEnvTypeName.pData, 0 );
1112 uno_createEnvironment(
1113 reinterpret_cast< uno_Environment ** >( &aUnoEnv_ano ),
1114 aUnoEnvTypeName.pData, 0 );
1116 UnoInterfaceReference unoI;
1117 Mapping cpp2uno( aCppEnv_official.get(), aUnoEnv_ano.get() );
1118 Mapping uno2cpp( aUnoEnv_ano.get(), aCppEnv_ano.get() );
1119 if (!cpp2uno.is() || !uno2cpp.is())
1121 throw RuntimeException(
1122 OUSTR("cannot get C++-UNO mappings!"),
1123 Reference< XInterface >() );
1125 cpp2uno.mapInterface(
1126 reinterpret_cast< void ** >( &unoI.m_pUnoI ),
1127 rOriginal.get(), ::getCppuType( &rOriginal ) );
1128 if (! unoI.is())
1130 throw RuntimeException(
1131 OUSTR("mapping C++ to binary UNO failed!"),
1132 Reference< XInterface >() );
1134 uno2cpp.mapInterface(
1135 reinterpret_cast< void ** >( &rOut ),
1136 unoI.get(), ::getCppuType( &rOriginal ) );
1137 if (! rOut.is())
1139 throw RuntimeException(
1140 OUSTR("mapping binary UNO to C++ failed!"),
1141 Reference< XInterface >() );
1144 return rOut.is();
1147 //==================================================================================================
1148 sal_Int32 TestBridgeImpl::run( const Sequence< OUString > & rArgs )
1149 throw (RuntimeException)
1151 bool bRet = false;
1154 if (! rArgs.getLength())
1156 throw RuntimeException( OUString( RTL_CONSTASCII_USTRINGPARAM(
1157 "no test object specified!\n"
1158 "usage : ServiceName of test object | -u unourl of test object\n" ) ),
1159 Reference< XInterface >() );
1162 Reference< XInterface > xOriginal;
1163 bool remote;
1164 sal_Int32 i;
1165 if( rArgs.getLength() > 1 && 0 == rArgs[0].compareToAscii( "-u" ) )
1167 remote = true;
1168 i = 2;
1170 else
1172 remote = false;
1173 i = 1;
1175 bool noCurrentContext = false;
1176 if (i < rArgs.getLength()
1177 && rArgs[i].equalsAsciiL(
1178 RTL_CONSTASCII_STRINGPARAM("noCurrentContext")))
1180 noCurrentContext = true;
1181 ++i;
1183 bool stress = false;
1184 if (i < rArgs.getLength()
1185 && rArgs[i].equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("stress")))
1187 stress = true;
1188 ++i;
1191 for (;;) {
1192 Reference< XInterface > o;
1193 if (remote) {
1194 o = UnoUrlResolver::create(m_xContext)->resolve(rArgs[1]);
1195 } else {
1196 o = m_xContext->getServiceManager()->createInstanceWithContext(
1197 rArgs[0], m_xContext);
1199 if (!stress) {
1200 xOriginal = o;
1201 break;
1205 if (! xOriginal.is())
1207 throw RuntimeException(
1208 OUString( RTL_CONSTASCII_USTRINGPARAM(
1209 "cannot get test object!") ),
1210 Reference< XInterface >() );
1212 Reference< XBridgeTest > xTest( xOriginal, UNO_QUERY );
1213 if (! xTest.is())
1215 throw RuntimeException(
1216 OUString( RTL_CONSTASCII_USTRINGPARAM("test object does not implement XBridgeTest!") ),
1217 Reference< XInterface >() );
1220 Reference<XBridgeTest > xLBT;
1221 bRet = check( makeSurrogate( xLBT, xTest ), "makeSurrogate" );
1222 bRet = check(
1223 performTest( m_xContext, xLBT, noCurrentContext ), "standard test" )
1224 && bRet;
1225 bRet = check( raiseException( xLBT ) , "exception test" )&& bRet;
1226 bRet = check( raiseOnewayException( xLBT ),
1227 "oneway exception test" ) && bRet;
1228 bRet = performQueryForUnknownType( xLBT ) && bRet;
1229 if (! bRet)
1231 throw RuntimeException(
1232 OUString( RTL_CONSTASCII_USTRINGPARAM("error: test failed!") ),
1233 Reference< XInterface >() );
1236 catch (Exception & exc)
1238 OString cstr( OUStringToOString( exc.Message, RTL_TEXTENCODING_ASCII_US ) );
1239 fprintf( stderr, "exception occured: %s\n", cstr.getStr() );
1240 throw;
1243 if( bRet )
1245 printf( "\n\n ### test succeeded!\n" );
1247 else
1249 printf( "\n> ### test failed!\n" );
1252 return 0;
1255 // XServiceInfo
1256 //__________________________________________________________________________________________________
1257 OUString TestBridgeImpl::getImplementationName()
1258 throw (RuntimeException)
1260 return OUString( RTL_CONSTASCII_USTRINGPARAM(IMPLNAME) );
1262 //__________________________________________________________________________________________________
1263 sal_Bool TestBridgeImpl::supportsService( const OUString & rServiceName )
1264 throw (RuntimeException)
1266 const Sequence< OUString > & rSNL = getSupportedServiceNames();
1267 const OUString * pArray = rSNL.getConstArray();
1268 for ( sal_Int32 nPos = rSNL.getLength(); nPos--; )
1270 if (pArray[nPos] == rServiceName)
1271 return sal_True;
1273 return sal_False;
1275 //__________________________________________________________________________________________________
1276 Sequence< OUString > TestBridgeImpl::getSupportedServiceNames()
1277 throw (RuntimeException)
1279 return bridge_test::getSupportedServiceNames();
1282 // ...
1284 //==================================================================================================
1285 static Reference< XInterface > SAL_CALL TestBridgeImpl_create(
1286 const Reference< XComponentContext > & xContext )
1288 return Reference< XInterface >(
1289 static_cast< OWeakObject * >( new TestBridgeImpl( xContext ) ) );
1294 extern "C"
1296 //==================================================================================================
1297 void SAL_CALL component_getImplementationEnvironment(
1298 const sal_Char ** ppEnvTypeName, uno_Environment ** )
1300 *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
1302 //==================================================================================================
1303 sal_Bool SAL_CALL component_writeInfo( void *, void * pRegistryKey )
1305 if (pRegistryKey)
1309 Reference< XRegistryKey > xNewKey(
1310 reinterpret_cast< XRegistryKey * >( pRegistryKey )->createKey(
1311 OUString( RTL_CONSTASCII_USTRINGPARAM("/" IMPLNAME "/UNO/SERVICES") ) ) );
1312 xNewKey->createKey( OUString( RTL_CONSTASCII_USTRINGPARAM(SERVICENAME) ) );
1314 return sal_True;
1316 catch (InvalidRegistryException &)
1318 OSL_ENSURE( sal_False, "### InvalidRegistryException!" );
1321 return sal_False;
1323 //==================================================================================================
1324 void * SAL_CALL component_getFactory(
1325 const sal_Char * pImplName, void * pServiceManager, void * )
1327 void * pRet = 0;
1329 if (pServiceManager && rtl_str_compare( pImplName, IMPLNAME ) == 0)
1331 Reference< XInterface > xFactory(
1332 createSingleComponentFactory(
1333 bridge_test::TestBridgeImpl_create,
1334 OUString( RTL_CONSTASCII_USTRINGPARAM(IMPLNAME) ),
1335 bridge_test::getSupportedServiceNames() ) );
1337 if (xFactory.is())
1339 xFactory->acquire();
1340 pRet = xFactory.get();
1344 return pRet;