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