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