Version 4.0.0.1, tag libreoffice-4.0.0.1
[LibreOffice.git] / testtools / source / performance / ubobject.cxx
blob67ae101811372bc71057e3f8f22851669affa3f6
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <osl/diagnose.h>
22 #include <osl/interlck.h>
24 #include <cppuhelper/factory.hxx>
26 #include <com/sun/star/lang/XServiceInfo.hpp>
27 #include <com/sun/star/lang/XComponent.hpp>
28 #include <com/sun/star/registry/XRegistryKey.hpp>
30 #include <com/sun/star/test/performance/XPerformanceTest.hpp>
32 using namespace osl;
33 using namespace cppu;
34 using namespace com::sun::star::uno;
35 using namespace com::sun::star::lang;
36 using namespace com::sun::star::registry;
37 using namespace com::sun::star::test::performance;
39 using ::rtl::OUString;
41 #define SERVICENAME "com.sun.star.test.performance.PerformanceTestObject"
42 #define IMPLNAME "com.sun.star.comp.performance.PerformanceTestObject"
44 namespace benchmark_object
47 //--------------------------------------------------------------------------------------------------
48 inline static Sequence< OUString > getSupportedServiceNames()
50 OUString aName( RTL_CONSTASCII_USTRINGPARAM(SERVICENAME) );
51 return Sequence< OUString >( &aName, 1 );
54 //==================================================================================================
55 class ServiceImpl
56 : public XServiceInfo
57 , public XPerformanceTest
59 OUString _aDummyString;
60 Any _aDummyAny;
61 Sequence< Reference< XInterface > > _aDummySequence;
62 ComplexTypes _aDummyStruct;
63 RuntimeException _aDummyRE;
65 sal_Int32 _nRef;
67 public:
68 ServiceImpl()
69 : _nRef( 0 )
71 ServiceImpl( const Reference< XMultiServiceFactory > & xMgr )
72 : _nRef( 0 )
75 // XInterface
76 virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type& aType ) throw(::com::sun::star::uno::RuntimeException)
78 // execution time remains appr. constant any time
79 Any aRet;
80 if (aType == ::getCppuType( (const Reference< XInterface > *)0 ))
82 void * p = (XInterface *)(XPerformanceTest *)this;
83 aRet.setValue( &p, ::getCppuType( (const Reference< XInterface > *)0 ) );
85 if (aType == ::getCppuType( (const Reference< XPerformanceTest > *)0 ))
87 void * p = (XPerformanceTest *)this;
88 aRet.setValue( &p, ::getCppuType( (const Reference< XPerformanceTest > *)0 ) );
90 if (! aRet.hasValue())
92 void * p = (XPerformanceTest *)this;
93 Any aDummy( &p, ::getCppuType( (const Reference< XPerformanceTest > *)0 ) );
95 return aRet;
97 virtual void SAL_CALL acquire() throw()
98 { osl_atomic_increment( &_nRef ); }
99 virtual void SAL_CALL release() throw()
100 { if (! osl_atomic_decrement( &_nRef )) delete this; }
102 // XServiceInfo
103 virtual OUString SAL_CALL getImplementationName() throw (RuntimeException);
104 virtual sal_Bool SAL_CALL supportsService( const OUString & rServiceName ) throw (RuntimeException);
105 virtual Sequence< OUString > SAL_CALL getSupportedServiceNames() throw (RuntimeException);
107 // Attributes
108 virtual sal_Int32 SAL_CALL getLong_attr() throw(::com::sun::star::uno::RuntimeException)
109 { return 0; }
110 virtual void SAL_CALL setLong_attr( sal_Int32 _attributelong ) throw(::com::sun::star::uno::RuntimeException)
112 virtual sal_Int64 SAL_CALL getHyper_attr() throw(::com::sun::star::uno::RuntimeException)
113 { return 0; }
114 virtual void SAL_CALL setHyper_attr( sal_Int64 _attributehyper ) throw(::com::sun::star::uno::RuntimeException)
116 virtual float SAL_CALL getFloat_attr() throw(::com::sun::star::uno::RuntimeException)
117 { return 0.0; }
118 virtual void SAL_CALL setFloat_attr( float _attributefloat ) throw(::com::sun::star::uno::RuntimeException)
120 virtual double SAL_CALL getDouble_attr() throw(::com::sun::star::uno::RuntimeException)
121 { return 0.0; }
122 virtual void SAL_CALL setDouble_attr( double _attributedouble ) throw(::com::sun::star::uno::RuntimeException)
124 virtual OUString SAL_CALL getString_attr() throw(::com::sun::star::uno::RuntimeException)
125 { return _aDummyString; }
126 virtual void SAL_CALL setString_attr( const ::rtl::OUString& _attributestring ) throw(::com::sun::star::uno::RuntimeException)
128 virtual Reference< XInterface > SAL_CALL getInterface_attr() throw(::com::sun::star::uno::RuntimeException)
129 { return Reference< XInterface >(); }
130 virtual void SAL_CALL setInterface_attr( const Reference< XInterface >& _attributeinterface ) throw(::com::sun::star::uno::RuntimeException)
132 virtual Any SAL_CALL getAny_attr() throw(::com::sun::star::uno::RuntimeException)
133 { return _aDummyAny; }
134 virtual void SAL_CALL setAny_attr( const Any& _attributeany ) throw(::com::sun::star::uno::RuntimeException)
136 virtual Sequence< Reference< XInterface > > SAL_CALL getSequence_attr() throw(::com::sun::star::uno::RuntimeException)
137 { return _aDummySequence; }
138 virtual void SAL_CALL setSequence_attr( const Sequence< Reference< XInterface > >& _attributesequence ) throw(::com::sun::star::uno::RuntimeException)
140 virtual ComplexTypes SAL_CALL getStruct_attr() throw(::com::sun::star::uno::RuntimeException)
141 { return _aDummyStruct; }
142 virtual void SAL_CALL setStruct_attr( const ::com::sun::star::test::performance::ComplexTypes& _attributestruct ) throw(::com::sun::star::uno::RuntimeException)
145 // Methods
146 virtual sal_Int32 SAL_CALL getLong() throw(::com::sun::star::uno::RuntimeException)
147 { return 0; }
148 virtual void SAL_CALL setLong( sal_Int32 _long ) throw(::com::sun::star::uno::RuntimeException)
150 virtual sal_Int64 SAL_CALL getHyper() throw(::com::sun::star::uno::RuntimeException)
151 { return 0; }
152 virtual void SAL_CALL setHyper( sal_Int64 _hyper ) throw(::com::sun::star::uno::RuntimeException)
154 virtual float SAL_CALL getFloat() throw(::com::sun::star::uno::RuntimeException)
155 { return 0; }
156 virtual void SAL_CALL setFloat( float _float ) throw(::com::sun::star::uno::RuntimeException)
158 virtual double SAL_CALL getDouble() throw(::com::sun::star::uno::RuntimeException)
159 { return 0; }
160 virtual void SAL_CALL setDouble( double _double ) throw(::com::sun::star::uno::RuntimeException)
162 virtual OUString SAL_CALL getString() throw(::com::sun::star::uno::RuntimeException)
163 { return _aDummyString; }
164 virtual void SAL_CALL setString( const ::rtl::OUString& _string ) throw(::com::sun::star::uno::RuntimeException)
166 virtual Reference< XInterface > SAL_CALL getInterface() throw(::com::sun::star::uno::RuntimeException)
167 { return Reference< XInterface >(); }
168 virtual void SAL_CALL setInterface( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _interface ) throw(::com::sun::star::uno::RuntimeException)
170 virtual Any SAL_CALL getAny() throw(::com::sun::star::uno::RuntimeException)
171 { return _aDummyAny; }
172 virtual void SAL_CALL setAny( const ::com::sun::star::uno::Any& _any ) throw(::com::sun::star::uno::RuntimeException)
174 virtual Sequence< Reference< XInterface > > SAL_CALL getSequence() throw(::com::sun::star::uno::RuntimeException)
175 { return _aDummySequence; }
176 virtual void SAL_CALL setSequence( const Sequence< Reference< XInterface > >& _sequence ) throw(::com::sun::star::uno::RuntimeException)
178 virtual ComplexTypes SAL_CALL getStruct() throw(::com::sun::star::uno::RuntimeException)
179 { return _aDummyStruct; }
180 virtual void SAL_CALL setStruct( const ::com::sun::star::test::performance::ComplexTypes& c ) throw(::com::sun::star::uno::RuntimeException)
183 virtual void SAL_CALL async() throw(::com::sun::star::uno::RuntimeException)
185 virtual void SAL_CALL sync() throw(::com::sun::star::uno::RuntimeException)
187 virtual ComplexTypes SAL_CALL complex_in( const ::com::sun::star::test::performance::ComplexTypes& aVal ) throw(::com::sun::star::uno::RuntimeException)
188 { return aVal; }
189 virtual ComplexTypes SAL_CALL complex_inout( ::com::sun::star::test::performance::ComplexTypes& aVal ) throw(::com::sun::star::uno::RuntimeException)
190 { return aVal; }
191 virtual void SAL_CALL complex_oneway( const ::com::sun::star::test::performance::ComplexTypes& aVal ) throw(::com::sun::star::uno::RuntimeException)
193 virtual void SAL_CALL complex_noreturn( const ::com::sun::star::test::performance::ComplexTypes& aVal ) throw(::com::sun::star::uno::RuntimeException)
195 virtual Reference< XPerformanceTest > SAL_CALL createObject() throw(::com::sun::star::uno::RuntimeException)
196 { return new ServiceImpl(); }
197 virtual void SAL_CALL raiseRuntimeException( ) throw(::com::sun::star::uno::RuntimeException)
198 { throw _aDummyRE; }
201 //##################################################################################################
203 // XServiceInfo
204 //__________________________________________________________________________________________________
205 OUString ServiceImpl::getImplementationName()
206 throw (RuntimeException)
208 return OUString( RTL_CONSTASCII_USTRINGPARAM(IMPLNAME) );
210 //__________________________________________________________________________________________________
211 sal_Bool ServiceImpl::supportsService( const OUString & rServiceName )
212 throw (RuntimeException)
214 const Sequence< OUString > & rSNL = getSupportedServiceNames();
215 const OUString * pArray = rSNL.getConstArray();
216 for ( sal_Int32 nPos = rSNL.getLength(); nPos--; )
218 if (pArray[nPos] == rServiceName)
219 return sal_True;
221 return sal_False;
223 //__________________________________________________________________________________________________
224 Sequence< OUString > ServiceImpl::getSupportedServiceNames()
225 throw (RuntimeException)
227 return benchmark_object::getSupportedServiceNames();
230 // ...
232 //==================================================================================================
233 static Reference< XInterface > SAL_CALL ServiceImpl_create( const Reference< XMultiServiceFactory > & xSMgr )
235 return Reference< XInterface >( (XPerformanceTest *)new ServiceImpl( xSMgr ) );
241 //##################################################################################################
242 //##################################################################################################
243 //##################################################################################################
246 extern "C"
248 sal_Bool SAL_CALL component_writeInfo(
249 void * pServiceManager, void * pRegistryKey )
251 if (pRegistryKey)
255 Reference< XRegistryKey > xNewKey(
256 reinterpret_cast< XRegistryKey * >( pRegistryKey )->createKey(
257 OUString( RTL_CONSTASCII_USTRINGPARAM("/" IMPLNAME "/UNO/SERVICES") ) ) );
258 xNewKey->createKey( OUString( RTL_CONSTASCII_USTRINGPARAM(SERVICENAME) ) );
260 return sal_True;
262 catch (InvalidRegistryException &)
264 OSL_FAIL( "### InvalidRegistryException!" );
267 return sal_False;
269 //==================================================================================================
270 SAL_DLLPUBLIC_EXPORT void * SAL_CALL component_getFactory(
271 const sal_Char * pImplName, void * pServiceManager, void * pRegistryKey )
273 void * pRet = 0;
275 if (pServiceManager && rtl_str_compare( pImplName, IMPLNAME ) == 0)
277 Reference< XSingleServiceFactory > xFactory( createSingleFactory(
278 reinterpret_cast< XMultiServiceFactory * >( pServiceManager ),
279 OUString( RTL_CONSTASCII_USTRINGPARAM(IMPLNAME) ),
280 benchmark_object::ServiceImpl_create,
281 benchmark_object::getSupportedServiceNames() ) );
283 if (xFactory.is())
285 xFactory->acquire();
286 pRet = xFactory.get();
290 return pRet;
294 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */