1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _XFastPropertySet.java,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
33 import java
.util
.Random
;
35 import java
.util
.Vector
;
37 import lib
.MultiMethodTest
;
38 import lib
.StatusException
;
39 import util
.ValueChanger
;
41 import com
.sun
.star
.beans
.Property
;
42 import com
.sun
.star
.beans
.PropertyAttribute
;
43 import com
.sun
.star
.beans
.XFastPropertySet
;
44 import com
.sun
.star
.beans
.XPropertySet
;
45 import com
.sun
.star
.beans
.XPropertySetInfo
;
46 import com
.sun
.star
.uno
.UnoRuntime
;
49 * Testing <code>com.sun.star.beans.XFastPropertySet</code>
52 * <li><code> setFastPropertyValue()</code></li>
53 * <li><code> getFastPropertyValue()</code></li>
55 * Required relations :
57 * <li> <code>'XFastPropertySet.ExcludeProps'</code>
58 * <b>(optional) </b> : java.util.Set.
59 * Has property names which must be skipped from testing in
60 * some reasons (for example property accepts restricted set
64 * @see com.sun.star.beans.XFastPropertySet
66 public class _XFastPropertySet
extends MultiMethodTest
{
68 public XFastPropertySet oObj
= null;
69 private Vector handles
= new Vector();
70 private int handle
= -1;
71 private Set exclude
= null ;
76 protected void before() {
77 exclude
= (Set
) tEnv
.getObjRelation("XFastPropertySet.ExcludeProps") ;
78 if (exclude
== null) {
79 exclude
= new java
.util
.HashSet() ;
84 * Test selects random property which can not be VOID and
85 * is writable, then change property value using <code>
86 * get/set</code> methods, and checks if value properly changed.
87 * Has <b> OK </b> status if value after change is not equal to value
88 * before and no exceptions were thrown. <p>
90 public void _setFastPropertyValue() {
91 XPropertySet PS
= (XPropertySet
)UnoRuntime
.queryInterface
92 (XPropertySet
.class, oObj
);
93 XPropertySetInfo propertySetInfo
= PS
.getPropertySetInfo();
95 if (propertySetInfo
== null) {
96 log
.println("getPropertySetInfo() method returned null");
97 tRes
.tested("setFastPropertyValue()", false) ;
99 getPropsToTest(propertySetInfo
);
101 Object gValue
= null;
102 Object sValue
= null;
105 log
.println("*** No changeable properties found ***");
106 tRes
.tested("setFastPropertyValue()", false) ;
109 gValue
= oObj
.getFastPropertyValue(handle
);
110 sValue
= ValueChanger
.changePValue(gValue
);
111 oObj
.setFastPropertyValue(handle
, sValue
);
112 sValue
= oObj
.getFastPropertyValue(handle
);
113 } catch (com
.sun
.star
.beans
.UnknownPropertyException e
) {
114 log
.println("Exception occured while trying to change property with handle = " + handle
);
115 e
.printStackTrace(log
);
116 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
117 log
.println("Exception occured while trying to change property with handle = " + handle
);
118 e
.printStackTrace(log
);
119 } catch (com
.sun
.star
.beans
.PropertyVetoException e
) {
120 log
.println("Exception occured while trying to change property with handle = " + handle
);
121 e
.printStackTrace(log
);
122 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
123 log
.println("Exception occured while trying to change property with handle = " + handle
);
124 e
.printStackTrace(log
);
127 tRes
.tested("setFastPropertyValue()",(!gValue
.equals(sValue
)));
132 * Test selects random property which can not be VOID and
133 * is writable, then calls the method and checks that
134 * no exceptions were thrown. <p>
135 * Has <b> OK </b> status if exceptions were thrown. <p>
137 public void _getFastPropertyValue() {
138 XPropertySet PS
= (XPropertySet
)UnoRuntime
.queryInterface
139 (XPropertySet
.class, oObj
);
140 XPropertySetInfo propertySetInfo
= PS
.getPropertySetInfo();
142 if (propertySetInfo
== null) {
143 log
.println("getPropertySetInfo() method returned null");
144 tRes
.tested("getFastPropertyValue()", false) ;
147 getPropsToTest(propertySetInfo
);
150 oObj
.getFastPropertyValue(handle
);
151 tRes
.tested("getFastPropertyValue()",true);
152 } catch (com
.sun
.star
.beans
.UnknownPropertyException e
) {
153 log
.println("Exception occured while trying to get property '"
155 e
.printStackTrace(log
);
156 tRes
.tested("getFastPropertyValue()",false);
157 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
158 log
.println("Exception occured while trying to get property '"
160 e
.printStackTrace(log
);
161 tRes
.tested("getFastPropertyValue()",false);
167 //Get the properties being tested
168 private void getPropsToTest(XPropertySetInfo xPSI
) {
170 Property
[] properties
= xPSI
.getProperties();
172 for (int i
= 0; i
< properties
.length
; i
++) {
173 if (exclude
.contains(properties
[i
].Name
)) continue ;
174 Property property
= properties
[i
];
175 String name
= property
.Name
;
176 int handle
= property
.Handle
;
177 log
.println("Checking '" + name
+ "' with handle = " + handle
);
179 ((property
.Attributes
& PropertyAttribute
.READONLY
) == 0);
181 ((property
.Attributes
& PropertyAttribute
.MAYBEVOID
) == 0);
182 boolean canChange
= false;
183 if ( isWritable
&& isNotNull
)
184 canChange
= isChangeable(handle
);
185 if ( isWritable
&& isNotNull
&& canChange
)
186 handles
.add(new Integer(handle
));
189 Random rnd
= new Random();
190 int nr
= rnd
.nextInt(handles
.size());
191 handle
= ((Integer
)handles
.elementAt(nr
)).intValue();
194 private boolean isChangeable(int handle
) {
195 boolean hasChanged
= false;
197 Object getProp
= oObj
.getFastPropertyValue(handle
);
198 Object setValue
= null;
201 setValue
= ValueChanger
.changePValue(getProp
);
203 log
.println("Property with handle = " + handle
204 + " is null but 'MAYBEVOID' isn't set");
205 if (setValue
!= null) {
206 oObj
.setFastPropertyValue(handle
, setValue
);
208 (!getProp
.equals(oObj
.getFastPropertyValue(handle
)));
211 log
.println("Couldn't change Property with handle " + handle
);
212 } catch(com
.sun
.star
.lang
.WrappedTargetException e
) {
213 log
.println("Property with handle " + handle
+ " throws exception");
214 e
.printStackTrace(log
);
215 throw new StatusException("Property with handle " + handle
216 + " throws exception", e
);
217 } catch(com
.sun
.star
.lang
.IllegalArgumentException e
) {
218 log
.println("Property with handle " + handle
+ " throws exception");
219 e
.printStackTrace(log
);
220 throw new StatusException("Property with handle " + handle
221 + " throws exception", e
);
222 } catch(com
.sun
.star
.beans
.PropertyVetoException e
) {
223 log
.println("Property with handle " + handle
+ " throws exception");
224 e
.printStackTrace(log
);
225 throw new StatusException("Property with handle " + handle
226 + " throws exception", e
);
227 } catch(com
.sun
.star
.beans
.UnknownPropertyException e
) {
228 log
.println("Property with handle " + handle
+ " throws exception");
229 e
.printStackTrace(log
);
230 throw new StatusException("Property with handle " + handle
231 + " throws exception", e
);