2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 import java
.util
.ArrayList
;
22 import java
.util
.List
;
23 import java
.util
.Random
;
26 import lib
.MultiMethodTest
;
27 import lib
.StatusException
;
28 import util
.ValueChanger
;
30 import com
.sun
.star
.beans
.Property
;
31 import com
.sun
.star
.beans
.PropertyAttribute
;
32 import com
.sun
.star
.beans
.XFastPropertySet
;
33 import com
.sun
.star
.beans
.XPropertySet
;
34 import com
.sun
.star
.beans
.XPropertySetInfo
;
35 import com
.sun
.star
.uno
.UnoRuntime
;
38 * Testing <code>com.sun.star.beans.XFastPropertySet</code>
41 * <li><code> setFastPropertyValue()</code></li>
42 * <li><code> getFastPropertyValue()</code></li>
44 * Required relations :
46 * <li> <code>'XFastPropertySet.ExcludeProps'</code>
47 * <b>(optional) </b> : java.util.Set.
48 * Has property names which must be skipped from testing in
49 * some reasons (for example property accepts restricted set
53 * @see com.sun.star.beans.XFastPropertySet
55 public class _XFastPropertySet
extends MultiMethodTest
{
57 public XFastPropertySet oObj
= null;
58 private List
<Integer
> handles
= new ArrayList
<Integer
>();
59 private int handle
= -1;
60 private Set
<String
> exclude
= null ;
65 protected void before() {
66 exclude
= (Set
<String
>) tEnv
.getObjRelation("XFastPropertySet.ExcludeProps") ;
67 if (exclude
== null) {
68 exclude
= new java
.util
.HashSet
<String
>() ;
73 * Test selects random property which can not be VOID and
74 * is writable, then change property value using <code>
75 * get/set</code> methods, and checks if value properly changed.
76 * Has <b> OK </b> status if value after change is not equal to value
77 * before and no exceptions were thrown. <p>
79 public void _setFastPropertyValue() {
80 XPropertySet PS
= UnoRuntime
.queryInterface
81 (XPropertySet
.class, oObj
);
82 XPropertySetInfo propertySetInfo
= PS
.getPropertySetInfo();
84 if (propertySetInfo
== null) {
85 log
.println("getPropertySetInfo() method returned null");
86 tRes
.tested("setFastPropertyValue()", false) ;
88 getPropsToTest(propertySetInfo
);
94 log
.println("*** No changeable properties found ***");
95 tRes
.tested("setFastPropertyValue()", false) ;
98 gValue
= oObj
.getFastPropertyValue(handle
);
99 sValue
= ValueChanger
.changePValue(gValue
);
100 oObj
.setFastPropertyValue(handle
, sValue
);
101 sValue
= oObj
.getFastPropertyValue(handle
);
102 } catch (com
.sun
.star
.beans
.UnknownPropertyException e
) {
103 log
.println("Exception occurred while trying to change property with handle = " + handle
);
104 e
.printStackTrace(log
);
105 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
106 log
.println("Exception occurred while trying to change property with handle = " + handle
);
107 e
.printStackTrace(log
);
108 } catch (com
.sun
.star
.beans
.PropertyVetoException e
) {
109 log
.println("Exception occurred while trying to change property with handle = " + handle
);
110 e
.printStackTrace(log
);
111 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
112 log
.println("Exception occurred while trying to change property with handle = " + handle
);
113 e
.printStackTrace(log
);
116 tRes
.tested("setFastPropertyValue()",(!gValue
.equals(sValue
)));
121 * Test selects random property which can not be VOID and
122 * is writable, then calls the method and checks that
123 * no exceptions were thrown. <p>
124 * Has <b> OK </b> status if exceptions were thrown. <p>
126 public void _getFastPropertyValue() {
127 XPropertySet PS
= UnoRuntime
.queryInterface
128 (XPropertySet
.class, oObj
);
129 XPropertySetInfo propertySetInfo
= PS
.getPropertySetInfo();
131 if (propertySetInfo
== null) {
132 log
.println("getPropertySetInfo() method returned null");
133 tRes
.tested("getFastPropertyValue()", false) ;
136 getPropsToTest(propertySetInfo
);
139 oObj
.getFastPropertyValue(handle
);
140 tRes
.tested("getFastPropertyValue()",true);
141 } catch (com
.sun
.star
.beans
.UnknownPropertyException e
) {
142 log
.println("Exception occurred while trying to get property '"
144 e
.printStackTrace(log
);
145 tRes
.tested("getFastPropertyValue()",false);
146 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
147 log
.println("Exception occurred while trying to get property '"
149 e
.printStackTrace(log
);
150 tRes
.tested("getFastPropertyValue()",false);
156 //Get the properties being tested
157 private void getPropsToTest(XPropertySetInfo xPSI
) {
159 Property
[] properties
= xPSI
.getProperties();
161 for (int i
= 0; i
< properties
.length
; i
++) {
162 if (exclude
.contains(properties
[i
].Name
)) continue ;
163 Property property
= properties
[i
];
164 String name
= property
.Name
;
165 int handle
= property
.Handle
;
166 log
.println("Checking '" + name
+ "' with handle = " + handle
);
168 ((property
.Attributes
& PropertyAttribute
.READONLY
) == 0);
170 ((property
.Attributes
& PropertyAttribute
.MAYBEVOID
) == 0);
171 boolean canChange
= false;
172 if ( isWritable
&& isNotNull
)
173 canChange
= isChangeable(handle
);
174 if ( isWritable
&& isNotNull
&& canChange
)
175 handles
.add(new Integer(handle
));
178 Random rnd
= new Random();
179 int nr
= rnd
.nextInt(handles
.size());
180 handle
= handles
.get(nr
).intValue();
183 private boolean isChangeable(int handle
) {
184 boolean hasChanged
= false;
186 Object getProp
= oObj
.getFastPropertyValue(handle
);
187 Object setValue
= null;
190 setValue
= ValueChanger
.changePValue(getProp
);
192 log
.println("Property with handle = " + handle
193 + " is null but 'MAYBEVOID' isn't set");
194 if (setValue
!= null) {
195 oObj
.setFastPropertyValue(handle
, setValue
);
197 (!getProp
.equals(oObj
.getFastPropertyValue(handle
)));
200 log
.println("Couldn't change Property with handle " + handle
);
201 } catch(com
.sun
.star
.lang
.WrappedTargetException e
) {
202 log
.println("Property with handle " + handle
+ " throws exception");
203 e
.printStackTrace(log
);
204 throw new StatusException("Property with handle " + handle
205 + " throws exception", e
);
206 } catch(com
.sun
.star
.lang
.IllegalArgumentException e
) {
207 log
.println("Property with handle " + handle
+ " throws exception");
208 e
.printStackTrace(log
);
209 throw new StatusException("Property with handle " + handle
210 + " throws exception", e
);
211 } catch(com
.sun
.star
.beans
.PropertyVetoException e
) {
212 log
.println("Property with handle " + handle
+ " throws exception");
213 e
.printStackTrace(log
);
214 throw new StatusException("Property with handle " + handle
215 + " throws exception", e
);
216 } catch(com
.sun
.star
.beans
.UnknownPropertyException e
) {
217 log
.println("Property with handle " + handle
+ " throws exception");
218 e
.printStackTrace(log
);
219 throw new StatusException("Property with handle " + handle
220 + " throws exception", e
);