xref: /trunk/main/testtools/source/performance/ubobject.cxx (revision f3385db031069db3e0655c6a4d85518bf39a7b68)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_testtools.hxx"
26 
27 #include <osl/diagnose.h>
28 #include <osl/interlck.h>
29 
30 #include <cppuhelper/factory.hxx>
31 
32 #include <com/sun/star/lang/XServiceInfo.hpp>
33 #include <com/sun/star/lang/XComponent.hpp>
34 #include <com/sun/star/registry/XRegistryKey.hpp>
35 
36 #include <com/sun/star/test/performance/XPerformanceTest.hpp>
37 
38 using namespace rtl;
39 using namespace osl;
40 using namespace cppu;
41 using namespace com::sun::star::uno;
42 using namespace com::sun::star::lang;
43 using namespace com::sun::star::registry;
44 using namespace com::sun::star::test::performance;
45 
46 #define SERVICENAME     "com.sun.star.test.performance.PerformanceTestObject"
47 #define IMPLNAME        "com.sun.star.comp.performance.PerformanceTestObject"
48 
49 namespace benchmark_object
50 {
51 
52 //--------------------------------------------------------------------------------------------------
53 inline static Sequence< OUString > getSupportedServiceNames()
54 {
55     OUString aName( RTL_CONSTASCII_USTRINGPARAM(SERVICENAME) );
56     return Sequence< OUString >( &aName, 1 );
57 }
58 
59 //==================================================================================================
60 class ServiceImpl
61     : public XServiceInfo
62     , public XPerformanceTest
63 {
64     OUString _aDummyString;
65     Any _aDummyAny;
66     Sequence< Reference< XInterface > > _aDummySequence;
67     ComplexTypes _aDummyStruct;
68     RuntimeException _aDummyRE;
69 
70     sal_Int32 _nRef;
71 
72 public:
73     ServiceImpl()
74         : _nRef( 0 )
75         {}
76     ServiceImpl( const Reference< XMultiServiceFactory > & xMgr )
77         : _nRef( 0 )
78         {}
79 
80     // XInterface
81     virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type& aType )
82     {
83         // execution time remains appr. constant any time
84         Any aRet;
85         if (aType == ::getCppuType( (const Reference< XInterface > *)0 ))
86         {
87             void * p = (XInterface *)(XPerformanceTest *)this;
88             aRet.setValue( &p, ::getCppuType( (const Reference< XInterface > *)0 ) );
89         }
90         if (aType == ::getCppuType( (const Reference< XPerformanceTest > *)0 ))
91         {
92             void * p = (XPerformanceTest *)this;
93             aRet.setValue( &p, ::getCppuType( (const Reference< XPerformanceTest > *)0 ) );
94         }
95         if (! aRet.hasValue())
96         {
97             void * p = (XPerformanceTest *)this;
98             Any aDummy( &p, ::getCppuType( (const Reference< XPerformanceTest > *)0 ) );
99         }
100         return aRet;
101     }
102     virtual void SAL_CALL acquire() throw()
103         { osl_incrementInterlockedCount( &_nRef ); }
104     virtual void SAL_CALL release() throw()
105         { if (! osl_decrementInterlockedCount( &_nRef )) delete this; }
106 
107     // XServiceInfo
108     virtual OUString SAL_CALL getImplementationName();
109     virtual sal_Bool SAL_CALL supportsService( const OUString & rServiceName );
110     virtual Sequence< OUString > SAL_CALL getSupportedServiceNames();
111 
112     // Attributes
113     virtual sal_Int32 SAL_CALL getLong_attr()
114         { return 0; }
115     virtual void SAL_CALL setLong_attr( sal_Int32 _attributelong )
116         {}
117     virtual sal_Int64 SAL_CALL getHyper_attr()
118         { return 0; }
119     virtual void SAL_CALL setHyper_attr( sal_Int64 _attributehyper )
120         {}
121     virtual float SAL_CALL getFloat_attr()
122         { return 0.0; }
123     virtual void SAL_CALL setFloat_attr( float _attributefloat )
124         {}
125     virtual double SAL_CALL getDouble_attr()
126         { return 0.0; }
127     virtual void SAL_CALL setDouble_attr( double _attributedouble )
128         {}
129     virtual OUString SAL_CALL getString_attr()
130         { return _aDummyString; }
131     virtual void SAL_CALL setString_attr( const ::rtl::OUString& _attributestring )
132         {}
133     virtual Reference< XInterface > SAL_CALL getInterface_attr()
134         { return Reference< XInterface >(); }
135     virtual void SAL_CALL setInterface_attr( const Reference< XInterface >& _attributeinterface )
136         {}
137     virtual Any SAL_CALL getAny_attr()
138         { return _aDummyAny; }
139     virtual void SAL_CALL setAny_attr( const Any& _attributeany )
140         {}
141     virtual Sequence< Reference< XInterface > > SAL_CALL getSequence_attr()
142         { return _aDummySequence; }
143     virtual void SAL_CALL setSequence_attr( const Sequence< Reference< XInterface > >& _attributesequence )
144         {}
145     virtual ComplexTypes SAL_CALL getStruct_attr()
146         { return _aDummyStruct; }
147     virtual void SAL_CALL setStruct_attr( const ::com::sun::star::test::performance::ComplexTypes& _attributestruct )
148         {}
149 
150     // Methods
151     virtual sal_Int32 SAL_CALL getLong()
152         { return 0; }
153     virtual void SAL_CALL setLong( sal_Int32 _long )
154         {}
155     virtual sal_Int64 SAL_CALL getHyper()
156         { return 0; }
157     virtual void SAL_CALL setHyper( sal_Int64 _hyper )
158         {}
159     virtual float SAL_CALL getFloat()
160         { return 0; }
161     virtual void SAL_CALL setFloat( float _float )
162         {}
163     virtual double SAL_CALL getDouble()
164         { return 0; }
165     virtual void SAL_CALL setDouble( double _double )
166         {}
167     virtual OUString SAL_CALL getString()
168         { return _aDummyString; }
169     virtual void SAL_CALL setString( const ::rtl::OUString& _string )
170         {}
171     virtual Reference< XInterface > SAL_CALL getInterface()
172         { return Reference< XInterface >(); }
173     virtual void SAL_CALL setInterface( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _interface )
174         {}
175     virtual Any SAL_CALL getAny()
176         { return _aDummyAny; }
177     virtual void SAL_CALL setAny( const ::com::sun::star::uno::Any& _any )
178         {}
179     virtual Sequence< Reference< XInterface > > SAL_CALL getSequence()
180         { return _aDummySequence; }
181     virtual void SAL_CALL setSequence( const Sequence< Reference< XInterface > >& _sequence )
182         {}
183     virtual ComplexTypes SAL_CALL getStruct()
184         { return _aDummyStruct; }
185     virtual void SAL_CALL setStruct( const ::com::sun::star::test::performance::ComplexTypes& c )
186         {}
187 
188     virtual void SAL_CALL async()
189         {}
190     virtual void SAL_CALL sync()
191         {}
192     virtual ComplexTypes SAL_CALL complex_in( const ::com::sun::star::test::performance::ComplexTypes& aVal )
193         { return aVal; }
194     virtual ComplexTypes SAL_CALL complex_inout( ::com::sun::star::test::performance::ComplexTypes& aVal )
195         { return aVal; }
196     virtual void SAL_CALL complex_oneway( const ::com::sun::star::test::performance::ComplexTypes& aVal )
197         {}
198     virtual void SAL_CALL complex_noreturn( const ::com::sun::star::test::performance::ComplexTypes& aVal )
199         {}
200     virtual Reference< XPerformanceTest > SAL_CALL createObject()
201         { return new ServiceImpl(); }
202     virtual void SAL_CALL raiseRuntimeException(  )
203         { throw _aDummyRE; }
204 };
205 
206 //##################################################################################################
207 
208 // XServiceInfo
209 //__________________________________________________________________________________________________
210 OUString ServiceImpl::getImplementationName()
211 {
212     return OUString( RTL_CONSTASCII_USTRINGPARAM(IMPLNAME) );
213 }
214 //__________________________________________________________________________________________________
215 sal_Bool ServiceImpl::supportsService( const OUString & rServiceName )
216 {
217     const Sequence< OUString > & rSNL = getSupportedServiceNames();
218     const OUString * pArray = rSNL.getConstArray();
219     for ( sal_Int32 nPos = rSNL.getLength(); nPos--; )
220     {
221         if (pArray[nPos] == rServiceName)
222             return sal_True;
223     }
224     return sal_False;
225 }
226 //__________________________________________________________________________________________________
227 Sequence< OUString > ServiceImpl::getSupportedServiceNames()
228 {
229     return benchmark_object::getSupportedServiceNames();
230 }
231 
232 // ...
233 
234 //==================================================================================================
235 static Reference< XInterface > SAL_CALL ServiceImpl_create( const Reference< XMultiServiceFactory > & xSMgr )
236 {
237     return Reference< XInterface >( (XPerformanceTest *)new ServiceImpl( xSMgr ) );
238 }
239 
240 }
241 
242 
243 //##################################################################################################
244 //##################################################################################################
245 //##################################################################################################
246 
247 
248 extern "C"
249 {
250 //==================================================================================================
251 void SAL_CALL component_getImplementationEnvironment(
252     const sal_Char ** ppEnvTypeName, uno_Environment ** ppEnv )
253 {
254     *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
255 }
256 //==================================================================================================
257 sal_Bool SAL_CALL component_writeInfo(
258     void * pServiceManager, void * pRegistryKey )
259 {
260     if (pRegistryKey)
261     {
262         try
263         {
264             Reference< XRegistryKey > xNewKey(
265                 reinterpret_cast< XRegistryKey * >( pRegistryKey )->createKey(
266                     OUString( RTL_CONSTASCII_USTRINGPARAM("/" IMPLNAME "/UNO/SERVICES") ) ) );
267             xNewKey->createKey( OUString( RTL_CONSTASCII_USTRINGPARAM(SERVICENAME) ) );
268 
269             return sal_True;
270         }
271         catch (InvalidRegistryException &)
272         {
273             OSL_ENSURE( sal_False, "### InvalidRegistryException!" );
274         }
275     }
276     return sal_False;
277 }
278 //==================================================================================================
279 void * SAL_CALL component_getFactory(
280     const sal_Char * pImplName, void * pServiceManager, void * pRegistryKey )
281 {
282     void * pRet = 0;
283 
284     if (pServiceManager && rtl_str_compare( pImplName, IMPLNAME ) == 0)
285     {
286         Reference< XSingleServiceFactory > xFactory( createSingleFactory(
287             reinterpret_cast< XMultiServiceFactory * >( pServiceManager ),
288             OUString( RTL_CONSTASCII_USTRINGPARAM(IMPLNAME) ),
289             benchmark_object::ServiceImpl_create,
290             benchmark_object::getSupportedServiceNames() ) );
291 
292         if (xFactory.is())
293         {
294             xFactory->acquire();
295             pRet = xFactory.get();
296         }
297     }
298 
299     return pRet;
300 }
301 }
302