diff options
author | Joachim Lingner <jl@openoffice.org> | 2001-06-07 09:13:57 +0000 |
---|---|---|
committer | Joachim Lingner <jl@openoffice.org> | 2001-06-07 09:13:57 +0000 |
commit | 46049d9ec096157dfcca6b403c0b74056d8d6f57 (patch) | |
tree | db0dff570cb49a1ef9144de665ea53d0f9b1fc12 /sal/test | |
parent | e2b8c022a545953392d16e96ed70777bdda9fdbd (diff) |
new
Diffstat (limited to 'sal/test')
-rw-r--r-- | sal/test/unloading/exports.dxp | 5 | ||||
-rw-r--r-- | sal/test/unloading/makefile.mk | 179 | ||||
-rw-r--r-- | sal/test/unloading/readme.txt | 14 | ||||
-rw-r--r-- | sal/test/unloading/samplelib1.cxx | 239 |
4 files changed, 437 insertions, 0 deletions
diff --git a/sal/test/unloading/exports.dxp b/sal/test/unloading/exports.dxp new file mode 100644 index 000000000000..ef7aff584724 --- /dev/null +++ b/sal/test/unloading/exports.dxp @@ -0,0 +1,5 @@ +component_getDescriptionFunc +component_getImplementationEnvironment +component_writeInfo +component_getFactory +component_canUnload diff --git a/sal/test/unloading/makefile.mk b/sal/test/unloading/makefile.mk new file mode 100644 index 000000000000..e3874542ea0f --- /dev/null +++ b/sal/test/unloading/makefile.mk @@ -0,0 +1,179 @@ +#************************************************************************* +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.1 $ +# +# last change: $Author: jl $ $Date: 2001-06-07 10:13:30 $ +# +# The Contents of this file are made available subject to the terms of +# either of the following licenses +# +# - GNU Lesser General Public License Version 2.1 +# - Sun Industry Standards Source License Version 1.1 +# +# Sun Microsystems Inc., October, 2000 +# +# GNU Lesser General Public License Version 2.1 +# ============================================= +# Copyright 2000 by Sun Microsystems, Inc. +# 901 San Antonio Road, Palo Alto, CA 94303, USA +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License version 2.1, as published by the Free Software Foundation. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, +# MA 02111-1307 USA +# +# +# Sun Industry Standards Source License Version 1.1 +# ================================================= +# The contents of this file are subject to the Sun Industry Standards +# Source License Version 1.1 (the "License"); You may not use this file +# except in compliance with the License. You may obtain a copy of the +# License at http://www.openoffice.org/license.html. +# +# Software provided under this License is provided on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, +# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, +# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. +# See the License for the specific provisions governing your rights and +# obligations concerning the Software. +# +# The Initial Developer of the Original Code is: Sun Microsystems, Inc. +# +# Copyright: 2000 by Sun Microsystems, Inc. +# +# All Rights Reserved. +# +# Contributor(s): _______________________________________ +# +# +# +#************************************************************************* +PRJ=..$/.. + +PRJNAME= sal +TARGET= unloading +TARGET1=samplelib1 +TARGET2=samplelib2 +#LIBTARGET=NO +TARGETTYPE=CUI +COMP1TYPELIST=$(TARGET1) + +NO_BSYMBOLIC= TRUE +ENABLE_EXCEPTIONS=TRUE + +USE_DEFFILE= TRUE + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk + +# --- Files -------------------------------------------------------- + +UNOUCRDEP=$(SOLARBINDIR)$/udkapi.rdb +UNOUCRRDB=$(SOLARBINDIR)$/udkapi.rdb + +CPPUMAKERFLAGS = + +.IF "$(BOOTSTRAP_SERVICE)" == "TRUE" +UNOUCROUT= $(OUT)$/inc$/bootstrap +INCPRE+= $(OUT)$/inc$/bootstrap +.ELSE +.IF "$(COM)" == "MSC" +CPPUMAKERFLAGS = -L +.ENDIF +UNOUCROUT= $(OUT)$/inc$/light +INCPRE+= $(OUT)$/inc$/light +.ENDIF + + +#SLOFILES= \ +# $(SLO)$/samplelib1.obj \ +# $(SLO)$/samplelib2.obj + +LIB1TARGET=$(SLB)$/$(TARGET1).lib +LIB1OBJFILES= \ + $(SLO)$/samplelib1.obj + +SHL1TARGET= $(TARGET1) + +SHL1STDLIBS= \ + $(CPPULIB) \ + $(CPPUHELPERLIB) \ + $(SALLIB) + + + +SHL1DEPN= +#SHL1IMPLIB= i$(TARGET1) +SHL1LIBS= $(SLB)$/$(TARGET1).lib +SHL1DEF= $(MISC)$/$(SHL1TARGET).def +DEF1EXPORTFILE= exports.dxp +DEF1NAME= $(SHL1TARGET) +#------------------------------------------------------- + +LIB2TARGET=$(SLB)$/$(TARGET2).lib +LIB2OBJFILES= \ + $(SLO)$/samplelib2.obj + +SHL2TARGET= $(TARGET2) + +SHL2STDLIBS= \ + $(CPPULIB) \ + $(CPPUHELPERLIB) \ + $(SALLIB) + +SHL2DEPN= +SHL2LIBS= $(SLB)$/$(TARGET2).lib +SHL2DEF= $(MISC)$/$(SHL2TARGET).def +DEF2EXPORTFILE= exports.dxp +DEF2NAME= $(SHL2TARGET) + +# generate exports ------------------------------------------------ +#DEF1DEPN= $(MISC)$/$(SHL1TARGET).flt +#DEFLIB1NAME= $(TARGET) +#----------------------------------------------------------------- + + + +# ------------------------------------------------------------------ + +APP1NOSAL=TRUE + +APP1TARGET= $(TARGET) + +APP1OBJS= $(OBJ)$/unloadTest.obj + +APP1STDLIBS= \ + $(SALLIB) \ + $(CPPUHELPERLIB) \ + $(CPPULIB) + + + + +LIBCIMT=MSVCPRTD.lib + + +.IF "$(GUI)"=="WNT" +#APP1STDLIBS += $(LIBCIMT) +.ENDIF + +# --- Targets ------------------------------------------------------ + +.INCLUDE : target.mk + +#$(MISC)$/$(SHL1TARGET).flt : makefile.mk +# +echo _TI2 >$@ +# +echo _TI1 >>$@ + diff --git a/sal/test/unloading/readme.txt b/sal/test/unloading/readme.txt new file mode 100644 index 000000000000..7fae8850c1be --- /dev/null +++ b/sal/test/unloading/readme.txt @@ -0,0 +1,14 @@ +The test program test the unloading API, and the default factories from cppuhelper +for their new XUnloadingPreference interface. + +The makefile produces the executable unloading.exe as wells as two +libraries, samplelib1 and samplelib2, which contain services. + + +Usage: + Copy unloading, samplelib1, samplelib2 into the program directory +of an office. + +Register samplelib1 and samplelib2 with regcomp + +Run unloading.
\ No newline at end of file diff --git a/sal/test/unloading/samplelib1.cxx b/sal/test/unloading/samplelib1.cxx new file mode 100644 index 000000000000..1a21c3d998a0 --- /dev/null +++ b/sal/test/unloading/samplelib1.cxx @@ -0,0 +1,239 @@ + +#include <sal/types.h> +#include <osl/time.h> +#include <rtl/ustring.hxx> +#include <uno/environment.h> +#include <cppu/macros.hxx> +#include <cppuhelper/factory.hxx> +#include <com/sun/star/uno/reference.hxx> +#include <com/sun/star/uno/sequence.hxx> +#include <cppuhelper/implbase1.hxx> +#include <rtl/unload.h> +#include <rtl/string.hxx> +#include <rtl/ustrbuf.hxx> +#include <com/sun/star/lang/XSingleServiceFactory.hpp> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/registry/XRegistryKey.hpp> + +using namespace ::com::sun::star::registry; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::lang; +using namespace ::rtl; +using namespace ::cppu; + +#define IMPLNAME1 "com.sun.star.comp.sal.UnloadingTest1" +#define SERVICENAME1 "com.sun.star.UnloadingTest1" +#define IMPLNAME2 "com.sun.star.comp.sal.UnloadingTest2" +#define SERVICENAME2 "com.sun.star.UnloadingTest2" +#define IMPLNAME3 "com.sun.star.comp.sal.UnloadingTest3" +#define SERVICENAME3 "com.sun.star.UnloadingTest3" +#define IMPLNAME4 "com.sun.star.comp.sal.OneInstanceTest" +#define SERVICENAME4 "com.sun.star.OneInstanceTest" + + +// Unloading Support ---------------------------------------------- +//rtl_StandardModuleCount globalModuleCount= MODULE_COUNT_INIT; +rtl_StandardModuleCount globalModuleCount= { {rtl_moduleCount_acquire,rtl_moduleCount_release}, rtl_moduleCount_canUnload,0,{0,0}}; //, 0, {0, 0}}; +// Services ------------------------------------------------------- +class TestService: public WeakImplHelper1<XServiceInfo> +{ +OUString m_implName; +OUString m_serviceName; +public: + TestService( OUString implName, OUString serviceName); + ~TestService(); + virtual OUString SAL_CALL getImplementationName( ) throw (RuntimeException); + virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) throw (RuntimeException); + virtual Sequence<OUString > SAL_CALL getSupportedServiceNames( ) throw (RuntimeException); +}; + +TestService::TestService( OUString implName, OUString serviceName): + m_implName(implName),m_serviceName(serviceName) +{ // Library unloading support + globalModuleCount.modCnt.acquire( &globalModuleCount.modCnt); +} + +TestService::~TestService() +{ // Library unloading support + globalModuleCount.modCnt.release( &globalModuleCount.modCnt); +} + +OUString SAL_CALL TestService::getImplementationName( ) throw (RuntimeException) +{ + return m_implName; +} +sal_Bool SAL_CALL TestService::supportsService( const OUString& ServiceName ) throw (RuntimeException) +{ + return ServiceName.equals( m_serviceName); +} +Sequence<OUString > SAL_CALL TestService::getSupportedServiceNames( ) throw (RuntimeException) +{ + return Sequence<OUString>( &m_serviceName, 1); +} + + +// Creator functions for Services ------------------------------------------------- +static Reference<XInterface> SAL_CALL test1_createInstance(const Reference<XMultiServiceFactory> & rSMgr) + throw (RuntimeException) +{ + return Reference<XInterface>( static_cast<XWeak*>( new TestService( + OUString( RTL_CONSTASCII_USTRINGPARAM( IMPLNAME1)), + OUString( RTL_CONSTASCII_USTRINGPARAM( SERVICENAME1)) )), UNO_QUERY); +} +static Reference<XInterface> SAL_CALL test2_createInstance(const Reference<XMultiServiceFactory> & rSMgr) + throw (RuntimeException) +{ + return Reference<XInterface>( static_cast<XWeak*>( new TestService( + OUString( RTL_CONSTASCII_USTRINGPARAM( IMPLNAME2)), + OUString( RTL_CONSTASCII_USTRINGPARAM( SERVICENAME2)) )), UNO_QUERY); +} +static Reference<XInterface> SAL_CALL test3_createInstance(const Reference<XMultiServiceFactory> & rSMgr) + throw (RuntimeException) +{ + return Reference<XInterface>( static_cast<XWeak*>( new TestService( + OUString( RTL_CONSTASCII_USTRINGPARAM( IMPLNAME3)), + OUString( RTL_CONSTASCII_USTRINGPARAM( SERVICENAME3)) )), UNO_QUERY); +} +static Reference<XInterface> SAL_CALL test4_createInstance(const Reference<XMultiServiceFactory> & rSMgr) + throw (RuntimeException) +{ + return Reference<XInterface>( static_cast<XWeak*>( new TestService( + OUString( RTL_CONSTASCII_USTRINGPARAM( IMPLNAME4)), + OUString( RTL_CONSTASCII_USTRINGPARAM( SERVICENAME4)) )), UNO_QUERY); +} + + +// Standard UNO library interface ------------------------------------------------- +extern "C" { + void SAL_CALL component_getImplementationEnvironment(const sal_Char ** ppEnvTypeName, uno_Environment ** ppEnv){ + *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME; + } + + sal_Bool SAL_CALL component_writeInfo(void * pServiceManager, void * pRegistryKey) throw() + { + if (pRegistryKey) + { + try + { + Reference< XRegistryKey > xNewKey( + reinterpret_cast< XRegistryKey * >( pRegistryKey )->createKey( + OUString::createFromAscii( "/" IMPLNAME1 "/UNO/SERVICES" ) ) ); + + xNewKey->createKey( OUString( RTL_CONSTASCII_USTRINGPARAM( SERVICENAME1))); + + xNewKey= + reinterpret_cast< XRegistryKey * >( pRegistryKey )->createKey( + OUString::createFromAscii( "/" IMPLNAME2 "/UNO/SERVICES" ) ); + + xNewKey->createKey(OUString( RTL_CONSTASCII_USTRINGPARAM( SERVICENAME2))); + xNewKey= + reinterpret_cast< XRegistryKey * >( pRegistryKey )->createKey( + OUString::createFromAscii( "/" IMPLNAME3 "/UNO/SERVICES" ) ); + + xNewKey->createKey(OUString( RTL_CONSTASCII_USTRINGPARAM( SERVICENAME3))); + + xNewKey= + reinterpret_cast< XRegistryKey * >( pRegistryKey )->createKey( + OUString::createFromAscii( "/" IMPLNAME4 "/UNO/SERVICES" ) ); + + xNewKey->createKey(OUString( RTL_CONSTASCII_USTRINGPARAM( SERVICENAME4))); + return sal_True; + } + catch (InvalidRegistryException &) + { + OSL_ENSURE( sal_False, "### InvalidRegistryException!" ); + } + } + return sal_False; + } + + void * SAL_CALL component_getFactory(const sal_Char * pImplName, void * pServiceManager, void * pRegistryKey) throw() + { + void * pRet = 0; + + + OUString implname1( RTL_CONSTASCII_USTRINGPARAM( IMPLNAME1) ); + OUString serviceName1( RTL_CONSTASCII_USTRINGPARAM( SERVICENAME1) ); + OUString implname2( RTL_CONSTASCII_USTRINGPARAM( IMPLNAME2) ); + OUString serviceName2( RTL_CONSTASCII_USTRINGPARAM( SERVICENAME2) ); + OUString implname3( RTL_CONSTASCII_USTRINGPARAM( IMPLNAME3) ); + OUString serviceName3( RTL_CONSTASCII_USTRINGPARAM( SERVICENAME3) ); + OUString implname4( RTL_CONSTASCII_USTRINGPARAM( IMPLNAME4) ); + OUString serviceName4( RTL_CONSTASCII_USTRINGPARAM( SERVICENAME4) ); + + if (implname1.equals( OUString::createFromAscii(pImplName))) + { + Reference<XMultiServiceFactory> mgr= reinterpret_cast<XMultiServiceFactory *>(pServiceManager); + Reference<XSingleServiceFactory> xFactory( createSingleFactory( + reinterpret_cast<XMultiServiceFactory *>(pServiceManager), + implname1, + test1_createInstance, + Sequence<OUString>( &serviceName1, 1), + &globalModuleCount.modCnt + )); + + if (xFactory.is()) + { + xFactory->acquire(); + pRet = xFactory.get(); + } + } + else if( implname2.equals( OUString::createFromAscii(pImplName))) + { + Reference<XMultiServiceFactory> mgr= reinterpret_cast<XMultiServiceFactory *>(pServiceManager); + Reference<XSingleServiceFactory> xFactory( createSingleFactory( + reinterpret_cast<XMultiServiceFactory *>(pServiceManager), + implname2, + test2_createInstance, + Sequence<OUString>( &serviceName2, 1), + &globalModuleCount.modCnt + )); + + if (xFactory.is()) + { + xFactory->acquire(); + pRet = xFactory.get(); + } + } + else if( implname3.equals( OUString::createFromAscii(pImplName))) + { + Reference<XMultiServiceFactory> mgr= reinterpret_cast<XMultiServiceFactory *>(pServiceManager); + Reference<XSingleServiceFactory> xFactory( createSingleFactory( + reinterpret_cast<XMultiServiceFactory *>(pServiceManager), + implname3, + test3_createInstance, + Sequence<OUString>( &serviceName3, 1), + &globalModuleCount.modCnt + )); + + if (xFactory.is()) + { + xFactory->acquire(); + pRet = xFactory.get(); + } + } + else if( implname4.equals( OUString::createFromAscii(pImplName))) + { + Reference<XMultiServiceFactory> mgr= reinterpret_cast<XMultiServiceFactory *>(pServiceManager); + Reference<XSingleServiceFactory> xFactory( createOneInstanceFactory( + reinterpret_cast<XMultiServiceFactory *>(pServiceManager), + implname3, + test4_createInstance, + Sequence<OUString>( &serviceName3, 1), + &globalModuleCount.modCnt + )); + + if (xFactory.is()) + { + xFactory->acquire(); + pRet = xFactory.get(); + } + } + return pRet; + } + + sal_Bool component_canUnload( TimeValue* libUnused) + { + return globalModuleCount.canUnload( &globalModuleCount, libUnused); + } +} |