Version 5.2.6.1, tag libreoffice-5.2.6.1
[LibreOffice.git] / cppuhelper / qa / propertysetmixin / comp_propertysetmixin.cxx
blobf6b96e26df57d2bd8efcbf4dee45c936cd81055c
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <sal/config.h>
23 #include <test/cppuhelper/propertysetmixin/XSupplier.hpp>
24 #include <test/cppuhelper/propertysetmixin/XTest3.hpp>
26 #include <com/sun/star/beans/Ambiguous.hpp>
27 #include <com/sun/star/beans/Defaulted.hpp>
28 #include <com/sun/star/beans/Optional.hpp>
29 #include <com/sun/star/beans/PropertyVetoException.hpp>
30 #include <com/sun/star/beans/UnknownPropertyException.hpp>
31 #include <com/sun/star/lang/XComponent.hpp>
32 #include <cppuhelper/propertysetmixin.hxx>
33 #include <cppuhelper/factory.hxx>
34 #include <cppuhelper/implbase1.hxx>
35 #include <cppuhelper/implementationentry.hxx>
36 #include <cppuhelper/queryinterface.hxx>
37 #include <cppuhelper/weak.hxx>
38 #include <com/sun/star/uno/Any.hxx>
39 #include <com/sun/star/uno/Exception.hpp>
40 #include <com/sun/star/uno/Reference.hxx>
41 #include <com/sun/star/uno/RuntimeException.hpp>
42 #include <com/sun/star/uno/Sequence.hxx>
43 #include <com/sun/star/uno/Type.hxx>
44 #include <com/sun/star/uno/XComponentContext.hpp>
45 #include <com/sun/star/uno/XInterface.hpp>
46 #include <osl/mutex.hxx>
47 #include <rtl/ustring.h>
48 #include <rtl/ustring.hxx>
49 #include <sal/types.h>
51 namespace com { namespace sun { namespace star {
52 class XEventListener;
53 } } }
55 namespace {
57 class Empty1:
58 public cppu::OWeakObject, public css::lang::XComponent,
59 public cppu::PropertySetMixin< css::lang::XComponent >
61 public:
62 explicit Empty1(
63 css::uno::Reference< css::uno::XComponentContext > const & context):
64 cppu::PropertySetMixin< css::lang::XComponent >(
65 context, static_cast< Implements >(0),
66 css::uno::Sequence< rtl::OUString >())
69 virtual css::uno::Any SAL_CALL queryInterface(css::uno::Type const & type)
70 throw (css::uno::RuntimeException);
72 virtual void SAL_CALL acquire() throw () { OWeakObject::acquire(); }
74 virtual void SAL_CALL release() throw () { OWeakObject::release(); }
76 virtual void SAL_CALL dispose() throw (css::uno::RuntimeException) {
77 cppu::PropertySetMixin< css::lang::XComponent >::dispose();
80 virtual void SAL_CALL addEventListener(
81 css::uno::Reference< css::lang::XEventListener > const &)
82 throw (css::uno::RuntimeException)
85 virtual void SAL_CALL removeEventListener(
86 css::uno::Reference< css::lang::XEventListener > const &)
87 throw (css::uno::RuntimeException)
90 private:
91 Empty1(Empty1 &); // not defined
92 void operator =(Empty1 &); // not defined
94 virtual ~Empty1() {}
97 css::uno::Any Empty1::queryInterface(css::uno::Type const & type)
98 throw (css::uno::RuntimeException)
100 css::uno::Any a(OWeakObject::queryInterface(type));
101 if (a.hasValue()) {
102 return a;
104 a = cppu::queryInterface(
105 type, static_cast< css::lang::XComponent * >(this));
106 return a.hasValue()
108 : cppu::PropertySetMixin< css::lang::XComponent >::queryInterface(
109 type);
112 class Empty2:
113 public cppu::OWeakObject, public css::lang::XComponent,
114 public cppu::PropertySetMixin< css::lang::XComponent >
116 public:
117 explicit Empty2(
118 css::uno::Reference< css::uno::XComponentContext > const & context):
119 cppu::PropertySetMixin< css::lang::XComponent >(
120 context,
121 static_cast< Implements >(
122 IMPLEMENTS_PROPERTY_SET | IMPLEMENTS_FAST_PROPERTY_SET
123 | IMPLEMENTS_PROPERTY_ACCESS),
124 css::uno::Sequence< rtl::OUString >())
127 virtual css::uno::Any SAL_CALL queryInterface(css::uno::Type const & type)
128 throw (css::uno::RuntimeException);
130 virtual void SAL_CALL acquire() throw () { OWeakObject::acquire(); }
132 virtual void SAL_CALL release() throw () { OWeakObject::release(); }
134 virtual void SAL_CALL dispose() throw (css::uno::RuntimeException) {
135 cppu::PropertySetMixin< css::lang::XComponent >::dispose();
138 virtual void SAL_CALL addEventListener(
139 css::uno::Reference< css::lang::XEventListener > const &)
140 throw (css::uno::RuntimeException)
143 virtual void SAL_CALL removeEventListener(
144 css::uno::Reference< css::lang::XEventListener > const &)
145 throw (css::uno::RuntimeException)
148 private:
149 Empty2(Empty2 &); // not defined
150 void operator =(Empty2 &); // not defined
152 virtual ~Empty2() {}
155 css::uno::Any Empty2::queryInterface(css::uno::Type const & type)
156 throw (css::uno::RuntimeException)
158 css::uno::Any a(OWeakObject::queryInterface(type));
159 if (a.hasValue()) {
160 return a;
162 a = cppu::queryInterface(
163 type, static_cast< css::lang::XComponent * >(this));
164 return a.hasValue()
166 : cppu::PropertySetMixin< css::lang::XComponent >::queryInterface(
167 type);
170 css::uno::Sequence< rtl::OUString > sequenceThird() {
171 css::uno::Sequence<OUString> s { rtl::OUString("Third") };
172 return s;
175 class Full:
176 public cppu::OWeakObject, public test::cppuhelper::propertysetmixin::XTest3,
177 public cppu::PropertySetMixin<
178 test::cppuhelper::propertysetmixin::XTest3 >
180 public:
181 explicit Full(
182 css::uno::Reference< css::uno::XComponentContext > const & context):
183 cppu::PropertySetMixin<
184 test::cppuhelper::propertysetmixin::XTest3 >(
185 context,
186 static_cast< Implements >(
187 IMPLEMENTS_PROPERTY_SET | IMPLEMENTS_FAST_PROPERTY_SET
188 | IMPLEMENTS_PROPERTY_ACCESS),
189 sequenceThird()),
190 m_a1(0),
191 m_a2(
192 css::beans::Defaulted< css::beans::Optional< sal_Int32 > >(
193 css::beans::Optional< sal_Int32 >(), true),
194 false)
197 virtual css::uno::Any SAL_CALL queryInterface(css::uno::Type const & type)
198 throw (css::uno::RuntimeException);
200 virtual void SAL_CALL acquire() throw () { OWeakObject::acquire(); }
202 virtual void SAL_CALL release() throw () { OWeakObject::release(); }
204 virtual sal_Int32 SAL_CALL getFirst() throw (css::uno::RuntimeException);
206 virtual void SAL_CALL setFirst(sal_Int32 value)
207 throw (css::uno::RuntimeException);
209 virtual
210 css::beans::Ambiguous<
211 css::beans::Defaulted< css::beans::Optional< sal_Int32 > > >
212 SAL_CALL getSecond()
213 throw (
214 css::beans::UnknownPropertyException, css::uno::RuntimeException);
216 virtual void SAL_CALL setSecond(
217 css::beans::Ambiguous<
218 css::beans::Defaulted< css::beans::Optional< ::sal_Int32 > > > const &
219 value)
220 throw (
221 css::beans::PropertyVetoException,
222 css::beans::UnknownPropertyException, css::uno::RuntimeException);
224 virtual sal_Int32 SAL_CALL getThird()
225 throw (
226 css::beans::UnknownPropertyException, css::uno::RuntimeException);
228 virtual void SAL_CALL setThird(sal_Int32 value)
229 throw (
230 css::beans::UnknownPropertyException, css::uno::RuntimeException);
232 virtual sal_Int32 SAL_CALL getFourth()
233 throw (
234 css::beans::UnknownPropertyException, css::uno::RuntimeException);
236 virtual void SAL_CALL setFourth(sal_Int32 value)
237 throw (
238 css::beans::UnknownPropertyException, css::uno::RuntimeException);
240 private:
241 Full(Full &); // not defined
242 void operator =(Full &); // not defined
244 virtual ~Full() {}
246 osl::Mutex m_mutex;
247 sal_Int32 m_a1;
248 css::beans::Ambiguous<
249 css::beans::Defaulted< css::beans::Optional< sal_Int32 > > > m_a2;
252 css::uno::Any Full::queryInterface(css::uno::Type const & type)
253 throw (css::uno::RuntimeException)
255 css::uno::Any a(OWeakObject::queryInterface(type));
256 if (a.hasValue()) {
257 return a;
259 a = cppu::queryInterface(
260 type,
261 static_cast< test::cppuhelper::propertysetmixin::XTest3 * >(this));
262 return a.hasValue()
264 : (cppu::PropertySetMixin<
265 test::cppuhelper::propertysetmixin::XTest3 >::queryInterface(
266 type));
269 sal_Int32 Full::getFirst() throw (css::uno::RuntimeException) {
270 osl::MutexGuard g(m_mutex);
271 return m_a1;
274 void Full::setFirst(sal_Int32 value) throw (css::uno::RuntimeException) {
275 prepareSet(
276 rtl::OUString("First"), css::uno::Any(),
277 css::uno::Any(), 0);
278 osl::MutexGuard g(m_mutex);
279 m_a1 = value;
282 css::beans::Ambiguous<
283 css::beans::Defaulted< css::beans::Optional< sal_Int32 > > >
284 Full::getSecond()
285 throw (css::beans::UnknownPropertyException, css::uno::RuntimeException)
287 osl::MutexGuard g(m_mutex);
288 return m_a2;
291 void Full::setSecond(
292 css::beans::Ambiguous<
293 css::beans::Defaulted< css::beans::Optional< ::sal_Int32 > > > const &
294 value)
295 throw (
296 css::beans::PropertyVetoException, css::beans::UnknownPropertyException,
297 css::uno::RuntimeException)
299 css::uno::Any v;
300 if (value.Value.Value.IsPresent) {
301 v <<= value.Value.Value.Value;
303 BoundListeners l;
304 prepareSet(
305 rtl::OUString("Second"), css::uno::Any(),
306 v, &l);
308 osl::MutexGuard g(m_mutex);
309 m_a2 = value;
311 l.notify();
314 sal_Int32 Full::getThird()
315 throw (css::beans::UnknownPropertyException, css::uno::RuntimeException)
317 throw css::beans::UnknownPropertyException(
318 rtl::OUString("Third"),
319 static_cast< cppu::OWeakObject * >(this));
322 void Full::setThird(sal_Int32)
323 throw (css::beans::UnknownPropertyException, css::uno::RuntimeException)
325 throw css::beans::UnknownPropertyException(
326 rtl::OUString("Third"),
327 static_cast< cppu::OWeakObject * >(this));
330 sal_Int32 Full::getFourth()
331 throw (css::beans::UnknownPropertyException, css::uno::RuntimeException)
333 throw css::beans::UnknownPropertyException(
334 rtl::OUString("Fourth"),
335 static_cast< cppu::OWeakObject * >(this));
338 void Full::setFourth(sal_Int32)
339 throw (css::beans::UnknownPropertyException, css::uno::RuntimeException)
341 throw css::beans::UnknownPropertyException(
342 rtl::OUString("Fourth"),
343 static_cast< cppu::OWeakObject * >(this));
346 class Supplier:
347 public cppu::WeakImplHelper1<
348 test::cppuhelper::propertysetmixin::XSupplier >
350 public:
351 explicit Supplier(
352 css::uno::Reference< css::uno::XComponentContext > const & context):
353 m_context(context) {}
355 virtual css::uno::Reference< css::lang::XComponent > SAL_CALL getEmpty1()
356 throw (css::uno::RuntimeException)
357 { return new Empty1(m_context); }
359 virtual css::uno::Reference< css::lang::XComponent > SAL_CALL getEmpty2()
360 throw (css::uno::RuntimeException)
361 { return new Empty2(m_context); }
363 virtual css::uno::Reference< test::cppuhelper::propertysetmixin::XTest3 >
364 SAL_CALL getFull() throw (css::uno::RuntimeException)
365 { return new Full(m_context); }
367 private:
368 Supplier(Supplier &); // not defined
369 void operator =(Supplier &); // not defined
371 virtual ~Supplier() {}
373 css::uno::Reference< css::uno::XComponentContext > m_context;
376 css::uno::Reference< css::uno::XInterface > SAL_CALL create(
377 css::uno::Reference< css::uno::XComponentContext > const & context)
379 return static_cast< cppu::OWeakObject * >(new Supplier(context));
382 rtl::OUString SAL_CALL getImplementationName() {
383 return rtl::OUString(
384 "test.cppuhelper.propertysetmixin.comp.CppSupplier");
387 css::uno::Sequence< rtl::OUString > SAL_CALL getSupportedServiceNames()
389 css::uno::Sequence< rtl::OUString > s { "test.cppuhelper.propertysetmixin.CppSupplier") };
390 return s;
393 cppu::ImplementationEntry entries[] = {
394 { &create, &getImplementationName, &getSupportedServiceNames,
395 &cppu::createSingleComponentFactory, 0, 0 },
396 { 0, 0, 0, 0, 0, 0 } };
400 extern "C" SAL_DLLPUBLIC_EXPORT void * SAL_CALL mixin_component_getFactory(
401 char const * implName, void * serviceManager, void * registryKey)
403 return cppu::component_getFactoryHelper(
404 implName, serviceManager, registryKey, entries);
407 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */