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