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, "exception 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 ) 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(); 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(); 390 sal_Bool SAL_CALL convertFastPropertyValue( 391 Any & rConvertedValue, Any & rOldValue, 392 sal_Int32 nHandle, const Any& rValue ); 393 void SAL_CALL setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, const Any& rValue ); 394 void SAL_CALL getFastPropertyValue( Any& rValue, sal_Int32 nHandle ) const; 395 }; 396 397 //---------------------------------------------------------------------- 398 //------ The Properties of this implementation ------------------------- 399 //---------------------------------------------------------------------- 400 // Id must be the index into the array 401 #define PROPERTY_BOOL 0 402 #define PROPERTY_INT16 1 403 #define PROPERTY_INT32 2 404 405 // Max number of properties 406 #define PROPERTY_COUNT 4 407 // Names of Properties 408 /** 409 * All Properties of this implementation. Must be sorted by name. 410 */ 411 Property * getBasicProps() 412 { 413 static Property *pTable = 0; 414 415 if( ! pTable ) { 416 MutexGuard guard( ::osl::Mutex::getGlobalMutex() ); 417 if( ! pTable ) { 418 419 static Property aBasicProps[PROPERTY_COUNT] = 420 { 421 Property( OUString( RTL_CONSTASCII_USTRINGPARAM("BOOL") ) , PROPERTY_BOOL , getCppuBooleanType(), PropertyAttribute::READONLY ), 422 Property( OUString( RTL_CONSTASCII_USTRINGPARAM("INT16") ) , PROPERTY_INT16, 423 getCppuType( (sal_Int16*)0 ), PropertyAttribute::BOUND | PropertyAttribute::CONSTRAINED ), 424 Property( OUString( RTL_CONSTASCII_USTRINGPARAM("INT32") ) , PROPERTY_INT32, getCppuType( (sal_Int32*)0 ), PropertyAttribute::BOUND ), 425 Property( OUString( RTL_CONSTASCII_USTRINGPARAM("TEST") ) , 55 , getCppuType( (sal_Int32*)0), PropertyAttribute::BOUND ) 426 }; 427 pTable = aBasicProps; 428 } 429 } 430 return pTable; 431 } 432 433 434 //---------------------------------------------------- 435 // test_OPropertySetHelper_Listener 436 //---------------------------------------------------- 437 class test_OPropertySetHelper_Listener 438 : public WeakImplHelper3< XPropertyChangeListener, XPropertiesChangeListener, XVetoableChangeListener > 439 { 440 public: 441 sal_Int32 nDisposing; 442 Mutex aMutex; 443 Any * pExceptedListenerValues; 444 sal_Int32 nCount; 445 sal_Int32 nCurrent; 446 447 test_OPropertySetHelper_Listener( Any * p = 0, sal_Int32 n = 0 ) 448 : nDisposing( 0 ) 449 , pExceptedListenerValues( p ) 450 , nCount( n ) 451 , nCurrent( 0 ) 452 { 453 } 454 ~test_OPropertySetHelper_Listener() 455 { 456 } 457 458 sal_Int32 getRefCount() 459 { return m_refCount; } 460 461 // XEventListener 462 void SAL_CALL disposing(const EventObject& /*evt*/) 463 { 464 MutexGuard aGuard( aMutex ); 465 nDisposing++; 466 } 467 468 // XPropertyChangeListener 469 void SAL_CALL propertyChange(const PropertyChangeEvent& evt) 470 { 471 if( !pExceptedListenerValues ) 472 return; 473 MutexGuard aGuard( aMutex ); 474 OSL_ENSURE( nCurrent +1 < nCount, "PropertySetHelper: too many listener calls" ); 475 476 switch( evt.PropertyHandle ) 477 { 478 case PROPERTY_BOOL: 479 { 480 OSL_ENSURE( sal_False , "PropertySetHelper: BOOL cannot change" ); 481 OSL_ENSURE( evt.PropertyName == OUString( RTL_CONSTASCII_USTRINGPARAM("BOOL") ), "PropertySetHelper: wrong name" ); 482 } 483 break; 484 485 case PROPERTY_INT16: 486 { 487 OSL_ENSURE( evt.PropertyName == OUString( RTL_CONSTASCII_USTRINGPARAM("INT16") ), "PropertySetHelper: wrong name" ); 488 489 OSL_ENSURE( pExceptedListenerValues[nCurrent].getValueType().getTypeClass() == TypeClass_SHORT , 490 "PropertySetHelper: wrong data type" ); 491 492 sal_Int16 nInt16, nOldInt16; 493 pExceptedListenerValues[nCurrent] >>= nInt16; 494 evt.OldValue >>= nOldInt16; 495 OSL_ENSURE( nInt16 == nOldInt16, "PropertySetHelper: wrong old value" ); 496 497 498 pExceptedListenerValues[nCurrent+1] >>= nInt16; 499 evt.NewValue >>= nOldInt16; 500 OSL_ENSURE( nInt16 == nOldInt16 , "PropertySetHelper: wrong new value" ); 501 } 502 break; 503 504 case PROPERTY_INT32: 505 { 506 OSL_ENSURE( evt.PropertyName == OUString( RTL_CONSTASCII_USTRINGPARAM("INT32") ), "PropertySetHelper: wrong name" ); 507 508 sal_Int32 nInt32,nOldInt32; 509 510 pExceptedListenerValues[nCurrent] >>= nInt32; 511 evt.OldValue >>= nOldInt32; 512 OSL_ENSURE( nInt32 == nOldInt32 , "PropertySetHelper: wrong old value" ); 513 514 pExceptedListenerValues[nCurrent+1] >>= nInt32; 515 evt.NewValue >>= nOldInt32; 516 OSL_ENSURE( nInt32 == nOldInt32 , "PropertySetHelper: wrong new value" ); 517 } 518 break; 519 520 default: 521 OSL_ENSURE( sal_False, "XPropeSetHelper: invalid property handle" ); 522 } 523 nCurrent += 2; 524 } 525 526 // XVetoableChangeListener 527 void SAL_CALL vetoableChange(const PropertyChangeEvent& evt) 528 { 529 if( !pExceptedListenerValues ) 530 return; 531 MutexGuard aGuard( aMutex ); 532 OSL_ENSURE( nCurrent +1 < nCount, "PropertySetHelper: too many listener calls" ); 533 534 switch( evt.PropertyHandle ) 535 { 536 case PROPERTY_BOOL: 537 { 538 OSL_ENSURE( sal_False , "PropertySetHelper: BOOL cannot change" ); 539 OSL_ENSURE( evt.PropertyName == OUString( RTL_CONSTASCII_USTRINGPARAM("BOOL") ), "PropertySetHelper: wrong name" ); 540 } 541 break; 542 543 case PROPERTY_INT16: 544 { 545 OSL_ENSURE( evt.PropertyName == OUString( RTL_CONSTASCII_USTRINGPARAM("INT16") ), "PropertySetHelper: wrong name" ); 546 547 sal_Int16 nInt16, nOldInt16; 548 pExceptedListenerValues[nCurrent] >>= nInt16; 549 evt.OldValue >>= nOldInt16; 550 551 OSL_ENSURE( nInt16 == nOldInt16,"PropertySetHelper: wrong old value" ); 552 553 pExceptedListenerValues[nCurrent+1] >>= nInt16; 554 evt.NewValue >>= nOldInt16; 555 OSL_ENSURE( nInt16 == nOldInt16 , "PropertySetHelper: wrong new value" ); 556 557 if( nOldInt16 == 100 ) 558 { 559 nCurrent += 2; 560 throw PropertyVetoException(); 561 } 562 } 563 break; 564 565 case PROPERTY_INT32: 566 { 567 OSL_ENSURE( evt.PropertyName == OUString( RTL_CONSTASCII_USTRINGPARAM("INT32") ), "PropertySetHelper: wrong name" ); 568 569 sal_Int32 nInt32,nOldInt32; 570 pExceptedListenerValues[nCurrent] >>= nInt32; 571 evt.OldValue >>= nOldInt32; 572 OSL_ENSURE( nInt32 == nOldInt32 , "PropertySetHelper: wrong old value" ); 573 574 pExceptedListenerValues[nCurrent+1] >>= nInt32; 575 evt.NewValue >>= nOldInt32; 576 OSL_ENSURE( nInt32 == nOldInt32 , "PropertySetHelper: wrong new value" ); 577 } 578 break; 579 580 default: 581 OSL_ENSURE( sal_False, "XPropeSetHelper: invalid property handle" ); 582 } 583 nCurrent += 2; 584 } 585 586 // XPropertiesChangeListener 587 void SAL_CALL propertiesChange(const Sequence< PropertyChangeEvent >& evtSeq) 588 { 589 if( !pExceptedListenerValues ) 590 return; 591 MutexGuard aGuard( aMutex ); 592 for( sal_Int32 i = 0; i < evtSeq.getLength(); i++ ) 593 { 594 const PropertyChangeEvent & evt = evtSeq.getConstArray()[i]; 595 OSL_ENSURE( nCurrent +1 < nCount, "PropertySetHelper: too many listener calls" ); 596 597 switch( evt.PropertyHandle ) 598 { 599 case PROPERTY_BOOL: 600 { 601 OSL_ENSURE( sal_False, "PropertySetHelper: BOOL cannot change" ); 602 OSL_ENSURE( evt.PropertyName == OUString( RTL_CONSTASCII_USTRINGPARAM("BOOL") ), "PropertySetHelper: wrong name" ); 603 } 604 break; 605 606 case PROPERTY_INT16: 607 { 608 OSL_ENSURE( evt.PropertyName == OUString( RTL_CONSTASCII_USTRINGPARAM("INT16") ), "PropertySetHelper: wrong name" ); 609 610 sal_Int16 nInt16, nOldInt16; 611 pExceptedListenerValues[nCurrent] >>= nInt16; 612 evt.OldValue >>= nOldInt16; 613 OSL_ENSURE( nInt16 == nOldInt16 , "PropertySetHelper: wrong old value" ); 614 615 616 pExceptedListenerValues[nCurrent+1] >>= nInt16; 617 evt.NewValue >>= nOldInt16; 618 OSL_ENSURE( nInt16 == nOldInt16 , "PropertySetHelper: wrong new value" ); 619 } 620 break; 621 622 case PROPERTY_INT32: 623 { 624 OSL_ENSURE( evt.PropertyName == OUString( RTL_CONSTASCII_USTRINGPARAM("INT32") ), "PropertySetHelper: wrong name" ); 625 626 627 sal_Int32 nInt32,nOldInt32; 628 pExceptedListenerValues[nCurrent] >>= nInt32; 629 evt.OldValue >>= nOldInt32; 630 OSL_ENSURE( nInt32 == nOldInt32 , "PropertySetHelper: wrong old value" ); 631 632 pExceptedListenerValues[nCurrent+1] >>= nInt32; 633 evt.NewValue >>= nOldInt32; 634 OSL_ENSURE( nInt32 == nOldInt32 , "PropertySetHelper: wrong new value" ); 635 } 636 break; 637 638 default: 639 OSL_ENSURE( sal_False, "XPropeSetHelper: invalid property handle" ); 640 } 641 nCurrent += 2; 642 } 643 } 644 }; 645 646 /** 647 * Create a table that map names to index values. 648 */ 649 IPropertyArrayHelper & test_OPropertySetHelper::getInfoHelper() 650 { 651 // no multi thread protection 652 static OPropertyArrayHelper aInfo( pBasicProps, nPropCount ); 653 return aInfo; 654 } 655 656 // XPropertySet 657 Reference < XPropertySetInfo > test_OPropertySetHelper::getPropertySetInfo() 658 { 659 // no multi thread protection 660 static Reference < XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) ); 661 return xInfo; 662 } 663 664 // Return sal_True, value changed 665 sal_Bool test_OPropertySetHelper::convertFastPropertyValue 666 ( 667 Any & rConvertedValue, 668 Any & rOldValue, 669 sal_Int32 nHandle, 670 const Any& rValue 671 ) 672 { 673 switch( nHandle ) 674 { 675 case PROPERTY_BOOL: 676 { 677 sal_Bool b; 678 convertPropertyValue( b , rValue ); 679 if( b != bBOOL ) 680 { 681 682 rConvertedValue.setValue( &b , ::getCppuBooleanType() ); 683 rOldValue.setValue( & bBOOL , ::getCppuBooleanType() ); 684 return sal_True; 685 } 686 else 687 return sal_False; 688 } 689 690 case PROPERTY_INT16: 691 { 692 sal_Int16 n16; 693 convertPropertyValue( n16 , rValue ); 694 695 if( n16 != nINT16 ) 696 { 697 rConvertedValue <<= n16; 698 rOldValue <<= nINT16; 699 return sal_True; 700 } 701 else 702 return sal_False; 703 } 704 705 case PROPERTY_INT32: 706 { 707 sal_Int32 n32; 708 convertPropertyValue( n32 , rValue ); 709 if( n32 != nINT32 ) 710 { 711 rConvertedValue <<= n32; 712 rOldValue <<= nINT32; 713 return sal_True; 714 } 715 else 716 return sal_False; 717 } 718 719 default: 720 OSL_ENSURE( nHandle == -1, "invalid property handle" ); 721 return sal_False; 722 } 723 } 724 725 /** 726 * only set the value. 727 */ 728 void test_OPropertySetHelper::setFastPropertyValue_NoBroadcast 729 ( 730 sal_Int32 nHandle, 731 const Any& rValue 732 ) 733 { 734 switch( nHandle ) 735 { 736 case PROPERTY_BOOL: 737 OSL_ENSURE( rValue.getValueType().getTypeClass() == TypeClass_BOOLEAN, "invalid type" ); 738 bBOOL = *((sal_Bool*)rValue.getValue()); 739 break; 740 741 case PROPERTY_INT16: 742 OSL_ENSURE( rValue.getValueType().getTypeClass() == TypeClass_SHORT, "invalid type" ); 743 rValue >>= nINT16; 744 break; 745 746 case PROPERTY_INT32: 747 OSL_ENSURE( rValue.getValueType().getTypeClass() == TypeClass_LONG, "invalid type" ); 748 rValue >>= nINT32; 749 break; 750 751 default: 752 OSL_ENSURE( nHandle == -1, "invalid property handle" ); 753 } 754 } 755 756 //-------------------------- 757 void test_OPropertySetHelper::getFastPropertyValue( Any & rRet, sal_Int32 nHandle ) const 758 { 759 switch( nHandle ) 760 { 761 case PROPERTY_BOOL: 762 rRet.setValue( &bBOOL , getCppuBooleanType() ); 763 break; 764 765 case PROPERTY_INT16: 766 rRet <<= nINT16; 767 break; 768 769 case PROPERTY_INT32: 770 rRet <<= nINT32; 771 break; 772 773 default: 774 OSL_ENSURE( nHandle == -1, "invalid property handle" ); 775 } 776 } 777 778 779 void test_PropertySetHelper() 780 { 781 test_PropertyArrayHelper(); 782 783 test_OPropertySetHelper * pPS; 784 785 Reference < XPropertySet > xPS; 786 Reference < XPropertyChangeListener > xPS_L; 787 test_OPropertySetHelper_Listener * pPS_L; 788 789 Reference < XInterface > x; 790 791 for( int z = 0; z < 2; z++ ) 792 { 793 // first test aBasicProps Handles are { 0, 1, 2, 55 } 794 // first test getBasicProps() Handles are { 0, 1, 2 } 795 xPS = pPS = new test_OPropertySetHelper( getBasicProps(), PROPERTY_COUNT - z ); 796 xPS_L = static_cast< XPropertyChangeListener * >( pPS_L = new test_OPropertySetHelper_Listener() ); 797 798 // Test queryInterface 799 Reference < XPropertySet > rProp( xPS , UNO_QUERY ); 800 OSL_ENSURE( rProp.is() , "PropertySetHelper: XPropertySet nor supported" ); 801 802 Reference < XMultiPropertySet > rMulti( xPS , UNO_QUERY ); 803 OSL_ENSURE( rMulti.is() , "PropertySetHelper: XMultiPropertySet nor supported" ); 804 805 Reference < XFastPropertySet > rFast( xPS , UNO_QUERY ); 806 OSL_ENSURE( rFast.is() , "PropertySetHelper: XFastPropertySet nor supported" ); 807 808 x = Reference < XInterface > (); 809 810 // Test add-remove listener 811 { 812 Reference < XPropertiesChangeListener > x1( xPS_L, UNO_QUERY ); 813 Reference < XVetoableChangeListener > x2( xPS_L, UNO_QUERY ); 814 815 xPS->addPropertyChangeListener( OUString( RTL_CONSTASCII_USTRINGPARAM("INT16") ), xPS_L ); 816 Sequence<OUString> szPN( 3 ); 817 szPN.getArray()[0] = OUString( RTL_CONSTASCII_USTRINGPARAM("BOOL") ); 818 szPN.getArray()[1] = OUString( RTL_CONSTASCII_USTRINGPARAM("INT32") ); 819 szPN.getArray()[2] = OUString( RTL_CONSTASCII_USTRINGPARAM("Does not exist") ); // must ne ignored by the addPropertiesChangeListener method 820 pPS->addPropertiesChangeListener( szPN, x1 ); 821 822 szPN = Sequence<OUString>(); 823 pPS->addPropertiesChangeListener( szPN, x1 ); 824 pPS->addVetoableChangeListener( OUString( RTL_CONSTASCII_USTRINGPARAM("INT16") ), x2 ); 825 826 xPS->removePropertyChangeListener( OUString( RTL_CONSTASCII_USTRINGPARAM("INT16") ), xPS_L ); 827 pPS->removePropertiesChangeListener( x1 ); 828 pPS->removePropertiesChangeListener( x1 ); 829 pPS->removeVetoableChangeListener( OUString( RTL_CONSTASCII_USTRINGPARAM("INT16") ), x2 ); 830 831 // this exception must thrown 832 try 833 { 834 xPS->addPropertyChangeListener( OUString( RTL_CONSTASCII_USTRINGPARAM("Does not exist") ), xPS_L ); 835 OSL_ENSURE( sal_False, "PropertySetHelper: exception not thrown" ); 836 } 837 catch( UnknownPropertyException & /*e*/ ) 838 { 839 840 } 841 842 try 843 { 844 xPS->addVetoableChangeListener( OUString( RTL_CONSTASCII_USTRINGPARAM("Does not exist") ), x2 ); 845 OSL_ENSURE( sal_False, "PropertySetHelper: exception not thrown" ); 846 } 847 catch( UnknownPropertyException & /*e*/ ) 848 { 849 850 } 851 852 } 853 OSL_ENSURE( pPS_L->getRefCount() == 1, "PropertySetHelper: wrong reference count" ); 854 855 // Test disposing 856 { 857 Reference < XPropertiesChangeListener > x1( xPS_L, UNO_QUERY ); 858 Reference < XVetoableChangeListener > x2( xPS_L, UNO_QUERY ); 859 860 xPS->addPropertyChangeListener( OUString( RTL_CONSTASCII_USTRINGPARAM("INT16") ), xPS_L ); 861 Sequence<OUString> szPN( 2 ); 862 szPN.getArray()[0] = OUString( RTL_CONSTASCII_USTRINGPARAM("BOOL") ); 863 szPN.getArray()[1] = OUString( RTL_CONSTASCII_USTRINGPARAM("INT32") ); 864 pPS->addPropertiesChangeListener( szPN, x1 ); 865 szPN = Sequence<OUString>(); 866 pPS->addPropertiesChangeListener( szPN, x1 ); 867 pPS->addVetoableChangeListener( OUString( RTL_CONSTASCII_USTRINGPARAM("INT16") ), x2 ); 868 pPS->dispose(); 869 } 870 OSL_ENSURE( pPS_L->nDisposing == 4 , "PropertySetHelper: wrong disposing count" ); 871 OSL_ENSURE( pPS_L->getRefCount() == 1 , "PropertySetHelper: wrong reference count" ); 872 pPS_L->nDisposing = 0; 873 xPS = pPS = new test_OPropertySetHelper( getBasicProps(), PROPERTY_COUNT - z ); 874 875 // Test set- and get- (Fast) propertyValue 876 { 877 // set read only property 878 try 879 { 880 // Readonly raises a vetoable exception 881 sal_Bool b = sal_True; 882 Any aBool; 883 aBool.setValue( &b , getCppuBooleanType() ); 884 xPS->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("BOOL") ), aBool ); 885 OSL_ENSURE( sal_False, "PropertySetHelper: exception not thrown" ); 886 } 887 catch( PropertyVetoException & /*e*/ ) 888 { 889 } 890 891 try 892 { 893 // Readonly raises a vetoable exception 894 sal_Bool b = sal_True; 895 Any aBool; 896 aBool.setValue( &b , getCppuBooleanType() ); 897 // BOOL i s0 898 pPS->setFastPropertyValue( PROPERTY_BOOL, aBool ); 899 OSL_ENSURE( sal_False, "PropertySetHelper: exception not thrown" ); 900 } 901 catch( PropertyVetoException & /*e*/ ) 902 { 903 } 904 905 // set unknown property 906 try 907 { 908 sal_Bool b = sal_True; 909 Any aBool; 910 aBool.setValue( &b , getCppuBooleanType() ); 911 xPS->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("Does not exist") ), aBool ); 912 OSL_ENSURE( sal_False, "PropertySetHelper: exception not thrown" ); 913 } 914 catch( UnknownPropertyException & /*e*/ ) 915 { 916 } 917 918 try 919 { 920 sal_Bool b = sal_True; 921 Any aBool; 922 aBool.setValue( &b , getCppuBooleanType() ); 923 pPS->setFastPropertyValue( 3, aBool ); 924 OSL_ENSURE( sal_False, "PropertySetHelper: exception not thrown" ); 925 } 926 catch( UnknownPropertyException & /*e*/ ) 927 { 928 } 929 930 // get unknown property 931 try 932 { 933 Any aBool; 934 aBool = xPS->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("Does not exist") ) ); 935 OSL_ENSURE( sal_False, "PropertySetHelper: exception not thrown" ); 936 } 937 catch( UnknownPropertyException & /*e*/ ) 938 { 939 } 940 941 try 942 { 943 Any aBool; 944 aBool = ((XFastPropertySet *)pPS)->getFastPropertyValue( 3 ); 945 OSL_ENSURE( sal_False, "PropertySetHelper: exception not thrown" ); 946 } 947 catch( UnknownPropertyException & /*e*/ ) 948 { 949 } 950 951 // set property with invalid type 952 try 953 { 954 Any aBool; 955 xPS->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("INT32") ), aBool ); 956 OSL_ENSURE( sal_False, "PropertySetHelper: exception not thrown" ); 957 } 958 catch( IllegalArgumentException & /*e*/ ) 959 { 960 } 961 962 try 963 { 964 Any aBool; 965 pPS->setFastPropertyValue( PROPERTY_INT32, aBool ); 966 OSL_ENSURE( sal_False, "PropertySetHelper: exception not thrown" ); 967 } 968 catch( IllegalArgumentException & /*e*/ ) 969 { 970 } 971 972 // narrowing conversion is not allowed! 973 try 974 { 975 Any aINT32; 976 aINT32 <<= (sal_Int32 ) 16; 977 xPS->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("INT16") ), aINT32 ); 978 OSL_ENSURE( sal_False, "PropertySetHelper: exception not thrown" ); 979 } 980 catch( IllegalArgumentException & /*e*/ ) 981 { 982 } 983 984 985 try 986 { 987 Any aINT32; 988 aINT32 <<= (sal_Int32) 16; 989 pPS->setFastPropertyValue( PROPERTY_INT16, aINT32 ); 990 OSL_ENSURE( sal_False, "PropertySetHelper: exception not thrown" ); 991 } 992 catch( IllegalArgumentException & /*e*/ ) 993 { 994 } 995 996 997 Any aValue; 998 aValue = xPS->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("BOOL") ) ); 999 sal_Bool b = *( (sal_Bool*)aValue.getValue()); 1000 OSL_ENSURE( ! b, "PropertySetHelper: wrong BOOL value" ); 1001 aValue = ((XFastPropertySet *)pPS)->getFastPropertyValue( PROPERTY_BOOL ); 1002 1003 b = *((sal_Bool*)aValue.getValue()); 1004 OSL_ENSURE( !b, "PropertySetHelper: wrong BOOL value" ); 1005 1006 sal_Int16 n16; 1007 aValue <<=(sal_Int16)22; 1008 xPS->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("INT16") ), aValue ); 1009 aValue = xPS->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("INT16") ) ); 1010 aValue >>= n16; 1011 OSL_ENSURE( 22 == n16 , "PropertySetHelper: wrong INT16 value" ); 1012 aValue <<= (sal_Int16)44; 1013 ((XFastPropertySet *)pPS)->setFastPropertyValue( PROPERTY_INT16, aValue ); 1014 1015 aValue = ((XFastPropertySet *)pPS)->getFastPropertyValue( PROPERTY_INT16 ); 1016 aValue >>= n16; 1017 OSL_ENSURE( 44 == n16, "PropertySetHelper: wrong INT16 value" ); 1018 1019 // widening conversion 1020 aValue <<= (sal_Int16)55; 1021 xPS->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("INT32") ), aValue ); 1022 aValue = xPS->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("INT32") ) ); 1023 sal_Int32 n32; 1024 aValue >>= n32; 1025 OSL_ENSURE( 55 == n32 , "PropertySetHelper: wrong INT32 value" ); 1026 aValue <<= (sal_Int16)66; 1027 ((XFastPropertySet *)pPS)->setFastPropertyValue( PROPERTY_INT32, aValue ); 1028 aValue = ((XFastPropertySet *)pPS)->getFastPropertyValue( PROPERTY_INT32 ); 1029 aValue >>= n32; 1030 OSL_ENSURE( 66 == n32, "PropertySetHelper: wrong INT32 value" ); 1031 1032 Sequence< OUString >valueNames = Sequence<OUString>( 3 ); 1033 valueNames.getArray()[0] = OUString( RTL_CONSTASCII_USTRINGPARAM("BOOL") ); 1034 valueNames.getArray()[1] = OUString( RTL_CONSTASCII_USTRINGPARAM("INT16") ); 1035 valueNames.getArray()[2] = OUString( RTL_CONSTASCII_USTRINGPARAM("INT32") ); 1036 Sequence< Any > aValues = pPS->getPropertyValues( valueNames ); 1037 1038 b = *((sal_Bool*)aValues.getConstArray()[0].getValue()); 1039 aValues.getConstArray()[1] >>= n16; 1040 aValues.getConstArray()[2] >>= n32; 1041 1042 OSL_ENSURE( !b, "PropertySetHelper: wrong BOOL value" ); 1043 OSL_ENSURE( 44 == n16, "PropertySetHelper: wrong INT16 value" ); 1044 OSL_ENSURE( 66 == n32, "PropertySetHelper: wrong INT32 value" ); 1045 } 1046 pPS->nINT32 = 0; 1047 pPS->nINT16 = 0; 1048 1049 // Test add-remove listener 1050 { 1051 Reference < XVetoableChangeListener > x2( xPS_L, UNO_QUERY ); 1052 1053 xPS->addPropertyChangeListener( OUString( RTL_CONSTASCII_USTRINGPARAM("INT16") ), xPS_L ); 1054 pPS->addVetoableChangeListener( OUString( RTL_CONSTASCII_USTRINGPARAM("INT16") ), x2 ); 1055 1056 pPS_L->nCount = 10; 1057 Sequence< Any > aSeq( pPS_L->nCount ); 1058 pPS_L->nCurrent = 0; 1059 1060 pPS_L->pExceptedListenerValues = aSeq.getArray(); 1061 1062 pPS_L->pExceptedListenerValues[0] <<= (sal_Int16) 0; // old value vetoable 1063 pPS_L->pExceptedListenerValues[1] <<= (sal_Int16) 22; // new value vetoable 1064 pPS_L->pExceptedListenerValues[2] <<= (sal_Int16) 0; // old value bound 1065 pPS_L->pExceptedListenerValues[3] <<= (sal_Int16) 22; // new value bound 1066 pPS_L->pExceptedListenerValues[4] <<= (sal_Int16) 22; // old value vetoable 1067 pPS_L->pExceptedListenerValues[5] <<= (sal_Int16) 44; // new value vetoable 1068 pPS_L->pExceptedListenerValues[6] <<= (sal_Int16) 22; // old value bound 1069 pPS_L->pExceptedListenerValues[7] <<= (sal_Int16) 44; // new value bound 1070 pPS_L->pExceptedListenerValues[8] <<= (sal_Int16) 44; // old value vetoable 1071 pPS_L->pExceptedListenerValues[9] <<= (sal_Int16) 100; // new value vetoable exception 1072 1073 Any aValue; 1074 aValue <<= (sal_Int16)22; 1075 xPS->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("INT16") ), aValue ); 1076 aValue <<= (sal_Int16) 44; 1077 ((XFastPropertySet *)pPS)->setFastPropertyValue( PROPERTY_INT16, aValue ); 1078 aValue <<= (sal_Int16)100;// exception 1079 1080 try 1081 { 1082 ((XFastPropertySet *)pPS)->setFastPropertyValue( PROPERTY_INT16, aValue ); 1083 OSL_ENSURE( sal_False, "PropertySetHelper: exception not thrown" ); 1084 } 1085 catch( PropertyVetoException & /*e*/ ) 1086 { 1087 } 1088 1089 OSL_ENSURE( pPS_L->nCount == pPS_L->nCurrent, "not all listeners called" ); 1090 pPS->nINT32 = 0; 1091 pPS->nINT16 = 0; 1092 pPS_L->nCount = 0; 1093 pPS_L->nCurrent = 0; 1094 pPS_L->pExceptedListenerValues = NULL; 1095 xPS->removePropertyChangeListener( OUString( RTL_CONSTASCII_USTRINGPARAM("INT16") ), xPS_L ); 1096 pPS->removeVetoableChangeListener( OUString( RTL_CONSTASCII_USTRINGPARAM("INT16") ), x2 ); 1097 } 1098 1099 // Test multi property set listener 1100 { 1101 Reference < XPropertiesChangeListener > x1( xPS_L, UNO_QUERY ); 1102 Reference < XVetoableChangeListener > x2( xPS_L, UNO_QUERY ); 1103 1104 pPS->addVetoableChangeListener( OUString( RTL_CONSTASCII_USTRINGPARAM("INT16") ) , x2 ); 1105 Sequence<OUString> szPN( 4 ); 1106 szPN.getArray()[0] = OUString( RTL_CONSTASCII_USTRINGPARAM("BOOL") ); 1107 szPN.getArray()[1] = OUString( RTL_CONSTASCII_USTRINGPARAM("INT32") ); 1108 szPN.getArray()[2] = OUString( RTL_CONSTASCII_USTRINGPARAM("Does not exist") ); // must ne ignored by the addPropertiesChangeListener method 1109 szPN.getArray()[3] = OUString( RTL_CONSTASCII_USTRINGPARAM("INT16") ); 1110 pPS->addPropertiesChangeListener( szPN, x1 ); 1111 1112 pPS_L->nCount = 6; 1113 Sequence< Any > aSeq( pPS_L->nCount ); 1114 pPS_L->nCurrent = 0; 1115 pPS_L->pExceptedListenerValues = aSeq.getArray(); 1116 pPS_L->pExceptedListenerValues[0] <<= (sal_Int16) 0; // old value vetoable 1117 pPS_L->pExceptedListenerValues[1] <<= (sal_Int16 ) 22; // new value vetoable 1118 // INT32 is not constrained 1119 pPS_L->pExceptedListenerValues[2] <<= (sal_Int16) 0; // old value bound 1120 pPS_L->pExceptedListenerValues[3] <<= (sal_Int16) 22; // new value bound 1121 pPS_L->pExceptedListenerValues[4] <<= (sal_Int32) 0; // old value bound 1122 pPS_L->pExceptedListenerValues[5] <<= (sal_Int32) 44; // new value bound 1123 1124 szPN = Sequence<OUString>( 2 ); 1125 szPN.getArray()[0] = OUString( RTL_CONSTASCII_USTRINGPARAM("INT16") ); 1126 szPN.getArray()[1] = OUString( RTL_CONSTASCII_USTRINGPARAM("INT32") ); 1127 Sequence< Any > aValues( 2 ); 1128 aValues.getArray()[0] <<= (sal_Int16) 22; 1129 aValues.getArray()[1] <<= (sal_Int16) 44; 1130 pPS->setPropertyValues( szPN, aValues ); 1131 OSL_ENSURE( pPS_L->nCount == pPS_L->nCurrent, "not all listeners called" ); 1132 1133 //firePropertiesChangeEvent 1134 pPS->nINT16 = 8; 1135 pPS->nINT32 = 5; 1136 pPS_L->nCount = 4; 1137 pPS_L->nCurrent = 0; 1138 pPS_L->pExceptedListenerValues[0] <<= (sal_Int16) 8; // old value 1139 pPS_L->pExceptedListenerValues[1] <<= (sal_Int16) 8; // new value 1140 pPS_L->pExceptedListenerValues[2] <<= (sal_Int32) 5; // old value 1141 pPS_L->pExceptedListenerValues[3] <<= (sal_Int32) 5; // new value 1142 pPS->firePropertiesChangeEvent( szPN, pPS_L ); 1143 OSL_ENSURE( pPS_L->nCount == pPS_L->nCurrent, "not all listeners called" ); 1144 1145 1146 //vetoable exception with multiple 1147 szPN.getArray()[0] = OUString( RTL_CONSTASCII_USTRINGPARAM("INT16") ); 1148 szPN.getArray()[1] = OUString( RTL_CONSTASCII_USTRINGPARAM("INT16") ); 1149 pPS->nINT32 = 0; 1150 pPS->nINT16 = 0; 1151 pPS_L->nCount = 4; 1152 pPS_L->nCurrent = 0; 1153 pPS_L->pExceptedListenerValues[0] <<= (sal_Int16) 0; // old value vetoable 1154 pPS_L->pExceptedListenerValues[1] <<= (sal_Int16) 44; // new value vetoable 1155 pPS_L->pExceptedListenerValues[2] <<= (sal_Int16) 0; // old value vetoable 1156 pPS_L->pExceptedListenerValues[3] <<= (sal_Int16) 100; // new value vetoable 1157 1158 try 1159 { 1160 aValues.getArray()[0] <<= (sal_Int16)44; 1161 aValues.getArray()[1] <<= (sal_Int16)100; 1162 pPS->setPropertyValues( szPN, aValues ); 1163 OSL_ENSURE( sal_False, "PropertySetHelper: exception not thrown" ); 1164 } 1165 catch ( PropertyVetoException & /*e*/ ) 1166 { 1167 } 1168 1169 OSL_ENSURE( pPS_L->nCount == pPS_L->nCurrent, "not all listeners called" ); 1170 pPS->removePropertiesChangeListener( x1 ); 1171 pPS->removeVetoableChangeListener( OUString( RTL_CONSTASCII_USTRINGPARAM("INT16") ), x2 ); 1172 } 1173 } 1174 } 1175