1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #if !defined(OSL_DEBUG_LEVEL) || OSL_DEBUG_LEVEL == 0 29 # undef OSL_DEBUG_LEVEL 30 # define OSL_DEBUG_LEVEL 2 31 #endif 32 33 34 // MARKER(update_precomp.py): autogen include statement, do not remove 35 #include "precompiled_cppuhelper.hxx" 36 #include <osl/mutex.hxx> 37 #include <osl/diagnose.h> 38 39 #include <cppuhelper/propshlp.hxx> 40 #include <cppuhelper/weak.hxx> 41 42 #include <cppuhelper/proptypehlp.hxx> 43 44 #include <com/sun/star/uno/Any.hxx> 45 #include <com/sun/star/beans/PropertyAttribute.hpp> 46 47 #include <cppuhelper/implbase3.hxx> 48 49 using namespace ::cppu; 50 using namespace ::rtl; 51 using namespace ::osl; 52 using namespace ::com::sun::star::uno; 53 using namespace ::com::sun::star::beans; 54 using namespace ::com::sun::star::lang; 55 56 57 58 /********************** 59 * 60 **********************/ 61 static Property * getPropertyTable1() 62 { 63 static Property *pTable = 0; 64 65 if( ! pTable ) { 66 MutexGuard guard( Mutex::getGlobalMutex() ); 67 if( ! pTable ) { 68 static Property aTable[] = 69 { 70 Property( OUString( RTL_CONSTASCII_USTRINGPARAM("a") ), 0, getCppuType( (OUString *)0) , 71 PropertyAttribute::READONLY | PropertyAttribute::MAYBEVOID ), //OUString 72 Property( OUString( RTL_CONSTASCII_USTRINGPARAM("b") ), 1, getCppuCharType( ) , 73 PropertyAttribute::READONLY | PropertyAttribute::MAYBEVOID ), //Char 74 Property( OUString( RTL_CONSTASCII_USTRINGPARAM("c") ), 2, getCppuType( (sal_Int32*)0) , 75 PropertyAttribute::READONLY | PropertyAttribute::MAYBEVOID ), //sal_Int32 76 Property( OUString( RTL_CONSTASCII_USTRINGPARAM("d") ), 5, getCppuType( (double*)0) , 77 PropertyAttribute::READONLY | PropertyAttribute::MAYBEVOID ), //double 78 Property( OUString( RTL_CONSTASCII_USTRINGPARAM("e") ), 7, getCppuBooleanType() , 79 PropertyAttribute::READONLY | PropertyAttribute::MAYBEVOID ), //BOOL 80 Property( OUString( RTL_CONSTASCII_USTRINGPARAM("f") ), 8, getCppuType( (Any*)0) , 81 PropertyAttribute::READONLY | PropertyAttribute::MAYBEVOID ) //Any 82 }; 83 pTable = aTable; 84 } 85 } 86 return pTable; 87 } 88 89 90 static Property * getPropertyTable2() 91 { 92 static Property *pTable = 0; 93 94 if( ! pTable ) { 95 MutexGuard guard( ::osl::Mutex::getGlobalMutex() ); 96 if( ! pTable ) { 97 static Property aTable[] = 98 { 99 Property( OUString( RTL_CONSTASCII_USTRINGPARAM("f") ), 8, getCppuType( (Any *)0) , 100 PropertyAttribute::READONLY | PropertyAttribute::MAYBEVOID ), // Any 101 Property( OUString( RTL_CONSTASCII_USTRINGPARAM("b") ), 1, getCppuCharType( ), 102 PropertyAttribute::READONLY | PropertyAttribute::MAYBEVOID ), // Char 103 Property( OUString( RTL_CONSTASCII_USTRINGPARAM("a") ), 0, getCppuType( (OUString*)0), 104 PropertyAttribute::READONLY | PropertyAttribute::MAYBEVOID ), // OUString 105 Property( OUString( RTL_CONSTASCII_USTRINGPARAM("d") ), 5, getCppuType( (double*)0) , 106 PropertyAttribute::READONLY | PropertyAttribute::MAYBEVOID ), // Double 107 Property( OUString( RTL_CONSTASCII_USTRINGPARAM("c") ), 2, getCppuType( (sal_Int32*)0), 108 PropertyAttribute::READONLY | PropertyAttribute::MAYBEVOID ), // sal_Int32 109 Property( OUString( RTL_CONSTASCII_USTRINGPARAM("e") ), 7, getCppuBooleanType() , 110 PropertyAttribute::READONLY | PropertyAttribute::MAYBEVOID ) // Bool 111 }; 112 pTable = aTable; 113 } 114 } 115 return pTable; 116 } 117 118 static Property * getPropertyTable3() 119 { 120 static Property *pTable = 0; 121 122 if( ! pTable ) { 123 MutexGuard guard( ::osl::Mutex::getGlobalMutex() ); 124 if( ! pTable ) { 125 static Property aTable[] = 126 { 127 Property( OUString( RTL_CONSTASCII_USTRINGPARAM("b") ), 1, getCppuCharType( ), 128 PropertyAttribute::READONLY | PropertyAttribute::MAYBEVOID ), // Char 129 Property( OUString( RTL_CONSTASCII_USTRINGPARAM("f") ), 8, getCppuType( (Any *)0) , 130 PropertyAttribute::READONLY | PropertyAttribute::MAYBEVOID ), // any 131 Property( OUString( RTL_CONSTASCII_USTRINGPARAM("a") ), 0, getCppuType( (OUString*)0), 132 PropertyAttribute::READONLY | PropertyAttribute::MAYBEVOID ) // OUString 133 }; 134 pTable = aTable; 135 } 136 } 137 return pTable; 138 } 139 140 141 static Property * getPropertyTable4() 142 { 143 static Property *pTable = 0; 144 145 if( ! pTable ) { 146 MutexGuard guard( ::osl::Mutex::getGlobalMutex() ); 147 if( ! pTable ) { 148 static Property aTable[] = 149 { 150 Property( OUString( RTL_CONSTASCII_USTRINGPARAM("a") ), 0, getCppuType( (OUString*)0), 151 PropertyAttribute::READONLY | PropertyAttribute::MAYBEVOID ), // OUString 152 Property( OUString( RTL_CONSTASCII_USTRINGPARAM("b") ), 1, getCppuCharType( ), 153 PropertyAttribute::READONLY | PropertyAttribute::MAYBEVOID ), // Char 154 Property( OUString( RTL_CONSTASCII_USTRINGPARAM("f") ), 2, getCppuType( (Any *)0) , 155 PropertyAttribute::READONLY | PropertyAttribute::MAYBEVOID ) // Any 156 }; 157 pTable = aTable; 158 } 159 } 160 return pTable; 161 } 162 163 164 165 /********************** 166 * 167 * Note : all Property names must be in the 127 ASCII subset ! 168 * 169 **********************/ 170 171 172 void test_PropertyArrayHelper() 173 { 174 // Test getProperties() and getCount() 175 { 176 OPropertyArrayHelper a1( getPropertyTable1(), 6 ); 177 OSL_ENSURE( 6 == a1.getCount(), "not all properties inserted" ); 178 Sequence< Property > aProps = a1.getProperties(); 179 Property * pP = aProps.getArray(); 180 OSL_ENSURE( 6 == aProps.getLength(), "getProperties() gives not all properties" ); 181 for( int i = 0; i < 6; i++ ) 182 { 183 OSL_ENSURE( pP[i].Name == getPropertyTable1()[i].Name , "Name not correct" ); 184 OSL_ENSURE( pP[i].Handle == getPropertyTable1()[i].Handle, "Handle not correct" ); 185 OSL_ENSURE( pP[i].Attributes == getPropertyTable1()[i].Attributes, "Attributes not correct" ); 186 OSL_ENSURE( pP[i].Type == getPropertyTable1()[i].Type, "Type not correct" ); 187 } 188 } 189 190 // Test sorting 191 { 192 OPropertyArrayHelper a1( getPropertyTable2(), 6, sal_False ); 193 Sequence< Property > aProps = a1.getProperties(); 194 Property * pP = aProps.getArray(); 195 OSL_ENSURE( 6 == aProps.getLength(), "getProperties() gives not all properties" ); 196 197 // table to switch to sorted 198 int a[] = { 2 , 1 , 4, 3, 5, 0 }; 199 for( int i = 0; i < 6; i++ ) 200 { 201 OSL_ENSURE( pP[i].Name == getPropertyTable2()[a[i]].Name , "Name not correct" ); 202 OSL_ENSURE( pP[i].Handle == getPropertyTable2()[a[i]].Handle, "Handle not correct" ); 203 OSL_ENSURE( pP[i].Attributes == getPropertyTable2()[a[i]].Attributes, "Attributes not correct" ); 204 OSL_ENSURE( pP[i].Type == getPropertyTable2()[a[i]].Type, "Type not correct" ); 205 } 206 } 207 208 // Test sorting 209 { 210 OPropertyArrayHelper a1( getPropertyTable3(), 3, sal_False ); 211 Sequence< Property > aProps = a1.getProperties(); 212 Property * pP = aProps.getArray(); 213 OSL_ENSURE( 3 == aProps.getLength(), "getProperties() gives not all properties" ); 214 // table to switch to sorted 215 int a[] = { 2 , 0 , 1 }; 216 for( int i = 0; i < 3; i++ ) 217 { 218 OSL_ENSURE( pP[i].Name == getPropertyTable3()[a[i]].Name , "Name not correct" ); 219 OSL_ENSURE( pP[i].Handle == getPropertyTable3()[a[i]].Handle, "Handle not correct" ); 220 OSL_ENSURE( pP[i].Attributes == getPropertyTable3()[a[i]].Attributes, "Attributes not correct" ); 221 OSL_ENSURE( pP[i].Type == getPropertyTable3()[a[i]].Type, "Type not correct" ); 222 } 223 } 224 225 // Test getPropertyByName and hasPropertyByName 226 { 227 OPropertyArrayHelper a1( getPropertyTable1(), 6 ); 228 for( int i = 0; i < 6; i++ ) 229 { 230 OSL_ENSURE( a1.hasPropertyByName( getPropertyTable1()[i].Name ), "hasPropertyByName not correct" ); 231 Property aP = a1.getPropertyByName( getPropertyTable1()[i].Name ); 232 OSL_ENSURE( aP.Name == getPropertyTable1()[i].Name , "Name not correct" ); 233 OSL_ENSURE( aP.Handle == getPropertyTable1()[i].Handle, "Handle not correct" ); 234 OSL_ENSURE( aP.Attributes == getPropertyTable1()[i].Attributes, "Attributes not correct" ); 235 OSL_ENSURE( aP.Type == getPropertyTable1()[i].Type, "Type not correct" ); 236 } 237 238 OSL_ENSURE( !a1.hasPropertyByName( OUString( RTL_CONSTASCII_USTRINGPARAM("never exist") ) ), "hasPropertyByName not correct" ); 239 try 240 { 241 a1.getPropertyByName( OUString( RTL_CONSTASCII_USTRINGPARAM("never exist") ) ); 242 OSL_ENSURE( sal_False, "exeption not thrown" ); 243 } 244 catch( UnknownPropertyException & ) 245 { 246 } 247 } 248 249 // Test getHandleByName 250 { 251 OPropertyArrayHelper a1( getPropertyTable1(), 6 ); 252 for( int i = 0; i < 6; i++ ) 253 { 254 sal_Int32 Handle = a1.getHandleByName( getPropertyTable1()[i].Name ); 255 OSL_ENSURE( Handle == getPropertyTable1()[i].Handle, "Handle not correct" ); 256 } 257 sal_Int32 Handle = a1.getHandleByName( OUString( RTL_CONSTASCII_USTRINGPARAM("asdaf") ) ); 258 OSL_ENSURE( Handle == -1, "Handle not correct" ); 259 } 260 261 // Test fillPropertyMembersByHandle 262 { 263 OPropertyArrayHelper a1( getPropertyTable1(), 6 ); 264 int i; 265 for( i = 0; i < 6; i++ ) 266 { 267 sal_Int16 nAttributes; 268 OUString aPropName; 269 sal_Bool b = a1.fillPropertyMembersByHandle( &aPropName, &nAttributes, getPropertyTable1()[i].Handle ); 270 OSL_ENSURE( b, "fillPropertyMembersByHandle: handle not found" ); 271 OSL_ENSURE( nAttributes == getPropertyTable1()[i].Attributes, "fillPropertyMembersByHandle: Attributes not correct" ); 272 OSL_ENSURE( aPropName == getPropertyTable1()[i].Name , "fillPropertyMembersByHandle: Name not correct" ); 273 } 274 OSL_ENSURE( !a1.fillPropertyMembersByHandle( NULL, NULL, 66666 ), "fillPropertyMembersByHandle: handle found" ); 275 // optimized table 276 OPropertyArrayHelper a4( getPropertyTable4(), 3 ); 277 for( i = 0; i < 3; i++ ) 278 { 279 sal_Int16 nAttributes; 280 OUString aPropName; 281 sal_Bool b = a1.fillPropertyMembersByHandle( &aPropName, &nAttributes, getPropertyTable4()[i].Handle ); 282 OSL_ENSURE( b, "fillPropertyMembersByHandle: handle not found" ); 283 OSL_ENSURE( nAttributes == getPropertyTable1()[i].Attributes, "fillPropertyMembersByHandle: Attributes not correct" ); 284 OSL_ENSURE( aPropName == getPropertyTable1()[i].Name , "fillPropertyMembersByHandle: Name not correct" ); 285 } 286 OSL_ENSURE( !a4.fillPropertyMembersByHandle( NULL, NULL, 66666 ), "fillPropertyMembersByHandle: handle found" ); 287 } 288 289 // Test fillHandles 290 { 291 OPropertyArrayHelper a1( getPropertyTable1(), 6 ); 292 Sequence< OUString > aS( 4 ); 293 sal_Int32 Handles[4]; 294 // muss sortiert sein 295 aS.getArray()[0] = OUString( RTL_CONSTASCII_USTRINGPARAM("a") ); 296 aS.getArray()[1] = OUString( RTL_CONSTASCII_USTRINGPARAM("d") ); 297 aS.getArray()[2] = OUString( RTL_CONSTASCII_USTRINGPARAM("f") ); 298 aS.getArray()[3] = OUString( RTL_CONSTASCII_USTRINGPARAM("t") ); 299 sal_Int32 nHitCount = a1.fillHandles( Handles, aS ); 300 OSL_ENSURE( nHitCount == 3, "wrong number of hits " ); 301 OSL_ENSURE( Handles[0] == getPropertyTable1()[0].Handle, "Handle not correct" ); 302 OSL_ENSURE( Handles[1] == getPropertyTable1()[3].Handle, "Handle not correct" ); 303 OSL_ENSURE( Handles[2] == getPropertyTable1()[5].Handle, "Handle not correct" ); 304 OSL_ENSURE( Handles[3] == -1, "Handle not correct" ); 305 } 306 } 307 308 309 310 311 //---------------------------------------------------- 312 // test_OPropertySetHelper 313 //---------------------------------------------------- 314 struct MutexContainer 315 { 316 Mutex aMutex; 317 }; 318 class test_OPropertySetHelper : 319 public MutexContainer, 320 public OBroadcastHelper , 321 public OPropertySetHelper, 322 public OWeakObject 323 { 324 public: 325 326 test_OPropertySetHelper( Property * p, sal_Int32 n ) 327 : MutexContainer() 328 , OBroadcastHelper( ((MutexContainer *)this)->aMutex ) 329 // , OPropertySetHelper( *SAL_STATIC_CAST(OBroadcastHelper *,this)) 330 // MSCI 4 bug ! : 331 // OBroadcastHelper == OBroadcastHelperVar<OMultiTypeInterfaceContainerHelper> 332 , OPropertySetHelper( 333 *SAL_STATIC_CAST(OBroadcastHelper *,this)) 334 , bBOOL( sal_False ) 335 , nINT16( 0 ) 336 , nINT32( 0 ) 337 , pBasicProps( p ) 338 , nPropCount( n ) 339 { 340 } 341 342 343 ~test_OPropertySetHelper() 344 { 345 } 346 347 void dispose() 348 { 349 // see comphlp.cxx 350 sal_Bool bDoDispose = sal_False; 351 { 352 MutexGuard aGuard( rBHelper.rMutex ); 353 if( !rBHelper.bDisposed && !rBHelper.bInDispose ) 354 { 355 rBHelper.bInDispose = sal_True; 356 bDoDispose = sal_True; 357 } 358 } 359 if( bDoDispose ) 360 { 361 disposing(); 362 EventObject aEvt; 363 aEvt.Source = Reference < XInterface > ( SAL_STATIC_CAST( OWeakObject * ,this) ); 364 365 rBHelper.aLC.disposeAndClear( aEvt ); 366 rBHelper.bDisposed = sal_True; 367 rBHelper.bInDispose = sal_False; 368 } 369 } 370 371 // XInterface 372 Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type & rType ) throw(RuntimeException) 373 { 374 Any aRet( OPropertySetHelper::queryInterface( rType ) ); 375 return (aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType )); 376 } 377 void SAL_CALL acquire() throw() 378 { OWeakObject::acquire(); } 379 void SAL_CALL release() throw() 380 { OWeakObject::release(); } 381 382 // XPropertySet 383 Reference < XPropertySetInfo > SAL_CALL getPropertySetInfo()throw(RuntimeException); 384 385 using OPropertySetHelper::getFastPropertyValue; 386 387 sal_Bool bBOOL; 388 sal_Int16 nINT16; 389 sal_Int32 nINT32; 390 Property * pBasicProps; 391 sal_Int32 nPropCount; 392 protected: 393 IPropertyArrayHelper & SAL_CALL getInfoHelper() throw(RuntimeException); 394 sal_Bool SAL_CALL convertFastPropertyValue( 395 Any & rConvertedValue, Any & rOldValue, 396 sal_Int32 nHandle, const Any& rValue ) 397 throw(IllegalArgumentException); 398 void SAL_CALL setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, const Any& rValue ) throw(RuntimeException); 399 void SAL_CALL getFastPropertyValue( Any& rValue, sal_Int32 nHandle ) const throw(RuntimeException); 400 }; 401 402 //---------------------------------------------------------------------- 403 //------ The Properties of this implementation ------------------------- 404 //---------------------------------------------------------------------- 405 // Id must be the index into the array 406 #define PROPERTY_BOOL 0 407 #define PROPERTY_INT16 1 408 #define PROPERTY_INT32 2 409 410 // Max number of properties 411 #define PROPERTY_COUNT 4 412 // Names of Properties 413 /** 414 * All Properties of this implementation. Must be sorted by name. 415 */ 416 Property * getBasicProps() 417 { 418 static Property *pTable = 0; 419 420 if( ! pTable ) { 421 MutexGuard guard( ::osl::Mutex::getGlobalMutex() ); 422 if( ! pTable ) { 423 424 static Property aBasicProps[PROPERTY_COUNT] = 425 { 426 Property( OUString( RTL_CONSTASCII_USTRINGPARAM("BOOL") ) , PROPERTY_BOOL , getCppuBooleanType(), PropertyAttribute::READONLY ), 427 Property( OUString( RTL_CONSTASCII_USTRINGPARAM("INT16") ) , PROPERTY_INT16, 428 getCppuType( (sal_Int16*)0 ), PropertyAttribute::BOUND | PropertyAttribute::CONSTRAINED ), 429 Property( OUString( RTL_CONSTASCII_USTRINGPARAM("INT32") ) , PROPERTY_INT32, getCppuType( (sal_Int32*)0 ), PropertyAttribute::BOUND ), 430 Property( OUString( RTL_CONSTASCII_USTRINGPARAM("TEST") ) , 55 , getCppuType( (sal_Int32*)0), PropertyAttribute::BOUND ) 431 }; 432 pTable = aBasicProps; 433 } 434 } 435 return pTable; 436 } 437 438 439 //---------------------------------------------------- 440 // test_OPropertySetHelper_Listener 441 //---------------------------------------------------- 442 class test_OPropertySetHelper_Listener 443 : public WeakImplHelper3< XPropertyChangeListener, XPropertiesChangeListener, XVetoableChangeListener > 444 { 445 public: 446 sal_Int32 nDisposing; 447 Mutex aMutex; 448 Any * pExceptedListenerValues; 449 sal_Int32 nCount; 450 sal_Int32 nCurrent; 451 452 test_OPropertySetHelper_Listener( Any * p = 0, sal_Int32 n = 0 ) 453 : nDisposing( 0 ) 454 , pExceptedListenerValues( p ) 455 , nCount( n ) 456 , nCurrent( 0 ) 457 { 458 } 459 ~test_OPropertySetHelper_Listener() 460 { 461 } 462 463 sal_Int32 getRefCount() 464 { return m_refCount; } 465 466 // XEventListener 467 void SAL_CALL disposing(const EventObject& /*evt*/) throw ( RuntimeException) 468 { 469 MutexGuard aGuard( aMutex ); 470 nDisposing++; 471 } 472 473 // XPropertyChangeListener 474 void SAL_CALL propertyChange(const PropertyChangeEvent& evt) throw (RuntimeException) 475 { 476 if( !pExceptedListenerValues ) 477 return; 478 MutexGuard aGuard( aMutex ); 479 OSL_ENSURE( nCurrent +1 < nCount, "PropertySetHelper: too many listener calls" ); 480 481 switch( evt.PropertyHandle ) 482 { 483 case PROPERTY_BOOL: 484 { 485 OSL_ENSURE( sal_False , "PropertySetHelper: BOOL cannot change" ); 486 OSL_ENSURE( evt.PropertyName == OUString( RTL_CONSTASCII_USTRINGPARAM("BOOL") ), "PropertySetHelper: wrong name" ); 487 } 488 break; 489 490 case PROPERTY_INT16: 491 { 492 OSL_ENSURE( evt.PropertyName == OUString( RTL_CONSTASCII_USTRINGPARAM("INT16") ), "PropertySetHelper: wrong name" ); 493 494 OSL_ENSURE( pExceptedListenerValues[nCurrent].getValueType().getTypeClass() == TypeClass_SHORT , 495 "PropertySetHelper: wrong data type" ); 496 497 sal_Int16 nInt16, nOldInt16; 498 pExceptedListenerValues[nCurrent] >>= nInt16; 499 evt.OldValue >>= nOldInt16; 500 OSL_ENSURE( nInt16 == nOldInt16, "PropertySetHelper: wrong old value" ); 501 502 503 pExceptedListenerValues[nCurrent+1] >>= nInt16; 504 evt.NewValue >>= nOldInt16; 505 OSL_ENSURE( nInt16 == nOldInt16 , "PropertySetHelper: wrong new value" ); 506 } 507 break; 508 509 case PROPERTY_INT32: 510 { 511 OSL_ENSURE( evt.PropertyName == OUString( RTL_CONSTASCII_USTRINGPARAM("INT32") ), "PropertySetHelper: wrong name" ); 512 513 sal_Int32 nInt32,nOldInt32; 514 515 pExceptedListenerValues[nCurrent] >>= nInt32; 516 evt.OldValue >>= nOldInt32; 517 OSL_ENSURE( nInt32 == nOldInt32 , "PropertySetHelper: wrong old value" ); 518 519 pExceptedListenerValues[nCurrent+1] >>= nInt32; 520 evt.NewValue >>= nOldInt32; 521 OSL_ENSURE( nInt32 == nOldInt32 , "PropertySetHelper: wrong new value" ); 522 } 523 break; 524 525 default: 526 OSL_ENSURE( sal_False, "XPropeSetHelper: invalid property handle" ); 527 } 528 nCurrent += 2; 529 } 530 531 // XVetoableChangeListener 532 void SAL_CALL vetoableChange(const PropertyChangeEvent& evt) throw (PropertyVetoException, RuntimeException) 533 { 534 if( !pExceptedListenerValues ) 535 return; 536 MutexGuard aGuard( aMutex ); 537 OSL_ENSURE( nCurrent +1 < nCount, "PropertySetHelper: too many listener calls" ); 538 539 switch( evt.PropertyHandle ) 540 { 541 case PROPERTY_BOOL: 542 { 543 OSL_ENSURE( sal_False , "PropertySetHelper: BOOL cannot change" ); 544 OSL_ENSURE( evt.PropertyName == OUString( RTL_CONSTASCII_USTRINGPARAM("BOOL") ), "PropertySetHelper: wrong name" ); 545 } 546 break; 547 548 case PROPERTY_INT16: 549 { 550 OSL_ENSURE( evt.PropertyName == OUString( RTL_CONSTASCII_USTRINGPARAM("INT16") ), "PropertySetHelper: wrong name" ); 551 552 sal_Int16 nInt16, nOldInt16; 553 pExceptedListenerValues[nCurrent] >>= nInt16; 554 evt.OldValue >>= nOldInt16; 555 556 OSL_ENSURE( nInt16 == nOldInt16,"PropertySetHelper: wrong old value" ); 557 558 pExceptedListenerValues[nCurrent+1] >>= nInt16; 559 evt.NewValue >>= nOldInt16; 560 OSL_ENSURE( nInt16 == nOldInt16 , "PropertySetHelper: wrong new value" ); 561 562 if( nOldInt16 == 100 ) 563 { 564 nCurrent += 2; 565 throw PropertyVetoException(); 566 } 567 } 568 break; 569 570 case PROPERTY_INT32: 571 { 572 OSL_ENSURE( evt.PropertyName == OUString( RTL_CONSTASCII_USTRINGPARAM("INT32") ), "PropertySetHelper: wrong name" ); 573 574 sal_Int32 nInt32,nOldInt32; 575 pExceptedListenerValues[nCurrent] >>= nInt32; 576 evt.OldValue >>= nOldInt32; 577 OSL_ENSURE( nInt32 == nOldInt32 , "PropertySetHelper: wrong old value" ); 578 579 pExceptedListenerValues[nCurrent+1] >>= nInt32; 580 evt.NewValue >>= nOldInt32; 581 OSL_ENSURE( nInt32 == nOldInt32 , "PropertySetHelper: wrong new value" ); 582 } 583 break; 584 585 default: 586 OSL_ENSURE( sal_False, "XPropeSetHelper: invalid property handle" ); 587 } 588 nCurrent += 2; 589 } 590 591 // XPropertiesChangeListener 592 void SAL_CALL propertiesChange(const Sequence< PropertyChangeEvent >& evtSeq) throw (RuntimeException) 593 { 594 if( !pExceptedListenerValues ) 595 return; 596 MutexGuard aGuard( aMutex ); 597 for( sal_Int32 i = 0; i < evtSeq.getLength(); i++ ) 598 { 599 const PropertyChangeEvent & evt = evtSeq.getConstArray()[i]; 600 OSL_ENSURE( nCurrent +1 < nCount, "PropertySetHelper: too many listener calls" ); 601 602 switch( evt.PropertyHandle ) 603 { 604 case PROPERTY_BOOL: 605 { 606 OSL_ENSURE( sal_False, "PropertySetHelper: BOOL cannot change" ); 607 OSL_ENSURE( evt.PropertyName == OUString( RTL_CONSTASCII_USTRINGPARAM("BOOL") ), "PropertySetHelper: wrong name" ); 608 } 609 break; 610 611 case PROPERTY_INT16: 612 { 613 OSL_ENSURE( evt.PropertyName == OUString( RTL_CONSTASCII_USTRINGPARAM("INT16") ), "PropertySetHelper: wrong name" ); 614 615 sal_Int16 nInt16, nOldInt16; 616 pExceptedListenerValues[nCurrent] >>= nInt16; 617 evt.OldValue >>= nOldInt16; 618 OSL_ENSURE( nInt16 == nOldInt16 , "PropertySetHelper: wrong old value" ); 619 620 621 pExceptedListenerValues[nCurrent+1] >>= nInt16; 622 evt.NewValue >>= nOldInt16; 623 OSL_ENSURE( nInt16 == nOldInt16 , "PropertySetHelper: wrong new value" ); 624 } 625 break; 626 627 case PROPERTY_INT32: 628 { 629 OSL_ENSURE( evt.PropertyName == OUString( RTL_CONSTASCII_USTRINGPARAM("INT32") ), "PropertySetHelper: wrong name" ); 630 631 632 sal_Int32 nInt32,nOldInt32; 633 pExceptedListenerValues[nCurrent] >>= nInt32; 634 evt.OldValue >>= nOldInt32; 635 OSL_ENSURE( nInt32 == nOldInt32 , "PropertySetHelper: wrong old value" ); 636 637 pExceptedListenerValues[nCurrent+1] >>= nInt32; 638 evt.NewValue >>= nOldInt32; 639 OSL_ENSURE( nInt32 == nOldInt32 , "PropertySetHelper: wrong new value" ); 640 } 641 break; 642 643 default: 644 OSL_ENSURE( sal_False, "XPropeSetHelper: invalid property handle" ); 645 } 646 nCurrent += 2; 647 } 648 } 649 }; 650 651 /** 652 * Create a table that map names to index values. 653 */ 654 IPropertyArrayHelper & test_OPropertySetHelper::getInfoHelper() throw(RuntimeException) 655 { 656 // no multi thread protection 657 static OPropertyArrayHelper aInfo( pBasicProps, nPropCount ); 658 return aInfo; 659 } 660 661 // XPropertySet 662 Reference < XPropertySetInfo > test_OPropertySetHelper::getPropertySetInfo() 663 throw(RuntimeException) 664 { 665 // no multi thread protection 666 static Reference < XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) ); 667 return xInfo; 668 } 669 670 // Return sal_True, value changed 671 sal_Bool test_OPropertySetHelper::convertFastPropertyValue 672 ( 673 Any & rConvertedValue, 674 Any & rOldValue, 675 sal_Int32 nHandle, 676 const Any& rValue 677 )throw(IllegalArgumentException) 678 { 679 switch( nHandle ) 680 { 681 case PROPERTY_BOOL: 682 { 683 sal_Bool b; 684 convertPropertyValue( b , rValue ); 685 if( b != bBOOL ) 686 { 687 688 rConvertedValue.setValue( &b , ::getCppuBooleanType() ); 689 rOldValue.setValue( & bBOOL , ::getCppuBooleanType() ); 690 return sal_True; 691 } 692 else 693 return sal_False; 694 } 695 696 case PROPERTY_INT16: 697 { 698 sal_Int16 n16; 699 convertPropertyValue( n16 , rValue ); 700 701 if( n16 != nINT16 ) 702 { 703 rConvertedValue <<= n16; 704 rOldValue <<= nINT16; 705 return sal_True; 706 } 707 else 708 return sal_False; 709 } 710 711 case PROPERTY_INT32: 712 { 713 sal_Int32 n32; 714 convertPropertyValue( n32 , rValue ); 715 if( n32 != nINT32 ) 716 { 717 rConvertedValue <<= n32; 718 rOldValue <<= nINT32; 719 return sal_True; 720 } 721 else 722 return sal_False; 723 } 724 725 default: 726 OSL_ENSURE( nHandle == -1, "invalid property handle" ); 727 return sal_False; 728 } 729 } 730 731 /** 732 * only set the value. 733 */ 734 void test_OPropertySetHelper::setFastPropertyValue_NoBroadcast 735 ( 736 sal_Int32 nHandle, 737 const Any& rValue 738 )throw(RuntimeException) 739 { 740 switch( nHandle ) 741 { 742 case PROPERTY_BOOL: 743 OSL_ENSURE( rValue.getValueType().getTypeClass() == TypeClass_BOOLEAN, "invalid type" ); 744 bBOOL = *((sal_Bool*)rValue.getValue()); 745 break; 746 747 case PROPERTY_INT16: 748 OSL_ENSURE( rValue.getValueType().getTypeClass() == TypeClass_SHORT, "invalid type" ); 749 rValue >>= nINT16; 750 break; 751 752 case PROPERTY_INT32: 753 OSL_ENSURE( rValue.getValueType().getTypeClass() == TypeClass_LONG, "invalid type" ); 754 rValue >>= nINT32; 755 break; 756 757 default: 758 OSL_ENSURE( nHandle == -1, "invalid property handle" ); 759 } 760 } 761 762 //-------------------------- 763 void test_OPropertySetHelper::getFastPropertyValue( Any & rRet, sal_Int32 nHandle ) const 764 throw(RuntimeException) 765 { 766 switch( nHandle ) 767 { 768 case PROPERTY_BOOL: 769 rRet.setValue( &bBOOL , getCppuBooleanType() ); 770 break; 771 772 case PROPERTY_INT16: 773 rRet <<= nINT16; 774 break; 775 776 case PROPERTY_INT32: 777 rRet <<= nINT32; 778 break; 779 780 default: 781 OSL_ENSURE( nHandle == -1, "invalid property handle" ); 782 } 783 } 784 785 786 void test_PropertySetHelper() 787 { 788 test_PropertyArrayHelper(); 789 790 test_OPropertySetHelper * pPS; 791 792 Reference < XPropertySet > xPS; 793 Reference < XPropertyChangeListener > xPS_L; 794 test_OPropertySetHelper_Listener * pPS_L; 795 796 Reference < XInterface > x; 797 798 for( int z = 0; z < 2; z++ ) 799 { 800 // first test aBasicProps Handles are { 0, 1, 2, 55 } 801 // first test getBasicProps() Handles are { 0, 1, 2 } 802 xPS = pPS = new test_OPropertySetHelper( getBasicProps(), PROPERTY_COUNT - z ); 803 xPS_L = static_cast< XPropertyChangeListener * >( pPS_L = new test_OPropertySetHelper_Listener() ); 804 805 // Test queryInterface 806 Reference < XPropertySet > rProp( xPS , UNO_QUERY ); 807 OSL_ENSURE( rProp.is() , "PropertySetHelper: XPropertySet nor supported" ); 808 809 Reference < XMultiPropertySet > rMulti( xPS , UNO_QUERY ); 810 OSL_ENSURE( rMulti.is() , "PropertySetHelper: XMultiPropertySet nor supported" ); 811 812 Reference < XFastPropertySet > rFast( xPS , UNO_QUERY ); 813 OSL_ENSURE( rFast.is() , "PropertySetHelper: XFastPropertySet nor supported" ); 814 815 x = Reference < XInterface > (); 816 817 // Test add-remove listener 818 { 819 Reference < XPropertiesChangeListener > x1( xPS_L, UNO_QUERY ); 820 Reference < XVetoableChangeListener > x2( xPS_L, UNO_QUERY ); 821 822 xPS->addPropertyChangeListener( OUString( RTL_CONSTASCII_USTRINGPARAM("INT16") ), xPS_L ); 823 Sequence<OUString> szPN( 3 ); 824 szPN.getArray()[0] = OUString( RTL_CONSTASCII_USTRINGPARAM("BOOL") ); 825 szPN.getArray()[1] = OUString( RTL_CONSTASCII_USTRINGPARAM("INT32") ); 826 szPN.getArray()[2] = OUString( RTL_CONSTASCII_USTRINGPARAM("Does not exist") ); // must ne ignored by the addPropertiesChangeListener method 827 pPS->addPropertiesChangeListener( szPN, x1 ); 828 829 szPN = Sequence<OUString>(); 830 pPS->addPropertiesChangeListener( szPN, x1 ); 831 pPS->addVetoableChangeListener( OUString( RTL_CONSTASCII_USTRINGPARAM("INT16") ), x2 ); 832 833 xPS->removePropertyChangeListener( OUString( RTL_CONSTASCII_USTRINGPARAM("INT16") ), xPS_L ); 834 pPS->removePropertiesChangeListener( x1 ); 835 pPS->removePropertiesChangeListener( x1 ); 836 pPS->removeVetoableChangeListener( OUString( RTL_CONSTASCII_USTRINGPARAM("INT16") ), x2 ); 837 838 // this exception must thrown 839 try 840 { 841 xPS->addPropertyChangeListener( OUString( RTL_CONSTASCII_USTRINGPARAM("Does not exist") ), xPS_L ); 842 OSL_ENSURE( sal_False, "PropertySetHelper: exeption not thrown" ); 843 } 844 catch( UnknownPropertyException & /*e*/ ) 845 { 846 847 } 848 849 try 850 { 851 xPS->addVetoableChangeListener( OUString( RTL_CONSTASCII_USTRINGPARAM("Does not exist") ), x2 ); 852 OSL_ENSURE( sal_False, "PropertySetHelper: exeption not thrown" ); 853 } 854 catch( UnknownPropertyException & /*e*/ ) 855 { 856 857 } 858 859 } 860 OSL_ENSURE( pPS_L->getRefCount() == 1, "PropertySetHelper: wrong reference count" ); 861 862 // Test disposing 863 { 864 Reference < XPropertiesChangeListener > x1( xPS_L, UNO_QUERY ); 865 Reference < XVetoableChangeListener > x2( xPS_L, UNO_QUERY ); 866 867 xPS->addPropertyChangeListener( OUString( RTL_CONSTASCII_USTRINGPARAM("INT16") ), xPS_L ); 868 Sequence<OUString> szPN( 2 ); 869 szPN.getArray()[0] = OUString( RTL_CONSTASCII_USTRINGPARAM("BOOL") ); 870 szPN.getArray()[1] = OUString( RTL_CONSTASCII_USTRINGPARAM("INT32") ); 871 pPS->addPropertiesChangeListener( szPN, x1 ); 872 szPN = Sequence<OUString>(); 873 pPS->addPropertiesChangeListener( szPN, x1 ); 874 pPS->addVetoableChangeListener( OUString( RTL_CONSTASCII_USTRINGPARAM("INT16") ), x2 ); 875 pPS->dispose(); 876 } 877 OSL_ENSURE( pPS_L->nDisposing == 4 , "PropertySetHelper: wrong disposing count" ); 878 OSL_ENSURE( pPS_L->getRefCount() == 1 , "PropertySetHelper: wrong reference count" ); 879 pPS_L->nDisposing = 0; 880 xPS = pPS = new test_OPropertySetHelper( getBasicProps(), PROPERTY_COUNT - z ); 881 882 // Test set- and get- (Fast) propertyValue 883 { 884 // set read only property 885 try 886 { 887 // Readonly raises a vetoable exception 888 sal_Bool b = sal_True; 889 Any aBool; 890 aBool.setValue( &b , getCppuBooleanType() ); 891 xPS->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("BOOL") ), aBool ); 892 OSL_ENSURE( sal_False, "PropertySetHelper: exeption not thrown" ); 893 } 894 catch( PropertyVetoException & /*e*/ ) 895 { 896 } 897 898 try 899 { 900 // Readonly raises a vetoable exception 901 sal_Bool b = sal_True; 902 Any aBool; 903 aBool.setValue( &b , getCppuBooleanType() ); 904 // BOOL i s0 905 pPS->setFastPropertyValue( PROPERTY_BOOL, aBool ); 906 OSL_ENSURE( sal_False, "PropertySetHelper: exeption not thrown" ); 907 } 908 catch( PropertyVetoException & /*e*/ ) 909 { 910 } 911 912 // set unknown property 913 try 914 { 915 sal_Bool b = sal_True; 916 Any aBool; 917 aBool.setValue( &b , getCppuBooleanType() ); 918 xPS->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("Does not exist") ), aBool ); 919 OSL_ENSURE( sal_False, "PropertySetHelper: exeption not thrown" ); 920 } 921 catch( UnknownPropertyException & /*e*/ ) 922 { 923 } 924 925 try 926 { 927 sal_Bool b = sal_True; 928 Any aBool; 929 aBool.setValue( &b , getCppuBooleanType() ); 930 pPS->setFastPropertyValue( 3, aBool ); 931 OSL_ENSURE( sal_False, "PropertySetHelper: exeption not thrown" ); 932 } 933 catch( UnknownPropertyException & /*e*/ ) 934 { 935 } 936 937 // get unknown property 938 try 939 { 940 Any aBool; 941 aBool = xPS->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("Does not exist") ) ); 942 OSL_ENSURE( sal_False, "PropertySetHelper: exeption not thrown" ); 943 } 944 catch( UnknownPropertyException & /*e*/ ) 945 { 946 } 947 948 try 949 { 950 Any aBool; 951 aBool = ((XFastPropertySet *)pPS)->getFastPropertyValue( 3 ); 952 OSL_ENSURE( sal_False, "PropertySetHelper: exeption not thrown" ); 953 } 954 catch( UnknownPropertyException & /*e*/ ) 955 { 956 } 957 958 // set property with invalid type 959 try 960 { 961 Any aBool; 962 xPS->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("INT32") ), aBool ); 963 OSL_ENSURE( sal_False, "PropertySetHelper: exeption not thrown" ); 964 } 965 catch( IllegalArgumentException & /*e*/ ) 966 { 967 } 968 969 try 970 { 971 Any aBool; 972 pPS->setFastPropertyValue( PROPERTY_INT32, aBool ); 973 OSL_ENSURE( sal_False, "PropertySetHelper: exeption not thrown" ); 974 } 975 catch( IllegalArgumentException & /*e*/ ) 976 { 977 } 978 979 // narrowing conversion is not allowed! 980 try 981 { 982 Any aINT32; 983 aINT32 <<= (sal_Int32 ) 16; 984 xPS->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("INT16") ), aINT32 ); 985 OSL_ENSURE( sal_False, "PropertySetHelper: exeption not thrown" ); 986 } 987 catch( IllegalArgumentException & /*e*/ ) 988 { 989 } 990 991 992 try 993 { 994 Any aINT32; 995 aINT32 <<= (sal_Int32) 16; 996 pPS->setFastPropertyValue( PROPERTY_INT16, aINT32 ); 997 OSL_ENSURE( sal_False, "PropertySetHelper: exeption not thrown" ); 998 } 999 catch( IllegalArgumentException & /*e*/ ) 1000 { 1001 } 1002 1003 1004 Any aValue; 1005 aValue = xPS->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("BOOL") ) ); 1006 sal_Bool b = *( (sal_Bool*)aValue.getValue()); 1007 OSL_ENSURE( ! b, "PropertySetHelper: wrong BOOL value" ); 1008 aValue = ((XFastPropertySet *)pPS)->getFastPropertyValue( PROPERTY_BOOL ); 1009 1010 b = *((sal_Bool*)aValue.getValue()); 1011 OSL_ENSURE( !b, "PropertySetHelper: wrong BOOL value" ); 1012 1013 sal_Int16 n16; 1014 aValue <<=(sal_Int16)22; 1015 xPS->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("INT16") ), aValue ); 1016 aValue = xPS->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("INT16") ) ); 1017 aValue >>= n16; 1018 OSL_ENSURE( 22 == n16 , "PropertySetHelper: wrong INT16 value" ); 1019 aValue <<= (sal_Int16)44; 1020 ((XFastPropertySet *)pPS)->setFastPropertyValue( PROPERTY_INT16, aValue ); 1021 1022 aValue = ((XFastPropertySet *)pPS)->getFastPropertyValue( PROPERTY_INT16 ); 1023 aValue >>= n16; 1024 OSL_ENSURE( 44 == n16, "PropertySetHelper: wrong INT16 value" ); 1025 1026 // widening conversion 1027 aValue <<= (sal_Int16)55; 1028 xPS->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("INT32") ), aValue ); 1029 aValue = xPS->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("INT32") ) ); 1030 sal_Int32 n32; 1031 aValue >>= n32; 1032 OSL_ENSURE( 55 == n32 , "PropertySetHelper: wrong INT32 value" ); 1033 aValue <<= (sal_Int16)66; 1034 ((XFastPropertySet *)pPS)->setFastPropertyValue( PROPERTY_INT32, aValue ); 1035 aValue = ((XFastPropertySet *)pPS)->getFastPropertyValue( PROPERTY_INT32 ); 1036 aValue >>= n32; 1037 OSL_ENSURE( 66 == n32, "PropertySetHelper: wrong INT32 value" ); 1038 1039 Sequence< OUString >valueNames = Sequence<OUString>( 3 ); 1040 valueNames.getArray()[0] = OUString( RTL_CONSTASCII_USTRINGPARAM("BOOL") ); 1041 valueNames.getArray()[1] = OUString( RTL_CONSTASCII_USTRINGPARAM("INT16") ); 1042 valueNames.getArray()[2] = OUString( RTL_CONSTASCII_USTRINGPARAM("INT32") ); 1043 Sequence< Any > aValues = pPS->getPropertyValues( valueNames ); 1044 1045 b = *((sal_Bool*)aValues.getConstArray()[0].getValue()); 1046 aValues.getConstArray()[1] >>= n16; 1047 aValues.getConstArray()[2] >>= n32; 1048 1049 OSL_ENSURE( !b, "PropertySetHelper: wrong BOOL value" ); 1050 OSL_ENSURE( 44 == n16, "PropertySetHelper: wrong INT16 value" ); 1051 OSL_ENSURE( 66 == n32, "PropertySetHelper: wrong INT32 value" ); 1052 } 1053 pPS->nINT32 = 0; 1054 pPS->nINT16 = 0; 1055 1056 // Test add-remove listener 1057 { 1058 Reference < XVetoableChangeListener > x2( xPS_L, UNO_QUERY ); 1059 1060 xPS->addPropertyChangeListener( OUString( RTL_CONSTASCII_USTRINGPARAM("INT16") ), xPS_L ); 1061 pPS->addVetoableChangeListener( OUString( RTL_CONSTASCII_USTRINGPARAM("INT16") ), x2 ); 1062 1063 pPS_L->nCount = 10; 1064 Sequence< Any > aSeq( pPS_L->nCount ); 1065 pPS_L->nCurrent = 0; 1066 1067 pPS_L->pExceptedListenerValues = aSeq.getArray(); 1068 1069 pPS_L->pExceptedListenerValues[0] <<= (sal_Int16) 0; // old value vetoable 1070 pPS_L->pExceptedListenerValues[1] <<= (sal_Int16) 22; // new value vetoable 1071 pPS_L->pExceptedListenerValues[2] <<= (sal_Int16) 0; // old value bound 1072 pPS_L->pExceptedListenerValues[3] <<= (sal_Int16) 22; // new value bound 1073 pPS_L->pExceptedListenerValues[4] <<= (sal_Int16) 22; // old value vetoable 1074 pPS_L->pExceptedListenerValues[5] <<= (sal_Int16) 44; // new value vetoable 1075 pPS_L->pExceptedListenerValues[6] <<= (sal_Int16) 22; // old value bound 1076 pPS_L->pExceptedListenerValues[7] <<= (sal_Int16) 44; // new value bound 1077 pPS_L->pExceptedListenerValues[8] <<= (sal_Int16) 44; // old value vetoable 1078 pPS_L->pExceptedListenerValues[9] <<= (sal_Int16) 100; // new value vetoable exception 1079 1080 Any aValue; 1081 aValue <<= (sal_Int16)22; 1082 xPS->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("INT16") ), aValue ); 1083 aValue <<= (sal_Int16) 44; 1084 ((XFastPropertySet *)pPS)->setFastPropertyValue( PROPERTY_INT16, aValue ); 1085 aValue <<= (sal_Int16)100;// exception 1086 1087 try 1088 { 1089 ((XFastPropertySet *)pPS)->setFastPropertyValue( PROPERTY_INT16, aValue ); 1090 OSL_ENSURE( sal_False, "PropertySetHelper: exeption not thrown" ); 1091 } 1092 catch( PropertyVetoException & /*e*/ ) 1093 { 1094 } 1095 1096 OSL_ENSURE( pPS_L->nCount == pPS_L->nCurrent, "not all listeners called" ); 1097 pPS->nINT32 = 0; 1098 pPS->nINT16 = 0; 1099 pPS_L->nCount = 0; 1100 pPS_L->nCurrent = 0; 1101 pPS_L->pExceptedListenerValues = NULL; 1102 xPS->removePropertyChangeListener( OUString( RTL_CONSTASCII_USTRINGPARAM("INT16") ), xPS_L ); 1103 pPS->removeVetoableChangeListener( OUString( RTL_CONSTASCII_USTRINGPARAM("INT16") ), x2 ); 1104 } 1105 1106 // Test multi property set listener 1107 { 1108 Reference < XPropertiesChangeListener > x1( xPS_L, UNO_QUERY ); 1109 Reference < XVetoableChangeListener > x2( xPS_L, UNO_QUERY ); 1110 1111 pPS->addVetoableChangeListener( OUString( RTL_CONSTASCII_USTRINGPARAM("INT16") ) , x2 ); 1112 Sequence<OUString> szPN( 4 ); 1113 szPN.getArray()[0] = OUString( RTL_CONSTASCII_USTRINGPARAM("BOOL") ); 1114 szPN.getArray()[1] = OUString( RTL_CONSTASCII_USTRINGPARAM("INT32") ); 1115 szPN.getArray()[2] = OUString( RTL_CONSTASCII_USTRINGPARAM("Does not exist") ); // must ne ignored by the addPropertiesChangeListener method 1116 szPN.getArray()[3] = OUString( RTL_CONSTASCII_USTRINGPARAM("INT16") ); 1117 pPS->addPropertiesChangeListener( szPN, x1 ); 1118 1119 pPS_L->nCount = 6; 1120 Sequence< Any > aSeq( pPS_L->nCount ); 1121 pPS_L->nCurrent = 0; 1122 pPS_L->pExceptedListenerValues = aSeq.getArray(); 1123 pPS_L->pExceptedListenerValues[0] <<= (sal_Int16) 0; // old value vetoable 1124 pPS_L->pExceptedListenerValues[1] <<= (sal_Int16 ) 22; // new value vetoable 1125 // INT32 is not constrained 1126 pPS_L->pExceptedListenerValues[2] <<= (sal_Int16) 0; // old value bound 1127 pPS_L->pExceptedListenerValues[3] <<= (sal_Int16) 22; // new value bound 1128 pPS_L->pExceptedListenerValues[4] <<= (sal_Int32) 0; // old value bound 1129 pPS_L->pExceptedListenerValues[5] <<= (sal_Int32) 44; // new value bound 1130 1131 szPN = Sequence<OUString>( 2 ); 1132 szPN.getArray()[0] = OUString( RTL_CONSTASCII_USTRINGPARAM("INT16") ); 1133 szPN.getArray()[1] = OUString( RTL_CONSTASCII_USTRINGPARAM("INT32") ); 1134 Sequence< Any > aValues( 2 ); 1135 aValues.getArray()[0] <<= (sal_Int16) 22; 1136 aValues.getArray()[1] <<= (sal_Int16) 44; 1137 pPS->setPropertyValues( szPN, aValues ); 1138 OSL_ENSURE( pPS_L->nCount == pPS_L->nCurrent, "not all listeners called" ); 1139 1140 //firePropertiesChangeEvent 1141 pPS->nINT16 = 8; 1142 pPS->nINT32 = 5; 1143 pPS_L->nCount = 4; 1144 pPS_L->nCurrent = 0; 1145 pPS_L->pExceptedListenerValues[0] <<= (sal_Int16) 8; // old value 1146 pPS_L->pExceptedListenerValues[1] <<= (sal_Int16) 8; // new value 1147 pPS_L->pExceptedListenerValues[2] <<= (sal_Int32) 5; // old value 1148 pPS_L->pExceptedListenerValues[3] <<= (sal_Int32) 5; // new value 1149 pPS->firePropertiesChangeEvent( szPN, pPS_L ); 1150 OSL_ENSURE( pPS_L->nCount == pPS_L->nCurrent, "not all listeners called" ); 1151 1152 1153 //vetoable exception with multible 1154 szPN.getArray()[0] = OUString( RTL_CONSTASCII_USTRINGPARAM("INT16") ); 1155 szPN.getArray()[1] = OUString( RTL_CONSTASCII_USTRINGPARAM("INT16") ); 1156 pPS->nINT32 = 0; 1157 pPS->nINT16 = 0; 1158 pPS_L->nCount = 4; 1159 pPS_L->nCurrent = 0; 1160 pPS_L->pExceptedListenerValues[0] <<= (sal_Int16) 0; // old value vetoable 1161 pPS_L->pExceptedListenerValues[1] <<= (sal_Int16) 44; // new value vetoable 1162 pPS_L->pExceptedListenerValues[2] <<= (sal_Int16) 0; // old value vetoable 1163 pPS_L->pExceptedListenerValues[3] <<= (sal_Int16) 100; // new value vetoable 1164 1165 try 1166 { 1167 aValues.getArray()[0] <<= (sal_Int16)44; 1168 aValues.getArray()[1] <<= (sal_Int16)100; 1169 pPS->setPropertyValues( szPN, aValues ); 1170 OSL_ENSURE( sal_False, "PropertySetHelper: exeption not thrown" ); 1171 } 1172 catch ( PropertyVetoException & /*e*/ ) 1173 { 1174 } 1175 1176 OSL_ENSURE( pPS_L->nCount == pPS_L->nCurrent, "not all listeners called" ); 1177 pPS->removePropertiesChangeListener( x1 ); 1178 pPS->removeVetoableChangeListener( OUString( RTL_CONSTASCII_USTRINGPARAM("INT16") ), x2 ); 1179 } 1180 } 1181 } 1182