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