diff options
Diffstat (limited to 'cppuhelper/test')
28 files changed, 4858 insertions, 0 deletions
diff --git a/cppuhelper/test/bootstrap/TestEnv.cxx b/cppuhelper/test/bootstrap/TestEnv.cxx new file mode 100644 index 000000000000..578378ee2898 --- /dev/null +++ b/cppuhelper/test/bootstrap/TestEnv.cxx @@ -0,0 +1,130 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_cppuhelper.hxx" + +#include "cppu/EnvDcp.hxx" + +#include "cppu/helper/purpenv/Environment.hxx" +#include "cppu/helper/purpenv/Mapping.hxx" + + + +#define LOG_LIFECYCLE_TestEnv +#ifdef LOG_LIFECYCLE_TestEnv +# include <iostream> +# define LOG_LIFECYCLE_TestEnv_emit(x) x + +#else +# define LOG_LIFECYCLE_TestEnv_emit(x) + +#endif + + +class SAL_DLLPRIVATE TestEnv : public cppu::Enterable +{ + int m_inCount; + + virtual ~TestEnv(); + +public: + explicit TestEnv(); + +protected: + virtual void v_enter(void); + virtual void v_leave(void); + + virtual void v_callInto_v(uno_EnvCallee * pCallee, va_list * pParam); + virtual void v_callOut_v (uno_EnvCallee * pCallee, va_list * pParam); + + virtual int v_isValid (rtl::OUString * pReason); +}; + +TestEnv::TestEnv() + : m_inCount(0) +{ + LOG_LIFECYCLE_TestEnv_emit(fprintf(stderr, "LIFE: %s -> %p\n", "TestEnv::TestEnv(...)", this)); +} + +TestEnv::~TestEnv(void) +{ + LOG_LIFECYCLE_TestEnv_emit(fprintf(stderr, "LIFE: %s -> %p\n", "TestEnv::~TestEnv(void)", this)); +} + + +void TestEnv::v_callInto_v(uno_EnvCallee * pCallee, va_list * pParam) +{ + ++ m_inCount; + pCallee(pParam); + -- m_inCount; +} + +void TestEnv::v_callOut_v(uno_EnvCallee * pCallee, va_list * pParam) +{ + -- m_inCount; + pCallee(pParam); + ++ m_inCount; +} + +void TestEnv::v_enter(void) +{ + ++ m_inCount; +} + +void TestEnv::v_leave(void) +{ + -- m_inCount; +} + +int TestEnv::v_isValid(rtl::OUString * pReason) +{ + int result = m_inCount & 1; + + if (result) + *pReason = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("OK")); + + else + *pReason = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("not entered/invoked")); + + return result; +} + +extern "C" void SAL_CALL uno_initEnvironment(uno_Environment * pEnv) SAL_THROW_EXTERN_C() +{ + cppu::helper::purpenv::Environment_initWithEnterable(pEnv, new TestEnv()); +} + +extern "C" void uno_ext_getMapping(uno_Mapping ** ppMapping, + uno_Environment * pFrom, + uno_Environment * pTo ) +{ + cppu::helper::purpenv::createMapping(ppMapping, pFrom, pTo); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/cppuhelper/test/bootstrap/TestEnv.def b/cppuhelper/test/bootstrap/TestEnv.def new file mode 100644 index 000000000000..1444d92c13fa --- /dev/null +++ b/cppuhelper/test/bootstrap/TestEnv.def @@ -0,0 +1,8 @@ +HEAPSIZE 0 +EXPORTS + uno_initEnvironment + uno_ext_getMapping + + + + diff --git a/cppuhelper/test/bootstrap/bootstrap.test.cxx b/cppuhelper/test/bootstrap/bootstrap.test.cxx new file mode 100644 index 000000000000..b0eadb6946a1 --- /dev/null +++ b/cppuhelper/test/bootstrap/bootstrap.test.cxx @@ -0,0 +1,323 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + + +#include "sal/main.h" +#include "osl/file.hxx" + +#include "typelib/typedescription.hxx" + +#include "cppuhelper/bootstrap.hxx" +#include "cppuhelper/shlib.hxx" + +#include <com/sun/star/lang/XComponent.hpp> + +#include "uno/environment.hxx" +#include "cppu/EnvDcp.hxx" +#include "cppu/EnvGuards.hxx" + +#include <iostream> + + +#ifndef SAL_DLLPREFIX +# define SAL_DLLPREFIX "" +#endif + + +using namespace com::sun::star; + + +static rtl::OUString s_comment; + +static bool s_check_object_is_in(void * pObject) +{ + uno::Environment currentEnv(uno::Environment::getCurrent()); + + rtl_uString * pOId = NULL; + currentEnv.get()->pExtEnv->getObjectIdentifier(currentEnv.get()->pExtEnv, &pOId, pObject); + + + uno::TypeDescription typeDescription(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.uno.XInterface"))); + + void * pRegisteredObject = NULL; + currentEnv.get()->pExtEnv->getRegisteredInterface(currentEnv.get()->pExtEnv, + &pRegisteredObject, + pOId, + (typelib_InterfaceTypeDescription *)typeDescription.get()); + + + if (pOId) rtl_uString_release(pOId); + + bool result = pRegisteredObject != NULL; + + if (result) + currentEnv.get()->pExtEnv->releaseInterface(currentEnv.get()->pExtEnv, pRegisteredObject); + + return result; +} + +static void s_test__loadSharedLibComponentFactory(rtl::OUString const & clientPurpose, + rtl::OUString const & servicePurpose) +{ + cppu::EnvGuard envGuard(uno::Environment(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(UNO_LB_UNO)) + + clientPurpose, NULL)); + if (clientPurpose.getLength() && !envGuard.is()) + { + s_comment += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\t\tcouldn't get purpose env: \"")); + s_comment += clientPurpose; + s_comment += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\" - FAILURE\n")); + + return; + } + + rtl::OString os_clientPurpose(rtl::OUStringToOString(clientPurpose, RTL_TEXTENCODING_ASCII_US)); + + uno::Reference<uno::XInterface> xItf( + cppu::loadSharedLibComponentFactory( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SAL_DLLPREFIX "TestComponent.uno" SAL_DLLEXTENSION)), +#ifdef WIN32 + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("")), +#else + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("file://../lib/")), +#endif + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("impl.test.TestComponent")) + servicePurpose, + uno::Reference<lang::XMultiServiceFactory>(), + uno::Reference<registry::XRegistryKey>() + ) + ); + + if (!xItf.is()) + { + s_comment += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\t\tgot no object - FAILURE\n")); + return; + } + + if (!clientPurpose.equals(servicePurpose) && !s_check_object_is_in(xItf.get())) + { + s_comment += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\t\tcouldn't find object in current purpose \"")); + s_comment += clientPurpose; + s_comment += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\" - FAILURE\n")); + } + + if (!cppu::EnvDcp::getPurpose(uno::Environment::getCurrent().getTypeName()).equals(clientPurpose)) + { + s_comment += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\t\tdid not enter client purpose \"")); + s_comment += clientPurpose; + s_comment += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\" - FAILURE\n")); + } +} + +static void s_test__loadSharedLibComponentFactory__free_free() +{ + s_comment += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\ts_test__loadSharedLibComponentFactory__free_free\n")); + + s_test__loadSharedLibComponentFactory(rtl::OUString(), rtl::OUString()); +} + +static void s_test__loadSharedLibComponentFactory__free_purpose() +{ + s_comment += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\ts_test__loadSharedLibComponentFactory__free_purpose\n")); + + s_test__loadSharedLibComponentFactory(rtl::OUString(), + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(":testenv"))); +} + +static void s_test__loadSharedLibComponentFactory__purpose_free() +{ + s_comment += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\ts_test__loadSharedLibComponentFactory__purpose_free\n")); + + s_test__loadSharedLibComponentFactory(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(":testenv")), + rtl::OUString()); +} + +static void s_test__loadSharedLibComponentFactory__purpose_purpose() +{ + s_comment += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\ts_test__loadSharedLibComponentFactory__purpose_purpose\n")); + + s_test__loadSharedLibComponentFactory(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(":testenv")), + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(":testenv"))); +} + +static rtl::OUString s_getSDrive(void) +{ + rtl::OUString path;//(RTL_CONSTASCII_USTRINGPARAM("file://")); + + char const * tmp = getenv("SOLARVER"); + path += rtl::OUString(tmp, rtl_str_getLength(tmp), RTL_TEXTENCODING_ASCII_US); + path += rtl::OUString(SAL_PATHDELIMITER); + + tmp = getenv("INPATH"); + path += rtl::OUString(tmp, rtl_str_getLength(tmp), RTL_TEXTENCODING_ASCII_US); + path += rtl::OUString(SAL_PATHDELIMITER); +#ifdef WIN32 + path += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("bin")); + +#else + path += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("lib")); +#endif + + tmp = getenv("UPDMINOREXT"); + if (tmp) + path += rtl::OUString(tmp, rtl_str_getLength(tmp), RTL_TEXTENCODING_ASCII_US); + + osl::FileBase::getFileURLFromSystemPath(path, path); + + return path; +} + +static void s_test__createSimpleRegistry(rtl::OUString const & clientPurpose) +{ + cppu::EnvGuard envGuard(uno::Environment(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(UNO_LB_UNO)) + + clientPurpose, NULL)); + if (clientPurpose.getLength() && !envGuard.is()) + { + s_comment += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\t\tcouldn't get purpose env: \"")); + s_comment += clientPurpose; + s_comment += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\" - FAILURE\n")); + + return; + } + + uno::Reference<registry::XSimpleRegistry> registry(cppu::createSimpleRegistry( + s_getSDrive())); + + if (!registry.is()) + { + s_comment += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\t\tgot no object - FAILURE\n")); + return; + } + + if (clientPurpose.getLength() != 0 && !s_check_object_is_in(registry.get())) + { + s_comment += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\t\tcouldn't find object in current purpose \"")); + s_comment += clientPurpose; + s_comment += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\" - FAILURE\n")); + } +} + +static void s_test__createSimpleRegistry__free(void) +{ + s_comment += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\ts_test__createSimpleRegistry__free\n")); + + s_test__createSimpleRegistry(rtl::OUString()); +} + +static void s_test__createSimpleRegistry__purpose(void) +{ + s_comment += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\ts_test__createSimpleRegistry__purpose\n")); + + s_test__createSimpleRegistry(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(":testenv"))); +} + + +static void s_test__bootstrap_InitialComponentContext(rtl::OUString const & clientPurpose) +{ + cppu::EnvGuard envGuard(uno::Environment(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(UNO_LB_UNO)) + + clientPurpose, NULL)); + if (clientPurpose.getLength() && !envGuard.is()) + { + s_comment += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\t\tcouldn't get purpose env: \"")); + s_comment += clientPurpose; + s_comment += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\" - FAILURE\n")); + + return; + } + + uno::Reference<uno::XComponentContext> xContext( + cppu::bootstrap_InitialComponentContext( + uno::Reference<registry::XSimpleRegistry>(), + s_getSDrive()) + ); + + if (!xContext.is()) + { + s_comment += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\t\tgot no object - FAILURE\n")); + return; + } + + if (clientPurpose.getLength() != 0 && !s_check_object_is_in(xContext.get())) + { + s_comment += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\t\tcouldn't find object in current purpose \"")); + s_comment += clientPurpose; + s_comment += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\" - FAILURE\n")); + } + + uno::Reference<lang::XComponent> xComponent(xContext, uno::UNO_QUERY_THROW); + xComponent->dispose(); +} + +static void s_test__bootstrap_InitialComponentContext__free(void) +{ + s_comment += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\ts_test__bootstrap_InitialComponentContext__free\n")); + + s_test__bootstrap_InitialComponentContext(rtl::OUString()); +} + +static void s_test__bootstrap_InitialComponentContext__purpose(void) +{ + s_comment += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\ts_test__bootstrap_InitialComponentContext__purpose\n")); + + s_test__bootstrap_InitialComponentContext(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(":testenv"))); +} + + +SAL_IMPLEMENT_MAIN_WITH_ARGS(/*argc*/, argv) +{ + s_test__createSimpleRegistry__free(); + s_test__createSimpleRegistry__purpose(); + + s_test__loadSharedLibComponentFactory__free_free(); + s_test__loadSharedLibComponentFactory__free_purpose(); + s_test__loadSharedLibComponentFactory__purpose_free(); + s_test__loadSharedLibComponentFactory__purpose_purpose(); + + s_test__bootstrap_InitialComponentContext__free(); + s_test__bootstrap_InitialComponentContext__purpose(); + + int ret; + if (s_comment.indexOf(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FAILURE"))) == -1) + { + s_comment += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("TESTS PASSED\n")); + ret = 0; + } + else + { + s_comment += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("TESTS _NOT_ PASSED\n")); + ret = -1; + } + + std::cerr + << argv[0] + << std::endl + << rtl::OUStringToOString(s_comment, RTL_TEXTENCODING_ASCII_US).getStr() + << std::endl; + + return ret; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/cppuhelper/test/bootstrap/makefile.mk b/cppuhelper/test/bootstrap/makefile.mk new file mode 100644 index 000000000000..59db7c00e611 --- /dev/null +++ b/cppuhelper/test/bootstrap/makefile.mk @@ -0,0 +1,61 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org 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 version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +PRJ := ..$/.. +PRJNAME := cppuhelper +TARGET := bootstrap.test + + +ENABLE_EXCEPTIONS := TRUE +NO_BSYMBOLIC := TRUE +USE_DEFFILE := TRUE + + +.INCLUDE : settings.mk + + +.IF "$(GUI)"=="UNX" || "$(GUI)"=="MAC" +PURPENVHELPERLIB := -luno_purpenvhelper$(COMID) + +.ELSE +PURPENVHELPERLIB := $(LIBPRE) ipurpenvhelper$(UDK_MAJOR)$(COMID).lib + +.ENDIF + + +APP1TARGET := $(TARGET) +APP1OBJS := $(OBJ)$/bootstrap.test.obj +APP1STDLIBS := $(CPPUHELPERLIB) $(CPPULIB) $(SALLIB) + +SHL1TARGET := testenv_uno_uno +SHL1IMPLIB := i$(SHL1TARGET) +SHL1OBJS := $(SLO)$/TestEnv.obj +SHL1STDLIBS := $(PURPENVHELPERLIB) $(SALHELPERLIB) $(SALLIB) +SHL1DEF := TestEnv.def + + +.INCLUDE : target.mk diff --git a/cppuhelper/test/cfg_data/instance/uno/components.xml b/cppuhelper/test/cfg_data/instance/uno/components.xml new file mode 100644 index 000000000000..b0ea5ce3b291 --- /dev/null +++ b/cppuhelper/test/cfg_data/instance/uno/components.xml @@ -0,0 +1,76 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<components cfg:package="uno" + xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" + xmlns:cfg="http://openoffice.org/2000/registry/instance" + xmlns="http://openoffice.org/2000/uno/Components"> + + +<services cfg:type="set" cfg:element-type="service"> + + <service cfg:name="com.sun.star.script.Converter"> + <available-implementations cfg:type="string" cfg:derivedBy="list"> + com.sun.star.comp.stoc.TypeConverter + </available-implementations> + </service> + + <service cfg:name="com.sun.star.bootstrap.TestComponent0"> + <available-implementations cfg:type="string" cfg:derivedBy="list"> + com.sun.star.comp.bootstrap.TestComponent0 + </available-implementations> + <context-properties cfg:type="set" cfg:element-type="cfg:any"> + <cfg:any cfg:name="serviceprop0" cfg:type="int">13</cfg:any> + <cfg:any cfg:name="serviceprop1" cfg:type="string">value of serviceprop1</cfg:any> + </context-properties> + </service> + +</services> + + +<implementations cfg:type="set" cfg:element-type="implementation"> + + <implementation cfg:name="com.sun.star.comp.stoc.TypeConverter"> + <activator cfg:type="string">com.sun.star.loader.SharedLibrary</activator> + <url cfg:type="string">tcv.dll</url> + <supported-services cfg:type="string" cfg:derivedBy="list">com.sun.star.script.Converter</supported-services> + </implementation> + + <implementation cfg:name="com.sun.star.comp.bootstrap.TestComponent0"> + <activator cfg:type="string">com.sun.star.loader.SharedLibrary</activator> + <url cfg:type="string">cfg_test.dll</url> + <supported-services cfg:type="string" cfg:derivedBy="list">com.sun.star.bootstrap.TestComponent0</supported-services> + <context-properties cfg:type="set" cfg:element-type="cfg:any"> + <cfg:any cfg:name="implprop0" cfg:type="int">15</cfg:any> + <cfg:any cfg:name="implprop1" cfg:type="string">value of implprop1</cfg:any> + </context-properties> + </implementation> + +</implementations> + + +<singletons cfg:type="set" cfg:element-type="singleton"> + + <singleton cfg:name="com.sun.star.script.theConverter"> + <used-service cfg:type="string">com.sun.star.script.Converter</used-service> + </singleton> + + <singleton cfg:name="com.sun.star.bootstrap.theTestComponent0"> + <used-service cfg:type="string">com.sun.star.bootstrap.TestComponent0</used-service> + <initial-arguments cfg:type="set" cfg:element-type="cfg:any"> + <cfg:any cfg:name="0" cfg:type="string">first argument</cfg:any> + <cfg:any cfg:name="1" cfg:type="string">second argument</cfg:any> + <cfg:any cfg:name="2" cfg:type="string">third argument</cfg:any> + </initial-arguments> + </singleton> + +</singletons> + + +<global-context-properties cfg:type="set" cfg:element-type="cfg:any"> + + <cfg:any cfg:name="TestValue" cfg:type="int">5</cfg:any> + +</global-context-properties> + + +</components> diff --git a/cppuhelper/test/cfg_data/template/uno/components.xml b/cppuhelper/test/cfg_data/template/uno/components.xml new file mode 100644 index 000000000000..5ab04d030fb3 --- /dev/null +++ b/cppuhelper/test/cfg_data/template/uno/components.xml @@ -0,0 +1,24 @@ +<?xml version="1.0" encoding="utf-8"?> + +<components cfg:package="uno" + xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" + xmlns:cfg="http://openoffice.org/2000/registry/instance"> + +<service> + <available-implementations cfg:type="string" cfg:derivedBy="list"/> + <context-properties cfg:type="set" cfg:element-type="cfg:any"/> +</service> + +<implementation> + <activator cfg:type="string"/> + <url cfg:type="string"/> + <supported-services cfg:type="string" cfg:derivedBy="list"/> + <context-properties cfg:type="set" cfg:element-type="cfg:any"/> +</implementation> + +<singleton> + <used-service cfg:type="string"/> + <initial-arguments cfg:type="set" cfg:element-type="cfg:any"/> +</singleton> + +</components> diff --git a/cppuhelper/test/cfg_test.cxx b/cppuhelper/test/cfg_test.cxx new file mode 100644 index 000000000000..dfee341e5109 --- /dev/null +++ b/cppuhelper/test/cfg_test.cxx @@ -0,0 +1,306 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_cppuhelper.hxx" + +// starting the executable: +// -env:UNO_CFG_URL=local;<absolute_path>..\\..\\test\\cfg_data;<absolute_path>\\cfg_update +// -env:UNO_TYPES=cpputest.rdb + +#include <sal/main.h> + +#include <stdio.h> + +#include <rtl/strbuf.hxx> + +#include <cppuhelper/implementationentry.hxx> +#include <cppuhelper/bootstrap.hxx> +#include <cppuhelper/implbase2.hxx> + +#include <com/sun/star/lang/XMultiComponentFactory.hpp> +#include <com/sun/star/lang/XInitialization.hpp> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/lang/XComponent.hpp> + +#include <com/sun/star/registry/XImplementationRegistration.hpp> + +#define OUSTR(x) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(x) ) + + +using namespace ::cppu; +using namespace ::rtl; +using namespace ::osl; +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; + +namespace cfg_test +{ + +//-------------------------------------------------------------------------------------------------- +static Sequence< OUString > impl0_getSupportedServiceNames() +{ + OUString str( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.bootstrap.TestComponent0") ); + return Sequence< OUString >( &str, 1 ); +} +//-------------------------------------------------------------------------------------------------- +static OUString impl0_getImplementationName() +{ + return OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.bootstrap.TestComponent0") ); +} +//-------------------------------------------------------------------------------------------------- +static Sequence< OUString > impl1_getSupportedServiceNames() +{ + OUString str( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.bootstrap.TestComponent1") ); + return Sequence< OUString >( &str, 1 ); +} +//-------------------------------------------------------------------------------------------------- +static OUString impl1_getImplementationName() +{ + return OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.bootstrap.TestComponent1") ); +} + +//================================================================================================== +class ServiceImpl0 + : public WeakImplHelper2< lang::XServiceInfo, lang::XInitialization > +{ + Reference< XComponentContext > m_xContext; + +public: + ServiceImpl0( Reference< XComponentContext > const & xContext ) SAL_THROW( () ); + + // XInitialization + virtual void SAL_CALL initialize( const Sequence< Any >& rArgs ) throw (Exception, RuntimeException); + + // XServiceInfo + virtual Sequence< OUString > SAL_CALL getSupportedServiceNames() throw (RuntimeException); + virtual OUString SAL_CALL getImplementationName() throw (RuntimeException); + virtual sal_Bool SAL_CALL supportsService( const OUString & rServiceName ) throw (RuntimeException); +}; +//__________________________________________________________________________________________________ +ServiceImpl0::ServiceImpl0( Reference< XComponentContext > const & xContext ) SAL_THROW( () ) + : m_xContext( xContext ) +{ + sal_Int32 n; + OUString val; + + // service properties + OSL_VERIFY( m_xContext->getValueByName( + OUSTR("/services/com.sun.star.bootstrap.TestComponent0/context-properties/serviceprop0") ) >>= n ); + OSL_VERIFY( n == 13 ); + OSL_VERIFY( m_xContext->getValueByName( + OUSTR("/services/com.sun.star.bootstrap.TestComponent0/context-properties/serviceprop1") ) >>= val ); + OSL_VERIFY( val.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("value of serviceprop1") ) ); + // impl properties + OSL_VERIFY( m_xContext->getValueByName( + OUSTR("/implementations/com.sun.star.comp.bootstrap.TestComponent0/context-properties/implprop0") ) >>= n ); + OSL_VERIFY( n == 15 ); + OSL_VERIFY( m_xContext->getValueByName( + OUSTR("/implementations/com.sun.star.comp.bootstrap.TestComponent0/context-properties/implprop1") ) >>= val ); + OSL_VERIFY( val.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("value of implprop1") ) ); +} +// XInitialization +//__________________________________________________________________________________________________ +void ServiceImpl0::initialize( const Sequence< Any >& rArgs ) + throw (Exception, RuntimeException) +{ + // check args + OUString val; + OSL_VERIFY( rArgs.getLength() == 3 ); + OSL_VERIFY( rArgs[ 0 ] >>= val ); + OSL_VERIFY( val.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("first argument") ) ); + OSL_VERIFY( rArgs[ 1 ] >>= val ); + OSL_VERIFY( val.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("second argument") ) ); + OSL_VERIFY( rArgs[ 2 ] >>= val ); + OSL_VERIFY( val.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("third argument") ) ); +} +// XServiceInfo +//__________________________________________________________________________________________________ +OUString ServiceImpl0::getImplementationName() + throw(::com::sun::star::uno::RuntimeException) +{ + return impl0_getImplementationName(); +} +//__________________________________________________________________________________________________ +Sequence< OUString > ServiceImpl0::getSupportedServiceNames() + throw(::com::sun::star::uno::RuntimeException) +{ + return impl0_getSupportedServiceNames(); +} +//__________________________________________________________________________________________________ +sal_Bool ServiceImpl0::supportsService( const OUString & rServiceName ) + throw(::com::sun::star::uno::RuntimeException) +{ + const Sequence< OUString > & rSNL = getSupportedServiceNames(); + const OUString * pArray = rSNL.getConstArray(); + for ( sal_Int32 nPos = rSNL.getLength(); nPos--; ) + { + if (pArray[nPos] == rServiceName) + return sal_True; + } + return sal_False; +} + +//================================================================================================== +class ServiceImpl1 : public ServiceImpl0 +{ +public: + inline ServiceImpl1( Reference< XComponentContext > const & xContext ) SAL_THROW( () ) + : ServiceImpl0( xContext ) + {} + + // XServiceInfo + virtual Sequence< OUString > SAL_CALL getSupportedServiceNames() throw (RuntimeException); + virtual OUString SAL_CALL getImplementationName() throw (RuntimeException); +}; +//__________________________________________________________________________________________________ +OUString ServiceImpl1::getImplementationName() + throw(::com::sun::star::uno::RuntimeException) +{ + return impl1_getImplementationName(); +} +//__________________________________________________________________________________________________ +Sequence< OUString > ServiceImpl1::getSupportedServiceNames() + throw(::com::sun::star::uno::RuntimeException) +{ + return impl1_getSupportedServiceNames(); +} + +//================================================================================================== +static Reference< XInterface > SAL_CALL ServiceImpl0_create( + Reference< XComponentContext > const & xContext ) + SAL_THROW( (Exception) ) +{ + return (OWeakObject *)new ServiceImpl0( xContext ); +} +//================================================================================================== +static Reference< XInterface > SAL_CALL ServiceImpl1_create( + Reference< XComponentContext > const & xContext ) + SAL_THROW( (Exception) ) +{ + return (OWeakObject *)new ServiceImpl1( xContext ); +} + +} // namespace cfg_test + +static struct ImplementationEntry g_entries[] = +{ + { + ::cfg_test::ServiceImpl0_create, ::cfg_test::impl0_getImplementationName, + ::cfg_test::impl0_getSupportedServiceNames, createSingleComponentFactory, + 0, 0 + }, + { + ::cfg_test::ServiceImpl1_create, ::cfg_test::impl1_getImplementationName, + ::cfg_test::impl1_getSupportedServiceNames, createSingleComponentFactory, + 0, 0 + }, + { 0, 0, 0, 0, 0, 0 } +}; + +// component exports +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 ) +{ + return component_writeInfoHelper( + pServiceManager, pRegistryKey, g_entries ); +} +//================================================================================================== +void * SAL_CALL component_getFactory( + const sal_Char * pImplName, void * pServiceManager, void * pRegistryKey ) +{ + return component_getFactoryHelper( + pImplName, pServiceManager, pRegistryKey , g_entries ); +} +} + + +//################################################################################################## +//################################################################################################## +//################################################################################################## + +SAL_IMPLEMENT_MAIN() +{ + try + { + Reference< XComponentContext > xContext( defaultBootstrap_InitialComponentContext() ); + Reference< lang::XMultiComponentFactory > xMgr( xContext->getServiceManager() ); + + // show what is in context + xContext->getValueByName( OUSTR("dump_maps") ); + + sal_Int32 n(0); + OSL_VERIFY( xContext->getValueByName( OUSTR("/global-context-properties/TestValue") ) >>= n ); + ::fprintf( stderr, "> n=%d\n", n ); + + Reference< XInterface > x; + OSL_VERIFY( !(xContext->getValueByName( OUSTR("/singletons/my_converter") ) >>= x) ); + OSL_VERIFY( xContext->getValueByName( OUSTR("/singletons/com.sun.star.script.theConverter") ) >>= x ); + OSL_VERIFY( xContext->getValueByName( OUSTR("/singletons/com.sun.star.bootstrap.theTestComponent0") ) >>= x ); + + ::fprintf( stderr, "> registering service...\n"); +#if defined(SAL_W32) || defined(SAL_OS2) + OUString libName( OUSTR("cfg_test.dll") ); +#elif defined(SAL_UNX) + OUString libName( OUSTR("libcfg_test.so") ); +#endif + Reference< registry::XImplementationRegistration > xImplReg( xMgr->createInstanceWithContext( + OUSTR("com.sun.star.registry.ImplementationRegistration"), xContext ), UNO_QUERY ); + OSL_ENSURE( xImplReg.is(), "### no impl reg!" ); + xImplReg->registerImplementation( + OUSTR("com.sun.star.loader.SharedLibrary"), libName, + Reference< registry::XSimpleRegistry >() ); + + OSL_VERIFY( (x = xMgr->createInstanceWithContext( OUSTR("com.sun.star.bootstrap.TestComponent0"), xContext )).is() ); + OSL_VERIFY( (x = xMgr->createInstanceWithContext( OUSTR("com.sun.star.bootstrap.TestComponent1"), xContext )).is() ); + + Reference< lang::XComponent > xComp( xContext, UNO_QUERY ); + if (xComp.is()) + { + xComp->dispose(); + } + return 0; + } + catch (Exception & exc) + { + OString str( OUStringToOString( exc.Message, RTL_TEXTENCODING_ASCII_US ) ); + ::fprintf( stderr, "# caught exception: %s\n", str.getStr() ); + return 1; + } +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/cppuhelper/test/helpertest.idl b/cppuhelper/test/helpertest.idl new file mode 100644 index 000000000000..e78629ab5313 --- /dev/null +++ b/cppuhelper/test/helpertest.idl @@ -0,0 +1,84 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _TEST_CPPUTEST_IDL_ +#define _TEST_CPPUTEST_IDL_ + +#include <com/sun/star/uno/XInterface.idl> +#include <com/sun/star/uno/TypeClass.idl> + +module test +{ + +interface A : com::sun::star::uno::XInterface +{ + string a(); +}; + +interface BA : A +{ + string ba(); +}; + +interface CA : A +{ + string ca(); +}; + +interface DBA : BA +{ + string dba(); +}; + +interface E : com::sun::star::uno::XInterface +{ + string e(); +}; + +interface FE : E +{ + string fe(); +}; + +interface G : com::sun::star::uno::XInterface +{ + string g(); + string a(); +}; + +interface H : com::sun::star::uno::XInterface +{ + string h(); +}; +interface I : com::sun::star::uno::XInterface +{ + string i(); +}; + +}; //module test + +#endif diff --git a/cppuhelper/test/loader/loader.test.cxx b/cppuhelper/test/loader/loader.test.cxx new file mode 100644 index 000000000000..53d5d96ac175 --- /dev/null +++ b/cppuhelper/test/loader/loader.test.cxx @@ -0,0 +1,208 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "sal/main.h" +#include <cppuhelper/shlib.hxx> +#include <cppuhelper/implbase1.hxx> +#include <cppu/EnvDcp.hxx> + +#include "../testcmp/TestComponent.hxx" + +#include <iostream> +#include <cstring> + +#ifndef SAL_DLLPREFIX +# define SAL_DLLPREFIX "" +#endif + + +using namespace ::com::sun::star; + + +class MyKey : public cppu::WeakImplHelper1<registry::XRegistryKey> + +{ +public: + virtual rtl::OUString SAL_CALL getKeyName() throw (uno::RuntimeException) { return rtl::OUString(); }; + + // Methods + virtual sal_Bool SAL_CALL isReadOnly( ) throw (registry::InvalidRegistryException, uno::RuntimeException) {return sal_False;}; + virtual sal_Bool SAL_CALL isValid( ) throw (uno::RuntimeException) {return sal_False;}; + virtual registry::RegistryKeyType SAL_CALL getKeyType( const rtl::OUString& /*rKeyName*/ ) throw (registry::InvalidRegistryException, uno::RuntimeException) {return registry::RegistryKeyType_KEY;}; + virtual registry::RegistryValueType SAL_CALL getValueType( ) throw (registry::InvalidRegistryException, uno::RuntimeException) {return registry::RegistryValueType_NOT_DEFINED;}; + virtual sal_Int32 SAL_CALL getLongValue( ) throw (registry::InvalidRegistryException, registry::InvalidValueException, uno::RuntimeException) {return 0;}; + virtual void SAL_CALL setLongValue( sal_Int32 /*value*/ ) throw (registry::InvalidRegistryException, uno::RuntimeException) {}; + virtual uno::Sequence< sal_Int32 > SAL_CALL getLongListValue( ) throw (registry::InvalidRegistryException, registry::InvalidValueException, uno::RuntimeException) { return uno::Sequence<sal_Int32>(); }; + virtual void SAL_CALL setLongListValue( const uno::Sequence< sal_Int32 >& /*seqValue*/ ) throw (registry::InvalidRegistryException, uno::RuntimeException) {}; + virtual rtl::OUString SAL_CALL getAsciiValue( ) throw (registry::InvalidRegistryException, registry::InvalidValueException, uno::RuntimeException) {return rtl::OUString();}; + virtual void SAL_CALL setAsciiValue( const rtl::OUString& /*value*/ ) throw (registry::InvalidRegistryException, uno::RuntimeException) {}; + virtual uno::Sequence< rtl::OUString > SAL_CALL getAsciiListValue( ) throw (registry::InvalidRegistryException, registry::InvalidValueException, uno::RuntimeException) {return uno::Sequence<rtl::OUString>();}; + virtual void SAL_CALL setAsciiListValue( const uno::Sequence< rtl::OUString >& /*seqValue*/ ) throw (registry::InvalidRegistryException, uno::RuntimeException) {}; + virtual rtl::OUString SAL_CALL getStringValue( ) throw (registry::InvalidRegistryException, registry::InvalidValueException, uno::RuntimeException) {return rtl::OUString();}; + virtual void SAL_CALL setStringValue( const rtl::OUString& /*value*/ ) throw (registry::InvalidRegistryException, uno::RuntimeException) {}; + virtual uno::Sequence< rtl::OUString > SAL_CALL getStringListValue( ) throw (registry::InvalidRegistryException, registry::InvalidValueException, uno::RuntimeException) {return uno::Sequence<rtl::OUString>();}; + virtual void SAL_CALL setStringListValue( const uno::Sequence< rtl::OUString >& /*seqValue*/ ) throw (registry::InvalidRegistryException, uno::RuntimeException) {}; + virtual uno::Sequence< sal_Int8 > SAL_CALL getBinaryValue( ) throw (registry::InvalidRegistryException, registry::InvalidValueException, uno::RuntimeException) {return uno::Sequence<sal_Int8>();}; + virtual void SAL_CALL setBinaryValue( const uno::Sequence< sal_Int8 >& /*value*/ ) throw (registry::InvalidRegistryException, uno::RuntimeException) {}; + virtual uno::Reference< registry::XRegistryKey > SAL_CALL openKey( const rtl::OUString& /*aKeyName*/ ) throw (registry::InvalidRegistryException, uno::RuntimeException) {return uno::Reference<registry::XRegistryKey>();}; + virtual uno::Reference< registry::XRegistryKey > SAL_CALL createKey( const rtl::OUString& /*aKeyName*/ ) throw (registry::InvalidRegistryException, uno::RuntimeException) {return uno::Reference<registry::XRegistryKey>();}; + virtual void SAL_CALL closeKey( ) throw (registry::InvalidRegistryException, uno::RuntimeException) {}; + virtual void SAL_CALL deleteKey( const rtl::OUString& /*rKeyName*/ ) throw (registry::InvalidRegistryException, uno::RuntimeException) {}; + virtual uno::Sequence< uno::Reference< registry::XRegistryKey > > SAL_CALL openKeys( ) throw (registry::InvalidRegistryException, uno::RuntimeException) {return uno::Sequence<uno::Reference<registry::XRegistryKey> >();}; + virtual uno::Sequence< rtl::OUString > SAL_CALL getKeyNames( ) throw (registry::InvalidRegistryException, uno::RuntimeException) {return uno::Sequence<rtl::OUString>();}; + virtual sal_Bool SAL_CALL createLink( const rtl::OUString& /*aLinkName*/, const rtl::OUString& /*aLinkTarget*/ ) throw (registry::InvalidRegistryException, uno::RuntimeException) {return sal_False;}; + virtual void SAL_CALL deleteLink( const rtl::OUString& /*rLinkName*/ ) throw (registry::InvalidRegistryException, uno::RuntimeException) {}; + virtual rtl::OUString SAL_CALL getLinkTarget( const rtl::OUString& /*rLinkName*/ ) throw (registry::InvalidRegistryException, uno::RuntimeException) {return rtl::OUString();}; + virtual rtl::OUString SAL_CALL getResolvedName( const rtl::OUString& /*aKeyName*/ ) throw (registry::InvalidRegistryException, uno::RuntimeException) {return rtl::OUString();}; +}; + + + +static rtl::OUString s_test__cppu_loadSharedLibComponentFactory(char const * pServicePurpose) +{ + rtl::OUString result; + + rtl::OUString servicePurpose = rtl::OUString(pServicePurpose, + rtl_str_getLength(pServicePurpose), + RTL_TEXTENCODING_ASCII_US); + + result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\ts_test__cppu_loadSharedLibComponentFactory ")); + result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("(\"")); + result += servicePurpose; + result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\") - ")); + + try { + uno::Reference<uno::XInterface> xObject( + cppu::loadSharedLibComponentFactory( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SAL_DLLPREFIX "TestComponent.uno" SAL_DLLEXTENSION)), + rtl::OUString(), + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("impl.test.TestComponent")) + servicePurpose, + uno::Reference<lang::XMultiServiceFactory>(), + uno::Reference<registry::XRegistryKey>()) + ); + + rtl::OUString envDcp_purpose(cppu::EnvDcp::getPurpose(g_envDcp)); + if (envDcp_purpose == servicePurpose) + result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("passed\n")); + + else + { + result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FAILED - got: \"")); + result += envDcp_purpose; + result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\"\n")); + } + } + catch(uno::Exception & exception) { + result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FAILED - got: \"")); + result += exception.Message; + result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\"\n")); + } + + return result; +} + +static rtl::OUString s_test__cppu_writeSharedLibComponentInfo(char const * pServicePurpose) +{ + rtl::OUString result; + + rtl::OUString servicePurpose = rtl::OUString(pServicePurpose, + rtl_str_getLength(pServicePurpose), + RTL_TEXTENCODING_ASCII_US); + + result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\ts_test__cppu_writeSharedLibComponentInfo ")); + result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("(\"")); + result += servicePurpose; + result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\") - ")); + + char buff[256]; + strcpy(buff, "TestComponent.uno="); + strcat(buff, pServicePurpose); + + putenv(buff); + + try { + cppu::writeSharedLibComponentInfo( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SAL_DLLPREFIX "TestComponent.uno" SAL_DLLEXTENSION)), + rtl::OUString(), + uno::Reference<lang::XMultiServiceFactory>(), + uno::Reference<registry::XRegistryKey>(new MyKey) + ); + + rtl::OUString envDcp_purpose(cppu::EnvDcp::getPurpose(g_envDcp)); + if (envDcp_purpose == servicePurpose) + result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("passed\n")); + + else + { + result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FAILED - got: \"")); + result += envDcp_purpose; + result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\"\n")); + } + } + catch(uno::Exception & exception) { + result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FAILED - got: \"")); + result += exception.Message; + result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\"\n")); + } + + return result; +} + + +SAL_IMPLEMENT_MAIN_WITH_ARGS(/*argc*/, argv) +{ + int result = 0; + + rtl::OUString message; + + message += rtl::OUString(argv[0], rtl_str_getLength(argv[0]), RTL_TEXTENCODING_ASCII_US); + message += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\n")); + + message += s_test__cppu_loadSharedLibComponentFactory(":unsafe"); + message += s_test__cppu_loadSharedLibComponentFactory(":affine"); + message += s_test__cppu_loadSharedLibComponentFactory(""); + + message += s_test__cppu_writeSharedLibComponentInfo(":unsafe"); + message += s_test__cppu_writeSharedLibComponentInfo(":affine"); + message += s_test__cppu_writeSharedLibComponentInfo(""); + + if (message.indexOf(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FAILED"))) == -1) + message += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("TESTS PASSED\n")); + + else + { + message += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("TESTS _NOT_ PASSED\n")); + result = -1; + } + + std::cout << rtl::OUStringToOString(message, RTL_TEXTENCODING_ASCII_US).getStr(); + + return result; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/cppuhelper/test/loader/makefile.mk b/cppuhelper/test/loader/makefile.mk new file mode 100644 index 000000000000..4816dcb47e36 --- /dev/null +++ b/cppuhelper/test/loader/makefile.mk @@ -0,0 +1,52 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org 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 version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +PRJ := ..$/.. +PRJNAME := cppuhelper +TARGET := loader.test + + +ENABLE_EXCEPTIONS := TRUE +NO_BSYMBOLIC := TRUE +USE_DEFFILE := TRUE + +.INCLUDE : settings.mk + +ENVINCPRE := -I$(OUT)$/inc$/$(TARGET) + +APP1TARGET := $(TARGET) +APP1OBJS := $(OBJ)$/loader.test.obj +.IF "$(GUI)"=="WNT" +APP1STDLIBS := iTestComponent.uno.lib +.ELSE +APP1STDLIBS := -lTestComponent.uno + +.ENDIF + +APP1STDLIBS += $(CPPUHELPERLIB) $(CPPULIB) $(SALLIB) + +.INCLUDE : target.mk diff --git a/cppuhelper/test/makefile.mk b/cppuhelper/test/makefile.mk new file mode 100644 index 000000000000..2746b3f07c1c --- /dev/null +++ b/cppuhelper/test/makefile.mk @@ -0,0 +1,168 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org 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 version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* +PRJ=.. + +PRJNAME=cppuhelper +TARGET=testhelper +ENABLE_EXCEPTIONS=TRUE +USE_DEFFILE=TRUE + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk + +# --- Files -------------------------------------------------------- + +UNOUCRDEP= $(SOLARBINDIR)$/udkapi.rdb +UNOUCRRDB= $(SOLARBINDIR)$/udkapi.rdb +UNOUCROUT= $(OUT)$/inc$/test +INCPRE+= $(OUT)$/inc$/test + +OBJFILES= \ + $(OBJ)$/testhelper.obj \ + $(OBJ)$/testpropshlp.obj \ + $(OBJ)$/testidlclass.obj \ + $(OBJ)$/testproptyphlp.obj \ + $(OBJ)$/testimplhelper.obj \ + $(OBJ)$/testcontainer.obj + +APP1TARGET=$(TARGET) +APP1OBJS=$(OBJFILES) + +APP1STDLIBS+= \ + $(CPPULIB) \ + $(CPPUHELPERLIB) \ + $(SALLIB) + +APP1DEF= $(MISC)$/$(APP1TARGET).def + +############################################# + +APP2OBJS = $(OBJ)$/testdefaultbootstrapping.obj +APP2STDLIBS += $(CPPUHELPERLIB) $(CPPULIB) $(SALLIB) +APP2TARGET = testdefaultbootstrapping + +############################################# + +SLOFILES= \ + $(SLO)$/cfg_test.obj +LIB1TARGET=$(SLB)$/cfg_test.lib +LIB1OBJFILES=$(SLOFILES) + + +APP3OBJS = $(OBJ)$/cfg_test.obj +APP3STDLIBS += $(CPPUHELPERLIB) $(CPPULIB) $(SALLIB) +APP3TARGET = test_cfg + +############################################# + +ALLIDLFILES:= helpertest.idl + +# --- Targets ------------------------------------------------------ + +.IF "$(depend)" == "" +ALL: $(BIN)$/cpputest.rdb \ + unoheader \ + $(BIN)$/testrc \ + $(BIN)$/testdefaultbootstrapping.pl \ + ALLTAR \ + $(BIN)$/$(APP2TARGET).bin \ + $(BIN)$/$(APP2TARGET).Bin \ + $(BIN)$/$(APP2TARGET).Exe + +.IF "$(GUI)"=="UNX" +ALL: $(BIN)$/$(APP2TARGET).exe + +$(BIN)$/$(APP2TARGET).exe : $(APP2TARGETN) + cp $(APP2TARGETN) $@ + +.ENDIF + + +$(BIN)$/$(APP2TARGET).bin : $(APP2TARGETN) + cp $(APP2TARGETN) $@ + +$(BIN)$/$(APP2TARGET).Bin : $(APP2TARGETN) + cp $(APP2TARGETN) $@ + +$(BIN)$/$(APP2TARGET).Exe : $(APP2TARGETN) + cp $(APP2TARGETN) $@ + +.ELSE +ALL: ALLDEP +.ENDIF + +.INCLUDE : target.mk + +CPPUMAKERFLAGS = +.IF "$(COM)" == "MSC" +CPPUMAKERFLAGS = -L +.ENDIF + +TYPES:=test.A;test.BA;test.CA;test.DBA;test.E;test.FE;test.G;test.H;test.I +HELPERTYPES:=com.sun.star.uno.XReference;com.sun.star.uno.XAdapter;com.sun.star.uno.XAggregation;com.sun.star.uno.XWeak;com.sun.star.lang.XComponent;com.sun.star.lang.XTypeProvider;com.sun.star.lang.XEventListener;com.sun.star.lang.XSingleServiceFactory;com.sun.star.lang.XMultiServiceFactory;com.sun.star.registry.XRegistryKey;com.sun.star.lang.XInitialization;com.sun.star.lang.XServiceInfo;com.sun.star.loader.XImplementationLoader;com.sun.star.lang.IllegalAccessException;com.sun.star.beans.XVetoableChangeListener;com.sun.star.beans.XPropertySet;com.sun.star.uno.XComponentContext +FACTORYTYPES:=com.sun.star.lang.XComponent;com.sun.star.registry.XSimpleRegistry;com.sun.star.lang.XInitialization;com.sun.star.lang.XMultiServiceFactory;com.sun.star.loader.XImplementationLoader;com.sun.star.registry.XImplementationRegistration;com.sun.star.container.XSet;com.sun.star.lang.XSingleServiceFactory;com.sun.star.lang.XSingleComponentFactory;com.sun.star.lang.XMultiComponentFactory + +.IF "$(OS)" == "WNT" || "$(OS)" == "OS2" +UNO_PATH := $(SOLARBINDIR) +UNO_OUT := $(OUT)$/bin +EXT_SO := .dll +.ELSE +UNO_PATH := $(SOLARLIBDIR) +UNO_OUT := $(OUT)$/lib +EXT_SO := .so +.ENDIF + +$(UNO_OUT)$/%$(EXT_SO): $(UNO_PATH)$/%$(EXT_SO) + $(COPY) $^ $@ + +$(BIN)$/cpputest.rdb: $(ALLIDLFILES) $(UNO_OUT)$/invocadapt.uno$(EXT_SO) $(UNO_OUT)$/bootstrap.uno$(EXT_SO) + $(IDLC) -I$(PRJ) -I$(SOLARIDLDIR) -O$(BIN) $(ALLIDLFILES) + $(REGMERGE) $@ /UCR $(BIN)$/{$(?:f:s/.idl/.urd/)} + $(REGMERGE) $@ / $(UNOUCRRDB) + $(REGCOMP) -register -r $@ -c reflection.uno$(DLLPOST) + $(TOUCH) $@ + +unoheader: $(BIN)$/cpputest.rdb + $(CPPUMAKER) $(CPPUMAKERFLAGS) -BUCR -O$(UNOUCROUT) -T"$(TYPES);$(HELPERTYPES)" $(BIN)$/cpputest.rdb + $(CPPUMAKER) $(CPPUMAKERFLAGS) -BUCR -O$(UNOUCROUT) -T"$(FACTORYTYPES)" $(BIN)$/cpputest.rdb + + +$(BIN)$/testdefaultbootstrapping.pl: testdefaultbootstrapping.pl + cp testdefaultbootstrapping.pl $@ + +$(BIN)$/testrc: makefile.mk +.IF "$(GUI)"=="WNT" + echo [Tests] > $@ + echo TestKey1=com.sun.star.uno.NamingService.rdb >> $@ +.ELSE + echo '[Tests]' > $@ + echo 'TestKey1=file:///'$(PWD)/$(BIN)'/com.sun.star.uno.NamingService.rdb' >> $@ +.ENDIF + + + diff --git a/cppuhelper/test/testcmp/TestComponent.cxx b/cppuhelper/test/testcmp/TestComponent.cxx new file mode 100644 index 000000000000..83bdac1a47a2 --- /dev/null +++ b/cppuhelper/test/testcmp/TestComponent.cxx @@ -0,0 +1,250 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_cppuhelper.hxx" + + +#define CPPUHELPER_TEST_COMPONENT_IMPL +#include "TestComponent.hxx" + + +#include <string.h> + +#include "osl/thread.h" + +#include "cppuhelper/implbase1.hxx" +#include "cppuhelper/implementationentry.hxx" + +#include "com/sun/star/lang/XMultiComponentFactory.hpp" +#include "com/sun/star/lang/XServiceInfo.hpp" + +#include "com/sun/star/uno/XComponentContext.hpp" + + +#include "cppu/EnvDcp.hxx" + +#include <uno/environment.hxx> + +using namespace ::com::sun::star; + + +#define LOG_LIFECYCLE_TestComponent +#ifdef LOG_LIFECYCLE_TestComponent +# include <iostream> +# define LOG_LIFECYCLE_TestComponent_emit(x) x + +#else +# define LOG_LIFECYCLE_TestComponent_emit(x) + +#endif + + +class TestComponent: public cppu::WeakImplHelper1<lang::XServiceInfo> +{ + rtl::OUString m_implName; + +public: + static uno::Reference<uno::XInterface> create( + uno::Reference<uno::XComponentContext> const & xCtx + ) + SAL_THROW((uno::Exception)); + + + static uno::Sequence<rtl::OUString> SAL_CALL getSupportedServiceNames_Static(); + + explicit TestComponent(uno::Reference<uno::XComponentContext> const & xCtx); + virtual ~TestComponent(); + + uno::Any SAL_CALL queryInterface(uno::Type const & rType ) throw (::com::sun::star::uno::RuntimeException); + void SAL_CALL release() throw (); + void SAL_CALL acquire() throw (); + + // lang::XServiceInfo + virtual rtl::OUString SAL_CALL getImplementationName() throw (uno::RuntimeException); + virtual sal_Bool SAL_CALL supportsService(rtl::OUString const & ServiceName) + throw (uno::RuntimeException); + virtual uno::Sequence<rtl::OUString> SAL_CALL getSupportedServiceNames() + throw (uno::RuntimeException); + +protected: + uno::Reference<uno::XComponentContext> m_xComponentContext; +}; + + +uno::Reference<uno::XInterface> SAL_CALL TestComponent::create( + uno::Reference<uno::XComponentContext> const & xCtx +) + SAL_THROW((uno::Exception)) +{ + try + { + return static_cast<cppu::OWeakObject *>(new TestComponent(xCtx)); + } + catch (std::bad_alloc &) + { + throw uno::RuntimeException(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("std::bad_alloc")), + uno::Reference<uno::XInterface>()); + } +} + +uno::Sequence<rtl::OUString> SAL_CALL TestComponent::getSupportedServiceNames_Static() +{ + uno::Sequence<rtl::OUString> serviceNames(1); + serviceNames[0] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.lang.ServiceInfo")); + + return serviceNames; +} + + +TestComponent::TestComponent(uno::Reference<uno::XComponentContext> const & xCtx) + : m_xComponentContext(xCtx) +{ + LOG_LIFECYCLE_TestComponent_emit(fprintf(stderr, "LIFE: %s -> %p\n", "TestComponent::TestComponent()", this)); +} + +TestComponent::~TestComponent() +{ + LOG_LIFECYCLE_TestComponent_emit(fprintf(stderr, "LIFE: %s -> %p\n", "TestComponent::~TestComponent", this)); +} + +rtl::OUString SAL_CALL TestComponent::getImplementationName() + throw (uno::RuntimeException) +{ + return m_implName; +} + +void SAL_CALL TestComponent::acquire() throw () +{ + cppu::WeakImplHelper1<lang::XServiceInfo>::acquire(); +} + +void SAL_CALL TestComponent::release() throw () +{ + cppu::WeakImplHelper1<lang::XServiceInfo>::release(); +} + +uno::Any SAL_CALL TestComponent::queryInterface(uno::Type const & rType ) throw (::com::sun::star::uno::RuntimeException) +{ + return cppu::WeakImplHelper1<lang::XServiceInfo>::queryInterface(rType); +} + +sal_Bool SAL_CALL TestComponent::supportsService(rtl::OUString const & ServiceName) + throw (uno::RuntimeException) +{ + uno::Sequence<rtl::OUString> serviceNames = getSupportedServiceNames_Static(); + + for (sal_Int32 n = 0; n < serviceNames.getLength(); ++n) + { + if (serviceNames[n] == ServiceName) + return true; + } + + return false; +} + +uno::Sequence<rtl::OUString> SAL_CALL TestComponent::getSupportedServiceNames() + throw (uno::RuntimeException) +{ + return getSupportedServiceNames_Static(); +} + +extern "C" sal_Bool SAL_CALL component_writeInfo( + void * /*serviceManager*/, + void * /*registryKey*/ +) +{ + g_envDcp = uno::Environment::getCurrent().getTypeName(); + + return true; +} + +extern "C" SAL_DLLPUBLIC_EXPORT void * SAL_CALL component_getFactory( + char const * pImplName, + void * /*serviceManager*/, + void * /*registryKey*/ +) +{ + g_envDcp = uno::Environment::getCurrent().getTypeName(); + + uno::Reference< lang::XSingleComponentFactory > xFactory; + + rtl::OUString uTmp(pImplName, rtl_str_getLength(pImplName), RTL_TEXTENCODING_ASCII_US); + + rtl::OUString uImplName(cppu::EnvDcp::getTypeName(uTmp)); + rtl::OUString cmpName(RTL_CONSTASCII_USTRINGPARAM("impl.test.TestComponent")); + + if (uImplName.equals(cmpName)) + { + xFactory = cppu::createSingleComponentFactory( + TestComponent::create, + uImplName, + TestComponent::getSupportedServiceNames_Static()); + + xFactory->acquire(); + } + + return xFactory.get(); +} + +extern "C" SAL_DLLPUBLIC_EXPORT void SAL_CALL component_getImplementationEnvironmentExt( + sal_Char const ** envTypeName, + uno_Environment ** /*ppEnv*/, + sal_Char const * pImplName, + uno_Environment * /*pSrcEnv*/ +) +{ + rtl::OString purpose; + + if (pImplName) // this is the purpose for a specified impl + { + rtl::OUString uImplName(pImplName, rtl_str_getLength(pImplName), RTL_TEXTENCODING_ASCII_US); + purpose = rtl::OUStringToOString(cppu::EnvDcp::getPurpose(uImplName), RTL_TEXTENCODING_ASCII_US); + } + + if (!purpose.getLength()) + { + char * pPurpose = getenv("TestComponent.uno"); + if (pPurpose) + purpose = rtl::OString(pPurpose); + } + + if (purpose.getLength() == 0) + *envTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME; + + else + { + char buff[256]; + strcpy(buff, CPPU_STRINGIFY(CPPU_ENV)); + strcat(buff, purpose.getStr()); + + *envTypeName = strdup(buff); + } +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/cppuhelper/test/testcmp/TestComponent.hxx b/cppuhelper/test/testcmp/TestComponent.hxx new file mode 100644 index 000000000000..7499628148f4 --- /dev/null +++ b/cppuhelper/test/testcmp/TestComponent.hxx @@ -0,0 +1,59 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef INCLUDED_cppuhelper_test_testcmp_TestComponent_hxx +#define INCLUDED_cppuhelper_test_testcmp_TestComponent_hxx + +#include <sal/types.h> +#include <rtl/ustring.hxx> + +#ifdef CPPUHELPER_TEST_COMPONENT_IMPL +# define CPPUHELPER_TEST_COMPONENT_EXPORT SAL_DLLPUBLIC_EXPORT + +#elif defined(CPPUHELPER_TEST_COMPONENT_LIB) +# define CPPUHELPER_TEST_COMPONENT_EXPORT extern + +#elif defined(__GNUC__) && defined(HAVE_GCC_VISIBILITY_FEATURE) +# define CPPUHELPER_TEST_COMPONENT_EXPORT extern __attribute__ ((weak)) + +#elif defined(__SUNPRO_CC) +# define CPPUHELPER_TEST_COMPONENT_EXPORT extern + extern rtl::OUString g_envDcp; +# pragma weak g_envDcp + +#else +# define CPPUHELPER_TEST_COMPONENT_EXPORT SAL_DLLPUBLIC_IMPORT + +#endif + +CPPUHELPER_TEST_COMPONENT_EXPORT rtl::OUString g_envDcp; + + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/cppuhelper/test/testcmp/TestComponent.uno.def b/cppuhelper/test/testcmp/TestComponent.uno.def new file mode 100755 index 000000000000..8c1906e67459 --- /dev/null +++ b/cppuhelper/test/testcmp/TestComponent.uno.def @@ -0,0 +1,11 @@ +HEAPSIZE 0 +EXPORTS + component_getImplementationEnvironmentExt; + component_getFactory; + component_writeInfo; + ?g_envDcp@@3VOUString@rtl@@A; + + + + + diff --git a/cppuhelper/test/testcmp/makefile.mk b/cppuhelper/test/testcmp/makefile.mk new file mode 100644 index 000000000000..24474b8abfa9 --- /dev/null +++ b/cppuhelper/test/testcmp/makefile.mk @@ -0,0 +1,49 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org 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 version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +PRJ := ..$/.. +PRJNAME := cppuhelper +TARGET := TestComponent.uno +ENABLE_EXCEPTIONS := TRUE + + +.INCLUDE: settings.mk + + +SHL1TARGET := $(TARGET) +SHL1OBJS := $(SLO)$/TestComponent.obj +SHL1STDLIBS := $(CPPUHELPERLIB) $(CPPULIB) $(SALHELPERLIB) $(SALLIB) +SHL1IMPLIB := i$(SHL1TARGET) +.IF "$(GUI)"=="WNT" +SHL1DEF := TestComponent.uno.def +.ELSE +DEF1NAME := $(SHL1TARGET) +.ENDIF + + +.INCLUDE: target.mk + diff --git a/cppuhelper/test/testcontainer.cxx b/cppuhelper/test/testcontainer.cxx new file mode 100644 index 000000000000..5665a762eaa0 --- /dev/null +++ b/cppuhelper/test/testcontainer.cxx @@ -0,0 +1,156 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_cppuhelper.hxx" +#include <osl/mutex.hxx> + +#include <cppuhelper/interfacecontainer.hxx> +#include <cppuhelper/implbase1.hxx> + +#include <com/sun/star/beans/XVetoableChangeListener.hpp> + +using namespace ::cppu; +using namespace ::osl; +using namespace ::com::sun::star::lang; +using namespace ::com::sun::star::beans; +using namespace ::com::sun::star::uno; + + +class TestListener : public WeakImplHelper1< XVetoableChangeListener > +{ +public: + // Methods + virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& /*Source*/ ) throw(::com::sun::star::uno::RuntimeException) + { + + } + + virtual void SAL_CALL vetoableChange( const ::com::sun::star::beans::PropertyChangeEvent& /*aEvent*/ ) + throw(::com::sun::star::beans::PropertyVetoException, ::com::sun::star::uno::RuntimeException) + { + + } +}; + +void test_interfacecontainer() +{ + Mutex mutex; + + { + OInterfaceContainerHelper helper( mutex ); + + Reference< XVetoableChangeListener > r1 = new TestListener(); + Reference< XVetoableChangeListener > r2 = new TestListener(); + Reference< XVetoableChangeListener > r3 = new TestListener(); + + helper.addInterface( r1 ); + helper.addInterface( r2 ); + helper.addInterface( r3 ); + + helper.disposeAndClear( EventObject() ); + } + + { + OInterfaceContainerHelper helper( mutex ); + + Reference< XVetoableChangeListener > r1 = new TestListener(); + Reference< XVetoableChangeListener > r2 = new TestListener(); + Reference< XVetoableChangeListener > r3 = new TestListener(); + + helper.addInterface( r1 ); + helper.addInterface( r2 ); + helper.addInterface( r3 ); + + OInterfaceIteratorHelper iterator( helper ); + + while( iterator.hasMoreElements() ) + ((XVetoableChangeListener*)iterator.next())->vetoableChange( PropertyChangeEvent() ); + + helper.disposeAndClear( EventObject() ); + } + + { + OInterfaceContainerHelper helper( mutex ); + + Reference< XVetoableChangeListener > r1 = new TestListener(); + Reference< XVetoableChangeListener > r2 = new TestListener(); + Reference< XVetoableChangeListener > r3 = new TestListener(); + + helper.addInterface( r1 ); + helper.addInterface( r2 ); + helper.addInterface( r3 ); + + OInterfaceIteratorHelper iterator( helper ); + + ((XVetoableChangeListener*)iterator.next())->vetoableChange( PropertyChangeEvent() ); + iterator.remove(); + ((XVetoableChangeListener*)iterator.next())->vetoableChange( PropertyChangeEvent() ); + iterator.remove(); + ((XVetoableChangeListener*)iterator.next())->vetoableChange( PropertyChangeEvent() ); + iterator.remove(); + + OSL_ASSERT( helper.getLength() == 0 ); + helper.disposeAndClear( EventObject() ); + } + + { + OInterfaceContainerHelper helper( mutex ); + + Reference< XVetoableChangeListener > r1 = new TestListener(); + Reference< XVetoableChangeListener > r2 = new TestListener(); + Reference< XVetoableChangeListener > r3 = new TestListener(); + + helper.addInterface( r1 ); + helper.addInterface( r2 ); + helper.addInterface( r3 ); + + { + OInterfaceIteratorHelper iterator( helper ); + while( iterator.hasMoreElements() ) + { + Reference< XVetoableChangeListener > r = ((XVetoableChangeListener*)iterator.next()); + if( r == r1 ) + iterator.remove(); + } + } + OSL_ASSERT( helper.getLength() == 2 ); + { + OInterfaceIteratorHelper iterator( helper ); + while( iterator.hasMoreElements() ) + { + Reference< XVetoableChangeListener > r = ((XVetoableChangeListener*)iterator.next()); + OSL_ASSERT( r != r1 && ( r == r2 || r == r3 ) ); + } + } + + helper.disposeAndClear( EventObject() ); + } +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/cppuhelper/test/testdefaultbootstrapping.cxx b/cppuhelper/test/testdefaultbootstrapping.cxx new file mode 100644 index 000000000000..82172c26d838 --- /dev/null +++ b/cppuhelper/test/testdefaultbootstrapping.cxx @@ -0,0 +1,88 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_cppuhelper.hxx" + +#include <sal/main.h> + + + +#include <cstdio> + +#include <rtl/process.h> +#include <cppuhelper/bootstrap.hxx> + +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/uno/XComponentContext.hpp> + +using namespace ::cppu; +using namespace ::com::sun::star::lang; +using namespace ::com::sun::star::uno; +using namespace ::rtl; + + +SAL_IMPLEMENT_MAIN() +{ + sal_Bool result = sal_True; + + try { + Reference<XComponentContext> xComponentContext = defaultBootstrap_InitialComponentContext(); + + Reference<XMultiServiceFactory> smgr(xComponentContext->getServiceManager(), UNO_QUERY); + + for(sal_uInt32 i = 0; i < rtl_getAppCommandArgCount(); ++ i) { + OUString arg; + + rtl_getAppCommandArg(i, &arg.pData); + if (arg.getLength()) + { + Reference<XInterface> xInterface = smgr->createInstance(arg); + OString tmp = OUStringToOString(arg, RTL_TEXTENCODING_ASCII_US); +#if OSL_DEBUG_LEVEL > 1 + fprintf(stderr, "got the %s service %p\n", tmp.getStr(), xInterface.get()); +#endif + + result = result && (xInterface.get() != 0); + } + } + } + catch(Exception & exception) { + OString message = OUStringToOString(exception.Message, RTL_TEXTENCODING_ASCII_US); + + fprintf(stderr, "an exception occurred: %s\n", message.getStr()); + } + +#if OSL_DEBUG_LEVEL > 1 + OSL_TRACE("---------------------------------- %i", result); +#endif + + return result; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/cppuhelper/test/testdefaultbootstrapping.pl b/cppuhelper/test/testdefaultbootstrapping.pl new file mode 100644 index 000000000000..c1756e908529 --- /dev/null +++ b/cppuhelper/test/testdefaultbootstrapping.pl @@ -0,0 +1,277 @@ +: +eval 'exec perl -wS $0 ${1+"$@"}' + if 0; +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org 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 version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +# +# deliver.pl - copy from module output tree to solver +# + +my $progname = "testdefaultbootstrapping"; +my $defExeExt; + +if ($ENV{GUI} eq "WNT") { + %services = ( + 'com.sun.star.uno.NamingService' => 'namingservice.uno.dll', + 'com.sun.star.reflection.CoreReflection' => 'reflection.uno.dll', + 'com.sun.star.script.InvocationAdapterFactory' => 'invocadapt.uno.dll', + ); + + $defExeExt = ".exe"; + +} +else { + %services = ( + 'com.sun.star.uno.NamingService' => 'namingservice.uno.so', + 'com.sun.star.reflection.CoreReflection' => 'reflection.uno.so', + 'com.sun.star.script.InvocationAdapterFactory' => 'invocadapt.uno.so' + ); + + $defExeExt = ""; +} + +sub extendProgName($) { + my $_extension = shift; + my $_result; + + if ($ENV{GUI} eq "WNT") { + $_result = $progname . $_extension; + } + else { + $_result = $ENV{PWD} . "/" . $progname . $_extension; + } + + return $_result; +} + + +sub rmDefRDB() { + unlink $progname . "_services.rdb"; +} + + +sub unregisterService($){ + my $service_name = shift; + + my $rdb_name = $service_name . '.rdb'; + + unlink $rdb_name; + + return 1; +} + +sub testForServices($$$) { + my $_services = shift; + my $_pars = shift; + my $_testexe = shift; + + +# my $_rc = system 'echo', $_testexe, @{$_services}, $_pars; + my $_rc = system $_testexe, @{$_services}, $_pars; + + return $_rc >> 8; +} + + +sub registerService($$){ + my $service_lib = shift; + my $rdb_name = shift; + +# system 'echo', "regcomp -register -r " . $rdb_name . " -c $service_lib"; + my $rc = system "regcomp -register -r " . $rdb_name . " -c $service_lib"; + + + return ! ( $rc >> 8 ); +} + + + +my $state = 1; +my @allservices; +my $allservices_rdbs=""; +my $rc; +my $comment; +my $testexe; + + +sub registerServices() { + use Cwd; + + # ensure that services can not be instantiated + foreach $service ( keys %services ) { + # ensure that the current service is not reachable + unregisterService($service); + $rc = !testForServices([$service], "", $testexe); + if(!$rc) { + $comment = $comment . "\tcouldn't unregister service " . $service . "\n"; + $state = 0; + } + + + # register the service and ensure that it is reachable + $rc = registerService($services{$service}, $service . '.rdb'); + if(!$rc) { + $comment = $comment . "\tcouldn't register service " . $service . "\n"; + $state = 0; + } + + $rc = testForServices([$service], "-env:UNO_SERVICES=" . $service . ".rdb", $testexe); + if(!$rc) { + $comment = $comment . "\tcouldn't reach service " . $service . "\n"; + $state = 0; + } + + # memorize all services + if (length($allservices_rdbs)) { + $allservices_rdbs = $allservices_rdbs . " "; + } + $allservices_rdbs = $allservices_rdbs . "file://" . getcwd() . "/" . $service . ".rdb"; + push @allservices, $service; + } +} + +sub testIndirection() { + #test indirection + $rc = testForServices(['com.sun.star.uno.NamingService'], '-env:UNO_SERVICES=${testrc:Tests:TestKey1}', $testexe); + if (!$rc) { + $comment = $comment . "\tindirection test not passed\n"; + $state = 0; + } +} + + +sub testBeneathExe() { + my $service = 'com.sun.star.reflection.CoreReflection'; + my $_testexe; + + my @_exes = (extendProgName(".exe"), + extendProgName(".Exe"), + extendProgName(".bin"), + extendProgName(".Bin")); + + foreach $_testexe ( @_exes ) { + #test rdb found beneath executable + registerService($services{$service}, $progname . "_services.rdb"); + my $_rc = testForServices([$service], "", $_testexe); + if (!$_rc) { + $comment = $comment . "\tbeneath executable test not passed: " . $_testexe . "\n"; + $state = 0; + } + } +} + +sub testBeneathLib_rdb() { + my $_service = 'com.sun.star.uno.NamingService'; + + use UNO; + + my $_rdb_name; + + if ($ENV{GUI} eq "WNT") { + $_rdb_name = "UNO" . "_services.rdb"; + } + else { + $_rdb_name = "../lib/UNO" . "_services.rdb"; + } + + registerService($services{$_service}, $_rdb_name); + my $_rc = UNO::tryService($_service); + if (!$_rc) { + $comment = $comment . "\tbeneath lib test not passed\n"; + $state = 0; + } + unlink $_rdb_name; +} + +sub testBeneathLib_rc() { + my $_service = 'com.sun.star.uno.NamingService'; + + use UNO; + + my $_rc_name; + + if ($ENV{GUI} eq "WNT") { + $_rc_name = "UNO.ini"; + } + else { + $_rc_name = "../lib/UNOrc"; + } + + my $_rdb_name = "../lib/test.rdb"; + + my $_handle; + open $_handle, ">" . $_rc_name; + print $_handle "UNO_SERVICES=" . $_rdb_name . "\n"; + close $_handle; + + registerService($services{$_service}, $_rdb_name); + my $_rc = UNO::tryService($_service); + if (!$_rc) { + $comment = $comment . "\tbeneath lib rc test not passed\n"; + $state = 0; + } + unlink $_rdb_name; + unlink $_rc_name; +} + +sub testAllAvailable() { + # test that all services are reachable through different rdbs + # change the directory to ensure, that all paths become expanded + chdir ".."; + + $rc = testForServices(\@allservices, "-env:UNO_SERVICES=" . $allservices_rdbs, $testexe); + if (!$rc) { + $comment = $comment . "\tmulti rdb test not passed\n"; + $state = 0; + } +} + +$testexe = extendProgName($defExeExt); + +rmDefRDB(); +registerServices(); +#print "alls:", @allservices, $allservices_rdbs, "\n"; + +testIndirection(); +testBeneathExe(); +testBeneathLib_rc(); +testBeneathLib_rdb(); +testAllAvailable(); + +print "**************************\n"; +if($state) { + print "****** tests passed ******\n"; +} +else { + print "**** tests NOT passed ****\n"; + print "Commnent:\n", $comment, "\n"; +} +print "**************************\n"; + + + diff --git a/cppuhelper/test/testhelper.cxx b/cppuhelper/test/testhelper.cxx new file mode 100644 index 000000000000..431c3cb16251 --- /dev/null +++ b/cppuhelper/test/testhelper.cxx @@ -0,0 +1,110 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#if !defined(OSL_DEBUG_LEVEL) || OSL_DEBUG_LEVEL == 0 +# undef OSL_DEBUG_LEVEL +# define OSL_DEBUG_LEVEL 2 +#endif + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_cppuhelper.hxx" + +#include <sal/main.h> + +#include <stdio.h> +#include <rtl/ustrbuf.hxx> +#include <osl/diagnose.h> + +#include <cppuhelper/component_context.hxx> +#include <cppuhelper/servicefactory.hxx> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/registry/XSimpleRegistry.hpp> +#include <com/sun/star/registry/XImplementationRegistration.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/lang/XComponent.hpp> + +#include "testhelper.hxx" + +using namespace cppu; +using namespace com::sun::star::uno; +using namespace com::sun::star; +using namespace com::sun::star::lang; +using namespace com::sun::star::registry; + +using ::rtl::OUString; +using ::rtl::OString; +using ::rtl::OUStringToOString; + +SAL_IMPLEMENT_MAIN() +{ + try + { + Reference< XMultiComponentFactory > xMgr( createRegistryServiceFactory( + OUString( RTL_CONSTASCII_USTRINGPARAM("cpputest.rdb") ) ), UNO_QUERY ); + Reference< XComponentContext > xInitialContext; + OSL_VERIFY( Reference< beans::XPropertySet >( xMgr, UNO_QUERY )->getPropertyValue( + OUString( RTL_CONSTASCII_USTRINGPARAM("DefaultContext") ) ) >>= xInitialContext ); + + ContextEntry_Init aEntry; + aEntry.bLateInitService = false; + aEntry.name = OUString( RTL_CONSTASCII_USTRINGPARAM("bla, bla") ); + aEntry.value = makeAny( (sal_Int32)5 ); + Reference< XComponentContext > xContext( createComponentContext( &aEntry, 1, xInitialContext ) ); + OSL_ASSERT( xContext->getServiceManager() != xMgr ); // must be wrapped one + OSL_ASSERT( + Reference< beans::XPropertySet >( + xContext->getServiceManager(), UNO_QUERY )->getPropertyValue( + OUString( RTL_CONSTASCII_USTRINGPARAM("DefaultContext") ) ) != xInitialContext ); + + Reference< XMultiServiceFactory > x( xMgr, UNO_QUERY ); + test_ImplHelper( x ); + testPropertyTypeHelper(); + testidlclass( x ); + test_PropertySetHelper(); + test_interfacecontainer(); + + OSL_VERIFY( xContext->getValueByName( + OUString( RTL_CONSTASCII_USTRINGPARAM("bla, bla") ) ) == (sal_Int32)5 ); + OSL_VERIFY( ! xInitialContext->getValueByName( + OUString( RTL_CONSTASCII_USTRINGPARAM("bla, bla") ) ).hasValue() ); + Reference< XComponent >( xInitialContext, UNO_QUERY )->dispose(); + xMgr.clear(); + xContext.clear(); + xInitialContext.clear(); + } + catch (Exception & exc) + { + OString cstr_msg( OUStringToOString( exc.Message, RTL_TEXTENCODING_ASCII_US ) ); + OSL_ENSURE( ! "exception occurred: ", cstr_msg.getStr() ); + } + + printf( "Test finished\n" ); + return 0; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/cppuhelper/test/testhelper.hxx b/cppuhelper/test/testhelper.hxx new file mode 100644 index 000000000000..a164c1c6b9f4 --- /dev/null +++ b/cppuhelper/test/testhelper.hxx @@ -0,0 +1,34 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +void testidlclass( const ::com::sun::star::uno::Reference < ::com::sun::star::lang::XMultiServiceFactory > &r); +void testPropertyTypeHelper(); +void test_PropertySetHelper(); +void test_ImplHelper( const ::com::sun::star::uno::Reference < ::com::sun::star::lang::XMultiServiceFactory > & xSF ); +void test_interfacecontainer(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/cppuhelper/test/testidlclass.cxx b/cppuhelper/test/testidlclass.cxx new file mode 100644 index 000000000000..48ee84ed9101 --- /dev/null +++ b/cppuhelper/test/testidlclass.cxx @@ -0,0 +1,230 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_cppuhelper.hxx" + +#include <cppuhelper/stdidlclass.hxx> + +#include <com/sun/star/reflection/XIdlClassProvider.hpp> +#include <com/sun/star/lang/XServiceInfo.hpp> + +#include "testhelper.hxx" + +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::lang; +using namespace ::com::sun::star::reflection; +using namespace ::rtl; + + + + +void testidlclass( const Reference < XMultiServiceFactory > &rSMgr) +{ + const OUString sImplName( OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.cpputest") ) ); + + // this reference is static to test behaviour during exiting application + Reference < XIdlClass > r = + ::cppu::createStandardClass( + rSMgr , + sImplName, + Reference < XIdlClass > () , + (XMultiServiceFactory * ) 0 , + (XServiceInfo * ) 0 + ); + + OSL_ASSERT( r.is() ); + + + { // test the xidlclassprovider interface ! + Reference< XIdlClassProvider > rProv( r , UNO_QUERY ); + OSL_ASSERT( rProv.is() ); + + { + Sequence < Reference < XIdlClass > > seq = rProv->getIdlClasses(); + + // is always one + OSL_ASSERT( seq.getLength() == 1 ); + + // test the weak reference + rProv->getIdlClasses(); + + } + + rProv->getIdlClasses(); + + + } + + + OSL_ASSERT( r->getName() == sImplName ); + + // test equals + Reference < XIdlClass > r2 = + ::cppu::createStandardClass( + rSMgr , + sImplName, + Reference < XIdlClass > () , + (XMultiServiceFactory * ) 0 , + (XServiceInfo * ) 0 + ); + // test for implementation name + OSL_ASSERT( r2->equals( r ) ); + + Sequence < Reference < XIdlClass > > seqIdlClass = r->getInterfaces(); + + //TODO ! + // one idl class for one interface + // this test fails, if core reflection fails ! +// OSL_ASSERT( 1 == seqIdlClass.getLength() ); +// Reference < XIdlClass > rIdlInterface = seqIdlClass.getArray()[0]; + + // check for IdlClass interface returned by Core Reflection +// OSL_ASSERT( rIdlInterface.is() ); + + + + // Test all ten templates + Reference< XIdlClass > x = ::cppu::createStandardClass( + rSMgr , + sImplName, + Reference < XIdlClass > () , + (XMultiServiceFactory * ) 0 , + (XServiceInfo * ) 0 , + (XServiceInfo * ) 0 + ); + + // Test all ten templates + x = ::cppu::createStandardClass( + rSMgr , + sImplName, + Reference < XIdlClass > () , + (XMultiServiceFactory * ) 0 , + (XServiceInfo * ) 0 , + (XServiceInfo * ) 0 , + (XServiceInfo * ) 0 + ); + + + // Test all ten templates + x = ::cppu::createStandardClass( + rSMgr , + sImplName, + Reference < XIdlClass > () , + (XMultiServiceFactory * ) 0 , + (XServiceInfo * ) 0 , + (XServiceInfo * ) 0 , + (XServiceInfo * ) 0 , + (XServiceInfo * ) 0 + ); + + + + // Test all ten templates + x = ::cppu::createStandardClass( + rSMgr , + sImplName, + Reference < XIdlClass > () , + (XMultiServiceFactory * ) 0 , + (XServiceInfo * ) 0 , + (XServiceInfo * ) 0 , + (XServiceInfo * ) 0 , + (XServiceInfo * ) 0 , + (XServiceInfo * ) 0 + ); + + + + // Test all ten templates + x = ::cppu::createStandardClass( + rSMgr , + sImplName, + Reference < XIdlClass > () , + (XMultiServiceFactory * ) 0 , + (XServiceInfo * ) 0 , + (XServiceInfo * ) 0 , + (XServiceInfo * ) 0 , + (XServiceInfo * ) 0 , + (XServiceInfo * ) 0 , + (XServiceInfo * ) 0 + ); + + + // Test all ten templates + x = ::cppu::createStandardClass( + rSMgr , + sImplName, + Reference < XIdlClass > () , + (XMultiServiceFactory * ) 0 , + (XServiceInfo * ) 0 , + (XServiceInfo * ) 0 , + (XServiceInfo * ) 0 , + (XServiceInfo * ) 0 , + (XServiceInfo * ) 0 , + (XServiceInfo * ) 0 , + (XServiceInfo * ) 0 + ); + + + + + // Test all ten templates + x = ::cppu::createStandardClass( + rSMgr , + sImplName, + Reference < XIdlClass > () , + (XMultiServiceFactory * ) 0 , + (XServiceInfo * ) 0 , + (XServiceInfo * ) 0 , + (XServiceInfo * ) 0 , + (XServiceInfo * ) 0 , + (XServiceInfo * ) 0 , + (XServiceInfo * ) 0 , + (XServiceInfo * ) 0 , + (XServiceInfo * ) 0 + ); + + // Test all ten templates + x = ::cppu::createStandardClass( + rSMgr , + sImplName, + Reference < XIdlClass > () , + (XMultiServiceFactory * ) 0 , + (XServiceInfo * ) 0 , + (XServiceInfo * ) 0 , + (XServiceInfo * ) 0 , + (XServiceInfo * ) 0 , + (XServiceInfo * ) 0 , + (XServiceInfo * ) 0 , + (XServiceInfo * ) 0 , + (XServiceInfo * ) 0 , + (XServiceInfo * ) 0 + ); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/cppuhelper/test/testimplhelper.cxx b/cppuhelper/test/testimplhelper.cxx new file mode 100644 index 000000000000..db45093f3e8b --- /dev/null +++ b/cppuhelper/test/testimplhelper.cxx @@ -0,0 +1,586 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#if !defined(OSL_DEBUG_LEVEL) || OSL_DEBUG_LEVEL == 0 +# undef OSL_DEBUG_LEVEL +# define OSL_DEBUG_LEVEL 2 +#endif + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_cppuhelper.hxx" + +#include <stdio.h> + +#include <cppuhelper/implbase1.hxx> +#include <cppuhelper/implbase2.hxx> +#include <cppuhelper/implbase3.hxx> +#include <cppuhelper/implbase4.hxx> +#include <cppuhelper/implbase5.hxx> +#include <cppuhelper/implbase6.hxx> +#include <cppuhelper/implbase7.hxx> +#include <cppuhelper/implbase8.hxx> +#include <cppuhelper/implbase9.hxx> +#include <cppuhelper/implbase10.hxx> +#include <cppuhelper/implbase11.hxx> +#include <cppuhelper/implbase12.hxx> + +#include <cppuhelper/compbase1.hxx> +#include <cppuhelper/compbase2.hxx> +#include <cppuhelper/compbase3.hxx> +#include <cppuhelper/compbase4.hxx> +#include <cppuhelper/compbase5.hxx> +#include <cppuhelper/compbase6.hxx> +#include <cppuhelper/compbase7.hxx> +#include <cppuhelper/compbase8.hxx> +#include <cppuhelper/compbase9.hxx> +#include <cppuhelper/compbase10.hxx> +#include <cppuhelper/compbase11.hxx> +#include <cppuhelper/compbase12.hxx> + +#include <osl/diagnose.h> +#include <cppuhelper/servicefactory.hxx> +#include <cppuhelper/implbase4.hxx> +#include <cppuhelper/compbase4.hxx> +#include <cppuhelper/exc_hlp.hxx> + +#include <test/A.hpp> +#include <test/BA.hpp> +#include <test/CA.hpp> +#include <test/DBA.hpp> +#include <test/E.hpp> +#include <test/FE.hpp> +#include <test/G.hpp> +#include <test/H.hpp> +#include <test/I.hpp> + +#include <com/sun/star/lang/IllegalAccessException.hpp> + +using namespace test; +using namespace osl; +using namespace cppu; +using namespace com::sun::star; +using namespace com::sun::star::uno; + +using ::rtl::OUString; +using ::rtl::OUStringToOString; +using ::rtl::OString; + +//================================================================================================== +struct TestImpl : public ImplHelper4< CA, DBA, FE, G > +{ + sal_Int32 nRef; + + virtual ~TestImpl() + { OSL_TRACE( "> TestImpl dtor called... <\n" ); } + + virtual Any SAL_CALL queryInterface( const Type & rType ) throw(RuntimeException) + { return ImplHelper4< CA, DBA, FE, G >::queryInterface( rType ); } + virtual void SAL_CALL acquire( ) throw() + { ++nRef; } + virtual void SAL_CALL release( ) throw() + { if (! --nRef) delete this; } + + // A + virtual OUString SAL_CALL a() throw(RuntimeException) + { return OUString( RTL_CONSTASCII_USTRINGPARAM("a") ); } + // BA + virtual OUString SAL_CALL ba() throw(RuntimeException) + { return OUString( RTL_CONSTASCII_USTRINGPARAM("ba") ); } + // CA + virtual OUString SAL_CALL ca() throw(RuntimeException) + { return OUString( RTL_CONSTASCII_USTRINGPARAM("ca") ); } + // DBA + virtual OUString SAL_CALL dba() throw(RuntimeException) + { return OUString( RTL_CONSTASCII_USTRINGPARAM("dba") ); } + // E + virtual OUString SAL_CALL e() throw(RuntimeException) + { return OUString( RTL_CONSTASCII_USTRINGPARAM("e") ); } + // FE + virtual OUString SAL_CALL fe() throw(RuntimeException) + { return OUString( RTL_CONSTASCII_USTRINGPARAM("fe") ); } + // G + virtual OUString SAL_CALL g() throw(RuntimeException) + { return OUString( RTL_CONSTASCII_USTRINGPARAM("g") ); } +}; + +//================================================================================================== +struct TestWeakAggImpl : public WeakAggImplHelper4< CA, DBA, FE, G > +{ + virtual ~TestWeakAggImpl() + { OSL_TRACE( "> TestWeakAggImpl dtor called... <\n" ); } + + // A + virtual OUString SAL_CALL a() throw(RuntimeException) + { return OUString( RTL_CONSTASCII_USTRINGPARAM("a") ); } + // BA + virtual OUString SAL_CALL ba() throw(RuntimeException) + { return OUString( RTL_CONSTASCII_USTRINGPARAM("ba") ); } + // CA + virtual OUString SAL_CALL ca() throw(RuntimeException) + { return OUString( RTL_CONSTASCII_USTRINGPARAM("ca") ); } + // DBA + virtual OUString SAL_CALL dba() throw(RuntimeException) + { return OUString( RTL_CONSTASCII_USTRINGPARAM("dba") ); } + // E + virtual OUString SAL_CALL e() throw(RuntimeException) + { return OUString( RTL_CONSTASCII_USTRINGPARAM("e") ); } + // FE + virtual OUString SAL_CALL fe() throw(RuntimeException) + { return OUString( RTL_CONSTASCII_USTRINGPARAM("fe") ); } + // G + virtual OUString SAL_CALL g() throw(RuntimeException) + { return OUString( RTL_CONSTASCII_USTRINGPARAM("g") ); } +}; + +//================================================================================================== +struct TestWeakImpl : public WeakImplHelper4< CA, DBA, FE, G > +{ + TestWeakImpl() {} + + virtual ~TestWeakImpl() + { OSL_TRACE( "> TestWeakImpl dtor called... <\n" ); } + + // A + virtual OUString SAL_CALL a() throw(RuntimeException) + { return OUString( RTL_CONSTASCII_USTRINGPARAM("a") ); } + // BA + virtual OUString SAL_CALL ba() throw(RuntimeException) + { return OUString( RTL_CONSTASCII_USTRINGPARAM("ba") ); } + // CA + virtual OUString SAL_CALL ca() throw(RuntimeException) + { return OUString( RTL_CONSTASCII_USTRINGPARAM("ca") ); } + // DBA + virtual OUString SAL_CALL dba() throw(RuntimeException) + { return OUString( RTL_CONSTASCII_USTRINGPARAM("dba") ); } + // E + virtual OUString SAL_CALL e() throw(RuntimeException) + { return OUString( RTL_CONSTASCII_USTRINGPARAM("e") ); } + // FE + virtual OUString SAL_CALL fe() throw(RuntimeException) + { return OUString( RTL_CONSTASCII_USTRINGPARAM("fe") ); } + // G + virtual OUString SAL_CALL g() throw(RuntimeException) + { return OUString( RTL_CONSTASCII_USTRINGPARAM("g") ); } + +protected: + TestWeakImpl(int) {} + + TestWeakImpl(int, int) {} + + TestWeakImpl(int, int, int) {} + + TestWeakImpl(int, int, int, int) {} + + TestWeakImpl(int, int, int, int, int) {} + + TestWeakImpl(int, int, int, int, int, int, int = 0) {} +}; + +//================================================================================================== +struct TestWeakComponentImpl : public WeakComponentImplHelper4< CA, DBA, FE, G > +{ + Mutex m; + TestWeakComponentImpl() + : WeakComponentImplHelper4< CA, DBA, FE, G >( m ) + {} + virtual ~TestWeakComponentImpl() + { OSL_TRACE( "> TestWeakComponentImpl dtor called... <\n" ); } + + void SAL_CALL disposing() + { OSL_TRACE( "> TestWeakComponentImpl disposing called... <\n" ); } + + // A + virtual OUString SAL_CALL a() throw(RuntimeException) + { return OUString( RTL_CONSTASCII_USTRINGPARAM("a") ); } + // BA + virtual OUString SAL_CALL ba() throw(RuntimeException) + { return OUString( RTL_CONSTASCII_USTRINGPARAM("ba") ); } + // CA + virtual OUString SAL_CALL ca() throw(RuntimeException) + { return OUString( RTL_CONSTASCII_USTRINGPARAM("ca") ); } + // DBA + virtual OUString SAL_CALL dba() throw(RuntimeException) + { return OUString( RTL_CONSTASCII_USTRINGPARAM("dba") ); } + // E + virtual OUString SAL_CALL e() throw(RuntimeException) + { return OUString( RTL_CONSTASCII_USTRINGPARAM("e") ); } + // FE + virtual OUString SAL_CALL fe() throw(RuntimeException) + { return OUString( RTL_CONSTASCII_USTRINGPARAM("fe") ); } + // G + virtual OUString SAL_CALL g() throw(RuntimeException) + { return OUString( RTL_CONSTASCII_USTRINGPARAM("g") ); } +}; + +//================================================================================================== +struct TestWeakAggComponentImpl : public WeakAggComponentImplHelper4< CA, DBA, FE, G > +{ + Mutex m; + TestWeakAggComponentImpl() + : WeakAggComponentImplHelper4< CA, DBA, FE, G >( m ) + {} + virtual ~TestWeakAggComponentImpl() + { OSL_TRACE( "> TestWeakAggComponentImpl dtor called... <\n" ); } + + void SAL_CALL disposing() + { OSL_TRACE( "> TestWeakAggComponentImpl disposing called... <\n" ); } + + // A + virtual OUString SAL_CALL a() throw(RuntimeException) + { return OUString( RTL_CONSTASCII_USTRINGPARAM("a") ); } + // BA + virtual OUString SAL_CALL ba() throw(RuntimeException) + { return OUString( RTL_CONSTASCII_USTRINGPARAM("ba") ); } + // CA + virtual OUString SAL_CALL ca() throw(RuntimeException) + { return OUString( RTL_CONSTASCII_USTRINGPARAM("ca") ); } + // DBA + virtual OUString SAL_CALL dba() throw(RuntimeException) + { return OUString( RTL_CONSTASCII_USTRINGPARAM("dba") ); } + // E + virtual OUString SAL_CALL e() throw(RuntimeException) + { return OUString( RTL_CONSTASCII_USTRINGPARAM("e") ); } + // FE + virtual OUString SAL_CALL fe() throw(RuntimeException) + { return OUString( RTL_CONSTASCII_USTRINGPARAM("fe") ); } + // G + virtual OUString SAL_CALL g() throw(RuntimeException) + { return OUString( RTL_CONSTASCII_USTRINGPARAM("g") ); } +}; + +//================================================================================================== +struct TestImplInh : public ImplInheritanceHelper2< TestWeakImpl, H, I > +{ + TestImplInh() {} + + explicit TestImplInh(int): + ImplInheritanceHelper2< TestWeakImpl, H, I >(1) {} + + TestImplInh(int, int): + ImplInheritanceHelper2< TestWeakImpl, H, I >(1, 2) {} + + TestImplInh(int, int, int): + ImplInheritanceHelper2< TestWeakImpl, H, I >(1, 2, 3) {} + + TestImplInh(int, int, int, int): + ImplInheritanceHelper2< TestWeakImpl, H, I >(1, 2, 3, 4) {} + + TestImplInh(int, int, int, int, int): + ImplInheritanceHelper2< TestWeakImpl, H, I >(1, 2, 3, 4, 5) {} + + TestImplInh(int, int, int, int, int, int): + ImplInheritanceHelper2< TestWeakImpl, H, I >(1, 2, 3, 4, 5, 6) {} + + virtual ~TestImplInh() + { OSL_TRACE( "> TestWeakImplInh dtor called... <\n" ); } + + // H + virtual OUString SAL_CALL h() throw(RuntimeException) + { return OUString( RTL_CONSTASCII_USTRINGPARAM("h") ); } + // I + virtual OUString SAL_CALL i() throw(RuntimeException) + { return OUString( RTL_CONSTASCII_USTRINGPARAM("i") ); } +}; + +//================================================================================================== +struct TestAggImplInh : public AggImplInheritanceHelper2< TestWeakAggImpl, H, I > +{ + virtual ~TestAggImplInh() + { OSL_TRACE( "> TestAggImplInh dtor called... <\n" ); } + + // H + virtual OUString SAL_CALL h() throw(RuntimeException) + { return OUString( RTL_CONSTASCII_USTRINGPARAM("h2") ); } + // I + virtual OUString SAL_CALL i() throw(RuntimeException) + { return OUString( RTL_CONSTASCII_USTRINGPARAM("i2") ); } +}; + + +static bool isIn( Sequence< Type > const & rTypes, char const * name ) +{ + OUString str( OUString::createFromAscii( name ) ); + Type const * pTypes = rTypes.getConstArray(); + for ( sal_Int32 nPos = rTypes.getLength(); nPos--; ) + { + if (pTypes[ nPos ].getTypeName().equals( str )) + return true; + } + return false; +} + +//================================================================================================== +static void dotest( const Reference< XInterface > & xOriginal ) +{ + Reference< lang::XTypeProvider > xTP( xOriginal, UNO_QUERY ); + Sequence< sal_Int8 > id( xTP->getImplementationId() ); + Sequence< Type > types( xTP->getTypes() ); + ::fprintf( stderr, "> supported types: " ); + long n = 0; + for ( ; n < types.getLength(); ++n ) + { + OString str( OUStringToOString( types[ n ].getTypeName(), RTL_TEXTENCODING_ASCII_US ) ); + ::fprintf( stderr, (n < (types.getLength()-1)) ? "%s, " : "%s; type-id=\n", str.getStr() ); + } + for ( n = 0; n < 16; ++n ) + { + ::fprintf( stderr, n < 15 ? "%x " : "%x \n", id[ n ] ); + } + + Reference< A > xa( xOriginal, UNO_QUERY ); + OSL_ENSURE( xa->a().equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("a") ), "### A failed!" ); + Reference< BA > xba( xa, UNO_QUERY ); + OSL_ENSURE( xba->ba().equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("ba") ), "### BA failed!" ); + OSL_ENSURE( xba->a().equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("a") ), "### BA failed!" ); + Reference< CA > xca( xba, UNO_QUERY ); + OSL_ENSURE( xca->ca().equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("ca") ), "### CA failed!" ); + OSL_ENSURE( xca->a().equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("a") ), "### CA failed!" ); + Reference< DBA > xdba( xca, UNO_QUERY ); + OSL_ENSURE( xdba->dba().equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("dba") ), "### DBA failed!" ); + OSL_ENSURE( xdba->ba().equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("ba") ), "### DBA failed!" ); + OSL_ENSURE( xdba->a().equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("a") ), "### DBA failed!" ); + Reference< E > xe( xdba, UNO_QUERY ); + OSL_ENSURE( xe->e().equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("e") ), "### E failed!" ); + Reference< FE > xfe( xe, UNO_QUERY ); + OSL_ENSURE( xfe->fe().equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("fe") ), "### FE failed!" ); + Reference< G > xg( xfe, UNO_QUERY ); + OSL_ENSURE( xg->g().equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("g") ), "### G failed!" ); + OSL_ENSURE( xg->a().equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("a") ), "### G failed!" ); + + // type provider + Reference< lang::XTypeProvider > xProv( xg, UNO_QUERY ); + Sequence< Type > aTypes( xProv->getTypes() ); + + // CA, DBA, FE, G, XTypeProvider + OSL_ASSERT( isIn( aTypes, "test.CA" ) ); + OSL_ASSERT( isIn( aTypes, "test.DBA" ) ); + OSL_ASSERT( isIn( aTypes, "test.FE") ); + OSL_ASSERT( isIn( aTypes, "test.G") ); + OSL_ASSERT( isIn( aTypes, "com.sun.star.lang.XTypeProvider") ); + + Reference< XWeak > xWeak( xg, UNO_QUERY ); + if (xWeak.is()) + { + OSL_ASSERT( isIn( aTypes, "com.sun.star.uno.XWeak") ); + } + Reference< lang::XComponent > xComp( xg, UNO_QUERY ); + if (xComp.is()) + { + OSL_ASSERT( isIn( aTypes, "com.sun.star.lang.XComponent") ); + } + + Reference< XAggregation > xAgg( xg, UNO_QUERY ); + if (xAgg.is()) + { + OSL_ASSERT( isIn( aTypes, "com.sun.star.uno.XAggregation") ); + } + Reference< H > xH( xg, UNO_QUERY ); + if (xH.is()) + { + OSL_ASSERT( isIn( aTypes, "test.H") ); + } + Reference< I > xI( xg, UNO_QUERY ); + if (xI.is()) + { + OSL_ASSERT( isIn( aTypes, "test.I") ); + } + + OSL_ENSURE( xg == xOriginal, "### root!" ); +} + +void rethrow() +{ + throw; +} + +void throw_one( + lang::IllegalAccessException exc ) +{ + try + { + throw exc; + } + catch (...) + { + rethrow(); + } +} + + +//================================================================================================== +void test_ImplHelper( const Reference< lang::XMultiServiceFactory > & /*xSF*/ ) +{ + Reference< XInterface > xImpl( (lang::XTypeProvider *)new TestImpl() ); + Reference< lang::XTypeProvider > xTP1( xImpl, UNO_QUERY ); + Reference< XInterface > xWeakImpl( (OWeakObject *)new TestWeakImpl() ); + Reference< lang::XTypeProvider > xTP2( xWeakImpl, UNO_QUERY ); + Reference< XInterface > xWeakAggImpl( (OWeakObject *)new TestWeakAggImpl() ); + Reference< lang::XTypeProvider > xTP3( xWeakAggImpl, UNO_QUERY ); + Reference< XInterface > xWeakComponentImpl( (OWeakObject *)new TestWeakComponentImpl() ); + Reference< lang::XTypeProvider > xTP4( xWeakComponentImpl, UNO_QUERY ); + Reference< XInterface > xWeakAggComponentImpl( (OWeakObject *)new TestWeakAggComponentImpl() ); + Reference< lang::XTypeProvider > xTP5( xWeakAggComponentImpl, UNO_QUERY ); + // + OSL_ASSERT( + xTP1->getImplementationId() != xTP2->getImplementationId() && + xTP1->getImplementationId() != xTP3->getImplementationId() && + xTP1->getImplementationId() != xTP4->getImplementationId() && + xTP1->getImplementationId() != xTP5->getImplementationId() && + xTP2->getImplementationId() != xTP3->getImplementationId() && + xTP2->getImplementationId() != xTP4->getImplementationId() && + xTP2->getImplementationId() != xTP5->getImplementationId() && + xTP3->getImplementationId() != xTP4->getImplementationId() && + xTP3->getImplementationId() != xTP5->getImplementationId() && + xTP4->getImplementationId() != xTP5->getImplementationId() ); + // + + dotest( xImpl ); + dotest( xWeakImpl ); + dotest( xWeakAggImpl ); + dotest( xWeakComponentImpl ); + dotest( xWeakAggComponentImpl ); + + xWeakImpl = (OWeakObject *)new TestImplInh(); + Reference< lang::XTypeProvider > xTP6( xWeakImpl, UNO_QUERY ); + dotest( xWeakImpl ); + Reference< H > xH( xWeakImpl, UNO_QUERY ); + Reference< I > xI( xH, UNO_QUERY ); + OSL_ASSERT( xH->h().equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("h") ) ); + OSL_ASSERT( xI->i().equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("i") ) ); + + xWeakAggImpl = (OWeakObject *)new TestAggImplInh(); + Reference< lang::XTypeProvider > xTP7( xWeakAggImpl, UNO_QUERY ); + dotest( xWeakAggImpl ); + xH.set( xWeakAggImpl, UNO_QUERY ); + xI.set( xH, UNO_QUERY ); + OSL_ASSERT( xH->h().equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("h2") ) ); + OSL_ASSERT( xI->i().equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("i2") ) ); + + // + OSL_ASSERT( + xTP6->getImplementationId() != xTP1->getImplementationId() && + xTP6->getImplementationId() != xTP2->getImplementationId() && + xTP6->getImplementationId() != xTP3->getImplementationId() && + xTP6->getImplementationId() != xTP4->getImplementationId() && + xTP6->getImplementationId() != xTP5->getImplementationId() && + xTP6->getImplementationId() != xTP7->getImplementationId() && + xTP7->getImplementationId() != xTP1->getImplementationId() && + xTP7->getImplementationId() != xTP2->getImplementationId() && + xTP7->getImplementationId() != xTP3->getImplementationId() && + xTP7->getImplementationId() != xTP4->getImplementationId() && + xTP7->getImplementationId() != xTP5->getImplementationId() ); + // + + bool exc_succ = false; + lang::IllegalAccessException exc( + OUString( RTL_CONSTASCII_USTRINGPARAM("testtest") ), + xWeakAggImpl ); + // exception helper tests + try + { + throw exc; + } + catch (Exception &) + { + Any a( getCaughtException() ); + OSL_ASSERT( a == exc ); + + try + { + throwException( a ); + } + catch (lang::IllegalAccessException & e) + { + OSL_ASSERT( exc.Message == e.Message && exc.Context == e.Context ); + + try + { + throw_one( exc ); + } + catch (Exception &) + { + Any a2( getCaughtException() ); + OSL_ASSERT( (a2 == a) && (a2 == exc) ); + + try + { + throw_one( exc ); + } + catch (lang::IllegalAccessException &) + { + Any a3( getCaughtException() ); + OSL_ASSERT( (a3 == a) && (a3 == a2) && (a3 == exc) ); + exc_succ = true; + } + } + } + } + OSL_ASSERT( exc_succ ); + + try + { + throwException( makeAny( RuntimeException( + OUString( RTL_CONSTASCII_USTRINGPARAM("runtime exc") ), xImpl ) ) ); + } + catch (RuntimeException & rExc) + { + OSL_ENSURE( rExc.Message.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("runtime exc") ) && rExc.Context == xImpl, + "### unexpected exception content!" ); + try + { + throwException( makeAny( Exception( + OUString( RTL_CONSTASCII_USTRINGPARAM("exc") ), rExc.Context ) ) ); + } + catch (lang::IllegalAccessException &) + { + OSL_FAIL( "### unexpected IllegalAccessException exception caught!" ); + } + catch (Exception & rExc2) + { + OSL_ENSURE( rExc2.Message.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("exc") ) && rExc2.Context == xImpl, + "### unexpected exception content!" ); + try + { + throwException( makeAny( lang::IllegalAccessException( + OUString( RTL_CONSTASCII_USTRINGPARAM("axxess exc") ), rExc2.Context ) ) ); + } + catch (lang::IllegalAccessException & rExc3) + { + OSL_ENSURE( rExc3.Message.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("axxess exc") ) && rExc3.Context == xImpl, + "### unexpected exception content!" ); + return; + } + } + } + catch (...) + { + } + OSL_FAIL( "### exception test failed!" ); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/cppuhelper/test/testlib/UNO.pm b/cppuhelper/test/testlib/UNO.pm new file mode 100644 index 000000000000..052a9ea986d3 --- /dev/null +++ b/cppuhelper/test/testlib/UNO.pm @@ -0,0 +1,68 @@ +package UNO; + +require 5.005_62; +use strict; +use warnings; + +require Exporter; +require DynaLoader; + +our @ISA = qw(Exporter DynaLoader); + +# Items to export into callers namespace by default. Note: do not export +# names by default without a very good reason. Use EXPORT_OK instead. +# Do not simply export all your public functions/methods/constants. + +# This allows declaration use UNO ':all'; +# If you do not need this, moving things directly into @EXPORT or @EXPORT_OK +# will save memory. +our %EXPORT_TAGS = ( 'all' => [ qw( + +) ] ); + +our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); + +our @EXPORT = qw( + +); +our $VERSION = '0.01'; + +bootstrap UNO $VERSION; + +# Preloaded methods go here. + +1; +__END__ +# Below is stub documentation for your module. You better edit it! + +=head1 NAME + +UNO - Perl extension for blah blah blah + +=head1 SYNOPSIS + + use UNO; + blah blah blah + +=head1 DESCRIPTION + +Stub documentation for UNO, created by h2xs. It looks like the +author of the extension was negligent enough to leave the stub +unedited. + +Blah blah blah. + +=head2 EXPORT + +None by default. + + +=head1 AUTHOR + +A. U. Thor, a.u.thor@a.galaxy.far.far.away + +=head1 SEE ALSO + +perl(1). + +=cut diff --git a/cppuhelper/test/testlib/defbootstrap.map b/cppuhelper/test/testlib/defbootstrap.map new file mode 100755 index 000000000000..2293d819d900 --- /dev/null +++ b/cppuhelper/test/testlib/defbootstrap.map @@ -0,0 +1,8 @@ +UDK_3_0_0 { + global: + + boot_UNO; + + local: + *; +}; diff --git a/cppuhelper/test/testlib/defbootstrap_lib.cxx b/cppuhelper/test/testlib/defbootstrap_lib.cxx new file mode 100644 index 000000000000..64c28766a5f3 --- /dev/null +++ b/cppuhelper/test/testlib/defbootstrap_lib.cxx @@ -0,0 +1,120 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_cppuhelper.hxx" + +#include "EXTERN.h" +#include "perl.h" +#include "XSUB.h" + +#include <cstdio> + +#include <osl/module.hxx> +#include <rtl/process.h> +#include <cppuhelper/bootstrap.hxx> + +#include <com/sun/star/lang/XMultiServiceFactory.hpp> + +using namespace ::cppu; +using namespace ::com::sun::star::lang; +using namespace ::com::sun::star::uno; +using namespace ::rtl; + +static sal_Bool tryService(const char * serviceName) +{ + // use micro deployment to create initial context + OUString libraryFileUrl; + ::osl::Module::getUrlFromAddress((void *)tryService, libraryFileUrl); + + OUString iniName = libraryFileUrl.copy(0, libraryFileUrl.lastIndexOf((sal_Unicode)'.')); // cut the library extension + iniName += OUString(RTL_CONSTASCII_USTRINGPARAM(SAL_CONFIGFILE(""))); // add the rc file extension + +#if OSL_DEBUG_LEVEL > 1 + OString sIniName = OUStringToOString(iniName, RTL_TEXTENCODING_ASCII_US); + fprintf(stderr, "defbootstrap.cxx:tryService: using ini: %s\n", sIniName.getStr()); +#endif + + sal_Bool result = sal_True; + + try { + Reference<XComponentContext> xComponentContext = defaultBootstrap_InitialComponentContext(iniName); + Reference<XMultiServiceFactory> smgr(xComponentContext->getServiceManager(), UNO_QUERY); + + OUString arg = OUString::createFromAscii(serviceName); + Reference<XInterface> xInterface = smgr->createInstance(arg); + +#if OSL_DEBUG_LEVEL > 1 + fprintf(stderr, "got the %s service %p\n", serviceName, xInterface.get()); +#endif + result = result && (xInterface.get() != 0); + } + catch(Exception & exception) { + OString message = OUStringToOString(exception.Message, RTL_TEXTENCODING_ASCII_US); + + fprintf(stderr, "an exception occurred: %s\n", message.getStr()); + } + +#if OSL_DEBUG_LEVEL > 1 + OSL_TRACE("---------------------------------- %i", result); +#endif + + return result; +} + +XS(XS_UNO_tryService) +{ + dXSARGS; + if (items != 1) + Perl_croak(aTHX_ "Usage: UNO::tryService(input)"); + { + const char * input = (const char *)SvPV(ST(0),PL_na); + int RETVAL; + dXSTARG; + + RETVAL = tryService(input); + XSprePUSH; PUSHi((IV)RETVAL); + } + XSRETURN(1); +} + +extern "C" { +XS(boot_UNO) +{ + dXSARGS; + char* file = __FILE__; + +/* XS_VERSION_BOOTCHECK ;*/ + + newXS("UNO::tryService", XS_UNO_tryService, file); + XSRETURN_YES; +} + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/cppuhelper/test/testlib/makefile.mk b/cppuhelper/test/testlib/makefile.mk new file mode 100755 index 000000000000..b53f6ebab71b --- /dev/null +++ b/cppuhelper/test/testlib/makefile.mk @@ -0,0 +1,101 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org 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 version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +LINKFLAGSDEFS="" + +PRJ=..$/.. + +PRJNAME=cppuhelper +TARGET=defbootstrap +ENABLE_EXCEPTIONS=TRUE + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk + +PERLINST1:=$(shell @+$(PERL) -V:installarchlib) +PERLINST2:=$(subst,installarchlib=, $(PERLINST1)) +PERLINST3:=$(PERLINST2:s/'//) +PERLINST :=$(PERLINST3:s/;//) + +PERLLIBS:=$(PERLINST)$/CORE +PERLINCS:=$(PERLINST)$/CORE + +CFLAGS += -I$(PERLINCS) + +.IF "$(GUI)"=="WNT" +PERLLIB=perl58.lib + +LIB!:=$(LIB);$(PERLLIBS) +.EXPORT : LIB + +.ENDIF + +# --- Files -------------------------------------------------------- + +SLOFILES= $(SLO)$/defbootstrap_lib.obj + +SHL1TARGET=$(TARGET) + +SHL1STDLIBS= \ + $(PERLLIB) \ + $(CPPUHELPERLIB) \ + $(CPPULIB) \ + $(SALLIB) + +SHL1DEPN= +SHL1IMPLIB=i$(TARGET) +SHL1LIBS=$(SLB)$/$(TARGET).lib +SHL1DEF=$(MISC)$/$(SHL1TARGET).def + +DEF1NAME=$(SHL1TARGET) +SHL1VERSIONMAP=defbootstrap.map + + +.IF "$(GUI)"=="WNT" +UNODLL=$(DLLDEST)$/UNO.dll +.ELSE +UNODLL=$(DLLDEST)$/UNO.so +.ENDIF + +# --- Targets ------------------------------------------------------ + +.IF "$(depend)" == "" +ALL: \ + ALLTAR \ + $(UNODLL) \ + $(BIN)$/UNO.pm +.ENDIF + +$(BIN)$/UNO.pm: UNO.pm + cp UNO.pm $@ + +$(UNODLL): $(SHL1TARGETN) + cp $(SHL1TARGETN) $@ + +.INCLUDE : target.mk + diff --git a/cppuhelper/test/testpropshlp.cxx b/cppuhelper/test/testpropshlp.cxx new file mode 100644 index 000000000000..965159ffc637 --- /dev/null +++ b/cppuhelper/test/testpropshlp.cxx @@ -0,0 +1,1184 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#if !defined(OSL_DEBUG_LEVEL) || OSL_DEBUG_LEVEL == 0 +# undef OSL_DEBUG_LEVEL +# define OSL_DEBUG_LEVEL 2 +#endif + + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_cppuhelper.hxx" +#include <osl/mutex.hxx> +#include <osl/diagnose.h> + +#include <cppuhelper/propshlp.hxx> +#include <cppuhelper/weak.hxx> + +#include <cppuhelper/proptypehlp.hxx> + +#include <com/sun/star/uno/Any.hxx> +#include <com/sun/star/beans/PropertyAttribute.hpp> + +#include <cppuhelper/implbase3.hxx> + +using namespace ::cppu; +using namespace ::rtl; +using namespace ::osl; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::beans; +using namespace ::com::sun::star::lang; + + + +/********************** +* +**********************/ +static Property * getPropertyTable1() +{ + static Property *pTable = 0; + + if( ! pTable ) { + MutexGuard guard( Mutex::getGlobalMutex() ); + if( ! pTable ) { + static Property aTable[] = + { + Property( OUString( RTL_CONSTASCII_USTRINGPARAM("a") ), 0, getCppuType( (OUString *)0) , + PropertyAttribute::READONLY | PropertyAttribute::MAYBEVOID ), //OUString + Property( OUString( RTL_CONSTASCII_USTRINGPARAM("b") ), 1, getCppuCharType( ) , + PropertyAttribute::READONLY | PropertyAttribute::MAYBEVOID ), //Char + Property( OUString( RTL_CONSTASCII_USTRINGPARAM("c") ), 2, getCppuType( (sal_Int32*)0) , + PropertyAttribute::READONLY | PropertyAttribute::MAYBEVOID ), //sal_Int32 + Property( OUString( RTL_CONSTASCII_USTRINGPARAM("d") ), 5, getCppuType( (double*)0) , + PropertyAttribute::READONLY | PropertyAttribute::MAYBEVOID ), //double + Property( OUString( RTL_CONSTASCII_USTRINGPARAM("e") ), 7, getCppuBooleanType() , + PropertyAttribute::READONLY | PropertyAttribute::MAYBEVOID ), //BOOL + Property( OUString( RTL_CONSTASCII_USTRINGPARAM("f") ), 8, getCppuType( (Any*)0) , + PropertyAttribute::READONLY | PropertyAttribute::MAYBEVOID ) //Any + }; + pTable = aTable; + } + } + return pTable; +} + + +static Property * getPropertyTable2() +{ + static Property *pTable = 0; + + if( ! pTable ) { + MutexGuard guard( ::osl::Mutex::getGlobalMutex() ); + if( ! pTable ) { + static Property aTable[] = + { + Property( OUString( RTL_CONSTASCII_USTRINGPARAM("f") ), 8, getCppuType( (Any *)0) , + PropertyAttribute::READONLY | PropertyAttribute::MAYBEVOID ), // Any + Property( OUString( RTL_CONSTASCII_USTRINGPARAM("b") ), 1, getCppuCharType( ), + PropertyAttribute::READONLY | PropertyAttribute::MAYBEVOID ), // Char + Property( OUString( RTL_CONSTASCII_USTRINGPARAM("a") ), 0, getCppuType( (OUString*)0), + PropertyAttribute::READONLY | PropertyAttribute::MAYBEVOID ), // OUString + Property( OUString( RTL_CONSTASCII_USTRINGPARAM("d") ), 5, getCppuType( (double*)0) , + PropertyAttribute::READONLY | PropertyAttribute::MAYBEVOID ), // Double + Property( OUString( RTL_CONSTASCII_USTRINGPARAM("c") ), 2, getCppuType( (sal_Int32*)0), + PropertyAttribute::READONLY | PropertyAttribute::MAYBEVOID ), // sal_Int32 + Property( OUString( RTL_CONSTASCII_USTRINGPARAM("e") ), 7, getCppuBooleanType() , + PropertyAttribute::READONLY | PropertyAttribute::MAYBEVOID ) // Bool + }; + pTable = aTable; + } + } + return pTable; +} + +static Property * getPropertyTable3() +{ + static Property *pTable = 0; + + if( ! pTable ) { + MutexGuard guard( ::osl::Mutex::getGlobalMutex() ); + if( ! pTable ) { + static Property aTable[] = + { + Property( OUString( RTL_CONSTASCII_USTRINGPARAM("b") ), 1, getCppuCharType( ), + PropertyAttribute::READONLY | PropertyAttribute::MAYBEVOID ), // Char + Property( OUString( RTL_CONSTASCII_USTRINGPARAM("f") ), 8, getCppuType( (Any *)0) , + PropertyAttribute::READONLY | PropertyAttribute::MAYBEVOID ), // any + Property( OUString( RTL_CONSTASCII_USTRINGPARAM("a") ), 0, getCppuType( (OUString*)0), + PropertyAttribute::READONLY | PropertyAttribute::MAYBEVOID ) // OUString + }; + pTable = aTable; + } + } + return pTable; +} + + +static Property * getPropertyTable4() +{ + static Property *pTable = 0; + + if( ! pTable ) { + MutexGuard guard( ::osl::Mutex::getGlobalMutex() ); + if( ! pTable ) { + static Property aTable[] = + { + Property( OUString( RTL_CONSTASCII_USTRINGPARAM("a") ), 0, getCppuType( (OUString*)0), + PropertyAttribute::READONLY | PropertyAttribute::MAYBEVOID ), // OUString + Property( OUString( RTL_CONSTASCII_USTRINGPARAM("b") ), 1, getCppuCharType( ), + PropertyAttribute::READONLY | PropertyAttribute::MAYBEVOID ), // Char + Property( OUString( RTL_CONSTASCII_USTRINGPARAM("f") ), 2, getCppuType( (Any *)0) , + PropertyAttribute::READONLY | PropertyAttribute::MAYBEVOID ) // Any + }; + pTable = aTable; + } + } + return pTable; +} + + + +/********************** +* +* Note : all Property names must be in the 127 ASCII subset ! +* +**********************/ + + +void test_PropertyArrayHelper() +{ + // Test getProperties() and getCount() + { + OPropertyArrayHelper a1( getPropertyTable1(), 6 ); + OSL_ENSURE( 6 == a1.getCount(), "not all properties inserted" ); + Sequence< Property > aProps = a1.getProperties(); + Property * pP = aProps.getArray(); + OSL_ENSURE( 6 == aProps.getLength(), "getProperties() gives not all properties" ); + for( int i = 0; i < 6; i++ ) + { + OSL_ENSURE( pP[i].Name == getPropertyTable1()[i].Name , "Name not correct" ); + OSL_ENSURE( pP[i].Handle == getPropertyTable1()[i].Handle, "Handle not correct" ); + OSL_ENSURE( pP[i].Attributes == getPropertyTable1()[i].Attributes, "Attributes not correct" ); + OSL_ENSURE( pP[i].Type == getPropertyTable1()[i].Type, "Type not correct" ); + } + } + + // Test sorting + { + OPropertyArrayHelper a1( getPropertyTable2(), 6, sal_False ); + Sequence< Property > aProps = a1.getProperties(); + Property * pP = aProps.getArray(); + OSL_ENSURE( 6 == aProps.getLength(), "getProperties() gives not all properties" ); + + // table to switch to sorted + int a[] = { 2 , 1 , 4, 3, 5, 0 }; + for( int i = 0; i < 6; i++ ) + { + OSL_ENSURE( pP[i].Name == getPropertyTable2()[a[i]].Name , "Name not correct" ); + OSL_ENSURE( pP[i].Handle == getPropertyTable2()[a[i]].Handle, "Handle not correct" ); + OSL_ENSURE( pP[i].Attributes == getPropertyTable2()[a[i]].Attributes, "Attributes not correct" ); + OSL_ENSURE( pP[i].Type == getPropertyTable2()[a[i]].Type, "Type not correct" ); + } + } + + // Test sorting + { + OPropertyArrayHelper a1( getPropertyTable3(), 3, sal_False ); + Sequence< Property > aProps = a1.getProperties(); + Property * pP = aProps.getArray(); + OSL_ENSURE( 3 == aProps.getLength(), "getProperties() gives not all properties" ); + // table to switch to sorted + int a[] = { 2 , 0 , 1 }; + for( int i = 0; i < 3; i++ ) + { + OSL_ENSURE( pP[i].Name == getPropertyTable3()[a[i]].Name , "Name not correct" ); + OSL_ENSURE( pP[i].Handle == getPropertyTable3()[a[i]].Handle, "Handle not correct" ); + OSL_ENSURE( pP[i].Attributes == getPropertyTable3()[a[i]].Attributes, "Attributes not correct" ); + OSL_ENSURE( pP[i].Type == getPropertyTable3()[a[i]].Type, "Type not correct" ); + } + } + + // Test getPropertyByName and hasPropertyByName + { + OPropertyArrayHelper a1( getPropertyTable1(), 6 ); + for( int i = 0; i < 6; i++ ) + { + OSL_ENSURE( a1.hasPropertyByName( getPropertyTable1()[i].Name ), "hasPropertyByName not correct" ); + Property aP = a1.getPropertyByName( getPropertyTable1()[i].Name ); + OSL_ENSURE( aP.Name == getPropertyTable1()[i].Name , "Name not correct" ); + OSL_ENSURE( aP.Handle == getPropertyTable1()[i].Handle, "Handle not correct" ); + OSL_ENSURE( aP.Attributes == getPropertyTable1()[i].Attributes, "Attributes not correct" ); + OSL_ENSURE( aP.Type == getPropertyTable1()[i].Type, "Type not correct" ); + } + + OSL_ENSURE( !a1.hasPropertyByName( OUString( RTL_CONSTASCII_USTRINGPARAM("never exist") ) ), "hasPropertyByName not correct" ); + try + { + a1.getPropertyByName( OUString( RTL_CONSTASCII_USTRINGPARAM("never exist") ) ); + OSL_FAIL( "exeption not thrown" ); + } + catch( UnknownPropertyException & ) + { + } + } + + // Test getHandleByName + { + OPropertyArrayHelper a1( getPropertyTable1(), 6 ); + for( int i = 0; i < 6; i++ ) + { + sal_Int32 Handle = a1.getHandleByName( getPropertyTable1()[i].Name ); + OSL_ENSURE( Handle == getPropertyTable1()[i].Handle, "Handle not correct" ); + } + sal_Int32 Handle = a1.getHandleByName( OUString( RTL_CONSTASCII_USTRINGPARAM("asdaf") ) ); + OSL_ENSURE( Handle == -1, "Handle not correct" ); + } + + // Test fillPropertyMembersByHandle + { + OPropertyArrayHelper a1( getPropertyTable1(), 6 ); + int i; + for( i = 0; i < 6; i++ ) + { + sal_Int16 nAttributes; + OUString aPropName; + sal_Bool b = a1.fillPropertyMembersByHandle( &aPropName, &nAttributes, getPropertyTable1()[i].Handle ); + OSL_ENSURE( b, "fillPropertyMembersByHandle: handle not found" ); + OSL_ENSURE( nAttributes == getPropertyTable1()[i].Attributes, "fillPropertyMembersByHandle: Attributes not correct" ); + OSL_ENSURE( aPropName == getPropertyTable1()[i].Name , "fillPropertyMembersByHandle: Name not correct" ); + } + OSL_ENSURE( !a1.fillPropertyMembersByHandle( NULL, NULL, 66666 ), "fillPropertyMembersByHandle: handle found" ); + // optimized table + OPropertyArrayHelper a4( getPropertyTable4(), 3 ); + for( i = 0; i < 3; i++ ) + { + sal_Int16 nAttributes; + OUString aPropName; + sal_Bool b = a1.fillPropertyMembersByHandle( &aPropName, &nAttributes, getPropertyTable4()[i].Handle ); + OSL_ENSURE( b, "fillPropertyMembersByHandle: handle not found" ); + OSL_ENSURE( nAttributes == getPropertyTable1()[i].Attributes, "fillPropertyMembersByHandle: Attributes not correct" ); + OSL_ENSURE( aPropName == getPropertyTable1()[i].Name , "fillPropertyMembersByHandle: Name not correct" ); + } + OSL_ENSURE( !a4.fillPropertyMembersByHandle( NULL, NULL, 66666 ), "fillPropertyMembersByHandle: handle found" ); + } + + // Test fillHandles + { + OPropertyArrayHelper a1( getPropertyTable1(), 6 ); + Sequence< OUString > aS( 4 ); + sal_Int32 Handles[4]; + // muss sortiert sein + aS.getArray()[0] = OUString( RTL_CONSTASCII_USTRINGPARAM("a") ); + aS.getArray()[1] = OUString( RTL_CONSTASCII_USTRINGPARAM("d") ); + aS.getArray()[2] = OUString( RTL_CONSTASCII_USTRINGPARAM("f") ); + aS.getArray()[3] = OUString( RTL_CONSTASCII_USTRINGPARAM("t") ); + sal_Int32 nHitCount = a1.fillHandles( Handles, aS ); + OSL_ENSURE( nHitCount == 3, "wrong number of hits " ); + OSL_ENSURE( Handles[0] == getPropertyTable1()[0].Handle, "Handle not correct" ); + OSL_ENSURE( Handles[1] == getPropertyTable1()[3].Handle, "Handle not correct" ); + OSL_ENSURE( Handles[2] == getPropertyTable1()[5].Handle, "Handle not correct" ); + OSL_ENSURE( Handles[3] == -1, "Handle not correct" ); + } +} + + + + +//---------------------------------------------------- +// test_OPropertySetHelper +//---------------------------------------------------- +struct MutexContainer +{ + Mutex aMutex; +}; +class test_OPropertySetHelper : + public MutexContainer, + public OBroadcastHelper , + public OPropertySetHelper, + public OWeakObject +{ +public: + + test_OPropertySetHelper( Property * p, sal_Int32 n ) + : MutexContainer() + , OBroadcastHelper( ((MutexContainer *)this)->aMutex ) +// , OPropertySetHelper( *SAL_STATIC_CAST(OBroadcastHelper *,this)) + // MSCI 4 bug ! : + // OBroadcastHelper == OBroadcastHelperVar<OMultiTypeInterfaceContainerHelper> + , OPropertySetHelper( + *SAL_STATIC_CAST(OBroadcastHelper *,this)) + , bBOOL( sal_False ) + , nINT16( 0 ) + , nINT32( 0 ) + , pBasicProps( p ) + , nPropCount( n ) + { + } + + + ~test_OPropertySetHelper() + { + } + + void dispose() + { + // see comphlp.cxx + sal_Bool bDoDispose = sal_False; + { + MutexGuard aGuard( rBHelper.rMutex ); + if( !rBHelper.bDisposed && !rBHelper.bInDispose ) + { + rBHelper.bInDispose = sal_True; + bDoDispose = sal_True; + } + } + if( bDoDispose ) + { + disposing(); + EventObject aEvt; + aEvt.Source = Reference < XInterface > ( SAL_STATIC_CAST( OWeakObject * ,this) ); + + rBHelper.aLC.disposeAndClear( aEvt ); + rBHelper.bDisposed = sal_True; + rBHelper.bInDispose = sal_False; + } + } + + // XInterface + Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type & rType ) throw(RuntimeException) + { + Any aRet( OPropertySetHelper::queryInterface( rType ) ); + return (aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType )); + } + void SAL_CALL acquire() throw() + { OWeakObject::acquire(); } + void SAL_CALL release() throw() + { OWeakObject::release(); } + + // XPropertySet + Reference < XPropertySetInfo > SAL_CALL getPropertySetInfo()throw(RuntimeException); + + using OPropertySetHelper::getFastPropertyValue; + + sal_Bool bBOOL; + sal_Int16 nINT16; + sal_Int32 nINT32; + Property * pBasicProps; + sal_Int32 nPropCount; +protected: + IPropertyArrayHelper & SAL_CALL getInfoHelper() throw(RuntimeException); + sal_Bool SAL_CALL convertFastPropertyValue( + Any & rConvertedValue, Any & rOldValue, + sal_Int32 nHandle, const Any& rValue ) + throw(IllegalArgumentException); + void SAL_CALL setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, const Any& rValue ) throw(RuntimeException); + void SAL_CALL getFastPropertyValue( Any& rValue, sal_Int32 nHandle ) const throw(RuntimeException); +}; + +//---------------------------------------------------------------------- +//------ The Properties of this implementation ------------------------- +//---------------------------------------------------------------------- +// Id must be the index into the array +#define PROPERTY_BOOL 0 +#define PROPERTY_INT16 1 +#define PROPERTY_INT32 2 + +// Max number of properties +#define PROPERTY_COUNT 4 +// Names of Properties +/** + * All Properties of this implementation. Must be sorted by name. + */ +Property * getBasicProps() +{ + static Property *pTable = 0; + + if( ! pTable ) { + MutexGuard guard( ::osl::Mutex::getGlobalMutex() ); + if( ! pTable ) { + + static Property aBasicProps[PROPERTY_COUNT] = + { + Property( OUString( RTL_CONSTASCII_USTRINGPARAM("BOOL") ) , PROPERTY_BOOL , getCppuBooleanType(), PropertyAttribute::READONLY ), + Property( OUString( RTL_CONSTASCII_USTRINGPARAM("INT16") ) , PROPERTY_INT16, + getCppuType( (sal_Int16*)0 ), PropertyAttribute::BOUND | PropertyAttribute::CONSTRAINED ), + Property( OUString( RTL_CONSTASCII_USTRINGPARAM("INT32") ) , PROPERTY_INT32, getCppuType( (sal_Int32*)0 ), PropertyAttribute::BOUND ), + Property( OUString( RTL_CONSTASCII_USTRINGPARAM("TEST") ) , 55 , getCppuType( (sal_Int32*)0), PropertyAttribute::BOUND ) + }; + pTable = aBasicProps; + } + } + return pTable; +} + + +//---------------------------------------------------- +// test_OPropertySetHelper_Listener +//---------------------------------------------------- +class test_OPropertySetHelper_Listener + : public WeakImplHelper3< XPropertyChangeListener, XPropertiesChangeListener, XVetoableChangeListener > +{ +public: + sal_Int32 nDisposing; + Mutex aMutex; + Any * pExceptedListenerValues; + sal_Int32 nCount; + sal_Int32 nCurrent; + + test_OPropertySetHelper_Listener( Any * p = 0, sal_Int32 n = 0 ) + : nDisposing( 0 ) + , pExceptedListenerValues( p ) + , nCount( n ) + , nCurrent( 0 ) + { + } + ~test_OPropertySetHelper_Listener() + { + } + + sal_Int32 getRefCount() const + { return m_refCount; } + + // XEventListener + void SAL_CALL disposing(const EventObject& /*evt*/) throw ( RuntimeException) + { + MutexGuard aGuard( aMutex ); + nDisposing++; + } + + // XPropertyChangeListener + void SAL_CALL propertyChange(const PropertyChangeEvent& evt) throw (RuntimeException) + { + if( !pExceptedListenerValues ) + return; + MutexGuard aGuard( aMutex ); + OSL_ENSURE( nCurrent +1 < nCount, "PropertySetHelper: too many listener calls" ); + + switch( evt.PropertyHandle ) + { + case PROPERTY_BOOL: + { + OSL_FAIL( "PropertySetHelper: BOOL cannot change" ); + OSL_ENSURE( evt.PropertyName == OUString( RTL_CONSTASCII_USTRINGPARAM("BOOL") ), "PropertySetHelper: wrong name" ); + } + break; + + case PROPERTY_INT16: + { + OSL_ENSURE( evt.PropertyName == OUString( RTL_CONSTASCII_USTRINGPARAM("INT16") ), "PropertySetHelper: wrong name" ); + + OSL_ENSURE( pExceptedListenerValues[nCurrent].getValueType().getTypeClass() == TypeClass_SHORT , + "PropertySetHelper: wrong data type" ); + + sal_Int16 nInt16(0), nOldInt16(0); + pExceptedListenerValues[nCurrent] >>= nInt16; + evt.OldValue >>= nOldInt16; + OSL_ENSURE( nInt16 == nOldInt16, "PropertySetHelper: wrong old value" ); + + + pExceptedListenerValues[nCurrent+1] >>= nInt16; + evt.NewValue >>= nOldInt16; + OSL_ENSURE( nInt16 == nOldInt16 , "PropertySetHelper: wrong new value" ); + } + break; + + case PROPERTY_INT32: + { + OSL_ENSURE( evt.PropertyName == OUString( RTL_CONSTASCII_USTRINGPARAM("INT32") ), "PropertySetHelper: wrong name" ); + + sal_Int32 nInt32(0),nOldInt32(0); + + pExceptedListenerValues[nCurrent] >>= nInt32; + evt.OldValue >>= nOldInt32; + OSL_ENSURE( nInt32 == nOldInt32 , "PropertySetHelper: wrong old value" ); + + pExceptedListenerValues[nCurrent+1] >>= nInt32; + evt.NewValue >>= nOldInt32; + OSL_ENSURE( nInt32 == nOldInt32 , "PropertySetHelper: wrong new value" ); + } + break; + + default: + OSL_FAIL( "XPropeSetHelper: invalid property handle" ); + } + nCurrent += 2; + } + + // XVetoableChangeListener + void SAL_CALL vetoableChange(const PropertyChangeEvent& evt) throw (PropertyVetoException, RuntimeException) + { + if( !pExceptedListenerValues ) + return; + MutexGuard aGuard( aMutex ); + OSL_ENSURE( nCurrent +1 < nCount, "PropertySetHelper: too many listener calls" ); + + switch( evt.PropertyHandle ) + { + case PROPERTY_BOOL: + { + OSL_FAIL( "PropertySetHelper: BOOL cannot change" ); + OSL_ENSURE( evt.PropertyName == OUString( RTL_CONSTASCII_USTRINGPARAM("BOOL") ), "PropertySetHelper: wrong name" ); + } + break; + + case PROPERTY_INT16: + { + OSL_ENSURE( evt.PropertyName == OUString( RTL_CONSTASCII_USTRINGPARAM("INT16") ), "PropertySetHelper: wrong name" ); + + sal_Int16 nInt16(0), nOldInt16(0); + pExceptedListenerValues[nCurrent] >>= nInt16; + evt.OldValue >>= nOldInt16; + + OSL_ENSURE( nInt16 == nOldInt16,"PropertySetHelper: wrong old value" ); + + pExceptedListenerValues[nCurrent+1] >>= nInt16; + evt.NewValue >>= nOldInt16; + OSL_ENSURE( nInt16 == nOldInt16 , "PropertySetHelper: wrong new value" ); + + if( nOldInt16 == 100 ) + { + nCurrent += 2; + throw PropertyVetoException(); + } + } + break; + + case PROPERTY_INT32: + { + OSL_ENSURE( evt.PropertyName == OUString( RTL_CONSTASCII_USTRINGPARAM("INT32") ), "PropertySetHelper: wrong name" ); + + sal_Int32 nInt32(0),nOldInt32(0); + pExceptedListenerValues[nCurrent] >>= nInt32; + evt.OldValue >>= nOldInt32; + OSL_ENSURE( nInt32 == nOldInt32 , "PropertySetHelper: wrong old value" ); + + pExceptedListenerValues[nCurrent+1] >>= nInt32; + evt.NewValue >>= nOldInt32; + OSL_ENSURE( nInt32 == nOldInt32 , "PropertySetHelper: wrong new value" ); + } + break; + + default: + OSL_FAIL( "XPropeSetHelper: invalid property handle" ); + } + nCurrent += 2; + } + + // XPropertiesChangeListener + void SAL_CALL propertiesChange(const Sequence< PropertyChangeEvent >& evtSeq) throw (RuntimeException) + { + if( !pExceptedListenerValues ) + return; + MutexGuard aGuard( aMutex ); + for( sal_Int32 i = 0; i < evtSeq.getLength(); i++ ) + { + const PropertyChangeEvent & evt = evtSeq.getConstArray()[i]; + OSL_ENSURE( nCurrent +1 < nCount, "PropertySetHelper: too many listener calls" ); + + switch( evt.PropertyHandle ) + { + case PROPERTY_BOOL: + { + OSL_FAIL( "PropertySetHelper: BOOL cannot change" ); + OSL_ENSURE( evt.PropertyName == OUString( RTL_CONSTASCII_USTRINGPARAM("BOOL") ), "PropertySetHelper: wrong name" ); + } + break; + + case PROPERTY_INT16: + { + OSL_ENSURE( evt.PropertyName == OUString( RTL_CONSTASCII_USTRINGPARAM("INT16") ), "PropertySetHelper: wrong name" ); + + sal_Int16 nInt16(0), nOldInt16(0); + pExceptedListenerValues[nCurrent] >>= nInt16; + evt.OldValue >>= nOldInt16; + OSL_ENSURE( nInt16 == nOldInt16 , "PropertySetHelper: wrong old value" ); + + + pExceptedListenerValues[nCurrent+1] >>= nInt16; + evt.NewValue >>= nOldInt16; + OSL_ENSURE( nInt16 == nOldInt16 , "PropertySetHelper: wrong new value" ); + } + break; + + case PROPERTY_INT32: + { + OSL_ENSURE( evt.PropertyName == OUString( RTL_CONSTASCII_USTRINGPARAM("INT32") ), "PropertySetHelper: wrong name" ); + + + sal_Int32 nInt32(0),nOldInt32(0); + pExceptedListenerValues[nCurrent] >>= nInt32; + evt.OldValue >>= nOldInt32; + OSL_ENSURE( nInt32 == nOldInt32 , "PropertySetHelper: wrong old value" ); + + pExceptedListenerValues[nCurrent+1] >>= nInt32; + evt.NewValue >>= nOldInt32; + OSL_ENSURE( nInt32 == nOldInt32 , "PropertySetHelper: wrong new value" ); + } + break; + + default: + OSL_FAIL( "XPropeSetHelper: invalid property handle" ); + } + nCurrent += 2; + } + } +}; + +/** + * Create a table that map names to index values. + */ +IPropertyArrayHelper & test_OPropertySetHelper::getInfoHelper() throw(RuntimeException) +{ + // no multi thread protection + static OPropertyArrayHelper aInfo( pBasicProps, nPropCount ); + return aInfo; +} + +// XPropertySet +Reference < XPropertySetInfo > test_OPropertySetHelper::getPropertySetInfo() + throw(RuntimeException) +{ + // no multi thread protection + static Reference < XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) ); + return xInfo; +} + +// Return sal_True, value changed +sal_Bool test_OPropertySetHelper::convertFastPropertyValue +( + Any & rConvertedValue, + Any & rOldValue, + sal_Int32 nHandle, + const Any& rValue +)throw(IllegalArgumentException) +{ + switch( nHandle ) + { + case PROPERTY_BOOL: + { + sal_Bool b; + convertPropertyValue( b , rValue ); + if( b != bBOOL ) + { + + rConvertedValue.setValue( &b , ::getCppuBooleanType() ); + rOldValue.setValue( & bBOOL , ::getCppuBooleanType() ); + return sal_True; + } + else + return sal_False; + } + + case PROPERTY_INT16: + { + sal_Int16 n16; + convertPropertyValue( n16 , rValue ); + + if( n16 != nINT16 ) + { + rConvertedValue <<= n16; + rOldValue <<= nINT16; + return sal_True; + } + else + return sal_False; + } + + case PROPERTY_INT32: + { + sal_Int32 n32; + convertPropertyValue( n32 , rValue ); + if( n32 != nINT32 ) + { + rConvertedValue <<= n32; + rOldValue <<= nINT32; + return sal_True; + } + else + return sal_False; + } + + default: + OSL_ENSURE( nHandle == -1, "invalid property handle" ); + return sal_False; + } +} + +/** + * only set the value. + */ +void test_OPropertySetHelper::setFastPropertyValue_NoBroadcast +( + sal_Int32 nHandle, + const Any& rValue +)throw(RuntimeException) +{ + switch( nHandle ) + { + case PROPERTY_BOOL: + OSL_ENSURE( rValue.getValueType().getTypeClass() == TypeClass_BOOLEAN, "invalid type" ); + bBOOL = *((sal_Bool*)rValue.getValue()); + break; + + case PROPERTY_INT16: + OSL_ENSURE( rValue.getValueType().getTypeClass() == TypeClass_SHORT, "invalid type" ); + rValue >>= nINT16; + break; + + case PROPERTY_INT32: + OSL_ENSURE( rValue.getValueType().getTypeClass() == TypeClass_LONG, "invalid type" ); + rValue >>= nINT32; + break; + + default: + OSL_ENSURE( nHandle == -1, "invalid property handle" ); + } +} + +//-------------------------- +void test_OPropertySetHelper::getFastPropertyValue( Any & rRet, sal_Int32 nHandle ) const + throw(RuntimeException) +{ + switch( nHandle ) + { + case PROPERTY_BOOL: + rRet.setValue( &bBOOL , getCppuBooleanType() ); + break; + + case PROPERTY_INT16: + rRet <<= nINT16; + break; + + case PROPERTY_INT32: + rRet <<= nINT32; + break; + + default: + OSL_ENSURE( nHandle == -1, "invalid property handle" ); + } +} + + +void test_PropertySetHelper() +{ + test_PropertyArrayHelper(); + + test_OPropertySetHelper * pPS; + + Reference < XPropertySet > xPS; + Reference < XPropertyChangeListener > xPS_L; + test_OPropertySetHelper_Listener * pPS_L; + + Reference < XInterface > x; + + for( int z = 0; z < 2; z++ ) + { + // first test aBasicProps Handles are { 0, 1, 2, 55 } + // first test getBasicProps() Handles are { 0, 1, 2 } + xPS = pPS = new test_OPropertySetHelper( getBasicProps(), PROPERTY_COUNT - z ); + xPS_L = static_cast< XPropertyChangeListener * >( pPS_L = new test_OPropertySetHelper_Listener() ); + + // Test queryInterface + Reference < XPropertySet > rProp( xPS , UNO_QUERY ); + OSL_ENSURE( rProp.is() , "PropertySetHelper: XPropertySet nor supported" ); + + Reference < XMultiPropertySet > rMulti( xPS , UNO_QUERY ); + OSL_ENSURE( rMulti.is() , "PropertySetHelper: XMultiPropertySet nor supported" ); + + Reference < XFastPropertySet > rFast( xPS , UNO_QUERY ); + OSL_ENSURE( rFast.is() , "PropertySetHelper: XFastPropertySet nor supported" ); + + x = Reference < XInterface > (); + + // Test add-remove listener + { + Reference < XPropertiesChangeListener > x1( xPS_L, UNO_QUERY ); + Reference < XVetoableChangeListener > x2( xPS_L, UNO_QUERY ); + + xPS->addPropertyChangeListener( OUString( RTL_CONSTASCII_USTRINGPARAM("INT16") ), xPS_L ); + Sequence<OUString> szPN( 3 ); + szPN.getArray()[0] = OUString( RTL_CONSTASCII_USTRINGPARAM("BOOL") ); + szPN.getArray()[1] = OUString( RTL_CONSTASCII_USTRINGPARAM("INT32") ); + szPN.getArray()[2] = OUString( RTL_CONSTASCII_USTRINGPARAM("Does not exist") ); // must ne ignored by the addPropertiesChangeListener method + pPS->addPropertiesChangeListener( szPN, x1 ); + + szPN = Sequence<OUString>(); + pPS->addPropertiesChangeListener( szPN, x1 ); + pPS->addVetoableChangeListener( OUString( RTL_CONSTASCII_USTRINGPARAM("INT16") ), x2 ); + + xPS->removePropertyChangeListener( OUString( RTL_CONSTASCII_USTRINGPARAM("INT16") ), xPS_L ); + pPS->removePropertiesChangeListener( x1 ); + pPS->removePropertiesChangeListener( x1 ); + pPS->removeVetoableChangeListener( OUString( RTL_CONSTASCII_USTRINGPARAM("INT16") ), x2 ); + + // this exception must thrown + try + { + xPS->addPropertyChangeListener( OUString( RTL_CONSTASCII_USTRINGPARAM("Does not exist") ), xPS_L ); + OSL_FAIL( "PropertySetHelper: exeption not thrown" ); + } + catch( UnknownPropertyException & /*e*/ ) + { + + } + + try + { + xPS->addVetoableChangeListener( OUString( RTL_CONSTASCII_USTRINGPARAM("Does not exist") ), x2 ); + OSL_FAIL( "PropertySetHelper: exeption not thrown" ); + } + catch( UnknownPropertyException & /*e*/ ) + { + + } + + } + OSL_ENSURE( pPS_L->getRefCount() == 1, "PropertySetHelper: wrong reference count" ); + + // Test disposing + { + Reference < XPropertiesChangeListener > x1( xPS_L, UNO_QUERY ); + Reference < XVetoableChangeListener > x2( xPS_L, UNO_QUERY ); + + xPS->addPropertyChangeListener( OUString( RTL_CONSTASCII_USTRINGPARAM("INT16") ), xPS_L ); + Sequence<OUString> szPN( 2 ); + szPN.getArray()[0] = OUString( RTL_CONSTASCII_USTRINGPARAM("BOOL") ); + szPN.getArray()[1] = OUString( RTL_CONSTASCII_USTRINGPARAM("INT32") ); + pPS->addPropertiesChangeListener( szPN, x1 ); + szPN = Sequence<OUString>(); + pPS->addPropertiesChangeListener( szPN, x1 ); + pPS->addVetoableChangeListener( OUString( RTL_CONSTASCII_USTRINGPARAM("INT16") ), x2 ); + pPS->dispose(); + } + OSL_ENSURE( pPS_L->nDisposing == 4 , "PropertySetHelper: wrong disposing count" ); + OSL_ENSURE( pPS_L->getRefCount() == 1 , "PropertySetHelper: wrong reference count" ); + pPS_L->nDisposing = 0; + xPS = pPS = new test_OPropertySetHelper( getBasicProps(), PROPERTY_COUNT - z ); + + // Test set- and get- (Fast) propertyValue + { + // set read only property + try + { + // Readonly raises a vetoable exception + sal_Bool b = sal_True; + Any aBool; + aBool.setValue( &b , getCppuBooleanType() ); + xPS->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("BOOL") ), aBool ); + OSL_FAIL( "PropertySetHelper: exeption not thrown" ); + } + catch( PropertyVetoException & /*e*/ ) + { + } + + try + { + // Readonly raises a vetoable exception + sal_Bool b = sal_True; + Any aBool; + aBool.setValue( &b , getCppuBooleanType() ); + // BOOL i s0 + pPS->setFastPropertyValue( PROPERTY_BOOL, aBool ); + OSL_FAIL( "PropertySetHelper: exeption not thrown" ); + } + catch( PropertyVetoException & /*e*/ ) + { + } + + // set unknown property + try + { + sal_Bool b = sal_True; + Any aBool; + aBool.setValue( &b , getCppuBooleanType() ); + xPS->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("Does not exist") ), aBool ); + OSL_FAIL( "PropertySetHelper: exeption not thrown" ); + } + catch( UnknownPropertyException & /*e*/ ) + { + } + + try + { + sal_Bool b = sal_True; + Any aBool; + aBool.setValue( &b , getCppuBooleanType() ); + pPS->setFastPropertyValue( 3, aBool ); + OSL_FAIL( "PropertySetHelper: exeption not thrown" ); + } + catch( UnknownPropertyException & /*e*/ ) + { + } + + // get unknown property + try + { + Any aBool; + aBool = xPS->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("Does not exist") ) ); + OSL_FAIL( "PropertySetHelper: exeption not thrown" ); + } + catch( UnknownPropertyException & /*e*/ ) + { + } + + try + { + Any aBool; + aBool = ((XFastPropertySet *)pPS)->getFastPropertyValue( 3 ); + OSL_FAIL( "PropertySetHelper: exeption not thrown" ); + } + catch( UnknownPropertyException & /*e*/ ) + { + } + + // set property with invalid type + try + { + Any aBool; + xPS->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("INT32") ), aBool ); + OSL_FAIL( "PropertySetHelper: exeption not thrown" ); + } + catch( IllegalArgumentException & /*e*/ ) + { + } + + try + { + Any aBool; + pPS->setFastPropertyValue( PROPERTY_INT32, aBool ); + OSL_FAIL( "PropertySetHelper: exeption not thrown" ); + } + catch( IllegalArgumentException & /*e*/ ) + { + } + + // narrowing conversion is not allowed! + try + { + Any aINT32; + aINT32 <<= (sal_Int32 ) 16; + xPS->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("INT16") ), aINT32 ); + OSL_FAIL( "PropertySetHelper: exeption not thrown" ); + } + catch( IllegalArgumentException & /*e*/ ) + { + } + + + try + { + Any aINT32; + aINT32 <<= (sal_Int32) 16; + pPS->setFastPropertyValue( PROPERTY_INT16, aINT32 ); + OSL_FAIL( "PropertySetHelper: exeption not thrown" ); + } + catch( IllegalArgumentException & /*e*/ ) + { + } + + + Any aValue; + aValue = xPS->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("BOOL") ) ); + sal_Bool b = *( (sal_Bool*)aValue.getValue()); + OSL_ENSURE( ! b, "PropertySetHelper: wrong BOOL value" ); + aValue = ((XFastPropertySet *)pPS)->getFastPropertyValue( PROPERTY_BOOL ); + + b = *((sal_Bool*)aValue.getValue()); + OSL_ENSURE( !b, "PropertySetHelper: wrong BOOL value" ); + + sal_Int16 n16(0); + aValue <<=(sal_Int16)22; + xPS->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("INT16") ), aValue ); + aValue = xPS->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("INT16") ) ); + aValue >>= n16; + OSL_ENSURE( 22 == n16 , "PropertySetHelper: wrong INT16 value" ); + aValue <<= (sal_Int16)44; + ((XFastPropertySet *)pPS)->setFastPropertyValue( PROPERTY_INT16, aValue ); + + aValue = ((XFastPropertySet *)pPS)->getFastPropertyValue( PROPERTY_INT16 ); + aValue >>= n16; + OSL_ENSURE( 44 == n16, "PropertySetHelper: wrong INT16 value" ); + + // widening conversion + aValue <<= (sal_Int16)55; + xPS->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("INT32") ), aValue ); + aValue = xPS->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("INT32") ) ); + sal_Int32 n32(0); + aValue >>= n32; + OSL_ENSURE( 55 == n32 , "PropertySetHelper: wrong INT32 value" ); + aValue <<= (sal_Int16)66; + ((XFastPropertySet *)pPS)->setFastPropertyValue( PROPERTY_INT32, aValue ); + aValue = ((XFastPropertySet *)pPS)->getFastPropertyValue( PROPERTY_INT32 ); + aValue >>= n32; + OSL_ENSURE( 66 == n32, "PropertySetHelper: wrong INT32 value" ); + + Sequence< OUString >valueNames = Sequence<OUString>( 3 ); + valueNames.getArray()[0] = OUString( RTL_CONSTASCII_USTRINGPARAM("BOOL") ); + valueNames.getArray()[1] = OUString( RTL_CONSTASCII_USTRINGPARAM("INT16") ); + valueNames.getArray()[2] = OUString( RTL_CONSTASCII_USTRINGPARAM("INT32") ); + Sequence< Any > aValues = pPS->getPropertyValues( valueNames ); + + b = *((sal_Bool*)aValues.getConstArray()[0].getValue()); + aValues.getConstArray()[1] >>= n16; + aValues.getConstArray()[2] >>= n32; + + OSL_ENSURE( !b, "PropertySetHelper: wrong BOOL value" ); + OSL_ENSURE( 44 == n16, "PropertySetHelper: wrong INT16 value" ); + OSL_ENSURE( 66 == n32, "PropertySetHelper: wrong INT32 value" ); + } + pPS->nINT32 = 0; + pPS->nINT16 = 0; + + // Test add-remove listener + { + Reference < XVetoableChangeListener > x2( xPS_L, UNO_QUERY ); + + xPS->addPropertyChangeListener( OUString( RTL_CONSTASCII_USTRINGPARAM("INT16") ), xPS_L ); + pPS->addVetoableChangeListener( OUString( RTL_CONSTASCII_USTRINGPARAM("INT16") ), x2 ); + + pPS_L->nCount = 10; + Sequence< Any > aSeq( pPS_L->nCount ); + pPS_L->nCurrent = 0; + + pPS_L->pExceptedListenerValues = aSeq.getArray(); + + pPS_L->pExceptedListenerValues[0] <<= (sal_Int16) 0; // old value vetoable + pPS_L->pExceptedListenerValues[1] <<= (sal_Int16) 22; // new value vetoable + pPS_L->pExceptedListenerValues[2] <<= (sal_Int16) 0; // old value bound + pPS_L->pExceptedListenerValues[3] <<= (sal_Int16) 22; // new value bound + pPS_L->pExceptedListenerValues[4] <<= (sal_Int16) 22; // old value vetoable + pPS_L->pExceptedListenerValues[5] <<= (sal_Int16) 44; // new value vetoable + pPS_L->pExceptedListenerValues[6] <<= (sal_Int16) 22; // old value bound + pPS_L->pExceptedListenerValues[7] <<= (sal_Int16) 44; // new value bound + pPS_L->pExceptedListenerValues[8] <<= (sal_Int16) 44; // old value vetoable + pPS_L->pExceptedListenerValues[9] <<= (sal_Int16) 100; // new value vetoable exception + + Any aValue; + aValue <<= (sal_Int16)22; + xPS->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("INT16") ), aValue ); + aValue <<= (sal_Int16) 44; + ((XFastPropertySet *)pPS)->setFastPropertyValue( PROPERTY_INT16, aValue ); + aValue <<= (sal_Int16)100;// exception + + try + { + ((XFastPropertySet *)pPS)->setFastPropertyValue( PROPERTY_INT16, aValue ); + OSL_FAIL( "PropertySetHelper: exeption not thrown" ); + } + catch( PropertyVetoException & /*e*/ ) + { + } + + OSL_ENSURE( pPS_L->nCount == pPS_L->nCurrent, "not all listeners called" ); + pPS->nINT32 = 0; + pPS->nINT16 = 0; + pPS_L->nCount = 0; + pPS_L->nCurrent = 0; + pPS_L->pExceptedListenerValues = NULL; + xPS->removePropertyChangeListener( OUString( RTL_CONSTASCII_USTRINGPARAM("INT16") ), xPS_L ); + pPS->removeVetoableChangeListener( OUString( RTL_CONSTASCII_USTRINGPARAM("INT16") ), x2 ); + } + + // Test multi property set listener + { + Reference < XPropertiesChangeListener > x1( xPS_L, UNO_QUERY ); + Reference < XVetoableChangeListener > x2( xPS_L, UNO_QUERY ); + + pPS->addVetoableChangeListener( OUString( RTL_CONSTASCII_USTRINGPARAM("INT16") ) , x2 ); + Sequence<OUString> szPN( 4 ); + szPN.getArray()[0] = OUString( RTL_CONSTASCII_USTRINGPARAM("BOOL") ); + szPN.getArray()[1] = OUString( RTL_CONSTASCII_USTRINGPARAM("INT32") ); + szPN.getArray()[2] = OUString( RTL_CONSTASCII_USTRINGPARAM("Does not exist") ); // must ne ignored by the addPropertiesChangeListener method + szPN.getArray()[3] = OUString( RTL_CONSTASCII_USTRINGPARAM("INT16") ); + pPS->addPropertiesChangeListener( szPN, x1 ); + + pPS_L->nCount = 6; + Sequence< Any > aSeq( pPS_L->nCount ); + pPS_L->nCurrent = 0; + pPS_L->pExceptedListenerValues = aSeq.getArray(); + pPS_L->pExceptedListenerValues[0] <<= (sal_Int16) 0; // old value vetoable + pPS_L->pExceptedListenerValues[1] <<= (sal_Int16 ) 22; // new value vetoable + // INT32 is not constrained + pPS_L->pExceptedListenerValues[2] <<= (sal_Int16) 0; // old value bound + pPS_L->pExceptedListenerValues[3] <<= (sal_Int16) 22; // new value bound + pPS_L->pExceptedListenerValues[4] <<= (sal_Int32) 0; // old value bound + pPS_L->pExceptedListenerValues[5] <<= (sal_Int32) 44; // new value bound + + szPN = Sequence<OUString>( 2 ); + szPN.getArray()[0] = OUString( RTL_CONSTASCII_USTRINGPARAM("INT16") ); + szPN.getArray()[1] = OUString( RTL_CONSTASCII_USTRINGPARAM("INT32") ); + Sequence< Any > aValues( 2 ); + aValues.getArray()[0] <<= (sal_Int16) 22; + aValues.getArray()[1] <<= (sal_Int16) 44; + pPS->setPropertyValues( szPN, aValues ); + OSL_ENSURE( pPS_L->nCount == pPS_L->nCurrent, "not all listeners called" ); + + //firePropertiesChangeEvent + pPS->nINT16 = 8; + pPS->nINT32 = 5; + pPS_L->nCount = 4; + pPS_L->nCurrent = 0; + pPS_L->pExceptedListenerValues[0] <<= (sal_Int16) 8; // old value + pPS_L->pExceptedListenerValues[1] <<= (sal_Int16) 8; // new value + pPS_L->pExceptedListenerValues[2] <<= (sal_Int32) 5; // old value + pPS_L->pExceptedListenerValues[3] <<= (sal_Int32) 5; // new value + pPS->firePropertiesChangeEvent( szPN, pPS_L ); + OSL_ENSURE( pPS_L->nCount == pPS_L->nCurrent, "not all listeners called" ); + + + //vetoable exception with multible + szPN.getArray()[0] = OUString( RTL_CONSTASCII_USTRINGPARAM("INT16") ); + szPN.getArray()[1] = OUString( RTL_CONSTASCII_USTRINGPARAM("INT16") ); + pPS->nINT32 = 0; + pPS->nINT16 = 0; + pPS_L->nCount = 4; + pPS_L->nCurrent = 0; + pPS_L->pExceptedListenerValues[0] <<= (sal_Int16) 0; // old value vetoable + pPS_L->pExceptedListenerValues[1] <<= (sal_Int16) 44; // new value vetoable + pPS_L->pExceptedListenerValues[2] <<= (sal_Int16) 0; // old value vetoable + pPS_L->pExceptedListenerValues[3] <<= (sal_Int16) 100; // new value vetoable + + try + { + aValues.getArray()[0] <<= (sal_Int16)44; + aValues.getArray()[1] <<= (sal_Int16)100; + pPS->setPropertyValues( szPN, aValues ); + OSL_FAIL( "PropertySetHelper: exeption not thrown" ); + } + catch ( PropertyVetoException & /*e*/ ) + { + } + + OSL_ENSURE( pPS_L->nCount == pPS_L->nCurrent, "not all listeners called" ); + pPS->removePropertiesChangeListener( x1 ); + pPS->removeVetoableChangeListener( OUString( RTL_CONSTASCII_USTRINGPARAM("INT16") ), x2 ); + } + } +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/cppuhelper/test/testproptyphlp.cxx b/cppuhelper/test/testproptyphlp.cxx new file mode 100644 index 000000000000..d913c7879b60 --- /dev/null +++ b/cppuhelper/test/testproptyphlp.cxx @@ -0,0 +1,87 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_cppuhelper.hxx" +#include <cppuhelper/proptypehlp.hxx> + +#include <com/sun/star/beans/Property.hpp> + +using namespace ::com::sun::star::uno; +using namespace ::cppu; + +void testPropertyTypeHelper() +{ + Any a; + + a <<= ( sal_Int8 ) 25; + + sal_Int32 i; + convertPropertyValue( i , a ); + OSL_ASSERT( 25 == i ); + + sal_Int16 i16; + convertPropertyValue( i16 , a ); + OSL_ASSERT( 25 == i16 ); + + sal_Int8 i8; + convertPropertyValue( i8 , a ); + OSL_ASSERT( 25 == i8 ); + + sal_uInt32 i32; + convertPropertyValue( i32 , a ); + OSL_ASSERT( 25 == i32 ); + + double d; + convertPropertyValue( d , a ); + OSL_ASSERT( 25. == d ); + + float f; + convertPropertyValue( f , a ); + OSL_ASSERT( 25. == f ); + + ::com::sun::star::beans::Property prop; + + prop.Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Huhu") ); + prop.Handle = 5; + prop.Attributes = 3; + + a <<= prop; + + ::com::sun::star::beans::Property prop2; + convertPropertyValue( prop2 , a ); + OSL_ASSERT( prop.Handle == prop2.Handle && prop.Name == prop2.Name && prop.Attributes == prop2.Attributes ); + + + ::rtl::OUString ow; + a <<= prop.Name; + convertPropertyValue( ow , a ); + OSL_ASSERT( ow == prop.Name ); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |