1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_cppuhelper.hxx"
26
27 #include "sal/config.h"
28
29 #include "test/cppuhelper/propertysetmixin/XSupplier.hpp"
30 #include "test/cppuhelper/propertysetmixin/XTest3.hpp"
31
32 #include "com/sun/star/beans/Ambiguous.hpp"
33 #include "com/sun/star/beans/Defaulted.hpp"
34 #include "com/sun/star/beans/Optional.hpp"
35 #include "com/sun/star/beans/PropertyVetoException.hpp"
36 #include "com/sun/star/beans/UnknownPropertyException.hpp"
37 #include "com/sun/star/lang/XComponent.hpp"
38 #include "cppuhelper/propertysetmixin.hxx"
39 #include "cppuhelper/factory.hxx"
40 #include "cppuhelper/implbase1.hxx"
41 #include "cppuhelper/implementationentry.hxx"
42 #include "cppuhelper/queryinterface.hxx"
43 #include "cppuhelper/weak.hxx"
44 #include "com/sun/star/uno/Any.hxx"
45 #include "com/sun/star/uno/Exception.hpp"
46 #include "com/sun/star/uno/Reference.hxx"
47 #include "com/sun/star/uno/RuntimeException.hpp"
48 #include "com/sun/star/uno/Sequence.hxx"
49 #include "com/sun/star/uno/Type.hxx"
50 #include "com/sun/star/uno/XComponentContext.hpp"
51 #include "com/sun/star/uno/XInterface.hpp"
52 #include "osl/mutex.hxx"
53 #include "rtl/ustring.h"
54 #include "rtl/ustring.hxx"
55 #include "sal/types.h"
56 #include "uno/lbnames.h"
57
58 namespace com { namespace sun { namespace star {
59 class XEventListener;
60 } } }
61
62 namespace css = com::sun::star;
63
64 namespace {
65
66 class Empty1:
67 public cppu::OWeakObject, public css::lang::XComponent,
68 public cppu::PropertySetMixin< css::lang::XComponent >
69 {
70 public:
Empty1(css::uno::Reference<css::uno::XComponentContext> const & context)71 explicit Empty1(
72 css::uno::Reference< css::uno::XComponentContext > const & context):
73 cppu::PropertySetMixin< css::lang::XComponent >(
74 context, static_cast< Implements >(0),
75 css::uno::Sequence< rtl::OUString >())
76 {}
77
78 virtual css::uno::Any SAL_CALL queryInterface(css::uno::Type const & type)
79 throw (css::uno::RuntimeException);
80
acquire()81 virtual void SAL_CALL acquire() throw () { OWeakObject::acquire(); }
82
release()83 virtual void SAL_CALL release() throw () { OWeakObject::release(); }
84
dispose()85 virtual void SAL_CALL dispose() throw (css::uno::RuntimeException) {
86 cppu::PropertySetMixin< css::lang::XComponent >::dispose();
87 }
88
addEventListener(css::uno::Reference<css::lang::XEventListener> const &)89 virtual void SAL_CALL addEventListener(
90 css::uno::Reference< css::lang::XEventListener > const &)
91 throw (css::uno::RuntimeException)
92 {}
93
removeEventListener(css::uno::Reference<css::lang::XEventListener> const &)94 virtual void SAL_CALL removeEventListener(
95 css::uno::Reference< css::lang::XEventListener > const &)
96 throw (css::uno::RuntimeException)
97 {}
98
99 private:
100 Empty1(Empty1 &); // not defined
101 void operator =(Empty1 &); // not defined
102
~Empty1()103 virtual ~Empty1() {}
104 };
105
queryInterface(css::uno::Type const & type)106 css::uno::Any Empty1::queryInterface(css::uno::Type const & type)
107 throw (css::uno::RuntimeException)
108 {
109 css::uno::Any a(OWeakObject::queryInterface(type));
110 if (a.hasValue()) {
111 return a;
112 }
113 a = cppu::queryInterface(
114 type, static_cast< css::lang::XComponent * >(this));
115 return a.hasValue()
116 ? a
117 : cppu::PropertySetMixin< css::lang::XComponent >::queryInterface(
118 type);
119 }
120
121 class Empty2:
122 public cppu::OWeakObject, public css::lang::XComponent,
123 public cppu::PropertySetMixin< css::lang::XComponent >
124 {
125 public:
Empty2(css::uno::Reference<css::uno::XComponentContext> const & context)126 explicit Empty2(
127 css::uno::Reference< css::uno::XComponentContext > const & context):
128 cppu::PropertySetMixin< css::lang::XComponent >(
129 context,
130 static_cast< Implements >(
131 IMPLEMENTS_PROPERTY_SET | IMPLEMENTS_FAST_PROPERTY_SET
132 | IMPLEMENTS_PROPERTY_ACCESS),
133 css::uno::Sequence< rtl::OUString >())
134 {}
135
136 virtual css::uno::Any SAL_CALL queryInterface(css::uno::Type const & type)
137 throw (css::uno::RuntimeException);
138
acquire()139 virtual void SAL_CALL acquire() throw () { OWeakObject::acquire(); }
140
release()141 virtual void SAL_CALL release() throw () { OWeakObject::release(); }
142
dispose()143 virtual void SAL_CALL dispose() throw (css::uno::RuntimeException) {
144 cppu::PropertySetMixin< css::lang::XComponent >::dispose();
145 }
146
addEventListener(css::uno::Reference<css::lang::XEventListener> const &)147 virtual void SAL_CALL addEventListener(
148 css::uno::Reference< css::lang::XEventListener > const &)
149 throw (css::uno::RuntimeException)
150 {}
151
removeEventListener(css::uno::Reference<css::lang::XEventListener> const &)152 virtual void SAL_CALL removeEventListener(
153 css::uno::Reference< css::lang::XEventListener > const &)
154 throw (css::uno::RuntimeException)
155 {}
156
157 private:
158 Empty2(Empty2 &); // not defined
159 void operator =(Empty2 &); // not defined
160
~Empty2()161 virtual ~Empty2() {}
162 };
163
queryInterface(css::uno::Type const & type)164 css::uno::Any Empty2::queryInterface(css::uno::Type const & type)
165 throw (css::uno::RuntimeException)
166 {
167 css::uno::Any a(OWeakObject::queryInterface(type));
168 if (a.hasValue()) {
169 return a;
170 }
171 a = cppu::queryInterface(
172 type, static_cast< css::lang::XComponent * >(this));
173 return a.hasValue()
174 ? a
175 : cppu::PropertySetMixin< css::lang::XComponent >::queryInterface(
176 type);
177 }
178
sequenceThird()179 css::uno::Sequence< rtl::OUString > sequenceThird() {
180 css::uno::Sequence< rtl::OUString > s(1);
181 s[0] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Third"));
182 return s;
183 }
184
185 class Full:
186 public cppu::OWeakObject, public test::cppuhelper::propertysetmixin::XTest3,
187 public cppu::PropertySetMixin<
188 test::cppuhelper::propertysetmixin::XTest3 >
189 {
190 public:
Full(css::uno::Reference<css::uno::XComponentContext> const & context)191 explicit Full(
192 css::uno::Reference< css::uno::XComponentContext > const & context):
193 cppu::PropertySetMixin<
194 test::cppuhelper::propertysetmixin::XTest3 >(
195 context,
196 static_cast< Implements >(
197 IMPLEMENTS_PROPERTY_SET | IMPLEMENTS_FAST_PROPERTY_SET
198 | IMPLEMENTS_PROPERTY_ACCESS),
199 sequenceThird()),
200 m_a1(0),
201 m_a2(
202 css::beans::Defaulted< css::beans::Optional< sal_Int32 > >(
203 css::beans::Optional< sal_Int32 >(), true),
204 false)
205 {}
206
207 virtual css::uno::Any SAL_CALL queryInterface(css::uno::Type const & type)
208 throw (css::uno::RuntimeException);
209
acquire()210 virtual void SAL_CALL acquire() throw () { OWeakObject::acquire(); }
211
release()212 virtual void SAL_CALL release() throw () { OWeakObject::release(); }
213
214 virtual sal_Int32 SAL_CALL getFirst() throw (css::uno::RuntimeException);
215
216 virtual void SAL_CALL setFirst(sal_Int32 value)
217 throw (css::uno::RuntimeException);
218
219 virtual
220 css::beans::Ambiguous<
221 css::beans::Defaulted< css::beans::Optional< sal_Int32 > > >
222 SAL_CALL getSecond()
223 throw (
224 css::beans::UnknownPropertyException, css::uno::RuntimeException);
225
226 virtual void SAL_CALL setSecond(
227 css::beans::Ambiguous<
228 css::beans::Defaulted< css::beans::Optional< ::sal_Int32 > > > const &
229 value)
230 throw (
231 css::beans::PropertyVetoException,
232 css::beans::UnknownPropertyException, css::uno::RuntimeException);
233
234 virtual sal_Int32 SAL_CALL getThird()
235 throw (
236 css::beans::UnknownPropertyException, css::uno::RuntimeException);
237
238 virtual void SAL_CALL setThird(sal_Int32 value)
239 throw (
240 css::beans::UnknownPropertyException, css::uno::RuntimeException);
241
242 virtual sal_Int32 SAL_CALL getFourth()
243 throw (
244 css::beans::UnknownPropertyException, css::uno::RuntimeException);
245
246 virtual void SAL_CALL setFourth(sal_Int32 value)
247 throw (
248 css::beans::UnknownPropertyException, css::uno::RuntimeException);
249
250 private:
251 Full(Full &); // not defined
252 void operator =(Full &); // not defined
253
~Full()254 virtual ~Full() {}
255
256 osl::Mutex m_mutex;
257 sal_Int32 m_a1;
258 css::beans::Ambiguous<
259 css::beans::Defaulted< css::beans::Optional< sal_Int32 > > > m_a2;
260 };
261
queryInterface(css::uno::Type const & type)262 css::uno::Any Full::queryInterface(css::uno::Type const & type)
263 throw (css::uno::RuntimeException)
264 {
265 css::uno::Any a(OWeakObject::queryInterface(type));
266 if (a.hasValue()) {
267 return a;
268 }
269 a = cppu::queryInterface(
270 type,
271 static_cast< test::cppuhelper::propertysetmixin::XTest3 * >(this));
272 return a.hasValue()
273 ? a
274 : (cppu::PropertySetMixin<
275 test::cppuhelper::propertysetmixin::XTest3 >::queryInterface(
276 type));
277 }
278
getFirst()279 sal_Int32 Full::getFirst() throw (css::uno::RuntimeException) {
280 osl::MutexGuard g(m_mutex);
281 return m_a1;
282 }
283
setFirst(sal_Int32 value)284 void Full::setFirst(sal_Int32 value) throw (css::uno::RuntimeException) {
285 prepareSet(
286 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("First")), css::uno::Any(),
287 css::uno::Any(), 0);
288 osl::MutexGuard g(m_mutex);
289 m_a1 = value;
290 }
291
292 css::beans::Ambiguous<
293 css::beans::Defaulted< css::beans::Optional< sal_Int32 > > >
getSecond()294 Full::getSecond()
295 throw (css::beans::UnknownPropertyException, css::uno::RuntimeException)
296 {
297 osl::MutexGuard g(m_mutex);
298 return m_a2;
299 }
300
setSecond(css::beans::Ambiguous<css::beans::Defaulted<css::beans::Optional<::sal_Int32>>> const & value)301 void Full::setSecond(
302 css::beans::Ambiguous<
303 css::beans::Defaulted< css::beans::Optional< ::sal_Int32 > > > const &
304 value)
305 throw (
306 css::beans::PropertyVetoException, css::beans::UnknownPropertyException,
307 css::uno::RuntimeException)
308 {
309 css::uno::Any v;
310 if (value.Value.Value.IsPresent) {
311 v <<= value.Value.Value.Value;
312 }
313 BoundListeners l;
314 prepareSet(
315 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Second")), css::uno::Any(),
316 v, &l);
317 {
318 osl::MutexGuard g(m_mutex);
319 m_a2 = value;
320 }
321 l.notify();
322 }
323
getThird()324 sal_Int32 Full::getThird()
325 throw (css::beans::UnknownPropertyException, css::uno::RuntimeException)
326 {
327 throw css::beans::UnknownPropertyException(
328 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Third")),
329 static_cast< cppu::OWeakObject * >(this));
330 }
331
setThird(sal_Int32)332 void Full::setThird(sal_Int32)
333 throw (css::beans::UnknownPropertyException, css::uno::RuntimeException)
334 {
335 throw css::beans::UnknownPropertyException(
336 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Third")),
337 static_cast< cppu::OWeakObject * >(this));
338 }
339
getFourth()340 sal_Int32 Full::getFourth()
341 throw (css::beans::UnknownPropertyException, css::uno::RuntimeException)
342 {
343 throw css::beans::UnknownPropertyException(
344 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Fourth")),
345 static_cast< cppu::OWeakObject * >(this));
346 }
347
setFourth(sal_Int32)348 void Full::setFourth(sal_Int32)
349 throw (css::beans::UnknownPropertyException, css::uno::RuntimeException)
350 {
351 throw css::beans::UnknownPropertyException(
352 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Fourth")),
353 static_cast< cppu::OWeakObject * >(this));
354 }
355
356 class Supplier:
357 public cppu::WeakImplHelper1<
358 test::cppuhelper::propertysetmixin::XSupplier >
359 {
360 public:
Supplier(css::uno::Reference<css::uno::XComponentContext> const & context)361 explicit Supplier(
362 css::uno::Reference< css::uno::XComponentContext > const & context):
363 m_context(context) {}
364
getEmpty1()365 virtual css::uno::Reference< css::lang::XComponent > SAL_CALL getEmpty1()
366 throw (css::uno::RuntimeException)
367 { return new Empty1(m_context); }
368
getEmpty2()369 virtual css::uno::Reference< css::lang::XComponent > SAL_CALL getEmpty2()
370 throw (css::uno::RuntimeException)
371 { return new Empty2(m_context); }
372
373 virtual css::uno::Reference< test::cppuhelper::propertysetmixin::XTest3 >
getFull()374 SAL_CALL getFull() throw (css::uno::RuntimeException)
375 { return new Full(m_context); }
376
377 private:
378 Supplier(Supplier &); // not defined
379 void operator =(Supplier &); // not defined
380
~Supplier()381 virtual ~Supplier() {}
382
383 css::uno::Reference< css::uno::XComponentContext > m_context;
384 };
385
create(css::uno::Reference<css::uno::XComponentContext> const & context)386 css::uno::Reference< css::uno::XInterface > SAL_CALL create(
387 css::uno::Reference< css::uno::XComponentContext > const & context)
388 SAL_THROW((css::uno::Exception))
389 {
390 return static_cast< cppu::OWeakObject * >(new Supplier(context));
391 }
392
getImplementationName()393 rtl::OUString SAL_CALL getImplementationName() {
394 return rtl::OUString(
395 RTL_CONSTASCII_USTRINGPARAM(
396 "test.cppuhelper.propertysetmixin.comp.CppSupplier"));
397 }
398
getSupportedServiceNames()399 css::uno::Sequence< rtl::OUString > SAL_CALL getSupportedServiceNames() {
400 css::uno::Sequence< rtl::OUString > s(1);
401 s[0] = rtl::OUString(
402 RTL_CONSTASCII_USTRINGPARAM(
403 "test.cppuhelper.propertysetmixin.CppSupplier"));
404 return s;
405 }
406
407 cppu::ImplementationEntry entries[] = {
408 { &create, &getImplementationName, &getSupportedServiceNames,
409 &cppu::createSingleComponentFactory, 0, 0 },
410 { 0, 0, 0, 0, 0, 0 } };
411
412 }
413
component_getFactory(char const * implName,void * serviceManager,void * registryKey)414 extern "C" void * SAL_CALL component_getFactory(
415 char const * implName, void * serviceManager, void * registryKey)
416 {
417 return cppu::component_getFactoryHelper(
418 implName, serviceManager, registryKey, entries);
419 }
420
component_getImplementationEnvironment(char const ** envTypeName,uno_Environment **)421 extern "C" void SAL_CALL component_getImplementationEnvironment(
422 char const ** envTypeName, uno_Environment **)
423 {
424 *envTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
425 }
426