xref: /trunk/main/testtools/source/performance/ubobject.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
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.
14  *
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).
20  *
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.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_testtools.hxx"
30 
31 #include <osl/diagnose.h>
32 #include <osl/interlck.h>
33 
34 #include <cppuhelper/factory.hxx>
35 
36 #include <com/sun/star/lang/XServiceInfo.hpp>
37 #include <com/sun/star/lang/XComponent.hpp>
38 #include <com/sun/star/registry/XRegistryKey.hpp>
39 
40 #include <com/sun/star/test/performance/XPerformanceTest.hpp>
41 
42 using namespace rtl;
43 using namespace osl;
44 using namespace cppu;
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;
49 
50 #define SERVICENAME     "com.sun.star.test.performance.PerformanceTestObject"
51 #define IMPLNAME        "com.sun.star.comp.performance.PerformanceTestObject"
52 
53 namespace benchmark_object
54 {
55 
56 //--------------------------------------------------------------------------------------------------
57 inline static Sequence< OUString > getSupportedServiceNames()
58 {
59     OUString aName( RTL_CONSTASCII_USTRINGPARAM(SERVICENAME) );
60     return Sequence< OUString >( &aName, 1 );
61 }
62 
63 //==================================================================================================
64 class ServiceImpl
65     : public XServiceInfo
66     , public XPerformanceTest
67 {
68     OUString _aDummyString;
69     Any _aDummyAny;
70     Sequence< Reference< XInterface > > _aDummySequence;
71     ComplexTypes _aDummyStruct;
72     RuntimeException _aDummyRE;
73 
74     sal_Int32 _nRef;
75 
76 public:
77     ServiceImpl()
78         : _nRef( 0 )
79         {}
80     ServiceImpl( const Reference< XMultiServiceFactory > & xMgr )
81         : _nRef( 0 )
82         {}
83 
84     // XInterface
85     virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type& aType ) throw(::com::sun::star::uno::RuntimeException)
86     {
87         // execution time remains appr. constant any time
88         Any aRet;
89         if (aType == ::getCppuType( (const Reference< XInterface > *)0 ))
90         {
91             void * p = (XInterface *)(XPerformanceTest *)this;
92             aRet.setValue( &p, ::getCppuType( (const Reference< XInterface > *)0 ) );
93         }
94         if (aType == ::getCppuType( (const Reference< XPerformanceTest > *)0 ))
95         {
96             void * p = (XPerformanceTest *)this;
97             aRet.setValue( &p, ::getCppuType( (const Reference< XPerformanceTest > *)0 ) );
98         }
99         if (! aRet.hasValue())
100         {
101             void * p = (XPerformanceTest *)this;
102             Any aDummy( &p, ::getCppuType( (const Reference< XPerformanceTest > *)0 ) );
103         }
104         return aRet;
105     }
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; }
110 
111     // XServiceInfo
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);
115 
116     // Attributes
117     virtual sal_Int32 SAL_CALL getLong_attr() throw(::com::sun::star::uno::RuntimeException)
118         { return 0; }
119     virtual void SAL_CALL setLong_attr( sal_Int32 _attributelong ) throw(::com::sun::star::uno::RuntimeException)
120         {}
121     virtual sal_Int64 SAL_CALL getHyper_attr() throw(::com::sun::star::uno::RuntimeException)
122         { return 0; }
123     virtual void SAL_CALL setHyper_attr( sal_Int64 _attributehyper ) throw(::com::sun::star::uno::RuntimeException)
124         {}
125     virtual float SAL_CALL getFloat_attr() throw(::com::sun::star::uno::RuntimeException)
126         { return 0.0; }
127     virtual void SAL_CALL setFloat_attr( float _attributefloat ) throw(::com::sun::star::uno::RuntimeException)
128         {}
129     virtual double SAL_CALL getDouble_attr() throw(::com::sun::star::uno::RuntimeException)
130         { return 0.0; }
131     virtual void SAL_CALL setDouble_attr( double _attributedouble ) throw(::com::sun::star::uno::RuntimeException)
132         {}
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)
136         {}
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)
140         {}
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)
144         {}
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)
148         {}
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)
152         {}
153 
154     // Methods
155     virtual sal_Int32 SAL_CALL getLong() throw(::com::sun::star::uno::RuntimeException)
156         { return 0; }
157     virtual void SAL_CALL setLong( sal_Int32 _long ) throw(::com::sun::star::uno::RuntimeException)
158         {}
159     virtual sal_Int64 SAL_CALL getHyper() throw(::com::sun::star::uno::RuntimeException)
160         { return 0; }
161     virtual void SAL_CALL setHyper( sal_Int64 _hyper ) throw(::com::sun::star::uno::RuntimeException)
162         {}
163     virtual float SAL_CALL getFloat() throw(::com::sun::star::uno::RuntimeException)
164         { return 0; }
165     virtual void SAL_CALL setFloat( float _float ) throw(::com::sun::star::uno::RuntimeException)
166         {}
167     virtual double SAL_CALL getDouble() throw(::com::sun::star::uno::RuntimeException)
168         { return 0; }
169     virtual void SAL_CALL setDouble( double _double ) throw(::com::sun::star::uno::RuntimeException)
170         {}
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)
174         {}
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)
178         {}
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)
182         {}
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)
186         {}
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)
190         {}
191 
192     virtual void SAL_CALL async() throw(::com::sun::star::uno::RuntimeException)
193         {}
194     virtual void SAL_CALL sync() throw(::com::sun::star::uno::RuntimeException)
195         {}
196     virtual ComplexTypes SAL_CALL complex_in( const ::com::sun::star::test::performance::ComplexTypes& aVal ) throw(::com::sun::star::uno::RuntimeException)
197         { return aVal; }
198     virtual ComplexTypes SAL_CALL complex_inout( ::com::sun::star::test::performance::ComplexTypes& aVal ) throw(::com::sun::star::uno::RuntimeException)
199         { return aVal; }
200     virtual void SAL_CALL complex_oneway( const ::com::sun::star::test::performance::ComplexTypes& aVal ) throw(::com::sun::star::uno::RuntimeException)
201         {}
202     virtual void SAL_CALL complex_noreturn( const ::com::sun::star::test::performance::ComplexTypes& aVal ) throw(::com::sun::star::uno::RuntimeException)
203         {}
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)
207         { throw _aDummyRE; }
208 };
209 
210 //##################################################################################################
211 
212 // XServiceInfo
213 //__________________________________________________________________________________________________
214 OUString ServiceImpl::getImplementationName()
215     throw (RuntimeException)
216 {
217     return OUString( RTL_CONSTASCII_USTRINGPARAM(IMPLNAME) );
218 }
219 //__________________________________________________________________________________________________
220 sal_Bool ServiceImpl::supportsService( const OUString & rServiceName )
221     throw (RuntimeException)
222 {
223     const Sequence< OUString > & rSNL = getSupportedServiceNames();
224     const OUString * pArray = rSNL.getConstArray();
225     for ( sal_Int32 nPos = rSNL.getLength(); nPos--; )
226     {
227         if (pArray[nPos] == rServiceName)
228             return sal_True;
229     }
230     return sal_False;
231 }
232 //__________________________________________________________________________________________________
233 Sequence< OUString > ServiceImpl::getSupportedServiceNames()
234     throw (RuntimeException)
235 {
236     return benchmark_object::getSupportedServiceNames();
237 }
238 
239 // ...
240 
241 //==================================================================================================
242 static Reference< XInterface > SAL_CALL ServiceImpl_create( const Reference< XMultiServiceFactory > & xSMgr )
243 {
244     return Reference< XInterface >( (XPerformanceTest *)new ServiceImpl( xSMgr ) );
245 }
246 
247 }
248 
249 
250 //##################################################################################################
251 //##################################################################################################
252 //##################################################################################################
253 
254 
255 extern "C"
256 {
257 //==================================================================================================
258 void SAL_CALL component_getImplementationEnvironment(
259     const sal_Char ** ppEnvTypeName, uno_Environment ** ppEnv )
260 {
261     *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
262 }
263 //==================================================================================================
264 sal_Bool SAL_CALL component_writeInfo(
265     void * pServiceManager, void * pRegistryKey )
266 {
267     if (pRegistryKey)
268     {
269         try
270         {
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) ) );
275 
276             return sal_True;
277         }
278         catch (InvalidRegistryException &)
279         {
280             OSL_ENSURE( sal_False, "### InvalidRegistryException!" );
281         }
282     }
283     return sal_False;
284 }
285 //==================================================================================================
286 void * SAL_CALL component_getFactory(
287     const sal_Char * pImplName, void * pServiceManager, void * pRegistryKey )
288 {
289     void * pRet = 0;
290 
291     if (pServiceManager && rtl_str_compare( pImplName, IMPLNAME ) == 0)
292     {
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() ) );
298 
299         if (xFactory.is())
300         {
301             xFactory->acquire();
302             pRet = xFactory.get();
303         }
304     }
305 
306     return pRet;
307 }
308 }
309