1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: unloadTest.cxx,v $
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>
37 #include <rtl/ustring.hxx>
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>
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
;
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");
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
);
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
;
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
);
108 return bTest2
&& bTest1
;
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
);
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
;
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
);
141 return bTest1
&& bTest2
;
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
);
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
;
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
);
177 // for (int i=0; i < 10; i++)
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);
189 return bTest1
&& bTest2
;
195 sal_Bool bTest1
= sal_False
;
196 sal_Bool bTest2
= sal_False
;
197 oslModule hMod
= NULL
;
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
);
224 rtl_unloadUnusedModules( NULL
);
225 pSymbol
= osl_getSymbol( hMod
,sFactoryFunc
.pData
);
226 bTest2
= pSymbol
? sal_False
: sal_True
;
228 return bTest1
&& bTest2
;