merge the formfield patch from ooo-build
[ooovba.git] / extensions / test / ole / unloading / unloadTest.cxx
blobb11ae89bd2a5295e67538e91187f30206415cef5
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: unloadTest.cxx,v $
10 * $Revision: 1.5 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
32 // MARKER(update_precomp.py): autogen include statement, do not remove
33 #include "precompiled_extensions.hxx"
35 #include<osl/module.hxx>
36 #include <osl/time.h>
37 #include <rtl/ustring.hxx>
38 #include <stdio.h>
39 #include <cppuhelper/factory.hxx>
40 #include <cppuhelper/servicefactory.hxx>
41 #include <cppuhelper/bootstrap.hxx>
42 #include <com/sun/star/lang/XMultiComponentFactory.hpp>
43 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
44 #include <com/sun/star/lang/XServiceInfo.hpp>
45 #include <com/sun/star/lang/XComponent.hpp>
46 #include <com/sun/star/uno/XComponentContext.hpp>
47 #include <com/sun/star/registry/XSimpleRegistry.hpp>
49 #include <stdio.h>
50 using namespace ::rtl;
51 using namespace ::osl;
52 using namespace ::com::sun::star::uno;
53 using namespace ::com::sun::star::lang;
54 using namespace ::cppu;
55 using namespace ::com::sun::star::registry;
58 sal_Bool test1();
59 sal_Bool test2();
60 sal_Bool test3();
61 sal_Bool test4();
63 int main(int, char**)
65 sal_Bool bTest1= test1();
66 sal_Bool bTest2= test2();
67 sal_Bool bTest3= test3();
68 sal_Bool bTest4= test4();
70 if( bTest1 && bTest2 && bTest3 && bTest4)
71 printf("\n#########################\n Test was successful\n#######################\n");
73 return 0;
76 sal_Bool test1()
78 printf("\n Test1: com.sun.star.bridge.oleautomation.BridgeSupplier\n");
79 Reference<XSimpleRegistry> xreg= createSimpleRegistry();
80 xreg->open( OUString( RTL_CONSTASCII_USTRINGPARAM("services.rdb")),
81 sal_False, sal_False );
83 Reference< XComponentContext > context= bootstrap_InitialComponentContext(xreg);
84 Reference<XMultiComponentFactory> fac= context->getServiceManager();
85 OUString sService1( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.bridge.oleautomation.BridgeSupplier"));
86 Reference<XInterface> xint1= fac->createInstanceWithContext( sService1, context);
88 OUString sModule(
89 RTL_CONSTASCII_USTRINGPARAM("oleautobridge.uno" SAL_DLLEXTENSION));
90 oslModule hMod= osl_loadModule( sModule.pData, 0);
91 osl_unloadModule( hMod);
93 rtl_unloadUnusedModules( NULL);
95 OUString sFactoryFunc( RTL_CONSTASCII_USTRINGPARAM("component_getFactory"));
96 void* pSymbol= osl_getSymbol( hMod,sFactoryFunc.pData);
97 // true, instance alive
98 sal_Bool bTest1= pSymbol ? sal_True : sal_False;
100 xint1=0;
101 rtl_unloadUnusedModules( NULL);
102 pSymbol= osl_getSymbol( hMod,sFactoryFunc.pData);
103 sal_Bool bTest2= pSymbol ? sal_False : sal_True;
105 Reference<XComponent> xcomp( context, UNO_QUERY);
106 xcomp->dispose();
108 return bTest2 && bTest1;
111 sal_Bool test2()
113 printf("Test2: com.sun.star.bridge.OleBridgeSupplierVar1\n");
114 Reference<XSimpleRegistry> xreg= createSimpleRegistry();
115 xreg->open( OUString( RTL_CONSTASCII_USTRINGPARAM("services.rdb")),
116 sal_False, sal_False );
118 Reference< XComponentContext > context= bootstrap_InitialComponentContext(xreg);
119 Reference<XMultiComponentFactory> fac= context->getServiceManager();
120 OUString sService2( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.bridge.OleBridgeSupplierVar1"));
121 Reference<XInterface> xint= fac->createInstanceWithContext( sService2, context);
123 OUString sModule(
124 RTL_CONSTASCII_USTRINGPARAM("oleautobridge.uno" SAL_DLLEXTENSION));
125 oslModule hMod= osl_loadModule( sModule.pData, 0);
126 osl_unloadModule( hMod);
128 rtl_unloadUnusedModules( NULL);
129 OUString sFactoryFunc( RTL_CONSTASCII_USTRINGPARAM("component_getFactory"));
130 void* pSymbol= osl_getSymbol( hMod,sFactoryFunc.pData);
131 // true, instance alive
132 sal_Bool bTest1= pSymbol ? sal_True : sal_False;
134 xint=0;
135 rtl_unloadUnusedModules( NULL);
136 pSymbol= osl_getSymbol( hMod,sFactoryFunc.pData);
137 sal_Bool bTest2= pSymbol ? sal_False : sal_True;
139 Reference<XComponent> xcomp( context, UNO_QUERY);
140 xcomp->dispose();
141 return bTest1 && bTest2;
144 sal_Bool test3()
146 printf("Test3: com.sun.star.bridge.oleautomation.Factory\n");
147 Reference<XSimpleRegistry> xreg= createSimpleRegistry();
148 xreg->open( OUString( RTL_CONSTASCII_USTRINGPARAM("services.rdb")),
149 sal_False, sal_False );
151 Reference< XComponentContext > context= bootstrap_InitialComponentContext(xreg);
153 Reference<XMultiComponentFactory> fac= context->getServiceManager();
154 OUString sService( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.bridge.oleautomation.Factory"));
155 Reference<XInterface> xint= fac->createInstanceWithContext( sService, context);
158 OUString sModule(
159 RTL_CONSTASCII_USTRINGPARAM("oleautobridge.uno" SAL_DLLEXTENSION));
160 oslModule hMod= osl_loadModule( sModule.pData, 0);
161 osl_unloadModule( hMod);
163 rtl_unloadUnusedModules( NULL);
164 OUString sFactoryFunc( RTL_CONSTASCII_USTRINGPARAM("component_getFactory"));
165 void* pSymbol= osl_getSymbol( hMod,sFactoryFunc.pData);
166 // true, instance alive
167 sal_Bool bTest1= pSymbol ? sal_True : sal_False;
169 xint=0;
170 rtl_unloadUnusedModules( NULL);
171 pSymbol= osl_getSymbol( hMod,sFactoryFunc.pData);
172 sal_Bool bTest2= pSymbol ? sal_False : sal_True;
174 Reference<XComponent> xcomp( context, UNO_QUERY);
175 xcomp->dispose();
177 // for (int i=0; i < 10; i++)
178 // {
179 // Reference<XSimpleRegistry> xreg= createSimpleRegistry();
180 // xreg->open( OUString( RTL_CONSTASCII_USTRINGPARAM("applicat.rdb")),
181 // sal_False, sal_False );
182 // Reference< XComponentContext > context= bootstrap_InitialComponentContext(xreg);
183 // Reference<XComponent> xcomp( context, UNO_QUERY);
184 // xcomp->dispose();
186 // }
188 // return sal_True;
189 return bTest1 && bTest2;
192 sal_Bool test4()
194 void* pSymbol= NULL;
195 sal_Bool bTest1= sal_False;
196 sal_Bool bTest2= sal_False;
197 oslModule hMod= NULL;
198 OUString sModule(
199 RTL_CONSTASCII_USTRINGPARAM("oleautobridge.uno" SAL_DLLEXTENSION));
200 OUString sFactoryFunc( RTL_CONSTASCII_USTRINGPARAM("component_getFactory"));
202 printf("Test4: com.sun.star.bridge.oleautomation.ApplicationRegistration\n");
203 Reference<XSimpleRegistry> xreg= createSimpleRegistry();
204 xreg->open( OUString( RTL_CONSTASCII_USTRINGPARAM("services.rdb")),
205 sal_False, sal_False );
207 Reference< XComponentContext > context= bootstrap_InitialComponentContext(xreg);
208 Reference<XMultiComponentFactory> fac= context->getServiceManager();
209 OUString sService4( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.bridge.oleautomation.ApplicationRegistration"));
210 Reference<XInterface> xint= fac->createInstanceWithContext( sService4, context);
212 hMod= osl_loadModule( sModule.pData, 0);
213 osl_unloadModule( hMod);
215 rtl_unloadUnusedModules( NULL);
216 void* pSymbol= osl_getSymbol( hMod,sFactoryFunc.pData);
217 // true, instance alive
218 bTest1= pSymbol ? sal_True : sal_False;
219 // ApplicationRegistration is a one-instance-service, therefore kill service manager first
220 Reference<XComponent> xcomp( context, UNO_QUERY);
221 xcomp->dispose();
224 rtl_unloadUnusedModules( NULL);
225 pSymbol= osl_getSymbol( hMod,sFactoryFunc.pData);
226 bTest2= pSymbol ? sal_False : sal_True;
228 return bTest1 && bTest2;