1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
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.
14  *
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).
20  *
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.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_testtools.hxx"
30 
31 #include <stdio.h>
32 #include <string.h>
33 #include <osl/diagnose.h>
34 #include "osl/diagnose.hxx"
35 #include <osl/time.h>
36 #include <sal/types.h>
37 #include "typelib/typedescription.hxx"
38 #include <uno/dispatcher.hxx>
39 #include "uno/mapping.hxx"
40 #include <uno/data.h>
41 #include "uno/environment.hxx"
42 
43 #include <cppuhelper/factory.hxx>
44 #include <cppuhelper/implbase2.hxx>
45 #include <cppuhelper/implbase1.hxx>
46 
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"
54 
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"
60 
61 #include "currentcontextchecker.hxx"
62 #include "multi.hxx"
63 
64 using namespace rtl;
65 using namespace osl;
66 using namespace cppu;
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;
72 
73 #define SERVICENAME		"com.sun.star.test.bridge.BridgeTest"
74 #define IMPLNAME		"com.sun.star.comp.bridge.BridgeTest"
75 
76 #define OUSTR(x) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(x) )
77 #define STRING_TEST_CONSTANT "\" paco\' chorizo\\\' \"\'"
78 
79 namespace bridge_test
80 {
81 template< class T>
82 Sequence<T> cloneSequence(const Sequence<T>& val);
83 
84 //--------------------------------------------------------------------------------------------------
85 inline static Sequence< OUString > getSupportedServiceNames()
86 {
87 	OUString aName( RTL_CONSTASCII_USTRINGPARAM(SERVICENAME) );
88 	return Sequence< OUString >( &aName, 1 );
89 }
90 
91 static bool check( bool b , char const * message )
92 {
93     if ( ! b )
94         fprintf( stderr, "%s failed\n" , message );
95     return b;
96 }
97 
98 namespace {
99 
100 bool checkEmpty(rtl::OUString const & string, char const * message) {
101     bool ok = string.getLength() == 0;
102     if (!ok) {
103         fprintf(
104             stderr, "%s failed: %s\n", message,
105             rtl::OUStringToOString(string, RTL_TEXTENCODING_UTF8).getStr());
106     }
107     return ok;
108 }
109 
110 }
111 
112 //==================================================================================================
113 class TestBridgeImpl : public osl::DebugBase<TestBridgeImpl>,
114                        public WeakImplHelper2< XMain, XServiceInfo >
115 {
116 	Reference< XComponentContext > m_xContext;
117 
118 public:
119 	TestBridgeImpl( const Reference< XComponentContext > & xContext )
120 		: m_xContext( xContext )
121 		{}
122     virtual ~TestBridgeImpl()
123     {
124     }
125 
126 	// XServiceInfo
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);
130 
131 	// XMain
132     virtual sal_Int32 SAL_CALL run( const Sequence< OUString > & rArgs ) throw (RuntimeException);
133 };
134 
135 //==================================================================================================
136 static sal_Bool equals( const TestElement & rData1, const TestElement & rData2 )
137 {
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!" );
153 
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);
169 }
170 //==================================================================================================
171 static sal_Bool equals( const TestData & rData1, const TestData & rData2 )
172 {
173 	sal_Int32 nLen;
174 
175 	if ((rData1.Sequence == rData2.Sequence) &&
176 		equals( (const TestElement &)rData1, (const TestElement &)rData2 ) &&
177 		(nLen = rData1.Sequence.getLength()) == rData2.Sequence.getLength())
178 	{
179 		// once again by hand sequence ==
180 		const TestElement * pElements1 = rData1.Sequence.getConstArray();
181 		const TestElement * pElements2 = rData2.Sequence.getConstArray();
182 		for ( ; nLen--; )
183 		{
184 			if (! equals( pElements1[nLen], pElements2[nLen] ))
185 			{
186 				check( sal_False, "### sequence element did not match!" );
187 				return sal_False;
188 			}
189 		}
190 		return sal_True;
191 	}
192 	return sal_False;
193 }
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 )
204 {
205 	rData.Bool = bBool;
206 	rData.Char = cChar;
207 	rData.Byte = nByte;
208 	rData.Short = nShort;
209 	rData.UShort = nUShort;
210 	rData.Long = nLong;
211 	rData.ULong = nULong;
212 	rData.Hyper = nHyper;
213 	rData.UHyper = nUHyper;
214 	rData.Float = fFloat;
215 	rData.Double = fDouble;
216 	rData.Enum = eEnum;
217 	rData.String = rStr;
218 	rData.Interface = xTest;
219 	rData.Any = rAny;
220 }
221 
222 namespace {
223 
224 template < typename T >
225 bool testAny(
226     T const & value, Reference< XBridgeTest > const & xLBT,
227     char const * typeName = 0)
228 {
229 	Any any;
230 	any <<=  value;
231 	Any any2 = xLBT->transportAny(any);
232     bool success = true;
233 	if (any != any2) {
234         fprintf(
235             stderr, "any is different after roundtrip: in %s, out %s\n",
236             OUStringToOString(
237                 any.getValueType().getTypeName(),
238                 RTL_TEXTENCODING_ASCII_US).getStr(),
239             OUStringToOString(
240                 any2.getValueType().getTypeName(),
241                 RTL_TEXTENCODING_ASCII_US).getStr());
242         success = false;
243     }
244     if (typeName != 0
245         && !any2.getValueType().getTypeName().equalsAscii(typeName))
246     {
247         fprintf(
248             stderr, "any has wrong type after roundtrip: %s instead of %s\n",
249             OUStringToOString(
250                 any2.getValueType().getTypeName(),
251                 RTL_TEXTENCODING_ASCII_US).getStr(),
252             typeName);
253         success = false;
254     }
255 	return success;
256 }
257 
258 }
259 
260 static sal_Bool performAnyTest( const Reference< XBridgeTest > &xLBT, const TestData &data)
261 {
262 	bool bReturn = true;
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;
276     bReturn &= testAny(
277         TestPolyStruct< sal_Unicode >(' '), xLBT,
278         "test.testtools.bridgetest.TestPolyStruct<char>");
279 
280 	Any a;
281 	{
282 		a.setValue( &(data.Bool) , getCppuBooleanType() );
283 		Any a2 = xLBT->transportAny( a );
284 		OSL_ASSERT( a2 == a );
285 	}
286 
287 	{
288 		a.setValue( &(data.Char) , getCppuCharType() );
289 		Any a2 = xLBT->transportAny( a );
290 		OSL_ASSERT( a2 == a );
291 	}
292 
293 	return bReturn;
294 }
295 
296 //_______________________________________________________________________________________
297 static sal_Bool performSequenceOfCallTest( const Reference < XBridgeTest > &xLBT )
298 {
299 	sal_Int32 i,nRounds;
300 	sal_Int32 nGlobalIndex = 0;
301 	const sal_Int32 nWaitTimeSpanMUSec = 10000;
302 	for( nRounds = 0 ; nRounds < 10 ; nRounds ++ )
303 	{
304 		for( i = 0 ; i < nRounds ; i ++ )
305 		{
306 			// fire oneways
307 			xLBT->callOneway( nGlobalIndex , nWaitTimeSpanMUSec );
308 			nGlobalIndex ++;
309 		}
310 
311 		// call synchron
312 		xLBT->call( nGlobalIndex , nWaitTimeSpanMUSec );
313 		nGlobalIndex ++;
314 	}
315 
316 	return xLBT->sequenceOfCallTestPassed();
317 }
318 
319 class ORecursiveCall : public WeakImplHelper1< XRecursiveCall >
320 {
321 private:
322 	Mutex m_mutex;
323 
324 public:
325 	void SAL_CALL callRecursivly(
326 		const ::com::sun::star::uno::Reference< XRecursiveCall >& xCall,
327 		sal_Int32 nToCall )
328 		throw(::com::sun::star::uno::RuntimeException)
329 		{
330 			MutexGuard guard( m_mutex );
331 			if( nToCall )
332 			{
333 				nToCall --;
334 				xCall->callRecursivly( this , nToCall );
335 			}
336 
337 		}
338 };
339 
340 
341 //_______________________________________________________________________________________
342 static sal_Bool performRecursiveCallTest( const Reference < XBridgeTest > & xLBT )
343 {
344 	xLBT->startRecursiveCall( new ORecursiveCall , 50 );
345 	// on failure, the test would lock up or crash
346 	return sal_True;
347 }
348 
349 class MyClass : public osl::DebugBase<MyClass>, public OWeakObject
350 {
351 public:
352     MyClass();
353     virtual ~MyClass();
354     virtual void SAL_CALL acquire() throw ();
355     virtual void SAL_CALL release() throw ();
356 };
357 
358 //______________________________________________________________________________
359 MyClass::MyClass()
360 {
361 }
362 //______________________________________________________________________________
363 MyClass::~MyClass()
364 {
365 }
366 //______________________________________________________________________________
367 void MyClass::acquire() throw ()
368 {
369     OWeakObject::acquire();
370 }
371 //______________________________________________________________________________
372 void MyClass::release() throw ()
373 {
374     OWeakObject::release();
375 }
376 
377 //==================================================================================================
378 static sal_Bool performTest(
379     const Reference<XComponentContext> & xContext,
380     const Reference<XBridgeTest > & xLBT,
381     bool noCurrentContext )
382 {
383     check(xLBT.is(), "### no test interface!");
384     bool bRet = true;
385     if (xLBT.is()) {
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);
390         assign(
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:
402         TestData aSetData;
403         assign(
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
411         xLBT->setValues(
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);
417         {
418             TestData aRet;
419             TestData aRet2;
420             xLBT->getValues(
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);
425             bRet &= check(
426                 equals(aData, aRet) && equals(aData, aRet2), "getValues test");
427             // Set last retrieved values:
428             TestData aSV2ret(
429                 xLBT->setValues2(
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;
439             bRet &= check(
440                 equals(aData, aSV2ret) && equals(aData, aRet2),
441                 "getValues2 test");
442         }
443         {
444             TestData aRet;
445             TestData aRet2;
446             TestData aGVret(
447                 xLBT->getValues(
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));
452             bRet &= check(
453                 (equals(aData, aRet) && equals(aData, aRet2) &&
454                  equals(aData, aGVret)),
455                 "getValues test");
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);
474         }
475         {
476             TestData aRet;
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());
494             bRet &= check(
495                 equals(aData, aRet) && equals(aData, aRet2),
496                 "struct comparison test");
497             {
498                 SmallStruct aIn(1, 2);
499                 SmallStruct aOut(xLBT->echoSmallStruct(aIn));
500                 bRet &= check(
501                     memcmp(&aIn, &aOut, sizeof(SmallStruct)) == 0,
502                     "small struct test");
503             }
504             {
505                 MediumStruct aIn(1, 2, 3, 4);
506                 MediumStruct aOut(xLBT->echoMediumStruct(aIn));
507                 bRet &= check(
508                     memcmp(&aIn, &aOut, sizeof(MediumStruct)) == 0,
509                     "medium struct test");
510             }
511             {
512                 BigStruct aIn(1, 2, 3, 4, 5, 6, 7, 8);
513                 BigStruct aOut(xLBT->echoBigStruct(aIn));
514                 bRet &= check(
515                     memcmp(&aIn, &aOut, sizeof(BigStruct)) == 0,
516                     "big struct test");
517             }
518             {
519                 AllFloats aIn(1.1f, 2.2f, 3.3f, 4.4f);
520                 AllFloats aOut(xLBT->echoAllFloats(aIn));
521                 bRet &= check(
522                     memcmp(&aIn, &aOut, sizeof(AllFloats)) == 0,
523                     "all floats struct test");
524             }
525             {
526                 sal_Int32 i2 = xLBT->testPPCAlignment(0, 0, 0, 0, 0xBEAF);
527                 bRet &= check(i2 == 0xBEAF, "ppc-style alignment test");
528             }
529             // Test extended attributes that raise exceptions:
530             try {
531                 xLBT->getRaiseAttr1();
532                 bRet &= check(false, "getRaiseAttr1 did not throw");
533             } catch (RuntimeException &) {
534             } catch (...) {
535                 bRet &= check(false, "getRaiseAttr1 threw wrong type");
536             }
537             try {
538                 xLBT->setRaiseAttr1(0);
539                 bRet &= check(false, "setRaiseAttr1 did not throw");
540             } catch (IllegalArgumentException &) {
541             } catch (...) {
542                 bRet &= check(false, "setRaiseAttr1 threw wrong type");
543             }
544             try {
545                 xLBT->getRaiseAttr2();
546                 bRet &= check(false, "getRaiseAttr2 did not throw");
547             } catch (IllegalArgumentException &) {
548             } catch (...) {
549                 bRet &= check(false, "getRaiseAttr2 threw wrong type");
550             }
551             // Test instantiated polymorphic struct types:
552             {
553                 bRet &= check(
554                     (xLBT->transportPolyBoolean(
555                         TestPolyStruct< sal_Bool >(true)).
556                      member),
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);
567                 bRet &= check(
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");
573                 rtl::OUString v1;
574                 tps3.member[1] >>= v1;
575                 bRet &= check(
576                     v1.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("ABC")),
577                     "transportPolySequence, element 1");
578                 bRet &= check(
579                     xLBT->getNullPolyLong().member == 0, "getNullPolyLong");
580                 bRet &= check(
581                     xLBT->getNullPolyString().member.getLength() == 0,
582                     "getNullPolyString");
583                 bRet &= check(
584                     xLBT->getNullPolyType().member == Type(),
585                     "getNullPolyType");
586                 Any nullAny(xLBT->getNullPolyAny().member);
587                 bRet &= check(
588                     (((nullAny.getValueTypeName() ==
589                        rtl::OUString(
590                            RTL_CONSTASCII_USTRINGPARAM(
591                                "com.sun.star.uno.XInterface"))) &&
592                       !static_cast< Reference< XInterface > const * >(
593                           nullAny.getValue())->is())
594                      || nullAny == Any()),
595                     "getNullPolyAny");
596                 bRet &= check(
597                     xLBT->getNullPolySequence().member.getLength() == 0,
598                     "getNullPolySequence");
599                 bRet &= check(
600                     xLBT->getNullPolyEnum().member == TestEnum_TEST,
601                     "getNullPolyEnum");
602                 bRet &= check(
603                     xLBT->getNullPolyBadEnum().member == TestBadEnum_M,
604                     "getNullPolyBadEnum");
605                 bRet &= check(
606                     xLBT->getNullPolyStruct().member.member == 0,
607                     "getNullPolyStruct");
608                 bRet &= check(
609                     !xLBT->getNullPolyInterface().member.is(),
610                     "getNullPolyInterface");
611             }
612             // Any test:
613             bRet &= check(performAnyTest(xLBT , aData), "any test");
614             // Sequence of call test:
615             bRet &= check(
616                 performSequenceOfCallTest(xLBT), "sequence of call test");
617             // Recursive call test:
618             bRet &= check(performRecursiveCallTest(xLBT), "recursive test");
619             bRet &= check(
620                 equals(aData, aRet) && equals(aData, aRet2),
621                 "recursive test results");
622             // Multiple inheritance test:
623             bRet &= checkEmpty(
624                 testtools::bridgetest::testMulti(xLBT->getMulti()),
625                 "remote multi");
626             bRet &= checkEmpty(
627                 xLBT->testMulti(new testtools::bridgetest::Multi),
628                 "local multi");
629         }
630     }
631     {
632         Reference< XBridgeTest2 > xBT2(xLBT, UNO_QUERY);
633         if (!xBT2.is()) {
634             return bRet;
635         }
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];
668         assign(
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)));
674         assign(
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)));
680         assign(
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)));
686         {
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);
708                 }
709                 _arSeqLong2[j] = Sequence< Sequence< sal_Int32 > >(
710                     _arSeqLong, 3);
711             }
712             Sequence< Sequence< Sequence< sal_Int32> > > arLong3(
713                 _arSeqLong2, 3);
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);
780             bRet &= check(
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),
790                 "sequence test");
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);
813             bRet &= check(
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),
823                 "sequence test");
824         }
825         {
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");
887         }
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:
891         try {
892             xBT2->testConstructorsService(xContext);
893         } catch (BadConstructorArguments &) {
894             bRet = false;
895         }
896         if (!noCurrentContext) {
897             if (!(new testtools::bridgetest::CurrentContextChecker)->perform(
898                     xBT2->getCurrentContextChecker(), 0, 1))
899             {
900                 bRet = false;
901             }
902             if (!(new testtools::bridgetest::CurrentContextChecker)->perform(
903                     xBT2->getCurrentContextChecker(), 0, 2))
904             {
905                 bRet = false;
906             }
907             if (!(new testtools::bridgetest::CurrentContextChecker)->perform(
908                     xBT2->getCurrentContextChecker(), 1, 2))
909             {
910                 bRet = false;
911             }
912             if (!(new testtools::bridgetest::CurrentContextChecker)->perform(
913                     xBT2->getCurrentContextChecker(), 1, 3))
914             {
915                 bRet = false;
916             }
917         }
918     }
919     return bRet;
920 }
921 
922 static sal_Bool raiseOnewayException( const Reference < XBridgeTest > & xLBT )
923 {
924 	sal_Bool bReturn = sal_True;
925 	OUString sCompare = OUSTR(STRING_TEST_CONSTANT);
926     Reference<XInterface> const x(xLBT->getInterface());
927 	try
928 	{
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 );
932 	}
933 	catch( RuntimeException & e )
934 	{
935 		bReturn = (
936 #if OSL_DEBUG_LEVEL == 0
937             // java stack traces trash Message
938             e.Message == sCompare &&
939 #endif
940             xLBT->getInterface() == e.Context &&
941             x == e.Context );
942 	}
943 	return bReturn;
944 }
945 
946 //==================================================================================================
947 static sal_Bool raiseException( const Reference< XBridgeTest > & xLBT )
948 {
949 	sal_Int32 nCount = 0;
950 	try
951 	{
952 		try
953 		{
954 			try
955 			{
956 				TestData aRet, aRet2;
957 				xLBT->raiseException(
958 					5, OUSTR(STRING_TEST_CONSTANT),
959 					xLBT->getInterface() );
960 			}
961 			catch (IllegalArgumentException aExc)
962 			{
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 &&
967 #endif
968 					aExc.Context == xLBT->getInterface())
969 				{
970 #ifdef COMPCHECK
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.
974                     return true;
975 #else
976 					++nCount;
977 #endif
978 				}
979 				else
980 				{
981 					check( sal_False, "### unexpected exception content!" );
982 				}
983 
984 				/** it is certain, that the RuntimeException testing will fail, if no */
985 				xLBT->getRuntimeException();
986 			}
987 		}
988 		catch (const RuntimeException & rExc)
989 		{
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
994 #endif
995                 )
996 			{
997 				++nCount;
998 			}
999 			else
1000 			{
1001 				check( sal_False, "### unexpected exception content!" );
1002 			}
1003 
1004 			/** it is certain, that the RuntimeException testing will fail, if no */
1005 			xLBT->setRuntimeException( 0xcafebabe );
1006 		}
1007 	}
1008 	catch (Exception & rExc)
1009 	{
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
1014 #endif
1015             )
1016 		{
1017 			++nCount;
1018 		}
1019 		else
1020 		{
1021 			check( sal_False, "### unexpected exception content!" );
1022 		}
1023 		return (nCount == 3);
1024 	}
1025 	return sal_False;
1026 }
1027 
1028 /* Returns an acquired sequence
1029  */
1030 uno_Sequence* cloneSequence(const uno_Sequence* val, const Type& type)
1031 {
1032     TypeDescription td(type);
1033     td.makeComplete();
1034     typelib_TypeDescription* pTdRaw = td.get();
1035     typelib_IndirectTypeDescription* pIndirectTd =
1036         (typelib_IndirectTypeDescription*) pTdRaw;
1037 
1038     typelib_TypeDescription* pTdElem = pIndirectTd->pType->pType;
1039     sal_Int8* buf = new sal_Int8[pTdElem->nSize * val->nElements];
1040     sal_Int8* pBufCur = buf;
1041 
1042     uno_Sequence* retSeq = NULL;
1043     switch (pTdElem->eTypeClass)
1044     {
1045     case TypeClass_SEQUENCE:
1046     {
1047         Type _tElem(pTdElem->pWeakRef);
1048         for (int i = 0; i < val->nElements; i++)
1049         {
1050             uno_Sequence* seq = cloneSequence(
1051                 *(uno_Sequence**) (&val->elements + i * pTdElem->nSize),
1052                 _tElem);
1053             *((uno_Sequence**) pBufCur) = seq;
1054             pBufCur += pTdElem->nSize;
1055         }
1056         break;
1057     }
1058     default:
1059         uno_type_sequence_construct(
1060             &retSeq, type.getTypeLibType(), (void*) val->elements,
1061             val->nElements, reinterpret_cast< uno_AcquireFunc >(cpp_acquire));
1062         break;
1063     }
1064     delete[] buf;
1065     return retSeq;
1066 }
1067 
1068 template< class T>
1069 Sequence<T> cloneSequence(const Sequence<T>& val)
1070 {
1071     Sequence<T> seq( cloneSequence(val.get(), getCppuType(&val)), SAL_NO_ACQUIRE);
1072     return seq;
1073 }
1074 
1075 template< class T >
1076 inline bool makeSurrogate(
1077     Reference< T > & rOut, Reference< T > const & rOriginal )
1078 {
1079     rOut.clear();
1080     if (! rOriginal.is())
1081         return false;
1082 
1083     Environment aCppEnv_official;
1084     Environment aUnoEnv_ano;
1085     Environment aCppEnv_ano;
1086 
1087     OUString aCppEnvTypeName(
1088         RTL_CONSTASCII_USTRINGPARAM(CPPU_CURRENT_LANGUAGE_BINDING_NAME) );
1089     OUString aUnoEnvTypeName(
1090         RTL_CONSTASCII_USTRINGPARAM(UNO_LB_UNO) );
1091     // official:
1092     uno_getEnvironment(
1093         reinterpret_cast< uno_Environment ** >( &aCppEnv_official ),
1094         aCppEnvTypeName.pData, 0 );
1095     // anonymous:
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 );
1102 
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())
1107     {
1108         throw RuntimeException(
1109             OUSTR("cannot get C++-UNO mappings!"),
1110             Reference< XInterface >() );
1111     }
1112     cpp2uno.mapInterface(
1113         reinterpret_cast< void ** >( &unoI.m_pUnoI ),
1114         rOriginal.get(), ::getCppuType( &rOriginal ) );
1115     if (! unoI.is())
1116     {
1117         throw RuntimeException(
1118             OUSTR("mapping C++ to binary UNO failed!"),
1119             Reference< XInterface >() );
1120     }
1121     uno2cpp.mapInterface(
1122         reinterpret_cast< void ** >( &rOut ),
1123         unoI.get(), ::getCppuType( &rOriginal ) );
1124     if (! rOut.is())
1125     {
1126         throw RuntimeException(
1127             OUSTR("mapping binary UNO to C++ failed!"),
1128             Reference< XInterface >() );
1129     }
1130 
1131 	return rOut.is();
1132 }
1133 
1134 //==================================================================================================
1135 sal_Int32 TestBridgeImpl::run( const Sequence< OUString > & rArgs )
1136 	throw (RuntimeException)
1137 {
1138     bool bRet = false;
1139     try
1140     {
1141         if (! rArgs.getLength())
1142         {
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 >() );
1147         }
1148 
1149         Reference< XInterface > xOriginal;
1150         bool remote;
1151         sal_Int32 i;
1152         if( rArgs.getLength() > 1 && 0 == rArgs[0].compareToAscii( "-u" ) )
1153         {
1154             remote = true;
1155             i = 2;
1156         }
1157         else
1158         {
1159             remote = false;
1160             i = 1;
1161         }
1162         bool noCurrentContext = false;
1163         if (i < rArgs.getLength()
1164             && rArgs[i].equalsAsciiL(
1165                 RTL_CONSTASCII_STRINGPARAM("noCurrentContext")))
1166         {
1167             noCurrentContext = true;
1168             ++i;
1169         }
1170         bool stress = false;
1171         if (i < rArgs.getLength()
1172             && rArgs[i].equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("stress")))
1173         {
1174             stress = true;
1175             ++i;
1176         }
1177 
1178         for (;;) {
1179             Reference< XInterface > o;
1180             if (remote) {
1181                 o = UnoUrlResolver::create(m_xContext)->resolve(rArgs[1]);
1182             } else {
1183                 o = m_xContext->getServiceManager()->createInstanceWithContext(
1184                     rArgs[0], m_xContext);
1185             }
1186             if (!stress) {
1187                 xOriginal = o;
1188                 break;
1189             }
1190         }
1191 
1192         if (! xOriginal.is())
1193         {
1194             throw RuntimeException(
1195                 OUString( RTL_CONSTASCII_USTRINGPARAM(
1196                               "cannot get test object!") ),
1197                 Reference< XInterface >() );
1198         }
1199         Reference< XBridgeTest > xTest( xOriginal, UNO_QUERY );
1200         if (! xTest.is())
1201         {
1202             throw RuntimeException(
1203                 OUString( RTL_CONSTASCII_USTRINGPARAM("test object does not implement XBridgeTest!") ),
1204                 Reference< XInterface >() );
1205         }
1206 
1207         Reference<XBridgeTest > xLBT;
1208         bRet = check( makeSurrogate( xLBT, xTest ), "makeSurrogate" );
1209         bRet = check(
1210             performTest( m_xContext, xLBT, noCurrentContext ), "standard test" )
1211             && bRet;
1212         bRet = check( raiseException( xLBT ) , "exception test" )&& bRet;
1213         bRet = check( raiseOnewayException( xLBT ),
1214                       "oneway exception test" ) && bRet;
1215         if (! bRet)
1216         {
1217             throw RuntimeException(
1218                 OUString( RTL_CONSTASCII_USTRINGPARAM("error: test failed!") ),
1219                 Reference< XInterface >() );
1220         }
1221 	}
1222     catch (Exception & exc)
1223     {
1224         OString cstr( OUStringToOString( exc.Message, RTL_TEXTENCODING_ASCII_US ) );
1225         fprintf( stderr, "exception occured: %s\n", cstr.getStr() );
1226         throw;
1227     }
1228 
1229     if( bRet )
1230     {
1231         printf( "\n\n ### test succeeded!\n" );
1232     }
1233     else
1234     {
1235         printf( "\n> ### test failed!\n" );
1236     }
1237 
1238 	return 0;
1239 }
1240 
1241 // XServiceInfo
1242 //__________________________________________________________________________________________________
1243 OUString TestBridgeImpl::getImplementationName()
1244 	throw (RuntimeException)
1245 {
1246 	return OUString( RTL_CONSTASCII_USTRINGPARAM(IMPLNAME) );
1247 }
1248 //__________________________________________________________________________________________________
1249 sal_Bool TestBridgeImpl::supportsService( const OUString & rServiceName )
1250 	throw (RuntimeException)
1251 {
1252 	const Sequence< OUString > & rSNL = getSupportedServiceNames();
1253 	const OUString * pArray = rSNL.getConstArray();
1254 	for ( sal_Int32 nPos = rSNL.getLength(); nPos--; )
1255 	{
1256 		if (pArray[nPos] == rServiceName)
1257 			return sal_True;
1258 	}
1259 	return sal_False;
1260 }
1261 //__________________________________________________________________________________________________
1262 Sequence< OUString > TestBridgeImpl::getSupportedServiceNames()
1263 	throw (RuntimeException)
1264 {
1265 	return bridge_test::getSupportedServiceNames();
1266 }
1267 
1268 // ...
1269 
1270 //==================================================================================================
1271 static Reference< XInterface > SAL_CALL TestBridgeImpl_create(
1272 	const Reference< XComponentContext > & xContext )
1273 {
1274 	return Reference< XInterface >(
1275         static_cast< OWeakObject * >( new TestBridgeImpl( xContext ) ) );
1276 }
1277 
1278 }
1279 
1280 extern "C"
1281 {
1282 //==================================================================================================
1283 void SAL_CALL component_getImplementationEnvironment(
1284 	const sal_Char ** ppEnvTypeName, uno_Environment ** )
1285 {
1286 	*ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
1287 }
1288 //==================================================================================================
1289 void * SAL_CALL component_getFactory(
1290 	const sal_Char * pImplName, void * pServiceManager, void * )
1291 {
1292 	void * pRet = 0;
1293 
1294 	if (pServiceManager && rtl_str_compare( pImplName, IMPLNAME ) == 0)
1295 	{
1296 		Reference< XInterface > xFactory(
1297             createSingleComponentFactory(
1298                 bridge_test::TestBridgeImpl_create,
1299                 OUString( RTL_CONSTASCII_USTRINGPARAM(IMPLNAME) ),
1300                 bridge_test::getSupportedServiceNames() ) );
1301 
1302 		if (xFactory.is())
1303 		{
1304 			xFactory->acquire();
1305 			pRet = xFactory.get();
1306 		}
1307 	}
1308 
1309 	return pRet;
1310 }
1311 }
1312