1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ubobject.cxx,v $
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>
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 //==================================================================================================
69 , public XPerformanceTest
71 OUString _aDummyString
;
73 Sequence
< Reference
< XInterface
> > _aDummySequence
;
74 ComplexTypes _aDummyStruct
;
75 RuntimeException _aDummyRE
;
83 ServiceImpl( const Reference
< XMultiServiceFactory
> & xMgr
)
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
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 ) );
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; }
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
);
120 virtual sal_Int32 SAL_CALL
getLong_attr() throw(::com::sun::star::uno::RuntimeException
)
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
)
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
)
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
)
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
)
158 virtual sal_Int32 SAL_CALL
getLong() throw(::com::sun::star::uno::RuntimeException
)
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
)
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
)
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
)
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
)
201 virtual ComplexTypes SAL_CALL
complex_inout( ::com::sun::star::test::performance::ComplexTypes
& aVal
) throw(::com::sun::star::uno::RuntimeException
)
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
)
213 //##################################################################################################
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
)
235 //__________________________________________________________________________________________________
236 Sequence
< OUString
> ServiceImpl::getSupportedServiceNames()
237 throw (RuntimeException
)
239 return benchmark_object::getSupportedServiceNames();
244 //==================================================================================================
245 static Reference
< XInterface
> SAL_CALL
ServiceImpl_create( const Reference
< XMultiServiceFactory
> & xSMgr
)
247 return Reference
< XInterface
>( (XPerformanceTest
*)new ServiceImpl( xSMgr
) );
253 //##################################################################################################
254 //##################################################################################################
255 //##################################################################################################
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
)
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
) ) );
281 catch (InvalidRegistryException
&)
283 OSL_ENSURE( sal_False
, "### InvalidRegistryException!" );
288 //==================================================================================================
289 void * SAL_CALL
component_getFactory(
290 const sal_Char
* pImplName
, void * pServiceManager
, void * pRegistryKey
)
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() ) );
305 pRet
= xFactory
.get();