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