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