diff options
Diffstat (limited to 'cppuhelper/qa/propertysetmixin')
-rw-r--r-- | cppuhelper/qa/propertysetmixin/JavaSupplier.java | 308 | ||||
-rw-r--r-- | cppuhelper/qa/propertysetmixin/comp_propertysetmixin.cxx | 407 | ||||
-rw-r--r-- | cppuhelper/qa/propertysetmixin/manifest | 2 | ||||
-rw-r--r-- | cppuhelper/qa/propertysetmixin/qa_propertysetmixin.cpp.component | 25 | ||||
-rw-r--r-- | cppuhelper/qa/propertysetmixin/qa_propertysetmixin.java.component | 25 | ||||
-rw-r--r-- | cppuhelper/qa/propertysetmixin/test_propertysetmixin.cxx | 639 | ||||
-rw-r--r-- | cppuhelper/qa/propertysetmixin/types.idl | 79 |
7 files changed, 1485 insertions, 0 deletions
diff --git a/cppuhelper/qa/propertysetmixin/JavaSupplier.java b/cppuhelper/qa/propertysetmixin/JavaSupplier.java new file mode 100644 index 000000000..a82e2bd7f --- /dev/null +++ b/cppuhelper/qa/propertysetmixin/JavaSupplier.java @@ -0,0 +1,308 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +package test.cppuhelper.propertysetmixin.comp; + +import com.sun.star.beans.Ambiguous; +import com.sun.star.beans.Defaulted; +import com.sun.star.beans.Optional; +import com.sun.star.beans.UnknownPropertyException; +import com.sun.star.beans.PropertyValue; +import com.sun.star.beans.PropertyVetoException; +import com.sun.star.beans.XFastPropertySet; +import com.sun.star.beans.XPropertyAccess; +import com.sun.star.beans.XPropertyChangeListener; +import com.sun.star.beans.XPropertySet; +import com.sun.star.beans.XPropertySetInfo; +import com.sun.star.beans.XVetoableChangeListener; +import com.sun.star.comp.loader.FactoryHelper; +import com.sun.star.lang.WrappedTargetException; +import com.sun.star.lang.XComponent; +import com.sun.star.lang.XEventListener; +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.lang.XSingleServiceFactory; +import com.sun.star.lib.uno.helper.WeakBase; +import com.sun.star.lib.uno.helper.PropertySetMixin; +import com.sun.star.registry.XRegistryKey; +import com.sun.star.uno.Any; +import com.sun.star.uno.IQueryInterface; +import com.sun.star.uno.Type; +import com.sun.star.uno.XComponentContext; +import test.cppuhelper.propertysetmixin.XSupplier; +import test.cppuhelper.propertysetmixin.XTest3; + +public final class JavaSupplier extends WeakBase implements XSupplier { + public JavaSupplier(XComponentContext context) { + this.context = context; + } + + public XComponent getEmpty1() { return new Empty1(); } + + public XComponent getEmpty2() { return new Empty2(); } + + public XTest3 getFull() { return new Full(); } + + public static XSingleServiceFactory __getServiceFactory( + String implName, XMultiServiceFactory multiFactory, XRegistryKey regKey) + { + return implName.equals(implementationName) + ? FactoryHelper.getServiceFactory( + JavaSupplier.class, serviceName, multiFactory, regKey) + : null; + } + + private static final String implementationName + = JavaSupplier.class.getName(); + private static final String serviceName + = "test.cppuhelper.propertysetmixin.JavaSupplier"; + + private final class Empty1 extends WeakBase implements XComponent { + public Empty1() {} + + public void dispose() { + prop.dispose(); + } + + public void addEventListener(XEventListener listener) {} + + public void removeEventListener(XEventListener listener) {} + + private final PropertySetMixin prop = new PropertySetMixin( + context, this, new Type(XComponent.class), null); + } + + private final class Empty2 extends WeakBase + implements XComponent, XPropertySet, XFastPropertySet, XPropertyAccess + { + public Empty2() {} + + public void dispose() { + prop.dispose(); + } + + public void addEventListener(XEventListener listener) {} + + public void removeEventListener(XEventListener listener) {} + + public com.sun.star.beans.XPropertySetInfo getPropertySetInfo() { + return prop.getPropertySetInfo(); + } + + public void setPropertyValue(String propertyName, Object value) + throws UnknownPropertyException, PropertyVetoException, + com.sun.star.lang.IllegalArgumentException, WrappedTargetException + { + prop.setPropertyValue(propertyName, value); + } + + public Object getPropertyValue(String propertyName) + throws UnknownPropertyException, WrappedTargetException + { + return prop.getPropertyValue(propertyName); + } + + public void addPropertyChangeListener( + String propertyName, XPropertyChangeListener listener) + throws UnknownPropertyException, WrappedTargetException + { + prop.addPropertyChangeListener(propertyName, listener); + } + + public void removePropertyChangeListener( + String propertyName, XPropertyChangeListener listener) + throws UnknownPropertyException, WrappedTargetException + { + prop.removePropertyChangeListener(propertyName, listener); + } + + public void addVetoableChangeListener( + String propertyName, XVetoableChangeListener listener) + throws UnknownPropertyException, WrappedTargetException + { + prop.addVetoableChangeListener(propertyName, listener); + } + + public void removeVetoableChangeListener( + String propertyName, XVetoableChangeListener listener) + throws UnknownPropertyException, WrappedTargetException + { + prop.removeVetoableChangeListener(propertyName, listener); + } + + public void setFastPropertyValue(int handle, Object value) + throws UnknownPropertyException, PropertyVetoException, + com.sun.star.lang.IllegalArgumentException, WrappedTargetException + { + prop.setFastPropertyValue(handle, value); + } + + public Object getFastPropertyValue(int handle) + throws UnknownPropertyException, WrappedTargetException + { + return prop.getFastPropertyValue(handle); + } + + public PropertyValue[] getPropertyValues() { + return prop.getPropertyValues(); + } + + public void setPropertyValues(PropertyValue[] props) + throws UnknownPropertyException, PropertyVetoException, + com.sun.star.lang.IllegalArgumentException, WrappedTargetException + { + prop.setPropertyValues(props); + } + + private final PropertySetMixin prop = new PropertySetMixin( + context, this, new Type(XComponent.class), null); + } + + private final class Full extends WeakBase + implements XTest3, XPropertySet, XFastPropertySet, XPropertyAccess + { + public Full() {} + + public synchronized int getFirst() { + return a1; + } + + public void setFirst(int value) { + prop.prepareSet("First", null); + synchronized (this) { + a1 = value; + } + } + + public synchronized Ambiguous getSecond() + throws UnknownPropertyException + { + return a2; + } + + public void setSecond(Ambiguous value) + throws PropertyVetoException, UnknownPropertyException + { + PropertySetMixin.BoundListeners l + = new PropertySetMixin.BoundListeners(); + prop.prepareSet( + "Second", Any.VOID, + (((Optional) ((Defaulted) value.Value).Value).IsPresent + ? ((Optional) ((Defaulted) value.Value).Value).Value + : Any.VOID), + l); + synchronized (this) { + a2 = value; + } + l.notifyListeners(); + } + + public int getThird() throws UnknownPropertyException { + throw new UnknownPropertyException("Third", this); + } + + public void setThird(int value) throws UnknownPropertyException { + throw new UnknownPropertyException("Third", this); + } + + public int getFourth() throws UnknownPropertyException { + throw new UnknownPropertyException("Fourth", this); + } + + public void setFourth(int value) throws UnknownPropertyException { + throw new UnknownPropertyException("Fourth", this); + } + + public com.sun.star.beans.XPropertySetInfo getPropertySetInfo() { + return prop.getPropertySetInfo(); + } + + public void setPropertyValue(String propertyName, Object value) + throws UnknownPropertyException, PropertyVetoException, + com.sun.star.lang.IllegalArgumentException, WrappedTargetException + { + prop.setPropertyValue(propertyName, value); + } + + public Object getPropertyValue(String propertyName) + throws UnknownPropertyException, WrappedTargetException + { + return prop.getPropertyValue(propertyName); + } + + public void addPropertyChangeListener( + String propertyName, XPropertyChangeListener listener) + throws UnknownPropertyException, WrappedTargetException + { + prop.addPropertyChangeListener(propertyName, listener); + } + + public void removePropertyChangeListener( + String propertyName, XPropertyChangeListener listener) + throws UnknownPropertyException, WrappedTargetException + { + prop.removePropertyChangeListener(propertyName, listener); + } + + public void addVetoableChangeListener( + String propertyName, XVetoableChangeListener listener) + throws UnknownPropertyException, WrappedTargetException + { + prop.addVetoableChangeListener(propertyName, listener); + } + + public void removeVetoableChangeListener( + String propertyName, XVetoableChangeListener listener) + throws UnknownPropertyException, WrappedTargetException + { + prop.removeVetoableChangeListener(propertyName, listener); + } + + public void setFastPropertyValue(int handle, Object value) + throws UnknownPropertyException, PropertyVetoException, + com.sun.star.lang.IllegalArgumentException, WrappedTargetException + { + prop.setFastPropertyValue(handle, value); + } + + public Object getFastPropertyValue(int handle) + throws UnknownPropertyException, WrappedTargetException + { + return prop.getFastPropertyValue(handle); + } + + public PropertyValue[] getPropertyValues() { + return prop.getPropertyValues(); + } + + public void setPropertyValues(PropertyValue[] props) + throws UnknownPropertyException, PropertyVetoException, + com.sun.star.lang.IllegalArgumentException, WrappedTargetException + { + prop.setPropertyValues(props); + } + + private final PropertySetMixin prop = new PropertySetMixin( + context, this, new Type(XTest3.class), new String[] { "Third" }); + + private int a1 = 0; + private Ambiguous a2 = new Ambiguous( + new Defaulted(new Optional(), true), false); + } + + private final XComponentContext context; +} diff --git a/cppuhelper/qa/propertysetmixin/comp_propertysetmixin.cxx b/cppuhelper/qa/propertysetmixin/comp_propertysetmixin.cxx new file mode 100644 index 000000000..4de84ba3a --- /dev/null +++ b/cppuhelper/qa/propertysetmixin/comp_propertysetmixin.cxx @@ -0,0 +1,407 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + + +#include <sal/config.h> + +#include <test/cppuhelper/propertysetmixin/XSupplier.hpp> +#include <test/cppuhelper/propertysetmixin/XTest3.hpp> + +#include <com/sun/star/beans/Ambiguous.hpp> +#include <com/sun/star/beans/Defaulted.hpp> +#include <com/sun/star/beans/Optional.hpp> +#include <com/sun/star/beans/PropertyVetoException.hpp> +#include <com/sun/star/beans/UnknownPropertyException.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <cppuhelper/propertysetmixin.hxx> +#include <cppuhelper/factory.hxx> +#include <cppuhelper/implbase.hxx> +#include <cppuhelper/implementationentry.hxx> +#include <cppuhelper/queryinterface.hxx> +#include <cppuhelper/weak.hxx> +#include <com/sun/star/uno/Any.hxx> +#include <com/sun/star/uno/Exception.hpp> +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/RuntimeException.hpp> +#include <com/sun/star/uno/Sequence.hxx> +#include <com/sun/star/uno/Type.hxx> +#include <com/sun/star/uno/XComponentContext.hpp> +#include <com/sun/star/uno/XInterface.hpp> +#include <osl/mutex.hxx> +#include <rtl/ustring.h> +#include <rtl/ustring.hxx> +#include <sal/types.h> + +namespace com::sun::star { + class XEventListener; +} } } + +namespace { + +class Empty1: + public cppu::OWeakObject, public css::lang::XComponent, + public cppu::PropertySetMixin< css::lang::XComponent > +{ +public: + explicit Empty1( + css::uno::Reference< css::uno::XComponentContext > const & context): + cppu::PropertySetMixin< css::lang::XComponent >( + context, static_cast< Implements >(0), + css::uno::Sequence< OUString >()) + {} + + virtual css::uno::Any SAL_CALL queryInterface(css::uno::Type const & type) + throw (css::uno::RuntimeException); + + virtual void SAL_CALL acquire() throw () { OWeakObject::acquire(); } + + virtual void SAL_CALL release() throw () { OWeakObject::release(); } + + virtual void SAL_CALL dispose() throw (css::uno::RuntimeException) { + cppu::PropertySetMixin< css::lang::XComponent >::dispose(); + } + + virtual void SAL_CALL addEventListener( + css::uno::Reference< css::lang::XEventListener > const &) + throw (css::uno::RuntimeException) + {} + + virtual void SAL_CALL removeEventListener( + css::uno::Reference< css::lang::XEventListener > const &) + throw (css::uno::RuntimeException) + {} + +private: + Empty1(Empty1 &); // not defined + void operator =(Empty1 &); // not defined + + virtual ~Empty1() {} +}; + +css::uno::Any Empty1::queryInterface(css::uno::Type const & type) + throw (css::uno::RuntimeException) +{ + css::uno::Any a(OWeakObject::queryInterface(type)); + if (a.hasValue()) { + return a; + } + a = cppu::queryInterface( + type, static_cast< css::lang::XComponent * >(this)); + return a.hasValue() + ? a + : cppu::PropertySetMixin< css::lang::XComponent >::queryInterface( + type); +} + +class Empty2: + public cppu::OWeakObject, public css::lang::XComponent, + public cppu::PropertySetMixin< css::lang::XComponent > +{ +public: + explicit Empty2( + css::uno::Reference< css::uno::XComponentContext > const & context): + cppu::PropertySetMixin< css::lang::XComponent >( + context, + static_cast< Implements >( + IMPLEMENTS_PROPERTY_SET | IMPLEMENTS_FAST_PROPERTY_SET + | IMPLEMENTS_PROPERTY_ACCESS), + css::uno::Sequence< OUString >()) + {} + + virtual css::uno::Any SAL_CALL queryInterface(css::uno::Type const & type) + throw (css::uno::RuntimeException); + + virtual void SAL_CALL acquire() throw () { OWeakObject::acquire(); } + + virtual void SAL_CALL release() throw () { OWeakObject::release(); } + + virtual void SAL_CALL dispose() throw (css::uno::RuntimeException) { + cppu::PropertySetMixin< css::lang::XComponent >::dispose(); + } + + virtual void SAL_CALL addEventListener( + css::uno::Reference< css::lang::XEventListener > const &) + throw (css::uno::RuntimeException) + {} + + virtual void SAL_CALL removeEventListener( + css::uno::Reference< css::lang::XEventListener > const &) + throw (css::uno::RuntimeException) + {} + +private: + Empty2(Empty2 &); // not defined + void operator =(Empty2 &); // not defined + + virtual ~Empty2() {} +}; + +css::uno::Any Empty2::queryInterface(css::uno::Type const & type) + throw (css::uno::RuntimeException) +{ + css::uno::Any a(OWeakObject::queryInterface(type)); + if (a.hasValue()) { + return a; + } + a = cppu::queryInterface( + type, static_cast< css::lang::XComponent * >(this)); + return a.hasValue() + ? a + : cppu::PropertySetMixin< css::lang::XComponent >::queryInterface( + type); +} + +css::uno::Sequence< OUString > sequenceThird() { + css::uno::Sequence<OUString> s { OUString("Third") }; + return s; +} + +class Full: + public cppu::OWeakObject, public test::cppuhelper::propertysetmixin::XTest3, + public cppu::PropertySetMixin< + test::cppuhelper::propertysetmixin::XTest3 > +{ +public: + explicit Full( + css::uno::Reference< css::uno::XComponentContext > const & context): + cppu::PropertySetMixin< + test::cppuhelper::propertysetmixin::XTest3 >( + context, + static_cast< Implements >( + IMPLEMENTS_PROPERTY_SET | IMPLEMENTS_FAST_PROPERTY_SET + | IMPLEMENTS_PROPERTY_ACCESS), + sequenceThird()), + m_a1(0), + m_a2( + css::beans::Defaulted< css::beans::Optional< sal_Int32 > >( + css::beans::Optional< sal_Int32 >(), true), + false) + {} + + virtual css::uno::Any SAL_CALL queryInterface(css::uno::Type const & type) + throw (css::uno::RuntimeException); + + virtual void SAL_CALL acquire() throw () { OWeakObject::acquire(); } + + virtual void SAL_CALL release() throw () { OWeakObject::release(); } + + virtual sal_Int32 SAL_CALL getFirst() throw (css::uno::RuntimeException); + + virtual void SAL_CALL setFirst(sal_Int32 value) + throw (css::uno::RuntimeException); + + virtual + css::beans::Ambiguous< + css::beans::Defaulted< css::beans::Optional< sal_Int32 > > > + SAL_CALL getSecond() + throw ( + css::beans::UnknownPropertyException, css::uno::RuntimeException); + + virtual void SAL_CALL setSecond( + css::beans::Ambiguous< + css::beans::Defaulted< css::beans::Optional< ::sal_Int32 > > > const & + value) + throw ( + css::beans::PropertyVetoException, + css::beans::UnknownPropertyException, css::uno::RuntimeException); + + virtual sal_Int32 SAL_CALL getThird() + throw ( + css::beans::UnknownPropertyException, css::uno::RuntimeException); + + virtual void SAL_CALL setThird(sal_Int32 value) + throw ( + css::beans::UnknownPropertyException, css::uno::RuntimeException); + + virtual sal_Int32 SAL_CALL getFourth() + throw ( + css::beans::UnknownPropertyException, css::uno::RuntimeException); + + virtual void SAL_CALL setFourth(sal_Int32 value) + throw ( + css::beans::UnknownPropertyException, css::uno::RuntimeException); + +private: + Full(Full &); // not defined + void operator =(Full &); // not defined + + virtual ~Full() {} + + osl::Mutex m_mutex; + sal_Int32 m_a1; + css::beans::Ambiguous< + css::beans::Defaulted< css::beans::Optional< sal_Int32 > > > m_a2; +}; + +css::uno::Any Full::queryInterface(css::uno::Type const & type) + throw (css::uno::RuntimeException) +{ + css::uno::Any a(OWeakObject::queryInterface(type)); + if (a.hasValue()) { + return a; + } + a = cppu::queryInterface( + type, + static_cast< test::cppuhelper::propertysetmixin::XTest3 * >(this)); + return a.hasValue() + ? a + : (cppu::PropertySetMixin< + test::cppuhelper::propertysetmixin::XTest3 >::queryInterface( + type)); +} + +sal_Int32 Full::getFirst() throw (css::uno::RuntimeException) { + osl::MutexGuard g(m_mutex); + return m_a1; +} + +void Full::setFirst(sal_Int32 value) throw (css::uno::RuntimeException) { + prepareSet( + OUString("First"), css::uno::Any(), + css::uno::Any(), 0); + osl::MutexGuard g(m_mutex); + m_a1 = value; +} + +css::beans::Ambiguous< + css::beans::Defaulted< css::beans::Optional< sal_Int32 > > > +Full::getSecond() + throw (css::beans::UnknownPropertyException, css::uno::RuntimeException) +{ + osl::MutexGuard g(m_mutex); + return m_a2; +} + +void Full::setSecond( + css::beans::Ambiguous< + css::beans::Defaulted< css::beans::Optional< ::sal_Int32 > > > const & + value) + throw ( + css::beans::PropertyVetoException, css::beans::UnknownPropertyException, + css::uno::RuntimeException) +{ + css::uno::Any v; + if (value.Value.Value.IsPresent) { + v <<= value.Value.Value.Value; + } + BoundListeners l; + prepareSet( + OUString("Second"), css::uno::Any(), + v, &l); + { + osl::MutexGuard g(m_mutex); + m_a2 = value; + } + l.notify(); +} + +sal_Int32 Full::getThird() + throw (css::beans::UnknownPropertyException, css::uno::RuntimeException) +{ + throw css::beans::UnknownPropertyException( + OUString("Third"), + static_cast< cppu::OWeakObject * >(this)); +} + +void Full::setThird(sal_Int32) + throw (css::beans::UnknownPropertyException, css::uno::RuntimeException) +{ + throw css::beans::UnknownPropertyException( + OUString("Third"), + static_cast< cppu::OWeakObject * >(this)); +} + +sal_Int32 Full::getFourth() + throw (css::beans::UnknownPropertyException, css::uno::RuntimeException) +{ + throw css::beans::UnknownPropertyException( + OUString("Fourth"), + static_cast< cppu::OWeakObject * >(this)); +} + +void Full::setFourth(sal_Int32) + throw (css::beans::UnknownPropertyException, css::uno::RuntimeException) +{ + throw css::beans::UnknownPropertyException( + OUString("Fourth"), + static_cast< cppu::OWeakObject * >(this)); +} + +class Supplier: + public cppu::WeakImplHelper< + test::cppuhelper::propertysetmixin::XSupplier > +{ +public: + explicit Supplier( + css::uno::Reference< css::uno::XComponentContext > const & context): + m_context(context) {} + + virtual css::uno::Reference< css::lang::XComponent > SAL_CALL getEmpty1() + throw (css::uno::RuntimeException) + { return new Empty1(m_context); } + + virtual css::uno::Reference< css::lang::XComponent > SAL_CALL getEmpty2() + throw (css::uno::RuntimeException) + { return new Empty2(m_context); } + + virtual css::uno::Reference< test::cppuhelper::propertysetmixin::XTest3 > + SAL_CALL getFull() throw (css::uno::RuntimeException) + { return new Full(m_context); } + +private: + Supplier(Supplier &); // not defined + void operator =(Supplier &); // not defined + + virtual ~Supplier() {} + + css::uno::Reference< css::uno::XComponentContext > m_context; +}; + +css::uno::Reference< css::uno::XInterface > SAL_CALL create( + css::uno::Reference< css::uno::XComponentContext > const & context) +{ + return static_cast< cppu::OWeakObject * >(new Supplier(context)); +} + +OUString SAL_CALL getImplementationName() { + return OUString( + "test.cppuhelper.propertysetmixin.comp.CppSupplier"); +} + +css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() +{ + css::uno::Sequence< OUString > s { "test.cppuhelper.propertysetmixin.CppSupplier") }; + return s; +} + +cppu::ImplementationEntry entries[] = { + { &create, &getImplementationName, &getSupportedServiceNames, + &cppu::createSingleComponentFactory, 0, 0 }, + { 0, 0, 0, 0, 0, 0 } }; + +} + +extern "C" SAL_DLLPUBLIC_EXPORT void * SAL_CALL mixin_component_getFactory( + char const * implName, void * serviceManager, void * registryKey) +{ + return cppu::component_getFactoryHelper( + implName, serviceManager, registryKey, entries); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/cppuhelper/qa/propertysetmixin/manifest b/cppuhelper/qa/propertysetmixin/manifest new file mode 100644 index 000000000..168f4bc19 --- /dev/null +++ b/cppuhelper/qa/propertysetmixin/manifest @@ -0,0 +1,2 @@ +Manifest-Version: 1.0 +RegistrationClassName: test.cppuhelper.propertysetmixin.comp.JavaSupplier diff --git a/cppuhelper/qa/propertysetmixin/qa_propertysetmixin.cpp.component b/cppuhelper/qa/propertysetmixin/qa_propertysetmixin.cpp.component new file mode 100644 index 000000000..eebe9b725 --- /dev/null +++ b/cppuhelper/qa/propertysetmixin/qa_propertysetmixin.cpp.component @@ -0,0 +1,25 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + --> + +<component loader="com.sun.star.loader.SharedLibrary" environment="@CPPU_ENV@" + prefix="mixin" xmlns="http://openoffice.org/2010/uno-components"> + <implementation name="test.cppuhelper.propertysetmixin.comp.CppSupplier"> + <service name="test.cppuhelper.propertysetmixin.CppSupplier"/> + </implementation> +</component> diff --git a/cppuhelper/qa/propertysetmixin/qa_propertysetmixin.java.component b/cppuhelper/qa/propertysetmixin/qa_propertysetmixin.java.component new file mode 100644 index 000000000..887dfe6f0 --- /dev/null +++ b/cppuhelper/qa/propertysetmixin/qa_propertysetmixin.java.component @@ -0,0 +1,25 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + --> + +<component loader="com.sun.star.loader.Java2" + xmlns="http://openoffice.org/2010/uno-components"> + <implementation name="test.cppuhelper.propertysetmixin.comp.JavaSupplier"> + <service name="test.cppuhelper.propertysetmixin.JavaSupplier"/> + </implementation> +</component> diff --git a/cppuhelper/qa/propertysetmixin/test_propertysetmixin.cxx b/cppuhelper/qa/propertysetmixin/test_propertysetmixin.cxx new file mode 100644 index 000000000..d6679dae5 --- /dev/null +++ b/cppuhelper/qa/propertysetmixin/test_propertysetmixin.cxx @@ -0,0 +1,639 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <test/cppuhelper/propertysetmixin/CppSupplier.hpp> +#include <test/cppuhelper/propertysetmixin/JavaSupplier.hpp> +#include <test/cppuhelper/propertysetmixin/XSupplier.hpp> +#include <test/cppuhelper/propertysetmixin/XTest3.hpp> + +#include <com/sun/star/beans/Ambiguous.hpp> +#include <com/sun/star/beans/Defaulted.hpp> +#include <com/sun/star/beans/Optional.hpp> +#include <com/sun/star/beans/Property.hpp> +#include <com/sun/star/beans/PropertyAttribute.hpp> +#include <com/sun/star/beans/PropertyChangeEvent.hpp> +#include <com/sun/star/beans/PropertyState.hpp> +#include <com/sun/star/beans/PropertyValue.hpp> +#include <com/sun/star/beans/PropertyVetoException.hpp> +#include <com/sun/star/beans/UnknownPropertyException.hpp> +#include <com/sun/star/beans/XFastPropertySet.hpp> +#include <com/sun/star/beans/XPropertyAccess.hpp> +#include <com/sun/star/beans/XPropertyChangeListener.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/beans/XPropertySetInfo.hpp> +#include <com/sun/star/beans/XVetoableChangeListener.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/uno/Any.hxx> +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/RuntimeException.hpp> +#include <com/sun/star/uno/Sequence.hxx> +#include <com/sun/star/uno/Type.hxx> +#include <com/sun/star/uno/XComponentContext.hpp> +#include <cppuhelper/bootstrap.hxx> +#include <cppuhelper/implbase.hxx> +#include "cppunit/TestAssert.h" +#include "cppunit/TestFixture.h" +#include "cppunit/extensions/HelperMacros.h" +#include "cppunit/plugin/TestPlugIn.h" +#include <osl/mutex.hxx> +#include <rtl/ref.hxx> +#include <rtl/string.h> +#include <rtl/textenc.h> +#include <rtl/ustring.h> +#include <rtl/ustring.hxx> +#include <sal/types.h> + +#include <limits> +#include <ostream> + +namespace com::sun::star { + struct EventObject; +} } } + +namespace { + +std::ostream & operator <<(std::ostream & out, OUString const & value) { + return out << OUStringToOString(value, RTL_TEXTENCODING_UTF8).getStr(); +} + +std::ostream & operator <<(std::ostream & out, css::uno::Type const & value) { + return out << "com::sun::star::uno::Type[" << value.getTypeName() << ']'; +} + +std::ostream & operator <<(std::ostream & out, css::uno::Any const & value) { + return + out << "com::sun::star::uno::Any[" << value.getValueType() << ", ...]"; +} + +class BoundListener: + public cppu::WeakImplHelper< css::beans::XPropertyChangeListener > +{ +public: + BoundListener(): m_count(0) {} + + int count() const { + osl::MutexGuard g(m_mutex); + return m_count; + } + + virtual void SAL_CALL disposing(css::lang::EventObject const &) + throw (css::uno::RuntimeException) + { + osl::MutexGuard g(m_mutex); + CPPUNIT_ASSERT(m_count < std::numeric_limits< int >::max()); + ++m_count; + } + + virtual void SAL_CALL propertyChange( + css::beans::PropertyChangeEvent const &) + throw (css::uno::RuntimeException) + { CPPUNIT_FAIL("BoundListener::propertyChange called"); } + +private: + BoundListener(BoundListener &); // not defined + void operator =(BoundListener &); // not defined + + virtual ~BoundListener() {} + + mutable osl::Mutex m_mutex; + int m_count; +}; + +class VetoListener: + public cppu::WeakImplHelper< css::beans::XVetoableChangeListener > +{ +public: + VetoListener(): m_count(0) {} + + int count() const { + osl::MutexGuard g(m_mutex); + return m_count; + } + + virtual void SAL_CALL disposing(css::lang::EventObject const &) + throw (css::uno::RuntimeException) + { + osl::MutexGuard g(m_mutex); + CPPUNIT_ASSERT(m_count < std::numeric_limits< int >::max()); + ++m_count; + } + + virtual void SAL_CALL vetoableChange( + css::beans::PropertyChangeEvent const &) + throw (css::beans::PropertyVetoException, css::uno::RuntimeException) + { CPPUNIT_FAIL("VetoListener::vetoableChange called"); } + +private: + VetoListener(VetoListener &); // not defined + void operator =(VetoListener &); // not defined + + virtual ~VetoListener() {} + + mutable osl::Mutex m_mutex; + int m_count; +}; + +class Test: public CppUnit::TestFixture { +public: + virtual void setUp(); + + virtual void tearDown(); + + void testCppEmpty1() { testEmpty1(getCppSupplier()); } + + void testCppEmpty2() { testEmpty2(getCppSupplier()); } + + void testCppFull() { testFull(getCppSupplier()); } + + void testJavaEmpty1() { testEmpty1(getJavaSupplier()); } + + void testJavaEmpty2() { testEmpty2(getJavaSupplier()); } + + void testJavaFull() { testFull(getJavaSupplier()); } + + CPPUNIT_TEST_SUITE(Test); + CPPUNIT_TEST(testCppEmpty1); + CPPUNIT_TEST(testCppEmpty2); + CPPUNIT_TEST(testCppFull); + CPPUNIT_TEST(testJavaEmpty1); + CPPUNIT_TEST(testJavaEmpty2); + CPPUNIT_TEST(testJavaFull); + CPPUNIT_TEST_SUITE_END(); + +private: + css::uno::Reference< test::cppuhelper::propertysetmixin::XSupplier > + getCppSupplier() const; + + css::uno::Reference< test::cppuhelper::propertysetmixin::XSupplier > + getJavaSupplier() const; + + void testEmpty1( + css::uno::Reference< test::cppuhelper::propertysetmixin::XSupplier > + const & supplier) const; + + void testEmpty2( + css::uno::Reference< test::cppuhelper::propertysetmixin::XSupplier > + const & supplier) const; + + void testFull( + css::uno::Reference< test::cppuhelper::propertysetmixin::XSupplier > + const & supplier) const; + + css::uno::Reference< css::uno::XComponentContext > m_context; +}; + +void Test::setUp() { + m_context = cppu::defaultBootstrap_InitialComponentContext(); + CPPUNIT_ASSERT(m_context.is()); +} + +void Test::tearDown() { + css::uno::Reference< css::lang::XComponent >( + m_context, css::uno::UNO_QUERY_THROW)->dispose(); +} + +css::uno::Reference< test::cppuhelper::propertysetmixin::XSupplier > +Test::getCppSupplier() const +{ + return test::cppuhelper::propertysetmixin::CppSupplier::create(m_context); +} + +css::uno::Reference< test::cppuhelper::propertysetmixin::XSupplier > +Test::getJavaSupplier() const +{ + return test::cppuhelper::propertysetmixin::JavaSupplier::create(m_context); +} + +void Test::testEmpty1( + css::uno::Reference< test::cppuhelper::propertysetmixin::XSupplier > + const & supplier) const +{ + css::uno::Reference< css::lang::XComponent > empty1( + supplier->getEmpty1(), css::uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT( + !css::uno::Reference< css::beans::XPropertySet >( + empty1, css::uno::UNO_QUERY).is()); + CPPUNIT_ASSERT( + !css::uno::Reference< css::beans::XFastPropertySet >( + empty1, css::uno::UNO_QUERY).is()); + CPPUNIT_ASSERT( + !css::uno::Reference< css::beans::XPropertyAccess >( + empty1, css::uno::UNO_QUERY).is()); + empty1->dispose(); +} + +void Test::testEmpty2( + css::uno::Reference< test::cppuhelper::propertysetmixin::XSupplier > + const & supplier) const +{ + css::uno::Reference< css::lang::XComponent > empty2( + supplier->getEmpty2(), css::uno::UNO_QUERY_THROW); + css::uno::Reference< css::beans::XPropertySet > empty2p( + empty2, css::uno::UNO_QUERY); + CPPUNIT_ASSERT(empty2p.is()); + css::uno::Reference< css::beans::XPropertySetInfo > info( + empty2p->getPropertySetInfo()); + CPPUNIT_ASSERT(info.is()); + CPPUNIT_ASSERT_EQUAL( + static_cast< sal_Int32 >(0), info->getProperties().getLength()); + try { + info->getPropertyByName( + OUString("any")); + CPPUNIT_FAIL("exception expected"); + } catch (css::beans::UnknownPropertyException &) {} + CPPUNIT_ASSERT( + !info->hasPropertyByName( + OUString("any"))); + try { + empty2p->setPropertyValue( + OUString("any"), css::uno::Any()); + CPPUNIT_FAIL("exception expected"); + } catch (css::beans::UnknownPropertyException &) {} + try { + empty2p->getPropertyValue( + OUString("any")); + CPPUNIT_FAIL("exception expected"); + } catch (css::beans::UnknownPropertyException &) {} + rtl::Reference boundListener1(new BoundListener); + empty2p->addPropertyChangeListener(OUString(), boundListener1.get()); + empty2p->addPropertyChangeListener(OUString(), boundListener1.get()); + rtl::Reference boundListener2(new BoundListener); + empty2p->removePropertyChangeListener( + OUString(), boundListener2.get()); + rtl::Reference vetoListener1(new VetoListener); + empty2p->addVetoableChangeListener(OUString(), vetoListener1.get()); + empty2p->addVetoableChangeListener(OUString(), vetoListener1.get()); + rtl::Reference vetoListener2(new VetoListener); + empty2p->addVetoableChangeListener(OUString(), vetoListener2.get()); + empty2p->removeVetoableChangeListener(OUString(), vetoListener2.get()); + css::uno::Reference< css::beans::XFastPropertySet > empty2f( + empty2, css::uno::UNO_QUERY); + CPPUNIT_ASSERT(empty2f.is()); + try { + empty2f->setFastPropertyValue(-1, css::uno::Any()); + CPPUNIT_FAIL("exception expected"); + } catch (css::beans::UnknownPropertyException &) {} + try { + empty2f->setFastPropertyValue(0, css::uno::Any()); + CPPUNIT_FAIL("exception expected"); + } catch (css::beans::UnknownPropertyException &) {} + try { + empty2f->getFastPropertyValue(-1); + CPPUNIT_FAIL("exception expected"); + } catch (css::beans::UnknownPropertyException &) {} + try { + empty2f->getFastPropertyValue(0); + CPPUNIT_FAIL("exception expected"); + } catch (css::beans::UnknownPropertyException &) {} + css::uno::Reference< css::beans::XPropertyAccess > empty2a( + empty2, css::uno::UNO_QUERY); + CPPUNIT_ASSERT(empty2a.is()); + CPPUNIT_ASSERT_EQUAL( + static_cast< sal_Int32 >(0), empty2a->getPropertyValues().getLength()); + empty2a->setPropertyValues( + css::uno::Sequence< css::beans::PropertyValue >()); + css::uno::Sequence< css::beans::PropertyValue > vs(2); + vs[0].Name = OUString("any1"); + vs[0].Handle = -1; + vs[0].State = css::beans::PropertyState_DIRECT_VALUE; + vs[0].Name = OUString("any2"); + vs[0].Handle = -1; + vs[0].State = css::beans::PropertyState_DIRECT_VALUE; + try { + empty2a->setPropertyValues(vs); + CPPUNIT_FAIL("exception expected"); + } catch (css::beans::UnknownPropertyException &) {} + CPPUNIT_ASSERT_EQUAL(0, boundListener1->count()); + CPPUNIT_ASSERT_EQUAL(0, boundListener2->count()); + CPPUNIT_ASSERT_EQUAL(0, vetoListener1->count()); + CPPUNIT_ASSERT_EQUAL(0, vetoListener2->count()); + empty2->dispose(); + CPPUNIT_ASSERT_EQUAL(2, boundListener1->count()); + CPPUNIT_ASSERT_EQUAL(0, boundListener2->count()); + CPPUNIT_ASSERT_EQUAL(2, vetoListener1->count()); + CPPUNIT_ASSERT_EQUAL(0, vetoListener2->count()); + empty2p->removePropertyChangeListener( + OUString(), boundListener1.get()); + empty2p->removePropertyChangeListener( + OUString(), boundListener2.get()); + empty2p->removeVetoableChangeListener(OUString(), vetoListener1.get()); + empty2p->removeVetoableChangeListener(OUString(), vetoListener2.get()); + empty2p->addPropertyChangeListener(OUString(), boundListener1.get()); + empty2p->addPropertyChangeListener(OUString(), boundListener2.get()); + empty2p->addVetoableChangeListener(OUString(), vetoListener1.get()); + empty2p->addVetoableChangeListener(OUString(), vetoListener2.get()); + try { + empty2p->addPropertyChangeListener( + OUString(), + css::uno::Reference< css::beans::XPropertyChangeListener >()); + } catch (css::uno::RuntimeException &) {} + try { + empty2p->addVetoableChangeListener( + OUString(), + css::uno::Reference< css::beans::XVetoableChangeListener >()); + } catch (css::uno::RuntimeException &) {} + CPPUNIT_ASSERT_EQUAL(3, boundListener1->count()); + CPPUNIT_ASSERT_EQUAL(1, boundListener2->count()); + CPPUNIT_ASSERT_EQUAL(3, vetoListener1->count()); + CPPUNIT_ASSERT_EQUAL(1, vetoListener2->count()); +} + +void Test::testFull( + css::uno::Reference< test::cppuhelper::propertysetmixin::XSupplier > + const & supplier) const +{ + css::uno::Reference< test::cppuhelper::propertysetmixin::XTest3 > full( + supplier->getFull(), css::uno::UNO_QUERY_THROW); + css::uno::Reference< css::beans::XPropertySet > fullp( + full, css::uno::UNO_QUERY); + CPPUNIT_ASSERT(fullp.is()); + css::uno::Reference< css::beans::XPropertySetInfo > info( + fullp->getPropertySetInfo()); + CPPUNIT_ASSERT(info.is()); + CPPUNIT_ASSERT_EQUAL( + static_cast< sal_Int32 >(3), info->getProperties().getLength()); + css::beans::Property prop( + info->getPropertyByName( + OUString("First"))); + CPPUNIT_ASSERT_EQUAL( + OUString("First"), prop.Name); + CPPUNIT_ASSERT_EQUAL(static_cast< sal_Int32 >(0), prop.Handle); + CPPUNIT_ASSERT_EQUAL(cppu::UnoType<sal_Int32>::get(), prop.Type); + CPPUNIT_ASSERT_EQUAL(static_cast< sal_Int16 >(0), prop.Attributes); + prop = info->getPropertyByName( + OUString("Second")); + CPPUNIT_ASSERT_EQUAL( + OUString("Second"), prop.Name); + CPPUNIT_ASSERT_EQUAL(static_cast< sal_Int32 >(1), prop.Handle); + CPPUNIT_ASSERT_EQUAL(cppu::UnoType<sal_Int32>::get(), prop.Type); + CPPUNIT_ASSERT_EQUAL( + static_cast< sal_Int16 >( + css::beans::PropertyAttribute::MAYBEVOID + | css::beans::PropertyAttribute::BOUND + | css::beans::PropertyAttribute::CONSTRAINED + | css::beans::PropertyAttribute::MAYBEAMBIGUOUS + | css::beans::PropertyAttribute::MAYBEDEFAULT + | css::beans::PropertyAttribute::OPTIONAL), + prop.Attributes); + try { + info->getPropertyByName( + OUString("Third")); + CPPUNIT_FAIL("exception expected"); + } catch (css::beans::UnknownPropertyException &) {} + prop = info->getPropertyByName( + OUString("Fourth")); + CPPUNIT_ASSERT_EQUAL( + OUString("Fourth"), prop.Name); + CPPUNIT_ASSERT_EQUAL(static_cast< sal_Int32 >(3), prop.Handle); + CPPUNIT_ASSERT_EQUAL(cppu::UnoType<sal_Int32>::get(), prop.Type); + CPPUNIT_ASSERT_EQUAL( + static_cast< sal_Int16 >(css::beans::PropertyAttribute::OPTIONAL), + prop.Attributes); + try { + info->getPropertyByName( + OUString("first")); + CPPUNIT_FAIL("exception expected"); + } catch (css::beans::UnknownPropertyException &) {} + CPPUNIT_ASSERT( + info->hasPropertyByName( + OUString("First"))); + CPPUNIT_ASSERT( + info->hasPropertyByName( + OUString("Second"))); + CPPUNIT_ASSERT( + !info->hasPropertyByName( + OUString("Third"))); + CPPUNIT_ASSERT( + info->hasPropertyByName( + OUString("Fourth"))); + CPPUNIT_ASSERT( + !info->hasPropertyByName( + OUString("first"))); + CPPUNIT_ASSERT_EQUAL( + css::uno::Any(static_cast< sal_Int32 >(0)), + fullp->getPropertyValue( + OUString("First"))); + fullp->setPropertyValue( + OUString("First"), + css::uno::Any(static_cast< sal_Int32 >(-100))); + CPPUNIT_ASSERT_EQUAL( + css::uno::Any(static_cast< sal_Int32 >(-100)), + fullp->getPropertyValue( + OUString("First"))); + css::uno::Any voidAny; + CPPUNIT_ASSERT_EQUAL( + voidAny, + fullp->getPropertyValue( + OUString("Second"))); + fullp->setPropertyValue( + OUString("Second"), + css::uno::Any(static_cast< sal_Int32 >(100))); + CPPUNIT_ASSERT_EQUAL( + css::uno::Any(static_cast< sal_Int32 >(100)), + fullp->getPropertyValue( + OUString("Second"))); + CPPUNIT_ASSERT(full->getSecond().Value.Value.IsPresent); + CPPUNIT_ASSERT_EQUAL( + static_cast< sal_Int32 >(100), full->getSecond().Value.Value.Value); + CPPUNIT_ASSERT(!full->getSecond().Value.IsDefaulted); + CPPUNIT_ASSERT(!full->getSecond().IsAmbiguous); + fullp->setPropertyValue( + OUString("Second"), + css::uno::Any()); + CPPUNIT_ASSERT_EQUAL( + voidAny, + fullp->getPropertyValue( + OUString("Second"))); + CPPUNIT_ASSERT(!full->getSecond().Value.Value.IsPresent); + CPPUNIT_ASSERT(!full->getSecond().Value.IsDefaulted); + CPPUNIT_ASSERT(!full->getSecond().IsAmbiguous); + try { + fullp->setPropertyValue( + OUString("Third"), + css::uno::Any(static_cast< sal_Int32 >(100))); + CPPUNIT_FAIL("exception expected"); + } catch (css::beans::UnknownPropertyException &) {} + try { + fullp->getPropertyValue( + OUString("Third")); + CPPUNIT_FAIL("exception expected"); + } catch (css::beans::UnknownPropertyException &) {} + try { + fullp->setPropertyValue( + OUString("Fourth"), + css::uno::Any(static_cast< sal_Int32 >(100))); + CPPUNIT_FAIL("exception expected"); + } catch (css::beans::UnknownPropertyException &) {} + try { + fullp->getPropertyValue( + OUString("Fourth")); + CPPUNIT_FAIL("exception expected"); + } catch (css::beans::UnknownPropertyException &) {} + try { + fullp->setPropertyValue( + OUString("first"), + css::uno::Any()); + CPPUNIT_FAIL("exception expected"); + } catch (css::beans::UnknownPropertyException &) {} + try { + fullp->getPropertyValue( + OUString("first")); + CPPUNIT_FAIL("exception expected"); + } catch (css::beans::UnknownPropertyException &) {} + css::uno::Reference< css::beans::XFastPropertySet > fullf( + full, css::uno::UNO_QUERY); + CPPUNIT_ASSERT(fullf.is()); + CPPUNIT_ASSERT_EQUAL( + css::uno::Any(static_cast< sal_Int32 >(-100)), + fullf->getFastPropertyValue(0)); + fullf->setFastPropertyValue( + 0, css::uno::Any(static_cast< sal_Int32 >(0))); + CPPUNIT_ASSERT_EQUAL( + css::uno::Any(static_cast< sal_Int32 >(0)), + fullf->getFastPropertyValue(0)); + try { + fullf->getFastPropertyValue(-1); + } catch (css::beans::UnknownPropertyException &) {} + try { + fullf->setFastPropertyValue(-1, css::uno::Any()); + } catch (css::beans::UnknownPropertyException &) {} + css::uno::Reference< css::beans::XPropertyAccess > fulla( + full, css::uno::UNO_QUERY); + CPPUNIT_ASSERT(fulla.is()); + css::uno::Sequence< css::beans::PropertyValue > vs( + fulla->getPropertyValues()); + CPPUNIT_ASSERT_EQUAL(static_cast< sal_Int32 >(2), vs.getLength()); + CPPUNIT_ASSERT_EQUAL( + OUString("First"), vs[0].Name); + CPPUNIT_ASSERT_EQUAL(static_cast< sal_Int32 >(0), vs[0].Handle); + CPPUNIT_ASSERT_EQUAL( + css::uno::Any(static_cast< sal_Int32 >(0)), vs[0].Value); + CPPUNIT_ASSERT_EQUAL(css::beans::PropertyState_DIRECT_VALUE, vs[0].State); + CPPUNIT_ASSERT_EQUAL( + OUString("Second"), vs[1].Name); + CPPUNIT_ASSERT_EQUAL(static_cast< sal_Int32 >(1), vs[1].Handle); + CPPUNIT_ASSERT_EQUAL(voidAny, vs[1].Value); + CPPUNIT_ASSERT_EQUAL(css::beans::PropertyState_DIRECT_VALUE, vs[1].State); + vs[0].Value <<= static_cast< sal_Int32 >(-100); + vs[1].Value <<= static_cast< sal_Int32 >(100); + vs[1].State = css::beans::PropertyState_AMBIGUOUS_VALUE; + fulla->setPropertyValues(vs); + vs = fulla->getPropertyValues(); + CPPUNIT_ASSERT_EQUAL(static_cast< sal_Int32 >(2), vs.getLength()); + CPPUNIT_ASSERT_EQUAL( + OUString("First"), vs[0].Name); + CPPUNIT_ASSERT_EQUAL( + css::uno::Any(static_cast< sal_Int32 >(-100)), vs[0].Value); + CPPUNIT_ASSERT_EQUAL(css::beans::PropertyState_DIRECT_VALUE, vs[0].State); + CPPUNIT_ASSERT_EQUAL( + OUString("Second"), vs[1].Name); + CPPUNIT_ASSERT_EQUAL( + css::uno::Any(static_cast< sal_Int32 >(100)), vs[1].Value); + CPPUNIT_ASSERT_EQUAL( + css::beans::PropertyState_AMBIGUOUS_VALUE, vs[1].State); + CPPUNIT_ASSERT(full->getSecond().Value.Value.IsPresent); + CPPUNIT_ASSERT_EQUAL( + static_cast< sal_Int32 >(100), full->getSecond().Value.Value.Value); + CPPUNIT_ASSERT(!full->getSecond().Value.IsDefaulted); + CPPUNIT_ASSERT(full->getSecond().IsAmbiguous); + css::uno::Reference< css::beans::XPropertyChangeListener > boundListener( + new BoundListener); + fullp->addPropertyChangeListener( + OUString("First"), boundListener); + fullp->removePropertyChangeListener( + OUString("First"), boundListener); + fullp->addPropertyChangeListener( + OUString("Second"), boundListener); + fullp->removePropertyChangeListener( + OUString("Second"), boundListener); + try { + fullp->addPropertyChangeListener( + OUString("Third"), + boundListener); + CPPUNIT_FAIL("exception expected"); + } catch (css::beans::UnknownPropertyException &) {} + try { + fullp->removePropertyChangeListener( + OUString("Third"), + boundListener); + CPPUNIT_FAIL("exception expected"); + } catch (css::beans::UnknownPropertyException &) {} + fullp->addPropertyChangeListener( + OUString("Fourth"), boundListener); + fullp->removePropertyChangeListener( + OUString("Fourth"), boundListener); + try { + fullp->addPropertyChangeListener( + OUString("Fifth"), + boundListener); + CPPUNIT_FAIL("exception expected"); + } catch (css::beans::UnknownPropertyException &) {} + try { + fullp->removePropertyChangeListener( + OUString("Fifth"), + boundListener); + CPPUNIT_FAIL("exception expected"); + } catch (css::beans::UnknownPropertyException &) {} + css::uno::Reference< css::beans::XVetoableChangeListener > vetoListener( + new VetoListener); + fullp->addVetoableChangeListener( + OUString("First"), vetoListener); + fullp->removeVetoableChangeListener( + OUString("First"), vetoListener); + fullp->addVetoableChangeListener( + OUString("Second"), vetoListener); + fullp->removeVetoableChangeListener( + OUString("Second"), vetoListener); + try { + fullp->addVetoableChangeListener( + OUString("Third"), + vetoListener); + CPPUNIT_FAIL("exception expected"); + } catch (css::beans::UnknownPropertyException &) {} + try { + fullp->removeVetoableChangeListener( + OUString("Third"), + vetoListener); + CPPUNIT_FAIL("exception expected"); + } catch (css::beans::UnknownPropertyException &) {} + fullp->addVetoableChangeListener( + OUString("Fourth"), vetoListener); + fullp->removeVetoableChangeListener( + OUString("Fourth"), vetoListener); + try { + fullp->addVetoableChangeListener( + OUString("Fifth"), + vetoListener); + CPPUNIT_FAIL("exception expected"); + } catch (css::beans::UnknownPropertyException &) {} + try { + fullp->removeVetoableChangeListener( + OUString("Fifth"), + vetoListener); + CPPUNIT_FAIL("exception expected"); + } catch (css::beans::UnknownPropertyException &) {} +} + +CPPUNIT_TEST_SUITE_REGISTRATION(Test); + +} + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/cppuhelper/qa/propertysetmixin/types.idl b/cppuhelper/qa/propertysetmixin/types.idl new file mode 100644 index 000000000..ee1958032 --- /dev/null +++ b/cppuhelper/qa/propertysetmixin/types.idl @@ -0,0 +1,79 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef __testtools_servicetests_TestService1_idl__ +#define __testtools_servicetests_TestService1_idl__ + +#include <com/sun/star/beans/Ambiguous.idl> +#include <com/sun/star/beans/Defaulted.idl> +#include <com/sun/star/beans/Optional.idl> +#include <com/sun/star/beans/PropertyVetoException.idl> +#include <com/sun/star/beans/UnknownPropertyException.idl> +#include <com/sun/star/lang/XComponent.idl> +#include <com/sun/star/uno/XInterface.idl> + +module test { module cppuhelper { module propertysetmixin { + +interface XTest1 { + [attribute] long First; +}; + +interface XTest2 { + [attribute, bound] + com::sun::star::beans::Ambiguous< + com::sun::star::beans::Defaulted< + com::sun::star::beans::Optional< long > > > Second + { + get raises (com::sun::star::beans::UnknownPropertyException); + set raises ( + com::sun::star::beans::PropertyVetoException, + com::sun::star::beans::UnknownPropertyException); + }; +}; + +interface XTest3 { + interface XTest1; + interface XTest2; + [attribute] long Third { + get raises (com::sun::star::beans::UnknownPropertyException); + set raises (com::sun::star::beans::UnknownPropertyException); + }; + [attribute] long Fourth { + get raises (com::sun::star::beans::UnknownPropertyException); + set raises (com::sun::star::beans::UnknownPropertyException); + }; +}; + +interface XSupplier { + com::sun::star::lang::XComponent getEmpty1(); + + com::sun::star::lang::XComponent getEmpty2(); + + XTest3 getFull(); +}; + +service CppSupplier: XSupplier; + +service JavaSupplier: XSupplier; + +}; }; }; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |