bump product version to 4.1.6.2
[LibreOffice.git] / testtools / source / bridgetest / bridgetest.cxx
blob3c2bcda4995c5ea9973ad0fe2acdc669753c0d24
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <stdio.h>
22 #include <string.h>
23 #include <osl/diagnose.h>
24 #include "osl/diagnose.hxx"
25 #include <osl/time.h>
26 #include <sal/types.h>
27 #include "typelib/typedescription.hxx"
28 #include <uno/dispatcher.hxx>
29 #include "uno/mapping.hxx"
30 #include <uno/data.h>
31 #include "uno/environment.hxx"
33 #include <cppuhelper/factory.hxx>
34 #include <cppuhelper/implbase2.hxx>
35 #include <cppuhelper/implbase1.hxx>
37 #include <com/sun/star/lang/XServiceInfo.hpp>
38 #include <com/sun/star/lang/XComponent.hpp>
39 #include <com/sun/star/lang/XMain.hpp>
40 #include <com/sun/star/bridge/UnoUrlResolver.hpp>
41 #include <com/sun/star/bridge/XUnoUrlResolver.hpp>
42 #include "com/sun/star/uno/RuntimeException.hpp"
43 #include "com/sun/star/uno/Type.hxx"
45 #include "test/testtools/bridgetest/BadConstructorArguments.hpp"
46 #include "test/testtools/bridgetest/TestPolyStruct.hpp"
47 #include "test/testtools/bridgetest/XBridgeTest.hpp"
48 #include "test/testtools/bridgetest/XBridgeTest2.hpp"
49 #include "test/testtools/bridgetest/XMulti.hpp"
51 #include "currentcontextchecker.hxx"
52 #include "multi.hxx"
54 using namespace osl;
55 using namespace cppu;
56 using namespace com::sun::star::uno;
57 using namespace com::sun::star::lang;
58 using namespace com::sun::star::registry;
59 using namespace com::sun::star::bridge;
60 using namespace test::testtools::bridgetest;
63 #define SERVICENAME "com.sun.star.test.bridge.BridgeTest"
64 #define IMPLNAME "com.sun.star.comp.bridge.BridgeTest"
66 #define STRING_TEST_CONSTANT "\" paco\' chorizo\\\' \"\'"
68 namespace bridge_test
70 template< class T>
71 Sequence<T> cloneSequence(const Sequence<T>& val);
73 //--------------------------------------------------------------------------------------------------
74 inline static Sequence< OUString > getSupportedServiceNames()
76 OUString aName( SERVICENAME );
77 return Sequence< OUString >( &aName, 1 );
80 static bool check( bool b , char const * message )
82 if ( ! b )
83 fprintf( stderr, "%s failed\n" , message );
84 return b;
87 namespace {
89 bool checkEmpty(OUString const & string, char const * message) {
90 bool ok = string.isEmpty();
91 if (!ok) {
92 fprintf(
93 stderr, "%s failed: %s\n", message,
94 OUStringToOString(string, RTL_TEXTENCODING_UTF8).getStr());
96 return ok;
101 //==================================================================================================
102 class TestBridgeImpl : public osl::DebugBase<TestBridgeImpl>,
103 public WeakImplHelper2< XMain, XServiceInfo >
105 Reference< XComponentContext > m_xContext;
107 public:
108 TestBridgeImpl( const Reference< XComponentContext > & xContext )
109 : m_xContext( xContext )
111 virtual ~TestBridgeImpl()
115 // XServiceInfo
116 virtual OUString SAL_CALL getImplementationName() throw (RuntimeException);
117 virtual sal_Bool SAL_CALL supportsService( const OUString & rServiceName ) throw (RuntimeException);
118 virtual Sequence< OUString > SAL_CALL getSupportedServiceNames() throw (RuntimeException);
120 // XMain
121 virtual sal_Int32 SAL_CALL run( const Sequence< OUString > & rArgs ) throw (RuntimeException);
124 //==================================================================================================
125 static sal_Bool equals( const TestElement & rData1, const TestElement & rData2 )
127 check( rData1.Bool == rData2.Bool, "### bool does not match!" );
128 check( rData1.Char == rData2.Char, "### char does not match!" );
129 check( rData1.Byte == rData2.Byte, "### byte does not match!" );
130 check( rData1.Short == rData2.Short, "### short does not match!" );
131 check( rData1.UShort == rData2.UShort, "### unsigned short does not match!" );
132 check( rData1.Long == rData2.Long, "### long does not match!" );
133 check( rData1.ULong == rData2.ULong, "### unsigned long does not match!" );
134 check( rData1.Hyper == rData2.Hyper, "### hyper does not match!" );
135 check( rData1.UHyper == rData2.UHyper, "### unsigned hyper does not match!" );
136 check( rData1.Float == rData2.Float, "### float does not match!" );
137 check( rData1.Double == rData2.Double, "### double does not match!" );
138 check( rData1.Enum == rData2.Enum, "### enum does not match!" );
139 check( rData1.String == rData2.String, "### string does not match!" );
140 check( rData1.Interface == rData2.Interface, "### interface does not match!" );
141 check( rData1.Any == rData2.Any, "### any does not match!" );
143 return (rData1.Bool == rData2.Bool &&
144 rData1.Char == rData2.Char &&
145 rData1.Byte == rData2.Byte &&
146 rData1.Short == rData2.Short &&
147 rData1.UShort == rData2.UShort &&
148 rData1.Long == rData2.Long &&
149 rData1.ULong == rData2.ULong &&
150 rData1.Hyper == rData2.Hyper &&
151 rData1.UHyper == rData2.UHyper &&
152 rData1.Float == rData2.Float &&
153 rData1.Double == rData2.Double &&
154 rData1.Enum == rData2.Enum &&
155 rData1.String == rData2.String &&
156 rData1.Interface == rData2.Interface &&
157 rData1.Any == rData2.Any);
159 //==================================================================================================
160 static sal_Bool equals( const TestData & rData1, const TestData & rData2 )
162 sal_Int32 nLen;
164 if ((rData1.Sequence == rData2.Sequence) &&
165 equals( (const TestElement &)rData1, (const TestElement &)rData2 ) &&
166 (nLen = rData1.Sequence.getLength()) == rData2.Sequence.getLength())
168 // once again by hand sequence ==
169 const TestElement * pElements1 = rData1.Sequence.getConstArray();
170 const TestElement * pElements2 = rData2.Sequence.getConstArray();
171 for ( ; nLen--; )
173 if (! equals( pElements1[nLen], pElements2[nLen] ))
175 check( sal_False, "### sequence element did not match!" );
176 return sal_False;
179 return sal_True;
181 return sal_False;
183 //==================================================================================================
184 static void assign( TestElement & rData,
185 sal_Bool bBool, sal_Unicode cChar, sal_Int8 nByte,
186 sal_Int16 nShort, sal_uInt16 nUShort,
187 sal_Int32 nLong, sal_uInt32 nULong,
188 sal_Int64 nHyper, sal_uInt64 nUHyper,
189 float fFloat, double fDouble,
190 TestEnum eEnum, const OUString& rStr,
191 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& xTest,
192 const ::com::sun::star::uno::Any& rAny )
194 rData.Bool = bBool;
195 rData.Char = cChar;
196 rData.Byte = nByte;
197 rData.Short = nShort;
198 rData.UShort = nUShort;
199 rData.Long = nLong;
200 rData.ULong = nULong;
201 rData.Hyper = nHyper;
202 rData.UHyper = nUHyper;
203 rData.Float = fFloat;
204 rData.Double = fDouble;
205 rData.Enum = eEnum;
206 rData.String = rStr;
207 rData.Interface = xTest;
208 rData.Any = rAny;
211 namespace {
213 template < typename T >
214 bool testAny(
215 T const & value, Reference< XBridgeTest > const & xLBT,
216 char const * typeName = 0)
218 Any any;
219 any <<= value;
220 Any any2 = xLBT->transportAny(any);
221 bool success = true;
222 if (any != any2) {
223 fprintf(
224 stderr, "any is different after roundtrip: in %s, out %s\n",
225 OUStringToOString(
226 any.getValueType().getTypeName(),
227 RTL_TEXTENCODING_ASCII_US).getStr(),
228 OUStringToOString(
229 any2.getValueType().getTypeName(),
230 RTL_TEXTENCODING_ASCII_US).getStr());
231 success = false;
233 if (typeName != 0
234 && !any2.getValueType().getTypeName().equalsAscii(typeName))
236 fprintf(
237 stderr, "any has wrong type after roundtrip: %s instead of %s\n",
238 OUStringToOString(
239 any2.getValueType().getTypeName(),
240 RTL_TEXTENCODING_ASCII_US).getStr(),
241 typeName);
242 success = false;
244 return success;
249 static sal_Bool performAnyTest( const Reference< XBridgeTest > &xLBT, const TestData &data)
251 bool bReturn = true;
252 bReturn = testAny( data.Byte ,xLBT ) && bReturn;
253 bReturn = testAny( data.Short,xLBT ) && bReturn;
254 bReturn = testAny( data.UShort,xLBT ) && bReturn;
255 bReturn = testAny( data.Long,xLBT ) && bReturn;
256 bReturn = testAny( data.ULong,xLBT ) && bReturn;
257 bReturn = testAny( data.Hyper,xLBT ) && bReturn;
258 bReturn = testAny( data.UHyper,xLBT ) && bReturn;
259 bReturn = testAny( data.Float,xLBT ) && bReturn;
260 bReturn = testAny( data.Double,xLBT ) && bReturn;
261 bReturn = testAny( data.Enum,xLBT ) && bReturn;
262 bReturn = testAny( data.String,xLBT ) && bReturn;
263 bReturn = testAny( data.Interface,xLBT ) && bReturn;
264 bReturn = testAny( data, xLBT ) && bReturn;
265 bReturn &= testAny(
266 TestPolyStruct< sal_Unicode >(' '), xLBT,
267 "test.testtools.bridgetest.TestPolyStruct<char>");
269 Any a;
271 a.setValue( &(data.Bool) , getCppuBooleanType() );
272 Any a2 = xLBT->transportAny( a );
273 OSL_ASSERT( a2 == a );
277 a.setValue( &(data.Char) , getCppuCharType() );
278 Any a2 = xLBT->transportAny( a );
279 OSL_ASSERT( a2 == a );
282 return bReturn;
285 //_______________________________________________________________________________________
286 static sal_Bool performSequenceOfCallTest( const Reference < XBridgeTest > &xLBT )
288 sal_Int32 i,nRounds;
289 sal_Int32 nGlobalIndex = 0;
290 const sal_Int32 nWaitTimeSpanMUSec = 10000;
291 for( nRounds = 0 ; nRounds < 10 ; nRounds ++ )
293 for( i = 0 ; i < nRounds ; i ++ )
295 // fire oneways
296 xLBT->callOneway( nGlobalIndex , nWaitTimeSpanMUSec );
297 nGlobalIndex ++;
300 // call synchron
301 xLBT->call( nGlobalIndex , nWaitTimeSpanMUSec );
302 nGlobalIndex ++;
305 return xLBT->sequenceOfCallTestPassed();
308 class ORecursiveCall : public WeakImplHelper1< XRecursiveCall >
310 private:
311 Mutex m_mutex;
313 public:
314 void SAL_CALL callRecursivly(
315 const ::com::sun::star::uno::Reference< XRecursiveCall >& xCall,
316 sal_Int32 nToCall )
317 throw(::com::sun::star::uno::RuntimeException)
319 MutexGuard guard( m_mutex );
320 if( nToCall )
322 nToCall --;
323 xCall->callRecursivly( this , nToCall );
330 //_______________________________________________________________________________________
331 static sal_Bool performRecursiveCallTest( const Reference < XBridgeTest > & xLBT )
333 xLBT->startRecursiveCall( new ORecursiveCall , 50 );
334 // on failure, the test would lock up or crash
335 return sal_True;
338 class MyClass : public osl::DebugBase<MyClass>, public OWeakObject
340 public:
341 MyClass();
342 virtual ~MyClass();
343 virtual void SAL_CALL acquire() throw ();
344 virtual void SAL_CALL release() throw ();
347 //______________________________________________________________________________
348 MyClass::MyClass()
351 //______________________________________________________________________________
352 MyClass::~MyClass()
355 //______________________________________________________________________________
356 void MyClass::acquire() throw ()
358 OWeakObject::acquire();
360 //______________________________________________________________________________
361 void MyClass::release() throw ()
363 OWeakObject::release();
366 //==================================================================================================
367 static sal_Bool performTest(
368 const Reference<XComponentContext> & xContext,
369 const Reference<XBridgeTest > & xLBT,
370 bool noCurrentContext )
372 check(xLBT.is(), "### no test interface!");
373 bool bRet = true;
374 if (xLBT.is()) {
375 // this data is never ever granted access to by calls other than
376 // equals(), assign()!
377 TestData aData; // test against this data
378 Reference< XInterface > xI(new MyClass);
379 assign(
380 (TestElement &) aData, true, '@', 17, 0x1234, 0xFEDC, 0x12345678,
381 0xFEDCBA98, SAL_CONST_INT64(0x123456789ABCDEF0),
382 SAL_CONST_UINT64(0xFEDCBA9876543210), 17.0815f, 3.1415926359,
383 TestEnum_LOLA, STRING_TEST_CONSTANT, xI,
384 Any(&xI, getCppuType((Reference< XInterface > const *) 0)));
385 bRet &= check(aData.Any == xI, "### unexpected any!");
386 bRet &= check(!(aData.Any != xI), "### unexpected any!");
387 aData.Sequence.realloc(2);
388 aData.Sequence[0] = *(TestElement const *) &aData;
389 // aData.Sequence[1] is empty
390 // aSetData is a manually copy of aData for first setting:
391 TestData aSetData;
392 assign(
393 (TestElement &) aSetData, aData.Bool, aData.Char, aData.Byte,
394 aData.Short, aData.UShort, aData.Long, aData.ULong, aData.Hyper,
395 aData.UHyper, aData.Float, aData.Double, aData.Enum, aData.String,
396 xI, Any(&xI, getCppuType((Reference< XInterface > const *) 0)));
397 aSetData.Sequence.realloc(2);
398 aSetData.Sequence[0] = *(TestElement const *) &aSetData;
399 // aSetData.Sequence[1] is empty
400 xLBT->setValues(
401 aSetData.Bool, aSetData.Char, aSetData.Byte, aSetData.Short,
402 aSetData.UShort, aSetData.Long, aSetData.ULong, aSetData.Hyper,
403 aSetData.UHyper, aSetData.Float, aSetData.Double, aSetData.Enum,
404 aSetData.String, aSetData.Interface, aSetData.Any,
405 aSetData.Sequence, aSetData);
407 TestData aRet;
408 TestData aRet2;
409 xLBT->getValues(
410 aRet.Bool, aRet.Char, aRet.Byte, aRet.Short, aRet.UShort,
411 aRet.Long, aRet.ULong, aRet.Hyper, aRet.UHyper, aRet.Float,
412 aRet.Double, aRet.Enum, aRet.String, aRet.Interface, aRet.Any,
413 aRet.Sequence, aRet2);
414 bRet &= check(
415 equals(aData, aRet) && equals(aData, aRet2), "getValues test");
416 // Set last retrieved values:
417 TestData aSV2ret(
418 xLBT->setValues2(
419 aRet.Bool, aRet.Char, aRet.Byte, aRet.Short, aRet.UShort,
420 aRet.Long, aRet.ULong, aRet.Hyper, aRet.UHyper, aRet.Float,
421 aRet.Double, aRet.Enum, aRet.String, aRet.Interface,
422 aRet.Any, aRet.Sequence, aRet2));
423 // Check inout sequence order (=> inout sequence parameter was
424 // switched by test objects):
425 TestElement temp(aRet.Sequence[0]);
426 aRet.Sequence[0] = aRet.Sequence[1];
427 aRet.Sequence[1] = temp;
428 bRet &= check(
429 equals(aData, aSV2ret) && equals(aData, aRet2),
430 "getValues2 test");
433 TwoFloats aIn(1.1f, 2.2f);
434 TwoFloats aOut = xLBT->echoTwoFloats(aIn);
435 bRet = check( memcmp(&aIn, &aOut, sizeof(TwoFloats)) == 0, "two floats struct test" ) && bRet;
438 FourFloats aIn(3.3f, 4.4f, 5.5f, 6.6f);
439 FourFloats aOut = xLBT->echoFourFloats(aIn);
440 bRet = check( memcmp(&aIn, &aOut, sizeof(FourFloats)) == 0, "four floats struct test" ) && bRet;
443 MixedFloatAndInteger aIn(7.7f, 8);
444 MixedFloatAndInteger aOut = xLBT->echoMixedFloatAndInteger(aIn);
445 bRet = check( memcmp(&aIn, &aOut, sizeof(MixedFloatAndInteger)) == 0, "mixed float and integer struct test" ) && bRet;
448 ThreeByteStruct aIn(9, 10, 11);
449 ThreeByteStruct aOut = xLBT->echoThreeByteStruct(aIn);
450 bRet = check( memcmp(&aIn, &aOut, sizeof(ThreeByteStruct)) == 0, "three byte struct test" ) && bRet;
453 TestData aRet;
454 TestData aRet2;
455 TestData aGVret(
456 xLBT->getValues(
457 aRet.Bool, aRet.Char, aRet.Byte, aRet.Short, aRet.UShort,
458 aRet.Long, aRet.ULong, aRet.Hyper, aRet.UHyper, aRet.Float,
459 aRet.Double, aRet.Enum, aRet.String, aRet.Interface,
460 aRet.Any, aRet.Sequence, aRet2));
461 bRet &= check(
462 (equals(aData, aRet) && equals(aData, aRet2) &&
463 equals(aData, aGVret)),
464 "getValues test");
465 // Set last retrieved values:
466 xLBT->setBool(aRet.Bool);
467 xLBT->setChar(aRet.Char);
468 xLBT->setByte(aRet.Byte);
469 xLBT->setShort(aRet.Short);
470 xLBT->setUShort(aRet.UShort);
471 xLBT->setLong(aRet.Long);
472 xLBT->setULong(aRet.ULong);
473 xLBT->setHyper(aRet.Hyper);
474 xLBT->setUHyper(aRet.UHyper);
475 xLBT->setFloat(aRet.Float);
476 xLBT->setDouble(aRet.Double);
477 xLBT->setEnum(aRet.Enum);
478 xLBT->setString(aRet.String);
479 xLBT->setInterface(aRet.Interface);
480 xLBT->setAny(aRet.Any);
481 xLBT->setSequence(aRet.Sequence);
482 xLBT->setStruct(aRet2);
485 TestData aRet;
486 aRet.Hyper = xLBT->getHyper();
487 aRet.UHyper = xLBT->getUHyper();
488 aRet.Float = xLBT->getFloat();
489 aRet.Double = xLBT->getDouble();
490 aRet.Byte = xLBT->getByte();
491 aRet.Char = xLBT->getChar();
492 aRet.Bool = xLBT->getBool();
493 aRet.Short = xLBT->getShort();
494 aRet.UShort = xLBT->getUShort();
495 aRet.Long = xLBT->getLong();
496 aRet.ULong = xLBT->getULong();
497 aRet.Enum = xLBT->getEnum();
498 aRet.String = xLBT->getString();
499 aRet.Interface = xLBT->getInterface();
500 aRet.Any = xLBT->getAny();
501 aRet.Sequence = xLBT->getSequence();
502 TestData aRet2(xLBT->getStruct());
503 bRet &= check(
504 equals(aData, aRet) && equals(aData, aRet2),
505 "struct comparison test");
507 SmallStruct aIn(1, 2);
508 SmallStruct aOut(xLBT->echoSmallStruct(aIn));
509 bRet &= check(
510 memcmp(&aIn, &aOut, sizeof(SmallStruct)) == 0,
511 "small struct test");
514 MediumStruct aIn(1, 2, 3, 4);
515 MediumStruct aOut(xLBT->echoMediumStruct(aIn));
516 bRet &= check(
517 memcmp(&aIn, &aOut, sizeof(MediumStruct)) == 0,
518 "medium struct test");
521 BigStruct aIn(1, 2, 3, 4, 5, 6, 7, 8);
522 BigStruct aOut(xLBT->echoBigStruct(aIn));
523 bRet &= check(
524 memcmp(&aIn, &aOut, sizeof(BigStruct)) == 0,
525 "big struct test");
528 sal_Int32 i2 = xLBT->testPPCAlignment(0, 0, 0, 0, 0xBEAF);
529 bRet &= check(i2 == 0xBEAF, "ppc-style alignment test");
532 double d1 = xLBT->testTenDoubles(0.1, 0.2, 0.3, 0.4, 0.5,
533 0.6, 0.7, 0.8, 0.9, 1.0);
534 bRet &= check(d1 == 5.5, "armhf doubles test");
536 // Test extended attributes that raise exceptions:
537 try {
538 xLBT->getRaiseAttr1();
539 bRet &= check(false, "getRaiseAttr1 did not throw");
540 } catch (const 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 (const 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 (const IllegalArgumentException &) {
555 } catch (...) {
556 bRet &= check(false, "getRaiseAttr2 threw wrong type");
558 // Test instantiated polymorphic struct types:
560 bRet &= check(
561 (xLBT->transportPolyBoolean(
562 TestPolyStruct< sal_Bool >(true)).
563 member),
564 "transportPolyBoolean");
565 TestPolyStruct< sal_Int64 > tps1(12345);
566 xLBT->transportPolyHyper(tps1);
567 bRet &= check(tps1.member == 12345, "transportPolyHyper");
568 Sequence< Any > seq(2);
569 seq[0] <<= static_cast< sal_uInt32 >(33);
570 seq[1] <<= OUString("ABC");
571 TestPolyStruct< Sequence< Any > > tps2(seq);
572 TestPolyStruct< Sequence< Any > > tps3;
573 xLBT->transportPolySequence(tps2, tps3);
574 bRet &= check(
575 tps3.member.getLength() == 2,
576 "transportPolySequence, length");
577 sal_uInt32 v0 = sal_uInt32();
578 tps3.member[0] >>= v0;
579 bRet &= check(v0 == 33, "transportPolySequence, element 0");
580 OUString v1;
581 tps3.member[1] >>= v1;
582 bRet &= check( v1 == "ABC", "transportPolySequence, element 1" );
583 bRet &= check(
584 xLBT->getNullPolyLong().member == 0, "getNullPolyLong");
585 bRet &= check(
586 xLBT->getNullPolyString().member.isEmpty(),
587 "getNullPolyString");
588 bRet &= check(
589 xLBT->getNullPolyType().member == Type(),
590 "getNullPolyType");
591 Any nullAny(xLBT->getNullPolyAny().member);
592 bRet &= check(
593 (((nullAny.getValueTypeName() ==
594 OUString(
595 "com.sun.star.uno.XInterface")) &&
596 !static_cast< Reference< XInterface > const * >(
597 nullAny.getValue())->is())
598 || nullAny == Any()),
599 "getNullPolyAny");
600 bRet &= check(
601 xLBT->getNullPolySequence().member.getLength() == 0,
602 "getNullPolySequence");
603 bRet &= check(
604 xLBT->getNullPolyEnum().member == TestEnum_TEST,
605 "getNullPolyEnum");
606 bRet &= check(
607 xLBT->getNullPolyBadEnum().member == TestBadEnum_M,
608 "getNullPolyBadEnum");
609 bRet &= check(
610 xLBT->getNullPolyStruct().member.member == 0,
611 "getNullPolyStruct");
612 bRet &= check(
613 !xLBT->getNullPolyInterface().member.is(),
614 "getNullPolyInterface");
616 // Any test:
617 bRet &= check(performAnyTest(xLBT , aData), "any test");
618 // Sequence of call test:
619 bRet &= check(
620 performSequenceOfCallTest(xLBT), "sequence of call test");
621 // Recursive call test:
622 bRet &= check(performRecursiveCallTest(xLBT), "recursive test");
623 bRet &= check(
624 equals(aData, aRet) && equals(aData, aRet2),
625 "recursive test results");
626 // Multiple inheritance test:
627 bRet &= checkEmpty(
628 testtools::bridgetest::testMulti(xLBT->getMulti()),
629 "remote multi");
630 bRet &= checkEmpty(
631 xLBT->testMulti(new testtools::bridgetest::Multi),
632 "local multi");
636 Reference< XBridgeTest2 > xBT2(xLBT, UNO_QUERY);
637 if (!xBT2.is()) {
638 return bRet;
640 // Perform sequence tests (XBridgeTest2); create the sequence which is
641 // compared with the results:
642 sal_Bool _arBool[] = { true, false, true };
643 sal_Unicode _arChar[] = { 0x0065, 0x0066, 0x0067 };
644 sal_Int8 _arByte[] = { 1, 2, -1 };
645 sal_Int16 _arShort[] = { -0x8000, 1, 0x7FFF };
646 sal_uInt16 _arUShort[] = { 0 , 1, 0xFFFF };
647 sal_Int32 _arLong[] = {
648 static_cast< sal_Int32 >(0x80000000), 1, 0x7FFFFFFF };
649 sal_uInt32 _arULong[] = { 0, 1, 0xFFFFFFFF };
650 sal_Int64 _arHyper[] = {
651 static_cast< sal_Int64 >(SAL_CONST_INT64(0x8000000000000000)), 1,
652 SAL_CONST_INT64(0x7FFFFFFFFFFFFFFF) };
653 sal_uInt64 _arUHyper[] = { 0, 1, SAL_CONST_UINT64(0xFFFFFFFFFFFFFFFF) };
654 float _arFloat[] = { 1.1f, 2.2f, 3.3f };
655 double _arDouble[] = { 1.11, 2.22, 3.33 };
656 OUString _arString[] = {
657 OUString("String 1"),
658 OUString("String 2"),
659 OUString("String 3") };
660 sal_Bool _aBool = true;
661 sal_Int32 _aInt = 0xBABEBABE;
662 float _aFloat = 3.14f;
663 Any _any1(&_aBool, getCppuBooleanType());
664 Any _any2(&_aInt, getCppuType((sal_Int32 *) 0));
665 Any _any3(&_aFloat, getCppuType((float *) 0));
666 Any _arAny[] = { _any1, _any2, _any3 };
667 Reference< XInterface > _arObj[3];
668 _arObj[0] = new OWeakObject();
669 _arObj[1] = new OWeakObject();
670 _arObj[2] = new OWeakObject();
671 TestEnum _arEnum[] = { TestEnum_ONE, TestEnum_TWO, TestEnum_CHECK };
672 TestElement _arStruct[3];
673 assign(
674 _arStruct[0], true, '@', 17, 0x1234, 0xFEDC, 0x12345678, 0xFEDCBA98,
675 SAL_CONST_INT64(0x123456789ABCDEF0),
676 SAL_CONST_UINT64(0xFEDCBA9876543210), 17.0815f, 3.1415926359,
677 TestEnum_LOLA, STRING_TEST_CONSTANT, _arObj[0],
678 Any(&_arObj[0], getCppuType((Reference< XInterface > const *) 0)));
679 assign(
680 _arStruct[1], true, 'A', 17, 0x1234, 0xFEDC, 0x12345678, 0xFEDCBA98,
681 SAL_CONST_INT64(0x123456789ABCDEF0),
682 SAL_CONST_UINT64(0xFEDCBA9876543210), 17.0815f, 3.1415926359,
683 TestEnum_TWO, STRING_TEST_CONSTANT, _arObj[1],
684 Any(&_arObj[1], getCppuType((Reference< XInterface > const *) 0)));
685 assign(
686 _arStruct[2], true, 'B', 17, 0x1234, 0xFEDC, 0x12345678, 0xFEDCBA98,
687 SAL_CONST_INT64(0x123456789ABCDEF0),
688 SAL_CONST_UINT64(0xFEDCBA9876543210), 17.0815f, 3.1415926359,
689 TestEnum_CHECK, STRING_TEST_CONSTANT, _arObj[2],
690 Any(&_arObj[2], getCppuType((Reference< XInterface > const *) 0)));
692 Sequence<sal_Bool> arBool(_arBool, 3);
693 Sequence<sal_Unicode> arChar( _arChar, 3);
694 Sequence<sal_Int8> arByte(_arByte, 3);
695 Sequence<sal_Int16> arShort(_arShort, 3);
696 Sequence<sal_uInt16> arUShort(_arUShort, 3);
697 Sequence<sal_Int32> arLong(_arLong, 3);
698 Sequence<sal_uInt32> arULong(_arULong, 3);
699 Sequence<sal_Int64> arHyper(_arHyper, 3);
700 Sequence<sal_uInt64> arUHyper(_arUHyper, 3);
701 Sequence<float> arFloat(_arFloat, 3);
702 Sequence<double> arDouble(_arDouble, 3);
703 Sequence<OUString> arString(_arString, 3);
704 Sequence<Any> arAny(_arAny, 3);
705 Sequence<Reference<XInterface> > arObject(_arObj, 3);
706 Sequence<TestEnum> arEnum(_arEnum, 3);
707 Sequence<TestElement> arStruct(_arStruct, 3);
708 Sequence<Sequence<sal_Int32> > _arSeqLong2[3];
709 for (int j = 0; j != 3; ++j) {
710 Sequence< sal_Int32 > _arSeqLong[3];
711 for (int i = 0; i != 3; ++i) {
712 _arSeqLong[i] = Sequence< sal_Int32 >(_arLong, 3);
714 _arSeqLong2[j] = Sequence< Sequence< sal_Int32 > >(
715 _arSeqLong, 3);
717 Sequence< Sequence< Sequence< sal_Int32> > > arLong3(
718 _arSeqLong2, 3);
719 Sequence< Sequence< sal_Int32 > > seqSeqRet(
720 xBT2->setDim2(arLong3[0]));
721 bRet &= check(seqSeqRet == arLong3[0], "sequence test");
722 Sequence< Sequence< Sequence< sal_Int32 > > > seqSeqRet2(
723 xBT2->setDim3(arLong3));
724 bRet &= check(seqSeqRet2 == arLong3, "sequence test");
725 Sequence< Any > seqAnyRet(xBT2->setSequenceAny(arAny));
726 bRet &= check(seqAnyRet == arAny, "sequence test");
727 Sequence< sal_Bool > seqBoolRet(xBT2->setSequenceBool(arBool));
728 bRet &= check(seqBoolRet == arBool, "sequence test");
729 Sequence< sal_Int8 > seqByteRet(xBT2->setSequenceByte(arByte));
730 bRet &= check(seqByteRet == arByte, "sequence test");
731 Sequence< sal_Unicode > seqCharRet(xBT2->setSequenceChar(arChar));
732 bRet &= check(seqCharRet == arChar, "sequence test");
733 Sequence< sal_Int16 > seqShortRet(xBT2->setSequenceShort(arShort));
734 bRet &= check(seqShortRet == arShort, "sequence test");
735 Sequence< sal_Int32 > seqLongRet(xBT2->setSequenceLong(arLong));
736 bRet &= check(seqLongRet == arLong, "sequence test");
737 Sequence< sal_Int64 > seqHyperRet(xBT2->setSequenceHyper(arHyper));
738 bRet &= check(seqHyperRet == arHyper, "sequence test");
739 Sequence< float > seqFloatRet(xBT2->setSequenceFloat(arFloat));
740 bRet &= check(seqFloatRet == arFloat, "sequence test");
741 Sequence< double > seqDoubleRet(xBT2->setSequenceDouble(arDouble));
742 bRet &= check(seqDoubleRet == arDouble, "sequence test");
743 Sequence< TestEnum > seqEnumRet(xBT2->setSequenceEnum(arEnum));
744 bRet &= check(seqEnumRet == arEnum, "sequence test");
745 Sequence< sal_uInt16 > seqUShortRet(
746 xBT2->setSequenceUShort(arUShort));
747 bRet &= check(seqUShortRet == arUShort, "sequence test");
748 Sequence< sal_uInt32 > seqULongRet(xBT2->setSequenceULong(arULong));
749 bRet &= check(seqULongRet == arULong, "sequence test");
750 Sequence< sal_uInt64 > seqUHyperRet(
751 xBT2->setSequenceUHyper(arUHyper));
752 bRet &= check(seqUHyperRet == arUHyper, "sequence test");
753 Sequence< Reference< XInterface > > seqObjectRet(
754 xBT2->setSequenceXInterface(arObject));
755 bRet &= check(seqObjectRet == arObject, "sequence test");
756 Sequence< OUString > seqStringRet(
757 xBT2->setSequenceString(arString));
758 bRet &= check(seqStringRet == arString, "sequence test");
759 Sequence< TestElement > seqStructRet(
760 xBT2->setSequenceStruct(arStruct));
761 bRet &= check(seqStructRet == arStruct, "sequence test");
762 Sequence< sal_Bool > arBoolTemp(cloneSequence(arBool));
763 Sequence< sal_Unicode > arCharTemp(cloneSequence(arChar));
764 Sequence< sal_Int8 > arByteTemp(cloneSequence(arByte));
765 Sequence< sal_Int16 > arShortTemp(cloneSequence(arShort));
766 Sequence< sal_uInt16 > arUShortTemp(cloneSequence(arUShort));
767 Sequence< sal_Int32 > arLongTemp(cloneSequence(arLong));
768 Sequence< sal_uInt32 > arULongTemp(cloneSequence(arULong));
769 Sequence< sal_Int64 > arHyperTemp(cloneSequence(arHyper));
770 Sequence< sal_uInt64 > arUHyperTemp(cloneSequence(arUHyper));
771 Sequence< float > arFloatTemp(cloneSequence(arFloat));
772 Sequence< double > arDoubleTemp(cloneSequence(arDouble));
773 Sequence< TestEnum > arEnumTemp(cloneSequence(arEnum));
774 Sequence< OUString > arStringTemp(cloneSequence(arString));
775 Sequence< Reference< XInterface > > arObjectTemp(
776 cloneSequence(arObject));
777 Sequence< Any > arAnyTemp(cloneSequence(arAny));
778 Sequence< Sequence< sal_Int32 > > arLong2Temp(arLong3[0]);
779 Sequence< Sequence< Sequence< sal_Int32 > > > arLong3Temp(arLong3);
780 xBT2->setSequencesInOut(
781 arBoolTemp, arCharTemp, arByteTemp, arShortTemp, arUShortTemp,
782 arLongTemp,arULongTemp, arHyperTemp, arUHyperTemp, arFloatTemp,
783 arDoubleTemp, arEnumTemp, arStringTemp, arObjectTemp, arAnyTemp,
784 arLong2Temp, arLong3Temp);
785 bRet &= check(
786 (arBoolTemp == arBool && arCharTemp == arChar &&
787 arByteTemp == arByte && arShortTemp == arShort &&
788 arUShortTemp == arUShort && arLongTemp == arLong &&
789 arULongTemp == arULong && arHyperTemp == arHyper &&
790 arUHyperTemp == arUHyper && arFloatTemp == arFloat &&
791 arDoubleTemp == arDouble && arEnumTemp == arEnum &&
792 arStringTemp == arString && arObjectTemp == arObject &&
793 arAnyTemp == arAny && arLong2Temp == arLong3[0] &&
794 arLong3Temp == arLong3),
795 "sequence test");
796 Sequence< sal_Bool > arBoolOut;
797 Sequence< sal_Unicode > arCharOut;
798 Sequence< sal_Int8 > arByteOut;
799 Sequence< sal_Int16 > arShortOut;
800 Sequence< sal_uInt16 > arUShortOut;
801 Sequence< sal_Int32 > arLongOut;
802 Sequence< sal_uInt32 > arULongOut;
803 Sequence< sal_Int64 > arHyperOut;
804 Sequence< sal_uInt64 > arUHyperOut;
805 Sequence< float > arFloatOut;
806 Sequence< double > arDoubleOut;
807 Sequence< TestEnum > arEnumOut;
808 Sequence< OUString > arStringOut;
809 Sequence< Reference< XInterface > > arObjectOut;
810 Sequence< Any > arAnyOut;
811 Sequence< Sequence< sal_Int32 > > arLong2Out;
812 Sequence< Sequence< Sequence< sal_Int32 > > > arLong3Out;
813 xBT2->setSequencesOut(
814 arBoolOut, arCharOut, arByteOut, arShortOut, arUShortOut,
815 arLongOut,arULongOut, arHyperOut, arUHyperOut, arFloatOut,
816 arDoubleOut, arEnumOut, arStringOut, arObjectOut, arAnyOut,
817 arLong2Out, arLong3Out);
818 bRet &= check(
819 (arBoolOut == arBool && arCharOut == arChar &&
820 arByteOut == arByte && arShortOut == arShort &&
821 arUShortOut == arUShort && arLongOut == arLong &&
822 arULongOut == arULong && arHyperOut == arHyper &&
823 arUHyperOut == arUHyper && arFloatOut == arFloat &&
824 arDoubleOut == arDouble && arEnumOut == arEnum &&
825 arStringOut == arString && arObjectOut == arObject &&
826 arAnyOut == arAny && arLong2Out == arLong3[0] &&
827 arLong3Out == arLong3),
828 "sequence test");
831 // Test with empty sequences:
832 Sequence< Sequence< sal_Int32 > > arLong2;
833 Sequence< Sequence< sal_Int32 > > seqSeqRet(xBT2->setDim2(arLong2));
834 bRet &= check(seqSeqRet == arLong2, "sequence test");
835 Sequence< Sequence< Sequence< sal_Int32 > > > arLong3;
836 Sequence< Sequence< Sequence< sal_Int32 > > > seqSeqRet2(
837 xBT2->setDim3(arLong3));
838 bRet &= check(seqSeqRet2 == arLong3, "sequence test");
839 Sequence< Any > arAny;
840 Sequence< Any > seqAnyRet(xBT2->setSequenceAny(arAny));
841 bRet &= check(seqAnyRet == arAny, "sequence test");
842 Sequence< sal_Bool > arBool;
843 Sequence< sal_Bool > seqBoolRet(xBT2->setSequenceBool(arBool));
844 bRet &= check(seqBoolRet == arBool, "sequence test");
845 Sequence< sal_Int8 > arByte;
846 Sequence< sal_Int8 > seqByteRet(xBT2->setSequenceByte(arByte));
847 bRet &= check(seqByteRet == arByte, "sequence test");
848 Sequence< sal_Unicode > arChar;
849 Sequence< sal_Unicode > seqCharRet(xBT2->setSequenceChar(arChar));
850 bRet &= check(seqCharRet == arChar, "sequence test");
851 Sequence< sal_Int16 > arShort;
852 Sequence< sal_Int16 > seqShortRet(xBT2->setSequenceShort(arShort));
853 bRet &= check(seqShortRet == arShort, "sequence test");
854 Sequence< sal_Int32 > arLong;
855 Sequence< sal_Int32 > seqLongRet(xBT2->setSequenceLong(arLong));
856 bRet &= check(seqLongRet == arLong, "sequence test");
857 Sequence< sal_Int64 > arHyper;
858 Sequence< sal_Int64 > seqHyperRet(xBT2->setSequenceHyper(arHyper));
859 bRet &= check(seqHyperRet == arHyper, "sequence test");
860 Sequence< float > arFloat;
861 Sequence< float > seqFloatRet(xBT2->setSequenceFloat(arFloat));
862 bRet &= check(seqFloatRet == arFloat, "sequence test");
863 Sequence< double > arDouble;
864 Sequence< double > seqDoubleRet(xBT2->setSequenceDouble(arDouble));
865 bRet &= check(seqDoubleRet == arDouble, "sequence test");
866 Sequence< TestEnum > arEnum;
867 Sequence< TestEnum > seqEnumRet(xBT2->setSequenceEnum(arEnum));
868 bRet &= check(seqEnumRet == arEnum, "sequence test");
869 Sequence< sal_uInt16 > arUShort;
870 Sequence< sal_uInt16 > seqUShortRet(
871 xBT2->setSequenceUShort(arUShort));
872 bRet &= check(seqUShortRet == arUShort, "sequence test");
873 Sequence< sal_uInt32 > arULong;
874 Sequence< sal_uInt32 > seqULongRet(xBT2->setSequenceULong(arULong));
875 bRet &= check(seqULongRet == arULong, "sequence test");
876 Sequence< sal_uInt64 > arUHyper;
877 Sequence< sal_uInt64 > seqUHyperRet(
878 xBT2->setSequenceUHyper(arUHyper));
879 bRet &= check(seqUHyperRet == arUHyper, "sequence test");
880 Sequence< Reference< XInterface > > arObject;
881 Sequence< Reference< XInterface > > seqObjectRet(
882 xBT2->setSequenceXInterface(arObject));
883 bRet &= check(seqObjectRet == arObject, "sequence test");
884 Sequence< OUString > arString;
885 Sequence< OUString > seqStringRet(
886 xBT2->setSequenceString(arString));
887 bRet &= check(seqStringRet == arString, "sequence test");
888 Sequence< TestElement > arStruct;
889 Sequence< TestElement > seqStructRet(
890 xBT2->setSequenceStruct(arStruct));
891 bRet &= check(seqStructRet == arStruct, "sequence test");
893 // Issue #i60341# shows that the most interesting case is were Java
894 // calls the constructors; however, since this client is currently not
895 // available in Java, while the server is, the logic is reversed here:
896 try {
897 xBT2->testConstructorsService(xContext);
898 } catch (const BadConstructorArguments &) {
899 bRet = false;
901 if (!noCurrentContext) {
902 if (!(new testtools::bridgetest::CurrentContextChecker)->perform(
903 xBT2->getCurrentContextChecker(), 0, 1))
905 bRet = false;
907 if (!(new testtools::bridgetest::CurrentContextChecker)->perform(
908 xBT2->getCurrentContextChecker(), 0, 2))
910 bRet = false;
912 if (!(new testtools::bridgetest::CurrentContextChecker)->perform(
913 xBT2->getCurrentContextChecker(), 1, 2))
915 bRet = false;
917 if (!(new testtools::bridgetest::CurrentContextChecker)->perform(
918 xBT2->getCurrentContextChecker(), 1, 3))
920 bRet = false;
924 return bRet;
927 static sal_Bool raiseOnewayException( const Reference < XBridgeTest > & xLBT )
929 sal_Bool bReturn = sal_True;
930 OUString sCompare = STRING_TEST_CONSTANT;
931 Reference<XInterface> const x(xLBT->getInterface());
934 // Note : the exception may fly or not (e.g. remote scenario).
935 // When it flies, it must contain the correct elements.
936 xLBT->raiseRuntimeExceptionOneway( sCompare, x );
938 catch( const RuntimeException & e )
940 bReturn = (
941 #if OSL_DEBUG_LEVEL == 0
942 // java stack traces trash Message
943 e.Message == sCompare &&
944 #endif
945 xLBT->getInterface() == e.Context &&
946 x == e.Context );
948 return bReturn;
951 //==================================================================================================
952 static sal_Bool raiseException( const Reference< XBridgeTest > & xLBT )
954 sal_Int32 nCount = 0;
961 TestData aRet, aRet2;
962 xLBT->raiseException(
963 5, STRING_TEST_CONSTANT,
964 xLBT->getInterface() );
966 catch (const IllegalArgumentException &rExc)
968 if (rExc.ArgumentPosition == 5 &&
969 #if OSL_DEBUG_LEVEL == 0
970 // java stack traces trash Message
971 rExc.Message.compareToAscii( STRING_TEST_CONSTANT ) == 0 &&
972 #endif
973 rExc.Context == xLBT->getInterface())
975 #ifdef COMPCHECK
976 //When we check if a new compiler still works then we must not call
977 //getRuntimeException because it uses cppu::getCaughtException which
978 //does only work if all libs are build with the same runtime.
979 return true;
980 #else
981 ++nCount;
982 #endif
984 else
986 check( sal_False, "### unexpected exception content!" );
989 /** it is certain, that the RuntimeException testing will fail, if no */
990 xLBT->getRuntimeException();
993 catch (const RuntimeException & rExc)
995 if (rExc.Context == xLBT->getInterface()
996 #if OSL_DEBUG_LEVEL == 0
997 // java stack traces trash Message
998 && rExc.Message.compareToAscii( STRING_TEST_CONSTANT ) == 0
999 #endif
1002 ++nCount;
1004 else
1006 check( sal_False, "### unexpected exception content!" );
1009 /** it is certain, that the RuntimeException testing will fail, if no */
1010 xLBT->setRuntimeException( 0xcafebabe );
1013 catch (const Exception & rExc)
1015 if (rExc.Context == xLBT->getInterface()
1016 #if OSL_DEBUG_LEVEL == 0
1017 // java stack traces trash Message
1018 && rExc.Message.compareToAscii( STRING_TEST_CONSTANT ) == 0
1019 #endif
1022 ++nCount;
1024 else
1026 check( sal_False, "### unexpected exception content!" );
1028 return (nCount == 3);
1030 return sal_False;
1033 /* Returns an acquired sequence
1035 uno_Sequence* cloneSequence(const uno_Sequence* val, const Type& type)
1037 TypeDescription td(type);
1038 td.makeComplete();
1039 typelib_TypeDescription* pTdRaw = td.get();
1040 typelib_IndirectTypeDescription* pIndirectTd =
1041 (typelib_IndirectTypeDescription*) pTdRaw;
1043 typelib_TypeDescription* pTdElem = pIndirectTd->pType->pType;
1044 sal_Int8* buf = new sal_Int8[pTdElem->nSize * val->nElements];
1045 sal_Int8* pBufCur = buf;
1047 uno_Sequence* retSeq = NULL;
1048 switch (pTdElem->eTypeClass)
1050 case TypeClass_SEQUENCE:
1052 Type _tElem(pTdElem->pWeakRef);
1053 for (int i = 0; i < val->nElements; i++)
1055 sal_Int8 *pValBuf = (sal_Int8 *)(&val->elements + i * pTdElem->nSize);
1057 uno_Sequence* seq = cloneSequence(
1058 *(uno_Sequence**) (pValBuf),
1059 _tElem);
1060 *((uno_Sequence**) pBufCur) = seq;
1061 pBufCur += pTdElem->nSize;
1063 break;
1065 default:
1066 uno_type_sequence_construct(
1067 &retSeq, type.getTypeLibType(), (void*) val->elements,
1068 val->nElements, reinterpret_cast< uno_AcquireFunc >(cpp_acquire));
1069 break;
1071 delete[] buf;
1072 return retSeq;
1075 template< class T>
1076 Sequence<T> cloneSequence(const Sequence<T>& val)
1078 Sequence<T> seq( cloneSequence(val.get(), getCppuType(&val)), SAL_NO_ACQUIRE);
1079 return seq;
1082 template< class T >
1083 inline bool makeSurrogate(
1084 Reference< T > & rOut, Reference< T > const & rOriginal )
1086 rOut.clear();
1087 if (! rOriginal.is())
1088 return false;
1090 Environment aCppEnv_official;
1091 Environment aUnoEnv_ano;
1092 Environment aCppEnv_ano;
1094 OUString aCppEnvTypeName(
1095 CPPU_CURRENT_LANGUAGE_BINDING_NAME );
1096 OUString aUnoEnvTypeName(
1097 UNO_LB_UNO );
1098 // official:
1099 uno_getEnvironment(
1100 reinterpret_cast< uno_Environment ** >( &aCppEnv_official ),
1101 aCppEnvTypeName.pData, 0 );
1102 // anonymous:
1103 uno_createEnvironment(
1104 reinterpret_cast< uno_Environment ** >( &aCppEnv_ano ),
1105 aCppEnvTypeName.pData, 0 );
1106 uno_createEnvironment(
1107 reinterpret_cast< uno_Environment ** >( &aUnoEnv_ano ),
1108 aUnoEnvTypeName.pData, 0 );
1110 UnoInterfaceReference unoI;
1111 Mapping cpp2uno( aCppEnv_official.get(), aUnoEnv_ano.get() );
1112 Mapping uno2cpp( aUnoEnv_ano.get(), aCppEnv_ano.get() );
1113 if (!cpp2uno.is() || !uno2cpp.is())
1115 throw RuntimeException(
1116 "cannot get C++-UNO mappings!",
1117 Reference< XInterface >() );
1119 cpp2uno.mapInterface(
1120 reinterpret_cast< void ** >( &unoI.m_pUnoI ),
1121 rOriginal.get(), ::getCppuType( &rOriginal ) );
1122 if (! unoI.is())
1124 throw RuntimeException(
1125 "mapping C++ to binary UNO failed!",
1126 Reference< XInterface >() );
1128 uno2cpp.mapInterface(
1129 reinterpret_cast< void ** >( &rOut ),
1130 unoI.get(), ::getCppuType( &rOriginal ) );
1131 if (! rOut.is())
1133 throw RuntimeException(
1134 "mapping binary UNO to C++ failed!",
1135 Reference< XInterface >() );
1138 return rOut.is();
1141 //==================================================================================================
1142 sal_Int32 TestBridgeImpl::run( const Sequence< OUString > & rArgs )
1143 throw (RuntimeException)
1145 bool bRet = false;
1148 if (! rArgs.getLength())
1150 throw RuntimeException( OUString(
1151 "no test object specified!\n"
1152 "usage : ServiceName of test object | -u unourl of test object\n" ),
1153 Reference< XInterface >() );
1156 Reference< XInterface > xOriginal;
1157 bool remote;
1158 sal_Int32 i;
1159 if( rArgs.getLength() > 1 && 0 == rArgs[0].compareToAscii( "-u" ) )
1161 remote = true;
1162 i = 2;
1164 else
1166 remote = false;
1167 i = 1;
1169 bool noCurrentContext = false;
1170 if ( i < rArgs.getLength() && rArgs[i] == "noCurrentContext" )
1172 noCurrentContext = true;
1173 ++i;
1175 bool stress = false;
1176 if ( i < rArgs.getLength() && rArgs[i] == "stress" )
1178 stress = true;
1179 ++i;
1182 for (;;) {
1183 Reference< XInterface > o;
1184 if (remote) {
1185 o = UnoUrlResolver::create(m_xContext)->resolve(rArgs[1]);
1186 } else {
1187 o = m_xContext->getServiceManager()->createInstanceWithContext(
1188 rArgs[0], m_xContext);
1190 if (!stress) {
1191 xOriginal = o;
1192 break;
1196 if (! xOriginal.is())
1198 throw RuntimeException(
1199 OUString(
1200 "cannot get test object!"),
1201 Reference< XInterface >() );
1203 Reference< XBridgeTest > xTest( xOriginal, UNO_QUERY );
1204 if (! xTest.is())
1206 throw RuntimeException(
1207 OUString("test object does not implement XBridgeTest!"),
1208 Reference< XInterface >() );
1211 Reference<XBridgeTest > xLBT;
1212 bRet = check( makeSurrogate( xLBT, xTest ), "makeSurrogate" );
1213 bRet = check(
1214 performTest( m_xContext, xLBT, noCurrentContext ), "standard test" )
1215 && bRet;
1216 bRet = check( raiseException( xLBT ) , "exception test" )&& bRet;
1217 bRet = check( raiseOnewayException( xLBT ),
1218 "oneway exception test" ) && bRet;
1219 if (! bRet)
1221 throw RuntimeException(
1222 OUString("error: test failed!"),
1223 Reference< XInterface >() );
1226 catch (const Exception & exc)
1228 OString cstr( OUStringToOString( exc.Message, RTL_TEXTENCODING_ASCII_US ) );
1229 fprintf( stderr, "exception occurred: %s\n", cstr.getStr() );
1230 throw;
1233 return bRet ? 0 : 1;
1236 // XServiceInfo
1237 //__________________________________________________________________________________________________
1238 OUString TestBridgeImpl::getImplementationName()
1239 throw (RuntimeException)
1241 return OUString( IMPLNAME );
1243 //__________________________________________________________________________________________________
1244 sal_Bool TestBridgeImpl::supportsService( const OUString & rServiceName )
1245 throw (RuntimeException)
1247 const Sequence< OUString > & rSNL = getSupportedServiceNames();
1248 const OUString * pArray = rSNL.getConstArray();
1249 for ( sal_Int32 nPos = rSNL.getLength(); nPos--; )
1251 if (pArray[nPos] == rServiceName)
1252 return sal_True;
1254 return sal_False;
1256 //__________________________________________________________________________________________________
1257 Sequence< OUString > TestBridgeImpl::getSupportedServiceNames()
1258 throw (RuntimeException)
1260 return bridge_test::getSupportedServiceNames();
1263 // ...
1265 //==================================================================================================
1266 static Reference< XInterface > SAL_CALL TestBridgeImpl_create(
1267 const Reference< XComponentContext > & xContext )
1269 return Reference< XInterface >(
1270 static_cast< OWeakObject * >( new TestBridgeImpl( xContext ) ) );
1275 extern "C"
1277 //==================================================================================================
1278 SAL_DLLPUBLIC_EXPORT void * SAL_CALL component_getFactory(
1279 const sal_Char * pImplName, void * pServiceManager,
1280 SAL_UNUSED_PARAMETER void * )
1282 void * pRet = 0;
1284 if (pServiceManager && rtl_str_compare( pImplName, IMPLNAME ) == 0)
1286 Reference< XInterface > xFactory(
1287 createSingleComponentFactory(
1288 bridge_test::TestBridgeImpl_create,
1289 OUString( IMPLNAME ),
1290 bridge_test::getSupportedServiceNames() ) );
1292 if (xFactory.is())
1294 xFactory->acquire();
1295 pRet = xFactory.get();
1299 return pRet;
1303 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */