merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / ifc / beans / _XPropertyAccess.java
blob8144db1dacee57bd068a40cb05c72616182dc6b2
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: _XPropertyAccess.java,v $
10 * $Revision: 1.3 $
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 com.sun.star.beans.PropertyValue;
34 import com.sun.star.beans.PropertyVetoException;
35 import com.sun.star.lang.WrappedTargetException;
36 import lib.MultiMethodTest;
37 import com.sun.star.beans.UnknownPropertyException;
38 import com.sun.star.beans.XPropertyAccess;
39 import lib.Status;
40 import lib.StatusException;
42 /**
43 * Testing <code>com.sun.star.beans.XPropertyAccess</code>
44 * interface methods :
45 * <ul>
46 * <li><code>getPropertyValues()</code></li>
47 * <li><code>setPropertyValues()</code></li>
48 * </ul>
49 * @see com.sun.star.beans.XPropertyAccess
51 public class _XPropertyAccess extends MultiMethodTest {
53 /**
54 * oObj filled by MultiMethodTest
56 public XPropertyAccess oObj = null;// oObj filled by MultiMethodTest
58 /**
59 * object relation X<CODE>PropertyAccess.propertyToChange</CODE><br>
60 * This relation must be filled from the module. It contains a property which must
61 * be kind of String property, available at <CODE>getPropertyValues()</CODE> and changeable by
62 * <CODE>setPropertyValues()</CODE>
64 public PropertyValue propertyToChange = null;
66 /**
67 * checks if the object relation <CODE>XPropertyAccess.propertyToChange</CODE>
68 * is available
70 public void before() {
71 propertyToChange = (PropertyValue) tEnv.getObjRelation("XPropertyAccess.propertyToChange");
72 if (propertyToChange == null) {
73 throw new StatusException(Status.failed("Object raltion 'XPropertyAccess.propertyToChange' is null"));
77 /**
78 * Test calls the method and checks if the returned sequenze contanis a propterty which is named
79 * in the object relation <code>XPropertyAccess.propertyToChange</code>.
81 public void _getPropertyValues() {
82 PropertyValue[] properties = oObj.getPropertyValues();
84 boolean ok = true;
86 if (properties != null){
88 boolean found = false;
89 for (int i=0; i < properties.length; i++){
90 if (properties[i].Name.equals(propertyToChange.Name)) found = true;
92 if (! found){
93 log.println("ERROR: could not find desired property '"+ propertyToChange.Name+"'");
94 ok=false;
97 } else {
98 log.println("ERROR: the method returned NULL");
99 ok =false;
102 tRes.tested("getPropertyValues()", ok );
103 return;
107 * Test calls the method and checks if:
108 * <ul>
109 * <li>the property given by the object relation
110 * <CODE>XPropertyAccess.propertyToChange</CODE> has changed</LI>
111 * <li><CODE>com.sun.star.lang.IllegalArgumentException</CODE> was thrown if a <CODE>Integer</CODE>
112 * value was set to a <CODE>String</CODE> property</LI>
113 * <li><CODE>com.sun.star.beans.UnknownPropertyException</CODE> was throen if an invalid property
114 * was set</LI>
115 * </ul>
117 public void _setPropertyValues(){
119 boolean ok = true;
120 boolean test = true;
121 boolean exp = false;
123 try {
124 PropertyValue[] newProps = new PropertyValue[1];
125 newProps[0] = propertyToChange;
127 log.println("try to set property vlaues given by object relation 'XPropertyAccess.propertyToChange'...");
128 oObj.setPropertyValues(newProps);
130 } catch (UnknownPropertyException ex) {
131 log.println("ERROR: Exception was thrown while trying to set property value: " +
132 ex.toString());
133 test = false;
134 } catch (PropertyVetoException ex) {
135 log.println("ERROR: Exception was thrown while trying to set property value: " +
136 ex.toString());
137 test = false;
138 } catch (WrappedTargetException ex) {
139 log.println("ERROR: Exception was thrown while trying to set property value: " +
140 ex.toString());
141 test = false;
142 } catch (com.sun.star.lang.IllegalArgumentException ex) {
143 log.println("ERROR: Exception was thrown while trying to set property value: " +
144 ex.toString());
145 test = false;
148 if ( test){
149 log.println("... OK");
152 ok &= test;
153 test = false;
154 exp = false;
155 try {
156 log.println("try to set integer value to string property, " +
157 "expect 'com.sun.star.lang.IllegalArgumentException'...");
158 PropertyValue[] newProps = new PropertyValue[1];
159 PropertyValue failedProp = new PropertyValue();
160 failedProp.Name = propertyToChange.Name;
161 failedProp.Value = new Integer(10);
162 newProps[0] = failedProp;
163 oObj.setPropertyValues(newProps);
164 } catch (PropertyVetoException ex) {
165 log.println("ERROR: unexptected exception was thrown while trying to set null value: " +
166 ex.toString());
167 exp = true;
168 } catch (WrappedTargetException ex) {
169 log.println("ERROR: unexptected exception was thrown while trying to set null value: " +
170 ex.toString());
171 exp = true;
172 } catch (com.sun.star.lang.IllegalArgumentException ex) {
173 log.println("OK: exptected exception was thrown while trying to set null value: " +
174 ex.toString());
175 test = true;
176 exp = true;
177 } catch (UnknownPropertyException ex) {
178 log.println("ERROR: unexptected exception was thrown while trying to set null value: " +
179 ex.toString());
180 exp = true;
183 if (! exp){
184 log.println("FAILED: expected exception 'UnknownPropertyException' was not thrown");
185 } else {
186 if (test) log.println("... OK");
189 ok &= test;
190 test = false;
191 exp = false;
192 try {
194 log.println("try to set values with invalid property name. " +
195 "Expect 'com.sun.star.beans.UnknownPropertyException'...");
197 PropertyValue[] newProps = new PropertyValue[1];
198 PropertyValue newProp = new PropertyValue();
199 newProp.Name = "XPropertyAccess.InvalidPropertyName";
200 newProp.Value = "invalid property";
201 newProps[0] = newProp;
203 oObj.setPropertyValues(newProps);
205 } catch (WrappedTargetException ex) {
206 log.println("ERROR: unexptected exception was thrown while trying to set invalid value: " +
207 ex.toString());
208 exp = true;
209 } catch (com.sun.star.lang.IllegalArgumentException ex) {
210 log.println("ERROR: unexptected exception was thrown while trying to set invalid value: " +
211 ex.toString());
212 exp = true;
213 } catch (PropertyVetoException ex) {
214 log.println("ERROR: unexptected exception was thrown while trying to set invalid value: " +
215 ex.toString());
216 exp = true;
217 } catch (UnknownPropertyException ex) {
218 log.println("OK: Exptected exception was thrown while trying to set invalid value: " +
219 ex.toString());
220 exp = true;
221 test = true;
224 ok &= test;
226 if (! exp){
227 log.println("FAILED: expected exception 'UnknownPropertyException' was not thrown");
228 } else {
229 if (test) log.println("... OK");
232 tRes.tested("setPropertyValues()", ok);
233 return;
237 } /// finish class XPropertyAccess