bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / ifc / beans / _XPropertyContainer.java
blob5befa68df01b41e6173a36fd10477660a9b6dc76
1 /*
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 .
19 package ifc.beans;
21 import com.sun.star.beans.IllegalTypeException;
22 import com.sun.star.beans.NotRemoveableException;
23 import com.sun.star.beans.PropertyExistException;
24 import com.sun.star.uno.Any;
25 import lib.MultiMethodTest;
26 import com.sun.star.beans.UnknownPropertyException;
27 import com.sun.star.beans.XPropertyContainer;
28 import lib.Status;
29 import lib.StatusException;
31 /**
32 * Testing <code>com.sun.star.beans.XPropertyAccess</code>
33 * interface methods :
34 * <ul>
35 * <li><code>addProperty()</code></li>
36 * <li><code>removeProperty()</code></li>
37 * </ul>
38 * @see com.sun.star.beans.XPropertyAccess
40 public class _XPropertyContainer extends MultiMethodTest {
42 /**
43 * oObj filled by MultiMethodTest
45 public XPropertyContainer oObj = null;// oObj filled by MultiMethodTest
47 /**
48 * object relation X<CODE>PropertyAccess.propertyNotRemovable</CODE><br>
49 * This relation must be filled from the module. It contains a property which must
50 * be a property of the implementaion object.
52 private String propertyNotRemovable = null;
54 /**
55 * checks if the object relation <CODE>XPropertyAccess.propertyNotRemovable</CODE>
56 * is available
58 public void before() {
59 propertyNotRemovable = (String) tEnv.getObjRelation("XPropertyContainer.propertyNotRemovable");
60 if (propertyNotRemovable == null) {
61 throw new StatusException(Status.failed("Object raltion 'XPropertyAccess.propertyNotRemovable' is null"));
67 /**
68 * Test calls the method and checks if the returned sequence contanis a propterty which is named
69 * in the object relation <code>XPropertyAccess.propertyNotRemovable</code>.
71 public void _addProperty() {
73 boolean ok = true;
74 boolean test = true;
75 boolean exp = false;
77 try {
78 log.println("try to add following property:\n" +
79 "\t('myXPropertContainerProperty', com.sun.star.beans.PropertyAttribute.MAYBEVOID, null) ...");
80 oObj.addProperty("myXPropertContainerProperty" , com.sun.star.beans.PropertyAttribute.MAYBEVOID, null);
81 } catch (com.sun.star.lang.IllegalArgumentException ex) {
82 log.println("ERROR: Exception was thrown while adding following property: " +
83 "('myXPropertContainerProperty', com.sun.star.beans.PropertyAttribute.MAYBEVOID, null) : " +
84 ex.toString());
85 log.println("... FAILED");
86 test = false;
87 } catch (PropertyExistException ex) {
88 log.println("ERROR: Exception was thrown while adding following property: " +
89 "('myXPropertContainerProperty', com.sun.star.beans.PropertyAttribute.MAYBEVOID, null) : " +
90 ex.toString());
91 log.println("... FAILED");
92 test = false;
93 } catch (IllegalTypeException 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;
101 if ( test){
102 log.println("... OK");
105 ok &= test;
106 test = false;
107 exp = false;
108 try {
109 log.println("add following property second time:\n" +
110 "\t('myXPropertContainerProperty', com.sun.star.beans.PropertyAttribute.MAYBEVOID, null) ...");
111 oObj.addProperty("myXPropertContainerProperty" , com.sun.star.beans.PropertyAttribute.MAYBEVOID, null);
112 } catch (com.sun.star.lang.IllegalArgumentException ex) {
113 log.println("ERROR: wrong Exception was thrown while adding following property: " +
114 "('myXPropertContainerProperty', com.sun.star.beans.PropertyAttribute.MAYBEVOID, null) : " +
115 "Expected: 'PropertyExistException'\n" +
116 "Got: 'IllegalArgumentException\n" +
117 ex.toString());
118 log.println("... FAILED");
119 exp = true;
120 } catch (PropertyExistException ex) {
121 log.println("OK: expected Exception was thrown." + ex.toString());
122 test = true;
123 exp = true;
124 } catch (IllegalTypeException 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: 'IllegalTypeException\n" +
129 ex.toString());
130 log.println("... FAILED");
131 exp = true;
133 if (! exp){
134 log.println("FAILED: expected exception 'UnknownPropertyException' was not thrown");
135 } else {
136 if (test) log.println("... OK");
139 ok &= test;
140 test = false;
141 exp = false;
142 try {
143 log.println("try to add following property:\n" +
144 "\t('IllegalTypeProperty', com.sun.star.beans.PropertyAttribute.MAYBEVOID, Any.VOID) ...");
145 oObj.addProperty("IllegalTypeProperty", com.sun.star.beans.PropertyAttribute.MAYBEVOID, Any.VOID);
146 } catch (com.sun.star.lang.IllegalArgumentException ex) {
147 log.println("ERROR: wrong Exception was thrown while adding following property: " +
148 "'', com.sun.star.beans.PropertyAttribute.MAYBEVOID, null\n" +
149 "Expected: 'IllegalTypeException'\n" +
150 "Got: 'IllegalArgumentException\n" +
151 ex.toString());
152 log.println("... FAILED");
153 exp = true;
154 } catch (PropertyExistException ex) {
155 log.println("ERROR: wrong Exception was thrown while adding following property: " +
156 "'', com.sun.star.beans.PropertyAttribute.MAYBEVOID, null\n" +
157 "Expected: 'IllegalArgumentException'\n" +
158 "Got: 'PropertyExistException\n" +
159 ex.toString());
160 log.println("... FAILED");
161 exp = true;
162 } catch (IllegalTypeException ex) {
163 log.println("OK: expected Exception was thrown." + ex.toString());
164 test = true;
165 exp = true;
168 if (! exp){
169 log.println("FAILED: expected exception 'IllegalTypeException' was not thrown");
170 } else {
171 if (test) log.println("... OK");
174 ok &= test;
175 test = false;
176 exp = false;
177 try {
178 short attrib = -1;
179 log.println("add following property:\n" +
180 "'', -1, new Object");
181 oObj.addProperty("", attrib, null);
182 } catch (com.sun.star.lang.IllegalArgumentException ex) {
183 log.println("OK: expected Exception was thrown." + ex.toString());
184 test = true;
185 exp = true;
186 } catch (PropertyExistException ex) {
187 log.println("ERROR: wrong Exception was thrown while adding following property: " +
188 "'invalidPropertyAttribute', -1, null\n" +
189 "Expected: 'IllegalTypeException'\n" +
190 "Got: 'PropertyExistException\n" +
191 ex.toString());
192 log.println("... FAILED");
193 exp = true;
194 } catch (IllegalTypeException ex) {
195 log.println("ERROR: unexpected Exception was thrown while adding following property: " +
196 "'', -1, null\n" +
197 "Expected: 'IllegalArgumentException'\n" +
198 "Got: 'IllegalTypeException\n" +
199 ex.toString());
200 log.println("... FAILED");
201 exp = true;
204 if (! exp){
205 log.println("FAILED: expected exception 'IllegalArgumentException' was not thrown");
206 } else {
207 if (test) log.println("... OK");
210 ok &= test;
212 tRes.tested("addProperty()", ok );
213 return;
217 * Test calls the method and checks if the returned sequence contanis a propterty which is named
218 * in the object relation <code>XPropertyAccess.propertyNotRemovable</code>.
220 public void _removeProperty() {
222 requiredMethod("addProperty()");
224 boolean ok = true;
225 boolean test = true;
226 boolean exp = false;
228 try {
229 log.println("remove 'myXPropertContainerProperty'");
230 oObj.removeProperty("myXPropertContainerProperty");
231 } catch (NotRemoveableException ex) {
232 log.println("ERROR: could not remote property 'myXPropertContainerProperty'" + ex.toString());
233 log.println("... FAILED");
234 test = false;
235 } catch (UnknownPropertyException ex) {
236 log.println("ERROR: could not remote property 'myXPropertContainerProperty'" + ex.toString());
237 log.println("... FAILED");
238 test = false;
240 if ( test){
241 log.println("... OK");
244 ok &= test;
245 test = false;
246 exp=false;
248 try {
249 log.println("remove not removable property '" + propertyNotRemovable + "'") ;
250 oObj.removeProperty(propertyNotRemovable);
251 } catch (NotRemoveableException ex) {
252 log.println("OK: expected Exception was thrown: " + ex.toString());
253 test = true;
254 exp = true;
255 } catch (UnknownPropertyException ex) {
256 log.println("ERROR: wrong exception was thrown.\n" +
257 "Expected: 'NotRemoveableException'\n" +
258 "Got: 'UnknownPropertyException'\n" +
259 ex.toString());
260 log.println("... FAILED");
261 exp = true;
264 if (! exp){
265 log.println("FAILED: expected exception 'NotRemoveableException' was not thrown");
266 } else {
267 if (test) log.println("... OK");
270 ok &= test;
271 test = false;
272 exp = false;
274 try {
275 log.println("remove property 'thisPropertyDoesNotExist'");
276 oObj.removeProperty("thisPropertyDoesNotExist");
277 } catch (UnknownPropertyException ex) {
278 log.println("OK: expected Exception was thrown: " + ex.toString());
279 test = true;
280 exp = true;
281 } catch (NotRemoveableException ex) {
282 log.println("ERROR: wrong exception was thrown.\n" +
283 "Expected: 'UnknownPropertyException'\n" +
284 "Got: 'NotRemoveableException\n" +
285 ex.toString());
286 log.println("... FAILED");
287 exp = true;
289 if (! exp){
290 log.println("FAILED: expected exception 'UnknownPropertyException' was not thrown");
291 } else {
292 if (test) log.println("... OK");
295 tRes.tested("removeProperty()", ok );
296 return;
300 } /// finish class XPropertyContainer