1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_testtools.hxx"
31 #include <osl/diagnose.h>
32 #include <osl/interlck.h>
34 #include <cppuhelper/factory.hxx>
36 #include <com/sun/star/lang/XServiceInfo.hpp>
37 #include <com/sun/star/lang/XComponent.hpp>
38 #include <com/sun/star/registry/XRegistryKey.hpp>
40 #include <com/sun/star/test/performance/XPerformanceTest.hpp>
45 using namespace com::sun::star::uno
;
46 using namespace com::sun::star::lang
;
47 using namespace com::sun::star::registry
;
48 using namespace com::sun::star::test::performance
;
50 #define SERVICENAME "com.sun.star.test.performance.PerformanceTestObject"
51 #define IMPLNAME "com.sun.star.comp.performance.PerformanceTestObject"
53 namespace benchmark_object
56 //--------------------------------------------------------------------------------------------------
57 inline static Sequence
< OUString
> getSupportedServiceNames()
59 OUString
aName( RTL_CONSTASCII_USTRINGPARAM(SERVICENAME
) );
60 return Sequence
< OUString
>( &aName
, 1 );
63 //==================================================================================================
66 , public XPerformanceTest
68 OUString _aDummyString
;
70 Sequence
< Reference
< XInterface
> > _aDummySequence
;
71 ComplexTypes _aDummyStruct
;
72 RuntimeException _aDummyRE
;
80 ServiceImpl( const Reference
< XMultiServiceFactory
> & xMgr
)
85 virtual ::com::sun::star::uno::Any SAL_CALL
queryInterface( const ::com::sun::star::uno::Type
& aType
) throw(::com::sun::star::uno::RuntimeException
)
87 // execution time remains appr. constant any time
89 if (aType
== ::getCppuType( (const Reference
< XInterface
> *)0 ))
91 void * p
= (XInterface
*)(XPerformanceTest
*)this;
92 aRet
.setValue( &p
, ::getCppuType( (const Reference
< XInterface
> *)0 ) );
94 if (aType
== ::getCppuType( (const Reference
< XPerformanceTest
> *)0 ))
96 void * p
= (XPerformanceTest
*)this;
97 aRet
.setValue( &p
, ::getCppuType( (const Reference
< XPerformanceTest
> *)0 ) );
99 if (! aRet
.hasValue())
101 void * p
= (XPerformanceTest
*)this;
102 Any
aDummy( &p
, ::getCppuType( (const Reference
< XPerformanceTest
> *)0 ) );
106 virtual void SAL_CALL
acquire() throw()
107 { osl_incrementInterlockedCount( &_nRef
); }
108 virtual void SAL_CALL
release() throw()
109 { if (! osl_decrementInterlockedCount( &_nRef
)) delete this; }
112 virtual OUString SAL_CALL
getImplementationName() throw (RuntimeException
);
113 virtual sal_Bool SAL_CALL
supportsService( const OUString
& rServiceName
) throw (RuntimeException
);
114 virtual Sequence
< OUString
> SAL_CALL
getSupportedServiceNames() throw (RuntimeException
);
117 virtual sal_Int32 SAL_CALL
getLong_attr() throw(::com::sun::star::uno::RuntimeException
)
119 virtual void SAL_CALL
setLong_attr( sal_Int32 _attributelong
) throw(::com::sun::star::uno::RuntimeException
)
121 virtual sal_Int64 SAL_CALL
getHyper_attr() throw(::com::sun::star::uno::RuntimeException
)
123 virtual void SAL_CALL
setHyper_attr( sal_Int64 _attributehyper
) throw(::com::sun::star::uno::RuntimeException
)
125 virtual float SAL_CALL
getFloat_attr() throw(::com::sun::star::uno::RuntimeException
)
127 virtual void SAL_CALL
setFloat_attr( float _attributefloat
) throw(::com::sun::star::uno::RuntimeException
)
129 virtual double SAL_CALL
getDouble_attr() throw(::com::sun::star::uno::RuntimeException
)
131 virtual void SAL_CALL
setDouble_attr( double _attributedouble
) throw(::com::sun::star::uno::RuntimeException
)
133 virtual OUString SAL_CALL
getString_attr() throw(::com::sun::star::uno::RuntimeException
)
134 { return _aDummyString
; }
135 virtual void SAL_CALL
setString_attr( const ::rtl::OUString
& _attributestring
) throw(::com::sun::star::uno::RuntimeException
)
137 virtual Reference
< XInterface
> SAL_CALL
getInterface_attr() throw(::com::sun::star::uno::RuntimeException
)
138 { return Reference
< XInterface
>(); }
139 virtual void SAL_CALL
setInterface_attr( const Reference
< XInterface
>& _attributeinterface
) throw(::com::sun::star::uno::RuntimeException
)
141 virtual Any SAL_CALL
getAny_attr() throw(::com::sun::star::uno::RuntimeException
)
142 { return _aDummyAny
; }
143 virtual void SAL_CALL
setAny_attr( const Any
& _attributeany
) throw(::com::sun::star::uno::RuntimeException
)
145 virtual Sequence
< Reference
< XInterface
> > SAL_CALL
getSequence_attr() throw(::com::sun::star::uno::RuntimeException
)
146 { return _aDummySequence
; }
147 virtual void SAL_CALL
setSequence_attr( const Sequence
< Reference
< XInterface
> >& _attributesequence
) throw(::com::sun::star::uno::RuntimeException
)
149 virtual ComplexTypes SAL_CALL
getStruct_attr() throw(::com::sun::star::uno::RuntimeException
)
150 { return _aDummyStruct
; }
151 virtual void SAL_CALL
setStruct_attr( const ::com::sun::star::test::performance::ComplexTypes
& _attributestruct
) throw(::com::sun::star::uno::RuntimeException
)
155 virtual sal_Int32 SAL_CALL
getLong() throw(::com::sun::star::uno::RuntimeException
)
157 virtual void SAL_CALL
setLong( sal_Int32 _long
) throw(::com::sun::star::uno::RuntimeException
)
159 virtual sal_Int64 SAL_CALL
getHyper() throw(::com::sun::star::uno::RuntimeException
)
161 virtual void SAL_CALL
setHyper( sal_Int64 _hyper
) throw(::com::sun::star::uno::RuntimeException
)
163 virtual float SAL_CALL
getFloat() throw(::com::sun::star::uno::RuntimeException
)
165 virtual void SAL_CALL
setFloat( float _float
) throw(::com::sun::star::uno::RuntimeException
)
167 virtual double SAL_CALL
getDouble() throw(::com::sun::star::uno::RuntimeException
)
169 virtual void SAL_CALL
setDouble( double _double
) throw(::com::sun::star::uno::RuntimeException
)
171 virtual OUString SAL_CALL
getString() throw(::com::sun::star::uno::RuntimeException
)
172 { return _aDummyString
; }
173 virtual void SAL_CALL
setString( const ::rtl::OUString
& _string
) throw(::com::sun::star::uno::RuntimeException
)
175 virtual Reference
< XInterface
> SAL_CALL
getInterface() throw(::com::sun::star::uno::RuntimeException
)
176 { return Reference
< XInterface
>(); }
177 virtual void SAL_CALL
setInterface( const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>& _interface
) throw(::com::sun::star::uno::RuntimeException
)
179 virtual Any SAL_CALL
getAny() throw(::com::sun::star::uno::RuntimeException
)
180 { return _aDummyAny
; }
181 virtual void SAL_CALL
setAny( const ::com::sun::star::uno::Any
& _any
) throw(::com::sun::star::uno::RuntimeException
)
183 virtual Sequence
< Reference
< XInterface
> > SAL_CALL
getSequence() throw(::com::sun::star::uno::RuntimeException
)
184 { return _aDummySequence
; }
185 virtual void SAL_CALL
setSequence( const Sequence
< Reference
< XInterface
> >& _sequence
) throw(::com::sun::star::uno::RuntimeException
)
187 virtual ComplexTypes SAL_CALL
getStruct() throw(::com::sun::star::uno::RuntimeException
)
188 { return _aDummyStruct
; }
189 virtual void SAL_CALL
setStruct( const ::com::sun::star::test::performance::ComplexTypes
& c
) throw(::com::sun::star::uno::RuntimeException
)
192 virtual void SAL_CALL
async() throw(::com::sun::star::uno::RuntimeException
)
194 virtual void SAL_CALL
sync() throw(::com::sun::star::uno::RuntimeException
)
196 virtual ComplexTypes SAL_CALL
complex_in( const ::com::sun::star::test::performance::ComplexTypes
& aVal
) throw(::com::sun::star::uno::RuntimeException
)
198 virtual ComplexTypes SAL_CALL
complex_inout( ::com::sun::star::test::performance::ComplexTypes
& aVal
) throw(::com::sun::star::uno::RuntimeException
)
200 virtual void SAL_CALL
complex_oneway( const ::com::sun::star::test::performance::ComplexTypes
& aVal
) throw(::com::sun::star::uno::RuntimeException
)
202 virtual void SAL_CALL
complex_noreturn( const ::com::sun::star::test::performance::ComplexTypes
& aVal
) throw(::com::sun::star::uno::RuntimeException
)
204 virtual Reference
< XPerformanceTest
> SAL_CALL
createObject() throw(::com::sun::star::uno::RuntimeException
)
205 { return new ServiceImpl(); }
206 virtual void SAL_CALL
raiseRuntimeException( ) throw(::com::sun::star::uno::RuntimeException
)
210 //##################################################################################################
213 //__________________________________________________________________________________________________
214 OUString
ServiceImpl::getImplementationName()
215 throw (RuntimeException
)
217 return OUString( RTL_CONSTASCII_USTRINGPARAM(IMPLNAME
) );
219 //__________________________________________________________________________________________________
220 sal_Bool
ServiceImpl::supportsService( const OUString
& rServiceName
)
221 throw (RuntimeException
)
223 const Sequence
< OUString
> & rSNL
= getSupportedServiceNames();
224 const OUString
* pArray
= rSNL
.getConstArray();
225 for ( sal_Int32 nPos
= rSNL
.getLength(); nPos
--; )
227 if (pArray
[nPos
] == rServiceName
)
232 //__________________________________________________________________________________________________
233 Sequence
< OUString
> ServiceImpl::getSupportedServiceNames()
234 throw (RuntimeException
)
236 return benchmark_object::getSupportedServiceNames();
241 //==================================================================================================
242 static Reference
< XInterface
> SAL_CALL
ServiceImpl_create( const Reference
< XMultiServiceFactory
> & xSMgr
)
244 return Reference
< XInterface
>( (XPerformanceTest
*)new ServiceImpl( xSMgr
) );
250 //##################################################################################################
251 //##################################################################################################
252 //##################################################################################################
257 //==================================================================================================
258 void SAL_CALL
component_getImplementationEnvironment(
259 const sal_Char
** ppEnvTypeName
, uno_Environment
** ppEnv
)
261 *ppEnvTypeName
= CPPU_CURRENT_LANGUAGE_BINDING_NAME
;
263 //==================================================================================================
264 sal_Bool SAL_CALL
component_writeInfo(
265 void * pServiceManager
, void * pRegistryKey
)
271 Reference
< XRegistryKey
> xNewKey(
272 reinterpret_cast< XRegistryKey
* >( pRegistryKey
)->createKey(
273 OUString( RTL_CONSTASCII_USTRINGPARAM("/" IMPLNAME
"/UNO/SERVICES") ) ) );
274 xNewKey
->createKey( OUString( RTL_CONSTASCII_USTRINGPARAM(SERVICENAME
) ) );
278 catch (InvalidRegistryException
&)
280 OSL_ENSURE( sal_False
, "### InvalidRegistryException!" );
285 //==================================================================================================
286 void * SAL_CALL
component_getFactory(
287 const sal_Char
* pImplName
, void * pServiceManager
, void * pRegistryKey
)
291 if (pServiceManager
&& rtl_str_compare( pImplName
, IMPLNAME
) == 0)
293 Reference
< XSingleServiceFactory
> xFactory( createSingleFactory(
294 reinterpret_cast< XMultiServiceFactory
* >( pServiceManager
),
295 OUString( RTL_CONSTASCII_USTRINGPARAM(IMPLNAME
) ),
296 benchmark_object::ServiceImpl_create
,
297 benchmark_object::getSupportedServiceNames() ) );
302 pRet
= xFactory
.get();