merge the formfield patch from ooo-build
[ooovba.git] / bridges / test / testcomp.cxx
blob6d21da0ad47a4c616323be0262512d55d5a5b1cd
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: testcomp.cxx,v $
10 * $Revision: 1.12 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_bridges.hxx"
33 #if OSL_DEBUG_LEVEL == 0
34 #undef NDEBUG
35 #define NDEBUG
36 #endif
37 #include <assert.h>
38 #include <string.h>
39 #include <stdlib.h>
40 #include <osl/time.h>
42 #include <uno/threadpool.h>
44 #include <osl/mutex.hxx>
45 #include <osl/diagnose.h>
47 #include <test/XTestFactory.hpp>
48 #include <cppuhelper/servicefactory.hxx>
50 #include <com/sun/star/bridge/XInstanceProvider.hpp>
52 #include <com/sun/star/registry/XImplementationRegistration.hpp>
54 #include <com/sun/star/test/performance/XPerformanceTest.hpp>
55 #include <com/sun/star/lang/XServiceInfo.hpp>
57 #include <cppuhelper/weak.hxx>
59 using namespace ::test;
60 using namespace ::rtl;
61 using namespace ::test;
62 using namespace ::com::sun::star::uno;
63 using namespace ::com::sun::star::bridge;
64 using namespace ::com::sun::star::lang;
65 using namespace ::com::sun::star::registry;
66 using namespace ::com::sun::star::test::performance;
68 #include "testcomp.h"
71 void parseCommandLine( char *argv[] ,
72 ::rtl::OUString *pConnection , ::rtl::OUString *pProtocol ,
73 sal_Bool *pbLatency , sal_Bool *pbReverse)
75 sal_Int32 nArgIndex = 1;
76 if( ! strcmp( argv[1] , "-r" ) )
78 nArgIndex = 2;
79 *pbReverse = sal_True;
81 else if( ! strcmp( argv[1] , "-latency" ) )
83 *pbLatency = sal_True;
84 nArgIndex = 2;
87 OUString sTemp = OUString::createFromAscii( argv[nArgIndex] );
88 sal_Int32 nIndex = sTemp.indexOf( ';' );
89 if( -1 == nIndex )
91 *pConnection = sTemp;
92 *pProtocol = OUString( RTL_CONSTASCII_USTRINGPARAM( "iiop" ) );
94 else
96 *pConnection = sTemp.copy( 0 , nIndex );
97 *pProtocol = sTemp.copy( nIndex+1, sTemp.getLength() - (nIndex+1) );
101 Any OInstanceProvider::queryInterface( const Type & aType ) throw ( RuntimeException )
103 Any a = ::cppu::queryInterface( aType ,
104 SAL_STATIC_CAST( XInstanceProvider * , this ) );
105 if( a.hasValue() )
107 return a;
109 return OWeakObject::queryInterface( aType );
112 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >
113 OInstanceProvider::getInstance( const ::rtl::OUString& sObjectName )
114 throw(::com::sun::star::container::NoSuchElementException,
115 ::com::sun::star::uno::RuntimeException)
117 // Tries to get the PerformanceTestObject
118 if( sObjectName == OUString( RTL_CONSTASCII_USTRINGPARAM( "TestRemoteObject" ) ) )
120 return m_rSMgr->createInstance(
121 OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.test.performance.PerformanceTestObject") ) );
123 return Reference < XInterface > ( (::cppu::OWeakObject * ) new OTestFactory() );
126 class ServiceImpl
127 : public XServiceInfo
128 , public XPerformanceTest
130 OUString _aDummyString;
131 Any _aDummyAny;
132 Sequence< Reference< XInterface > > _aDummySequence;
133 ComplexTypes _aDummyStruct;
134 RuntimeException _aDummyRE;
136 sal_Int32 _nRef;
138 public:
139 ServiceImpl()
140 : _nRef( 0 )
142 ServiceImpl( const Reference< XMultiServiceFactory > & /* xMgr */)
143 : _nRef( 0 )
146 // XInterface
147 virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type& aType ) throw(::com::sun::star::uno::RuntimeException)
149 // execution time remains appr. constant any time
150 Any aRet;
151 if (aType == ::getCppuType( (const Reference< XInterface > *)0 ))
153 void * p = (XInterface *)(XPerformanceTest *)this;
154 aRet.setValue( &p, ::getCppuType( (const Reference< XInterface > *)0 ) );
156 if (aType == ::getCppuType( (const Reference< XPerformanceTest > *)0 ))
158 void * p = (XPerformanceTest *)this;
159 aRet.setValue( &p, ::getCppuType( (const Reference< XPerformanceTest > *)0 ) );
161 if (! aRet.hasValue())
163 void * p = (XPerformanceTest *)this;
164 Any aDummy( &p, ::getCppuType( (const Reference< XPerformanceTest > *)0 ) );
166 return aRet;
168 virtual void SAL_CALL acquire() throw()
169 { osl_incrementInterlockedCount( &_nRef ); }
170 virtual void SAL_CALL release() throw()
171 { if (! osl_decrementInterlockedCount( &_nRef )) delete this; }
173 // XServiceInfo
174 virtual OUString SAL_CALL getImplementationName() throw (RuntimeException);
175 virtual sal_Bool SAL_CALL supportsService( const OUString & rServiceName ) throw (RuntimeException);
176 virtual Sequence< OUString > SAL_CALL getSupportedServiceNames() throw (RuntimeException);
178 // Attributes
179 virtual sal_Int32 SAL_CALL getLong_attr() throw(::com::sun::star::uno::RuntimeException)
180 { return 0; }
181 virtual void SAL_CALL setLong_attr( sal_Int32 /* _attributelong */) throw(::com::sun::star::uno::RuntimeException)
183 virtual sal_Int64 SAL_CALL getHyper_attr() throw(::com::sun::star::uno::RuntimeException)
184 { return 0; }
185 virtual void SAL_CALL setHyper_attr( sal_Int64 /* _attributehyper */) throw(::com::sun::star::uno::RuntimeException)
187 virtual float SAL_CALL getFloat_attr() throw(::com::sun::star::uno::RuntimeException)
188 { return 0.0; }
189 virtual void SAL_CALL setFloat_attr( float /* _attributefloat */) throw(::com::sun::star::uno::RuntimeException)
191 virtual double SAL_CALL getDouble_attr() throw(::com::sun::star::uno::RuntimeException)
192 { return 0.0; }
193 virtual void SAL_CALL setDouble_attr( double /* _attributedouble */) throw(::com::sun::star::uno::RuntimeException)
195 virtual OUString SAL_CALL getString_attr() throw(::com::sun::star::uno::RuntimeException)
196 { return _aDummyString; }
197 virtual void SAL_CALL setString_attr( const ::rtl::OUString& /* _attributestring */) throw(::com::sun::star::uno::RuntimeException)
199 virtual Reference< XInterface > SAL_CALL getInterface_attr() throw(::com::sun::star::uno::RuntimeException)
200 { return Reference< XInterface >(); }
201 virtual void SAL_CALL setInterface_attr( const Reference< XInterface >& /* _attributeinterface */) throw(::com::sun::star::uno::RuntimeException)
203 virtual Any SAL_CALL getAny_attr() throw(::com::sun::star::uno::RuntimeException)
204 { return _aDummyAny; }
205 virtual void SAL_CALL setAny_attr( const Any& /* _attributeany */) throw(::com::sun::star::uno::RuntimeException)
207 virtual Sequence< Reference< XInterface > > SAL_CALL getSequence_attr() throw(::com::sun::star::uno::RuntimeException)
208 { return _aDummySequence; }
209 virtual void SAL_CALL setSequence_attr( const Sequence< Reference< XInterface > >& /* _attributesequence */) throw(::com::sun::star::uno::RuntimeException)
211 virtual ComplexTypes SAL_CALL getStruct_attr() throw(::com::sun::star::uno::RuntimeException)
212 { return _aDummyStruct; }
213 virtual void SAL_CALL setStruct_attr( const ::com::sun::star::test::performance::ComplexTypes& /* _attributestruct */) throw(::com::sun::star::uno::RuntimeException)
216 // Methods
217 virtual sal_Int32 SAL_CALL getLong() throw(::com::sun::star::uno::RuntimeException)
218 { return 0; }
219 virtual void SAL_CALL setLong( sal_Int32 /* _long */) throw(::com::sun::star::uno::RuntimeException)
221 virtual sal_Int64 SAL_CALL getHyper() throw(::com::sun::star::uno::RuntimeException)
222 { return 0; }
223 virtual void SAL_CALL setHyper( sal_Int64 /* _hyper */) throw(::com::sun::star::uno::RuntimeException)
225 virtual float SAL_CALL getFloat() throw(::com::sun::star::uno::RuntimeException)
226 { return 0; }
227 virtual void SAL_CALL setFloat( float /* _float */) throw(::com::sun::star::uno::RuntimeException)
229 virtual double SAL_CALL getDouble() throw(::com::sun::star::uno::RuntimeException)
230 { return 0; }
231 virtual void SAL_CALL setDouble( double /* _double */) throw(::com::sun::star::uno::RuntimeException)
233 virtual OUString SAL_CALL getString() throw(::com::sun::star::uno::RuntimeException)
234 { return _aDummyString; }
235 virtual void SAL_CALL setString( const ::rtl::OUString& /* _string */) throw(::com::sun::star::uno::RuntimeException)
237 virtual Reference< XInterface > SAL_CALL getInterface() throw(::com::sun::star::uno::RuntimeException)
238 { return Reference< XInterface >(); }
239 virtual void SAL_CALL setInterface( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& /* _interface */) throw(::com::sun::star::uno::RuntimeException)
241 virtual Any SAL_CALL getAny() throw(::com::sun::star::uno::RuntimeException)
242 { return _aDummyAny; }
243 virtual void SAL_CALL setAny( const ::com::sun::star::uno::Any& /* _any */) throw(::com::sun::star::uno::RuntimeException)
245 virtual Sequence< Reference< XInterface > > SAL_CALL getSequence() throw(::com::sun::star::uno::RuntimeException)
246 { return _aDummySequence; }
247 virtual void SAL_CALL setSequence( const Sequence< Reference< XInterface > >& /*_sequence */) throw(::com::sun::star::uno::RuntimeException)
249 virtual ComplexTypes SAL_CALL getStruct() throw(::com::sun::star::uno::RuntimeException)
250 { return _aDummyStruct; }
251 virtual void SAL_CALL setStruct( const ::com::sun::star::test::performance::ComplexTypes& /* c */) throw(::com::sun::star::uno::RuntimeException)
254 virtual void SAL_CALL async() throw(::com::sun::star::uno::RuntimeException);
256 virtual void SAL_CALL sync() throw(::com::sun::star::uno::RuntimeException)
258 virtual ComplexTypes SAL_CALL complex_in( const ::com::sun::star::test::performance::ComplexTypes& aVal ) throw(::com::sun::star::uno::RuntimeException)
259 { return aVal; }
260 virtual ComplexTypes SAL_CALL complex_inout( ::com::sun::star::test::performance::ComplexTypes& aVal ) throw(::com::sun::star::uno::RuntimeException)
261 { return aVal; }
262 virtual void SAL_CALL complex_oneway( const ::com::sun::star::test::performance::ComplexTypes& /* aVal */) throw(::com::sun::star::uno::RuntimeException)
264 virtual void SAL_CALL complex_noreturn( const ::com::sun::star::test::performance::ComplexTypes& /* aVal */) throw(::com::sun::star::uno::RuntimeException)
266 virtual Reference< XPerformanceTest > SAL_CALL createObject() throw(::com::sun::star::uno::RuntimeException)
267 { return new ServiceImpl(); }
268 virtual void SAL_CALL raiseRuntimeException( ) throw(::com::sun::star::uno::RuntimeException)
269 { throw _aDummyRE; }
273 void ServiceImpl::async() throw(::com::sun::star::uno::RuntimeException)
276 // XServiceInfo
277 //__________________________________________________________________________________________________
278 OUString ServiceImpl::getImplementationName()
279 throw (RuntimeException)
281 return OUString( );
283 //__________________________________________________________________________________________________
284 sal_Bool ServiceImpl::supportsService( const OUString & /* rServiceName */)
285 throw (RuntimeException)
287 return sal_False;
289 //__________________________________________________________________________________________________
290 Sequence< OUString > ServiceImpl::getSupportedServiceNames()
291 throw (RuntimeException)
293 return Sequence< OUString > ();
296 /******************
297 * OCallMe
299 *****************/
301 Any OCallMe::queryInterface( const Type & aType ) throw ( RuntimeException )
303 Any a = ::cppu::queryInterface( aType,
304 SAL_STATIC_CAST( XCallMe * , this ) );
306 if( a.hasValue() )
308 return a;
311 return OWeakObject::queryInterface( aType );
314 void OCallMe::call( const ::rtl::OUString& s, sal_Int32 nToDo )
315 throw( RuntimeException, ::test::TestBridgeException)
317 if( nToDo < 0 )
319 throw TestBridgeException();
322 OUString sDummy;
323 if( ! nToDo ) {
324 OString o = OUStringToOString( s,RTL_TEXTENCODING_ASCII_US);
325 printf( "%s\n" , o.pData->buffer );
327 for( sal_Int32 i = 0 ; i < nToDo ; i ++ )
329 sDummy += s;
333 void SAL_CALL OCallMe::drawLine( sal_Int32 /* x1 */, sal_Int32 /* y1 */, sal_Int32 /* x2 */, sal_Int32 /* y2 */)
334 throw(::com::sun::star::uno::RuntimeException)
336 // do nothings
339 void OCallMe::callOneway( const ::rtl::OUString& /* s */, sal_Int32 nToDo )
340 throw(RuntimeException)
342 OUString sDummy;
343 m_nLastToDos = nToDo;
346 if( nToDo )
348 printf( "+" );
349 fflush( stdout );
351 TimeValue val = { nToDo , 0 };
352 osl_waitThread( &val );
353 printf( "-\n" );
358 ::test::TestTypes SAL_CALL OCallMe::transport( const ::test::TestTypes& types )
359 throw(::com::sun::star::uno::RuntimeException)
361 return types;
364 ::rtl::OUString OCallMe::getsAttribute() throw(RuntimeException)
366 return m_sAttribute;
368 void OCallMe::setsAttribute( const ::rtl::OUString& _sattribute )
369 throw(RuntimeException)
371 m_sAttribute = _sattribute;
373 void OCallMe::callAgain( const Reference< ::test::XCallMe >& callAgainArg,
374 sal_Int32 nToCall ) throw(RuntimeException)
376 ::osl::MutexGuard guard( m_mutex );
377 if( nToCall %2 )
379 printf( "Deadlocktest pong %" SAL_PRIdINT32 "\n", nToCall );
381 else
383 printf( "Deadlocktest ping %" SAL_PRIdINT32 "\n", nToCall );
385 if( nToCall )
387 callAgainArg->callAgain( Reference< XCallMe > ( (XCallMe *) this ) , nToCall -1 );
391 /********************
392 * OInterfaceTest
394 *******************/
395 Any OInterfaceTest::queryInterface( const Type & aType ) throw ( RuntimeException )
397 Any a = ::cppu::queryInterface( aType,
398 SAL_STATIC_CAST( XInterfaceTest * , this ) );
399 if( a.hasValue() )
401 return a;
403 return OWeakObject::queryInterface( aType );
407 void OInterfaceTest::setIn(
408 const Reference< ::test::XCallMe >& callback )
409 throw(RuntimeException)
411 m_rCallMe = callback;
412 call();
415 void OInterfaceTest::setInOut( Reference< ::test::XCallMe >& callback )
416 throw(RuntimeException)
418 Reference< XCallMe > r = m_rCallMe;
419 m_rCallMe = callback;
420 callback = r;
421 call();
425 void OInterfaceTest::getOut( Reference< ::test::XCallMe >& callback )
426 throw(RuntimeException)
428 callback = m_rCallMe;
431 Reference< ::test::XCallMe > OInterfaceTest::get( )
432 throw(RuntimeException)
434 call();
435 return m_rCallMe;
438 void OInterfaceTest::call()
440 if( m_rCallMe.is() )
442 m_rCallMe->call( OUString( RTL_CONSTASCII_USTRINGPARAM("This is my String during a callback!")) , 5);
447 Any OTestFactory::queryInterface( const Type & aType ) throw ( RuntimeException )
449 Any a = ::cppu::queryInterface( aType,
450 SAL_STATIC_CAST( XTestFactory * , this ) );
452 if( a.hasValue() )
454 return a;
457 return OWeakObject::queryInterface( aType );
460 Reference< ::test::XCallMe > OTestFactory::createCallMe( )
461 throw(RuntimeException)
463 return Reference< XCallMe > ( (XCallMe * ) new OCallMe() );
466 Reference< ::test::XInterfaceTest > SAL_CALL OTestFactory::createInterfaceTest( )
467 throw(RuntimeException)
469 return Reference < XInterfaceTest > ( (XInterfaceTest * ) new OInterfaceTest() );
475 // class OInstanceProvider :
476 // public ::cppu::OWeakObject,
477 // public XInstanceProvider
478 // {
479 // public:
480 // OInstanceProvider( ){}
481 // ~OInstanceProvider(){ printf( "instance provider dies\n" );}
482 // public:
483 // // XInterface
484 // Any SAL_CALL queryInterface( const Type & aType);
485 // void SAL_CALL acquire() { OWeakObject::acquire(); }
486 // void SAL_CALL release() { OWeakObject::release(); }
488 // public:
489 // virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL
490 // getInstance( const ::rtl::OUString& sObjectName )
491 // throw( ::com::sun::star::container::NoSuchElementException,
492 // ::com::sun::star::uno::RuntimeException);
493 // };
502 double getCallsPerSec( const Reference < XCallMe > &rCall , int nLoops, int nToDo )
504 TimeValue aStartTime, aEndTime;
505 osl_getSystemTime( &aStartTime );
506 for( sal_Int32 i = 0; i < nLoops; i ++ )
508 rCall->call( OUString( RTL_CONSTASCII_USTRINGPARAM("Performance test string")) , nToDo );
510 osl_getSystemTime( &aEndTime );
512 double fStart = (double)aStartTime.Seconds + ((double)aStartTime.Nanosec / 1000000000.0);
513 double fEnd = (double)aEndTime.Seconds + ((double)aEndTime.Nanosec / 1000000000.0);
514 return fEnd-fStart;
517 double getCallsPerSecOneway( const Reference < XCallMe > &rCall ,
518 int nLoops,
519 int nToDo,
520 double *pdAfterExecution
523 TimeValue aStartTime, aEndTime, aAfterExecution;
524 osl_getSystemTime( &aStartTime );
525 for( sal_Int32 i = 0; i < nLoops; i ++ )
527 // rCall->callOneway( OUString( RTL_CONSTASCII_USTRINGPARAM("Performance test string" )), 0 );
528 rCall->drawLine( 0 , 0 , 500 , 123 );
530 osl_getSystemTime( &aEndTime );
532 rCall->call( OUString( RTL_CONSTASCII_USTRINGPARAM("Performance test string")) , nToDo );
533 osl_getSystemTime( &aAfterExecution );
535 double fStart = (double)aStartTime.Seconds + ((double)aStartTime.Nanosec / 1000000000.0);
536 double fEnd = (double)aEndTime.Seconds + ((double)aEndTime.Nanosec / 1000000000.0);
537 *pdAfterExecution = (double)aAfterExecution.Seconds +
538 ((double)aAfterExecution.Nanosec / 1000000000.0) - fStart;
539 return fEnd-fStart;
542 void testOnewayPerformanceOnTwoInterfaces(
543 const Reference < XCallMe > &rRemote1, const Reference < XCallMe > &rRemote2 )
545 printf( "Doing oneway performance test on two interfaces ...\n" );
546 const sal_Int32 nLoops = 10000;
547 TimeValue aStartTime, aEndTime;
548 osl_getSystemTime( &aStartTime );
549 for( sal_Int32 i = 0; i < nLoops ; i ++ )
551 rRemote1->drawLine( 0 , 0 , 500 , 123 );
552 rRemote2->drawLine( 0 , 0 , 500 , 123 );
554 osl_getSystemTime( &aEndTime );
555 double fStart = (double)aStartTime.Seconds + ((double)aStartTime.Nanosec / 1000000000.0);
556 double fEnd = (double)aEndTime.Seconds + ((double)aEndTime.Nanosec / 1000000000.0);
558 printf( "Overhead per Call [ms] %g\n" , ((fEnd-fStart)/((double)nLoops/1000 ))/2. );
561 void testPerformance( const Reference < XCallMe > &rRemote,
562 const Reference < XCallMe > &rLocal )
564 OUString aTestString;
566 sal_Int32 nDoSomething = 1;
567 sal_Int32 nCalls = 80000;
568 double dRemote, dLocal,dAfterExecution;
570 printf( "performance test oneway...\n" );
571 dLocal = getCallsPerSecOneway( rLocal , nCalls , nDoSomething , &dAfterExecution);
572 dRemote = getCallsPerSecOneway( rRemote , nCalls , nDoSomething , &dAfterExecution);
573 printf( "Local=%g s,"
574 "Remote : %g s\n" , dLocal, dRemote );
575 if( dLocal > 0. )
577 printf( "Remote/Local : %g\n", dRemote/dLocal );
580 printf( "Overhead per Call [ms] %g\n" , (dRemote - dLocal)/((double)nCalls/1000 ) );
581 printf( "Overhead per Call after completion [ms] %g\n" , (dAfterExecution - dLocal)/((double)nCalls/1000 ) );
583 nCalls = 2000;
585 printf( "Doing performance test ...\n" );
586 dRemote = getCallsPerSec( rRemote , nCalls , nDoSomething );
587 dLocal = getCallsPerSec( rLocal , nCalls , nDoSomething );
588 printf( "Local=%g s,\n"
589 "Remote=%g s\n" , dLocal, dRemote );
590 if( dLocal > 0. )
592 printf( "Remote/Local : %g\n", dRemote/dLocal );
594 printf( "Overhead per synchron Call [ms] %g\n" , ((dRemote - dLocal)/((double)nCalls/1000 )) );
597 void testException( const Reference < XCallMe > &r )
599 try {
600 r->call( OUString( RTL_CONSTASCII_USTRINGPARAM("dummy")) , -1 );
601 assert( ! "no exception flown !" );
603 catch( TestBridgeException & e )
605 // Exception flew successfully !
607 catch( Exception & e )
609 assert( ! "only base class of exception could be catched!" );
611 catch(...)
613 assert(! "wrong unknown exception !" );
617 void testSequenceOfCalls( const Reference< XCallMe > & rRCallMe )
619 printf( "Testing sequence of calls\n" );
620 for( sal_Int32 i = 0 ; i < 800 ; i ++ )
622 rRCallMe->callOneway( OUString( RTL_CONSTASCII_USTRINGPARAM("hifuj" )), 0 );
626 void testAllTypes( const Reference < XCallMe > & rRCallMe )
628 printf( "Testing all types\n" );
630 for( sal_Int32 i = 0; i < 32 ; i ++ )
633 TestTypes types;
634 types.Bool = sal_True;
635 types.Char = L'i';
636 types.Byte = -12;
637 types.Short = -32000;
638 types.UShort = (sal_uInt16 ) (1 << i);
639 types.Long = -123;
640 types.ULong = 1 << i;
641 types.Hyper = 50;
642 types.UHyper = 1 << i*2;
643 types.Float = (float)123.239;
644 types.Double = 1279.12490012;
645 types.String = OUString( RTL_CONSTASCII_USTRINGPARAM("abcdefghijklmnopqrstuvwxyz"));
646 types.Interface = Reference< XInterface >( rRCallMe , UNO_QUERY);
647 types.Any <<= types.Double;
649 TestTypes retTypes = rRCallMe->transport( types );
651 OSL_ASSERT( ( types.Bool && retTypes.Bool ) || ( ! types.Bool && ! retTypes.Bool ) );
652 OSL_ASSERT( types.Char == retTypes.Char );
653 OSL_ASSERT( types.Byte == retTypes.Byte );
654 OSL_ASSERT( types.Short == retTypes.Short );
655 OSL_ASSERT( types.UShort == retTypes.UShort );
656 OSL_ASSERT( types.Long == retTypes.Long );
657 OSL_ASSERT( types.ULong == retTypes.ULong );
658 OSL_ASSERT( types.Hyper == retTypes.Hyper );
659 OSL_ASSERT( types.UHyper == retTypes.UHyper );
660 OSL_ASSERT( types.Float == retTypes.Float );
661 OSL_ASSERT( types.Double == retTypes.Double );
662 OSL_ASSERT( types.String == retTypes.String );
663 OSL_ASSERT( types.Interface == retTypes.Interface );
664 OSL_ASSERT( types.Any == retTypes.Any );
669 void testRemote( const Reference< XInterface > &rRemote )
671 char a;
672 getCppuType( (sal_Int8*)&a );
674 Reference< XTestFactory > rRFact( rRemote , UNO_QUERY );
675 if( ! rRFact.is() )
677 printf( "remote object doesn't support XTestFactory\n" );
678 return;
680 OSL_ASSERT( rRFact.is() );
681 Reference< XCallMe > rLCallMe = (XCallMe * ) new OCallMe();
682 Reference< XCallMe > rRCallMe = rRFact->createCallMe();
684 testAllTypes( rLCallMe );
685 testAllTypes( rRCallMe );
687 printf( "Testing exception local ...\n" );
688 testException( rLCallMe );
689 printf( "Testing exception remote ...\n" );
690 testException( rRCallMe );
692 //--------------------
693 // Test attributes
694 //----------------------
695 OUString ow = OUString::createFromAscii( "dum didel dum dideldei" );
696 rLCallMe->setsAttribute( ow );
697 OSL_ASSERT( rLCallMe->getsAttribute() == ow );
699 rRCallMe->setsAttribute( ow );
700 OSL_ASSERT( rRCallMe->getsAttribute() == ow );
702 //-------------------
703 // Performance test
704 //-------------------
705 testPerformance( rRCallMe , rLCallMe );
706 testOnewayPerformanceOnTwoInterfaces( rRFact->createCallMe(), rRCallMe );
708 //----------------
709 // Test sequence
710 //----------------
711 testSequenceOfCalls( rRCallMe );
714 // test triple to check if transporting the same interface multiple
715 // times causes any problems
716 Reference< XInterfaceTest > rRTest = rRFact->createInterfaceTest();
717 Reference< XInterfaceTest > rRTest2 = rRFact->createInterfaceTest();
718 Reference< XInterfaceTest > rRTest3 = rRFact->createInterfaceTest();
720 rRTest->setIn( rRCallMe );
721 rRTest2->setIn( rRCallMe );
722 rRTest3->setIn( rRCallMe );
724 OSL_ASSERT( rRTest->get() == rRCallMe );
725 OSL_ASSERT( rRTest2->get() == rRCallMe );
726 OSL_ASSERT( rRTest3->get() == rRCallMe );
728 rRTest->setIn( rLCallMe );
729 rRTest2->setIn( rLCallMe );
730 rRTest3->setIn( rLCallMe );
733 Reference< XCallMe > rLCallMe1 = (XCallMe * ) new OCallMe();
734 Reference< XCallMe > rLCallMe2 = (XCallMe * ) new OCallMe();
735 Reference< XCallMe > rLCallMe3 = (XCallMe * ) new OCallMe();
736 rRTest->setIn( rLCallMe1 );
737 rRTest2->setIn( rLCallMe2 );
738 rRTest3->setIn( rLCallMe3 );
739 OSL_ASSERT( rRTest->get() == rLCallMe1 );
740 OSL_ASSERT( rRTest2->get() == rLCallMe2 );
741 OSL_ASSERT( rRTest3->get() == rLCallMe3 );
743 rRTest->setIn( rLCallMe );
744 rRTest2->setIn( rLCallMe );
745 rRTest3->setIn( rLCallMe );
747 OSL_ASSERT( rRTest->get() == rLCallMe );
748 OSL_ASSERT( rRTest2->get() == rLCallMe );
749 OSL_ASSERT( rRTest3->get() == rLCallMe );
752 Reference < XCallMe > r = rRCallMe;
753 rRTest->setInOut( r );
754 OSL_ASSERT( r == rLCallMe );
755 OSL_ASSERT( ! ( r == rRCallMe ) );
757 // test empty references
758 rRTest->setIn( Reference < XCallMe > () );
760 //--------------------------------
761 // test thread deadlocking
762 //--------------------------------
763 rLCallMe->callAgain( rRCallMe, 20 );
772 Reference <XInterface > createComponent( const ::rtl::OUString &sService ,
773 const ::rtl::OUString &sDllName,
774 const Reference < XMultiServiceFactory > &rSMgr )
776 Reference< XInterface > rInterface;
777 rInterface = rSMgr->createInstance( sService );
779 if( ! rInterface.is() )
781 // erst registrieren
782 Reference < XImplementationRegistration > rReg (
783 rSMgr->createInstance(
784 OUString::createFromAscii( "com.sun.star.registry.ImplementationRegistration" )),
785 UNO_QUERY );
787 OSL_ASSERT( rReg.is() );
788 OUString aDllName = sDllName;
792 rReg->registerImplementation(
793 OUString::createFromAscii( "com.sun.star.loader.SharedLibrary" ),
794 aDllName,
795 Reference< XSimpleRegistry > () );
796 rInterface = rSMgr->createInstance( sService );
798 catch( Exception & )
800 printf( "couldn't register dll %s\n" ,
801 OUStringToOString( aDllName, RTL_TEXTENCODING_ASCII_US ).getStr() );
804 return rInterface;