merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / ifc / beans / _XPropertyState.java
blob18f6b2d99566d80fb7ed4117114b080f0cb9a110
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _XPropertyState.java,v $
10 * $Revision: 1.5 $
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 ************************************************************************/
31 package ifc.beans;
33 import lib.MultiMethodTest;
34 import lib.Status;
35 import lib.StatusException;
37 import com.sun.star.beans.Property;
38 import com.sun.star.beans.PropertyAttribute;
39 import com.sun.star.beans.PropertyState;
40 import com.sun.star.beans.XPropertySet;
41 import com.sun.star.beans.XPropertySetInfo;
42 import com.sun.star.beans.XPropertyState;
43 import com.sun.star.uno.Any;
44 import com.sun.star.uno.UnoRuntime;
47 /**
48 * Testing <code>com.sun.star.beans.XPropertyState</code>
49 * interface methods :
50 * <ul>
51 * <li><code> getPropertyState()</code></li>
52 * <li><code> getPropertyStates()</code></li>
53 * <li><code> setPropertyToDefault()</code></li>
54 * <li><code> getPropertyDefault()</code></li>
55 * </ul>
56 * Test is <b> NOT </b> multithread compilant. <p>
57 * After test completion object environment has to be recreated. <p>
58 * <b>Note:</b> object tested must also implement
59 * <code>com.sun.star.beans.XPropertySet</code> interface.
60 * @see com.sun.star.beans.XPropertyState
62 public class _XPropertyState extends MultiMethodTest {
64 public XPropertyState oObj = null;
66 private XPropertySet oPS = null ;
67 private XPropertySetInfo propertySetInfo = null;
68 private Property[] properties = null ;
69 private String pName = null ;
70 private Object propDef = null ;
72 /**
73 * Queries object for <code>XPropertySet</code> interface and
74 * initializes some fields used by all methods. <p>
76 * Searches property which is not READONLY and MAYBEDEFAULT, if
77 * such property is not found, then uses property with only
78 * READONLY attribute. This property name is stored and is used
79 * by all tests.
81 * @throws StatusException If <code>XPropertySet</code> is not
82 * implemented by object.
84 public void before() throws StatusException {
85 oPS = (XPropertySet)
86 UnoRuntime.queryInterface( XPropertySet.class, oObj );
87 if (oPS == null)
88 throw new StatusException
89 ("XPropertySet interface isn't implemented.",
90 new NullPointerException
91 ("XPropertySet interface isn't implemented.")) ;
93 propertySetInfo = oPS.getPropertySetInfo();
94 properties = propertySetInfo.getProperties();
95 Property prop = null;
96 for (int i=0;i<properties.length;i++) {
97 try {
98 prop = propertySetInfo.getPropertyByName
99 (properties[i].Name);
100 } catch (com.sun.star.beans.UnknownPropertyException e) {
101 log.println("Unknown Property "+prop.Name);
103 boolean readOnly = (prop.Attributes &
104 PropertyAttribute.READONLY) != 0;
105 boolean maybeDefault = (prop.Attributes &
106 PropertyAttribute.MAYBEDEFAULT) != 0;
107 if (!readOnly && maybeDefault) {
108 pName = properties[i].Name;
109 log.println("Property '" + pName + "' has attributes "+
110 prop.Attributes);
111 break ;
112 } else
113 if (!readOnly) {
114 pName = properties[i].Name;
115 log.println("Property '" + pName +
116 "' is not readonly, may be used ...");
117 } else {
118 log.println("Skipping property '" + properties[i].Name +
119 "' Readonly: " + readOnly + ", MaybeDefault: " +
120 maybeDefault);
127 * Test calls the method and checks that no exceptions were thrown. <p>
128 * Has <b> OK </b> status if no exceptions were thrown. <p>
130 public void _getPropertyDefault(){
131 boolean result = true ;
132 String localName = pName;
133 if (localName == null) {
134 localName = (propertySetInfo.getProperties()[0]).Name;
136 try {
137 propDef = oObj.getPropertyDefault(localName);
138 log.println("Default property value is : '" + propDef + "'");
139 } catch (com.sun.star.beans.UnknownPropertyException e) {
140 log.println("Exception " + e +
141 "occured while getting Property default");
142 result=false;
143 } catch (com.sun.star.lang.WrappedTargetException e) {
144 log.println("Exception " + e +
145 "occured while getting Property default");
146 result=false;
148 tRes.tested("getPropertyDefault()", result);
152 * Test calls the method and checks return value and that
153 * no exceptions were thrown. <p>
154 * Has <b> OK </b> status if the method returns not null value
155 * and no exceptions were thrown. <p>
157 public void _getPropertyState(){
158 boolean result = true ;
160 String localName = pName;
161 if (localName == null) {
162 localName = (propertySetInfo.getProperties()[0]).Name;
165 try {
166 PropertyState ps = oObj.getPropertyState(localName);
167 if (ps == null) {
168 log.println("!!! Returned value == null") ;
169 result = false ;
171 } catch (com.sun.star.beans.UnknownPropertyException e) {
172 log.println("Exception " + e +
173 "occured while getting Property state");
174 result = false;
176 tRes.tested("getPropertyState()", result);
180 * Test calls the method with array of one property name
181 * and checks return value and that no exceptions were thrown. <p>
182 * Has <b> OK </b> status if the method returns array with one
183 * PropertyState and no exceptions were thrown. <p>
185 public void _getPropertyStates(){
186 boolean result = true ;
188 String localName = pName;
189 if (localName == null) {
190 localName = (propertySetInfo.getProperties()[0]).Name;
193 try {
194 PropertyState[] ps = oObj.getPropertyStates
195 (new String[] {localName});
196 if (ps == null) {
197 log.println("!!! Returned value == null") ;
198 result = false ;
199 } else {
200 if (ps.length != 1) {
201 log.println("!!! Array lebgth returned is invalid - " +
202 ps.length) ;
203 result = false ;
206 } catch (com.sun.star.beans.UnknownPropertyException e) {
207 log.println("Exception " + e +
208 "occured while getting Property state");
209 result = false;
212 tRes.tested("getPropertyStates()", result);
217 * Sets the property to default, then compares the current property
218 * value to value received by method <code>getPropertyDefault</code>.
219 * Has <b> OK </b> status if the current proeprty value equals to
220 * default property. <p>
221 * The following method tests are to be completed successfully before :
222 * <ul>
223 * <li> <code>getPropertyDefault</code>: we have to know what is
224 * default value</li></ul>
226 public void _setPropertyToDefault(){
227 requiredMethod("getPropertyDefault()") ;
229 if (pName == null) {
230 log.println("all found properties are read only");
231 tRes.tested("setPropertyToDefault()",Status.skipped(true));
232 return;
235 boolean result = true ;
236 try {
237 try {
238 oObj.setPropertyToDefault(pName);
240 catch(RuntimeException e) {
241 System.out.println("Ignoring RuntimeException: " + e.getMessage());
243 if ((properties[0].Attributes &
244 PropertyAttribute.MAYBEDEFAULT) != 0) {
245 Object actualDef = propDef ;
246 if (propDef instanceof Any) {
247 actualDef = ((Any)propDef).getObject() ;
249 Object actualVal = oPS.getPropertyValue(pName) ;
250 if (actualVal instanceof Any) {
251 actualVal = ((Any)actualVal).getObject() ;
253 result = util.ValueComparer.equalValue
254 (actualDef,actualVal) ;
255 log.println("Default value = '" + actualDef +
256 "', returned value = '"
257 + actualVal + "' for property " + pName) ;
259 } catch (com.sun.star.beans.UnknownPropertyException e) {
260 log.println("Exception " + e +
261 "occured while setting Property to default");
262 result=false;
263 } catch (com.sun.star.lang.WrappedTargetException e) {
264 log.println("Exception " + e +
265 "occured while testing property value");
266 result=false;
269 tRes.tested("setPropertyToDefault()", result);
272 public void after() {
273 disposeEnvironment() ;
276 }// EOF _XPropertyState