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/CppSupplier.hpp"
30 #include "test/cppuhelper/propertysetmixin/JavaSupplier.hpp"
31 #include "test/cppuhelper/propertysetmixin/XSupplier.hpp"
32 #include "test/cppuhelper/propertysetmixin/XTest3.hpp"
33
34 #include "com/sun/star/beans/Ambiguous.hpp"
35 #include "com/sun/star/beans/Defaulted.hpp"
36 #include "com/sun/star/beans/Optional.hpp"
37 #include "com/sun/star/beans/Property.hpp"
38 #include "com/sun/star/beans/PropertyAttribute.hpp"
39 #include "com/sun/star/beans/PropertyChangeEvent.hpp"
40 #include "com/sun/star/beans/PropertyState.hpp"
41 #include "com/sun/star/beans/PropertyValue.hpp"
42 #include "com/sun/star/beans/PropertyVetoException.hpp"
43 #include "com/sun/star/beans/UnknownPropertyException.hpp"
44 #include "com/sun/star/beans/XFastPropertySet.hpp"
45 #include "com/sun/star/beans/XPropertyAccess.hpp"
46 #include "com/sun/star/beans/XPropertyChangeListener.hpp"
47 #include "com/sun/star/beans/XPropertySet.hpp"
48 #include "com/sun/star/beans/XPropertySetInfo.hpp"
49 #include "com/sun/star/beans/XVetoableChangeListener.hpp"
50 #include "com/sun/star/lang/XComponent.hpp"
51 #include "com/sun/star/uno/Any.hxx"
52 #include "com/sun/star/uno/Reference.hxx"
53 #include "com/sun/star/uno/RuntimeException.hpp"
54 #include "com/sun/star/uno/Sequence.hxx"
55 #include "com/sun/star/uno/Type.hxx"
56 #include "com/sun/star/uno/XComponentContext.hpp"
57 #include "cppuhelper/bootstrap.hxx"
58 #include "cppuhelper/implbase1.hxx"
59 #include "gtest/gtest.h"
60 #include "osl/mutex.hxx"
61 #include "rtl/ref.hxx"
62 #include "rtl/string.h"
63 #include "rtl/textenc.h"
64 #include "rtl/ustring.h"
65 #include "rtl/ustring.hxx"
66 #include "sal/types.h"
67 #include "osl/process.h"
68
69 #include <limits>
70 #include <ostream>
71
72 namespace com { namespace sun { namespace star {
73 struct EventObject;
74 } } }
75
76 namespace css = com::sun::star;
77
78 namespace {
79
operator <<(std::ostream & out,rtl::OUString const & value)80 std::ostream & operator <<(std::ostream & out, rtl::OUString const & value) {
81 return out << rtl::OUStringToOString(value, RTL_TEXTENCODING_UTF8).getStr();
82 }
83
operator <<(std::ostream & out,css::uno::Type const & value)84 std::ostream & operator <<(std::ostream & out, css::uno::Type const & value) {
85 return out << "com::sun::star::uno::Type[" << value.getTypeName() << ']';
86 }
87
operator <<(std::ostream & out,css::uno::Any const & value)88 std::ostream & operator <<(std::ostream & out, css::uno::Any const & value) {
89 return
90 out << "com::sun::star::uno::Any[" << value.getValueType() << ", ...]";
91 }
92
93 class BoundListener:
94 public cppu::WeakImplHelper1< css::beans::XPropertyChangeListener >
95 {
96 public:
BoundListener()97 BoundListener(): m_count(0) {}
98
count() const99 int count() const {
100 osl::MutexGuard g(m_mutex);
101 return m_count;
102 }
103
disposing(css::lang::EventObject const &)104 virtual void SAL_CALL disposing(css::lang::EventObject const &)
105 {
106 osl::MutexGuard g(m_mutex);
107 ASSERT_TRUE(m_count < std::numeric_limits< int >::max());
108 ++m_count;
109 }
110
propertyChange(css::beans::PropertyChangeEvent const &)111 virtual void SAL_CALL propertyChange(
112 css::beans::PropertyChangeEvent const &)
113 { FAIL() << "BoundListener::propertyChange called"; }
114
115 private:
116 BoundListener(BoundListener &); // not defined
117 void operator =(BoundListener &); // not defined
118
~BoundListener()119 virtual ~BoundListener() {}
120
121 mutable osl::Mutex m_mutex;
122 int m_count;
123 };
124
125 class VetoListener:
126 public cppu::WeakImplHelper1< css::beans::XVetoableChangeListener >
127 {
128 public:
VetoListener()129 VetoListener(): m_count(0) {}
130
count() const131 int count() const {
132 osl::MutexGuard g(m_mutex);
133 return m_count;
134 }
135
disposing(css::lang::EventObject const &)136 virtual void SAL_CALL disposing(css::lang::EventObject const &)
137 {
138 osl::MutexGuard g(m_mutex);
139 ASSERT_TRUE(m_count < std::numeric_limits< int >::max());
140 ++m_count;
141 }
142
vetoableChange(css::beans::PropertyChangeEvent const &)143 virtual void SAL_CALL vetoableChange(
144 css::beans::PropertyChangeEvent const &)
145 { FAIL() << "VetoListener::vetoableChange called"; }
146
147 private:
148 VetoListener(VetoListener &); // not defined
149 void operator =(VetoListener &); // not defined
150
~VetoListener()151 virtual ~VetoListener() {}
152
153 mutable osl::Mutex m_mutex;
154 int m_count;
155 };
156
157 class Test: public ::testing::Test {
158 public:
159 virtual void SetUp();
160
161 virtual void TearDown();
162
163 protected:
164 css::uno::Reference< test::cppuhelper::propertysetmixin::XSupplier >
165 getCppSupplier() const;
166
167 css::uno::Reference< test::cppuhelper::propertysetmixin::XSupplier >
168 getJavaSupplier() const;
169
170 void testEmpty1(
171 css::uno::Reference< test::cppuhelper::propertysetmixin::XSupplier >
172 const & supplier) const;
173
174 void testEmpty2(
175 css::uno::Reference< test::cppuhelper::propertysetmixin::XSupplier >
176 const & supplier) const;
177
178 void testFull(
179 css::uno::Reference< test::cppuhelper::propertysetmixin::XSupplier >
180 const & supplier) const;
181
182 css::uno::Reference< css::uno::XComponentContext > m_context;
183 };
184
SetUp()185 void Test::SetUp() {
186 m_context = cppu::defaultBootstrap_InitialComponentContext();
187 ASSERT_TRUE(m_context.is());
188 }
189
TearDown()190 void Test::TearDown() {
191 css::uno::Reference< css::lang::XComponent >(
192 m_context, css::uno::UNO_QUERY_THROW)->dispose();
193 }
194
195 css::uno::Reference< test::cppuhelper::propertysetmixin::XSupplier >
getCppSupplier() const196 Test::getCppSupplier() const
197 {
198 return test::cppuhelper::propertysetmixin::CppSupplier::create(m_context);
199 }
200
201 css::uno::Reference< test::cppuhelper::propertysetmixin::XSupplier >
getJavaSupplier() const202 Test::getJavaSupplier() const
203 {
204 return test::cppuhelper::propertysetmixin::JavaSupplier::create(m_context);
205 }
206
testEmpty1(css::uno::Reference<test::cppuhelper::propertysetmixin::XSupplier> const & supplier) const207 void Test::testEmpty1(
208 css::uno::Reference< test::cppuhelper::propertysetmixin::XSupplier >
209 const & supplier) const
210 {
211 css::uno::Reference< css::lang::XComponent > empty1(
212 supplier->getEmpty1(), css::uno::UNO_QUERY_THROW);
213 ASSERT_TRUE(
214 !css::uno::Reference< css::beans::XPropertySet >(
215 empty1, css::uno::UNO_QUERY).is());
216 ASSERT_TRUE(
217 !css::uno::Reference< css::beans::XFastPropertySet >(
218 empty1, css::uno::UNO_QUERY).is());
219 ASSERT_TRUE(
220 !css::uno::Reference< css::beans::XPropertyAccess >(
221 empty1, css::uno::UNO_QUERY).is());
222 empty1->dispose();
223 }
224
testEmpty2(css::uno::Reference<test::cppuhelper::propertysetmixin::XSupplier> const & supplier) const225 void Test::testEmpty2(
226 css::uno::Reference< test::cppuhelper::propertysetmixin::XSupplier >
227 const & supplier) const
228 {
229 css::uno::Reference< css::lang::XComponent > empty2(
230 supplier->getEmpty2(), css::uno::UNO_QUERY_THROW);
231 css::uno::Reference< css::beans::XPropertySet > empty2p(
232 empty2, css::uno::UNO_QUERY);
233 ASSERT_TRUE(empty2p.is());
234 css::uno::Reference< css::beans::XPropertySetInfo > info(
235 empty2p->getPropertySetInfo());
236 ASSERT_TRUE(info.is());
237 ASSERT_EQ(
238 static_cast< sal_Int32 >(0), info->getProperties().getLength());
239 try {
240 info->getPropertyByName(
241 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("any")));
242 FAIL() << "exception expected";
243 } catch (css::beans::UnknownPropertyException &) {}
244 ASSERT_TRUE(
245 !info->hasPropertyByName(
246 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("any"))));
247 try {
248 empty2p->setPropertyValue(
249 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("any")), css::uno::Any());
250 FAIL() << "exception expected";
251 } catch (css::beans::UnknownPropertyException &) {}
252 try {
253 empty2p->getPropertyValue(
254 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("any")));
255 FAIL() << "exception expected";
256 } catch (css::beans::UnknownPropertyException &) {}
257 rtl::Reference< BoundListener > boundListener1(new BoundListener);
258 empty2p->addPropertyChangeListener(rtl::OUString(), boundListener1.get());
259 empty2p->addPropertyChangeListener(rtl::OUString(), boundListener1.get());
260 rtl::Reference< BoundListener > boundListener2(new BoundListener);
261 empty2p->removePropertyChangeListener(
262 rtl::OUString(), boundListener2.get());
263 rtl::Reference< VetoListener > vetoListener1(new VetoListener);
264 empty2p->addVetoableChangeListener(rtl::OUString(), vetoListener1.get());
265 empty2p->addVetoableChangeListener(rtl::OUString(), vetoListener1.get());
266 rtl::Reference< VetoListener > vetoListener2(new VetoListener);
267 empty2p->addVetoableChangeListener(rtl::OUString(), vetoListener2.get());
268 empty2p->removeVetoableChangeListener(rtl::OUString(), vetoListener2.get());
269 css::uno::Reference< css::beans::XFastPropertySet > empty2f(
270 empty2, css::uno::UNO_QUERY);
271 ASSERT_TRUE(empty2f.is());
272 try {
273 empty2f->setFastPropertyValue(-1, css::uno::Any());
274 FAIL() << "exception expected";
275 } catch (css::beans::UnknownPropertyException &) {}
276 try {
277 empty2f->setFastPropertyValue(0, css::uno::Any());
278 FAIL() << "exception expected";
279 } catch (css::beans::UnknownPropertyException &) {}
280 try {
281 empty2f->getFastPropertyValue(-1);
282 FAIL() << "exception expected";
283 } catch (css::beans::UnknownPropertyException &) {}
284 try {
285 empty2f->getFastPropertyValue(0);
286 FAIL() << "exception expected";
287 } catch (css::beans::UnknownPropertyException &) {}
288 css::uno::Reference< css::beans::XPropertyAccess > empty2a(
289 empty2, css::uno::UNO_QUERY);
290 ASSERT_TRUE(empty2a.is());
291 ASSERT_EQ(
292 static_cast< sal_Int32 >(0), empty2a->getPropertyValues().getLength());
293 empty2a->setPropertyValues(
294 css::uno::Sequence< css::beans::PropertyValue >());
295 css::uno::Sequence< css::beans::PropertyValue > vs(2);
296 vs[0].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("any1"));
297 vs[0].Handle = -1;
298 vs[0].State = css::beans::PropertyState_DIRECT_VALUE;
299 vs[0].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("any2"));
300 vs[0].Handle = -1;
301 vs[0].State = css::beans::PropertyState_DIRECT_VALUE;
302 try {
303 empty2a->setPropertyValues(vs);
304 FAIL() << "exception expected";
305 } catch (css::beans::UnknownPropertyException &) {}
306 ASSERT_EQ(0, boundListener1->count());
307 ASSERT_EQ(0, boundListener2->count());
308 ASSERT_EQ(0, vetoListener1->count());
309 ASSERT_EQ(0, vetoListener2->count());
310 empty2->dispose();
311 ASSERT_EQ(2, boundListener1->count());
312 ASSERT_EQ(0, boundListener2->count());
313 ASSERT_EQ(2, vetoListener1->count());
314 ASSERT_EQ(0, vetoListener2->count());
315 empty2p->removePropertyChangeListener(
316 rtl::OUString(), boundListener1.get());
317 empty2p->removePropertyChangeListener(
318 rtl::OUString(), boundListener2.get());
319 empty2p->removeVetoableChangeListener(rtl::OUString(), vetoListener1.get());
320 empty2p->removeVetoableChangeListener(rtl::OUString(), vetoListener2.get());
321 empty2p->addPropertyChangeListener(rtl::OUString(), boundListener1.get());
322 empty2p->addPropertyChangeListener(rtl::OUString(), boundListener2.get());
323 empty2p->addVetoableChangeListener(rtl::OUString(), vetoListener1.get());
324 empty2p->addVetoableChangeListener(rtl::OUString(), vetoListener2.get());
325 try {
326 empty2p->addPropertyChangeListener(
327 rtl::OUString(),
328 css::uno::Reference< css::beans::XPropertyChangeListener >());
329 } catch (css::uno::RuntimeException &) {}
330 try {
331 empty2p->addVetoableChangeListener(
332 rtl::OUString(),
333 css::uno::Reference< css::beans::XVetoableChangeListener >());
334 } catch (css::uno::RuntimeException &) {}
335 ASSERT_EQ(3, boundListener1->count());
336 ASSERT_EQ(1, boundListener2->count());
337 ASSERT_EQ(3, vetoListener1->count());
338 ASSERT_EQ(1, vetoListener2->count());
339 }
340
testFull(css::uno::Reference<test::cppuhelper::propertysetmixin::XSupplier> const & supplier) const341 void Test::testFull(
342 css::uno::Reference< test::cppuhelper::propertysetmixin::XSupplier >
343 const & supplier) const
344 {
345 css::uno::Reference< test::cppuhelper::propertysetmixin::XTest3 > full(
346 supplier->getFull(), css::uno::UNO_QUERY_THROW);
347 css::uno::Reference< css::beans::XPropertySet > fullp(
348 full, css::uno::UNO_QUERY);
349 ASSERT_TRUE(fullp.is());
350 css::uno::Reference< css::beans::XPropertySetInfo > info(
351 fullp->getPropertySetInfo());
352 ASSERT_TRUE(info.is());
353 ASSERT_EQ(
354 static_cast< sal_Int32 >(3), info->getProperties().getLength());
355 css::beans::Property prop(
356 info->getPropertyByName(
357 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("First"))));
358 ASSERT_EQ(
359 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("First")), prop.Name);
360 ASSERT_EQ(static_cast< sal_Int32 >(0), prop.Handle);
361 ASSERT_EQ(getCppuType(static_cast< sal_Int32 * >(0)), prop.Type);
362 ASSERT_EQ(static_cast< sal_Int16 >(0), prop.Attributes);
363 prop = info->getPropertyByName(
364 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Second")));
365 ASSERT_EQ(
366 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Second")), prop.Name);
367 ASSERT_EQ(static_cast< sal_Int32 >(1), prop.Handle);
368 ASSERT_EQ(getCppuType(static_cast< sal_Int32 * >(0)), prop.Type);
369 ASSERT_EQ(
370 static_cast< sal_Int16 >(
371 css::beans::PropertyAttribute::MAYBEVOID
372 | css::beans::PropertyAttribute::BOUND
373 | css::beans::PropertyAttribute::CONSTRAINED
374 | css::beans::PropertyAttribute::MAYBEAMBIGUOUS
375 | css::beans::PropertyAttribute::MAYBEDEFAULT
376 | css::beans::PropertyAttribute::OPTIONAL),
377 prop.Attributes);
378 try {
379 info->getPropertyByName(
380 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Third")));
381 FAIL() << "exception expected";
382 } catch (css::beans::UnknownPropertyException &) {}
383 prop = info->getPropertyByName(
384 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Fourth")));
385 ASSERT_EQ(
386 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Fourth")), prop.Name);
387 ASSERT_EQ(static_cast< sal_Int32 >(3), prop.Handle);
388 ASSERT_EQ(getCppuType(static_cast< sal_Int32 * >(0)), prop.Type);
389 ASSERT_EQ(
390 static_cast< sal_Int16 >(css::beans::PropertyAttribute::OPTIONAL),
391 prop.Attributes);
392 try {
393 info->getPropertyByName(
394 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("first")));
395 FAIL() << "exception expected";
396 } catch (css::beans::UnknownPropertyException &) {}
397 ASSERT_TRUE(
398 info->hasPropertyByName(
399 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("First"))));
400 ASSERT_TRUE(
401 info->hasPropertyByName(
402 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Second"))));
403 ASSERT_TRUE(
404 !info->hasPropertyByName(
405 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Third"))));
406 ASSERT_TRUE(
407 info->hasPropertyByName(
408 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Fourth"))));
409 ASSERT_TRUE(
410 !info->hasPropertyByName(
411 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("first"))));
412 ASSERT_EQ(
413 css::uno::makeAny(static_cast< sal_Int32 >(0)),
414 fullp->getPropertyValue(
415 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("First"))));
416 fullp->setPropertyValue(
417 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("First")),
418 css::uno::makeAny(static_cast< sal_Int32 >(-100)));
419 ASSERT_EQ(
420 css::uno::makeAny(static_cast< sal_Int32 >(-100)),
421 fullp->getPropertyValue(
422 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("First"))));
423 css::uno::Any voidAny;
424 ASSERT_EQ(
425 voidAny,
426 fullp->getPropertyValue(
427 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Second"))));
428 fullp->setPropertyValue(
429 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Second")),
430 css::uno::makeAny(static_cast< sal_Int32 >(100)));
431 ASSERT_EQ(
432 css::uno::makeAny(static_cast< sal_Int32 >(100)),
433 fullp->getPropertyValue(
434 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Second"))));
435 ASSERT_TRUE(full->getSecond().Value.Value.IsPresent);
436 ASSERT_EQ(
437 static_cast< sal_Int32 >(100), full->getSecond().Value.Value.Value);
438 ASSERT_TRUE(!full->getSecond().Value.IsDefaulted);
439 ASSERT_TRUE(!full->getSecond().IsAmbiguous);
440 fullp->setPropertyValue(
441 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Second")),
442 css::uno::Any());
443 ASSERT_EQ(
444 voidAny,
445 fullp->getPropertyValue(
446 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Second"))));
447 ASSERT_TRUE(!full->getSecond().Value.Value.IsPresent);
448 ASSERT_TRUE(!full->getSecond().Value.IsDefaulted);
449 ASSERT_TRUE(!full->getSecond().IsAmbiguous);
450 try {
451 fullp->setPropertyValue(
452 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Third")),
453 css::uno::makeAny(static_cast< sal_Int32 >(100)));
454 FAIL() << "exception expected";
455 } catch (css::beans::UnknownPropertyException &) {}
456 try {
457 fullp->getPropertyValue(
458 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Third")));
459 FAIL() << "exception expected";
460 } catch (css::beans::UnknownPropertyException &) {}
461 try {
462 fullp->setPropertyValue(
463 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Fourth")),
464 css::uno::makeAny(static_cast< sal_Int32 >(100)));
465 FAIL() << "exception expected";
466 } catch (css::beans::UnknownPropertyException &) {}
467 try {
468 fullp->getPropertyValue(
469 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Fourth")));
470 FAIL() << "exception expected";
471 } catch (css::beans::UnknownPropertyException &) {}
472 try {
473 fullp->setPropertyValue(
474 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("first")),
475 css::uno::Any());
476 FAIL() << "exception expected";
477 } catch (css::beans::UnknownPropertyException &) {}
478 try {
479 fullp->getPropertyValue(
480 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("first")));
481 FAIL() << "exception expected";
482 } catch (css::beans::UnknownPropertyException &) {}
483 css::uno::Reference< css::beans::XFastPropertySet > fullf(
484 full, css::uno::UNO_QUERY);
485 ASSERT_TRUE(fullf.is());
486 ASSERT_EQ(
487 css::uno::makeAny(static_cast< sal_Int32 >(-100)),
488 fullf->getFastPropertyValue(0));
489 fullf->setFastPropertyValue(
490 0, css::uno::makeAny(static_cast< sal_Int32 >(0)));
491 ASSERT_EQ(
492 css::uno::makeAny(static_cast< sal_Int32 >(0)),
493 fullf->getFastPropertyValue(0));
494 try {
495 fullf->getFastPropertyValue(-1);
496 } catch (css::beans::UnknownPropertyException &) {}
497 try {
498 fullf->setFastPropertyValue(-1, css::uno::Any());
499 } catch (css::beans::UnknownPropertyException &) {}
500 css::uno::Reference< css::beans::XPropertyAccess > fulla(
501 full, css::uno::UNO_QUERY);
502 ASSERT_TRUE(fulla.is());
503 css::uno::Sequence< css::beans::PropertyValue > vs(
504 fulla->getPropertyValues());
505 ASSERT_EQ(static_cast< sal_Int32 >(2), vs.getLength());
506 ASSERT_EQ(
507 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("First")), vs[0].Name);
508 ASSERT_EQ(static_cast< sal_Int32 >(0), vs[0].Handle);
509 ASSERT_EQ(
510 css::uno::makeAny(static_cast< sal_Int32 >(0)), vs[0].Value);
511 ASSERT_EQ(css::beans::PropertyState_DIRECT_VALUE, vs[0].State);
512 ASSERT_EQ(
513 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Second")), vs[1].Name);
514 ASSERT_EQ(static_cast< sal_Int32 >(1), vs[1].Handle);
515 ASSERT_EQ(voidAny, vs[1].Value);
516 ASSERT_EQ(css::beans::PropertyState_DIRECT_VALUE, vs[1].State);
517 vs[0].Value <<= static_cast< sal_Int32 >(-100);
518 vs[1].Value <<= static_cast< sal_Int32 >(100);
519 vs[1].State = css::beans::PropertyState_AMBIGUOUS_VALUE;
520 fulla->setPropertyValues(vs);
521 vs = fulla->getPropertyValues();
522 ASSERT_EQ(static_cast< sal_Int32 >(2), vs.getLength());
523 ASSERT_EQ(
524 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("First")), vs[0].Name);
525 ASSERT_EQ(
526 css::uno::makeAny(static_cast< sal_Int32 >(-100)), vs[0].Value);
527 ASSERT_EQ(css::beans::PropertyState_DIRECT_VALUE, vs[0].State);
528 ASSERT_EQ(
529 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Second")), vs[1].Name);
530 ASSERT_EQ(
531 css::uno::makeAny(static_cast< sal_Int32 >(100)), vs[1].Value);
532 ASSERT_EQ(
533 css::beans::PropertyState_AMBIGUOUS_VALUE, vs[1].State);
534 ASSERT_TRUE(full->getSecond().Value.Value.IsPresent);
535 ASSERT_EQ(
536 static_cast< sal_Int32 >(100), full->getSecond().Value.Value.Value);
537 ASSERT_TRUE(!full->getSecond().Value.IsDefaulted);
538 ASSERT_TRUE(full->getSecond().IsAmbiguous);
539 css::uno::Reference< css::beans::XPropertyChangeListener > boundListener(
540 new BoundListener);
541 fullp->addPropertyChangeListener(
542 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("First")), boundListener);
543 fullp->removePropertyChangeListener(
544 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("First")), boundListener);
545 fullp->addPropertyChangeListener(
546 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Second")), boundListener);
547 fullp->removePropertyChangeListener(
548 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Second")), boundListener);
549 try {
550 fullp->addPropertyChangeListener(
551 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Third")),
552 boundListener);
553 FAIL() << "exception expected";
554 } catch (css::beans::UnknownPropertyException &) {}
555 try {
556 fullp->removePropertyChangeListener(
557 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Third")),
558 boundListener);
559 FAIL() << "exception expected";
560 } catch (css::beans::UnknownPropertyException &) {}
561 fullp->addPropertyChangeListener(
562 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Fourth")), boundListener);
563 fullp->removePropertyChangeListener(
564 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Fourth")), boundListener);
565 try {
566 fullp->addPropertyChangeListener(
567 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Fifth")),
568 boundListener);
569 FAIL() << "exception expected";
570 } catch (css::beans::UnknownPropertyException &) {}
571 try {
572 fullp->removePropertyChangeListener(
573 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Fifth")),
574 boundListener);
575 FAIL() << "exception expected";
576 } catch (css::beans::UnknownPropertyException &) {}
577 css::uno::Reference< css::beans::XVetoableChangeListener > vetoListener(
578 new VetoListener);
579 fullp->addVetoableChangeListener(
580 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("First")), vetoListener);
581 fullp->removeVetoableChangeListener(
582 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("First")), vetoListener);
583 fullp->addVetoableChangeListener(
584 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Second")), vetoListener);
585 fullp->removeVetoableChangeListener(
586 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Second")), vetoListener);
587 try {
588 fullp->addVetoableChangeListener(
589 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Third")),
590 vetoListener);
591 FAIL() << "exception expected";
592 } catch (css::beans::UnknownPropertyException &) {}
593 try {
594 fullp->removeVetoableChangeListener(
595 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Third")),
596 vetoListener);
597 FAIL() << "exception expected";
598 } catch (css::beans::UnknownPropertyException &) {}
599 fullp->addVetoableChangeListener(
600 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Fourth")), vetoListener);
601 fullp->removeVetoableChangeListener(
602 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Fourth")), vetoListener);
603 try {
604 fullp->addVetoableChangeListener(
605 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Fifth")),
606 vetoListener);
607 FAIL() << "exception expected";
608 } catch (css::beans::UnknownPropertyException &) {}
609 try {
610 fullp->removeVetoableChangeListener(
611 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Fifth")),
612 vetoListener);
613 FAIL() << "exception expected";
614 } catch (css::beans::UnknownPropertyException &) {}
615 }
616
TEST_F(Test,testCppEmpty1)617 TEST_F(Test, testCppEmpty1) { testEmpty1(getCppSupplier()); }
618
TEST_F(Test,testCppEmpty2)619 TEST_F(Test, testCppEmpty2) { testEmpty2(getCppSupplier()); }
620
TEST_F(Test,testCppFull)621 TEST_F(Test, testCppFull) { testFull(getCppSupplier()); }
622
TEST_F(Test,testJavaEmpty1)623 TEST_F(Test, testJavaEmpty1) { testEmpty1(getJavaSupplier()); }
624
TEST_F(Test,testJavaEmpty2)625 TEST_F(Test, testJavaEmpty2) { testEmpty2(getJavaSupplier()); }
626
TEST_F(Test,testJavaFull)627 TEST_F(Test, testJavaFull) { testFull(getJavaSupplier()); }
628
629
630
631 }
632
main(int argc,char ** argv)633 int main(int argc, char **argv)
634 {
635 osl_setCommandArgs(argc, argv);
636 ::testing::InitGoogleTest(&argc, argv);
637 return RUN_ALL_TESTS();
638 }
639