Branch libreoffice-5-0-4
[LibreOffice.git] / testtools / source / performance / ubobject.cxx
blob972f53e28646be00556da7b976d55b8622b7d45a
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>
25 #include <cppuhelper/supportsservice.hxx>
27 #include <com/sun/star/lang/XServiceInfo.hpp>
28 #include <com/sun/star/lang/XComponent.hpp>
29 #include <com/sun/star/registry/XRegistryKey.hpp>
31 #include <com/sun/star/test/performance/XPerformanceTest.hpp>
33 using namespace osl;
34 using namespace cppu;
35 using namespace com::sun::star::uno;
36 using namespace com::sun::star::lang;
37 using namespace com::sun::star::registry;
38 using namespace com::sun::star::test::performance;
41 #define SERVICENAME "com.sun.star.test.performance.PerformanceTestObject"
42 #define IMPLNAME "com.sun.star.comp.performance.PerformanceTestObject"
44 namespace benchmark_object
48 inline static Sequence< OUString > getSupportedServiceNames()
50 OUString aName( SERVICENAME);
51 return Sequence< OUString >( &aName, 1 );
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 == cppu::UnoType<XInterface>::get())
82 void * p = (XInterface *)(XPerformanceTest *)this;
83 aRet.setValue( &p, cppu::UnoType<XInterface>::get() );
85 if (aType == cppu::UnoType<XPerformanceTest>::get())
87 void * p = (XPerformanceTest *)this;
88 aRet.setValue( &p, cppu::UnoType<XPerformanceTest>::get() );
90 if (! aRet.hasValue())
92 void * p = (XPerformanceTest *)this;
93 Any aDummy( &p, cppu::UnoType<XPerformanceTest>::get() );
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 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 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; }
203 // XServiceInfo
205 OUString ServiceImpl::getImplementationName()
206 throw (RuntimeException)
208 return OUString( IMPLNAME );
211 sal_Bool ServiceImpl::supportsService( const OUString & rServiceName )
212 throw (RuntimeException)
214 return cppu::supportsService(this, rServiceName);
217 Sequence< OUString > ServiceImpl::getSupportedServiceNames()
218 throw (RuntimeException)
220 return benchmark_object::getSupportedServiceNames();
226 static Reference< XInterface > SAL_CALL ServiceImpl_create( const Reference< XMultiServiceFactory > & xSMgr )
228 return Reference< XInterface >( (XPerformanceTest *)new ServiceImpl( xSMgr ) );
239 extern "C"
241 sal_Bool SAL_CALL component_writeInfo(
242 void * pServiceManager, void * pRegistryKey )
244 if (pRegistryKey)
248 Reference< XRegistryKey > xNewKey(
249 reinterpret_cast< XRegistryKey * >( pRegistryKey )->createKey(
250 OUString( ("/" IMPLNAME "/UNO/SERVICES") ) ) );
251 xNewKey->createKey( OUString( SERVICENAME ) );
253 return sal_True;
255 catch (InvalidRegistryException &)
257 OSL_FAIL( "### InvalidRegistryException!" );
260 return sal_False;
263 SAL_DLLPUBLIC_EXPORT void * SAL_CALL component_getFactory(
264 const sal_Char * pImplName, void * pServiceManager, void * pRegistryKey )
266 void * pRet = 0;
268 if (pServiceManager && rtl_str_compare( pImplName, IMPLNAME ) == 0)
270 Reference< XSingleServiceFactory > xFactory( createSingleFactory(
271 reinterpret_cast< XMultiServiceFactory * >( pServiceManager ),
272 OUString( IMPLNAME ),
273 benchmark_object::ServiceImpl_create,
274 benchmark_object::getSupportedServiceNames() ) );
276 if (xFactory.is())
278 xFactory->acquire();
279 pRet = xFactory.get();
283 return pRet;
287 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */