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