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