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