bump product version to 4.1.6.2
[LibreOffice.git] / bridges / test / testcomp.cxx
blob2ccda76c5c26257911ac3ccf3a3038383d702e18
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 .
20 #include <string.h>
21 #include <stdlib.h>
22 #include <osl/time.h>
24 #include <uno/threadpool.h>
26 #include <osl/mutex.hxx>
27 #include <osl/diagnose.h>
29 #include <test/XTestFactory.hpp>
30 #include <cppuhelper/servicefactory.hxx>
32 #include <com/sun/star/bridge/XInstanceProvider.hpp>
34 #include <com/sun/star/registry/XImplementationRegistration.hpp>
36 #include <com/sun/star/test/performance/XPerformanceTest.hpp>
37 #include <com/sun/star/lang/XServiceInfo.hpp>
39 #include <cppuhelper/weak.hxx>
41 using namespace ::test;
42 using namespace ::com::sun::star::uno;
43 using namespace ::com::sun::star::bridge;
44 using namespace ::com::sun::star::lang;
45 using namespace ::com::sun::star::registry;
46 using namespace ::com::sun::star::test::performance;
48 #include "testcomp.h"
51 void parseCommandLine( char *argv[] ,
52 OUString *pConnection , OUString *pProtocol ,
53 sal_Bool *pbLatency , sal_Bool *pbReverse)
55 sal_Int32 nArgIndex = 1;
56 if( ! strcmp( argv[1] , "-r" ) )
58 nArgIndex = 2;
59 *pbReverse = sal_True;
61 else if( ! strcmp( argv[1] , "-latency" ) )
63 *pbLatency = sal_True;
64 nArgIndex = 2;
67 OUString sTemp = OUString::createFromAscii( argv[nArgIndex] );
68 sal_Int32 nIndex = sTemp.indexOf( ';' );
69 if( -1 == nIndex )
71 *pConnection = sTemp;
72 *pProtocol = OUString( "iiop" );
74 else
76 *pConnection = sTemp.copy( 0 , nIndex );
77 *pProtocol = sTemp.copy( nIndex+1, sTemp.getLength() - (nIndex+1) );
81 Any OInstanceProvider::queryInterface( const Type & aType ) throw ( RuntimeException )
83 Any a = ::cppu::queryInterface( aType ,
84 (static_cast< XInstanceProvider * >(this)) );
85 if( a.hasValue() )
87 return a;
89 return OWeakObject::queryInterface( aType );
92 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >
93 OInstanceProvider::getInstance( const OUString& sObjectName )
94 throw(::com::sun::star::container::NoSuchElementException,
95 ::com::sun::star::uno::RuntimeException)
97 // Tries to get the PerformanceTestObject
98 if( sObjectName == OUString( "TestRemoteObject" ) )
100 return m_rSMgr->createInstance(
101 OUString("com.sun.star.test.performance.PerformanceTestObject") );
103 return Reference < XInterface > ( (::cppu::OWeakObject * ) new OTestFactory() );
106 class ServiceImpl
107 : public XServiceInfo
108 , public XPerformanceTest
110 OUString _aDummyString;
111 Any _aDummyAny;
112 Sequence< Reference< XInterface > > _aDummySequence;
113 ComplexTypes _aDummyStruct;
114 RuntimeException _aDummyRE;
116 sal_Int32 _nRef;
118 public:
119 ServiceImpl()
120 : _nRef( 0 )
122 ServiceImpl( const Reference< XMultiServiceFactory > & /* xMgr */)
123 : _nRef( 0 )
126 // XInterface
127 virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type& aType ) throw(::com::sun::star::uno::RuntimeException)
129 // execution time remains appr. constant any time
130 Any aRet;
131 if (aType == ::getCppuType( (const Reference< XInterface > *)0 ))
133 void * p = (XInterface *)(XPerformanceTest *)this;
134 aRet.setValue( &p, ::getCppuType( (const Reference< XInterface > *)0 ) );
136 if (aType == ::getCppuType( (const Reference< XPerformanceTest > *)0 ))
138 void * p = (XPerformanceTest *)this;
139 aRet.setValue( &p, ::getCppuType( (const Reference< XPerformanceTest > *)0 ) );
141 if (! aRet.hasValue())
143 void * p = (XPerformanceTest *)this;
144 Any aDummy( &p, ::getCppuType( (const Reference< XPerformanceTest > *)0 ) );
146 return aRet;
148 virtual void SAL_CALL acquire() throw()
149 { osl_atomic_increment( &_nRef ); }
150 virtual void SAL_CALL release() throw()
151 { if (! osl_atomic_decrement( &_nRef )) delete this; }
153 // XServiceInfo
154 virtual OUString SAL_CALL getImplementationName() throw (RuntimeException);
155 virtual sal_Bool SAL_CALL supportsService( const OUString & rServiceName ) throw (RuntimeException);
156 virtual Sequence< OUString > SAL_CALL getSupportedServiceNames() throw (RuntimeException);
158 // Attributes
159 virtual sal_Int32 SAL_CALL getLong_attr() throw(::com::sun::star::uno::RuntimeException)
160 { return 0; }
161 virtual void SAL_CALL setLong_attr( sal_Int32 /* _attributelong */) throw(::com::sun::star::uno::RuntimeException)
163 virtual sal_Int64 SAL_CALL getHyper_attr() throw(::com::sun::star::uno::RuntimeException)
164 { return 0; }
165 virtual void SAL_CALL setHyper_attr( sal_Int64 /* _attributehyper */) throw(::com::sun::star::uno::RuntimeException)
167 virtual float SAL_CALL getFloat_attr() throw(::com::sun::star::uno::RuntimeException)
168 { return 0.0; }
169 virtual void SAL_CALL setFloat_attr( float /* _attributefloat */) throw(::com::sun::star::uno::RuntimeException)
171 virtual double SAL_CALL getDouble_attr() throw(::com::sun::star::uno::RuntimeException)
172 { return 0.0; }
173 virtual void SAL_CALL setDouble_attr( double /* _attributedouble */) throw(::com::sun::star::uno::RuntimeException)
175 virtual OUString SAL_CALL getString_attr() throw(::com::sun::star::uno::RuntimeException)
176 { return _aDummyString; }
177 virtual void SAL_CALL setString_attr( const OUString& /* _attributestring */) throw(::com::sun::star::uno::RuntimeException)
179 virtual Reference< XInterface > SAL_CALL getInterface_attr() throw(::com::sun::star::uno::RuntimeException)
180 { return Reference< XInterface >(); }
181 virtual void SAL_CALL setInterface_attr( const Reference< XInterface >& /* _attributeinterface */) throw(::com::sun::star::uno::RuntimeException)
183 virtual Any SAL_CALL getAny_attr() throw(::com::sun::star::uno::RuntimeException)
184 { return _aDummyAny; }
185 virtual void SAL_CALL setAny_attr( const Any& /* _attributeany */) throw(::com::sun::star::uno::RuntimeException)
187 virtual Sequence< Reference< XInterface > > SAL_CALL getSequence_attr() throw(::com::sun::star::uno::RuntimeException)
188 { return _aDummySequence; }
189 virtual void SAL_CALL setSequence_attr( const Sequence< Reference< XInterface > >& /* _attributesequence */) throw(::com::sun::star::uno::RuntimeException)
191 virtual ComplexTypes SAL_CALL getStruct_attr() throw(::com::sun::star::uno::RuntimeException)
192 { return _aDummyStruct; }
193 virtual void SAL_CALL setStruct_attr( const ::com::sun::star::test::performance::ComplexTypes& /* _attributestruct */) throw(::com::sun::star::uno::RuntimeException)
196 // Methods
197 virtual sal_Int32 SAL_CALL getLong() throw(::com::sun::star::uno::RuntimeException)
198 { return 0; }
199 virtual void SAL_CALL setLong( sal_Int32 /* _long */) throw(::com::sun::star::uno::RuntimeException)
201 virtual sal_Int64 SAL_CALL getHyper() throw(::com::sun::star::uno::RuntimeException)
202 { return 0; }
203 virtual void SAL_CALL setHyper( sal_Int64 /* _hyper */) throw(::com::sun::star::uno::RuntimeException)
205 virtual float SAL_CALL getFloat() throw(::com::sun::star::uno::RuntimeException)
206 { return 0; }
207 virtual void SAL_CALL setFloat( float /* _float */) throw(::com::sun::star::uno::RuntimeException)
209 virtual double SAL_CALL getDouble() throw(::com::sun::star::uno::RuntimeException)
210 { return 0; }
211 virtual void SAL_CALL setDouble( double /* _double */) throw(::com::sun::star::uno::RuntimeException)
213 virtual OUString SAL_CALL getString() throw(::com::sun::star::uno::RuntimeException)
214 { return _aDummyString; }
215 virtual void SAL_CALL setString( const OUString& /* _string */) throw(::com::sun::star::uno::RuntimeException)
217 virtual Reference< XInterface > SAL_CALL getInterface() throw(::com::sun::star::uno::RuntimeException)
218 { return Reference< XInterface >(); }
219 virtual void SAL_CALL setInterface( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& /* _interface */) throw(::com::sun::star::uno::RuntimeException)
221 virtual Any SAL_CALL getAny() throw(::com::sun::star::uno::RuntimeException)
222 { return _aDummyAny; }
223 virtual void SAL_CALL setAny( const ::com::sun::star::uno::Any& /* _any */) throw(::com::sun::star::uno::RuntimeException)
225 virtual Sequence< Reference< XInterface > > SAL_CALL getSequence() throw(::com::sun::star::uno::RuntimeException)
226 { return _aDummySequence; }
227 virtual void SAL_CALL setSequence( const Sequence< Reference< XInterface > >& /*_sequence */) throw(::com::sun::star::uno::RuntimeException)
229 virtual ComplexTypes SAL_CALL getStruct() throw(::com::sun::star::uno::RuntimeException)
230 { return _aDummyStruct; }
231 virtual void SAL_CALL setStruct( const ::com::sun::star::test::performance::ComplexTypes& /* c */) throw(::com::sun::star::uno::RuntimeException)
234 virtual void SAL_CALL async() throw(::com::sun::star::uno::RuntimeException);
236 virtual void SAL_CALL sync() throw(::com::sun::star::uno::RuntimeException)
238 virtual ComplexTypes SAL_CALL complex_in( const ::com::sun::star::test::performance::ComplexTypes& aVal ) throw(::com::sun::star::uno::RuntimeException)
239 { return aVal; }
240 virtual ComplexTypes SAL_CALL complex_inout( ::com::sun::star::test::performance::ComplexTypes& aVal ) throw(::com::sun::star::uno::RuntimeException)
241 { return aVal; }
242 virtual void SAL_CALL complex_oneway( const ::com::sun::star::test::performance::ComplexTypes& /* aVal */) throw(::com::sun::star::uno::RuntimeException)
244 virtual void SAL_CALL complex_noreturn( const ::com::sun::star::test::performance::ComplexTypes& /* aVal */) throw(::com::sun::star::uno::RuntimeException)
246 virtual Reference< XPerformanceTest > SAL_CALL createObject() throw(::com::sun::star::uno::RuntimeException)
247 { return new ServiceImpl(); }
248 virtual void SAL_CALL raiseRuntimeException( ) throw(::com::sun::star::uno::RuntimeException)
249 { throw _aDummyRE; }
253 void ServiceImpl::async() throw(::com::sun::star::uno::RuntimeException)
256 // XServiceInfo
257 //__________________________________________________________________________________________________
258 OUString ServiceImpl::getImplementationName()
259 throw (RuntimeException)
261 return OUString( );
263 //__________________________________________________________________________________________________
264 sal_Bool ServiceImpl::supportsService( const OUString & /* rServiceName */)
265 throw (RuntimeException)
267 return sal_False;
269 //__________________________________________________________________________________________________
270 Sequence< OUString > ServiceImpl::getSupportedServiceNames()
271 throw (RuntimeException)
273 return Sequence< OUString > ();
276 /******************
277 * OCallMe
279 *****************/
281 Any OCallMe::queryInterface( const Type & aType ) throw ( RuntimeException )
283 Any a = ::cppu::queryInterface( aType,
284 (static_cast< XCallMe * >(this)) );
286 if( a.hasValue() )
288 return a;
291 return OWeakObject::queryInterface( aType );
294 void OCallMe::call( const OUString& s, sal_Int32 nToDo )
295 throw( RuntimeException, ::test::TestBridgeException)
297 if( nToDo < 0 )
299 throw TestBridgeException();
302 OUString sDummy;
303 if( ! nToDo ) {
304 OString o = OUStringToOString( s,RTL_TEXTENCODING_ASCII_US);
305 printf( "%s\n" , o.pData->buffer );
307 for( sal_Int32 i = 0 ; i < nToDo ; i ++ )
309 sDummy += s;
313 void SAL_CALL OCallMe::drawLine( sal_Int32 /* x1 */, sal_Int32 /* y1 */, sal_Int32 /* x2 */, sal_Int32 /* y2 */)
314 throw(::com::sun::star::uno::RuntimeException)
316 // do nothings
319 void OCallMe::callOneway( const OUString& /* s */, sal_Int32 nToDo )
320 throw(RuntimeException)
322 OUString sDummy;
323 m_nLastToDos = nToDo;
326 if( nToDo )
328 printf( "+" );
329 fflush( stdout );
331 TimeValue val = { nToDo , 0 };
332 osl_waitThread( &val );
333 printf( "-\n" );
338 ::test::TestTypes SAL_CALL OCallMe::transport( const ::test::TestTypes& types )
339 throw(::com::sun::star::uno::RuntimeException)
341 return types;
344 OUString OCallMe::getsAttribute() throw(RuntimeException)
346 return m_sAttribute;
348 void OCallMe::setsAttribute( const OUString& _sattribute )
349 throw(RuntimeException)
351 m_sAttribute = _sattribute;
353 void OCallMe::callAgain( const Reference< ::test::XCallMe >& callAgainArg,
354 sal_Int32 nToCall ) throw(RuntimeException)
356 ::osl::MutexGuard guard( m_mutex );
357 if( nToCall %2 )
359 printf( "Deadlocktest pong %" SAL_PRIdINT32 "\n", nToCall );
361 else
363 printf( "Deadlocktest ping %" SAL_PRIdINT32 "\n", nToCall );
365 if( nToCall )
367 callAgainArg->callAgain( Reference< XCallMe > ( (XCallMe *) this ) , nToCall -1 );
371 /********************
372 * OInterfaceTest
374 *******************/
375 Any OInterfaceTest::queryInterface( const Type & aType ) throw ( RuntimeException )
377 Any a = ::cppu::queryInterface( aType,
378 (static_cast< XInterfaceTest * >(this)) );
379 if( a.hasValue() )
381 return a;
383 return OWeakObject::queryInterface( aType );
387 void OInterfaceTest::setIn(
388 const Reference< ::test::XCallMe >& callback )
389 throw(RuntimeException)
391 m_rCallMe = callback;
392 call();
395 void OInterfaceTest::setInOut( Reference< ::test::XCallMe >& callback )
396 throw(RuntimeException)
398 Reference< XCallMe > r = m_rCallMe;
399 m_rCallMe = callback;
400 callback = r;
401 call();
405 void OInterfaceTest::getOut( Reference< ::test::XCallMe >& callback )
406 throw(RuntimeException)
408 callback = m_rCallMe;
411 Reference< ::test::XCallMe > OInterfaceTest::get( )
412 throw(RuntimeException)
414 call();
415 return m_rCallMe;
418 void OInterfaceTest::call()
420 if( m_rCallMe.is() )
422 m_rCallMe->call( OUString("This is my String during a callback!") , 5);
427 Any OTestFactory::queryInterface( const Type & aType ) throw ( RuntimeException )
429 Any a = ::cppu::queryInterface( aType,
430 (static_cast< XTestFactory * >(this)) );
432 if( a.hasValue() )
434 return a;
437 return OWeakObject::queryInterface( aType );
440 Reference< ::test::XCallMe > OTestFactory::createCallMe( )
441 throw(RuntimeException)
443 return Reference< XCallMe > ( (XCallMe * ) new OCallMe() );
446 Reference< ::test::XInterfaceTest > SAL_CALL OTestFactory::createInterfaceTest( )
447 throw(RuntimeException)
449 return Reference < XInterfaceTest > ( (XInterfaceTest * ) new OInterfaceTest() );
455 // class OInstanceProvider :
456 // public ::cppu::OWeakObject,
457 // public XInstanceProvider
458 // {
459 // public:
460 // OInstanceProvider( ){}
461 // ~OInstanceProvider(){ printf( "instance provider dies\n" );}
462 // public:
463 // // XInterface
464 // Any SAL_CALL queryInterface( const Type & aType);
465 // void SAL_CALL acquire() { OWeakObject::acquire(); }
466 // void SAL_CALL release() { OWeakObject::release(); }
468 // public:
469 // virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL
470 // getInstance( const OUString& sObjectName )
471 // throw( ::com::sun::star::container::NoSuchElementException,
472 // ::com::sun::star::uno::RuntimeException);
473 // };
482 double getCallsPerSec( const Reference < XCallMe > &rCall , int nLoops, int nToDo )
484 TimeValue aStartTime, aEndTime;
485 osl_getSystemTime( &aStartTime );
486 for( sal_Int32 i = 0; i < nLoops; i ++ )
488 rCall->call( OUString("Performance test string") , nToDo );
490 osl_getSystemTime( &aEndTime );
492 double fStart = (double)aStartTime.Seconds + ((double)aStartTime.Nanosec / 1000000000.0);
493 double fEnd = (double)aEndTime.Seconds + ((double)aEndTime.Nanosec / 1000000000.0);
494 return fEnd-fStart;
497 double getCallsPerSecOneway( const Reference < XCallMe > &rCall ,
498 int nLoops,
499 int nToDo,
500 double *pdAfterExecution
503 TimeValue aStartTime, aEndTime, aAfterExecution;
504 osl_getSystemTime( &aStartTime );
505 for( sal_Int32 i = 0; i < nLoops; i ++ )
507 // rCall->callOneway( OUString("Performance test string" ), 0 );
508 rCall->drawLine( 0 , 0 , 500 , 123 );
510 osl_getSystemTime( &aEndTime );
512 rCall->call( OUString("Performance test string") , nToDo );
513 osl_getSystemTime( &aAfterExecution );
515 double fStart = (double)aStartTime.Seconds + ((double)aStartTime.Nanosec / 1000000000.0);
516 double fEnd = (double)aEndTime.Seconds + ((double)aEndTime.Nanosec / 1000000000.0);
517 *pdAfterExecution = (double)aAfterExecution.Seconds +
518 ((double)aAfterExecution.Nanosec / 1000000000.0) - fStart;
519 return fEnd-fStart;
522 void testOnewayPerformanceOnTwoInterfaces(
523 const Reference < XCallMe > &rRemote1, const Reference < XCallMe > &rRemote2 )
525 printf( "Doing oneway performance test on two interfaces ...\n" );
526 const sal_Int32 nLoops = 10000;
527 TimeValue aStartTime, aEndTime;
528 osl_getSystemTime( &aStartTime );
529 for( sal_Int32 i = 0; i < nLoops ; i ++ )
531 rRemote1->drawLine( 0 , 0 , 500 , 123 );
532 rRemote2->drawLine( 0 , 0 , 500 , 123 );
534 osl_getSystemTime( &aEndTime );
535 double fStart = (double)aStartTime.Seconds + ((double)aStartTime.Nanosec / 1000000000.0);
536 double fEnd = (double)aEndTime.Seconds + ((double)aEndTime.Nanosec / 1000000000.0);
538 printf( "Overhead per Call [ms] %g\n" , ((fEnd-fStart)/((double)nLoops/1000 ))/2. );
541 void testPerformance( const Reference < XCallMe > &rRemote,
542 const Reference < XCallMe > &rLocal )
544 sal_Int32 nDoSomething = 1;
545 sal_Int32 nCalls = 80000;
546 double dRemote, dLocal,dAfterExecution;
548 printf( "performance test oneway...\n" );
549 dLocal = getCallsPerSecOneway( rLocal , nCalls , nDoSomething , &dAfterExecution);
550 dRemote = getCallsPerSecOneway( rRemote , nCalls , nDoSomething , &dAfterExecution);
551 printf( "Local=%g s,"
552 "Remote : %g s\n" , dLocal, dRemote );
553 if( dLocal > 0. )
555 printf( "Remote/Local : %g\n", dRemote/dLocal );
558 printf( "Overhead per Call [ms] %g\n" , (dRemote - dLocal)/((double)nCalls/1000 ) );
559 printf( "Overhead per Call after completion [ms] %g\n" , (dAfterExecution - dLocal)/((double)nCalls/1000 ) );
561 nCalls = 2000;
563 printf( "Doing performance test ...\n" );
564 dRemote = getCallsPerSec( rRemote , nCalls , nDoSomething );
565 dLocal = getCallsPerSec( rLocal , nCalls , nDoSomething );
566 printf( "Local=%g s,\n"
567 "Remote=%g s\n" , dLocal, dRemote );
568 if( dLocal > 0. )
570 printf( "Remote/Local : %g\n", dRemote/dLocal );
572 printf( "Overhead per synchron Call [ms] %g\n" , ((dRemote - dLocal)/((double)nCalls/1000 )) );
575 void testException( const Reference < XCallMe > &r )
577 try {
578 r->call( OUString("dummy") , -1 );
579 OSL_ASSERT( ! "no exception flown !" );
581 catch( TestBridgeException & e )
583 // Exception flew successfully !
585 catch( Exception & e )
587 OSL_ASSERT( ! "only base class of exception could be catched!" );
589 catch(...)
591 OSL_ASSERT(! "wrong unknown exception !" );
595 void testSequenceOfCalls( const Reference< XCallMe > & rRCallMe )
597 printf( "Testing sequence of calls\n" );
598 for( sal_Int32 i = 0 ; i < 800 ; i ++ )
600 rRCallMe->callOneway( OUString("hifuj" ), 0 );
604 void testAllTypes( const Reference < XCallMe > & rRCallMe )
606 printf( "Testing all types\n" );
608 for( sal_Int32 i = 0; i < 32 ; i ++ )
611 TestTypes types;
612 types.Bool = sal_True;
613 types.Char = L'i';
614 types.Byte = -12;
615 types.Short = -32000;
616 types.UShort = (sal_uInt16 ) (1 << i);
617 types.Long = -123;
618 types.ULong = 1 << i;
619 types.Hyper = 50;
620 types.UHyper = 1 << i*2;
621 types.Float = (float)123.239;
622 types.Double = 1279.12490012;
623 types.String = OUString("abcdefghijklmnopqrstuvwxyz");
624 types.Interface = Reference< XInterface >( rRCallMe , UNO_QUERY);
625 types.Any <<= types.Double;
627 TestTypes retTypes = rRCallMe->transport( types );
629 OSL_ASSERT( ( types.Bool && retTypes.Bool ) || ( ! types.Bool && ! retTypes.Bool ) );
630 OSL_ASSERT( types.Char == retTypes.Char );
631 OSL_ASSERT( types.Byte == retTypes.Byte );
632 OSL_ASSERT( types.Short == retTypes.Short );
633 OSL_ASSERT( types.UShort == retTypes.UShort );
634 OSL_ASSERT( types.Long == retTypes.Long );
635 OSL_ASSERT( types.ULong == retTypes.ULong );
636 OSL_ASSERT( types.Hyper == retTypes.Hyper );
637 OSL_ASSERT( types.UHyper == retTypes.UHyper );
638 OSL_ASSERT( types.Float == retTypes.Float );
639 OSL_ASSERT( types.Double == retTypes.Double );
640 OSL_ASSERT( types.String == retTypes.String );
641 OSL_ASSERT( types.Interface == retTypes.Interface );
642 OSL_ASSERT( types.Any == retTypes.Any );
647 void testRemote( const Reference< XInterface > &rRemote )
649 char a;
650 getCppuType( (sal_Int8*)&a );
652 Reference< XTestFactory > rRFact( rRemote , UNO_QUERY );
653 if( ! rRFact.is() )
655 printf( "remote object doesn't support XTestFactory\n" );
656 return;
658 OSL_ASSERT( rRFact.is() );
659 Reference< XCallMe > rLCallMe = (XCallMe * ) new OCallMe();
660 Reference< XCallMe > rRCallMe = rRFact->createCallMe();
662 testAllTypes( rLCallMe );
663 testAllTypes( rRCallMe );
665 printf( "Testing exception local ...\n" );
666 testException( rLCallMe );
667 printf( "Testing exception remote ...\n" );
668 testException( rRCallMe );
670 //--------------------
671 // Test attributes
672 //----------------------
673 OUString ow( "dum didel dum dideldei" );
674 rLCallMe->setsAttribute( ow );
675 OSL_ASSERT( rLCallMe->getsAttribute() == ow );
677 rRCallMe->setsAttribute( ow );
678 OSL_ASSERT( rRCallMe->getsAttribute() == ow );
680 //-------------------
681 // Performance test
682 //-------------------
683 testPerformance( rRCallMe , rLCallMe );
684 testOnewayPerformanceOnTwoInterfaces( rRFact->createCallMe(), rRCallMe );
686 //----------------
687 // Test sequence
688 //----------------
689 testSequenceOfCalls( rRCallMe );
692 // test triple to check if transporting the same interface multiple
693 // times causes any problems
694 Reference< XInterfaceTest > rRTest = rRFact->createInterfaceTest();
695 Reference< XInterfaceTest > rRTest2 = rRFact->createInterfaceTest();
696 Reference< XInterfaceTest > rRTest3 = rRFact->createInterfaceTest();
698 rRTest->setIn( rRCallMe );
699 rRTest2->setIn( rRCallMe );
700 rRTest3->setIn( rRCallMe );
702 OSL_ASSERT( rRTest->get() == rRCallMe );
703 OSL_ASSERT( rRTest2->get() == rRCallMe );
704 OSL_ASSERT( rRTest3->get() == rRCallMe );
706 rRTest->setIn( rLCallMe );
707 rRTest2->setIn( rLCallMe );
708 rRTest3->setIn( rLCallMe );
711 Reference< XCallMe > rLCallMe1 = (XCallMe * ) new OCallMe();
712 Reference< XCallMe > rLCallMe2 = (XCallMe * ) new OCallMe();
713 Reference< XCallMe > rLCallMe3 = (XCallMe * ) new OCallMe();
714 rRTest->setIn( rLCallMe1 );
715 rRTest2->setIn( rLCallMe2 );
716 rRTest3->setIn( rLCallMe3 );
717 OSL_ASSERT( rRTest->get() == rLCallMe1 );
718 OSL_ASSERT( rRTest2->get() == rLCallMe2 );
719 OSL_ASSERT( rRTest3->get() == rLCallMe3 );
721 rRTest->setIn( rLCallMe );
722 rRTest2->setIn( rLCallMe );
723 rRTest3->setIn( rLCallMe );
725 OSL_ASSERT( rRTest->get() == rLCallMe );
726 OSL_ASSERT( rRTest2->get() == rLCallMe );
727 OSL_ASSERT( rRTest3->get() == rLCallMe );
730 Reference < XCallMe > r = rRCallMe;
731 rRTest->setInOut( r );
732 OSL_ASSERT( r == rLCallMe );
733 OSL_ASSERT( ! ( r == rRCallMe ) );
735 // test empty references
736 rRTest->setIn( Reference < XCallMe > () );
738 //--------------------------------
739 // test thread deadlocking
740 //--------------------------------
741 rLCallMe->callAgain( rRCallMe, 20 );
750 Reference <XInterface > createComponent( const OUString &sService ,
751 const OUString &sDllName,
752 const Reference < XMultiServiceFactory > &rSMgr )
754 Reference< XInterface > rInterface;
755 rInterface = rSMgr->createInstance( sService );
757 if( ! rInterface.is() )
759 // erst registrieren
760 Reference < XImplementationRegistration > rReg (
761 rSMgr->createInstance(
762 OUString( "com.sun.star.registry.ImplementationRegistration" )),
763 UNO_QUERY );
765 OSL_ASSERT( rReg.is() );
766 OUString aDllName = sDllName;
770 rReg->registerImplementation(
771 OUString( "com.sun.star.loader.SharedLibrary" ),
772 aDllName,
773 Reference< XSimpleRegistry > () );
774 rInterface = rSMgr->createInstance( sService );
776 catch( Exception & )
778 printf( "couldn't register dll %s\n" ,
779 OUStringToOString( aDllName, RTL_TEXTENCODING_ASCII_US ).getStr() );
782 return rInterface;
786 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */