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_stoc.hxx" 30*cdf0e10cSrcweir #include <rtl/alloc.h> 31*cdf0e10cSrcweir #include <osl/security.h> 32*cdf0e10cSrcweir #include <osl/thread.h> 33*cdf0e10cSrcweir #include <osl/mutex.hxx> 34*cdf0e10cSrcweir #include <cppuhelper/queryinterface.hxx> 35*cdf0e10cSrcweir #include <cppuhelper/weak.hxx> 36*cdf0e10cSrcweir #include <uno/mapping.hxx> 37*cdf0e10cSrcweir 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir #include <cppuhelper/factory.hxx> 40*cdf0e10cSrcweir #include <cppuhelper/servicefactory.hxx> 41*cdf0e10cSrcweir #include <cppuhelper/implbase1.hxx> 42*cdf0e10cSrcweir #include <registry/registry.hxx> 43*cdf0e10cSrcweir 44*cdf0e10cSrcweir #include <com/sun/star/registry/XSimpleRegistry.hpp> 45*cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp> 46*cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp> 47*cdf0e10cSrcweir #include <com/sun/star/registry/XImplementationRegistration.hpp> 48*cdf0e10cSrcweir #include <com/sun/star/lang/XSingleServiceFactory.hpp> 49*cdf0e10cSrcweir #include <com/sun/star/lang/XComponent.hpp> 50*cdf0e10cSrcweir #include <com/sun/star/container/XContentEnumerationAccess.hpp> 51*cdf0e10cSrcweir #include <com/sun/star/container/XEnumerationAccess.hpp> 52*cdf0e10cSrcweir #include <com/sun/star/container/XEnumeration.hpp> 53*cdf0e10cSrcweir 54*cdf0e10cSrcweir #if defined ( UNX ) 55*cdf0e10cSrcweir #include <limits.h> 56*cdf0e10cSrcweir #define _MAX_PATH PATH_MAX 57*cdf0e10cSrcweir #endif 58*cdf0e10cSrcweir 59*cdf0e10cSrcweir 60*cdf0e10cSrcweir 61*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0 62*cdf0e10cSrcweir #define TEST_ENSHURE(c, m) OSL_ENSURE(c, m) 63*cdf0e10cSrcweir #else 64*cdf0e10cSrcweir #define TEST_ENSHURE(c, m) OSL_VERIFY(c) 65*cdf0e10cSrcweir #endif 66*cdf0e10cSrcweir 67*cdf0e10cSrcweir 68*cdf0e10cSrcweir #define IMPLEMENTATION_NAME "com.sun.star.DummyService.V10" 69*cdf0e10cSrcweir #define SERVICE_NAME "com.sun.star.ts.TestManagerImpl" 70*cdf0e10cSrcweir 71*cdf0e10cSrcweir 72*cdf0e10cSrcweir using namespace com::sun::star::uno; 73*cdf0e10cSrcweir using namespace com::sun::star::registry; 74*cdf0e10cSrcweir using namespace com::sun::star::lang; 75*cdf0e10cSrcweir using namespace com::sun::star::container; 76*cdf0e10cSrcweir using namespace osl; 77*cdf0e10cSrcweir using namespace rtl; 78*cdf0e10cSrcweir using namespace cppu; 79*cdf0e10cSrcweir 80*cdf0e10cSrcweir 81*cdf0e10cSrcweir Reference<XMultiServiceFactory> getProcessServiceManager() 82*cdf0e10cSrcweir { 83*cdf0e10cSrcweir Reference<XMultiServiceFactory > s_x; 84*cdf0e10cSrcweir if (! s_x.is()) 85*cdf0e10cSrcweir { 86*cdf0e10cSrcweir MutexGuard aGuard( Mutex::getGlobalMutex() ); 87*cdf0e10cSrcweir if (! s_x.is()) 88*cdf0e10cSrcweir s_x = createRegistryServiceFactory( OUString::createFromAscii( "stoctest.rdb" ), sal_False ); 89*cdf0e10cSrcweir } 90*cdf0e10cSrcweir return s_x; 91*cdf0e10cSrcweir } 92*cdf0e10cSrcweir 93*cdf0e10cSrcweir Reference< XMultiServiceFactory > createRegistryServiceManager( const OUString& registryName ) 94*cdf0e10cSrcweir { 95*cdf0e10cSrcweir return createRegistryServiceFactory( registryName ); 96*cdf0e10cSrcweir } 97*cdf0e10cSrcweir 98*cdf0e10cSrcweir 99*cdf0e10cSrcweir /********************************** 100*cdf0e10cSrcweir * The service, that is used to test the Service manager 101*cdf0e10cSrcweir * 102*cdf0e10cSrcweir * 103*cdf0e10cSrcweir * 104*cdf0e10cSrcweir *************************************/ 105*cdf0e10cSrcweir static sal_uInt32 nInstanceCount = 0; 106*cdf0e10cSrcweir class Test_Manager_Impl : public WeakImplHelper1< XServiceInfo > 107*cdf0e10cSrcweir { 108*cdf0e10cSrcweir public: 109*cdf0e10cSrcweir Test_Manager_Impl(){ nInstanceCount++;} 110*cdf0e10cSrcweir ~Test_Manager_Impl(); 111*cdf0e10cSrcweir 112*cdf0e10cSrcweir // XServiceInfo 113*cdf0e10cSrcweir OUString SAL_CALL getImplementationName() throw(); 114*cdf0e10cSrcweir sal_Bool SAL_CALL supportsService(const OUString& ServiceName) throw(); 115*cdf0e10cSrcweir Sequence< OUString > SAL_CALL getSupportedServiceNames(void) throw(); 116*cdf0e10cSrcweir static Sequence< OUString > SAL_CALL getSupportedServiceNames_Static(void) throw(); 117*cdf0e10cSrcweir 118*cdf0e10cSrcweir private: 119*cdf0e10cSrcweir // static XIdlClassRef getStaticIdlClass(); 120*cdf0e10cSrcweir }; 121*cdf0e10cSrcweir 122*cdf0e10cSrcweir Test_Manager_Impl::~Test_Manager_Impl() 123*cdf0e10cSrcweir { 124*cdf0e10cSrcweir nInstanceCount--; 125*cdf0e10cSrcweir } 126*cdf0e10cSrcweir 127*cdf0e10cSrcweir 128*cdf0e10cSrcweir // alt, wird von der neuen Mimic nicht mehr gebraucht 129*cdf0e10cSrcweir Reference< XInterface > SAL_CALL Test_Manager_Impl_CreateInstance_Impl() 130*cdf0e10cSrcweir { 131*cdf0e10cSrcweir return (OWeakObject *)new Test_Manager_Impl(); 132*cdf0e10cSrcweir } 133*cdf0e10cSrcweir 134*cdf0e10cSrcweir 135*cdf0e10cSrcweir //************************************************************************* 136*cdf0e10cSrcweir // Test_Manager_Impl_CreateInstance() 137*cdf0e10cSrcweir // 138*cdf0e10cSrcweir Reference < XInterface > SAL_CALL Test_Manager_Impl_CreateInstance( 139*cdf0e10cSrcweir const Reference< XMultiServiceFactory > & /*rSMgr*/ ) throw (Exception) 140*cdf0e10cSrcweir { 141*cdf0e10cSrcweir Reference < XInterface > xService = (XWeak *)(OWeakObject *)new Test_Manager_Impl( ); 142*cdf0e10cSrcweir 143*cdf0e10cSrcweir return xService; 144*cdf0e10cSrcweir } 145*cdf0e10cSrcweir 146*cdf0e10cSrcweir 147*cdf0e10cSrcweir //************************************************************************* 148*cdf0e10cSrcweir // Test_Manager_Impl::getImplementationName 149*cdf0e10cSrcweir // 150*cdf0e10cSrcweir OUString Test_Manager_Impl::getImplementationName() throw() 151*cdf0e10cSrcweir { 152*cdf0e10cSrcweir return OUString::createFromAscii(IMPLEMENTATION_NAME); 153*cdf0e10cSrcweir } 154*cdf0e10cSrcweir 155*cdf0e10cSrcweir //************************************************************************* 156*cdf0e10cSrcweir // Test_Manager_Impl::supportsService 157*cdf0e10cSrcweir // 158*cdf0e10cSrcweir sal_Bool Test_Manager_Impl::supportsService( const OUString& ServiceName ) throw() 159*cdf0e10cSrcweir { 160*cdf0e10cSrcweir Sequence< OUString > aSNL = getSupportedServiceNames(); 161*cdf0e10cSrcweir const OUString * pArray = aSNL.getConstArray(); 162*cdf0e10cSrcweir for( sal_Int32 i = 0; i < aSNL.getLength(); i++ ) 163*cdf0e10cSrcweir if( pArray[i] == ServiceName ) 164*cdf0e10cSrcweir return sal_True; 165*cdf0e10cSrcweir return sal_False; 166*cdf0e10cSrcweir } 167*cdf0e10cSrcweir 168*cdf0e10cSrcweir //************************************************************************* 169*cdf0e10cSrcweir // Test_Manager_Impl::getSupportedServiceNames 170*cdf0e10cSrcweir // 171*cdf0e10cSrcweir Sequence< OUString > Test_Manager_Impl::getSupportedServiceNames(void) throw () 172*cdf0e10cSrcweir { 173*cdf0e10cSrcweir return getSupportedServiceNames_Static(); 174*cdf0e10cSrcweir } 175*cdf0e10cSrcweir 176*cdf0e10cSrcweir //************************************************************************* 177*cdf0e10cSrcweir // Test_Manager_Impl::getSupportedServiceNames_Static 178*cdf0e10cSrcweir // 179*cdf0e10cSrcweir Sequence< OUString > Test_Manager_Impl::getSupportedServiceNames_Static(void) throw () 180*cdf0e10cSrcweir { 181*cdf0e10cSrcweir Sequence< OUString > aSNS( 2 ); 182*cdf0e10cSrcweir aSNS.getArray()[0] = OUString::createFromAscii(SERVICE_NAME); 183*cdf0e10cSrcweir aSNS.getArray()[1] = OUString::createFromAscii("com.sun.star.bridge.Bridge"); 184*cdf0e10cSrcweir return aSNS; 185*cdf0e10cSrcweir } 186*cdf0e10cSrcweir 187*cdf0e10cSrcweir 188*cdf0e10cSrcweir 189*cdf0e10cSrcweir 190*cdf0e10cSrcweir /**** 191*cdf0e10cSrcweir * 192*cdf0e10cSrcweir * 193*cdf0e10cSrcweir * This routine performs the test of the process service manager ( getProcessServiceManager is called ) 194*cdf0e10cSrcweir * 195*cdf0e10cSrcweir * 196*cdf0e10cSrcweir * 197*cdf0e10cSrcweir ****/ 198*cdf0e10cSrcweir 199*cdf0e10cSrcweir #include <stdio.h> 200*cdf0e10cSrcweir 201*cdf0e10cSrcweir extern "C" void SAL_CALL test_ServiceManager() 202*cdf0e10cSrcweir { 203*cdf0e10cSrcweir #if ! defined SAL_DLLPREFIX 204*cdf0e10cSrcweir #define SAL_DLLPREFIX "" 205*cdf0e10cSrcweir #endif 206*cdf0e10cSrcweir OUString atUModule2 = OUString( 207*cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM( 208*cdf0e10cSrcweir SAL_DLLPREFIX "testsmgr_component" SAL_DLLEXTENSION ) ); 209*cdf0e10cSrcweir 210*cdf0e10cSrcweir // expand shared library name 211*cdf0e10cSrcweir OString atModule2( OUStringToOString(atUModule2, RTL_TEXTENCODING_ASCII_US) ); 212*cdf0e10cSrcweir 213*cdf0e10cSrcweir // get the process servicemanager 214*cdf0e10cSrcweir Reference <XMultiServiceFactory> xSMgr = getProcessServiceManager(); 215*cdf0e10cSrcweir 216*cdf0e10cSrcweir TEST_ENSHURE( xSMgr.is() , "query on XServiceManager failed" ); 217*cdf0e10cSrcweir 218*cdf0e10cSrcweir Reference<XContentEnumerationAccess> xContEnum(xSMgr, UNO_QUERY); 219*cdf0e10cSrcweir TEST_ENSHURE( xContEnum.is() , "query on XContentEnumerationAccess failed" ); 220*cdf0e10cSrcweir Reference<XEnumeration > xEnum(xContEnum->createContentEnumeration(OUString::createFromAscii("com.sun.star.registry.SimpleRegistry"))); 221*cdf0e10cSrcweir TEST_ENSHURE( xEnum.is() , "createContentEnumeration failed" ); 222*cdf0e10cSrcweir sal_Int32 nLen = 0; 223*cdf0e10cSrcweir while( xEnum->hasMoreElements() ) 224*cdf0e10cSrcweir { 225*cdf0e10cSrcweir nLen++; 226*cdf0e10cSrcweir xEnum->nextElement(); 227*cdf0e10cSrcweir } 228*cdf0e10cSrcweir TEST_ENSHURE( nLen == 1, "more than one implementation for SimpleRegistry" ); 229*cdf0e10cSrcweir 230*cdf0e10cSrcweir Reference<XEnumerationAccess> xImplEnum(xSMgr, UNO_QUERY); 231*cdf0e10cSrcweir TEST_ENSHURE( xImplEnum.is() , "query on XEnumeration failed" ); 232*cdf0e10cSrcweir xEnum = Reference<XEnumeration >(xImplEnum->createEnumeration()); 233*cdf0e10cSrcweir TEST_ENSHURE( xEnum.is() , "createEnumeration failed" ); 234*cdf0e10cSrcweir nLen = 0; 235*cdf0e10cSrcweir while( xEnum->hasMoreElements() ) 236*cdf0e10cSrcweir { 237*cdf0e10cSrcweir nLen++; 238*cdf0e10cSrcweir Reference< XServiceInfo > sf( xEnum->nextElement(), UNO_QUERY ); 239*cdf0e10cSrcweir OString str( OUStringToOString( sf->getImplementationName(), RTL_TEXTENCODING_ASCII_US ) ); 240*cdf0e10cSrcweir ::fprintf( stderr, "> implementation name: %s\n", str.getStr() ); 241*cdf0e10cSrcweir } 242*cdf0e10cSrcweir TEST_ENSHURE( nLen == 8, "more than 6 factories" ); 243*cdf0e10cSrcweir 244*cdf0e10cSrcweir // try to get an instance for a unknown service 245*cdf0e10cSrcweir TEST_ENSHURE( !xSMgr->createInstance(OUString::createFromAscii("bla.blup.Q")).is(), "unknown service provider found" ); 246*cdf0e10cSrcweir 247*cdf0e10cSrcweir // 248*cdf0e10cSrcweir // First test : register service via the internal function of the component itself 249*cdf0e10cSrcweir // 250*cdf0e10cSrcweir { 251*cdf0e10cSrcweir Reference< XImplementationRegistration > 252*cdf0e10cSrcweir xInst( xSMgr->createInstance(OUString::createFromAscii("com.sun.star.registry.ImplementationRegistration")), UNO_QUERY ); 253*cdf0e10cSrcweir TEST_ENSHURE( xInst.is(), "no ImplementationRegistration" ); 254*cdf0e10cSrcweir 255*cdf0e10cSrcweir try { 256*cdf0e10cSrcweir // register the services via writeComponentRegInfo (see at end of this file) 257*cdf0e10cSrcweir xInst->registerImplementation(OUString::createFromAscii("com.sun.star.loader.SharedLibrary"), atUModule2, Reference< XSimpleRegistry >() ); 258*cdf0e10cSrcweir } 259*cdf0e10cSrcweir catch( CannotRegisterImplementationException e ) { 260*cdf0e10cSrcweir TEST_ENSHURE( 0, "register implementation failed" ); 261*cdf0e10cSrcweir } 262*cdf0e10cSrcweir 263*cdf0e10cSrcweir // getImplementations() check 264*cdf0e10cSrcweir Sequence<OUString> seqImpl = xInst->getImplementations(OUString::createFromAscii("com.sun.star.loader.SharedLibrary"), atUModule2); 265*cdf0e10cSrcweir TEST_ENSHURE( seqImpl.getLength() == 1, "count of implementantions is wrong" ); 266*cdf0e10cSrcweir TEST_ENSHURE( seqImpl.getConstArray()[0] == OUString::createFromAscii("com.sun.star.DummyService.V10"), "implementation name is not equal" ); 267*cdf0e10cSrcweir 268*cdf0e10cSrcweir 269*cdf0e10cSrcweir // tests, if a service provider can be instantiated. 270*cdf0e10cSrcweir 271*cdf0e10cSrcweir Reference< XInterface > xIFace(xSMgr->createInstance(OUString::createFromAscii("com.sun.star.ts.TestManagerImpl"))); 272*cdf0e10cSrcweir TEST_ENSHURE( xIFace.is(), "loadable service not found" ); 273*cdf0e10cSrcweir 274*cdf0e10cSrcweir // remove the service 275*cdf0e10cSrcweir TEST_ENSHURE( xInst->revokeImplementation(atUModule2, Reference< XSimpleRegistry > ()), 276*cdf0e10cSrcweir "revoke implementation failed" ); 277*cdf0e10cSrcweir } 278*cdf0e10cSrcweir 279*cdf0e10cSrcweir 280*cdf0e10cSrcweir // Reference < XSimpleRegistry > xSReg( xSMgr->createInstance(OUString::createFromAscii("com::sun::star.uno.repos.SimpleRegistry")), UNO_QUERY ); 281*cdf0e10cSrcweir // TEST_ENSHURE( xSReg.is() , "Simple registry couldn't be instantiated" ); 282*cdf0e10cSrcweir 283*cdf0e10cSrcweir // xSReg->open(OUString::createFromAscii("dummy.reg"), sal_False, sal_True); 284*cdf0e10cSrcweir // xSReg->close(); 285*cdf0e10cSrcweir 286*cdf0e10cSrcweir // laut dbo : C-API muss nicht mehr unterstuezt werden 287*cdf0e10cSrcweir //TEST_ENSHURE( registerExternService(atModule, "dummy.reg"), "install failed" ); 288*cdf0e10cSrcweir //TEST_ENSHURE( deregisterExternService(atModule, "dummy.reg"), "deinstall failed" ); 289*cdf0e10cSrcweir 290*cdf0e10cSrcweir 291*cdf0e10cSrcweir // UNO_INTERFACE(XMultiServiceFactory) xUnoSMgr = {0,0}; 292*cdf0e10cSrcweir // smart2uno(xSMgr, xUnoSMgr); 293*cdf0e10cSrcweir 294*cdf0e10cSrcweir // TEST_ENSHURE(registerExternImplementation(xUnoSMgr, "com::sun::star.loader.SharedLibrary", atModule2, "dummy.reg"), "install failed" ); 295*cdf0e10cSrcweir // TEST_ENSHURE(revokeExternImplementation(xUnoSMgr, atModule2, "dummy.reg"), "deinstall failed" ); 296*cdf0e10cSrcweir 297*cdf0e10cSrcweir // TEST_ENSHURE(registerExternImplementation(xUnoSMgr, "com::sun::star.loader.SharedLibrary", atModule2, "dummy2.reg"), "install failed" ); 298*cdf0e10cSrcweir 299*cdf0e10cSrcweir //TODO : Java loader test 300*cdf0e10cSrcweir // String testUrl(getTestJarUrl()); 301*cdf0e10cSrcweir // TEST_ENSHURE(registerExternImplementation(xUnoSMgr, "com::sun::star.loader.Java", testUrl, "dummy.reg"), "install failed" ); 302*cdf0e10cSrcweir // TEST_ENSHURE(revokeExternImplementation(xUnoSMgr, testUrl, "dummy.reg"), "deinstall failed" ); 303*cdf0e10cSrcweir 304*cdf0e10cSrcweir // if (!UNO_isNull((UNO_Ifc*)&xUnoSMgr)) 305*cdf0e10cSrcweir // xUnoSMgr.m_pVmt->release(xUnoSMgr.m_pCtx); 306*cdf0e10cSrcweir 307*cdf0e10cSrcweir // xSReg->open(OUString::createFromAscii("dummy.reg"), sal_True, sal_False); 308*cdf0e10cSrcweir // TEST_ENSHURE(!xSReg->getRootKey()->openKey(OUString::createFromAscii("/SERVICES/com::sun::star/ts/TestManagerImpl/URL")).is(), 309*cdf0e10cSrcweir // "deinstall failed" ); 310*cdf0e10cSrcweir 311*cdf0e10cSrcweir // xSReg->close(); 312*cdf0e10cSrcweir 313*cdf0e10cSrcweir // xSReg->open(OUString::createFromAscii("dummy.reg"), sal_False, sal_False); 314*cdf0e10cSrcweir // xSReg->destroy(); 315*cdf0e10cSrcweir // xSReg->open(OUString::createFromAscii("dummy2.reg"), sal_False, sal_False); 316*cdf0e10cSrcweir // xSReg->destroy(); 317*cdf0e10cSrcweir 318*cdf0e10cSrcweir 319*cdf0e10cSrcweir // Test initialisieren 320*cdf0e10cSrcweir /* 321*cdf0e10cSrcweir XServiceProviderRef xSiSP1 = createSimpleServiceProvider( OUString::createFromAscii("com::sun::star.usr.Test_Manager_Impl1"), Test_Manager_Impl_getReflection ); 322*cdf0e10cSrcweir XServiceProviderRef xSiSP11 = createSimpleServiceProvider( OUString::createFromAscii("com::sun::star.usr.Test_Manager_Impl1"), Test_Manager_Impl_getReflection ); 323*cdf0e10cSrcweir XServiceProviderRef xSiSP2 = createSimpleServiceProvider( OUString::createFromAscii("com::sun::star.usr.Test_Manager_Impl2"), Test_Manager_Impl_getReflection ); 324*cdf0e10cSrcweir */ 325*cdf0e10cSrcweir /* 326*cdf0e10cSrcweir // second test 327*cdf0e10cSrcweir // create XServiceProvider via createSingleFactory and write them directly into the registry 328*cdf0e10cSrcweir // For this is needed a sequence of supported servicenames and a createComponent function pointer 329*cdf0e10cSrcweir { 330*cdf0e10cSrcweir Reference< XServiceProvider > xSiSP1(createSingleFactory( 331*cdf0e10cSrcweir xSMgr, 332*cdf0e10cSrcweir OUString::createFromAscii("com::sun::star.usr.Test_Manager_Impl1), 333*cdf0e10cSrcweir Test_Manager_Impl_CreateInstance, 334*cdf0e10cSrcweir Test_Manager_Impl::getSupportedServiceNames_Static() ), UNO_QUERY); 335*cdf0e10cSrcweir Reference< XServiceProvider > xSiSP11(createSingleFactory( 336*cdf0e10cSrcweir xSMgr, 337*cdf0e10cSrcweir OUString::createFromAscii("com::sun::star.usr.Test_Manager_Impl1"), 338*cdf0e10cSrcweir Test_Manager_Impl_CreateInstance, 339*cdf0e10cSrcweir Test_Manager_Impl::getSupportedServiceNames_Static() ),UNO_QUERY); 340*cdf0e10cSrcweir Reference< XServiceProvider > xSiSP2(createSingleFactory( 341*cdf0e10cSrcweir xSMgr, 342*cdf0e10cSrcweir L"com::sun::star.usr.Test_Manager_Impl2", 343*cdf0e10cSrcweir Test_Manager_Impl_CreateInstance, 344*cdf0e10cSrcweir Test_Manager_Impl::getSupportedServiceNames_Static() ), UNO_QUERY); 345*cdf0e10cSrcweir 346*cdf0e10cSrcweir // put the service providers into the registry 347*cdf0e10cSrcweir xReg->registerServiceProvider( L"com::sun::star.test.TestManager1", xSiSP1 ); 348*cdf0e10cSrcweir xReg->registerServiceProvider( L"com::sun::star.test.TestManager1", xSiSP11 ); 349*cdf0e10cSrcweir xReg->registerServiceProvider( L"com::sun::star.test.TestManager2", xSiSP2 ); 350*cdf0e10cSrcweir 351*cdf0e10cSrcweir // TestManager1 352*cdf0e10cSrcweir Reference< XServiceProvider > xProv = xSMgr->queryServiceProvider( L"com::sun::star.test.TestManager1"); 353*cdf0e10cSrcweir Reference< XSingleServiceFactory > xFact( xProv, UNO_QUERY ); 354*cdf0e10cSrcweir TEST_ENSHURE( xFact.is(), "Service com::sun::star.test.TestManager1 not found" ); 355*cdf0e10cSrcweir 356*cdf0e10cSrcweir Reference< XInterface > xTest1 = xFact->createInstance(); 357*cdf0e10cSrcweir TEST_ENSHURE( nInstanceCount == 1, "wrong service instanciated" ); 358*cdf0e10cSrcweir 359*cdf0e10cSrcweir // TestManager2 360*cdf0e10cSrcweir xProv = xSMgr->queryServiceProvider( L"com::sun::star.test.TestManager2"); 361*cdf0e10cSrcweir xFact = Reference < XSingleServiceFactory > ( xProv , UNO_QUERY ); 362*cdf0e10cSrcweir TEST_ENSHURE( xFact.is(), "Service com::sun::star.test.TestManager2 not found" ); 363*cdf0e10cSrcweir 364*cdf0e10cSrcweir Reference < XInterface > xTest2 = xFact->createInstance(); 365*cdf0e10cSrcweir TEST_ENSHURE( nInstanceCount == 2, "wrong service instanciated" ); 366*cdf0e10cSrcweir 367*cdf0e10cSrcweir xTest1 = Reference< XInterface >(); 368*cdf0e10cSrcweir xTest2 = Reference< XInterface >(); 369*cdf0e10cSrcweir TEST_ENSHURE( nInstanceCount == 0, "wrong service deleted" ); 370*cdf0e10cSrcweir 371*cdf0e10cSrcweir Reference< XEnumeration > xEnum = xSMgr->createProviderEnumeration( L"com::sun::star.test.TestManager1"); 372*cdf0e10cSrcweir TEST_ENSHURE( xEnum.is() , "no provider enumeration" ); 373*cdf0e10cSrcweir 374*cdf0e10cSrcweir sal_Int32 nSPTestManagerImplLen2 = 0; 375*cdf0e10cSrcweir 376*cdf0e10cSrcweir while (xEnum.is() && xEnum->hasMoreElements()) 377*cdf0e10cSrcweir { 378*cdf0e10cSrcweir nSPTestManagerImplLen2++; 379*cdf0e10cSrcweir xEnum->nextElement(); 380*cdf0e10cSrcweir 381*cdf0e10cSrcweir } 382*cdf0e10cSrcweir TEST_ENSHURE( nSPTestManagerImplLen2 == 2, "queryServiceProviders() wrong length" ); 383*cdf0e10cSrcweir 384*cdf0e10cSrcweir sal_Int32 nCount = 0; 385*cdf0e10cSrcweir xEnum = xSMgr->createProviderEnumeration( L"com::sun::star.test.TestManager1"); 386*cdf0e10cSrcweir while (xEnum->hasMoreElements()) 387*cdf0e10cSrcweir { 388*cdf0e10cSrcweir Reference< XServiceProvider > xProv; 389*cdf0e10cSrcweir xEnum->nextElement() >>= xProv; 390*cdf0e10cSrcweir if (xProv == xSiSP1 || xProv == xSiSP11) 391*cdf0e10cSrcweir nCount++; 392*cdf0e10cSrcweir } 393*cdf0e10cSrcweir 394*cdf0e10cSrcweir TEST_ENSHURE( nCount == 2 , "not all com::sun::star.testimpl.TestManagerImpl registered" ); 395*cdf0e10cSrcweir */ 396*cdf0e10cSrcweir /* 397*cdf0e10cSrcweir { 398*cdf0e10cSrcweir Reference< XMultiServiceFactory > xTestManager(createRegistryServiceManager(L"testmanager.rdb")); 399*cdf0e10cSrcweir TEST_ENSHURE( xTestManager.is(), "create Test ServiceManager failed!" ); 400*cdf0e10cSrcweir } 401*cdf0e10cSrcweir */ 402*cdf0e10cSrcweir Reference<XComponent> xComp(xSMgr, UNO_QUERY); 403*cdf0e10cSrcweir xComp->dispose(); 404*cdf0e10cSrcweir 405*cdf0e10cSrcweir xComp.clear(); 406*cdf0e10cSrcweir xSMgr.clear(); 407*cdf0e10cSrcweir } 408*cdf0e10cSrcweir 409*cdf0e10cSrcweir 410*cdf0e10cSrcweir 411*cdf0e10cSrcweir extern "C" 412*cdf0e10cSrcweir { 413*cdf0e10cSrcweir //================================================================================================== 414*cdf0e10cSrcweir void SAL_CALL component_getImplementationEnvironment( 415*cdf0e10cSrcweir const sal_Char ** ppEnvTypeName, uno_Environment ** /*ppEnv*/ ) 416*cdf0e10cSrcweir { 417*cdf0e10cSrcweir *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME; 418*cdf0e10cSrcweir } 419*cdf0e10cSrcweir //================================================================================================== 420*cdf0e10cSrcweir sal_Bool SAL_CALL component_writeInfo( 421*cdf0e10cSrcweir void * /*pServiceManager*/, void * pRegistryKey ) 422*cdf0e10cSrcweir { 423*cdf0e10cSrcweir if (pRegistryKey) 424*cdf0e10cSrcweir { 425*cdf0e10cSrcweir try 426*cdf0e10cSrcweir { 427*cdf0e10cSrcweir Reference< XRegistryKey > xNewKey( 428*cdf0e10cSrcweir reinterpret_cast< XRegistryKey * >( pRegistryKey )->createKey( 429*cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM("/" IMPLEMENTATION_NAME "/UNO/SERVICES") ) ) ); 430*cdf0e10cSrcweir 431*cdf0e10cSrcweir const Sequence< OUString > & rSNL = 432*cdf0e10cSrcweir Test_Manager_Impl::getSupportedServiceNames_Static(); 433*cdf0e10cSrcweir const OUString * pArray = rSNL.getConstArray(); 434*cdf0e10cSrcweir for ( sal_Int32 nPos = rSNL.getLength(); nPos--; ) 435*cdf0e10cSrcweir xNewKey->createKey( pArray[nPos] ); 436*cdf0e10cSrcweir 437*cdf0e10cSrcweir return sal_True; 438*cdf0e10cSrcweir } 439*cdf0e10cSrcweir catch (InvalidRegistryException &) 440*cdf0e10cSrcweir { 441*cdf0e10cSrcweir OSL_ENSURE( sal_False, "### InvalidRegistryException!" ); 442*cdf0e10cSrcweir } 443*cdf0e10cSrcweir } 444*cdf0e10cSrcweir return sal_False; 445*cdf0e10cSrcweir } 446*cdf0e10cSrcweir //================================================================================================== 447*cdf0e10cSrcweir void * SAL_CALL component_getFactory( 448*cdf0e10cSrcweir const sal_Char * pImplName, void * pServiceManager, void * /*pRegistryKey*/ ) 449*cdf0e10cSrcweir { 450*cdf0e10cSrcweir void * pRet = 0; 451*cdf0e10cSrcweir 452*cdf0e10cSrcweir if (rtl_str_compare( pImplName, IMPLEMENTATION_NAME ) == 0) 453*cdf0e10cSrcweir { 454*cdf0e10cSrcweir Reference< XSingleServiceFactory > xFactory( createSingleFactory( 455*cdf0e10cSrcweir reinterpret_cast< XMultiServiceFactory * >( pServiceManager ), 456*cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM(IMPLEMENTATION_NAME) ), 457*cdf0e10cSrcweir Test_Manager_Impl_CreateInstance, 458*cdf0e10cSrcweir Test_Manager_Impl::getSupportedServiceNames_Static() ) ); 459*cdf0e10cSrcweir 460*cdf0e10cSrcweir if (xFactory.is()) 461*cdf0e10cSrcweir { 462*cdf0e10cSrcweir xFactory->acquire(); 463*cdf0e10cSrcweir pRet = xFactory.get(); 464*cdf0e10cSrcweir } 465*cdf0e10cSrcweir } 466*cdf0e10cSrcweir 467*cdf0e10cSrcweir return pRet; 468*cdf0e10cSrcweir } 469*cdf0e10cSrcweir } 470*cdf0e10cSrcweir 471*cdf0e10cSrcweir 472*cdf0e10cSrcweir 473