Avoid potential negative array index access to cached text.
[LibreOffice.git] / qadevOOo / tests / java / ifc / beans / _XPropertyContainer.java
blob00fcff66f09f350f7292caf7a0f4455c531e5005
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 implementation object.
52 private String propertyNotRemovable = null;
54 /**
55 * checks if the object relation <CODE>XPropertyAccess.propertyNotRemovable</CODE>
56 * is available
58 @Override
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"));
68 /**
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() {
74 boolean ok = true;
75 boolean test = true;
76 boolean exp = false;
78 try {
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) : " +
85 ex.toString());
86 log.println("... FAILED");
87 test = false;
88 } catch (PropertyExistException ex) {
89 log.println("ERROR: Exception was thrown while adding following property: " +
90 "('myXPropertContainerProperty', com.sun.star.beans.PropertyAttribute.MAYBEVOID, null) : " +
91 ex.toString());
92 log.println("... FAILED");
93 test = false;
94 } catch (IllegalTypeException ex) {
95 log.println("ERROR: Exception was thrown while adding following property: " +
96 "('myXPropertContainerProperty', com.sun.star.beans.PropertyAttribute.MAYBEVOID, null) : " +
97 ex.toString());
98 log.println("... FAILED");
99 test = false;
102 if ( test){
103 log.println("... OK");
106 ok &= test;
107 test = false;
108 exp = false;
109 try {
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" +
118 ex.toString());
119 log.println("... FAILED");
120 exp = true;
121 } catch (PropertyExistException ex) {
122 log.println("OK: expected Exception was thrown." + ex.toString());
123 test = true;
124 exp = true;
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" +
130 ex.toString());
131 log.println("... FAILED");
132 exp = true;
134 if (! exp){
135 log.println("FAILED: expected exception 'UnknownPropertyException' was not thrown");
136 } else {
137 if (test) log.println("... OK");
140 ok &= test;
141 test = false;
142 exp = false;
143 try {
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" +
152 ex.toString());
153 log.println("... FAILED");
154 exp = true;
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" +
160 ex.toString());
161 log.println("... FAILED");
162 exp = true;
163 } catch (IllegalTypeException ex) {
164 log.println("OK: expected Exception was thrown." + ex.toString());
165 test = true;
166 exp = true;
169 if (! exp){
170 log.println("FAILED: expected exception 'IllegalTypeException' was not thrown");
171 } else {
172 if (test) log.println("... OK");
175 ok &= test;
176 test = false;
177 exp = false;
178 try {
179 short attrib = -1;
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());
185 test = true;
186 exp = true;
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" +
192 ex.toString());
193 log.println("... FAILED");
194 exp = true;
195 } catch (IllegalTypeException ex) {
196 log.println("ERROR: unexpected Exception was thrown while adding following property: " +
197 "'', -1, null\n" +
198 "Expected: 'IllegalArgumentException'\n" +
199 "Got: 'IllegalTypeException\n" +
200 ex.toString());
201 log.println("... FAILED");
202 exp = true;
205 if (! exp){
206 log.println("FAILED: expected exception 'IllegalArgumentException' was not thrown");
207 } else {
208 if (test) log.println("... OK");
211 ok &= test;
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()");
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 );
299 } /// finish class XPropertyContainer