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 
29*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
30*cdf0e10cSrcweir #include "precompiled_extensions.hxx"
31*cdf0e10cSrcweir 
32*cdf0e10cSrcweir #include<osl/module.hxx>
33*cdf0e10cSrcweir #include <osl/time.h>
34*cdf0e10cSrcweir #include <rtl/ustring.hxx>
35*cdf0e10cSrcweir #include <stdio.h>
36*cdf0e10cSrcweir #include <cppuhelper/factory.hxx>
37*cdf0e10cSrcweir #include <cppuhelper/servicefactory.hxx>
38*cdf0e10cSrcweir #include <cppuhelper/bootstrap.hxx>
39*cdf0e10cSrcweir #include <com/sun/star/lang/XMultiComponentFactory.hpp>
40*cdf0e10cSrcweir #include <com/sun/star/lang/XSingleServiceFactory.hpp>
41*cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp>
42*cdf0e10cSrcweir #include <com/sun/star/lang/XComponent.hpp>
43*cdf0e10cSrcweir #include <com/sun/star/uno/XComponentContext.hpp>
44*cdf0e10cSrcweir #include <com/sun/star/registry/XSimpleRegistry.hpp>
45*cdf0e10cSrcweir 
46*cdf0e10cSrcweir #include <stdio.h>
47*cdf0e10cSrcweir using namespace ::rtl;
48*cdf0e10cSrcweir using namespace ::osl;
49*cdf0e10cSrcweir using namespace ::com::sun::star::uno;
50*cdf0e10cSrcweir using namespace ::com::sun::star::lang;
51*cdf0e10cSrcweir using namespace ::cppu;
52*cdf0e10cSrcweir using namespace ::com::sun::star::registry;
53*cdf0e10cSrcweir 
54*cdf0e10cSrcweir 
55*cdf0e10cSrcweir sal_Bool test1();
56*cdf0e10cSrcweir sal_Bool test2();
57*cdf0e10cSrcweir sal_Bool test3();
58*cdf0e10cSrcweir sal_Bool test4();
59*cdf0e10cSrcweir 
60*cdf0e10cSrcweir int main(int, char**)
61*cdf0e10cSrcweir {
62*cdf0e10cSrcweir    	sal_Bool bTest1= test1();
63*cdf0e10cSrcweir    	sal_Bool bTest2= test2();
64*cdf0e10cSrcweir 	sal_Bool bTest3= test3();
65*cdf0e10cSrcweir 	sal_Bool bTest4= test4();
66*cdf0e10cSrcweir 
67*cdf0e10cSrcweir 	if( bTest1 && bTest2 && bTest3 && bTest4)
68*cdf0e10cSrcweir 		printf("\n#########################\n Test was successful\n#######################\n");
69*cdf0e10cSrcweir 
70*cdf0e10cSrcweir 	return 0;
71*cdf0e10cSrcweir }
72*cdf0e10cSrcweir 
73*cdf0e10cSrcweir sal_Bool test1()
74*cdf0e10cSrcweir {
75*cdf0e10cSrcweir 	printf("\n Test1:  com.sun.star.bridge.oleautomation.BridgeSupplier\n");
76*cdf0e10cSrcweir 	Reference<XSimpleRegistry> xreg= createSimpleRegistry();
77*cdf0e10cSrcweir 	xreg->open( OUString( RTL_CONSTASCII_USTRINGPARAM("services.rdb")),
78*cdf0e10cSrcweir 							   sal_False, sal_False );
79*cdf0e10cSrcweir 
80*cdf0e10cSrcweir 	Reference< XComponentContext > context= bootstrap_InitialComponentContext(xreg);
81*cdf0e10cSrcweir 	Reference<XMultiComponentFactory> fac= context->getServiceManager();
82*cdf0e10cSrcweir 	OUString sService1( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.bridge.oleautomation.BridgeSupplier"));
83*cdf0e10cSrcweir 	Reference<XInterface> xint1= fac->createInstanceWithContext( sService1, context);
84*cdf0e10cSrcweir 
85*cdf0e10cSrcweir 	OUString sModule(
86*cdf0e10cSrcweir         RTL_CONSTASCII_USTRINGPARAM("oleautobridge.uno" SAL_DLLEXTENSION));
87*cdf0e10cSrcweir 	oslModule hMod= osl_loadModule( sModule.pData, 0);
88*cdf0e10cSrcweir 	osl_unloadModule( hMod);
89*cdf0e10cSrcweir 
90*cdf0e10cSrcweir 	rtl_unloadUnusedModules( NULL);
91*cdf0e10cSrcweir 
92*cdf0e10cSrcweir 	OUString sFactoryFunc( RTL_CONSTASCII_USTRINGPARAM("component_getFactory"));
93*cdf0e10cSrcweir 	void* pSymbol= osl_getSymbol( hMod,sFactoryFunc.pData);
94*cdf0e10cSrcweir 	// true, instance alive
95*cdf0e10cSrcweir 	sal_Bool bTest1= pSymbol ? sal_True : sal_False;
96*cdf0e10cSrcweir 
97*cdf0e10cSrcweir 	xint1=0;
98*cdf0e10cSrcweir 	rtl_unloadUnusedModules( NULL);
99*cdf0e10cSrcweir 	pSymbol= osl_getSymbol( hMod,sFactoryFunc.pData);
100*cdf0e10cSrcweir 	sal_Bool bTest2= pSymbol ? sal_False : sal_True;
101*cdf0e10cSrcweir 
102*cdf0e10cSrcweir 	Reference<XComponent> xcomp( context, UNO_QUERY);
103*cdf0e10cSrcweir 	xcomp->dispose();
104*cdf0e10cSrcweir 
105*cdf0e10cSrcweir 	return bTest2 && bTest1;
106*cdf0e10cSrcweir }
107*cdf0e10cSrcweir 
108*cdf0e10cSrcweir sal_Bool test2()
109*cdf0e10cSrcweir {
110*cdf0e10cSrcweir 	printf("Test2:  com.sun.star.bridge.OleBridgeSupplierVar1\n");
111*cdf0e10cSrcweir 	Reference<XSimpleRegistry> xreg= createSimpleRegistry();
112*cdf0e10cSrcweir 	xreg->open( OUString( RTL_CONSTASCII_USTRINGPARAM("services.rdb")),
113*cdf0e10cSrcweir 							   sal_False, sal_False );
114*cdf0e10cSrcweir 
115*cdf0e10cSrcweir 	Reference< XComponentContext > context= bootstrap_InitialComponentContext(xreg);
116*cdf0e10cSrcweir 	Reference<XMultiComponentFactory> fac= context->getServiceManager();
117*cdf0e10cSrcweir   	OUString sService2( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.bridge.OleBridgeSupplierVar1"));
118*cdf0e10cSrcweir 	Reference<XInterface> xint= fac->createInstanceWithContext( sService2, context);
119*cdf0e10cSrcweir 
120*cdf0e10cSrcweir 	OUString sModule(
121*cdf0e10cSrcweir         RTL_CONSTASCII_USTRINGPARAM("oleautobridge.uno" SAL_DLLEXTENSION));
122*cdf0e10cSrcweir 	oslModule hMod= osl_loadModule( sModule.pData, 0);
123*cdf0e10cSrcweir 	osl_unloadModule( hMod);
124*cdf0e10cSrcweir 
125*cdf0e10cSrcweir 	rtl_unloadUnusedModules( NULL);
126*cdf0e10cSrcweir 	OUString sFactoryFunc( RTL_CONSTASCII_USTRINGPARAM("component_getFactory"));
127*cdf0e10cSrcweir 	void* pSymbol= osl_getSymbol( hMod,sFactoryFunc.pData);
128*cdf0e10cSrcweir 	// true, instance alive
129*cdf0e10cSrcweir 	sal_Bool bTest1= pSymbol ? sal_True : sal_False;
130*cdf0e10cSrcweir 
131*cdf0e10cSrcweir 	xint=0;
132*cdf0e10cSrcweir 	rtl_unloadUnusedModules( NULL);
133*cdf0e10cSrcweir 	pSymbol= osl_getSymbol( hMod,sFactoryFunc.pData);
134*cdf0e10cSrcweir 	sal_Bool bTest2= pSymbol ? sal_False : sal_True;
135*cdf0e10cSrcweir 
136*cdf0e10cSrcweir 	Reference<XComponent> xcomp( context, UNO_QUERY);
137*cdf0e10cSrcweir 	xcomp->dispose();
138*cdf0e10cSrcweir 	return bTest1 && bTest2;
139*cdf0e10cSrcweir }
140*cdf0e10cSrcweir 
141*cdf0e10cSrcweir sal_Bool test3()
142*cdf0e10cSrcweir {
143*cdf0e10cSrcweir 	printf("Test3:  com.sun.star.bridge.oleautomation.Factory\n");
144*cdf0e10cSrcweir 	Reference<XSimpleRegistry> xreg= createSimpleRegistry();
145*cdf0e10cSrcweir 	xreg->open( OUString( RTL_CONSTASCII_USTRINGPARAM("services.rdb")),
146*cdf0e10cSrcweir 				sal_False, sal_False );
147*cdf0e10cSrcweir 
148*cdf0e10cSrcweir 	Reference< XComponentContext > context= bootstrap_InitialComponentContext(xreg);
149*cdf0e10cSrcweir 
150*cdf0e10cSrcweir 	Reference<XMultiComponentFactory> fac= context->getServiceManager();
151*cdf0e10cSrcweir   	OUString sService( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.bridge.oleautomation.Factory"));
152*cdf0e10cSrcweir 	Reference<XInterface> xint= fac->createInstanceWithContext( sService, context);
153*cdf0e10cSrcweir 
154*cdf0e10cSrcweir 
155*cdf0e10cSrcweir 	OUString sModule(
156*cdf0e10cSrcweir         RTL_CONSTASCII_USTRINGPARAM("oleautobridge.uno" SAL_DLLEXTENSION));
157*cdf0e10cSrcweir 	oslModule hMod= osl_loadModule( sModule.pData, 0);
158*cdf0e10cSrcweir 	osl_unloadModule( hMod);
159*cdf0e10cSrcweir 
160*cdf0e10cSrcweir 	rtl_unloadUnusedModules( NULL);
161*cdf0e10cSrcweir 	OUString sFactoryFunc( RTL_CONSTASCII_USTRINGPARAM("component_getFactory"));
162*cdf0e10cSrcweir 	void* pSymbol= osl_getSymbol( hMod,sFactoryFunc.pData);
163*cdf0e10cSrcweir 	// true, instance alive
164*cdf0e10cSrcweir 	sal_Bool bTest1= pSymbol ? sal_True : sal_False;
165*cdf0e10cSrcweir 
166*cdf0e10cSrcweir 	xint=0;
167*cdf0e10cSrcweir 	rtl_unloadUnusedModules( NULL);
168*cdf0e10cSrcweir 	pSymbol= osl_getSymbol( hMod,sFactoryFunc.pData);
169*cdf0e10cSrcweir 	sal_Bool bTest2= pSymbol ? sal_False : sal_True;
170*cdf0e10cSrcweir 
171*cdf0e10cSrcweir 	Reference<XComponent> xcomp( context, UNO_QUERY);
172*cdf0e10cSrcweir 	xcomp->dispose();
173*cdf0e10cSrcweir 
174*cdf0e10cSrcweir //	for (int i=0; i < 10; i++)
175*cdf0e10cSrcweir //	{
176*cdf0e10cSrcweir //		Reference<XSimpleRegistry> xreg= createSimpleRegistry();
177*cdf0e10cSrcweir //		xreg->open( OUString( RTL_CONSTASCII_USTRINGPARAM("applicat.rdb")),
178*cdf0e10cSrcweir //							   sal_False, sal_False );
179*cdf0e10cSrcweir //		Reference< XComponentContext > context= bootstrap_InitialComponentContext(xreg);
180*cdf0e10cSrcweir //		Reference<XComponent> xcomp( context, UNO_QUERY);
181*cdf0e10cSrcweir //		xcomp->dispose();
182*cdf0e10cSrcweir //
183*cdf0e10cSrcweir //	}
184*cdf0e10cSrcweir 
185*cdf0e10cSrcweir //	return sal_True;
186*cdf0e10cSrcweir 	return bTest1 && bTest2;
187*cdf0e10cSrcweir }
188*cdf0e10cSrcweir 
189*cdf0e10cSrcweir sal_Bool test4()
190*cdf0e10cSrcweir {
191*cdf0e10cSrcweir 	void* pSymbol= NULL;
192*cdf0e10cSrcweir 	sal_Bool bTest1= sal_False;
193*cdf0e10cSrcweir 	sal_Bool bTest2= sal_False;
194*cdf0e10cSrcweir 	oslModule hMod= NULL;
195*cdf0e10cSrcweir 	OUString sModule(
196*cdf0e10cSrcweir         RTL_CONSTASCII_USTRINGPARAM("oleautobridge.uno" SAL_DLLEXTENSION));
197*cdf0e10cSrcweir 	OUString sFactoryFunc( RTL_CONSTASCII_USTRINGPARAM("component_getFactory"));
198*cdf0e10cSrcweir 	{
199*cdf0e10cSrcweir 	printf("Test4:  com.sun.star.bridge.oleautomation.ApplicationRegistration\n");
200*cdf0e10cSrcweir    	Reference<XSimpleRegistry> xreg= createSimpleRegistry();
201*cdf0e10cSrcweir 	xreg->open( OUString( RTL_CONSTASCII_USTRINGPARAM("services.rdb")),
202*cdf0e10cSrcweir 							   sal_False, sal_False );
203*cdf0e10cSrcweir 
204*cdf0e10cSrcweir 	Reference< XComponentContext > context= bootstrap_InitialComponentContext(xreg);
205*cdf0e10cSrcweir 	Reference<XMultiComponentFactory> fac= context->getServiceManager();
206*cdf0e10cSrcweir 	OUString sService4( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.bridge.oleautomation.ApplicationRegistration"));
207*cdf0e10cSrcweir 	Reference<XInterface> xint= fac->createInstanceWithContext( sService4, context);
208*cdf0e10cSrcweir 
209*cdf0e10cSrcweir 	hMod= osl_loadModule( sModule.pData, 0);
210*cdf0e10cSrcweir 	osl_unloadModule( hMod);
211*cdf0e10cSrcweir 
212*cdf0e10cSrcweir 	rtl_unloadUnusedModules( NULL);
213*cdf0e10cSrcweir 	void* pSymbol= osl_getSymbol( hMod,sFactoryFunc.pData);
214*cdf0e10cSrcweir 	// true, instance alive
215*cdf0e10cSrcweir 	bTest1= pSymbol ? sal_True : sal_False;
216*cdf0e10cSrcweir 	// ApplicationRegistration is a one-instance-service, therefore kill service manager first
217*cdf0e10cSrcweir 	Reference<XComponent> xcomp( context, UNO_QUERY);
218*cdf0e10cSrcweir 	xcomp->dispose();
219*cdf0e10cSrcweir 
220*cdf0e10cSrcweir 	}
221*cdf0e10cSrcweir 	rtl_unloadUnusedModules( NULL);
222*cdf0e10cSrcweir 	pSymbol= osl_getSymbol( hMod,sFactoryFunc.pData);
223*cdf0e10cSrcweir 	bTest2= pSymbol ? sal_False : sal_True;
224*cdf0e10cSrcweir 
225*cdf0e10cSrcweir 	return bTest1 && bTest2;
226*cdf0e10cSrcweir }
227