update dev300-m58
[ooovba.git] / cppuhelper / qa / propertysetmixin / test_propertysetmixin.cxx
blob15213132cd4e3f6811e1e2a6edfec913db7a1ed0
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: test_propertysetmixin.cxx,v $
10 * $Revision: 1.6 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_cppuhelper.hxx"
34 #include "sal/config.h"
36 #include "test/cppuhelper/propertysetmixin/CppSupplier.hpp"
37 #include "test/cppuhelper/propertysetmixin/JavaSupplier.hpp"
38 #include "test/cppuhelper/propertysetmixin/XSupplier.hpp"
39 #include "test/cppuhelper/propertysetmixin/XTest3.hpp"
41 #include "com/sun/star/beans/Ambiguous.hpp"
42 #include "com/sun/star/beans/Defaulted.hpp"
43 #include "com/sun/star/beans/Optional.hpp"
44 #include "com/sun/star/beans/Property.hpp"
45 #include "com/sun/star/beans/PropertyAttribute.hpp"
46 #include "com/sun/star/beans/PropertyChangeEvent.hpp"
47 #include "com/sun/star/beans/PropertyState.hpp"
48 #include "com/sun/star/beans/PropertyValue.hpp"
49 #include "com/sun/star/beans/PropertyVetoException.hpp"
50 #include "com/sun/star/beans/UnknownPropertyException.hpp"
51 #include "com/sun/star/beans/XFastPropertySet.hpp"
52 #include "com/sun/star/beans/XPropertyAccess.hpp"
53 #include "com/sun/star/beans/XPropertyChangeListener.hpp"
54 #include "com/sun/star/beans/XPropertySet.hpp"
55 #include "com/sun/star/beans/XPropertySetInfo.hpp"
56 #include "com/sun/star/beans/XVetoableChangeListener.hpp"
57 #include "com/sun/star/lang/XComponent.hpp"
58 #include "com/sun/star/lang/XMultiComponentFactory.hpp"
59 #include "com/sun/star/uno/Any.hxx"
60 #include "com/sun/star/uno/Reference.hxx"
61 #include "com/sun/star/uno/RuntimeException.hpp"
62 #include "com/sun/star/uno/Sequence.hxx"
63 #include "com/sun/star/uno/Type.hxx"
64 #include "com/sun/star/uno/XComponentContext.hpp"
65 #include "cppuhelper/implbase1.hxx"
66 #include "cppuhelper/servicefactory.hxx"
67 #include "cppunit/simpleheader.hxx"
68 #include "osl/mutex.hxx"
69 #include "osl/thread.h"
70 #include "rtl/ref.hxx"
71 #include "rtl/string.h"
72 #include "rtl/textenc.h"
73 #include "rtl/ustring.h"
74 #include "rtl/ustring.hxx"
75 #include "sal/types.h"
77 #include <limits>
78 #include <ostream>
80 namespace com { namespace sun { namespace star {
81 struct EventObject;
82 } } }
84 namespace css = com::sun::star;
86 namespace {
88 std::ostream & operator <<(std::ostream & out, rtl::OUString const & value) {
89 return out << rtl::OUStringToOString(value, RTL_TEXTENCODING_UTF8).getStr();
92 std::ostream & operator <<(std::ostream & out, css::uno::Type const & value) {
93 return out << "com::sun::star::uno::Type[" << value.getTypeName() << ']';
96 std::ostream & operator <<(std::ostream & out, css::uno::Any const & value) {
97 return
98 out << "com::sun::star::uno::Any[" << value.getValueType() << ", ...]";
101 class BoundListener:
102 public cppu::WeakImplHelper1< css::beans::XPropertyChangeListener >
104 public:
105 BoundListener(): m_count(0) {}
107 int count() const {
108 osl::MutexGuard g(m_mutex);
109 return m_count;
112 virtual void SAL_CALL disposing(css::lang::EventObject const &)
113 throw (css::uno::RuntimeException)
115 osl::MutexGuard g(m_mutex);
116 CPPUNIT_ASSERT(m_count < std::numeric_limits< int >::max());
117 ++m_count;
120 virtual void SAL_CALL propertyChange(
121 css::beans::PropertyChangeEvent const &)
122 throw (css::uno::RuntimeException)
123 { CPPUNIT_FAIL("BoundListener::propertyChange called"); }
125 private:
126 BoundListener(BoundListener &); // not defined
127 void operator =(BoundListener &); // not defined
129 virtual ~BoundListener() {}
131 mutable osl::Mutex m_mutex;
132 int m_count;
135 class VetoListener:
136 public cppu::WeakImplHelper1< css::beans::XVetoableChangeListener >
138 public:
139 VetoListener(): m_count(0) {}
141 int count() const {
142 osl::MutexGuard g(m_mutex);
143 return m_count;
146 virtual void SAL_CALL disposing(css::lang::EventObject const &)
147 throw (css::uno::RuntimeException)
149 osl::MutexGuard g(m_mutex);
150 CPPUNIT_ASSERT(m_count < std::numeric_limits< int >::max());
151 ++m_count;
154 virtual void SAL_CALL vetoableChange(
155 css::beans::PropertyChangeEvent const &)
156 throw (css::beans::PropertyVetoException, css::uno::RuntimeException)
157 { CPPUNIT_FAIL("VetoListener::vetoableChange called"); }
159 private:
160 VetoListener(VetoListener &); // not defined
161 void operator =(VetoListener &); // not defined
163 virtual ~VetoListener() {}
165 mutable osl::Mutex m_mutex;
166 int m_count;
169 class Test: public CppUnit::TestFixture {
170 public:
171 virtual void setUp();
173 void finish();
175 void testCppEmpty1() { testEmpty1(getCppSupplier()); }
177 void testCppEmpty2() { testEmpty2(getCppSupplier()); }
179 void testCppFull() { testFull(getCppSupplier()); }
181 void testJavaEmpty1() { testEmpty1(getJavaSupplier()); }
183 void testJavaEmpty2() { testEmpty2(getJavaSupplier()); }
185 void testJavaFull() { testFull(getJavaSupplier()); }
187 CPPUNIT_TEST_SUITE(Test);
188 CPPUNIT_TEST(testCppEmpty1);
189 CPPUNIT_TEST(testCppEmpty2);
190 CPPUNIT_TEST(testCppFull);
191 CPPUNIT_TEST(testJavaEmpty1);
192 CPPUNIT_TEST(testJavaEmpty2);
193 CPPUNIT_TEST(testJavaFull);
194 CPPUNIT_TEST(finish);
195 CPPUNIT_TEST_SUITE_END();
197 private:
198 css::uno::Reference< test::cppuhelper::propertysetmixin::XSupplier >
199 getCppSupplier() const;
201 css::uno::Reference< test::cppuhelper::propertysetmixin::XSupplier >
202 getJavaSupplier() const;
204 void testEmpty1(
205 css::uno::Reference< test::cppuhelper::propertysetmixin::XSupplier >
206 const & supplier) const;
208 void testEmpty2(
209 css::uno::Reference< test::cppuhelper::propertysetmixin::XSupplier >
210 const & supplier) const;
212 void testFull(
213 css::uno::Reference< test::cppuhelper::propertysetmixin::XSupplier >
214 const & supplier) const;
216 static css::uno::Reference< css::uno::XComponentContext > m_context;
219 void Test::setUp() {
220 // For whatever reason, on W32 it does not work to create/destroy a fresh
221 // component context for each test in Test::setUp/tearDown; therefore, a
222 // single component context is used for all tests and destroyed in the last
223 // pseudo-test "finish":
224 if (!m_context.is()) {
225 char const * fw = getForwardString();
226 rtl::OUString forward(fw, rtl_str_getLength(fw),
227 osl_getThreadTextEncoding());
228 //TODO: check for string conversion failure
229 sal_Int32 index = forward.indexOf('#');
230 rtl::OUString registry = forward.copy(0, index);
231 rtl::OUString bootstrappath = forward.copy(index+1);
233 css::uno::Reference< css::lang::XMultiComponentFactory > factory(
234 cppu::createRegistryServiceFactory(
235 registry, sal_False, bootstrappath),
236 css::uno::UNO_QUERY_THROW);
237 css::uno::Reference< css::beans::XPropertySet >(
238 factory, css::uno::UNO_QUERY_THROW)->getPropertyValue(
239 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DefaultContext")))
240 >>= m_context;
244 void Test::finish() {
245 css::uno::Reference< css::lang::XComponent >(
246 m_context, css::uno::UNO_QUERY_THROW)->dispose();
249 css::uno::Reference< test::cppuhelper::propertysetmixin::XSupplier >
250 Test::getCppSupplier() const
252 return test::cppuhelper::propertysetmixin::CppSupplier::create(m_context);
255 css::uno::Reference< test::cppuhelper::propertysetmixin::XSupplier >
256 Test::getJavaSupplier() const
258 return test::cppuhelper::propertysetmixin::JavaSupplier::create(m_context);
261 void Test::testEmpty1(
262 css::uno::Reference< test::cppuhelper::propertysetmixin::XSupplier >
263 const & supplier) const
265 css::uno::Reference< css::lang::XComponent > empty1(
266 supplier->getEmpty1(), css::uno::UNO_QUERY_THROW);
267 CPPUNIT_ASSERT(
268 !css::uno::Reference< css::beans::XPropertySet >(
269 empty1, css::uno::UNO_QUERY).is());
270 CPPUNIT_ASSERT(
271 !css::uno::Reference< css::beans::XFastPropertySet >(
272 empty1, css::uno::UNO_QUERY).is());
273 CPPUNIT_ASSERT(
274 !css::uno::Reference< css::beans::XPropertyAccess >(
275 empty1, css::uno::UNO_QUERY).is());
276 empty1->dispose();
279 void Test::testEmpty2(
280 css::uno::Reference< test::cppuhelper::propertysetmixin::XSupplier >
281 const & supplier) const
283 css::uno::Reference< css::lang::XComponent > empty2(
284 supplier->getEmpty2(), css::uno::UNO_QUERY_THROW);
285 css::uno::Reference< css::beans::XPropertySet > empty2p(
286 empty2, css::uno::UNO_QUERY);
287 CPPUNIT_ASSERT(empty2p.is());
288 css::uno::Reference< css::beans::XPropertySetInfo > info(
289 empty2p->getPropertySetInfo());
290 CPPUNIT_ASSERT(info.is());
291 CPPUNIT_ASSERT_EQUAL(
292 static_cast< sal_Int32 >(0), info->getProperties().getLength());
293 try {
294 info->getPropertyByName(
295 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("any")));
296 CPPUNIT_FAIL("exception expected");
297 } catch (css::beans::UnknownPropertyException &) {}
298 CPPUNIT_ASSERT(
299 !info->hasPropertyByName(
300 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("any"))));
301 try {
302 empty2p->setPropertyValue(
303 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("any")), css::uno::Any());
304 CPPUNIT_FAIL("exception expected");
305 } catch (css::beans::UnknownPropertyException &) {}
306 try {
307 empty2p->getPropertyValue(
308 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("any")));
309 CPPUNIT_FAIL("exception expected");
310 } catch (css::beans::UnknownPropertyException &) {}
311 rtl::Reference< BoundListener > boundListener1(new BoundListener);
312 empty2p->addPropertyChangeListener(rtl::OUString(), boundListener1.get());
313 empty2p->addPropertyChangeListener(rtl::OUString(), boundListener1.get());
314 rtl::Reference< BoundListener > boundListener2(new BoundListener);
315 empty2p->removePropertyChangeListener(
316 rtl::OUString(), boundListener2.get());
317 rtl::Reference< VetoListener > vetoListener1(new VetoListener);
318 empty2p->addVetoableChangeListener(rtl::OUString(), vetoListener1.get());
319 empty2p->addVetoableChangeListener(rtl::OUString(), vetoListener1.get());
320 rtl::Reference< VetoListener > vetoListener2(new VetoListener);
321 empty2p->addVetoableChangeListener(rtl::OUString(), vetoListener2.get());
322 empty2p->removeVetoableChangeListener(rtl::OUString(), vetoListener2.get());
323 css::uno::Reference< css::beans::XFastPropertySet > empty2f(
324 empty2, css::uno::UNO_QUERY);
325 CPPUNIT_ASSERT(empty2f.is());
326 try {
327 empty2f->setFastPropertyValue(-1, css::uno::Any());
328 CPPUNIT_FAIL("exception expected");
329 } catch (css::beans::UnknownPropertyException &) {}
330 try {
331 empty2f->setFastPropertyValue(0, css::uno::Any());
332 CPPUNIT_FAIL("exception expected");
333 } catch (css::beans::UnknownPropertyException &) {}
334 try {
335 empty2f->getFastPropertyValue(-1);
336 CPPUNIT_FAIL("exception expected");
337 } catch (css::beans::UnknownPropertyException &) {}
338 try {
339 empty2f->getFastPropertyValue(0);
340 CPPUNIT_FAIL("exception expected");
341 } catch (css::beans::UnknownPropertyException &) {}
342 css::uno::Reference< css::beans::XPropertyAccess > empty2a(
343 empty2, css::uno::UNO_QUERY);
344 CPPUNIT_ASSERT(empty2a.is());
345 CPPUNIT_ASSERT_EQUAL(
346 static_cast< sal_Int32 >(0), empty2a->getPropertyValues().getLength());
347 empty2a->setPropertyValues(
348 css::uno::Sequence< css::beans::PropertyValue >());
349 css::uno::Sequence< css::beans::PropertyValue > vs(2);
350 vs[0].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("any1"));
351 vs[0].Handle = -1;
352 vs[0].State = css::beans::PropertyState_DIRECT_VALUE;
353 vs[0].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("any2"));
354 vs[0].Handle = -1;
355 vs[0].State = css::beans::PropertyState_DIRECT_VALUE;
356 try {
357 empty2a->setPropertyValues(vs);
358 CPPUNIT_FAIL("exception expected");
359 } catch (css::beans::UnknownPropertyException &) {}
360 CPPUNIT_ASSERT_EQUAL(0, boundListener1->count());
361 CPPUNIT_ASSERT_EQUAL(0, boundListener2->count());
362 CPPUNIT_ASSERT_EQUAL(0, vetoListener1->count());
363 CPPUNIT_ASSERT_EQUAL(0, vetoListener2->count());
364 empty2->dispose();
365 CPPUNIT_ASSERT_EQUAL(2, boundListener1->count());
366 CPPUNIT_ASSERT_EQUAL(0, boundListener2->count());
367 CPPUNIT_ASSERT_EQUAL(2, vetoListener1->count());
368 CPPUNIT_ASSERT_EQUAL(0, vetoListener2->count());
369 empty2p->removePropertyChangeListener(
370 rtl::OUString(), boundListener1.get());
371 empty2p->removePropertyChangeListener(
372 rtl::OUString(), boundListener2.get());
373 empty2p->removeVetoableChangeListener(rtl::OUString(), vetoListener1.get());
374 empty2p->removeVetoableChangeListener(rtl::OUString(), vetoListener2.get());
375 empty2p->addPropertyChangeListener(rtl::OUString(), boundListener1.get());
376 empty2p->addPropertyChangeListener(rtl::OUString(), boundListener2.get());
377 empty2p->addVetoableChangeListener(rtl::OUString(), vetoListener1.get());
378 empty2p->addVetoableChangeListener(rtl::OUString(), vetoListener2.get());
379 try {
380 empty2p->addPropertyChangeListener(
381 rtl::OUString(),
382 css::uno::Reference< css::beans::XPropertyChangeListener >());
383 } catch (css::uno::RuntimeException &) {}
384 try {
385 empty2p->addVetoableChangeListener(
386 rtl::OUString(),
387 css::uno::Reference< css::beans::XVetoableChangeListener >());
388 } catch (css::uno::RuntimeException &) {}
389 CPPUNIT_ASSERT_EQUAL(3, boundListener1->count());
390 CPPUNIT_ASSERT_EQUAL(1, boundListener2->count());
391 CPPUNIT_ASSERT_EQUAL(3, vetoListener1->count());
392 CPPUNIT_ASSERT_EQUAL(1, vetoListener2->count());
395 void Test::testFull(
396 css::uno::Reference< test::cppuhelper::propertysetmixin::XSupplier >
397 const & supplier) const
399 css::uno::Reference< test::cppuhelper::propertysetmixin::XTest3 > full(
400 supplier->getFull(), css::uno::UNO_QUERY_THROW);
401 css::uno::Reference< css::beans::XPropertySet > fullp(
402 full, css::uno::UNO_QUERY);
403 CPPUNIT_ASSERT(fullp.is());
404 css::uno::Reference< css::beans::XPropertySetInfo > info(
405 fullp->getPropertySetInfo());
406 CPPUNIT_ASSERT(info.is());
407 CPPUNIT_ASSERT_EQUAL(
408 static_cast< sal_Int32 >(3), info->getProperties().getLength());
409 css::beans::Property prop(
410 info->getPropertyByName(
411 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("First"))));
412 CPPUNIT_ASSERT_EQUAL(
413 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("First")), prop.Name);
414 CPPUNIT_ASSERT_EQUAL(static_cast< sal_Int32 >(0), prop.Handle);
415 CPPUNIT_ASSERT_EQUAL(getCppuType(static_cast< sal_Int32 * >(0)), prop.Type);
416 CPPUNIT_ASSERT_EQUAL(static_cast< sal_Int16 >(0), prop.Attributes);
417 prop = info->getPropertyByName(
418 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Second")));
419 CPPUNIT_ASSERT_EQUAL(
420 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Second")), prop.Name);
421 CPPUNIT_ASSERT_EQUAL(static_cast< sal_Int32 >(1), prop.Handle);
422 CPPUNIT_ASSERT_EQUAL(getCppuType(static_cast< sal_Int32 * >(0)), prop.Type);
423 CPPUNIT_ASSERT_EQUAL(
424 static_cast< sal_Int16 >(
425 css::beans::PropertyAttribute::MAYBEVOID
426 | css::beans::PropertyAttribute::BOUND
427 | css::beans::PropertyAttribute::CONSTRAINED
428 | css::beans::PropertyAttribute::MAYBEAMBIGUOUS
429 | css::beans::PropertyAttribute::MAYBEDEFAULT
430 | css::beans::PropertyAttribute::OPTIONAL),
431 prop.Attributes);
432 try {
433 info->getPropertyByName(
434 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Third")));
435 CPPUNIT_FAIL("exception expected");
436 } catch (css::beans::UnknownPropertyException &) {}
437 prop = info->getPropertyByName(
438 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Fourth")));
439 CPPUNIT_ASSERT_EQUAL(
440 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Fourth")), prop.Name);
441 CPPUNIT_ASSERT_EQUAL(static_cast< sal_Int32 >(3), prop.Handle);
442 CPPUNIT_ASSERT_EQUAL(getCppuType(static_cast< sal_Int32 * >(0)), prop.Type);
443 CPPUNIT_ASSERT_EQUAL(
444 static_cast< sal_Int16 >(css::beans::PropertyAttribute::OPTIONAL),
445 prop.Attributes);
446 try {
447 info->getPropertyByName(
448 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("first")));
449 CPPUNIT_FAIL("exception expected");
450 } catch (css::beans::UnknownPropertyException &) {}
451 CPPUNIT_ASSERT(
452 info->hasPropertyByName(
453 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("First"))));
454 CPPUNIT_ASSERT(
455 info->hasPropertyByName(
456 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Second"))));
457 CPPUNIT_ASSERT(
458 !info->hasPropertyByName(
459 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Third"))));
460 CPPUNIT_ASSERT(
461 info->hasPropertyByName(
462 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Fourth"))));
463 CPPUNIT_ASSERT(
464 !info->hasPropertyByName(
465 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("first"))));
466 CPPUNIT_ASSERT_EQUAL(
467 css::uno::makeAny(static_cast< sal_Int32 >(0)),
468 fullp->getPropertyValue(
469 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("First"))));
470 fullp->setPropertyValue(
471 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("First")),
472 css::uno::makeAny(static_cast< sal_Int32 >(-100)));
473 CPPUNIT_ASSERT_EQUAL(
474 css::uno::makeAny(static_cast< sal_Int32 >(-100)),
475 fullp->getPropertyValue(
476 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("First"))));
477 css::uno::Any voidAny;
478 CPPUNIT_ASSERT_EQUAL(
479 voidAny,
480 fullp->getPropertyValue(
481 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Second"))));
482 fullp->setPropertyValue(
483 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Second")),
484 css::uno::makeAny(static_cast< sal_Int32 >(100)));
485 CPPUNIT_ASSERT_EQUAL(
486 css::uno::makeAny(static_cast< sal_Int32 >(100)),
487 fullp->getPropertyValue(
488 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Second"))));
489 CPPUNIT_ASSERT(full->getSecond().Value.Value.IsPresent);
490 CPPUNIT_ASSERT_EQUAL(
491 static_cast< sal_Int32 >(100), full->getSecond().Value.Value.Value);
492 CPPUNIT_ASSERT(!full->getSecond().Value.IsDefaulted);
493 CPPUNIT_ASSERT(!full->getSecond().IsAmbiguous);
494 fullp->setPropertyValue(
495 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Second")),
496 css::uno::Any());
497 CPPUNIT_ASSERT_EQUAL(
498 voidAny,
499 fullp->getPropertyValue(
500 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Second"))));
501 CPPUNIT_ASSERT(!full->getSecond().Value.Value.IsPresent);
502 CPPUNIT_ASSERT(!full->getSecond().Value.IsDefaulted);
503 CPPUNIT_ASSERT(!full->getSecond().IsAmbiguous);
504 try {
505 fullp->setPropertyValue(
506 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Third")),
507 css::uno::makeAny(static_cast< sal_Int32 >(100)));
508 CPPUNIT_FAIL("exception expected");
509 } catch (css::beans::UnknownPropertyException &) {}
510 try {
511 fullp->getPropertyValue(
512 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Third")));
513 CPPUNIT_FAIL("exception expected");
514 } catch (css::beans::UnknownPropertyException &) {}
515 try {
516 fullp->setPropertyValue(
517 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Fourth")),
518 css::uno::makeAny(static_cast< sal_Int32 >(100)));
519 CPPUNIT_FAIL("exception expected");
520 } catch (css::beans::UnknownPropertyException &) {}
521 try {
522 fullp->getPropertyValue(
523 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Fourth")));
524 CPPUNIT_FAIL("exception expected");
525 } catch (css::beans::UnknownPropertyException &) {}
526 try {
527 fullp->setPropertyValue(
528 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("first")),
529 css::uno::Any());
530 CPPUNIT_FAIL("exception expected");
531 } catch (css::beans::UnknownPropertyException &) {}
532 try {
533 fullp->getPropertyValue(
534 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("first")));
535 CPPUNIT_FAIL("exception expected");
536 } catch (css::beans::UnknownPropertyException &) {}
537 css::uno::Reference< css::beans::XFastPropertySet > fullf(
538 full, css::uno::UNO_QUERY);
539 CPPUNIT_ASSERT(fullf.is());
540 CPPUNIT_ASSERT_EQUAL(
541 css::uno::makeAny(static_cast< sal_Int32 >(-100)),
542 fullf->getFastPropertyValue(0));
543 fullf->setFastPropertyValue(
544 0, css::uno::makeAny(static_cast< sal_Int32 >(0)));
545 CPPUNIT_ASSERT_EQUAL(
546 css::uno::makeAny(static_cast< sal_Int32 >(0)),
547 fullf->getFastPropertyValue(0));
548 try {
549 fullf->getFastPropertyValue(-1);
550 } catch (css::beans::UnknownPropertyException &) {}
551 try {
552 fullf->setFastPropertyValue(-1, css::uno::Any());
553 } catch (css::beans::UnknownPropertyException &) {}
554 css::uno::Reference< css::beans::XPropertyAccess > fulla(
555 full, css::uno::UNO_QUERY);
556 CPPUNIT_ASSERT(fulla.is());
557 css::uno::Sequence< css::beans::PropertyValue > vs(
558 fulla->getPropertyValues());
559 CPPUNIT_ASSERT_EQUAL(static_cast< sal_Int32 >(2), vs.getLength());
560 CPPUNIT_ASSERT_EQUAL(
561 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("First")), vs[0].Name);
562 CPPUNIT_ASSERT_EQUAL(static_cast< sal_Int32 >(0), vs[0].Handle);
563 CPPUNIT_ASSERT_EQUAL(
564 css::uno::makeAny(static_cast< sal_Int32 >(0)), vs[0].Value);
565 CPPUNIT_ASSERT_EQUAL(css::beans::PropertyState_DIRECT_VALUE, vs[0].State);
566 CPPUNIT_ASSERT_EQUAL(
567 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Second")), vs[1].Name);
568 CPPUNIT_ASSERT_EQUAL(static_cast< sal_Int32 >(1), vs[1].Handle);
569 CPPUNIT_ASSERT_EQUAL(voidAny, vs[1].Value);
570 CPPUNIT_ASSERT_EQUAL(css::beans::PropertyState_DIRECT_VALUE, vs[1].State);
571 vs[0].Value <<= static_cast< sal_Int32 >(-100);
572 vs[1].Value <<= static_cast< sal_Int32 >(100);
573 vs[1].State = css::beans::PropertyState_AMBIGUOUS_VALUE;
574 fulla->setPropertyValues(vs);
575 vs = fulla->getPropertyValues();
576 CPPUNIT_ASSERT_EQUAL(static_cast< sal_Int32 >(2), vs.getLength());
577 CPPUNIT_ASSERT_EQUAL(
578 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("First")), vs[0].Name);
579 CPPUNIT_ASSERT_EQUAL(
580 css::uno::makeAny(static_cast< sal_Int32 >(-100)), vs[0].Value);
581 CPPUNIT_ASSERT_EQUAL(css::beans::PropertyState_DIRECT_VALUE, vs[0].State);
582 CPPUNIT_ASSERT_EQUAL(
583 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Second")), vs[1].Name);
584 CPPUNIT_ASSERT_EQUAL(
585 css::uno::makeAny(static_cast< sal_Int32 >(100)), vs[1].Value);
586 CPPUNIT_ASSERT_EQUAL(
587 css::beans::PropertyState_AMBIGUOUS_VALUE, vs[1].State);
588 CPPUNIT_ASSERT(full->getSecond().Value.Value.IsPresent);
589 CPPUNIT_ASSERT_EQUAL(
590 static_cast< sal_Int32 >(100), full->getSecond().Value.Value.Value);
591 CPPUNIT_ASSERT(!full->getSecond().Value.IsDefaulted);
592 CPPUNIT_ASSERT(full->getSecond().IsAmbiguous);
593 css::uno::Reference< css::beans::XPropertyChangeListener > boundListener(
594 new BoundListener);
595 fullp->addPropertyChangeListener(
596 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("First")), boundListener);
597 fullp->removePropertyChangeListener(
598 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("First")), boundListener);
599 fullp->addPropertyChangeListener(
600 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Second")), boundListener);
601 fullp->removePropertyChangeListener(
602 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Second")), boundListener);
603 try {
604 fullp->addPropertyChangeListener(
605 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Third")),
606 boundListener);
607 CPPUNIT_FAIL("exception expected");
608 } catch (css::beans::UnknownPropertyException &) {}
609 try {
610 fullp->removePropertyChangeListener(
611 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Third")),
612 boundListener);
613 CPPUNIT_FAIL("exception expected");
614 } catch (css::beans::UnknownPropertyException &) {}
615 fullp->addPropertyChangeListener(
616 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Fourth")), boundListener);
617 fullp->removePropertyChangeListener(
618 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Fourth")), boundListener);
619 try {
620 fullp->addPropertyChangeListener(
621 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Fifth")),
622 boundListener);
623 CPPUNIT_FAIL("exception expected");
624 } catch (css::beans::UnknownPropertyException &) {}
625 try {
626 fullp->removePropertyChangeListener(
627 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Fifth")),
628 boundListener);
629 CPPUNIT_FAIL("exception expected");
630 } catch (css::beans::UnknownPropertyException &) {}
631 css::uno::Reference< css::beans::XVetoableChangeListener > vetoListener(
632 new VetoListener);
633 fullp->addVetoableChangeListener(
634 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("First")), vetoListener);
635 fullp->removeVetoableChangeListener(
636 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("First")), vetoListener);
637 fullp->addVetoableChangeListener(
638 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Second")), vetoListener);
639 fullp->removeVetoableChangeListener(
640 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Second")), vetoListener);
641 try {
642 fullp->addVetoableChangeListener(
643 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Third")),
644 vetoListener);
645 CPPUNIT_FAIL("exception expected");
646 } catch (css::beans::UnknownPropertyException &) {}
647 try {
648 fullp->removeVetoableChangeListener(
649 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Third")),
650 vetoListener);
651 CPPUNIT_FAIL("exception expected");
652 } catch (css::beans::UnknownPropertyException &) {}
653 fullp->addVetoableChangeListener(
654 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Fourth")), vetoListener);
655 fullp->removeVetoableChangeListener(
656 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Fourth")), vetoListener);
657 try {
658 fullp->addVetoableChangeListener(
659 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Fifth")),
660 vetoListener);
661 CPPUNIT_FAIL("exception expected");
662 } catch (css::beans::UnknownPropertyException &) {}
663 try {
664 fullp->removeVetoableChangeListener(
665 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Fifth")),
666 vetoListener);
667 CPPUNIT_FAIL("exception expected");
668 } catch (css::beans::UnknownPropertyException &) {}
671 css::uno::Reference< css::uno::XComponentContext > Test::m_context;
673 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(Test, "alltests");
677 NOADDITIONAL;