1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 25 // MARKER(update_precomp.py): autogen include statement, do not remove 26 #include "precompiled_extensions.hxx" 27 28 #include<osl/module.hxx> 29 #include <osl/time.h> 30 #include <rtl/ustring.hxx> 31 #include <stdio.h> 32 #include <cppuhelper/factory.hxx> 33 #include <cppuhelper/servicefactory.hxx> 34 #include <cppuhelper/bootstrap.hxx> 35 #include <com/sun/star/lang/XMultiComponentFactory.hpp> 36 #include <com/sun/star/lang/XSingleServiceFactory.hpp> 37 #include <com/sun/star/lang/XServiceInfo.hpp> 38 #include <com/sun/star/lang/XComponent.hpp> 39 #include <com/sun/star/uno/XComponentContext.hpp> 40 #include <com/sun/star/registry/XSimpleRegistry.hpp> 41 42 #include <stdio.h> 43 using namespace ::rtl; 44 using namespace ::osl; 45 using namespace ::com::sun::star::uno; 46 using namespace ::com::sun::star::lang; 47 using namespace ::cppu; 48 using namespace ::com::sun::star::registry; 49 50 51 sal_Bool test1(); 52 sal_Bool test2(); 53 sal_Bool test3(); 54 sal_Bool test4(); 55 56 int main(int, char**) 57 { 58 sal_Bool bTest1= test1(); 59 sal_Bool bTest2= test2(); 60 sal_Bool bTest3= test3(); 61 sal_Bool bTest4= test4(); 62 63 if( bTest1 && bTest2 && bTest3 && bTest4) 64 printf("\n#########################\n Test was successful\n#######################\n"); 65 66 return 0; 67 } 68 69 sal_Bool test1() 70 { 71 printf("\n Test1: com.sun.star.bridge.oleautomation.BridgeSupplier\n"); 72 Reference<XSimpleRegistry> xreg= createSimpleRegistry(); 73 xreg->open( OUString( RTL_CONSTASCII_USTRINGPARAM("services.rdb")), 74 sal_False, sal_False ); 75 76 Reference< XComponentContext > context= bootstrap_InitialComponentContext(xreg); 77 Reference<XMultiComponentFactory> fac= context->getServiceManager(); 78 OUString sService1( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.bridge.oleautomation.BridgeSupplier")); 79 Reference<XInterface> xint1= fac->createInstanceWithContext( sService1, context); 80 81 OUString sModule( 82 RTL_CONSTASCII_USTRINGPARAM("oleautobridge.uno" SAL_DLLEXTENSION)); 83 oslModule hMod= osl_loadModule( sModule.pData, 0); 84 osl_unloadModule( hMod); 85 86 rtl_unloadUnusedModules( NULL); 87 88 OUString sFactoryFunc( RTL_CONSTASCII_USTRINGPARAM("component_getFactory")); 89 void* pSymbol= osl_getSymbol( hMod,sFactoryFunc.pData); 90 // true, instance alive 91 sal_Bool bTest1= pSymbol ? sal_True : sal_False; 92 93 xint1=0; 94 rtl_unloadUnusedModules( NULL); 95 pSymbol= osl_getSymbol( hMod,sFactoryFunc.pData); 96 sal_Bool bTest2= pSymbol ? sal_False : sal_True; 97 98 Reference<XComponent> xcomp( context, UNO_QUERY); 99 xcomp->dispose(); 100 101 return bTest2 && bTest1; 102 } 103 104 sal_Bool test2() 105 { 106 printf("Test2: com.sun.star.bridge.OleBridgeSupplierVar1\n"); 107 Reference<XSimpleRegistry> xreg= createSimpleRegistry(); 108 xreg->open( OUString( RTL_CONSTASCII_USTRINGPARAM("services.rdb")), 109 sal_False, sal_False ); 110 111 Reference< XComponentContext > context= bootstrap_InitialComponentContext(xreg); 112 Reference<XMultiComponentFactory> fac= context->getServiceManager(); 113 OUString sService2( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.bridge.OleBridgeSupplierVar1")); 114 Reference<XInterface> xint= fac->createInstanceWithContext( sService2, context); 115 116 OUString sModule( 117 RTL_CONSTASCII_USTRINGPARAM("oleautobridge.uno" SAL_DLLEXTENSION)); 118 oslModule hMod= osl_loadModule( sModule.pData, 0); 119 osl_unloadModule( hMod); 120 121 rtl_unloadUnusedModules( NULL); 122 OUString sFactoryFunc( RTL_CONSTASCII_USTRINGPARAM("component_getFactory")); 123 void* pSymbol= osl_getSymbol( hMod,sFactoryFunc.pData); 124 // true, instance alive 125 sal_Bool bTest1= pSymbol ? sal_True : sal_False; 126 127 xint=0; 128 rtl_unloadUnusedModules( NULL); 129 pSymbol= osl_getSymbol( hMod,sFactoryFunc.pData); 130 sal_Bool bTest2= pSymbol ? sal_False : sal_True; 131 132 Reference<XComponent> xcomp( context, UNO_QUERY); 133 xcomp->dispose(); 134 return bTest1 && bTest2; 135 } 136 137 sal_Bool test3() 138 { 139 printf("Test3: com.sun.star.bridge.oleautomation.Factory\n"); 140 Reference<XSimpleRegistry> xreg= createSimpleRegistry(); 141 xreg->open( OUString( RTL_CONSTASCII_USTRINGPARAM("services.rdb")), 142 sal_False, sal_False ); 143 144 Reference< XComponentContext > context= bootstrap_InitialComponentContext(xreg); 145 146 Reference<XMultiComponentFactory> fac= context->getServiceManager(); 147 OUString sService( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.bridge.oleautomation.Factory")); 148 Reference<XInterface> xint= fac->createInstanceWithContext( sService, context); 149 150 151 OUString sModule( 152 RTL_CONSTASCII_USTRINGPARAM("oleautobridge.uno" SAL_DLLEXTENSION)); 153 oslModule hMod= osl_loadModule( sModule.pData, 0); 154 osl_unloadModule( hMod); 155 156 rtl_unloadUnusedModules( NULL); 157 OUString sFactoryFunc( RTL_CONSTASCII_USTRINGPARAM("component_getFactory")); 158 void* pSymbol= osl_getSymbol( hMod,sFactoryFunc.pData); 159 // true, instance alive 160 sal_Bool bTest1= pSymbol ? sal_True : sal_False; 161 162 xint=0; 163 rtl_unloadUnusedModules( NULL); 164 pSymbol= osl_getSymbol( hMod,sFactoryFunc.pData); 165 sal_Bool bTest2= pSymbol ? sal_False : sal_True; 166 167 Reference<XComponent> xcomp( context, UNO_QUERY); 168 xcomp->dispose(); 169 170 // for (int i=0; i < 10; i++) 171 // { 172 // Reference<XSimpleRegistry> xreg= createSimpleRegistry(); 173 // xreg->open( OUString( RTL_CONSTASCII_USTRINGPARAM("applicat.rdb")), 174 // sal_False, sal_False ); 175 // Reference< XComponentContext > context= bootstrap_InitialComponentContext(xreg); 176 // Reference<XComponent> xcomp( context, UNO_QUERY); 177 // xcomp->dispose(); 178 // 179 // } 180 181 // return sal_True; 182 return bTest1 && bTest2; 183 } 184 185 sal_Bool test4() 186 { 187 void* pSymbol= NULL; 188 sal_Bool bTest1= sal_False; 189 sal_Bool bTest2= sal_False; 190 oslModule hMod= NULL; 191 OUString sModule( 192 RTL_CONSTASCII_USTRINGPARAM("oleautobridge.uno" SAL_DLLEXTENSION)); 193 OUString sFactoryFunc( RTL_CONSTASCII_USTRINGPARAM("component_getFactory")); 194 { 195 printf("Test4: com.sun.star.bridge.oleautomation.ApplicationRegistration\n"); 196 Reference<XSimpleRegistry> xreg= createSimpleRegistry(); 197 xreg->open( OUString( RTL_CONSTASCII_USTRINGPARAM("services.rdb")), 198 sal_False, sal_False ); 199 200 Reference< XComponentContext > context= bootstrap_InitialComponentContext(xreg); 201 Reference<XMultiComponentFactory> fac= context->getServiceManager(); 202 OUString sService4( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.bridge.oleautomation.ApplicationRegistration")); 203 Reference<XInterface> xint= fac->createInstanceWithContext( sService4, context); 204 205 hMod= osl_loadModule( sModule.pData, 0); 206 osl_unloadModule( hMod); 207 208 rtl_unloadUnusedModules( NULL); 209 void* pSymbol= osl_getSymbol( hMod,sFactoryFunc.pData); 210 // true, instance alive 211 bTest1= pSymbol ? sal_True : sal_False; 212 // ApplicationRegistration is a one-instance-service, therefore kill service manager first 213 Reference<XComponent> xcomp( context, UNO_QUERY); 214 xcomp->dispose(); 215 216 } 217 rtl_unloadUnusedModules( NULL); 218 pSymbol= osl_getSymbol( hMod,sFactoryFunc.pData); 219 bTest2= pSymbol ? sal_False : sal_True; 220 221 return bTest1 && bTest2; 222 } 223