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