merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / ifc / beans / _XPropertyContainer.java
blob0b751beb9638ef874d0359c4e5e7359950dc262f
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: _XPropertyContainer.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.IllegalTypeException;
34 import com.sun.star.beans.NotRemoveableException;
35 import com.sun.star.beans.PropertyExistException;
36 import com.sun.star.uno.Any;
37 import lib.MultiMethodTest;
38 import com.sun.star.beans.UnknownPropertyException;
39 import com.sun.star.beans.XPropertyContainer;
40 import lib.Status;
41 import lib.StatusException;
43 /**
44 * Testing <code>com.sun.star.beans.XPropertyAccess</code>
45 * interface methods :
46 * <ul>
47 * <li><code>addProperty()</code></li>
48 * <li><code>removeProperty()</code></li>
49 * </ul>
50 * @see com.sun.star.beans.XPropertyAccess
52 public class _XPropertyContainer extends MultiMethodTest {
54 /**
55 * oObj filled by MultiMethodTest
57 public XPropertyContainer oObj = null;// oObj filled by MultiMethodTest
59 /**
60 * object relation X<CODE>PropertyAccess.propertyNotRemovable</CODE><br>
61 * This relation must be filled from the module. It contains a property which must
62 * be a property of the implementaion object.
64 private String propertyNotRemovable = null;
66 /**
67 * checks if the object relation <CODE>XPropertyAccess.propertyNotRemovable</CODE>
68 * is available
70 public void before() {
71 propertyNotRemovable = (String) tEnv.getObjRelation("XPropertyContainer.propertyNotRemovable");
72 if (propertyNotRemovable == null) {
73 throw new StatusException(Status.failed("Object raltion 'XPropertyAccess.propertyNotRemovable' is null"));
79 /**
80 * Test calls the method and checks if the returned sequence contanis a propterty which is named
81 * in the object relation <code>XPropertyAccess.propertyNotRemovable</code>.
83 public void _addProperty() {
85 boolean ok = true;
86 boolean test = true;
87 boolean exp = false;
89 try {
90 log.println("try to add following property:\n" +
91 "\t('myXPropertContainerProperty', com.sun.star.beans.PropertyAttribute.MAYBEVOID, null) ...");
92 oObj.addProperty("myXPropertContainerProperty" , com.sun.star.beans.PropertyAttribute.MAYBEVOID, null);
93 } catch (com.sun.star.lang.IllegalArgumentException ex) {
94 log.println("ERROR: Exception was thrown while adding following property: " +
95 "('myXPropertContainerProperty', com.sun.star.beans.PropertyAttribute.MAYBEVOID, null) : " +
96 ex.toString());
97 log.println("... FAILED");
98 test = false;
99 } catch (PropertyExistException ex) {
100 log.println("ERROR: Exception was thrown while adding following property: " +
101 "('myXPropertContainerProperty', com.sun.star.beans.PropertyAttribute.MAYBEVOID, null) : " +
102 ex.toString());
103 log.println("... FAILED");
104 test = false;
105 } catch (IllegalTypeException ex) {
106 log.println("ERROR: Exception was thrown while adding following property: " +
107 "('myXPropertContainerProperty', com.sun.star.beans.PropertyAttribute.MAYBEVOID, null) : " +
108 ex.toString());
109 log.println("... FAILED");
110 test = false;
113 if ( test){
114 log.println("... OK");
117 ok &= test;
118 test = false;
119 exp = false;
120 try {
121 log.println("add following property second time:\n" +
122 "\t('myXPropertContainerProperty', com.sun.star.beans.PropertyAttribute.MAYBEVOID, null) ...");
123 oObj.addProperty("myXPropertContainerProperty" , com.sun.star.beans.PropertyAttribute.MAYBEVOID, null);
124 } catch (com.sun.star.lang.IllegalArgumentException ex) {
125 log.println("ERROR: wrong Exception was thrown while adding following property: " +
126 "('myXPropertContainerProperty', com.sun.star.beans.PropertyAttribute.MAYBEVOID, null) : " +
127 "Expected: 'PropertyExistException'\n" +
128 "Got: 'IllegalArgumentException\n" +
129 ex.toString());
130 log.println("... FAILED");
131 exp = true;
132 } catch (PropertyExistException ex) {
133 log.println("OK: expected Exception was thrown." + ex.toString());
134 test = true;
135 exp = true;
136 } catch (IllegalTypeException ex) {
137 log.println("ERROR: wrong Exception was thrown while adding following property: " +
138 "('myXPropertContainerProperty', com.sun.star.beans.PropertyAttribute.MAYBEVOID, null) : " +
139 "Expected: 'PropertyExistException'\n" +
140 "Got: 'IllegalTypeException\n" +
141 ex.toString());
142 log.println("... FAILED");
143 exp = true;
145 if (! exp){
146 log.println("FAILED: expected exception 'UnknownPropertyException' was not thrown");
147 } else {
148 if (test) log.println("... OK");
151 ok &= test;
152 test = false;
153 exp = false;
154 try {
155 log.println("try to add following property:\n" +
156 "\t('IllegalTypeProperty', com.sun.star.beans.PropertyAttribute.MAYBEVOID, Any.VOID) ...");
157 oObj.addProperty("IllegalTypeProperty", com.sun.star.beans.PropertyAttribute.MAYBEVOID, Any.VOID);
158 } catch (com.sun.star.lang.IllegalArgumentException ex) {
159 log.println("ERROR: wrong Exception was thrown while adding following property: " +
160 "'', com.sun.star.beans.PropertyAttribute.MAYBEVOID, null\n" +
161 "Expected: 'IllegalTypeException'\n" +
162 "Got: 'IllegalArgumentException\n" +
163 ex.toString());
164 log.println("... FAILED");
165 exp = true;
166 } catch (PropertyExistException ex) {
167 log.println("ERROR: wrong Exception was thrown while adding following property: " +
168 "'', com.sun.star.beans.PropertyAttribute.MAYBEVOID, null\n" +
169 "Expected: 'IllegalArgumentException'\n" +
170 "Got: 'PropertyExistException\n" +
171 ex.toString());
172 log.println("... FAILED");
173 exp = true;
174 } catch (IllegalTypeException ex) {
175 log.println("OK: expected Exception was thrown." + ex.toString());
176 test = true;
177 exp = true;
180 if (! exp){
181 log.println("FAILED: expected exception 'IllegalTypeException' was not thrown");
182 } else {
183 if (test) log.println("... OK");
186 ok &= test;
187 test = false;
188 exp = false;
189 try {
190 short attrib = -1;
191 log.println("add following property:\n" +
192 "'', -1, new Object");
193 oObj.addProperty("", attrib, null);
194 } catch (com.sun.star.lang.IllegalArgumentException ex) {
195 log.println("OK: expected Exception was thrown." + ex.toString());
196 test = true;
197 exp = true;
198 } catch (PropertyExistException ex) {
199 log.println("ERROR: wrong Exception was thrown while adding following property: " +
200 "'invalidPropertyAttribute', -1, null\n" +
201 "Expected: 'IllegalTypeException'\n" +
202 "Got: 'PropertyExistException\n" +
203 ex.toString());
204 log.println("... FAILED");
205 exp = true;
206 } catch (IllegalTypeException ex) {
207 log.println("ERROR: unexpected Exception was thrown while adding following property: " +
208 "'', -1, null\n" +
209 "Expected: 'IllegalArgumentException'\n" +
210 "Got: 'IllegalTypeException\n" +
211 ex.toString());
212 log.println("... FAILED");
213 exp = true;
216 if (! exp){
217 log.println("FAILED: expected exception 'IllegalArgumentException' was not thrown");
218 } else {
219 if (test) log.println("... OK");
222 ok &= test;
224 tRes.tested("addProperty()", ok );
225 return;
229 * Test calls the method and checks if the returned sequence contanis a propterty which is named
230 * in the object relation <code>XPropertyAccess.propertyNotRemovable</code>.
232 public void _removeProperty() {
234 requiredMethod("addProperty()");
236 boolean ok = true;
237 boolean test = true;
238 boolean exp = false;
240 try {
241 log.println("remove 'myXPropertContainerProperty'");
242 oObj.removeProperty("myXPropertContainerProperty");
243 } catch (NotRemoveableException ex) {
244 log.println("ERROR: could not remote property 'myXPropertContainerProperty'" + ex.toString());
245 log.println("... FAILED");
246 test = false;
247 } catch (UnknownPropertyException ex) {
248 log.println("ERROR: could not remote property 'myXPropertContainerProperty'" + ex.toString());
249 log.println("... FAILED");
250 test = false;
252 if ( test){
253 log.println("... OK");
256 ok &= test;
257 test = false;
258 exp=false;
260 try {
261 log.println("remove not removeable property '" + propertyNotRemovable + "'") ;
262 oObj.removeProperty(propertyNotRemovable);
263 } catch (NotRemoveableException ex) {
264 log.println("OK: expected Exception was thrown: " + ex.toString());
265 test = true;
266 exp = true;
267 } catch (UnknownPropertyException ex) {
268 log.println("ERROR: wrong exception was thrown.\n" +
269 "Expected: 'NotRemoveableException'\n" +
270 "Got: 'UnknownPropertyException'\n" +
271 ex.toString());
272 log.println("... FAILED");
273 exp = true;
276 if (! exp){
277 log.println("FAILED: expected exception 'NotRemoveableException' was not thrown");
278 } else {
279 if (test) log.println("... OK");
282 ok &= test;
283 test = false;
284 exp = false;
286 try {
287 log.println("remove property 'thisPropertyDoesNotExist'");
288 oObj.removeProperty("thisPropertyDoesNotExist");
289 } catch (UnknownPropertyException ex) {
290 log.println("OK: expected Exception was thrown: " + ex.toString());
291 test = true;
292 exp = true;
293 } catch (NotRemoveableException ex) {
294 log.println("ERROR: wrong exception was thrown.\n" +
295 "Expected: 'UnknownPropertyException'\n" +
296 "Got: 'NotRemoveableException\n" +
297 ex.toString());
298 log.println("... FAILED");
299 exp = true;
301 if (! exp){
302 log.println("FAILED: expected exception 'UnknownPropertyException' was not thrown");
303 } else {
304 if (test) log.println("... OK");
307 tRes.tested("removeProperty()", ok );
308 return;
312 } /// finish class XPropertyContainer