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