diff options
author | Jens-Heiner Rechtien <hr@openoffice.org> | 2000-09-18 14:29:57 +0000 |
---|---|---|
committer | Jens-Heiner Rechtien <hr@openoffice.org> | 2000-09-18 14:29:57 +0000 |
commit | b525a3115f54576017a576ff842dede5e2e3545d (patch) | |
tree | c534b95a9e572b63896467624293a5ca1887d3a3 /cppu/test | |
parent | 9399c662f36c385b0c705eb34e636a9aec450282 (diff) |
initial import
Diffstat (limited to 'cppu/test')
-rw-r--r-- | cppu/test/cpputest.idl | 129 | ||||
-rw-r--r-- | cppu/test/language_binding.idl | 212 | ||||
-rw-r--r-- | cppu/test/makefile.mk | 153 | ||||
-rw-r--r-- | cppu/test/surrogate.hxx | 189 | ||||
-rw-r--r-- | cppu/test/test_di.cxx | 608 | ||||
-rw-r--r-- | cppu/test/testcppu.cxx | 886 | ||||
-rw-r--r-- | cppu/test/testthreadpool.cxx | 223 |
7 files changed, 2400 insertions, 0 deletions
diff --git a/cppu/test/cpputest.idl b/cppu/test/cpputest.idl new file mode 100644 index 000000000000..fab2b36ae7a8 --- /dev/null +++ b/cppu/test/cpputest.idl @@ -0,0 +1,129 @@ +/************************************************************************* + * + * $RCSfile: cpputest.idl,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 15:25:53 $ + * + * 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): _______________________________________ + * + * + ************************************************************************/ +#ifndef _TEST_CPPUTEST_IDL_ +#define _TEST_CPPUTEST_IDL_ + +#include <com/sun/star/uno/XInterface.idl> +#include <com/sun/star/uno/TypeClass.idl> + +module test +{ + +struct Test1 +{ + short nInt16; + double dDouble; + boolean bBool; +}; + +struct Test2 +{ + short nInt16; + Test1 aTest1; +}; + +typedef Test1 TdTest1; + +struct Test3 +{ + byte nInt8; + float nFloat; + double nDouble; + short nInt16; + string aString; + unsigned short nuInt16; + hyper nInt64; + long nInt32; + unsigned hyper nuInt64; + unsigned long nuInt32; + com::sun::star::uno::TypeClass eType; + char wChar; + TdTest1 td; + boolean bBool; + any aAny; +}; + + +struct Base +{ + long n; + short o; +}; + +struct Base1 : Base +{ + short p; +}; + +struct Base2 : Base1 +{ + double p2; +}; + +[ uik(46121273-3462-11d3-87A400A0-24494732), ident("SimpleInterface", 1.0) ] +interface XSimpleInterface : com::sun::star::uno::XInterface +{ + void method(); +}; + +}; //module test + +#endif diff --git a/cppu/test/language_binding.idl b/cppu/test/language_binding.idl new file mode 100644 index 000000000000..ad23f590bf12 --- /dev/null +++ b/cppu/test/language_binding.idl @@ -0,0 +1,212 @@ +/************************************************************************* + * + * $RCSfile: language_binding.idl,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 15:25:54 $ + * + * 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): _______________________________________ + * + * + ************************************************************************/ +#ifndef _TEST_LANGUAGE_BINDING_IDL_ +#define _TEST_LANGUAGE_BINDING_IDL_ + +#include <com/sun/star/uno/XInterface.idl> +#include <com/sun/star/lang/IllegalArgumentException.idl> + +module test +{ + +enum TestEnum +{ + TEST, + ONE, + TWO, + CHECK, + LOLA, + PALOO, + ZA +}; + +/** + * simple c++ types + */ +struct TestSimple +{ + boolean Bool; + char Char; + byte Byte; + short Short; + unsigned short UShort; + long Long; + unsigned long ULong; + hyper Hyper; + unsigned hyper UHyper; + float Float; + double Double; + test::TestEnum Enum; +}; +/** + * complex c++ types + */ +struct TestElement : test::TestSimple +{ + string String; + com::sun::star::uno::XInterface Interface; + any Any; +}; +struct TestDataElements : test::TestElement +{ + sequence<test::TestElement > Sequence; +}; + +typedef TestDataElements TestData; + +/** + * Monster test interface to test language binding calls. + * + * @author Daniel Boelzle + */ +[ uik(46833373-3462-11d3-87A400A0-24494732), ident("XLBTest", 1.0) ] +interface XLBTestBase : com::sun::star::uno::XInterface +{ + /** + * in parameter test, tests by calls reference also (complex types) + */ + [oneway] void setValues( [in] boolean bBool, [in] char cChar, [in] byte nByte, + [in] short nShort, [in] unsigned short nUShort, + [in] long nLong, [in] unsigned long nULong, + [in] hyper nHyper, [in] unsigned hyper nUHyper, + [in] float fFloat, [in] double fDouble, + [in] test::TestEnum eEnum, [in] string aString, + [in] com::sun::star::uno::XInterface xInterface, [in] any aAny, + [in] sequence<test::TestElement > aSequence, + [in] test::TestData aStruct ); + /** + * inout parameter test + */ + test::TestData setValues2( [inout] boolean bBool, [inout] char cChar, [inout] byte nByte, + [inout] short nShort, [inout] unsigned short nUShort, + [inout] long nLong, [inout] unsigned long nULong, + [inout] hyper nHyper, [inout] unsigned hyper nUHyper, + [inout] float fFloat, [inout] double fDouble, + [inout] test::TestEnum eEnum, [inout] string aString, + [inout] com::sun::star::uno::XInterface xInterface, [inout] any aAny, + [inout] sequence<test::TestElement > aSequence, + [inout] test::TestData aStruct ); + + /** + * out parameter test + */ + test::TestData getValues( [out] boolean bBool, [out] char cChar, [out] byte nByte, + [out] short nShort, [out] unsigned short nUShort, + [out] long nLong, [out] unsigned long nULong, + [out] hyper nHyper, [out] unsigned hyper nUHyper, + [out] float fFloat, [out] double fDouble, + [out] test::TestEnum eEnum, [out] string aString, + [out] com::sun::star::uno::XInterface xInterface, [out] any aAny, + [out] sequence<test::TestElement > aSequence, + [out] test::TestData aStruct ); + + [attribute] boolean Bool; + [attribute] byte Byte; + [attribute] char Char; + [attribute] short Short; + [attribute] unsigned short UShort; + [attribute] long Long; + [attribute] unsigned long ULong; + [attribute] hyper Hyper; + [attribute] unsigned hyper UHyper; + [attribute] float Float; + [attribute] double Double; + [attribute] test::TestEnum Enum; + [attribute] string String; + [attribute] com::sun::star::uno::XInterface Interface; + [attribute] any Any; + [attribute] sequence<test::TestElement > Sequence; + [attribute] test::TestData Struct; +}; + + +/** + * Inherting from monster; adds raiseException(). + * + * @author Daniel Boelzle + */ +[ uik(44C34C20-3478-11d3-87A400A0-24494732), ident("XLanguageBindingTest", 1.0) ] +interface XLanguageBindingTest : test::XLBTestBase +{ + /** + * params are there only for dummy, to test if all temp out params will be released. + */ + test::TestData raiseException( [out] boolean bBool, [out] char cChar, [out] byte nByte, + [out] short nShort, [out] unsigned short nUShort, + [out] long nLong, [out] unsigned long nULong, + [out] hyper nHyper, [out] unsigned hyper nUHyper, + [out] float fFloat, [out] double fDouble, + [out] test::TestEnum eEnum, [out] string aString, + [out] com::sun::star::uno::XInterface xInterface, [out] any aAny, + [out] sequence<test::TestElement > aSequence, + [out] test::TestData aStruct ) + raises( com::sun::star::lang::IllegalArgumentException ); + + /** + * raises runtime exception + */ + [attribute] long RuntimeException; +}; + +}; // test + + +#endif diff --git a/cppu/test/makefile.mk b/cppu/test/makefile.mk new file mode 100644 index 000000000000..ee745c922cba --- /dev/null +++ b/cppu/test/makefile.mk @@ -0,0 +1,153 @@ +#************************************************************************* +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.1.1.1 $ +# +# last change: $Author: hr $ $Date: 2000-09-18 15:25:53 $ +# +# 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= testcppu +TARGET= testcppu +LIBTARGET= NO +TARGETTYPE= CUI +ENABLE_EXCEPTIONS=TRUE +NO_BSYMBOLIC= TRUE + +# --- Settings ----------------------------------------------------- + +.INCLUDE : svpre.mk +.INCLUDE : settings.mk +.INCLUDE : sv.mk + +# --- Files -------------------------------------------------------- + +UNOUCRDEP= $(SOLARBINDIR)$/applicat.rdb +UNOUCRRDB= $(SOLARBINDIR)$/applicat.rdb +UNOUCROUT= $(OUT)$/inc$/test +INCPRE+= $(OUT)$/inc$/test + +OBJFILES= \ + $(OBJ)$/testcppu.obj \ + $(OBJ)$/test_di.obj + + +APP1TARGET= testcppu +APP1OBJS= $(OBJ)$/test_di.obj \ + $(OBJ)$/testcppu.obj + +APP1STDLIBS+= \ + $(CPPULIB) \ + $(CPPUHELPERLIB) \ + $(SALLIB) + +APP1DEF= $(MISC)$/$(APP1TARGET).def + +ALLIDLFILES:= cpputest.idl \ + language_binding.idl + +# --- Targets ------------------------------------------------------ + +.IF "$(depend)" == "" +ALL : $(BIN)$/testcppu.rdb unoheader ALLTAR +.ELSE +ALL: ALLDEP +.ENDIF + +.INCLUDE : target.mk + +CPPUMAKERFLAGS = -C +.IF "$(COM)" == "MSC" +CPPUMAKERFLAGS = -L +.ENDIF + +TYPES:= -Ttest.XLanguageBindingTest \ + -Ttest.XSimpleInterface \ + -Ttest.Test1 \ + -Ttest.Test2 \ + -Ttest.TdTest1 \ + -Ttest.Test3 \ + -Ttest.Base \ + -Ttest.Base1 \ + -Ttest.Base2 \ + -Tcom.sun.star.lang.XMultiServiceFactory \ + -Tcom.sun.star.lang.XSingleServiceFactory \ + -Tcom.sun.star.lang.XInitialization \ + -Tcom.sun.star.lang.XServiceInfo \ + -Tcom.sun.star.lang.XEventListener \ + -Tcom.sun.star.lang.XTypeProvider \ + -Tcom.sun.star.registry.XSimpleRegistry \ + -Tcom.sun.star.registry.XRegistryKey \ + -Tcom.sun.star.loader.XImplementationLoader \ + -Tcom.sun.star.registry.XImplementationRegistration \ + -Tcom.sun.star.lang.XComponent \ + -Tcom.sun.star.container.XSet \ + -Tcom.sun.star.uno.XReference \ + -Tcom.sun.star.uno.XAdapter \ + -Tcom.sun.star.uno.XAggregation \ + -Tcom.sun.star.uno.XWeak \ + -Tcom.sun.star.reflection.XIdlClassProvider + +$(BIN)$/testcppu.rdb: $(ALLIDLFILES) + +unoidl -I$(PRJ) -I$(SOLARIDLDIR) -Burd -OH$(BIN) $? + +regmerge $@ /UCR $(BIN)$/{$(?:f:s/.idl/.urd/)} + +regmerge $@ / $(UNOUCRRDB) + touch $@ + +unoheader: $(BIN)$/testcppu.rdb + +cppumaker $(CPPUMAKERFLAGS) -BUCR -O$(UNOUCROUT) $(TYPES) $(BIN)$/testcppu.rdb + diff --git a/cppu/test/surrogate.hxx b/cppu/test/surrogate.hxx new file mode 100644 index 000000000000..bb60f491055e --- /dev/null +++ b/cppu/test/surrogate.hxx @@ -0,0 +1,189 @@ +/************************************************************************* + * + * $RCSfile: surrogate.hxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 15:25:54 $ + * + * 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): _______________________________________ + * + * + ************************************************************************/ + +#include <uno/dispatcher.h> +#include <uno/mapping.hxx> +#include <uno/environment.h> +#include <uno/data.h> +#include <osl/diagnose.h> +#include <osl/interlck.h> + +#include <com/sun/star/uno/Reference.hxx> + +/* +//================================================================================================== +struct UnoMediator : public uno_Interface +{ + oslInterlockedCount nRef; + uno_Interface * pDest; + + UnoMediator( uno_Interface * pDest ); + ~UnoMediator(); +}; + +//-------------------------------------------------------------------------------------------------- +inline static void SAL_CALL UnoMediator_acquire( uno_Interface * pUnoI ) +{ + osl_incrementInterlockedCount( &((UnoMediator *)pUnoI)->nRef ); +} +//-------------------------------------------------------------------------------------------------- +inline static void SAL_CALL UnoMediator_release( uno_Interface * pUnoI ) +{ + if (! osl_decrementInterlockedCount( &((UnoMediator *)pUnoI)->nRef )) + delete (UnoMediator *)pUnoI; +} +//-------------------------------------------------------------------------------------------------- +inline static void SAL_CALL UnoMediator_dispatch( + uno_Interface * pUnoI, const typelib_TypeDescription * pMemberType, + void * pReturn, void * pArgs[], uno_Any ** ppException ) +{ + (*((UnoMediator *)pUnoI)->pDest->pDispatcher)( + ((UnoMediator *)pUnoI)->pDest, pMemberType, pReturn, pArgs, ppException ); +} + +//__________________________________________________________________________________________________ +UnoMediator::UnoMediator( uno_Interface * pDest_ ) + : nRef( 0 ) + , pDest( pDest_ ) +{ + (*pDest->acquire)( pDest ); + uno_Interface::acquire = UnoMediator_acquire; + uno_Interface::release = UnoMediator_release; + uno_Interface::pDispatcher = UnoMediator_dispatch; +} +//__________________________________________________________________________________________________ +UnoMediator::~UnoMediator() +{ + (*pDest->release)( pDest ); +} +*/ + +//################################################################################################## + +template< class T > +inline sal_Bool makeSurrogate( com::sun::star::uno::Reference< T > & rOut, + const com::sun::star::uno::Reference< T > & rOriginal ) +{ + rOut.clear(); + + typelib_TypeDescription * pTD = 0; + const com::sun::star::uno::Type & rType = ::getCppuType( &rOriginal ); + TYPELIB_DANGER_GET( &pTD, rType.getTypeLibType() ); + OSL_ENSHURE( pTD, "### cannot get typedescription!" ); + if (pTD) + { + uno_Environment * pCppEnv1 = 0; + uno_Environment * pCppEnv2 = 0; + + ::rtl::OUString aCppEnvTypeName( RTL_CONSTASCII_USTRINGPARAM(CPPU_CURRENT_LANGUAGE_BINDING_NAME) ); + uno_getEnvironment( &pCppEnv1, aCppEnvTypeName.pData, 0 ); + uno_createEnvironment( &pCppEnv2, aCppEnvTypeName.pData, 0 ); // anonymous + + ::com::sun::star::uno::Mapping aMapping( pCppEnv1, pCppEnv2, ::rtl::OUString::createFromAscii("prot") ); + T * p = (T *)aMapping.mapInterface( rOriginal.get(), (typelib_InterfaceTypeDescription *)pTD ); + if (p) + { + rOut = p; + p->release(); + } + + (*pCppEnv2->release)( pCppEnv2 ); + (*pCppEnv1->release)( pCppEnv1 ); + + TYPELIB_DANGER_RELEASE( pTD ); + } +/* + ::com::sun::star::uno::Mapping aCpp2Uno( CPPU_CURRENT_LANGUAGE_BINDING_NAME, UNO_LB_UNO ); + ::com::sun::star::uno::Mapping aUno2Cpp( UNO_LB_UNO, CPPU_CURRENT_LANGUAGE_BINDING_NAME ); + OSL_ENSHURE( aCpp2Uno.is() && aUno2Cpp.is(), "### cannot get mappings!" ); + if (aCpp2Uno.is() && aUno2Cpp.is()) + { + typelib_TypeDescription * pTD = 0; + const com::sun::star::uno::Type & rType = ::getCppuType( &rOriginal ); + TYPELIB_DANGER_GET( &pTD, rType.getTypeLibType() ); + OSL_ENSHURE( pTD, "### cannot get typedescription!" ); + if (pTD) + { + uno_Interface * pUno = (uno_Interface *)aCpp2Uno.mapInterface( + rOriginal.get(), (typelib_InterfaceTypeDescription *)pTD ); + if (pUno) + { + UnoMediator * pPseudo = new UnoMediator( pUno ); + (*pPseudo->acquire)( pPseudo ); + OSL_ENSHURE( uno_equals( &pUno, &pPseudo, pTD, 0 ), "### interfaces don't belong to same object, but they do!?" ); + (*pUno->release)( pUno ); + + T * pCpp = (T *)aUno2Cpp.mapInterface( + pPseudo, (typelib_InterfaceTypeDescription *)pTD ); + (*pPseudo->release)( pPseudo ); + + if (pCpp) + { + rOut = pCpp; + pCpp->release(); + } + } + TYPELIB_DANGER_RELEASE( pTD ); + } + } +*/ + return rOut.is(); +} diff --git a/cppu/test/test_di.cxx b/cppu/test/test_di.cxx new file mode 100644 index 000000000000..5f8e750fb179 --- /dev/null +++ b/cppu/test/test_di.cxx @@ -0,0 +1,608 @@ +/************************************************************************* + * + * $RCSfile: test_di.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 15:25:54 $ + * + * 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): _______________________________________ + * + * + ************************************************************************/ + +#include <stdio.h> +#include <rtl/ustring.hxx> +#include <osl/diagnose.h> +#include <osl/time.h> +// +#include <uno/dispatcher.h> +#include <uno/environment.h> +#include <uno/mapping.hxx> +#include <uno/data.h> + +#include <cppuhelper/weak.hxx> +#include <cppuhelper/queryinterface.hxx> +#include <cppu/macros.hxx> +#include <test/XLanguageBindingTest.hpp> + +#include <cppuhelper/implbase1.hxx> + + +using namespace test; +using namespace cppu; +using namespace com::sun::star::uno; +using namespace com::sun::star::lang; +using namespace osl; +using namespace rtl; + + +//================================================================================================== +sal_Bool equals( const test::TestElement & rData1, const test::TestElement & rData2 ) +{ + OSL_ENSHURE( rData1.Bool == rData2.Bool, "### bool does not match!" ); + OSL_ENSHURE( rData1.Char == rData2.Char, "### char does not match!" ); + OSL_ENSHURE( rData1.Byte == rData2.Byte, "### byte does not match!" ); + OSL_ENSHURE( rData1.Short == rData2.Short, "### short does not match!" ); + OSL_ENSHURE( rData1.UShort == rData2.UShort, "### unsigned short does not match!" ); + OSL_ENSHURE( rData1.Long == rData2.Long, "### long does not match!" ); + OSL_ENSHURE( rData1.ULong == rData2.ULong, "### unsigned long does not match!" ); + OSL_ENSHURE( rData1.Hyper == rData2.Hyper, "### hyper does not match!" ); + OSL_ENSHURE( rData1.UHyper == rData2.UHyper, "### unsigned hyper does not match!" ); + OSL_ENSHURE( rData1.Float == rData2.Float, "### float does not match!" ); + OSL_ENSHURE( rData1.Double == rData2.Double, "### double does not match!" ); + OSL_ENSHURE( rData1.Enum == rData2.Enum, "### enum does not match!" ); + OSL_ENSHURE( rData1.String == rData2.String, "### string does not match!" ); + OSL_ENSHURE( rData1.Interface == rData2.Interface, "### interface does not match!" ); + OSL_ENSHURE( rData1.Any == rData2.Any, "### any does not match!" ); + + return (rData1.Bool == rData2.Bool && + rData1.Char == rData2.Char && + rData1.Byte == rData2.Byte && + rData1.Short == rData2.Short && + rData1.UShort == rData2.UShort && + rData1.Long == rData2.Long && + rData1.ULong == rData2.ULong && + rData1.Hyper == rData2.Hyper && + rData1.UHyper == rData2.UHyper && + rData1.Float == rData2.Float && + rData1.Double == rData2.Double && + rData1.Enum == rData2.Enum && + rData1.String == rData2.String && + rData1.Interface == rData2.Interface && + rData1.Any == rData2.Any); +} +//================================================================================================== +sal_Bool equals( const test::TestData & rData1, const test::TestData & rData2 ) +{ + sal_Int32 nLen; + + if ((rData1.Sequence == rData2.Sequence) && + equals( (const test::TestElement &)rData1, (const test::TestElement &)rData2 ) && + (nLen = rData1.Sequence.getLength()) == rData2.Sequence.getLength()) + { + // once again by hand sequence == + const test::TestElement * pElements1 = rData1.Sequence.getConstArray(); + const test::TestElement * pElements2 = rData2.Sequence.getConstArray(); + for ( ; nLen--; ) + { + if (! equals( pElements1[nLen], pElements2[nLen] )) + { + OSL_ENSHURE( sal_False, "### sequence element did not match!" ); + return sal_False; + } + } + return sal_True; + } + return sal_False; +} +//================================================================================================== +void assign( test::TestElement & rData, + sal_Bool bBool, sal_Unicode cChar, sal_Int8 nByte, + sal_Int16 nShort, sal_uInt16 nUShort, + sal_Int32 nLong, sal_uInt32 nULong, + sal_Int64 nHyper, sal_uInt64 nUHyper, + float fFloat, double fDouble, + test::TestEnum eEnum, const ::rtl::OUString& rStr, + const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& xTest, + const ::com::sun::star::uno::Any& rAny ) +{ + rData.Bool = bBool; + rData.Char = cChar; + rData.Byte = nByte; + rData.Short = nShort; + rData.UShort = nUShort; + rData.Long = nLong; + rData.ULong = nULong; + rData.Hyper = nHyper; + rData.UHyper = nUHyper; + rData.Float = fFloat; + rData.Double = fDouble; + rData.Enum = eEnum; + rData.String = rStr; + rData.Interface = xTest; + rData.Any = rAny; +} +//================================================================================================== +void assign( test::TestData & rData, + sal_Bool bBool, sal_Unicode cChar, sal_Int8 nByte, + sal_Int16 nShort, sal_uInt16 nUShort, + sal_Int32 nLong, sal_uInt32 nULong, + sal_Int64 nHyper, sal_uInt64 nUHyper, + float fFloat, double fDouble, + test::TestEnum eEnum, const ::rtl::OUString& rStr, + const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& xTest, + const ::com::sun::star::uno::Any& rAny, + const com::sun::star::uno::Sequence< test::TestElement >& rSequence ) +{ + assign( (test::TestElement &)rData, + bBool, cChar, nByte, nShort, nUShort, nLong, nULong, nHyper, nUHyper, fFloat, fDouble, + eEnum, rStr, xTest, rAny ); + rData.Sequence = rSequence; +} + +//================================================================================================== +class Test_Impl : public cppu::WeakImplHelper1< XLanguageBindingTest > +{ + test::TestData _aData, _aStructData; + +public: + virtual ~Test_Impl() + { OSL_TRACE( "> scalar Test_Impl dtor <\n" ); } + + // XLBTestBase + virtual void SAL_CALL setValues( sal_Bool bBool, sal_Unicode cChar, sal_Int8 nByte, + sal_Int16 nShort, sal_uInt16 nUShort, + sal_Int32 nLong, sal_uInt32 nULong, + sal_Int64 nHyper, sal_uInt64 nUHyper, + float fFloat, double fDouble, + test::TestEnum eEnum, const ::rtl::OUString& rStr, + const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& xTest, + const ::com::sun::star::uno::Any& rAny, + const ::com::sun::star::uno::Sequence<test::TestElement >& rSequence, + const test::TestData& rStruct ) + throw(com::sun::star::uno::RuntimeException); + + virtual test::TestData SAL_CALL setValues2( sal_Bool& bBool, sal_Unicode& cChar, sal_Int8& nByte, + sal_Int16& nShort, sal_uInt16& nUShort, + sal_Int32& nLong, sal_uInt32& nULong, + sal_Int64& nHyper, sal_uInt64& nUHyper, + float& fFloat, double& fDouble, + test::TestEnum& eEnum, rtl::OUString& rStr, + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& xTest, + ::com::sun::star::uno::Any& rAny, + ::com::sun::star::uno::Sequence<test::TestElement >& rSequence, + test::TestData& rStruct ) + throw(com::sun::star::uno::RuntimeException); + + virtual test::TestData SAL_CALL getValues( sal_Bool& bBool, sal_Unicode& cChar, sal_Int8& nByte, + sal_Int16& nShort, sal_uInt16& nUShort, + sal_Int32& nLong, sal_uInt32& nULong, + sal_Int64& nHyper, sal_uInt64& nUHyper, + float& fFloat, double& fDouble, + test::TestEnum& eEnum, rtl::OUString& rStr, + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& xTest, + ::com::sun::star::uno::Any& rAny, + ::com::sun::star::uno::Sequence< test::TestElement >& rSequence, + test::TestData& rStruct ) + throw(com::sun::star::uno::RuntimeException); + + virtual sal_Bool SAL_CALL getBool() throw(com::sun::star::uno::RuntimeException) + { return _aData.Bool; } + virtual sal_Int8 SAL_CALL getByte() throw(com::sun::star::uno::RuntimeException) + { return _aData.Byte; } + virtual sal_Unicode SAL_CALL getChar() throw(com::sun::star::uno::RuntimeException) + { return _aData.Char; } + virtual sal_Int16 SAL_CALL getShort() throw(com::sun::star::uno::RuntimeException) + { return _aData.Short; } + virtual sal_uInt16 SAL_CALL getUShort() throw(com::sun::star::uno::RuntimeException) + { return _aData.UShort; } + virtual sal_Int32 SAL_CALL getLong() throw(com::sun::star::uno::RuntimeException) + { return _aData.Long; } + virtual sal_uInt32 SAL_CALL getULong() throw(com::sun::star::uno::RuntimeException) + { return _aData.ULong; } + virtual sal_Int64 SAL_CALL getHyper() throw(com::sun::star::uno::RuntimeException) + { return _aData.Hyper; } + virtual sal_uInt64 SAL_CALL getUHyper() throw(com::sun::star::uno::RuntimeException) + { return _aData.UHyper; } + virtual float SAL_CALL getFloat() throw(com::sun::star::uno::RuntimeException) + { return _aData.Float; } + virtual double SAL_CALL getDouble() throw(com::sun::star::uno::RuntimeException) + { return _aData.Double; } + virtual test::TestEnum SAL_CALL getEnum() throw(com::sun::star::uno::RuntimeException) + { return _aData.Enum; } + virtual rtl::OUString SAL_CALL getString() throw(com::sun::star::uno::RuntimeException) + { return _aData.String; } + virtual com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL getInterface( ) throw(com::sun::star::uno::RuntimeException) + { return _aData.Interface; } + virtual com::sun::star::uno::Any SAL_CALL getAny() throw(com::sun::star::uno::RuntimeException) + { return _aData.Any; } + virtual com::sun::star::uno::Sequence< test::TestElement > SAL_CALL getSequence() throw(com::sun::star::uno::RuntimeException) + { return _aData.Sequence; } + virtual test::TestData SAL_CALL getStruct() throw(com::sun::star::uno::RuntimeException) + { return _aStructData; } + + virtual void SAL_CALL setBool( sal_Bool _bool ) throw(::com::sun::star::uno::RuntimeException) + { _aData.Bool = _bool; } + virtual void SAL_CALL setByte( sal_Int8 _byte ) throw(::com::sun::star::uno::RuntimeException) + { _aData.Byte = _byte; } + virtual void SAL_CALL setChar( sal_Unicode _char ) throw(::com::sun::star::uno::RuntimeException) + { _aData.Char = _char; } + virtual void SAL_CALL setShort( sal_Int16 _short ) throw(::com::sun::star::uno::RuntimeException) + { _aData.Short = _short; } + virtual void SAL_CALL setUShort( sal_uInt16 _ushort ) throw(::com::sun::star::uno::RuntimeException) + { _aData.UShort = _ushort; } + virtual void SAL_CALL setLong( sal_Int32 _long ) throw(::com::sun::star::uno::RuntimeException) + { _aData.Long = _long; } + virtual void SAL_CALL setULong( sal_uInt32 _ulong ) throw(::com::sun::star::uno::RuntimeException) + { _aData.ULong = _ulong; } + virtual void SAL_CALL setHyper( sal_Int64 _hyper ) throw(::com::sun::star::uno::RuntimeException) + { _aData.Hyper = _hyper; } + virtual void SAL_CALL setUHyper( sal_uInt64 _uhyper ) throw(::com::sun::star::uno::RuntimeException) + { _aData.UHyper = _uhyper; } + virtual void SAL_CALL setFloat( float _float ) throw(::com::sun::star::uno::RuntimeException) + { _aData.Float = _float; } + virtual void SAL_CALL setDouble( double _double ) throw(::com::sun::star::uno::RuntimeException) + { _aData.Double = _double; } + virtual void SAL_CALL setEnum( test::TestEnum _enum ) throw(::com::sun::star::uno::RuntimeException) + { _aData.Enum = _enum; } + virtual void SAL_CALL setString( const ::rtl::OUString& _string ) throw(::com::sun::star::uno::RuntimeException) + { _aData.String = _string; } + virtual void SAL_CALL setInterface( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _interface ) throw(::com::sun::star::uno::RuntimeException) + { _aData.Interface = _interface; } + virtual void SAL_CALL setAny( const ::com::sun::star::uno::Any& _any ) throw(::com::sun::star::uno::RuntimeException) + { _aData.Any = _any; } + virtual void SAL_CALL setSequence( const ::com::sun::star::uno::Sequence<test::TestElement >& _sequence ) throw(::com::sun::star::uno::RuntimeException) + { _aData.Sequence = _sequence; } + virtual void SAL_CALL setStruct( const test::TestData& _struct ) throw(::com::sun::star::uno::RuntimeException) + { _aStructData = _struct; } + + // XLanguageBindingTest + virtual test::TestData SAL_CALL raiseException( sal_Bool& bBool, sal_Unicode& cChar, sal_Int8& nByte, sal_Int16& nShort, sal_uInt16& nUShort, sal_Int32& nLong, sal_uInt32& nULong, sal_Int64& nHyper, sal_uInt64& nUHyper, float& fFloat, double& fDouble, test::TestEnum& eEnum, ::rtl::OUString& aString, ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& xInterface, ::com::sun::star::uno::Any& aAny, ::com::sun::star::uno::Sequence<test::TestElement >& aSequence,test::TestData& aStruct ) + throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + + virtual sal_Int32 SAL_CALL getRuntimeException() throw(::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setRuntimeException( sal_Int32 _runtimeexception ) throw(::com::sun::star::uno::RuntimeException); +}; +//__________________________________________________________________________________________________ +void Test_Impl::setValues( sal_Bool bBool, sal_Unicode cChar, sal_Int8 nByte, + sal_Int16 nShort, sal_uInt16 nUShort, + sal_Int32 nLong, sal_uInt32 nULong, + sal_Int64 nHyper, sal_uInt64 nUHyper, + float fFloat, double fDouble, + test::TestEnum eEnum, const ::rtl::OUString& rStr, + const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& xTest, + const ::com::sun::star::uno::Any& rAny, + const ::com::sun::star::uno::Sequence<test::TestElement >& rSequence, + const test::TestData& rStruct ) + throw(com::sun::star::uno::RuntimeException) +{ + assign( _aData, + bBool, cChar, nByte, nShort, nUShort, nLong, nULong, nHyper, nUHyper, fFloat, fDouble, + eEnum, rStr, xTest, rAny, rSequence ); + _aStructData = rStruct; +} +//__________________________________________________________________________________________________ +test::TestData Test_Impl::setValues2( sal_Bool& bBool, sal_Unicode& cChar, sal_Int8& nByte, + sal_Int16& nShort, sal_uInt16& nUShort, + sal_Int32& nLong, sal_uInt32& nULong, + sal_Int64& nHyper, sal_uInt64& nUHyper, + float& fFloat, double& fDouble, + test::TestEnum& eEnum, rtl::OUString& rStr, + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& xTest, + ::com::sun::star::uno::Any& rAny, + ::com::sun::star::uno::Sequence<test::TestElement >& rSequence, + test::TestData& rStruct ) + throw(com::sun::star::uno::RuntimeException) +{ + assign( _aData, + bBool, cChar, nByte, nShort, nUShort, nLong, nULong, nHyper, nUHyper, fFloat, fDouble, + eEnum, rStr, xTest, rAny, rSequence ); + _aStructData = rStruct; + return _aStructData; +} +//__________________________________________________________________________________________________ +test::TestData Test_Impl::getValues( sal_Bool& bBool, sal_Unicode& cChar, sal_Int8& nByte, + sal_Int16& nShort, sal_uInt16& nUShort, + sal_Int32& nLong, sal_uInt32& nULong, + sal_Int64& nHyper, sal_uInt64& nUHyper, + float& fFloat, double& fDouble, + test::TestEnum& eEnum, rtl::OUString& rStr, + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& xTest, + ::com::sun::star::uno::Any& rAny, + ::com::sun::star::uno::Sequence<test::TestElement >& rSequence, + test::TestData& rStruct ) + throw(com::sun::star::uno::RuntimeException) +{ + bBool = _aData.Bool; + cChar = _aData.Char; + nByte = _aData.Byte; + nShort = _aData.Short; + nUShort = _aData.UShort; + nLong = _aData.Long; + nULong = _aData.ULong; + nHyper = _aData.Hyper; + nUHyper = _aData.UHyper; + fFloat = _aData.Float; + fDouble = _aData.Double; + eEnum = _aData.Enum; + rStr = _aData.String; + xTest = _aData.Interface; + rAny = _aData.Any; + rSequence = _aData.Sequence; + rStruct = _aStructData; + return _aStructData; +} + +//================================================================================================== +sal_Bool performTest( const Reference<XLanguageBindingTest > & xLBT ) +{ + OSL_ENSHURE( xLBT.is(), "### no test interface!" ); + if (xLBT.is()) + { + // this data is never ever granted access to by calls other than equals(), assign()! + test::TestData aData; // test against this data + + Reference<XInterface > xI( *new OWeakObject() ); + + assign( (test::TestElement &)aData, + sal_True, '@', 17, 0x1234, 0xfedc, 0x12345678, 0xfedcba98, + 0x123456789abcdef0, 0xfedcba9876543210, + (float)17.0815, 3.1415926359, TestEnum_LOLA, + OUString::createFromAscii("dumdidum"), xI, + Any( &xI, ::getCppuType( (const Reference<XInterface > *)0 ) ) ); + + OSL_ENSHURE( aData.Any == xI, "### unexpected any!" ); + OSL_ENSHURE( !(aData.Any != xI), "### unexpected any!" ); + + aData.Sequence = Sequence<test::TestElement >( (const test::TestElement *)&aData, 1 ); + // aData complete + //================================================================================ + + // this is a manually copy of aData for first setting... + test::TestData aSetData; + + assign( (test::TestElement &)aSetData, + aData.Bool, aData.Char, aData.Byte, aData.Short, aData.UShort, + aData.Long, aData.ULong, aData.Hyper, aData.UHyper, aData.Float, aData.Double, + aData.Enum, aData.String, xI, + Any( &xI, ::getCppuType( (const Reference<XInterface > *)0 ) ) ); + + aSetData.Sequence = Sequence<test::TestElement >( (const test::TestElement *)&aSetData, 1 ); + + xLBT->setValues( + aSetData.Bool, aSetData.Char, aSetData.Byte, aSetData.Short, aSetData.UShort, + aSetData.Long, aSetData.ULong, aSetData.Hyper, aSetData.UHyper, aSetData.Float, aSetData.Double, + aSetData.Enum, aSetData.String, aSetData.Interface, aSetData.Any, aSetData.Sequence, aSetData ); + + { + test::TestData aRet, aRet2; + xLBT->getValues( + aRet.Bool, aRet.Char, aRet.Byte, aRet.Short, aRet.UShort, + aRet.Long, aRet.ULong, aRet.Hyper, aRet.UHyper, aRet.Float, aRet.Double, + aRet.Enum, aRet.String, aRet.Interface, aRet.Any, aRet.Sequence, aRet2 ); + + OSL_ASSERT( equals( aData, aRet ) && equals( aData, aRet2 ) ); + + // set last retrieved values + test::TestData aSV2ret = xLBT->setValues2( + aRet.Bool, aRet.Char, aRet.Byte, aRet.Short, aRet.UShort, + aRet.Long, aRet.ULong, aRet.Hyper, aRet.UHyper, aRet.Float, aRet.Double, + aRet.Enum, aRet.String, aRet.Interface, aRet.Any, aRet.Sequence, aRet2 ); + + OSL_ASSERT( equals( aData, aSV2ret ) && equals( aData, aRet2 ) ); + } + { + test::TestData aRet, aRet2; + test::TestData aGVret = xLBT->getValues( + aRet.Bool, aRet.Char, aRet.Byte, aRet.Short, aRet.UShort, + aRet.Long, aRet.ULong, aRet.Hyper, aRet.UHyper, aRet.Float, aRet.Double, + aRet.Enum, aRet.String, aRet.Interface, aRet.Any, aRet.Sequence, aRet2 ); + + OSL_ASSERT( equals( aData, aRet ) && equals( aData, aRet2 ) && equals( aData, aGVret ) ); + + // set last retrieved values + xLBT->setBool( aRet.Bool ); + xLBT->setChar( aRet.Char ); + xLBT->setByte( aRet.Byte ); + xLBT->setShort( aRet.Short ); + xLBT->setUShort( aRet.UShort ); + xLBT->setLong( aRet.Long ); + xLBT->setULong( aRet.ULong ); + xLBT->setHyper( aRet.Hyper ); + xLBT->setUHyper( aRet.UHyper ); + xLBT->setFloat( aRet.Float ); + xLBT->setDouble( aRet.Double ); + xLBT->setEnum( aRet.Enum ); + xLBT->setString( aRet.String ); + xLBT->setInterface( aRet.Interface ); + xLBT->setAny( aRet.Any ); + xLBT->setSequence( aRet.Sequence ); + xLBT->setStruct( aRet2 ); + } + { + test::TestData aRet, aRet2; + aRet.Hyper = xLBT->getHyper(); + aRet.UHyper = xLBT->getUHyper(); + aRet.Float = xLBT->getFloat(); + aRet.Double = xLBT->getDouble(); + aRet.Byte = xLBT->getByte(); + aRet.Char = xLBT->getChar(); + aRet.Bool = xLBT->getBool(); + aRet.Short = xLBT->getShort(); + aRet.UShort = xLBT->getUShort(); + aRet.Long = xLBT->getLong(); + aRet.ULong = xLBT->getULong(); + aRet.Enum = xLBT->getEnum(); + aRet.String = xLBT->getString(); + aRet.Interface = xLBT->getInterface(); + aRet.Any = xLBT->getAny(); + aRet.Sequence = xLBT->getSequence(); + aRet2 = xLBT->getStruct(); + + return (equals( aData, aRet ) && equals( aData, aRet2 )); + } + } + return sal_False; +} + +//__________________________________________________________________________________________________ +test::TestData Test_Impl::raiseException( sal_Bool& bBool, sal_Unicode& cChar, sal_Int8& nByte, sal_Int16& nShort, sal_uInt16& nUShort, sal_Int32& nLong, sal_uInt32& nULong, sal_Int64& nHyper, sal_uInt64& nUHyper, float& fFloat, double& fDouble, test::TestEnum& eEnum, ::rtl::OUString& aString, ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& xInterface, ::com::sun::star::uno::Any& aAny, ::com::sun::star::uno::Sequence< test::TestElement >& aSequence, test::TestData& aStruct ) + throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException) +{ + IllegalArgumentException aExc; + aExc.ArgumentPosition = 5; + aExc.Message = OUString::createFromAscii( "dum dum dum ich tanz im kreis herum..." ); + aExc.Context = getInterface(); + throw aExc; + return test::TestData(); +} +//__________________________________________________________________________________________________ +sal_Int32 Test_Impl::getRuntimeException() throw(::com::sun::star::uno::RuntimeException) +{ + RuntimeException aExc; + aExc.Message = OUString::createFromAscii( "dum dum dum ich tanz im kreis herum..." ); + aExc.Context = getInterface(); + throw aExc; + return 0; +} +//__________________________________________________________________________________________________ +void Test_Impl::setRuntimeException( sal_Int32 _runtimeexception ) throw(::com::sun::star::uno::RuntimeException) +{ + RuntimeException aExc; + aExc.Message = OUString::createFromAscii( "dum dum dum ich tanz im kreis herum..." ); + aExc.Context = getInterface(); + throw aExc; +} +//================================================================================================== +sal_Bool raiseException( const Reference< XLanguageBindingTest > & xLBT ) +{ + sal_Int32 nCount = 0; + try + { + try + { + try + { + test::TestData aRet, aRet2; + xLBT->raiseException( + aRet.Bool, aRet.Char, aRet.Byte, aRet.Short, aRet.UShort, + aRet.Long, aRet.ULong, aRet.Hyper, aRet.UHyper, aRet.Float, aRet.Double, + aRet.Enum, aRet.String, aRet.Interface, aRet.Any, aRet.Sequence, aRet2 ); + } + catch (IllegalArgumentException aExc) + { + ++nCount; + OSL_ENSHURE( aExc.ArgumentPosition == 5 && + aExc.Context == xLBT->getInterface() && + aExc.Message.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("dum dum dum ich tanz im kreis herum...") ), + "### unexpected exception content!" ); + + /** it is certain, that the RuntimeException testing will fail, if no */ + xLBT->getRuntimeException(); + } + } + catch (const RuntimeException & rExc) + { + ++nCount; + OSL_ENSHURE( rExc.Context == xLBT->getInterface() && + rExc.Message.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("dum dum dum ich tanz im kreis herum...") ), + "### unexpected exception content!" ); + + /** it is certain, that the RuntimeException testing will fail, if no */ + xLBT->setRuntimeException( 0xcafebabe ); + } + } + catch (Exception & rExc) + { + ++nCount; + OSL_ENSHURE( rExc.Context == xLBT->getInterface() && + rExc.Message.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("dum dum dum ich tanz im kreis herum...") ), + "### unexpected exception content!" ); + return (nCount == 3 && + rExc.Context == xLBT->getInterface() && + rExc.Message.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("dum dum dum ich tanz im kreis herum...") )); + } + return sal_False; +} + +//================================================================================================== +void test_di(void) +{ + Reference<XLanguageBindingTest > xOriginal( (XLanguageBindingTest *)new Test_Impl() ); + Reference<XLanguageBindingTest > xLBT; + + uno_Environment * pCppEnv1 = 0; + uno_Environment * pCppEnv2 = 0; + + OUString aCppEnvTypeName( RTL_CONSTASCII_USTRINGPARAM(CPPU_CURRENT_LANGUAGE_BINDING_NAME) ); + uno_getEnvironment( &pCppEnv1, aCppEnvTypeName.pData, 0 ); + uno_createEnvironment( &pCppEnv2, aCppEnvTypeName.pData, 0 ); // anonymous + + Mapping aMapping( pCppEnv1, pCppEnv2, OUString::createFromAscii("prot") ); + aMapping.mapInterface( (void **)&xLBT, xOriginal.get(), ::getCppuType( &xOriginal ) ); + OSL_ENSHURE( aMapping.is(), "### cannot get mapping!" ); + + (*pCppEnv2->release)( pCppEnv2 ); + (*pCppEnv1->release)( pCppEnv1 ); + + OSL_ASSERT( xLBT.is() ); + + if (xLBT.is() && performTest( xLBT )) + { + if (raiseException( xLBT )) + { + printf( "> dynamic invocation test succeeded!\n" ); + return; + } + } + printf( "> dynamic invocation test failed!\n" ); +} diff --git a/cppu/test/testcppu.cxx b/cppu/test/testcppu.cxx new file mode 100644 index 000000000000..d08b29214b5a --- /dev/null +++ b/cppu/test/testcppu.cxx @@ -0,0 +1,886 @@ +/************************************************************************* + * + * $RCSfile: testcppu.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 15:25:54 $ + * + * 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): _______________________________________ + * + * + ************************************************************************/ + +#include <uno/environment.h> +#include <uno/mapping.hxx> + +#include <uno/dispatcher.h> +#include <rtl/alloc.h> + +#include <cppuhelper/queryinterface.hxx> +#include <com/sun/star/uno/Exception.hpp> +#include <com/sun/star/uno/XInterface.hpp> +#include <com/sun/star/uno/Uik.hpp> +#include <rtl/ustring.hxx> +#include <osl/diagnose.h> +#include <osl/interlck.h> + + +#include <test/Test1.hpp> +#include <test/Test2.hpp> +#include <test/TdTest1.hpp> +#include <test/Test3.hpp> +#include <test/Base.hpp> +#include <test/Base1.hpp> +#include <test/Base2.hpp> + +#include <cppuhelper/servicefactory.hxx> + +#include <com/sun/star/lang/XComponent.hpp> +#include <test/XSimpleInterface.hpp> +#include <test/XLanguageBindingTest.hpp> + +using namespace test; +using namespace rtl; +using namespace osl; + +using namespace com::sun::star::uno; +using namespace com::sun::star::lang; +using namespace com::sun::star::registry; +using namespace test; + + +sal_Int32 getSize( const Type & rT ) +{ + sal_Int32 nSize; + typelib_TypeDescription * pTD = 0; + typelib_typedescriptionreference_getDescription( &pTD, rT.getTypeLibType() ); + nSize = pTD->nSize; + typelib_typedescription_release( pTD ); + return nSize; +} +/* + * main. + */ +void testCppu() +{ + { + // test the size of types + OSL_ENSHURE( sizeof( Uik ) == getSize( getCppuType( (Uik *)0) ), + "bad sizeof uik" ); + OSL_ENSHURE( sizeof( Test1 ) == getSize( getCppuType( (Test1*)0).getTypeLibType() ), + "bad sizeof test1" ); +// OSL_ENSHURE( sizeof( TdTest1 ) == getSize( get_test_TdTest1_Type().getTypeLibType() ), +// "bad sizeof TypedefTest1" ); + OSL_ENSHURE( sizeof( Test2 ) == getSize( getCppuType( (Test2*)0).getTypeLibType() ), + "bad sizeof test2" ); + +/* find the error +sal_Int32 nPos; +nPos = (sal_Int32)&((Test3 *)0)->nInt8; +nPos = (sal_Int32)&((Test3 *)0)->nFloat; +nPos = (sal_Int32)&((Test3 *)0)->nuInt8; +nPos = (sal_Int32)&((Test3 *)0)->nDouble; +nPos = (sal_Int32)&((Test3 *)0)->nInt16; +nPos = (sal_Int32)&((Test3 *)0)->aString; +nPos = (sal_Int32)&((Test3 *)0)->nuInt16; +nPos = (sal_Int32)&((Test3 *)0)->nInt64; +nPos = (sal_Int32)&((Test3 *)0)->nInt32; +nPos = (sal_Int32)&((Test3 *)0)->nuInt64; +nPos = (sal_Int32)&((Test3 *)0)->nuInt32; +nPos = (sal_Int32)&((Test3 *)0)->eType; +nPos = (sal_Int32)&((Test3 *)0)->wChar; +nPos = (sal_Int32)&((Test3 *)0)->td; +nPos = (sal_Int32)&((Test3 *)0)->bBool; +nPos = (sal_Int32)&((Test3 *)0)->aAny; +*/ + OSL_ENSHURE( sizeof( Test3 ) == getSize( getCppuType( (Test3*)0).getTypeLibType() ), + "bad sizeof test3" ); + } + + { + // test the default constructor + Test1 a1; + a1.nInt16 = 4; + a1.dDouble = 3.6; + a1.bBool = sal_True; + uno_type_constructData( &a1, getCppuType( (Test1*)0).getTypeLibType() ); + OSL_ASSERT( a1.nInt16 == 0 && a1.dDouble == 0.0 && a1.bBool == sal_False); + + Test2 a2; + a2.nInt16 = 2; + a2.aTest1.nInt16 = 4; + a2.aTest1.dDouble = 3.6; + a2.aTest1.dDouble = sal_True; + uno_type_constructData( &a2, getCppuType( (Test2*)0).getTypeLibType() ); + OSL_ASSERT( a2.nInt16 == 0 && a2.aTest1.nInt16 == 0 && a2.aTest1.dDouble == 0.0 && a2.aTest1.bBool == sal_False); + + Test3 * pa3 = (Test3 *)new char[ sizeof( Test3 ) ]; + Test3 & a3 = *pa3; + a3.nInt8 = 2; + a3.nFloat = (float)2; + a3.nDouble = 2; + a3.nInt16 = 2; + a3.nuInt16 = 2; + a3.nInt64 = 2; + a3.nInt32 = 2; + a3.nuInt64 = 2; + a3.nuInt32 = 2; + a3.eType = TypeClass_STRUCT; + a3.wChar = L'g'; + a3.td.nInt16 = 2; + a3.td.dDouble = 2; + a3.bBool = sal_True; + uno_type_constructData( &a3, getCppuType( (Test3*)0).getTypeLibType() ); + OSL_ASSERT( a3.nInt8 == 0 && a3.nFloat == (float)0 + && a3.nDouble == 0 && a3.nInt16 == 0 && a3.aString == OUString() + && a3.nuInt16 == 0 && a3.nInt64 == 0 && a3.nInt32 == 0 + && a3.nuInt64 == 0 && a3.nuInt32 == 0 && a3.eType == TypeClass_VOID + && a3.wChar == L'\0' && a3.td.nInt16 == 0 && a3.td.dDouble == 0 + && a3.bBool == sal_False ); + OSL_ASSERT( a3.aAny.getValueType() == getCppuVoidType() ); + delete pa3; + } + + { + // test the destructor + long a1[ sizeof( Test1 ) / sizeof(long) +1 ]; + uno_type_constructData( &a1, getCppuType( (Test1*)0).getTypeLibType() ); + uno_type_destructData( &a1, getCppuType( (Test1*)0).getTypeLibType(), cpp_release ); + + long a2[ sizeof( Test2 ) / sizeof(long) +1 ]; + uno_type_constructData( &a2, getCppuType( (Test2*)0).getTypeLibType() ); + uno_type_destructData( &a2, getCppuType( (Test2*)0).getTypeLibType(), cpp_release ); + + long a3[ sizeof( Test3 ) / sizeof(long) +1 ]; + uno_type_constructData( &a3, getCppuType( (Test3*)0).getTypeLibType() ); + OUString aTestString( RTL_CONSTASCII_USTRINGPARAM("test") ); + ((Test3*)a3)->aString = aTestString; + uno_type_destructData( &a3, getCppuType( (Test3*)0).getTypeLibType(), cpp_release ); + OSL_ASSERT( aTestString.pData->refCount == 1 ); + } + + { + // test the copy constructor + Test1 a1; + a1.nInt16 = 4; + a1.dDouble = 3.6; + a1.bBool = sal_True; + char sz1[sizeof( Test1 )]; + uno_type_copyData( sz1, &a1, getCppuType( (Test1*)0).getTypeLibType(), cpp_acquire ); + OSL_ASSERT( ((Test1*)sz1)->nInt16 == 4 && ((Test1*)sz1)->dDouble == 3.6 && ((Test1*)sz1)->bBool == sal_True); + + Test2 a2; + a2.nInt16 = 2; + a2.aTest1.nInt16 = 4; + a2.aTest1.dDouble = 3.6; + a2.aTest1.bBool = sal_True; + char sz2[sizeof( Test2 )]; + uno_type_copyData( sz2, &a2, getCppuType( (Test2*)0).getTypeLibType(), cpp_acquire ); + OSL_ASSERT( ((Test2*)sz2)->nInt16 == 2 ); + OSL_ASSERT(((Test2*)sz2)->aTest1.nInt16 == 4 ); + OSL_ASSERT( ((Test2*)sz2)->aTest1.dDouble == 3.6 ); + OSL_ASSERT(((Test2*)sz2)->aTest1.bBool == sal_True); + + Test3 a3; + a3.nInt8 = 2; + a3.nFloat = (float)2; + a3.nDouble = 2; + a3.nInt16 = 2; + a3.aString = OUString::createFromAscii("2"); + a3.nuInt16 = 2; + a3.nInt64 = 2; + a3.nInt32 = 2; + a3.nuInt64 = 2; + a3.nuInt32 = 2; + a3.eType = TypeClass_STRUCT; + a3.wChar = L'2'; + a3.td.nInt16 = 2; + a3.td.dDouble = 2; + a3.bBool = sal_True; + a3.aAny = makeAny( (sal_Int32)2 ); + char sz3[sizeof( Test3 )]; + uno_type_copyData( sz3, &a3, getCppuType( (Test3*)0).getTypeLibType(), cpp_acquire ); + OSL_ASSERT( ((Test3*)sz3)->nInt8 == 2 ); + OSL_ASSERT( ((Test3*)sz3)->nFloat == (float)2 ); + OSL_ASSERT( ((Test3*)sz3)->nDouble == 2 ); + OSL_ASSERT( ((Test3*)sz3)->nInt16 == 2 ); + OSL_ASSERT( ((Test3*)sz3)->aString == OUString::createFromAscii("2") ); + OSL_ASSERT( ((Test3*)sz3)->nuInt16 == 2 ); + OSL_ASSERT( ((Test3*)sz3)->nInt64 == 2 ); + OSL_ASSERT( ((Test3*)sz3)->nInt32 == 2 ); + OSL_ASSERT( ((Test3*)sz3)->nuInt64 == 2 ); + OSL_ASSERT( ((Test3*)sz3)->nuInt32 == 2 ); + OSL_ASSERT( ((Test3*)sz3)->eType == TypeClass_STRUCT ); + OSL_ASSERT( ((Test3*)sz3)->wChar == L'2' ); + OSL_ASSERT( ((Test3*)sz3)->td.nInt16 == 2 ); + OSL_ASSERT( ((Test3*)sz3)->td.dDouble == 2 ); + OSL_ASSERT( ((Test3*)sz3)->bBool == sal_True ); + OSL_ASSERT( ((Test3*)sz3)->aAny.getValueType() == getCppuType( (sal_Int32 *)0 ) ); + OSL_ASSERT( *(sal_Int32*)((Test3*)sz3)->aAny.getValue() == 2 ); + ((Test3 *)sz3)->~Test3(); + } + + { + sal_Bool bAssignable; + // test assignment + Test1 a1; + a1.nInt16 = 4; + a1.dDouble = 3.6; + a1.bBool = sal_True; + Test1 sz1; + bAssignable = uno_type_assignData( + &sz1, getCppuType( (Test1*)0).getTypeLibType(), + &a1, getCppuType( (Test1*)0).getTypeLibType(), + cpp_queryInterface, cpp_acquire, cpp_release ); + OSL_ASSERT( bAssignable ); + OSL_ASSERT( sz1.nInt16 == 4 && sz1.dDouble == 3.6 && sz1.bBool == sal_True); + + Test2 a2; + a2.nInt16 = 2; + a2.aTest1.nInt16 = 4; + a2.aTest1.dDouble = 3.6; + a2.aTest1.bBool = sal_True; + Test2 sz2; + bAssignable = uno_type_assignData( + &sz2, getCppuType( (Test2*)0).getTypeLibType(), + &a2, getCppuType( (Test2*)0).getTypeLibType(), + cpp_queryInterface, cpp_acquire, cpp_release ); + OSL_ASSERT( bAssignable ); + OSL_ASSERT( sz2.nInt16 == 2 && sz2.aTest1.nInt16 == 4 + && sz2.aTest1.dDouble == 3.6 && sz2.aTest1.bBool == sal_True); + + Test3 a3; + Test3 sz3; + a3.nInt8 = 2; + a3.nFloat = (float)2; + a3.nDouble = 2; + a3.nInt16 = 2; + a3.aString = OUString::createFromAscii("2"); + a3.nuInt16 = 2; + a3.nInt64 = 2; + a3.nInt32 = 2; + a3.nuInt64 = 2; + a3.nuInt32 = 2; + a3.eType = TypeClass_STRUCT; + a3.wChar = L'2'; + a3.td.nInt16 = 2; + a3.td.dDouble = 2; + a3.bBool = sal_True; + a3.aAny = makeAny( (sal_Int32)2 ); + bAssignable = uno_type_assignData( + &sz3, getCppuType( (Test3*)0).getTypeLibType(), + &a3, getCppuType( (Test3*)0).getTypeLibType(), + cpp_queryInterface, cpp_acquire, cpp_release ); + OSL_ASSERT( bAssignable ); + OSL_ASSERT( sz3.nInt8 == 2 ); + OSL_ASSERT( sz3.nFloat == (float)2 ); + OSL_ASSERT( sz3.nDouble == 2 ); + OSL_ASSERT( sz3.nInt16 == 2 ); + OSL_ASSERT( sz3.aString == OUString::createFromAscii("2") ); + OSL_ASSERT( sz3.nuInt16 == 2 ); + OSL_ASSERT( sz3.nInt64 == 2 ); + OSL_ASSERT( sz3.nInt32 == 2 ); + OSL_ASSERT( sz3.nuInt64 == 2 ); + OSL_ASSERT( sz3.nuInt32 == 2 ); + OSL_ASSERT( sz3.eType == TypeClass_STRUCT ); + OSL_ASSERT( sz3.wChar == L'2' ); + OSL_ASSERT( sz3.td.nInt16 == 2 ); + OSL_ASSERT( sz3.td.dDouble == 2 ); + OSL_ASSERT( sz3.bBool == sal_True ); + OSL_ASSERT( sz3.aAny.getValueType() == getCppuType( (sal_Int32 *)0 ) ); + OSL_ASSERT( *(sal_Int32*)sz3.aAny.getValue() == 2 ); + + // test not assigneable values + bAssignable = uno_type_assignData( + &a1, getCppuType( (Test1*)0).getTypeLibType(), + &a2, getCppuType( (Test2*)0).getTypeLibType(), + cpp_queryInterface, cpp_acquire, cpp_release ); + OSL_ASSERT( !bAssignable ); + } + + { + // test any + Any aAny = makeAny( (sal_Int8)2 ); + OSL_ASSERT( aAny.getValueType() == getCppuType( (sal_Int8 *)0 ) ); + OSL_ASSERT( *(sal_Int8*)aAny.getValue() == 2 ); + aAny = makeAny( (float)2 ); + OSL_ASSERT( aAny.getValueType() == getCppuType( (float *)0 ) ); + OSL_ASSERT( *(float*)aAny.getValue() == (float)2 ); + aAny = makeAny( (sal_Int8)2 ); + OSL_ASSERT( aAny.getValueType() == getCppuType( (sal_Int8 *)0 ) ); + OSL_ASSERT( *(sal_Int8*)aAny.getValue() == 2 ); + aAny = makeAny( (double)2 ); + OSL_ASSERT( aAny.getValueType() == getCppuType( (double *)0 ) ); + OSL_ASSERT( *(double*)aAny.getValue() == (double)2 ); + aAny = makeAny( (sal_Int16)2 ); + OSL_ASSERT( aAny.getValueType() == getCppuType( (sal_Int16 *)0 ) ); + OSL_ASSERT( *(sal_Int16*)aAny.getValue() == 2 ); + aAny = makeAny( OUString( RTL_CONSTASCII_USTRINGPARAM("test") ) ); + OSL_ASSERT( aAny.getValueType() == getCppuType( (OUString *)0 ) ); + OSL_ASSERT( *(OUString*)aAny.getValue() == OUString::createFromAscii("test") ); + aAny = makeAny( (sal_uInt16)2 ); + OSL_ASSERT( aAny.getValueType() == getCppuType( (sal_uInt16 *)0 ) ); + OSL_ASSERT( *(sal_Int16*)aAny.getValue() == 2 ); + sal_Int64 aInt64; + sal_setInt64( &aInt64, 2, 0 ); + aAny = makeAny( aInt64 ); + OSL_ASSERT( aAny.getValueType() == getCppuType( (sal_Int64 *)0 ) ); + sal_uInt32 lowInt; + sal_Int32 highInt; + sal_getInt64( *(sal_Int64*)aAny.getValue(), &lowInt, &highInt ); + OSL_ASSERT( lowInt == 2 && highInt == 0 ); + aAny = makeAny( (sal_Int32)2 ); + OSL_ASSERT( aAny.getValueType() == getCppuType( (sal_Int32 *)0 ) ); + OSL_ASSERT( *(sal_Int32*)aAny.getValue() == 2 ); + sal_uInt64 auInt64; + sal_setUInt64( &auInt64, 2, 0 ); + aAny = makeAny( auInt64 ); + OSL_ASSERT( aAny.getValueType() == getCppuType( (sal_uInt64 *)0 ) ); + sal_uInt32 uhighInt; + sal_getUInt64( *(sal_Int64*)aAny.getValue(), &lowInt, &uhighInt ); + OSL_ASSERT( lowInt == 2 && uhighInt == 0 ); + aAny = makeAny( (sal_uInt32)2 ); + OSL_ASSERT( aAny.getValueType() == getCppuType( (sal_uInt32 *)0 ) ); + OSL_ASSERT( *(sal_uInt32*)aAny.getValue() == 2 ); + aAny = makeAny( TypeClass_STRUCT ); + OSL_ASSERT( aAny.getValueType() == getCppuType( (TypeClass *)0 ) ); + OSL_ASSERT( *(TypeClass*)aAny.getValue() == TypeClass_STRUCT ); + sal_Unicode c = L'2'; + aAny.setValue( &c, getCppuCharType() ); + OSL_ASSERT( aAny.getValueType() == getCppuCharType() ); + OSL_ASSERT( *(sal_Unicode*)aAny.getValue() == L'2' ); + sal_Bool b = sal_True; + aAny.setValue( &b, getCppuBooleanType() ); + OSL_ASSERT( aAny.getValueType() == getCppuBooleanType() ); + OSL_ASSERT( *(sal_Bool*)aAny.getValue() == sal_True ); + } + + { + // test: operator <<=( any, value ) + Any aAny; + aAny <<= (sal_Int8)2; + OSL_ASSERT( aAny.getValueType() == getCppuType( (sal_Int8 *)0 ) ); + OSL_ASSERT( *(sal_Int8*)aAny.getValue() == 2 ); + aAny <<=( (float)2 ); + OSL_ASSERT( aAny.getValueType() == getCppuType( (float *)0 ) ); + OSL_ASSERT( *(float*)aAny.getValue() == (float)2 ); +// aAny <<=( (sal_uInt8)2 ); +// OSL_ASSERT( aAny.getValueType() == getCppuType( (sal_uInt8 *)0 ) ); +// OSL_ASSERT( *(sal_uInt8*)aAny.getValue() == 2 ); + aAny <<=( (double)2 ); + OSL_ASSERT( aAny.getValueType() == getCppuType( (double *)0 ) ); + OSL_ASSERT( *(double*)aAny.getValue() == (double)2 ); + aAny <<=( (sal_Int16)2 ); + OSL_ASSERT( aAny.getValueType() == getCppuType( (sal_Int16 *)0 ) ); + OSL_ASSERT( *(sal_Int16*)aAny.getValue() == 2 ); + aAny <<=( OUString( RTL_CONSTASCII_USTRINGPARAM("test") ) ); + OSL_ASSERT( aAny.getValueType() == getCppuType( (OUString *)0 ) ); + OSL_ASSERT( *(OUString*)aAny.getValue() == OUString::createFromAscii("test") ); + aAny <<=( (sal_uInt16)2 ); + OSL_ASSERT( aAny.getValueType() == getCppuType( (sal_uInt16 *)0 ) ); + OSL_ASSERT( *(sal_Int16*)aAny.getValue() == 2 ); + sal_Int64 aInt64; + sal_setInt64( &aInt64, 2, 0 ); + aAny <<=( aInt64 ); + OSL_ASSERT( aAny.getValueType() == getCppuType( (sal_Int64 *)0 ) ); + sal_uInt32 lowInt; + sal_Int32 highInt; + sal_getInt64( *(sal_Int64*)aAny.getValue(), &lowInt, &highInt ); + OSL_ASSERT( lowInt == 2 && highInt == 0 ); + aAny <<=( (sal_Int32)2 ); + OSL_ASSERT( aAny.getValueType() == getCppuType( (sal_Int32 *)0 ) ); + OSL_ASSERT( *(sal_Int32*)aAny.getValue() == 2 ); + sal_uInt64 auInt64; + sal_setUInt64( &auInt64, 2, 0 ); + aAny <<=( auInt64 ); + OSL_ASSERT( aAny.getValueType() == getCppuType( (sal_uInt64 *)0 ) ); + sal_uInt32 uhighInt; + sal_getUInt64( *(sal_Int64*)aAny.getValue(), &lowInt, &uhighInt ); + OSL_ASSERT( lowInt == 2 && uhighInt == 0 ); + aAny <<=( (sal_uInt32)2 ); + OSL_ASSERT( aAny.getValueType() == getCppuType( (sal_uInt32 *)0 ) ); + OSL_ASSERT( *(sal_uInt32*)aAny.getValue() == 2 ); + aAny <<=( TypeClass_STRUCT ); + OSL_ASSERT( aAny.getValueType() == getCppuType( (TypeClass *)0 ) ); + OSL_ASSERT( *(TypeClass*)aAny.getValue() == TypeClass_STRUCT ); + } + + { + // test: operator >>=( any, value ) + Test3 a3; + makeAny( (sal_Int8)2) >>= a3.nInt8; + OSL_ASSERT( (makeAny( (sal_Int8)2) >>= a3.nInt8) && a3.nInt8 == 2 ); + OSL_ASSERT( (makeAny( (float)2) >>= a3.nFloat) && a3.nFloat ==(float)2 ); + OSL_ASSERT( (makeAny( (double)2) >>= a3.nDouble) && a3.nDouble == 2 ); + OSL_ASSERT( (makeAny( (sal_Int16)2) >>= a3.nInt16) && a3.nInt16 == 2 ); + OSL_ASSERT( (makeAny( OUString( RTL_CONSTASCII_USTRINGPARAM("2") )) >>= a3.aString) && + a3.aString == OUString::createFromAscii("2") ); + OSL_ASSERT( (makeAny( (sal_uInt16)2) >>= a3.nuInt16) && a3.nuInt16 == 2 ); + sal_Int64 aInt64; + sal_uInt32 lowInt; + sal_Int32 highInt; + sal_setInt64( &aInt64, 2, 0 ); + OSL_ASSERT( makeAny( aInt64 ) >>= a3.nInt64 ); + sal_getInt64( a3.nInt64, &lowInt, &highInt ); + OSL_ASSERT( lowInt == 2 ); + OSL_ASSERT( (makeAny( (sal_Int32)2) >>= a3.nInt32) && a3.nInt32 == 2 ); + sal_uInt64 auInt64; + sal_uInt32 uhighInt; + sal_setUInt64( &auInt64, 2, 0 ); + OSL_ASSERT( makeAny( auInt64 ) >>= a3.nuInt64 ); + sal_getUInt64( a3.nuInt64, &lowInt, &uhighInt ); + OSL_ASSERT( lowInt == 2 ); + OSL_ASSERT( (makeAny( (sal_uInt32)2) >>= a3.nuInt32) && a3.nuInt32 == 2 ); + OSL_ASSERT( (makeAny( TypeClass_STRUCT) >>= a3.eType) && a3.eType == TypeClass_STRUCT ); + //OSL_ASSERT( (makeAny( L'2' ) >>= a3.wChar) && a3.nInt8 ==L'2'; + OSL_ASSERT( (makeAny( (sal_Int16)2) >>= a3.td.nInt16) && a3.nInt16 == 2 ); + OSL_ASSERT( (makeAny( (double)2) >>= a3.td.dDouble) && a3.nDouble == 2 ); + //OSL_ASSERT( (makeAny( (sal_True)2) >>= a3.bBool) && a3.nInt8 ==sal_True; + + // Only one negative test, the implementation has only one if to test this + OSL_ASSERT( (makeAny( (float)2) >>= a3.nFloat) && a3.nFloat ==(float)2 ); + } + + { + // test: Sequence + Sequence< Test1 > aTestSeq; + OSL_ASSERT( aTestSeq.getLength() == 0 ); + sal_Int32 szInt32[2] = { 1, 2 }; + Sequence< sal_Int32 > aInt32Seq( szInt32, 2 ); + OSL_ASSERT( aInt32Seq.getLength() == 2 ); + OSL_ASSERT( aInt32Seq[0] == 1 && aInt32Seq[1] == 2 ); + OSL_ASSERT( aInt32Seq.getArray()[0] == 1 && aInt32Seq.getArray()[1] == 2 ); + Sequence< sal_Int32 > aNextInt32Seq( aInt32Seq ); + OSL_ASSERT( aNextInt32Seq[0] == 1 && aNextInt32Seq[1] == 2 ); + aInt32Seq[0] = 45; + OSL_ASSERT( aInt32Seq[0] == 45 && aInt32Seq[1] == 2 ); + OSL_ASSERT( aNextInt32Seq[0] == 1 && aNextInt32Seq[1] == 2 ); + sal_Int32 * pArray = aNextInt32Seq.getArray(); + OSL_ASSERT( pArray[0] == 1 && pArray[1] == 2 ); + Sequence< double > aDoubleSeq( 5 ); + OSL_ASSERT( aDoubleSeq[4] == 0.0 ); + Sequence< OUString > aStringSeq( 5 ); + OSL_ASSERT( aStringSeq[4] == OUString() ); + } + sal_Int32 szInt32[2] = { 1, 2 }; + Sequence<sal_Int32 > aInt32Seq( szInt32, 2 ); + Sequence<sal_Int32 > aNextInt32Seq( aInt32Seq ); + aNextInt32Seq.realloc( 1 ); // split of sequence + const sal_Int32 * pArray = aNextInt32Seq.getConstArray(); + OSL_ASSERT( pArray[0] == 1 ); + aInt32Seq.realloc( 1 ); // reallocate mem + pArray = aInt32Seq.getConstArray(); + OSL_ASSERT( pArray[0] == 1 ); +} + +class TestInterface : public XInterface +{ +public: + // XInterface + void SAL_CALL acquire() { osl_incrementInterlockedCount( &nRefCount ); } + void SAL_CALL release() + { + if( !osl_decrementInterlockedCount( &nRefCount ) ) + delete this; + } + Any SAL_CALL queryInterface( const Type & rType ) + { + return cppu::queryInterface( rType, static_cast< XInterface* >( this ) ); + } + + TestInterface() : nRefCount( 0 ) {} + + sal_Int32 nRefCount; +}; + +struct SimpleInterface : public TestInterface, public XSimpleInterface +{ + void SAL_CALL acquire() { TestInterface::acquire(); } + void SAL_CALL release() { TestInterface::release(); } + Any SAL_CALL queryInterface( const Type & rType ) + { + Any aRet( cppu::queryInterface( rType, static_cast< XSimpleInterface * >( this ) ) ); + return (aRet.hasValue() ? aRet : TestInterface::queryInterface( rType )); + } + virtual void SAL_CALL method() throw(::com::sun::star::uno::RuntimeException) + {} +}; + +static sal_Bool s_aAssignableFromTab[11][11] = +{ + /* from CH,BO,BY,SH,US,LO,UL,HY,UH,FL,DO */ +/* TypeClass_CHAR */ { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, +/* TypeClass_BOOLEAN */ { 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, +/* TypeClass_BYTE */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 }, +/* TypeClass_SHORT */ { 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0 }, +/* TypeClass_UNSIGNED_SHORT */ { 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0 }, +/* TypeClass_LONG */ { 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0 }, +/* TypeClass_UNSIGNED_LONG */ { 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0 }, +/* TypeClass_HYPER */ { 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0 }, +/* TypeClass_UNSIGNED_HYPER */ { 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0 }, +/* TypeClass_FLOAT */ { 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0 }, +/* TypeClass_DOUBLE */ { 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1 } +}; +template < class T > +static void test_assignSimple( const T & rVal, /*const*/ Any /*&*/ rAny ) +{ + typelib_TypeDescription * pTD = 0; + ::getCppuType( &rVal ).getDescription( &pTD ); + sal_Bool bTable = s_aAssignableFromTab[pTD->eTypeClass-1][rAny.getValueTypeClass()-1]; + OSL_ASSERT( + (bTable!=sal_False) == + (typelib_typedescriptionreference_isAssignableFrom( + pTD->pWeakRef, rAny.getValueTypeRef() )!=sal_False) ); + T t; + OSL_ASSERT( (bTable!=sal_False) == ((rAny >>= t)!=sal_False) ); + if (bTable) + OSL_ASSERT( t == rVal ); + typelib_typedescription_release( pTD ); +} +template < class T > +static void test_simple_assignment( const T & rVal ) +{ + // bool + sal_Bool tr = sal_True; + typelib_TypeDescription * pBoolTD = 0; + ::getCppuBooleanType().getDescription( &pBoolTD ); + Any a( &tr, pBoolTD ); + test_assignSimple( rVal, a ); + OSL_ASSERT( typelib_typedescriptionreference_isAssignableFrom( pBoolTD->pWeakRef, a.getValueTypeRef() ) ); + typelib_typedescription_release( pBoolTD ); + OSL_ASSERT( *(sal_Bool *)a.getValue() ); + // char + sal_Unicode ch = 'a'; + typelib_TypeDescription * pCharTD = 0; + ::getCppuCharType().getDescription( &pCharTD ); + a.setValue( &ch, pCharTD ); + test_assignSimple( rVal, a ); + OSL_ASSERT( typelib_typedescriptionreference_isAssignableFrom( pCharTD->pWeakRef, a.getValueTypeRef() ) ); + typelib_typedescription_release( pCharTD ); + OSL_ASSERT( *(sal_Unicode *)a.getValue() == 'a' ); + + // rest by template + a <<= (sal_Int8)5; + test_assignSimple( rVal, a ); + a <<= (sal_Int16)5; + test_assignSimple( rVal, a ); + a <<= (sal_uInt16)5; + test_assignSimple( rVal, a ); + a <<= (sal_Int32)5; + test_assignSimple( rVal, a ); + a <<= (sal_uInt32)5; + test_assignSimple( rVal, a ); + a <<= (sal_Int64)5; + test_assignSimple( rVal, a ); + a <<= (sal_uInt64)5; + test_assignSimple( rVal, a ); + a <<= (float)5; + test_assignSimple( rVal, a ); + a <<= (double)5; + test_assignSimple( rVal, a ); +} +static void testAssignment() +{ + // simple types + test_simple_assignment( (sal_Int8)5 ); + test_simple_assignment( (sal_Int16)5 ); + test_simple_assignment( (sal_uInt16)5 ); + test_simple_assignment( (sal_Int32)5 ); + test_simple_assignment( (sal_uInt32)5 ); + test_simple_assignment( (sal_Int64)5 ); + test_simple_assignment( (sal_uInt64)5 ); + test_simple_assignment( (float)5 ); + test_simple_assignment( (double)5 ); + // some complex things + Any a; + TestSimple ts; + TestElement te; // derived from simple + a <<= ts; + OSL_ASSERT( !(a >>= te) ); + OSL_ASSERT( a >>= ts ); + a <<= te; + OSL_ASSERT( (a >>= te) && (a >>= ts) ); + // interface + Reference< XSimpleInterface > xOriginal( new SimpleInterface() ); + a <<= xOriginal; + Reference< XInterface > x; + OSL_ASSERT( (a >>= x) && (a == xOriginal) && (xOriginal == x) && (x == xOriginal) ); + // sequence + Sequence< TestElement > aSeq( 5 ); + Sequence< TestElement > aSeq2( 3 ); + aSeq[1].Byte = 17; + a <<= aSeq; + OSL_ASSERT( a >>= aSeq2 ); + OSL_ASSERT( aSeq2[1].Byte == 17 ); + aSeq2[1].Byte = 20; + OSL_ASSERT( aSeq != aSeq2 ); + OSL_ASSERT( a != aSeq2 ); + a <<= aSeq2; + OSL_ASSERT( a >>= aSeq ); + OSL_ASSERT( a == aSeq ); + OSL_ASSERT( !(a != aSeq) ); + OSL_ASSERT( aSeq == aSeq2 ); + OSL_ASSERT( aSeq[1].Byte == 20 ); +} + +void test_interface() +{ + { + // test: Interface + Reference< XInterface > xIFace; + OSL_ASSERT( !xIFace.is() ); + xIFace.clear(); // do nothing + } +} + +void test_inheritance() +{ + OSL_ASSERT( sizeof( Base ) == getSize( getCppuType( (Base *)0).getTypeLibType() ) ); + OSL_ASSERT( sizeof( Base1 ) == getSize( getCppuType( (Base1 *)0).getTypeLibType() ) ); + OSL_ASSERT( sizeof( Base2 ) == getSize( getCppuType( (Base2 *)0).getTypeLibType() ) ); +} + +sal_Int32 nCallback_1; +sal_Int32 nCallback; +void SAL_CALL typedescription_Callback_1 +( + void * pContext, + typelib_TypeDescription ** ppRet, + rtl_uString * pTypeName +) +{ + OSL_ENSHURE( pContext == (void *)1, "### unexpected context!" ); + if( *ppRet ) + { + typelib_typedescription_release( *ppRet ); + *ppRet = 0; + } + + OUString aTypeName( pTypeName ); + if( -1 != aTypeName.indexOf( OUString::createFromAscii("1_") ) ) + { + nCallback_1++; + OUString aName( RTL_CONSTASCII_USTRINGPARAM("unsigned short") ); + OUString empty; + typelib_CompoundMember_Init aMember = { typelib_TypeClass_UNSIGNED_SHORT, + aName.pData, + empty.pData }; + typelib_typedescription_new( + ppRet, + typelib_TypeClass_STRUCT, pTypeName, 0, + 1, + &aMember + ); + } +} + +void SAL_CALL typedescription_Callback +( + void * pContext, + typelib_TypeDescription ** ppRet, + rtl_uString * pTypeName +) +{ + OSL_ENSHURE( pContext == (void *)0, "### unexpected context!" ); + if( *ppRet ) + { + typelib_typedescription_release( *ppRet ); + *ppRet = 0; + } + + OUString aTypeName( pTypeName ); + if( -1 != aTypeName.indexOf( OUString::createFromAscii("cachetest") ) ) + { + nCallback++; + aTypeName = OUString( RTL_CONSTASCII_USTRINGPARAM("1_") ) + aTypeName; + OUString empty; + typelib_CompoundMember_Init aMember = { typelib_TypeClass_STRUCT, + aTypeName.pData, + empty.pData }; + typelib_typedescription_new( + ppRet, + typelib_TypeClass_STRUCT, pTypeName, 0, + 1, + &aMember + ); + } +} + +void test_cache() +{ + typelib_typedescription_registerCallback( (void *)1, typedescription_Callback_1 ); + typelib_typedescription_registerCallback( 0, typedescription_Callback ); + + for( sal_Int32 i = 0; i < 300; i++ ) + { + typelib_TypeDescription * pTD = 0; + OUString aTypeName( RTL_CONSTASCII_USTRINGPARAM("cachetest") ); + aTypeName = aTypeName + OUString::valueOf( i ); + typelib_typedescription_getByName( &pTD, aTypeName.pData ); + typelib_typedescription_release( pTD ); + } + OSL_ASSERT( nCallback_1 == 300 ); + OSL_ASSERT( nCallback == 300 ); + // The cache size is 200 so the description "cachetest200" is in the cache + typelib_TypeDescription * pTD = 0; + OUString aName200( RTL_CONSTASCII_USTRINGPARAM("cachetest200") ); + typelib_typedescription_getByName( &pTD, aName200.pData ); + OSL_ASSERT( nCallback_1 == 300 ); + OSL_ASSERT( nCallback == 300 ); + // The cache size is 200 so the description "cachetest199" is not in the cache + // "1_cachetest199" is loaded too. + OUString aName199( RTL_CONSTASCII_USTRINGPARAM("cachetest199") ); + typelib_typedescription_getByName( &pTD, aName199.pData ); + typelib_typedescription_release( pTD ); + OSL_ASSERT( nCallback_1 == 301 ); + OSL_ASSERT( nCallback == 301 ); + + typelib_typedescription_revokeCallback( (void *)1, typedescription_Callback_1 ); + typelib_typedescription_revokeCallback( 0, typedescription_Callback ); +} + +static OUString s_aAddPurpose; + +static void SAL_CALL getMappingCallback( + uno_Mapping ** ppMapping, + uno_Environment * pFrom, uno_Environment * pTo, rtl_uString * pAddPurpose ) +{ + s_aAddPurpose = pAddPurpose; +} +static void testMappingCallback() +{ + uno_registerMappingCallback( getMappingCallback ); + OSL_ASSERT( ! s_aAddPurpose.getLength() ); + Mapping aTest( + OUString( RTL_CONSTASCII_USTRINGPARAM(CPPU_CURRENT_LANGUAGE_BINDING_NAME) ), + OUString( RTL_CONSTASCII_USTRINGPARAM(CPPU_CURRENT_LANGUAGE_BINDING_NAME) ), + OUString( RTL_CONSTASCII_USTRINGPARAM("test") ) ); + uno_revokeMappingCallback( getMappingCallback ); + OSL_ASSERT( s_aAddPurpose.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("test") ) ); + s_aAddPurpose = OUString(); + Mapping aTest2( + OUString( RTL_CONSTASCII_USTRINGPARAM(CPPU_CURRENT_LANGUAGE_BINDING_NAME) ), + OUString( RTL_CONSTASCII_USTRINGPARAM(CPPU_CURRENT_LANGUAGE_BINDING_NAME) ), + OUString( RTL_CONSTASCII_USTRINGPARAM("test") ) ); + OSL_ASSERT( ! s_aAddPurpose.getLength() ); +} + +static void testEnvironment(void) +{ + uno_Environment * pEnv = 0; + void ** ppInterfaces = 0; + sal_Int32 nLen; + + OUString aUnoEnvTypeName( RTL_CONSTASCII_USTRINGPARAM(UNO_LB_UNO) ); + uno_getEnvironment( &pEnv, aUnoEnvTypeName.pData, 0 ); + (*pEnv->pExtEnv->getRegisteredInterfaces)( pEnv->pExtEnv, &ppInterfaces, &nLen, rtl_allocateMemory ); + while (nLen--) + { + uno_Interface * pUnoI = (uno_Interface *)ppInterfaces[nLen]; + (*pUnoI->release)( pUnoI ); + } + rtl_freeMemory( ppInterfaces ); + + OUString aCppEnvTypeName( RTL_CONSTASCII_USTRINGPARAM(CPPU_CURRENT_LANGUAGE_BINDING_NAME) ); + uno_getEnvironment( &pEnv, aCppEnvTypeName.pData, 0 ); + (*pEnv->pExtEnv->getRegisteredInterfaces)( pEnv->pExtEnv, &ppInterfaces, &nLen, rtl_allocateMemory ); + while (nLen--) + { + uno_Interface * pUnoI = (uno_Interface *)ppInterfaces[nLen]; + (*pUnoI->release)( pUnoI ); + } + rtl_freeMemory( ppInterfaces ); + (*pEnv->release)( pEnv ); +} + +#ifdef SOLARIS +extern "C" void ChangeGlobalInit(); +#endif + +/* + * main. + */ +int SAL_CALL main(int argc, char **argv) +{ +#ifdef SOLARIS + ChangeGlobalInit(); +#endif + typelib_setCacheSize( 200 ); +#ifdef SAL_W32 + Reference< XMultiServiceFactory > xMgr( cppu::createRegistryServiceFactory( + OUString( RTL_CONSTASCII_USTRINGPARAM("testcppu.rdb") ) ) ); +#endif + testEnvironment(); + testMappingCallback(); + + // perform test + void test_di(void); + test_di(); + void test_performance(void); + testAssignment(); + testCppu(); +// test_cache(); // cache test not possible if types are loaded dynamically... + test_interface(); + test_inheritance(); + + // shutdown +#ifdef SAL_W32 + Reference< XComponent > xComp( xMgr, UNO_QUERY ); + OSL_ENSHURE( xComp.is(), "### serivce manager has to implement XComponent!" ); + xComp->dispose(); + xMgr.clear(); +#endif + typelib_setCacheSize( 0 ); + testEnvironment(); + + return 0; +} diff --git a/cppu/test/testthreadpool.cxx b/cppu/test/testthreadpool.cxx new file mode 100644 index 000000000000..2f2f84499599 --- /dev/null +++ b/cppu/test/testthreadpool.cxx @@ -0,0 +1,223 @@ +/************************************************************************* + * + * $RCSfile: testthreadpool.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 15:25:53 $ + * + * 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): _______________________________________ + * + * + ************************************************************************/ +#include <osl/diagnose.h> + +#include <rtl/uuid.h> + +#include <uno/threadpool.h> + +#include <vos/thread.hxx> + +#define TEST_ENSURE OSL_ENSHURE + +using namespace ::vos; + + +class OThread1 : public OThread +{ +public: + OThread1( sal_uInt8 *pCallerUuid ); + virtual void run(); + +public: + sal_uInt8 *m_pCallerUuid; + sal_Int8 *m_pThreadIdentifier; + sal_Int32 m_nThreadIdentifierLength; + + void *m_pThreadData; +}; + +OThread1::OThread1( sal_uInt8 *pCallerUuid ) : + m_pCallerUuid( pCallerUuid ), + m_pThreadData( (void*) 1 ), + m_pThreadIdentifier( 0 ), + m_nThreadIdentifierLength( 0 ) +{ + +} + +void OThread1::run() +{ + + uno_threadpool_Ticket *pTicket = uno_threadpool_createTicket( m_pCallerUuid ); + + uno_threadIdent_retrieve( &m_pThreadIdentifier , &m_nThreadIdentifierLength ); + + uno_threadpool_waitOnTicket( pTicket , &m_pThreadData ); + + uno_threadIdent_revoke(); +} + + +void SAL_CALL doIt( void *pThreadData ) +{ + *( sal_Int32 *) pThreadData = 2; +} + +void testthreadpool() +{ + printf( "Testing threadpool ..." ); + fflush( stdout ); + + sal_uInt8 pCallerUuid1[16]; + sal_uInt8 pCallerUuid2[16]; + rtl_createUuid( pCallerUuid1, 0 , sal_True ); + rtl_createUuid( pCallerUuid2, 0 , sal_True ); + + //------------ + // Test reply + //------------ + { + OThread1 thread1( pCallerUuid1 ); + + thread1.create(); + + // do a busy wait + while( ! thread1.m_pThreadIdentifier && ! thread1.m_nThreadIdentifierLength ); + + void *pThreadData = (void*)0xdeadbabe; + uno_threadpool_reply( thread1.m_pThreadIdentifier , + thread1.m_nThreadIdentifierLength, + pThreadData ); + + // do a busy wait + while( (void*)1 == thread1.m_pThreadData ); + + TEST_ENSURE( pThreadData == thread1.m_pThreadData, "uno_threadpool_reply error" ); + } + + //--------------- + // Test request + //--------------- + { + OThread1 thread1( pCallerUuid1 ); + + thread1.create(); + + // do a busy wait + while( ! thread1.m_pThreadIdentifier && ! thread1.m_nThreadIdentifierLength ); + + // do a request + sal_Int32 i = 1; + uno_threadpool_request( thread1.m_pThreadIdentifier , + thread1.m_nThreadIdentifierLength, + &i, + doIt, + sal_False); + + // do a busy wait + while( 1 == i ); + TEST_ENSURE( 2 == i, "uno_threadpool_request error" ); + + // get it out of the pool + void *pThreadData = (void*)0xdeadbabe; + uno_threadpool_reply( thread1.m_pThreadIdentifier , + thread1.m_nThreadIdentifierLength, + pThreadData ); + + // do a busy wait + while( pThreadData != thread1.m_pThreadData ); + + } + + //--------------- + // Test dispose threads + //--------------- + { + OThread1 thread1( pCallerUuid1 ); + OThread1 thread2( pCallerUuid2 ); + + thread1.create(); + thread2.create(); + + // do a busy wait + while( ! thread1.m_pThreadIdentifier && ! thread1.m_nThreadIdentifierLength && + ! thread2.m_pThreadIdentifier && ! thread2.m_nThreadIdentifierLength ); + + // dispose the first + uno_threadpool_disposeThreads( pCallerUuid1 ); + + while( (void*)1 == thread1.m_pThreadData ); + TEST_ENSURE( (void*)0 == thread1.m_pThreadData, "disposing threads failed" ); + + TimeValue value = {1,0}; + osl_waitThread( &value ); + TEST_ENSURE( (void*)1 == thread2.m_pThreadData, "wrong thread disposed !" ); + + // test, if new threads are directly disposed + OThread1 thread3( pCallerUuid1 ); + thread3.create(); + + while( (void*)1 == thread3.m_pThreadData ); + TEST_ENSURE( (void*)0 == thread3.m_pThreadData , + "new threads entering threadpool are not disposed" ); + + uno_threadpool_reply( thread2.m_pThreadIdentifier , + thread2.m_nThreadIdentifierLength, + (void*)0x2 ); + + while( (void*)1 == thread2.m_pThreadData ); + TEST_ENSURE( (void*)2 == thread2.m_pThreadData , "reply does not work correctly" ); + + uno_threadpool_stopDisposeThreads( pCallerUuid1 ); + } + printf( "Done\n" ); +} |