1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
30 import java
.util
.Random
;
32 import java
.util
.Vector
;
34 import lib
.MultiMethodTest
;
35 import lib
.StatusException
;
36 import util
.ValueChanger
;
38 import com
.sun
.star
.beans
.Property
;
39 import com
.sun
.star
.beans
.PropertyAttribute
;
40 import com
.sun
.star
.beans
.XFastPropertySet
;
41 import com
.sun
.star
.beans
.XPropertySet
;
42 import com
.sun
.star
.beans
.XPropertySetInfo
;
43 import com
.sun
.star
.uno
.UnoRuntime
;
46 * Testing <code>com.sun.star.beans.XFastPropertySet</code>
49 * <li><code> setFastPropertyValue()</code></li>
50 * <li><code> getFastPropertyValue()</code></li>
52 * Required relations :
54 * <li> <code>'XFastPropertySet.ExcludeProps'</code>
55 * <b>(optional) </b> : java.util.Set.
56 * Has property names which must be skipped from testing in
57 * some reasons (for example property accepts restricted set
61 * @see com.sun.star.beans.XFastPropertySet
63 public class _XFastPropertySet
extends MultiMethodTest
{
65 public XFastPropertySet oObj
= null;
66 private Vector handles
= new Vector();
67 private int handle
= -1;
68 private Set exclude
= null ;
73 protected void before() {
74 exclude
= (Set
) tEnv
.getObjRelation("XFastPropertySet.ExcludeProps") ;
75 if (exclude
== null) {
76 exclude
= new java
.util
.HashSet() ;
81 * Test selects random property which can not be VOID and
82 * is writable, then change property value using <code>
83 * get/set</code> methods, and checks if value properly changed.
84 * Has <b> OK </b> status if value after change is not equal to value
85 * before and no exceptions were thrown. <p>
87 public void _setFastPropertyValue() {
88 XPropertySet PS
= (XPropertySet
)UnoRuntime
.queryInterface
89 (XPropertySet
.class, oObj
);
90 XPropertySetInfo propertySetInfo
= PS
.getPropertySetInfo();
92 if (propertySetInfo
== null) {
93 log
.println("getPropertySetInfo() method returned null");
94 tRes
.tested("setFastPropertyValue()", false) ;
96 getPropsToTest(propertySetInfo
);
102 log
.println("*** No changeable properties found ***");
103 tRes
.tested("setFastPropertyValue()", false) ;
106 gValue
= oObj
.getFastPropertyValue(handle
);
107 sValue
= ValueChanger
.changePValue(gValue
);
108 oObj
.setFastPropertyValue(handle
, sValue
);
109 sValue
= oObj
.getFastPropertyValue(handle
);
110 } catch (com
.sun
.star
.beans
.UnknownPropertyException e
) {
111 log
.println("Exception occurred while trying to change property with handle = " + handle
);
112 e
.printStackTrace(log
);
113 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
114 log
.println("Exception occurred while trying to change property with handle = " + handle
);
115 e
.printStackTrace(log
);
116 } catch (com
.sun
.star
.beans
.PropertyVetoException e
) {
117 log
.println("Exception occurred while trying to change property with handle = " + handle
);
118 e
.printStackTrace(log
);
119 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
120 log
.println("Exception occurred while trying to change property with handle = " + handle
);
121 e
.printStackTrace(log
);
124 tRes
.tested("setFastPropertyValue()",(!gValue
.equals(sValue
)));
129 * Test selects random property which can not be VOID and
130 * is writable, then calls the method and checks that
131 * no exceptions were thrown. <p>
132 * Has <b> OK </b> status if exceptions were thrown. <p>
134 public void _getFastPropertyValue() {
135 XPropertySet PS
= (XPropertySet
)UnoRuntime
.queryInterface
136 (XPropertySet
.class, oObj
);
137 XPropertySetInfo propertySetInfo
= PS
.getPropertySetInfo();
139 if (propertySetInfo
== null) {
140 log
.println("getPropertySetInfo() method returned null");
141 tRes
.tested("getFastPropertyValue()", false) ;
144 getPropsToTest(propertySetInfo
);
147 oObj
.getFastPropertyValue(handle
);
148 tRes
.tested("getFastPropertyValue()",true);
149 } catch (com
.sun
.star
.beans
.UnknownPropertyException e
) {
150 log
.println("Exception occurred while trying to get property '"
152 e
.printStackTrace(log
);
153 tRes
.tested("getFastPropertyValue()",false);
154 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
155 log
.println("Exception occurred while trying to get property '"
157 e
.printStackTrace(log
);
158 tRes
.tested("getFastPropertyValue()",false);
164 //Get the properties being tested
165 private void getPropsToTest(XPropertySetInfo xPSI
) {
167 Property
[] properties
= xPSI
.getProperties();
169 for (int i
= 0; i
< properties
.length
; i
++) {
170 if (exclude
.contains(properties
[i
].Name
)) continue ;
171 Property property
= properties
[i
];
172 String name
= property
.Name
;
173 int handle
= property
.Handle
;
174 log
.println("Checking '" + name
+ "' with handle = " + handle
);
176 ((property
.Attributes
& PropertyAttribute
.READONLY
) == 0);
178 ((property
.Attributes
& PropertyAttribute
.MAYBEVOID
) == 0);
179 boolean canChange
= false;
180 if ( isWritable
&& isNotNull
)
181 canChange
= isChangeable(handle
);
182 if ( isWritable
&& isNotNull
&& canChange
)
183 handles
.add(new Integer(handle
));
186 Random rnd
= new Random();
187 int nr
= rnd
.nextInt(handles
.size());
188 handle
= ((Integer
)handles
.elementAt(nr
)).intValue();
191 private boolean isChangeable(int handle
) {
192 boolean hasChanged
= false;
194 Object getProp
= oObj
.getFastPropertyValue(handle
);
195 Object setValue
= null;
198 setValue
= ValueChanger
.changePValue(getProp
);
200 log
.println("Property with handle = " + handle
201 + " is null but 'MAYBEVOID' isn't set");
202 if (setValue
!= null) {
203 oObj
.setFastPropertyValue(handle
, setValue
);
205 (!getProp
.equals(oObj
.getFastPropertyValue(handle
)));
208 log
.println("Couldn't change Property with handle " + handle
);
209 } catch(com
.sun
.star
.lang
.WrappedTargetException e
) {
210 log
.println("Property with handle " + handle
+ " throws exception");
211 e
.printStackTrace(log
);
212 throw new StatusException("Property with handle " + handle
213 + " throws exception", e
);
214 } catch(com
.sun
.star
.lang
.IllegalArgumentException e
) {
215 log
.println("Property with handle " + handle
+ " throws exception");
216 e
.printStackTrace(log
);
217 throw new StatusException("Property with handle " + handle
218 + " throws exception", e
);
219 } catch(com
.sun
.star
.beans
.PropertyVetoException e
) {
220 log
.println("Property with handle " + handle
+ " throws exception");
221 e
.printStackTrace(log
);
222 throw new StatusException("Property with handle " + handle
223 + " throws exception", e
);
224 } catch(com
.sun
.star
.beans
.UnknownPropertyException e
) {
225 log
.println("Property with handle " + handle
+ " throws exception");
226 e
.printStackTrace(log
);
227 throw new StatusException("Property with handle " + handle
228 + " throws exception", e
);