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 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
;
29 import lib
.StatusException
;
32 * Testing <code>com.sun.star.beans.XPropertyAccess</code>
35 * <li><code>addProperty()</code></li>
36 * <li><code>removeProperty()</code></li>
38 * @see com.sun.star.beans.XPropertyAccess
40 public class _XPropertyContainer
extends MultiMethodTest
{
43 * oObj filled by MultiMethodTest
45 public XPropertyContainer oObj
= null;// oObj filled by MultiMethodTest
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 implementation object.
52 private String propertyNotRemovable
= null;
55 * checks if the object relation <CODE>XPropertyAccess.propertyNotRemovable</CODE>
59 public void before() {
60 propertyNotRemovable
= (String
) tEnv
.getObjRelation("XPropertyContainer.propertyNotRemovable");
61 if (propertyNotRemovable
== null) {
62 throw new StatusException(Status
.failed("Object raltion 'XPropertyAccess.propertyNotRemovable' is null"));
69 * Test calls the method and checks if the returned sequence contains a property which is named
70 * in the object relation <code>XPropertyAccess.propertyNotRemovable</code>.
72 public void _addProperty() {
79 log
.println("try to add following property:\n" +
80 "\t('myXPropertContainerProperty', com.sun.star.beans.PropertyAttribute.MAYBEVOID, null) ...");
81 oObj
.addProperty("myXPropertContainerProperty" , com
.sun
.star
.beans
.PropertyAttribute
.MAYBEVOID
, null);
82 } catch (com
.sun
.star
.lang
.IllegalArgumentException ex
) {
83 log
.println("ERROR: Exception was thrown while adding following property: " +
84 "('myXPropertContainerProperty', com.sun.star.beans.PropertyAttribute.MAYBEVOID, null) : " +
86 log
.println("... FAILED");
88 } catch (PropertyExistException ex
) {
89 log
.println("ERROR: Exception was thrown while adding following property: " +
90 "('myXPropertContainerProperty', com.sun.star.beans.PropertyAttribute.MAYBEVOID, null) : " +
92 log
.println("... FAILED");
94 } catch (IllegalTypeException ex
) {
95 log
.println("ERROR: Exception was thrown while adding following property: " +
96 "('myXPropertContainerProperty', com.sun.star.beans.PropertyAttribute.MAYBEVOID, null) : " +
98 log
.println("... FAILED");
103 log
.println("... OK");
110 log
.println("add following property second time:\n" +
111 "\t('myXPropertContainerProperty', com.sun.star.beans.PropertyAttribute.MAYBEVOID, null) ...");
112 oObj
.addProperty("myXPropertContainerProperty" , com
.sun
.star
.beans
.PropertyAttribute
.MAYBEVOID
, null);
113 } catch (com
.sun
.star
.lang
.IllegalArgumentException ex
) {
114 log
.println("ERROR: wrong Exception was thrown while adding following property: " +
115 "('myXPropertContainerProperty', com.sun.star.beans.PropertyAttribute.MAYBEVOID, null) : " +
116 "Expected: 'PropertyExistException'\n" +
117 "Got: 'IllegalArgumentException\n" +
119 log
.println("... FAILED");
121 } catch (PropertyExistException ex
) {
122 log
.println("OK: expected Exception was thrown." + ex
.toString());
125 } catch (IllegalTypeException ex
) {
126 log
.println("ERROR: wrong Exception was thrown while adding following property: " +
127 "('myXPropertContainerProperty', com.sun.star.beans.PropertyAttribute.MAYBEVOID, null) : " +
128 "Expected: 'PropertyExistException'\n" +
129 "Got: 'IllegalTypeException\n" +
131 log
.println("... FAILED");
135 log
.println("FAILED: expected exception 'UnknownPropertyException' was not thrown");
137 if (test
) log
.println("... OK");
144 log
.println("try to add following property:\n" +
145 "\t('IllegalTypeProperty', com.sun.star.beans.PropertyAttribute.MAYBEVOID, Any.VOID) ...");
146 oObj
.addProperty("IllegalTypeProperty", com
.sun
.star
.beans
.PropertyAttribute
.MAYBEVOID
, Any
.VOID
);
147 } catch (com
.sun
.star
.lang
.IllegalArgumentException ex
) {
148 log
.println("ERROR: wrong Exception was thrown while adding following property: " +
149 "'', com.sun.star.beans.PropertyAttribute.MAYBEVOID, null\n" +
150 "Expected: 'IllegalTypeException'\n" +
151 "Got: 'IllegalArgumentException\n" +
153 log
.println("... FAILED");
155 } catch (PropertyExistException ex
) {
156 log
.println("ERROR: wrong Exception was thrown while adding following property: " +
157 "'', com.sun.star.beans.PropertyAttribute.MAYBEVOID, null\n" +
158 "Expected: 'IllegalArgumentException'\n" +
159 "Got: 'PropertyExistException\n" +
161 log
.println("... FAILED");
163 } catch (IllegalTypeException ex
) {
164 log
.println("OK: expected Exception was thrown." + ex
.toString());
170 log
.println("FAILED: expected exception 'IllegalTypeException' was not thrown");
172 if (test
) log
.println("... OK");
180 log
.println("add following property:\n" +
181 "'', -1, new Object");
182 oObj
.addProperty("", attrib
, null);
183 } catch (com
.sun
.star
.lang
.IllegalArgumentException ex
) {
184 log
.println("OK: expected Exception was thrown." + ex
.toString());
187 } catch (PropertyExistException ex
) {
188 log
.println("ERROR: wrong Exception was thrown while adding following property: " +
189 "'invalidPropertyAttribute', -1, null\n" +
190 "Expected: 'IllegalTypeException'\n" +
191 "Got: 'PropertyExistException\n" +
193 log
.println("... FAILED");
195 } catch (IllegalTypeException ex
) {
196 log
.println("ERROR: unexpected Exception was thrown while adding following property: " +
198 "Expected: 'IllegalArgumentException'\n" +
199 "Got: 'IllegalTypeException\n" +
201 log
.println("... FAILED");
206 log
.println("FAILED: expected exception 'IllegalArgumentException' was not thrown");
208 if (test
) log
.println("... OK");
213 tRes
.tested("addProperty()", ok
);
217 * Test calls the method and checks if the returned sequence contains a property which is named
218 * in the object relation <code>XPropertyAccess.propertyNotRemovable</code>.
220 public void _removeProperty() {
222 requiredMethod("addProperty()");
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");
235 } catch (UnknownPropertyException ex
) {
236 log
.println("ERROR: could not remote property 'myXPropertContainerProperty'" + ex
.toString());
237 log
.println("... FAILED");
241 log
.println("... OK");
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());
255 } catch (UnknownPropertyException ex
) {
256 log
.println("ERROR: wrong exception was thrown.\n" +
257 "Expected: 'NotRemoveableException'\n" +
258 "Got: 'UnknownPropertyException'\n" +
260 log
.println("... FAILED");
265 log
.println("FAILED: expected exception 'NotRemoveableException' was not thrown");
267 if (test
) log
.println("... OK");
275 log
.println("remove property 'thisPropertyDoesNotExist'");
276 oObj
.removeProperty("thisPropertyDoesNotExist");
277 } catch (UnknownPropertyException ex
) {
278 log
.println("OK: expected Exception was thrown: " + ex
.toString());
281 } catch (NotRemoveableException ex
) {
282 log
.println("ERROR: wrong exception was thrown.\n" +
283 "Expected: 'UnknownPropertyException'\n" +
284 "Got: 'NotRemoveableException\n" +
286 log
.println("... FAILED");
290 log
.println("FAILED: expected exception 'UnknownPropertyException' was not thrown");
292 if (test
) log
.println("... OK");
295 tRes
.tested("removeProperty()", ok
);
299 } /// finish class XPropertyContainer