Update ooo320-m1
[ooovba.git] / testtools / source / performance / ubobject.cxx
blobba57da51c21cb2896d8a4198932d0fe760bb66d7
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: ubobject.cxx,v $
10 * $Revision: 1.6 $
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_testtools.hxx"
34 #include <osl/diagnose.h>
35 #include <osl/interlck.h>
37 #include <cppuhelper/factory.hxx>
39 #include <com/sun/star/lang/XServiceInfo.hpp>
40 #include <com/sun/star/lang/XComponent.hpp>
41 #include <com/sun/star/registry/XRegistryKey.hpp>
43 #include <com/sun/star/test/performance/XPerformanceTest.hpp>
45 using namespace rtl;
46 using namespace osl;
47 using namespace cppu;
48 using namespace com::sun::star::uno;
49 using namespace com::sun::star::lang;
50 using namespace com::sun::star::registry;
51 using namespace com::sun::star::test::performance;
53 #define SERVICENAME "com.sun.star.test.performance.PerformanceTestObject"
54 #define IMPLNAME "com.sun.star.comp.performance.PerformanceTestObject"
56 namespace benchmark_object
59 //--------------------------------------------------------------------------------------------------
60 inline static Sequence< OUString > getSupportedServiceNames()
62 OUString aName( RTL_CONSTASCII_USTRINGPARAM(SERVICENAME) );
63 return Sequence< OUString >( &aName, 1 );
66 //==================================================================================================
67 class ServiceImpl
68 : public XServiceInfo
69 , public XPerformanceTest
71 OUString _aDummyString;
72 Any _aDummyAny;
73 Sequence< Reference< XInterface > > _aDummySequence;
74 ComplexTypes _aDummyStruct;
75 RuntimeException _aDummyRE;
77 sal_Int32 _nRef;
79 public:
80 ServiceImpl()
81 : _nRef( 0 )
83 ServiceImpl( const Reference< XMultiServiceFactory > & xMgr )
84 : _nRef( 0 )
87 // XInterface
88 virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type& aType ) throw(::com::sun::star::uno::RuntimeException)
90 // execution time remains appr. constant any time
91 Any aRet;
92 if (aType == ::getCppuType( (const Reference< XInterface > *)0 ))
94 void * p = (XInterface *)(XPerformanceTest *)this;
95 aRet.setValue( &p, ::getCppuType( (const Reference< XInterface > *)0 ) );
97 if (aType == ::getCppuType( (const Reference< XPerformanceTest > *)0 ))
99 void * p = (XPerformanceTest *)this;
100 aRet.setValue( &p, ::getCppuType( (const Reference< XPerformanceTest > *)0 ) );
102 if (! aRet.hasValue())
104 void * p = (XPerformanceTest *)this;
105 Any aDummy( &p, ::getCppuType( (const Reference< XPerformanceTest > *)0 ) );
107 return aRet;
109 virtual void SAL_CALL acquire() throw()
110 { osl_incrementInterlockedCount( &_nRef ); }
111 virtual void SAL_CALL release() throw()
112 { if (! osl_decrementInterlockedCount( &_nRef )) delete this; }
114 // XServiceInfo
115 virtual OUString SAL_CALL getImplementationName() throw (RuntimeException);
116 virtual sal_Bool SAL_CALL supportsService( const OUString & rServiceName ) throw (RuntimeException);
117 virtual Sequence< OUString > SAL_CALL getSupportedServiceNames() throw (RuntimeException);
119 // Attributes
120 virtual sal_Int32 SAL_CALL getLong_attr() throw(::com::sun::star::uno::RuntimeException)
121 { return 0; }
122 virtual void SAL_CALL setLong_attr( sal_Int32 _attributelong ) throw(::com::sun::star::uno::RuntimeException)
124 virtual sal_Int64 SAL_CALL getHyper_attr() throw(::com::sun::star::uno::RuntimeException)
125 { return 0; }
126 virtual void SAL_CALL setHyper_attr( sal_Int64 _attributehyper ) throw(::com::sun::star::uno::RuntimeException)
128 virtual float SAL_CALL getFloat_attr() throw(::com::sun::star::uno::RuntimeException)
129 { return 0.0; }
130 virtual void SAL_CALL setFloat_attr( float _attributefloat ) throw(::com::sun::star::uno::RuntimeException)
132 virtual double SAL_CALL getDouble_attr() throw(::com::sun::star::uno::RuntimeException)
133 { return 0.0; }
134 virtual void SAL_CALL setDouble_attr( double _attributedouble ) throw(::com::sun::star::uno::RuntimeException)
136 virtual OUString SAL_CALL getString_attr() throw(::com::sun::star::uno::RuntimeException)
137 { return _aDummyString; }
138 virtual void SAL_CALL setString_attr( const ::rtl::OUString& _attributestring ) throw(::com::sun::star::uno::RuntimeException)
140 virtual Reference< XInterface > SAL_CALL getInterface_attr() throw(::com::sun::star::uno::RuntimeException)
141 { return Reference< XInterface >(); }
142 virtual void SAL_CALL setInterface_attr( const Reference< XInterface >& _attributeinterface ) throw(::com::sun::star::uno::RuntimeException)
144 virtual Any SAL_CALL getAny_attr() throw(::com::sun::star::uno::RuntimeException)
145 { return _aDummyAny; }
146 virtual void SAL_CALL setAny_attr( const Any& _attributeany ) throw(::com::sun::star::uno::RuntimeException)
148 virtual Sequence< Reference< XInterface > > SAL_CALL getSequence_attr() throw(::com::sun::star::uno::RuntimeException)
149 { return _aDummySequence; }
150 virtual void SAL_CALL setSequence_attr( const Sequence< Reference< XInterface > >& _attributesequence ) throw(::com::sun::star::uno::RuntimeException)
152 virtual ComplexTypes SAL_CALL getStruct_attr() throw(::com::sun::star::uno::RuntimeException)
153 { return _aDummyStruct; }
154 virtual void SAL_CALL setStruct_attr( const ::com::sun::star::test::performance::ComplexTypes& _attributestruct ) throw(::com::sun::star::uno::RuntimeException)
157 // Methods
158 virtual sal_Int32 SAL_CALL getLong() throw(::com::sun::star::uno::RuntimeException)
159 { return 0; }
160 virtual void SAL_CALL setLong( sal_Int32 _long ) throw(::com::sun::star::uno::RuntimeException)
162 virtual sal_Int64 SAL_CALL getHyper() throw(::com::sun::star::uno::RuntimeException)
163 { return 0; }
164 virtual void SAL_CALL setHyper( sal_Int64 _hyper ) throw(::com::sun::star::uno::RuntimeException)
166 virtual float SAL_CALL getFloat() throw(::com::sun::star::uno::RuntimeException)
167 { return 0; }
168 virtual void SAL_CALL setFloat( float _float ) throw(::com::sun::star::uno::RuntimeException)
170 virtual double SAL_CALL getDouble() throw(::com::sun::star::uno::RuntimeException)
171 { return 0; }
172 virtual void SAL_CALL setDouble( double _double ) throw(::com::sun::star::uno::RuntimeException)
174 virtual OUString SAL_CALL getString() throw(::com::sun::star::uno::RuntimeException)
175 { return _aDummyString; }
176 virtual void SAL_CALL setString( const ::rtl::OUString& _string ) throw(::com::sun::star::uno::RuntimeException)
178 virtual Reference< XInterface > SAL_CALL getInterface() throw(::com::sun::star::uno::RuntimeException)
179 { return Reference< XInterface >(); }
180 virtual void SAL_CALL setInterface( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _interface ) throw(::com::sun::star::uno::RuntimeException)
182 virtual Any SAL_CALL getAny() throw(::com::sun::star::uno::RuntimeException)
183 { return _aDummyAny; }
184 virtual void SAL_CALL setAny( const ::com::sun::star::uno::Any& _any ) throw(::com::sun::star::uno::RuntimeException)
186 virtual Sequence< Reference< XInterface > > SAL_CALL getSequence() throw(::com::sun::star::uno::RuntimeException)
187 { return _aDummySequence; }
188 virtual void SAL_CALL setSequence( const Sequence< Reference< XInterface > >& _sequence ) throw(::com::sun::star::uno::RuntimeException)
190 virtual ComplexTypes SAL_CALL getStruct() throw(::com::sun::star::uno::RuntimeException)
191 { return _aDummyStruct; }
192 virtual void SAL_CALL setStruct( const ::com::sun::star::test::performance::ComplexTypes& c ) throw(::com::sun::star::uno::RuntimeException)
195 virtual void SAL_CALL async() throw(::com::sun::star::uno::RuntimeException)
197 virtual void SAL_CALL sync() throw(::com::sun::star::uno::RuntimeException)
199 virtual ComplexTypes SAL_CALL complex_in( const ::com::sun::star::test::performance::ComplexTypes& aVal ) throw(::com::sun::star::uno::RuntimeException)
200 { return aVal; }
201 virtual ComplexTypes SAL_CALL complex_inout( ::com::sun::star::test::performance::ComplexTypes& aVal ) throw(::com::sun::star::uno::RuntimeException)
202 { return aVal; }
203 virtual void SAL_CALL complex_oneway( const ::com::sun::star::test::performance::ComplexTypes& aVal ) throw(::com::sun::star::uno::RuntimeException)
205 virtual void SAL_CALL complex_noreturn( const ::com::sun::star::test::performance::ComplexTypes& aVal ) throw(::com::sun::star::uno::RuntimeException)
207 virtual Reference< XPerformanceTest > SAL_CALL createObject() throw(::com::sun::star::uno::RuntimeException)
208 { return new ServiceImpl(); }
209 virtual void SAL_CALL raiseRuntimeException( ) throw(::com::sun::star::uno::RuntimeException)
210 { throw _aDummyRE; }
213 //##################################################################################################
215 // XServiceInfo
216 //__________________________________________________________________________________________________
217 OUString ServiceImpl::getImplementationName()
218 throw (RuntimeException)
220 return OUString( RTL_CONSTASCII_USTRINGPARAM(IMPLNAME) );
222 //__________________________________________________________________________________________________
223 sal_Bool ServiceImpl::supportsService( const OUString & rServiceName )
224 throw (RuntimeException)
226 const Sequence< OUString > & rSNL = getSupportedServiceNames();
227 const OUString * pArray = rSNL.getConstArray();
228 for ( sal_Int32 nPos = rSNL.getLength(); nPos--; )
230 if (pArray[nPos] == rServiceName)
231 return sal_True;
233 return sal_False;
235 //__________________________________________________________________________________________________
236 Sequence< OUString > ServiceImpl::getSupportedServiceNames()
237 throw (RuntimeException)
239 return benchmark_object::getSupportedServiceNames();
242 // ...
244 //==================================================================================================
245 static Reference< XInterface > SAL_CALL ServiceImpl_create( const Reference< XMultiServiceFactory > & xSMgr )
247 return Reference< XInterface >( (XPerformanceTest *)new ServiceImpl( xSMgr ) );
253 //##################################################################################################
254 //##################################################################################################
255 //##################################################################################################
258 extern "C"
260 //==================================================================================================
261 void SAL_CALL component_getImplementationEnvironment(
262 const sal_Char ** ppEnvTypeName, uno_Environment ** ppEnv )
264 *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
266 //==================================================================================================
267 sal_Bool SAL_CALL component_writeInfo(
268 void * pServiceManager, void * pRegistryKey )
270 if (pRegistryKey)
274 Reference< XRegistryKey > xNewKey(
275 reinterpret_cast< XRegistryKey * >( pRegistryKey )->createKey(
276 OUString( RTL_CONSTASCII_USTRINGPARAM("/" IMPLNAME "/UNO/SERVICES") ) ) );
277 xNewKey->createKey( OUString( RTL_CONSTASCII_USTRINGPARAM(SERVICENAME) ) );
279 return sal_True;
281 catch (InvalidRegistryException &)
283 OSL_ENSURE( sal_False, "### InvalidRegistryException!" );
286 return sal_False;
288 //==================================================================================================
289 void * SAL_CALL component_getFactory(
290 const sal_Char * pImplName, void * pServiceManager, void * pRegistryKey )
292 void * pRet = 0;
294 if (pServiceManager && rtl_str_compare( pImplName, IMPLNAME ) == 0)
296 Reference< XSingleServiceFactory > xFactory( createSingleFactory(
297 reinterpret_cast< XMultiServiceFactory * >( pServiceManager ),
298 OUString( RTL_CONSTASCII_USTRINGPARAM(IMPLNAME) ),
299 benchmark_object::ServiceImpl_create,
300 benchmark_object::getSupportedServiceNames() ) );
302 if (xFactory.is())
304 xFactory->acquire();
305 pRet = xFactory.get();
309 return pRet;