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