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 //--------------------------------------------------------------------------------------------------
getSupportedServiceNames()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:
ServiceImpl()73 	ServiceImpl()
74 		: _nRef( 0 )
75 		{}
ServiceImpl(const Reference<XMultiServiceFactory> & xMgr)76 	ServiceImpl( const Reference< XMultiServiceFactory > & xMgr )
77 		: _nRef( 0 )
78 		{}
79 
80 	// XInterface
queryInterface(const::com::sun::star::uno::Type & aType)81     virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type& aType ) throw(::com::sun::star::uno::RuntimeException)
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 	}
acquire()102     virtual void SAL_CALL acquire() throw()
103 		{ osl_incrementInterlockedCount( &_nRef ); }
release()104     virtual void SAL_CALL release() throw()
105 		{ if (! osl_decrementInterlockedCount( &_nRef )) delete this; }
106 
107 	// XServiceInfo
108 	virtual OUString SAL_CALL getImplementationName() throw (RuntimeException);
109 	virtual sal_Bool SAL_CALL supportsService( const OUString & rServiceName ) throw (RuntimeException);
110 	virtual Sequence< OUString > SAL_CALL getSupportedServiceNames() throw (RuntimeException);
111 
112     // Attributes
getLong_attr()113     virtual sal_Int32 SAL_CALL getLong_attr() throw(::com::sun::star::uno::RuntimeException)
114 		{ return 0; }
setLong_attr(sal_Int32 _attributelong)115     virtual void SAL_CALL setLong_attr( sal_Int32 _attributelong ) throw(::com::sun::star::uno::RuntimeException)
116 		{}
getHyper_attr()117     virtual sal_Int64 SAL_CALL getHyper_attr() throw(::com::sun::star::uno::RuntimeException)
118 		{ return 0; }
setHyper_attr(sal_Int64 _attributehyper)119     virtual void SAL_CALL setHyper_attr( sal_Int64 _attributehyper ) throw(::com::sun::star::uno::RuntimeException)
120 		{}
getFloat_attr()121     virtual float SAL_CALL getFloat_attr() throw(::com::sun::star::uno::RuntimeException)
122 		{ return 0.0; }
setFloat_attr(float _attributefloat)123     virtual void SAL_CALL setFloat_attr( float _attributefloat ) throw(::com::sun::star::uno::RuntimeException)
124 		{}
getDouble_attr()125     virtual double SAL_CALL getDouble_attr() throw(::com::sun::star::uno::RuntimeException)
126 		{ return 0.0; }
setDouble_attr(double _attributedouble)127     virtual void SAL_CALL setDouble_attr( double _attributedouble ) throw(::com::sun::star::uno::RuntimeException)
128 		{}
getString_attr()129     virtual OUString SAL_CALL getString_attr() throw(::com::sun::star::uno::RuntimeException)
130 		{ return _aDummyString; }
setString_attr(const::rtl::OUString & _attributestring)131     virtual void SAL_CALL setString_attr( const ::rtl::OUString& _attributestring ) throw(::com::sun::star::uno::RuntimeException)
132 		{}
getInterface_attr()133     virtual Reference< XInterface > SAL_CALL getInterface_attr() throw(::com::sun::star::uno::RuntimeException)
134 		{ return Reference< XInterface >(); }
setInterface_attr(const Reference<XInterface> & _attributeinterface)135     virtual void SAL_CALL setInterface_attr( const Reference< XInterface >& _attributeinterface ) throw(::com::sun::star::uno::RuntimeException)
136 		{}
getAny_attr()137     virtual Any SAL_CALL getAny_attr() throw(::com::sun::star::uno::RuntimeException)
138 		{ return _aDummyAny; }
setAny_attr(const Any & _attributeany)139     virtual void SAL_CALL setAny_attr( const Any& _attributeany ) throw(::com::sun::star::uno::RuntimeException)
140 		{}
getSequence_attr()141     virtual Sequence< Reference< XInterface > > SAL_CALL getSequence_attr() throw(::com::sun::star::uno::RuntimeException)
142 		{ return _aDummySequence; }
setSequence_attr(const Sequence<Reference<XInterface>> & _attributesequence)143     virtual void SAL_CALL setSequence_attr( const Sequence< Reference< XInterface > >& _attributesequence ) throw(::com::sun::star::uno::RuntimeException)
144 		{}
getStruct_attr()145     virtual ComplexTypes SAL_CALL getStruct_attr() throw(::com::sun::star::uno::RuntimeException)
146 		{ return _aDummyStruct; }
setStruct_attr(const::com::sun::star::test::performance::ComplexTypes & _attributestruct)147     virtual void SAL_CALL setStruct_attr( const ::com::sun::star::test::performance::ComplexTypes& _attributestruct ) throw(::com::sun::star::uno::RuntimeException)
148 		{}
149 
150     // Methods
getLong()151     virtual sal_Int32 SAL_CALL getLong() throw(::com::sun::star::uno::RuntimeException)
152 		{ return 0; }
setLong(sal_Int32 _long)153     virtual void SAL_CALL setLong( sal_Int32 _long ) throw(::com::sun::star::uno::RuntimeException)
154 		{}
getHyper()155     virtual sal_Int64 SAL_CALL getHyper() throw(::com::sun::star::uno::RuntimeException)
156 		{ return 0; }
setHyper(sal_Int64 _hyper)157     virtual void SAL_CALL setHyper( sal_Int64 _hyper ) throw(::com::sun::star::uno::RuntimeException)
158 		{}
getFloat()159     virtual float SAL_CALL getFloat() throw(::com::sun::star::uno::RuntimeException)
160 		{ return 0; }
setFloat(float _float)161     virtual void SAL_CALL setFloat( float _float ) throw(::com::sun::star::uno::RuntimeException)
162 		{}
getDouble()163     virtual double SAL_CALL getDouble() throw(::com::sun::star::uno::RuntimeException)
164 		{ return 0; }
setDouble(double _double)165     virtual void SAL_CALL setDouble( double _double ) throw(::com::sun::star::uno::RuntimeException)
166 		{}
getString()167     virtual OUString SAL_CALL getString() throw(::com::sun::star::uno::RuntimeException)
168 		{ return _aDummyString; }
setString(const::rtl::OUString & _string)169     virtual void SAL_CALL setString( const ::rtl::OUString& _string ) throw(::com::sun::star::uno::RuntimeException)
170 		{}
getInterface()171     virtual Reference< XInterface > SAL_CALL getInterface() throw(::com::sun::star::uno::RuntimeException)
172 		{ return Reference< XInterface >(); }
setInterface(const::com::sun::star::uno::Reference<::com::sun::star::uno::XInterface> & _interface)173     virtual void SAL_CALL setInterface( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _interface ) throw(::com::sun::star::uno::RuntimeException)
174 		{}
getAny()175     virtual Any SAL_CALL getAny() throw(::com::sun::star::uno::RuntimeException)
176 		{ return _aDummyAny; }
setAny(const::com::sun::star::uno::Any & _any)177     virtual void SAL_CALL setAny( const ::com::sun::star::uno::Any& _any ) throw(::com::sun::star::uno::RuntimeException)
178 		{}
getSequence()179     virtual Sequence< Reference< XInterface > > SAL_CALL getSequence() throw(::com::sun::star::uno::RuntimeException)
180 		{ return _aDummySequence; }
setSequence(const Sequence<Reference<XInterface>> & _sequence)181     virtual void SAL_CALL setSequence( const Sequence< Reference< XInterface > >& _sequence ) throw(::com::sun::star::uno::RuntimeException)
182 		{}
getStruct()183     virtual ComplexTypes SAL_CALL getStruct() throw(::com::sun::star::uno::RuntimeException)
184 		{ return _aDummyStruct; }
setStruct(const::com::sun::star::test::performance::ComplexTypes & c)185     virtual void SAL_CALL setStruct( const ::com::sun::star::test::performance::ComplexTypes& c ) throw(::com::sun::star::uno::RuntimeException)
186 		{}
187 
async()188     virtual void SAL_CALL async() throw(::com::sun::star::uno::RuntimeException)
189 		{}
sync()190     virtual void SAL_CALL sync() throw(::com::sun::star::uno::RuntimeException)
191 		{}
complex_in(const::com::sun::star::test::performance::ComplexTypes & aVal)192     virtual ComplexTypes SAL_CALL complex_in( const ::com::sun::star::test::performance::ComplexTypes& aVal ) throw(::com::sun::star::uno::RuntimeException)
193 		{ return aVal; }
complex_inout(::com::sun::star::test::performance::ComplexTypes & aVal)194     virtual ComplexTypes SAL_CALL complex_inout( ::com::sun::star::test::performance::ComplexTypes& aVal ) throw(::com::sun::star::uno::RuntimeException)
195 		{ return aVal; }
complex_oneway(const::com::sun::star::test::performance::ComplexTypes & aVal)196     virtual void SAL_CALL complex_oneway( const ::com::sun::star::test::performance::ComplexTypes& aVal ) throw(::com::sun::star::uno::RuntimeException)
197 		{}
complex_noreturn(const::com::sun::star::test::performance::ComplexTypes & aVal)198     virtual void SAL_CALL complex_noreturn( const ::com::sun::star::test::performance::ComplexTypes& aVal ) throw(::com::sun::star::uno::RuntimeException)
199 		{}
createObject()200     virtual Reference< XPerformanceTest > SAL_CALL createObject() throw(::com::sun::star::uno::RuntimeException)
201 		{ return new ServiceImpl(); }
raiseRuntimeException()202     virtual void SAL_CALL raiseRuntimeException(  ) throw(::com::sun::star::uno::RuntimeException)
203 		{ throw _aDummyRE; }
204 };
205 
206 //##################################################################################################
207 
208 // XServiceInfo
209 //__________________________________________________________________________________________________
getImplementationName()210 OUString ServiceImpl::getImplementationName()
211 	throw (RuntimeException)
212 {
213 	return OUString( RTL_CONSTASCII_USTRINGPARAM(IMPLNAME) );
214 }
215 //__________________________________________________________________________________________________
supportsService(const OUString & rServiceName)216 sal_Bool ServiceImpl::supportsService( const OUString & rServiceName )
217 	throw (RuntimeException)
218 {
219 	const Sequence< OUString > & rSNL = getSupportedServiceNames();
220 	const OUString * pArray = rSNL.getConstArray();
221 	for ( sal_Int32 nPos = rSNL.getLength(); nPos--; )
222 	{
223 		if (pArray[nPos] == rServiceName)
224 			return sal_True;
225 	}
226 	return sal_False;
227 }
228 //__________________________________________________________________________________________________
getSupportedServiceNames()229 Sequence< OUString > ServiceImpl::getSupportedServiceNames()
230 	throw (RuntimeException)
231 {
232 	return benchmark_object::getSupportedServiceNames();
233 }
234 
235 // ...
236 
237 //==================================================================================================
ServiceImpl_create(const Reference<XMultiServiceFactory> & xSMgr)238 static Reference< XInterface > SAL_CALL ServiceImpl_create( const Reference< XMultiServiceFactory > & xSMgr )
239 {
240 	return Reference< XInterface >( (XPerformanceTest *)new ServiceImpl( xSMgr ) );
241 }
242 
243 }
244 
245 
246 //##################################################################################################
247 //##################################################################################################
248 //##################################################################################################
249 
250 
251 extern "C"
252 {
253 //==================================================================================================
component_getImplementationEnvironment(const sal_Char ** ppEnvTypeName,uno_Environment ** ppEnv)254 void SAL_CALL component_getImplementationEnvironment(
255 	const sal_Char ** ppEnvTypeName, uno_Environment ** ppEnv )
256 {
257 	*ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
258 }
259 //==================================================================================================
component_writeInfo(void * pServiceManager,void * pRegistryKey)260 sal_Bool SAL_CALL component_writeInfo(
261 	void * pServiceManager, void * pRegistryKey )
262 {
263 	if (pRegistryKey)
264 	{
265 		try
266 		{
267 			Reference< XRegistryKey > xNewKey(
268 				reinterpret_cast< XRegistryKey * >( pRegistryKey )->createKey(
269 					OUString( RTL_CONSTASCII_USTRINGPARAM("/" IMPLNAME "/UNO/SERVICES") ) ) );
270 			xNewKey->createKey( OUString( RTL_CONSTASCII_USTRINGPARAM(SERVICENAME) ) );
271 
272 			return sal_True;
273 		}
274 		catch (InvalidRegistryException &)
275 		{
276 			OSL_ENSURE( sal_False, "### InvalidRegistryException!" );
277 		}
278 	}
279 	return sal_False;
280 }
281 //==================================================================================================
component_getFactory(const sal_Char * pImplName,void * pServiceManager,void * pRegistryKey)282 void * SAL_CALL component_getFactory(
283 	const sal_Char * pImplName, void * pServiceManager, void * pRegistryKey )
284 {
285 	void * pRet = 0;
286 
287 	if (pServiceManager && rtl_str_compare( pImplName, IMPLNAME ) == 0)
288 	{
289 		Reference< XSingleServiceFactory > xFactory( createSingleFactory(
290 			reinterpret_cast< XMultiServiceFactory * >( pServiceManager ),
291 			OUString( RTL_CONSTASCII_USTRINGPARAM(IMPLNAME) ),
292 			benchmark_object::ServiceImpl_create,
293 			benchmark_object::getSupportedServiceNames() ) );
294 
295 		if (xFactory.is())
296 		{
297 			xFactory->acquire();
298 			pRet = xFactory.get();
299 		}
300 	}
301 
302 	return pRet;
303 }
304 }
305