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_bridges.hxx" 30 #include <string.h> 31 #include <stdlib.h> 32 #include <osl/time.h> 33 34 #include <uno/threadpool.h> 35 36 #include <osl/mutex.hxx> 37 #include <osl/diagnose.h> 38 39 #include <test/XTestFactory.hpp> 40 #include <cppuhelper/servicefactory.hxx> 41 42 #include <com/sun/star/bridge/XInstanceProvider.hpp> 43 44 #include <com/sun/star/registry/XImplementationRegistration.hpp> 45 46 #include <com/sun/star/test/performance/XPerformanceTest.hpp> 47 #include <com/sun/star/lang/XServiceInfo.hpp> 48 49 #include <cppuhelper/weak.hxx> 50 51 using namespace ::test; 52 using namespace ::rtl; 53 using namespace ::test; 54 using namespace ::com::sun::star::uno; 55 using namespace ::com::sun::star::bridge; 56 using namespace ::com::sun::star::lang; 57 using namespace ::com::sun::star::registry; 58 using namespace ::com::sun::star::test::performance; 59 60 #include "testcomp.h" 61 62 63 void parseCommandLine( char *argv[] , 64 ::rtl::OUString *pConnection , ::rtl::OUString *pProtocol , 65 sal_Bool *pbLatency , sal_Bool *pbReverse) 66 { 67 sal_Int32 nArgIndex = 1; 68 if( ! strcmp( argv[1] , "-r" ) ) 69 { 70 nArgIndex = 2; 71 *pbReverse = sal_True; 72 } 73 else if( ! strcmp( argv[1] , "-latency" ) ) 74 { 75 *pbLatency = sal_True; 76 nArgIndex = 2; 77 } 78 79 OUString sTemp = OUString::createFromAscii( argv[nArgIndex] ); 80 sal_Int32 nIndex = sTemp.indexOf( ';' ); 81 if( -1 == nIndex ) 82 { 83 *pConnection = sTemp; 84 *pProtocol = OUString( RTL_CONSTASCII_USTRINGPARAM( "iiop" ) ); 85 } 86 else 87 { 88 *pConnection = sTemp.copy( 0 , nIndex ); 89 *pProtocol = sTemp.copy( nIndex+1, sTemp.getLength() - (nIndex+1) ); 90 } 91 } 92 93 Any OInstanceProvider::queryInterface( const Type & aType ) throw ( RuntimeException ) 94 { 95 Any a = ::cppu::queryInterface( aType , 96 SAL_STATIC_CAST( XInstanceProvider * , this ) ); 97 if( a.hasValue() ) 98 { 99 return a; 100 } 101 return OWeakObject::queryInterface( aType ); 102 } 103 104 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > 105 OInstanceProvider::getInstance( const ::rtl::OUString& sObjectName ) 106 throw(::com::sun::star::container::NoSuchElementException, 107 ::com::sun::star::uno::RuntimeException) 108 { 109 // Tries to get the PerformanceTestObject 110 if( sObjectName == OUString( RTL_CONSTASCII_USTRINGPARAM( "TestRemoteObject" ) ) ) 111 { 112 return m_rSMgr->createInstance( 113 OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.test.performance.PerformanceTestObject") ) ); 114 } 115 return Reference < XInterface > ( (::cppu::OWeakObject * ) new OTestFactory() ); 116 } 117 118 class ServiceImpl 119 : public XServiceInfo 120 , public XPerformanceTest 121 { 122 OUString _aDummyString; 123 Any _aDummyAny; 124 Sequence< Reference< XInterface > > _aDummySequence; 125 ComplexTypes _aDummyStruct; 126 RuntimeException _aDummyRE; 127 128 sal_Int32 _nRef; 129 130 public: 131 ServiceImpl() 132 : _nRef( 0 ) 133 {} 134 ServiceImpl( const Reference< XMultiServiceFactory > & /* xMgr */) 135 : _nRef( 0 ) 136 {} 137 138 // XInterface 139 virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type& aType ) throw(::com::sun::star::uno::RuntimeException) 140 { 141 // execution time remains appr. constant any time 142 Any aRet; 143 if (aType == ::getCppuType( (const Reference< XInterface > *)0 )) 144 { 145 void * p = (XInterface *)(XPerformanceTest *)this; 146 aRet.setValue( &p, ::getCppuType( (const Reference< XInterface > *)0 ) ); 147 } 148 if (aType == ::getCppuType( (const Reference< XPerformanceTest > *)0 )) 149 { 150 void * p = (XPerformanceTest *)this; 151 aRet.setValue( &p, ::getCppuType( (const Reference< XPerformanceTest > *)0 ) ); 152 } 153 if (! aRet.hasValue()) 154 { 155 void * p = (XPerformanceTest *)this; 156 Any aDummy( &p, ::getCppuType( (const Reference< XPerformanceTest > *)0 ) ); 157 } 158 return aRet; 159 } 160 virtual void SAL_CALL acquire() throw() 161 { osl_incrementInterlockedCount( &_nRef ); } 162 virtual void SAL_CALL release() throw() 163 { if (! osl_decrementInterlockedCount( &_nRef )) delete this; } 164 165 // XServiceInfo 166 virtual OUString SAL_CALL getImplementationName() throw (RuntimeException); 167 virtual sal_Bool SAL_CALL supportsService( const OUString & rServiceName ) throw (RuntimeException); 168 virtual Sequence< OUString > SAL_CALL getSupportedServiceNames() throw (RuntimeException); 169 170 // Attributes 171 virtual sal_Int32 SAL_CALL getLong_attr() throw(::com::sun::star::uno::RuntimeException) 172 { return 0; } 173 virtual void SAL_CALL setLong_attr( sal_Int32 /* _attributelong */) throw(::com::sun::star::uno::RuntimeException) 174 {} 175 virtual sal_Int64 SAL_CALL getHyper_attr() throw(::com::sun::star::uno::RuntimeException) 176 { return 0; } 177 virtual void SAL_CALL setHyper_attr( sal_Int64 /* _attributehyper */) throw(::com::sun::star::uno::RuntimeException) 178 {} 179 virtual float SAL_CALL getFloat_attr() throw(::com::sun::star::uno::RuntimeException) 180 { return 0.0; } 181 virtual void SAL_CALL setFloat_attr( float /* _attributefloat */) throw(::com::sun::star::uno::RuntimeException) 182 {} 183 virtual double SAL_CALL getDouble_attr() throw(::com::sun::star::uno::RuntimeException) 184 { return 0.0; } 185 virtual void SAL_CALL setDouble_attr( double /* _attributedouble */) throw(::com::sun::star::uno::RuntimeException) 186 {} 187 virtual OUString SAL_CALL getString_attr() throw(::com::sun::star::uno::RuntimeException) 188 { return _aDummyString; } 189 virtual void SAL_CALL setString_attr( const ::rtl::OUString& /* _attributestring */) throw(::com::sun::star::uno::RuntimeException) 190 {} 191 virtual Reference< XInterface > SAL_CALL getInterface_attr() throw(::com::sun::star::uno::RuntimeException) 192 { return Reference< XInterface >(); } 193 virtual void SAL_CALL setInterface_attr( const Reference< XInterface >& /* _attributeinterface */) throw(::com::sun::star::uno::RuntimeException) 194 {} 195 virtual Any SAL_CALL getAny_attr() throw(::com::sun::star::uno::RuntimeException) 196 { return _aDummyAny; } 197 virtual void SAL_CALL setAny_attr( const Any& /* _attributeany */) throw(::com::sun::star::uno::RuntimeException) 198 {} 199 virtual Sequence< Reference< XInterface > > SAL_CALL getSequence_attr() throw(::com::sun::star::uno::RuntimeException) 200 { return _aDummySequence; } 201 virtual void SAL_CALL setSequence_attr( const Sequence< Reference< XInterface > >& /* _attributesequence */) throw(::com::sun::star::uno::RuntimeException) 202 {} 203 virtual ComplexTypes SAL_CALL getStruct_attr() throw(::com::sun::star::uno::RuntimeException) 204 { return _aDummyStruct; } 205 virtual void SAL_CALL setStruct_attr( const ::com::sun::star::test::performance::ComplexTypes& /* _attributestruct */) throw(::com::sun::star::uno::RuntimeException) 206 {} 207 208 // Methods 209 virtual sal_Int32 SAL_CALL getLong() throw(::com::sun::star::uno::RuntimeException) 210 { return 0; } 211 virtual void SAL_CALL setLong( sal_Int32 /* _long */) throw(::com::sun::star::uno::RuntimeException) 212 {} 213 virtual sal_Int64 SAL_CALL getHyper() throw(::com::sun::star::uno::RuntimeException) 214 { return 0; } 215 virtual void SAL_CALL setHyper( sal_Int64 /* _hyper */) throw(::com::sun::star::uno::RuntimeException) 216 {} 217 virtual float SAL_CALL getFloat() throw(::com::sun::star::uno::RuntimeException) 218 { return 0; } 219 virtual void SAL_CALL setFloat( float /* _float */) throw(::com::sun::star::uno::RuntimeException) 220 {} 221 virtual double SAL_CALL getDouble() throw(::com::sun::star::uno::RuntimeException) 222 { return 0; } 223 virtual void SAL_CALL setDouble( double /* _double */) throw(::com::sun::star::uno::RuntimeException) 224 {} 225 virtual OUString SAL_CALL getString() throw(::com::sun::star::uno::RuntimeException) 226 { return _aDummyString; } 227 virtual void SAL_CALL setString( const ::rtl::OUString& /* _string */) throw(::com::sun::star::uno::RuntimeException) 228 {} 229 virtual Reference< XInterface > SAL_CALL getInterface() throw(::com::sun::star::uno::RuntimeException) 230 { return Reference< XInterface >(); } 231 virtual void SAL_CALL setInterface( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& /* _interface */) throw(::com::sun::star::uno::RuntimeException) 232 {} 233 virtual Any SAL_CALL getAny() throw(::com::sun::star::uno::RuntimeException) 234 { return _aDummyAny; } 235 virtual void SAL_CALL setAny( const ::com::sun::star::uno::Any& /* _any */) throw(::com::sun::star::uno::RuntimeException) 236 {} 237 virtual Sequence< Reference< XInterface > > SAL_CALL getSequence() throw(::com::sun::star::uno::RuntimeException) 238 { return _aDummySequence; } 239 virtual void SAL_CALL setSequence( const Sequence< Reference< XInterface > >& /*_sequence */) throw(::com::sun::star::uno::RuntimeException) 240 {} 241 virtual ComplexTypes SAL_CALL getStruct() throw(::com::sun::star::uno::RuntimeException) 242 { return _aDummyStruct; } 243 virtual void SAL_CALL setStruct( const ::com::sun::star::test::performance::ComplexTypes& /* c */) throw(::com::sun::star::uno::RuntimeException) 244 {} 245 246 virtual void SAL_CALL async() throw(::com::sun::star::uno::RuntimeException); 247 248 virtual void SAL_CALL sync() throw(::com::sun::star::uno::RuntimeException) 249 {} 250 virtual ComplexTypes SAL_CALL complex_in( const ::com::sun::star::test::performance::ComplexTypes& aVal ) throw(::com::sun::star::uno::RuntimeException) 251 { return aVal; } 252 virtual ComplexTypes SAL_CALL complex_inout( ::com::sun::star::test::performance::ComplexTypes& aVal ) throw(::com::sun::star::uno::RuntimeException) 253 { return aVal; } 254 virtual void SAL_CALL complex_oneway( const ::com::sun::star::test::performance::ComplexTypes& /* aVal */) throw(::com::sun::star::uno::RuntimeException) 255 {} 256 virtual void SAL_CALL complex_noreturn( const ::com::sun::star::test::performance::ComplexTypes& /* aVal */) throw(::com::sun::star::uno::RuntimeException) 257 {} 258 virtual Reference< XPerformanceTest > SAL_CALL createObject() throw(::com::sun::star::uno::RuntimeException) 259 { return new ServiceImpl(); } 260 virtual void SAL_CALL raiseRuntimeException( ) throw(::com::sun::star::uno::RuntimeException) 261 { throw _aDummyRE; } 262 }; 263 264 265 void ServiceImpl::async() throw(::com::sun::star::uno::RuntimeException) 266 {} 267 268 // XServiceInfo 269 //__________________________________________________________________________________________________ 270 OUString ServiceImpl::getImplementationName() 271 throw (RuntimeException) 272 { 273 return OUString( ); 274 } 275 //__________________________________________________________________________________________________ 276 sal_Bool ServiceImpl::supportsService( const OUString & /* rServiceName */) 277 throw (RuntimeException) 278 { 279 return sal_False; 280 } 281 //__________________________________________________________________________________________________ 282 Sequence< OUString > ServiceImpl::getSupportedServiceNames() 283 throw (RuntimeException) 284 { 285 return Sequence< OUString > (); 286 } 287 288 /****************** 289 * OCallMe 290 * 291 *****************/ 292 293 Any OCallMe::queryInterface( const Type & aType ) throw ( RuntimeException ) 294 { 295 Any a = ::cppu::queryInterface( aType, 296 SAL_STATIC_CAST( XCallMe * , this ) ); 297 298 if( a.hasValue() ) 299 { 300 return a; 301 } 302 303 return OWeakObject::queryInterface( aType ); 304 } 305 306 void OCallMe::call( const ::rtl::OUString& s, sal_Int32 nToDo ) 307 throw( RuntimeException, ::test::TestBridgeException) 308 { 309 if( nToDo < 0 ) 310 { 311 throw TestBridgeException(); 312 } 313 314 OUString sDummy; 315 if( ! nToDo ) { 316 OString o = OUStringToOString( s,RTL_TEXTENCODING_ASCII_US); 317 printf( "%s\n" , o.pData->buffer ); 318 } 319 for( sal_Int32 i = 0 ; i < nToDo ; i ++ ) 320 { 321 sDummy += s; 322 } 323 } 324 325 void SAL_CALL OCallMe::drawLine( sal_Int32 /* x1 */, sal_Int32 /* y1 */, sal_Int32 /* x2 */, sal_Int32 /* y2 */) 326 throw(::com::sun::star::uno::RuntimeException) 327 { 328 // do nothings 329 } 330 331 void OCallMe::callOneway( const ::rtl::OUString& /* s */, sal_Int32 nToDo ) 332 throw(RuntimeException) 333 { 334 OUString sDummy; 335 m_nLastToDos = nToDo; 336 337 338 if( nToDo ) 339 { 340 printf( "+" ); 341 fflush( stdout ); 342 343 TimeValue val = { nToDo , 0 }; 344 osl_waitThread( &val ); 345 printf( "-\n" ); 346 } 347 348 } 349 350 ::test::TestTypes SAL_CALL OCallMe::transport( const ::test::TestTypes& types ) 351 throw(::com::sun::star::uno::RuntimeException) 352 { 353 return types; 354 } 355 356 ::rtl::OUString OCallMe::getsAttribute() throw(RuntimeException) 357 { 358 return m_sAttribute; 359 } 360 void OCallMe::setsAttribute( const ::rtl::OUString& _sattribute ) 361 throw(RuntimeException) 362 { 363 m_sAttribute = _sattribute; 364 } 365 void OCallMe::callAgain( const Reference< ::test::XCallMe >& callAgainArg, 366 sal_Int32 nToCall ) throw(RuntimeException) 367 { 368 ::osl::MutexGuard guard( m_mutex ); 369 if( nToCall %2 ) 370 { 371 printf( "Deadlocktest pong %" SAL_PRIdINT32 "\n", nToCall ); 372 } 373 else 374 { 375 printf( "Deadlocktest ping %" SAL_PRIdINT32 "\n", nToCall ); 376 } 377 if( nToCall ) 378 { 379 callAgainArg->callAgain( Reference< XCallMe > ( (XCallMe *) this ) , nToCall -1 ); 380 } 381 } 382 383 /******************** 384 * OInterfaceTest 385 * 386 *******************/ 387 Any OInterfaceTest::queryInterface( const Type & aType ) throw ( RuntimeException ) 388 { 389 Any a = ::cppu::queryInterface( aType, 390 SAL_STATIC_CAST( XInterfaceTest * , this ) ); 391 if( a.hasValue() ) 392 { 393 return a; 394 } 395 return OWeakObject::queryInterface( aType ); 396 } 397 398 399 void OInterfaceTest::setIn( 400 const Reference< ::test::XCallMe >& callback ) 401 throw(RuntimeException) 402 { 403 m_rCallMe = callback; 404 call(); 405 } 406 407 void OInterfaceTest::setInOut( Reference< ::test::XCallMe >& callback ) 408 throw(RuntimeException) 409 { 410 Reference< XCallMe > r = m_rCallMe; 411 m_rCallMe = callback; 412 callback = r; 413 call(); 414 } 415 416 417 void OInterfaceTest::getOut( Reference< ::test::XCallMe >& callback ) 418 throw(RuntimeException) 419 { 420 callback = m_rCallMe; 421 } 422 423 Reference< ::test::XCallMe > OInterfaceTest::get( ) 424 throw(RuntimeException) 425 { 426 call(); 427 return m_rCallMe; 428 } 429 430 void OInterfaceTest::call() 431 { 432 if( m_rCallMe.is() ) 433 { 434 m_rCallMe->call( OUString( RTL_CONSTASCII_USTRINGPARAM("This is my String during a callback!")) , 5); 435 } 436 } 437 438 439 Any OTestFactory::queryInterface( const Type & aType ) throw ( RuntimeException ) 440 { 441 Any a = ::cppu::queryInterface( aType, 442 SAL_STATIC_CAST( XTestFactory * , this ) ); 443 444 if( a.hasValue() ) 445 { 446 return a; 447 } 448 449 return OWeakObject::queryInterface( aType ); 450 } 451 452 Reference< ::test::XCallMe > OTestFactory::createCallMe( ) 453 throw(RuntimeException) 454 { 455 return Reference< XCallMe > ( (XCallMe * ) new OCallMe() ); 456 } 457 458 Reference< ::test::XInterfaceTest > SAL_CALL OTestFactory::createInterfaceTest( ) 459 throw(RuntimeException) 460 { 461 return Reference < XInterfaceTest > ( (XInterfaceTest * ) new OInterfaceTest() ); 462 } 463 464 465 466 467 // class OInstanceProvider : 468 // public ::cppu::OWeakObject, 469 // public XInstanceProvider 470 // { 471 // public: 472 // OInstanceProvider( ){} 473 // ~OInstanceProvider(){ printf( "instance provider dies\n" );} 474 // public: 475 // // XInterface 476 // Any SAL_CALL queryInterface( const Type & aType); 477 // void SAL_CALL acquire() { OWeakObject::acquire(); } 478 // void SAL_CALL release() { OWeakObject::release(); } 479 480 // public: 481 // virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL 482 // getInstance( const ::rtl::OUString& sObjectName ) 483 // throw( ::com::sun::star::container::NoSuchElementException, 484 // ::com::sun::star::uno::RuntimeException); 485 // }; 486 487 488 489 490 491 492 493 494 double getCallsPerSec( const Reference < XCallMe > &rCall , int nLoops, int nToDo ) 495 { 496 TimeValue aStartTime, aEndTime; 497 osl_getSystemTime( &aStartTime ); 498 for( sal_Int32 i = 0; i < nLoops; i ++ ) 499 { 500 rCall->call( OUString( RTL_CONSTASCII_USTRINGPARAM("Performance test string")) , nToDo ); 501 } 502 osl_getSystemTime( &aEndTime ); 503 504 double fStart = (double)aStartTime.Seconds + ((double)aStartTime.Nanosec / 1000000000.0); 505 double fEnd = (double)aEndTime.Seconds + ((double)aEndTime.Nanosec / 1000000000.0); 506 return fEnd-fStart; 507 } 508 509 double getCallsPerSecOneway( const Reference < XCallMe > &rCall , 510 int nLoops, 511 int nToDo, 512 double *pdAfterExecution 513 ) 514 { 515 TimeValue aStartTime, aEndTime, aAfterExecution; 516 osl_getSystemTime( &aStartTime ); 517 for( sal_Int32 i = 0; i < nLoops; i ++ ) 518 { 519 // rCall->callOneway( OUString( RTL_CONSTASCII_USTRINGPARAM("Performance test string" )), 0 ); 520 rCall->drawLine( 0 , 0 , 500 , 123 ); 521 } 522 osl_getSystemTime( &aEndTime ); 523 524 rCall->call( OUString( RTL_CONSTASCII_USTRINGPARAM("Performance test string")) , nToDo ); 525 osl_getSystemTime( &aAfterExecution ); 526 527 double fStart = (double)aStartTime.Seconds + ((double)aStartTime.Nanosec / 1000000000.0); 528 double fEnd = (double)aEndTime.Seconds + ((double)aEndTime.Nanosec / 1000000000.0); 529 *pdAfterExecution = (double)aAfterExecution.Seconds + 530 ((double)aAfterExecution.Nanosec / 1000000000.0) - fStart; 531 return fEnd-fStart; 532 } 533 534 void testOnewayPerformanceOnTwoInterfaces( 535 const Reference < XCallMe > &rRemote1, const Reference < XCallMe > &rRemote2 ) 536 { 537 printf( "Doing oneway performance test on two interfaces ...\n" ); 538 const sal_Int32 nLoops = 10000; 539 TimeValue aStartTime, aEndTime; 540 osl_getSystemTime( &aStartTime ); 541 for( sal_Int32 i = 0; i < nLoops ; i ++ ) 542 { 543 rRemote1->drawLine( 0 , 0 , 500 , 123 ); 544 rRemote2->drawLine( 0 , 0 , 500 , 123 ); 545 } 546 osl_getSystemTime( &aEndTime ); 547 double fStart = (double)aStartTime.Seconds + ((double)aStartTime.Nanosec / 1000000000.0); 548 double fEnd = (double)aEndTime.Seconds + ((double)aEndTime.Nanosec / 1000000000.0); 549 550 printf( "Overhead per Call [ms] %g\n" , ((fEnd-fStart)/((double)nLoops/1000 ))/2. ); 551 } 552 553 void testPerformance( const Reference < XCallMe > &rRemote, 554 const Reference < XCallMe > &rLocal ) 555 { 556 OUString aTestString; 557 558 sal_Int32 nDoSomething = 1; 559 sal_Int32 nCalls = 80000; 560 double dRemote, dLocal,dAfterExecution; 561 562 printf( "performance test oneway...\n" ); 563 dLocal = getCallsPerSecOneway( rLocal , nCalls , nDoSomething , &dAfterExecution); 564 dRemote = getCallsPerSecOneway( rRemote , nCalls , nDoSomething , &dAfterExecution); 565 printf( "Local=%g s," 566 "Remote : %g s\n" , dLocal, dRemote ); 567 if( dLocal > 0. ) 568 { 569 printf( "Remote/Local : %g\n", dRemote/dLocal ); 570 } 571 572 printf( "Overhead per Call [ms] %g\n" , (dRemote - dLocal)/((double)nCalls/1000 ) ); 573 printf( "Overhead per Call after completion [ms] %g\n" , (dAfterExecution - dLocal)/((double)nCalls/1000 ) ); 574 575 nCalls = 2000; 576 577 printf( "Doing performance test ...\n" ); 578 dRemote = getCallsPerSec( rRemote , nCalls , nDoSomething ); 579 dLocal = getCallsPerSec( rLocal , nCalls , nDoSomething ); 580 printf( "Local=%g s,\n" 581 "Remote=%g s\n" , dLocal, dRemote ); 582 if( dLocal > 0. ) 583 { 584 printf( "Remote/Local : %g\n", dRemote/dLocal ); 585 } 586 printf( "Overhead per synchron Call [ms] %g\n" , ((dRemote - dLocal)/((double)nCalls/1000 )) ); 587 } 588 589 void testException( const Reference < XCallMe > &r ) 590 { 591 try { 592 r->call( OUString( RTL_CONSTASCII_USTRINGPARAM("dummy")) , -1 ); 593 OSL_ASSERT( ! "no exception flown !" ); 594 } 595 catch( TestBridgeException & e ) 596 { 597 // Exception flew successfully ! 598 } 599 catch( Exception & e ) 600 { 601 OSL_ASSERT( ! "only base class of exception could be catched!" ); 602 } 603 catch(...) 604 { 605 OSL_ASSERT(! "wrong unknown exception !" ); 606 } 607 } 608 609 void testSequenceOfCalls( const Reference< XCallMe > & rRCallMe ) 610 { 611 printf( "Testing sequence of calls\n" ); 612 for( sal_Int32 i = 0 ; i < 800 ; i ++ ) 613 { 614 rRCallMe->callOneway( OUString( RTL_CONSTASCII_USTRINGPARAM("hifuj" )), 0 ); 615 } 616 } 617 618 void testAllTypes( const Reference < XCallMe > & rRCallMe ) 619 { 620 printf( "Testing all types\n" ); 621 622 for( sal_Int32 i = 0; i < 32 ; i ++ ) 623 { 624 625 TestTypes types; 626 types.Bool = sal_True; 627 types.Char = L'i'; 628 types.Byte = -12; 629 types.Short = -32000; 630 types.UShort = (sal_uInt16 ) (1 << i); 631 types.Long = -123; 632 types.ULong = 1 << i; 633 types.Hyper = 50; 634 types.UHyper = 1 << i*2; 635 types.Float = (float)123.239; 636 types.Double = 1279.12490012; 637 types.String = OUString( RTL_CONSTASCII_USTRINGPARAM("abcdefghijklmnopqrstuvwxyz")); 638 types.Interface = Reference< XInterface >( rRCallMe , UNO_QUERY); 639 types.Any <<= types.Double; 640 641 TestTypes retTypes = rRCallMe->transport( types ); 642 643 OSL_ASSERT( ( types.Bool && retTypes.Bool ) || ( ! types.Bool && ! retTypes.Bool ) ); 644 OSL_ASSERT( types.Char == retTypes.Char ); 645 OSL_ASSERT( types.Byte == retTypes.Byte ); 646 OSL_ASSERT( types.Short == retTypes.Short ); 647 OSL_ASSERT( types.UShort == retTypes.UShort ); 648 OSL_ASSERT( types.Long == retTypes.Long ); 649 OSL_ASSERT( types.ULong == retTypes.ULong ); 650 OSL_ASSERT( types.Hyper == retTypes.Hyper ); 651 OSL_ASSERT( types.UHyper == retTypes.UHyper ); 652 OSL_ASSERT( types.Float == retTypes.Float ); 653 OSL_ASSERT( types.Double == retTypes.Double ); 654 OSL_ASSERT( types.String == retTypes.String ); 655 OSL_ASSERT( types.Interface == retTypes.Interface ); 656 OSL_ASSERT( types.Any == retTypes.Any ); 657 } 658 659 } 660 661 void testRemote( const Reference< XInterface > &rRemote ) 662 { 663 char a; 664 getCppuType( (sal_Int8*)&a ); 665 666 Reference< XTestFactory > rRFact( rRemote , UNO_QUERY ); 667 if( ! rRFact.is() ) 668 { 669 printf( "remote object doesn't support XTestFactory\n" ); 670 return; 671 } 672 OSL_ASSERT( rRFact.is() ); 673 Reference< XCallMe > rLCallMe = (XCallMe * ) new OCallMe(); 674 Reference< XCallMe > rRCallMe = rRFact->createCallMe(); 675 676 testAllTypes( rLCallMe ); 677 testAllTypes( rRCallMe ); 678 679 printf( "Testing exception local ...\n" ); 680 testException( rLCallMe ); 681 printf( "Testing exception remote ...\n" ); 682 testException( rRCallMe ); 683 684 //-------------------- 685 // Test attributes 686 //---------------------- 687 OUString ow = OUString::createFromAscii( "dum didel dum dideldei" ); 688 rLCallMe->setsAttribute( ow ); 689 OSL_ASSERT( rLCallMe->getsAttribute() == ow ); 690 691 rRCallMe->setsAttribute( ow ); 692 OSL_ASSERT( rRCallMe->getsAttribute() == ow ); 693 694 //------------------- 695 // Performance test 696 //------------------- 697 testPerformance( rRCallMe , rLCallMe ); 698 testOnewayPerformanceOnTwoInterfaces( rRFact->createCallMe(), rRCallMe ); 699 700 //---------------- 701 // Test sequence 702 //---------------- 703 testSequenceOfCalls( rRCallMe ); 704 705 706 // test triple to check if transporting the same interface multiple 707 // times causes any problems 708 Reference< XInterfaceTest > rRTest = rRFact->createInterfaceTest(); 709 Reference< XInterfaceTest > rRTest2 = rRFact->createInterfaceTest(); 710 Reference< XInterfaceTest > rRTest3 = rRFact->createInterfaceTest(); 711 712 rRTest->setIn( rRCallMe ); 713 rRTest2->setIn( rRCallMe ); 714 rRTest3->setIn( rRCallMe ); 715 716 OSL_ASSERT( rRTest->get() == rRCallMe ); 717 OSL_ASSERT( rRTest2->get() == rRCallMe ); 718 OSL_ASSERT( rRTest3->get() == rRCallMe ); 719 720 rRTest->setIn( rLCallMe ); 721 rRTest2->setIn( rLCallMe ); 722 rRTest3->setIn( rLCallMe ); 723 724 { 725 Reference< XCallMe > rLCallMe1 = (XCallMe * ) new OCallMe(); 726 Reference< XCallMe > rLCallMe2 = (XCallMe * ) new OCallMe(); 727 Reference< XCallMe > rLCallMe3 = (XCallMe * ) new OCallMe(); 728 rRTest->setIn( rLCallMe1 ); 729 rRTest2->setIn( rLCallMe2 ); 730 rRTest3->setIn( rLCallMe3 ); 731 OSL_ASSERT( rRTest->get() == rLCallMe1 ); 732 OSL_ASSERT( rRTest2->get() == rLCallMe2 ); 733 OSL_ASSERT( rRTest3->get() == rLCallMe3 ); 734 735 rRTest->setIn( rLCallMe ); 736 rRTest2->setIn( rLCallMe ); 737 rRTest3->setIn( rLCallMe ); 738 739 OSL_ASSERT( rRTest->get() == rLCallMe ); 740 OSL_ASSERT( rRTest2->get() == rLCallMe ); 741 OSL_ASSERT( rRTest3->get() == rLCallMe ); 742 } 743 744 Reference < XCallMe > r = rRCallMe; 745 rRTest->setInOut( r ); 746 OSL_ASSERT( r == rLCallMe ); 747 OSL_ASSERT( ! ( r == rRCallMe ) ); 748 749 // test empty references 750 rRTest->setIn( Reference < XCallMe > () ); 751 752 //-------------------------------- 753 // test thread deadlocking 754 //-------------------------------- 755 rLCallMe->callAgain( rRCallMe, 20 ); 756 757 } 758 759 760 761 762 763 764 Reference <XInterface > createComponent( const ::rtl::OUString &sService , 765 const ::rtl::OUString &sDllName, 766 const Reference < XMultiServiceFactory > &rSMgr ) 767 { 768 Reference< XInterface > rInterface; 769 rInterface = rSMgr->createInstance( sService ); 770 771 if( ! rInterface.is() ) 772 { 773 // erst registrieren 774 Reference < XImplementationRegistration > rReg ( 775 rSMgr->createInstance( 776 OUString::createFromAscii( "com.sun.star.registry.ImplementationRegistration" )), 777 UNO_QUERY ); 778 779 OSL_ASSERT( rReg.is() ); 780 OUString aDllName = sDllName; 781 782 try 783 { 784 rReg->registerImplementation( 785 OUString::createFromAscii( "com.sun.star.loader.SharedLibrary" ), 786 aDllName, 787 Reference< XSimpleRegistry > () ); 788 rInterface = rSMgr->createInstance( sService ); 789 } 790 catch( Exception & ) 791 { 792 printf( "couldn't register dll %s\n" , 793 OUStringToOString( aDllName, RTL_TEXTENCODING_ASCII_US ).getStr() ); 794 } 795 } 796 return rInterface; 797 } 798 799 800