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 implementaion object.
52 private String propertyNotRemovable
= null;
55 * checks if the object relation <CODE>XPropertyAccess.propertyNotRemovable</CODE>
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"));
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() {
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) : " +
85 log
.println("... FAILED");
87 } catch (PropertyExistException ex
) {
88 log
.println("ERROR: Exception was thrown while adding following property: " +
89 "('myXPropertContainerProperty', com.sun.star.beans.PropertyAttribute.MAYBEVOID, null) : " +
91 log
.println("... FAILED");
93 } catch (IllegalTypeException ex
) {
94 log
.println("ERROR: Exception was thrown while adding following property: " +
95 "('myXPropertContainerProperty', com.sun.star.beans.PropertyAttribute.MAYBEVOID, null) : " +
97 log
.println("... FAILED");
102 log
.println("... OK");
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" +
118 log
.println("... FAILED");
120 } catch (PropertyExistException ex
) {
121 log
.println("OK: expected Exception was thrown." + ex
.toString());
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" +
130 log
.println("... FAILED");
134 log
.println("FAILED: expected exception 'UnknownPropertyException' was not thrown");
136 if (test
) log
.println("... OK");
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" +
152 log
.println("... FAILED");
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" +
160 log
.println("... FAILED");
162 } catch (IllegalTypeException ex
) {
163 log
.println("OK: expected Exception was thrown." + ex
.toString());
169 log
.println("FAILED: expected exception 'IllegalTypeException' was not thrown");
171 if (test
) log
.println("... OK");
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());
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" +
192 log
.println("... FAILED");
194 } catch (IllegalTypeException ex
) {
195 log
.println("ERROR: unexpected Exception was thrown while adding following property: " +
197 "Expected: 'IllegalArgumentException'\n" +
198 "Got: 'IllegalTypeException\n" +
200 log
.println("... FAILED");
205 log
.println("FAILED: expected exception 'IllegalArgumentException' was not thrown");
207 if (test
) log
.println("... OK");
212 tRes
.tested("addProperty()", ok
);
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()");
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
);
300 } /// finish class XPropertyContainer