Version 7.5.1.1, tag libreoffice-7.5.1.1
[LibreOffice.git] / testtools / source / performance / ubobject.cxx
blobacd199268f26851ee147b043d628c1f85b6e163f
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 return { SERVICENAME };
54 class ServiceImpl
55 : public XServiceInfo
56 , public XPerformanceTest
58 OUString _aDummyString;
59 Any _aDummyAny;
60 Sequence< Reference< XInterface > > _aDummySequence;
61 ComplexTypes _aDummyStruct;
62 RuntimeException _aDummyRE;
64 sal_Int32 _nRef;
66 public:
67 ServiceImpl()
68 : _nRef( 0 )
70 explicit ServiceImpl( const Reference< XMultiServiceFactory > & xMgr )
71 : _nRef( 0 )
74 // XInterface
75 virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type& aType ) throw(css::uno::RuntimeException)
77 // execution time remains appr. constant any time
78 Any aRet;
79 if (aType == cppu::UnoType<XInterface>::get())
81 void * p = (XInterface *)(XPerformanceTest *)this;
82 aRet.setValue( &p, cppu::UnoType<XInterface>::get() );
84 if (aType == cppu::UnoType<XPerformanceTest>::get())
86 void * p = (XPerformanceTest *)this;
87 aRet.setValue( &p, cppu::UnoType<XPerformanceTest>::get() );
89 if (! aRet.hasValue())
91 void * p = (XPerformanceTest *)this;
92 Any aDummy( &p, cppu::UnoType<XPerformanceTest>::get() );
94 return aRet;
96 virtual void SAL_CALL acquire() throw()
97 { osl_atomic_increment( &_nRef ); }
98 virtual void SAL_CALL release() throw()
99 { if (! osl_atomic_decrement( &_nRef )) delete this; }
101 // XServiceInfo
102 virtual OUString SAL_CALL getImplementationName() throw (RuntimeException);
103 virtual sal_Bool SAL_CALL supportsService( const OUString & rServiceName ) throw (RuntimeException);
104 virtual Sequence< OUString > SAL_CALL getSupportedServiceNames() throw (RuntimeException);
106 // Attributes
107 virtual sal_Int32 SAL_CALL getLong_attr() throw(css::uno::RuntimeException)
108 { return 0; }
109 virtual void SAL_CALL setLong_attr( sal_Int32 _attributelong ) throw(css::uno::RuntimeException)
111 virtual sal_Int64 SAL_CALL getHyper_attr() throw(css::uno::RuntimeException)
112 { return 0; }
113 virtual void SAL_CALL setHyper_attr( sal_Int64 _attributehyper ) throw(css::uno::RuntimeException)
115 virtual float SAL_CALL getFloat_attr() throw(css::uno::RuntimeException)
116 { return 0.0; }
117 virtual void SAL_CALL setFloat_attr( float _attributefloat ) throw(css::uno::RuntimeException)
119 virtual double SAL_CALL getDouble_attr() throw(css::uno::RuntimeException)
120 { return 0.0; }
121 virtual void SAL_CALL setDouble_attr( double _attributedouble ) throw(css::uno::RuntimeException)
123 virtual OUString SAL_CALL getString_attr() throw(css::uno::RuntimeException)
124 { return _aDummyString; }
125 virtual void SAL_CALL setString_attr( const OUString& _attributestring ) throw(css::uno::RuntimeException)
127 virtual Reference< XInterface > SAL_CALL getInterface_attr() throw(css::uno::RuntimeException)
128 { return Reference< XInterface >(); }
129 virtual void SAL_CALL setInterface_attr( const Reference< XInterface >& _attributeinterface ) throw(css::uno::RuntimeException)
131 virtual Any SAL_CALL getAny_attr() throw(css::uno::RuntimeException)
132 { return _aDummyAny; }
133 virtual void SAL_CALL setAny_attr( const Any& _attributeany ) throw(css::uno::RuntimeException)
135 virtual Sequence< Reference< XInterface > > SAL_CALL getSequence_attr() throw(css::uno::RuntimeException)
136 { return _aDummySequence; }
137 virtual void SAL_CALL setSequence_attr( const Sequence< Reference< XInterface > >& _attributesequence ) throw(css::uno::RuntimeException)
139 virtual ComplexTypes SAL_CALL getStruct_attr() throw(css::uno::RuntimeException)
140 { return _aDummyStruct; }
141 virtual void SAL_CALL setStruct_attr( const css::test::performance::ComplexTypes& _attributestruct ) throw(css::uno::RuntimeException)
144 // Methods
145 virtual sal_Int32 SAL_CALL getLong() throw(css::uno::RuntimeException)
146 { return 0; }
147 virtual void SAL_CALL setLong( sal_Int32 _long ) throw(css::uno::RuntimeException)
149 virtual sal_Int64 SAL_CALL getHyper() throw(css::uno::RuntimeException)
150 { return 0; }
151 virtual void SAL_CALL setHyper( sal_Int64 _hyper ) throw(css::uno::RuntimeException)
153 virtual float SAL_CALL getFloat() throw(css::uno::RuntimeException)
154 { return 0; }
155 virtual void SAL_CALL setFloat( float _float ) throw(css::uno::RuntimeException)
157 virtual double SAL_CALL getDouble() throw(css::uno::RuntimeException)
158 { return 0; }
159 virtual void SAL_CALL setDouble( double _double ) throw(css::uno::RuntimeException)
161 virtual OUString SAL_CALL getString() throw(css::uno::RuntimeException)
162 { return _aDummyString; }
163 virtual void SAL_CALL setString( const OUString& _string ) throw(css::uno::RuntimeException)
165 virtual Reference< XInterface > SAL_CALL getInterface() throw(css::uno::RuntimeException)
166 { return Reference< XInterface >(); }
167 virtual void SAL_CALL setInterface( const css::uno::Reference< css::uno::XInterface >& _interface ) throw(css::uno::RuntimeException)
169 virtual Any SAL_CALL getAny() throw(css::uno::RuntimeException)
170 { return _aDummyAny; }
171 virtual void SAL_CALL setAny( const css::uno::Any& _any ) throw(css::uno::RuntimeException)
173 virtual Sequence< Reference< XInterface > > SAL_CALL getSequence() throw(css::uno::RuntimeException)
174 { return _aDummySequence; }
175 virtual void SAL_CALL setSequence( const Sequence< Reference< XInterface > >& _sequence ) throw(css::uno::RuntimeException)
177 virtual ComplexTypes SAL_CALL getStruct() throw(css::uno::RuntimeException)
178 { return _aDummyStruct; }
179 virtual void SAL_CALL setStruct( const css::test::performance::ComplexTypes& c ) throw(css::uno::RuntimeException)
182 virtual void SAL_CALL async() throw(css::uno::RuntimeException)
184 virtual void SAL_CALL sync() throw(css::uno::RuntimeException)
186 virtual ComplexTypes SAL_CALL complexIn( const css::test::performance::ComplexTypes& aVal ) throw(css::uno::RuntimeException)
187 { return aVal; }
188 virtual ComplexTypes SAL_CALL complexInout( css::test::performance::ComplexTypes& aVal ) throw(css::uno::RuntimeException)
189 { return aVal; }
190 virtual void SAL_CALL complexOneway( const css::test::performance::ComplexTypes& aVal ) throw(css::uno::RuntimeException)
192 virtual void SAL_CALL complexNoreturn( const css::test::performance::ComplexTypes& aVal ) throw(css::uno::RuntimeException)
194 virtual Reference< XPerformanceTest > SAL_CALL createObject() throw(css::uno::RuntimeException)
195 { return new ServiceImpl(); }
196 virtual void SAL_CALL raiseRuntimeException( ) throw(css::uno::RuntimeException)
197 { throw _aDummyRE; }
201 // XServiceInfo
203 OUString ServiceImpl::getImplementationName()
204 throw (RuntimeException)
206 return OUString( IMPLNAME );
209 sal_Bool ServiceImpl::supportsService( const OUString & rServiceName )
210 throw (RuntimeException)
212 return cppu::supportsService(this, rServiceName);
215 Sequence< OUString > ServiceImpl::getSupportedServiceNames()
216 throw (RuntimeException)
218 return benchmark_object::getSupportedServiceNames();
222 static Reference< XInterface > SAL_CALL ServiceImpl_create( const Reference< XMultiServiceFactory > & xSMgr )
224 return Reference< XInterface >( (XPerformanceTest *)new ServiceImpl( xSMgr ) );
230 extern "C"
232 sal_Bool SAL_CALL component_writeInfo(
233 void * pServiceManager, void * pRegistryKey )
235 if (pRegistryKey)
239 Reference< XRegistryKey > xNewKey(
240 reinterpret_cast< XRegistryKey * >( pRegistryKey )->createKey(
241 OUString( ("/" IMPLNAME "/UNO/SERVICES") ) ) );
242 xNewKey->createKey( OUString( SERVICENAME ) );
244 return sal_True;
246 catch (InvalidRegistryException &)
248 OSL_FAIL( "### InvalidRegistryException!" );
251 return sal_False;
254 SAL_DLLPUBLIC_EXPORT void * SAL_CALL component_getFactory(
255 const char * pImplName, void * pServiceManager, void * pRegistryKey )
257 void * pRet = 0;
259 if (pServiceManager && rtl_str_compare( pImplName, IMPLNAME ) == 0)
261 Reference< XSingleServiceFactory > xFactory( createSingleFactory(
262 reinterpret_cast< XMultiServiceFactory * >( pServiceManager ),
263 OUString( IMPLNAME ),
264 benchmark_object::ServiceImpl_create,
265 benchmark_object::getSupportedServiceNames() ) );
267 if (xFactory.is())
269 xFactory->acquire();
270 pRet = xFactory.get();
274 return pRet;
278 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */