1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 package ifc.beans; 25 26 import com.sun.star.beans.IllegalTypeException; 27 import com.sun.star.beans.NotRemoveableException; 28 import com.sun.star.beans.PropertyExistException; 29 import com.sun.star.uno.Any; 30 import lib.MultiMethodTest; 31 import com.sun.star.beans.UnknownPropertyException; 32 import com.sun.star.beans.XPropertyContainer; 33 import lib.Status; 34 import lib.StatusException; 35 36 /** 37 * Testing <code>com.sun.star.beans.XPropertyAccess</code> 38 * interface methods : 39 * <ul> 40 * <li><code>addProperty()</code></li> 41 * <li><code>removeProperty()</code></li> 42 * </ul> 43 * @see com.sun.star.beans.XPropertyAccess 44 */ 45 public class _XPropertyContainer extends MultiMethodTest { 46 47 /** 48 * oObj filled by MultiMethodTest 49 */ 50 public XPropertyContainer oObj = null;// oObj filled by MultiMethodTest 51 52 /** 53 * object relation X<CODE>PropertyAccess.propertyNotRemovable</CODE><br> 54 * This relation must be filled from the module. It contains a property which must 55 * be a property of the implementaion object. 56 */ 57 private String propertyNotRemovable = null; 58 59 /** 60 * checks if the object relation <CODE>XPropertyAccess.propertyNotRemovable</CODE> 61 * is available 62 */ before()63 public void before() { 64 propertyNotRemovable = (String) tEnv.getObjRelation("XPropertyContainer.propertyNotRemovable"); 65 if (propertyNotRemovable == null) { 66 throw new StatusException(Status.failed("Object raltion 'XPropertyAccess.propertyNotRemovable' is null")); 67 } 68 } 69 70 71 72 /** 73 * Test calls the method and checks if the returned sequence contanis a propterty which is named 74 * in the object relation <code>XPropertyAccess.propertyNotRemovable</code>. 75 */ _addProperty()76 public void _addProperty() { 77 78 boolean ok = true; 79 boolean test = true; 80 boolean exp = false; 81 82 try { 83 log.println("try to add following property:\n" + 84 "\t('myXPropertContainerProperty', com.sun.star.beans.PropertyAttribute.MAYBEVOID, null) ..."); 85 oObj.addProperty("myXPropertContainerProperty" , com.sun.star.beans.PropertyAttribute.MAYBEVOID, null); 86 } catch (com.sun.star.lang.IllegalArgumentException ex) { 87 log.println("ERROR: Exception was thrown while adding following property: " + 88 "('myXPropertContainerProperty', com.sun.star.beans.PropertyAttribute.MAYBEVOID, null) : " + 89 ex.toString()); 90 log.println("... FAILED"); 91 test = false; 92 } catch (PropertyExistException ex) { 93 log.println("ERROR: Exception was thrown while adding following property: " + 94 "('myXPropertContainerProperty', com.sun.star.beans.PropertyAttribute.MAYBEVOID, null) : " + 95 ex.toString()); 96 log.println("... FAILED"); 97 test = false; 98 } catch (IllegalTypeException ex) { 99 log.println("ERROR: Exception was thrown while adding following property: " + 100 "('myXPropertContainerProperty', com.sun.star.beans.PropertyAttribute.MAYBEVOID, null) : " + 101 ex.toString()); 102 log.println("... FAILED"); 103 test = false; 104 } 105 106 if ( test){ 107 log.println("... OK"); 108 } 109 110 ok &= test; 111 test = false; 112 exp = false; 113 try { 114 log.println("add following property second time:\n" + 115 "\t('myXPropertContainerProperty', com.sun.star.beans.PropertyAttribute.MAYBEVOID, null) ..."); 116 oObj.addProperty("myXPropertContainerProperty" , com.sun.star.beans.PropertyAttribute.MAYBEVOID, null); 117 } catch (com.sun.star.lang.IllegalArgumentException ex) { 118 log.println("ERROR: wrong Exception was thrown while adding following property: " + 119 "('myXPropertContainerProperty', com.sun.star.beans.PropertyAttribute.MAYBEVOID, null) : " + 120 "Expected: 'PropertyExistException'\n" + 121 "Got: 'IllegalArgumentException\n" + 122 ex.toString()); 123 log.println("... FAILED"); 124 exp = true; 125 } catch (PropertyExistException ex) { 126 log.println("OK: expected Exception was thrown." + ex.toString()); 127 test = true; 128 exp = true; 129 } catch (IllegalTypeException ex) { 130 log.println("ERROR: wrong Exception was thrown while adding following property: " + 131 "('myXPropertContainerProperty', com.sun.star.beans.PropertyAttribute.MAYBEVOID, null) : " + 132 "Expected: 'PropertyExistException'\n" + 133 "Got: 'IllegalTypeException\n" + 134 ex.toString()); 135 log.println("... FAILED"); 136 exp = true; 137 } 138 if (! exp){ 139 log.println("FAILED: expected exception 'UnknownPropertyException' was not thrown"); 140 } else { 141 if (test) log.println("... OK"); 142 } 143 144 ok &= test; 145 test = false; 146 exp = false; 147 try { 148 log.println("try to add following property:\n" + 149 "\t('IllegalTypeProperty', com.sun.star.beans.PropertyAttribute.MAYBEVOID, Any.VOID) ..."); 150 oObj.addProperty("IllegalTypeProperty", com.sun.star.beans.PropertyAttribute.MAYBEVOID, Any.VOID); 151 } catch (com.sun.star.lang.IllegalArgumentException ex) { 152 log.println("ERROR: wrong Exception was thrown while adding following property: " + 153 "'', com.sun.star.beans.PropertyAttribute.MAYBEVOID, null\n" + 154 "Expected: 'IllegalTypeException'\n" + 155 "Got: 'IllegalArgumentException\n" + 156 ex.toString()); 157 log.println("... FAILED"); 158 exp = true; 159 } catch (PropertyExistException ex) { 160 log.println("ERROR: wrong Exception was thrown while adding following property: " + 161 "'', com.sun.star.beans.PropertyAttribute.MAYBEVOID, null\n" + 162 "Expected: 'IllegalArgumentException'\n" + 163 "Got: 'PropertyExistException\n" + 164 ex.toString()); 165 log.println("... FAILED"); 166 exp = true; 167 } catch (IllegalTypeException ex) { 168 log.println("OK: expected Exception was thrown." + ex.toString()); 169 test = true; 170 exp = true; 171 } 172 173 if (! exp){ 174 log.println("FAILED: expected exception 'IllegalTypeException' was not thrown"); 175 } else { 176 if (test) log.println("... OK"); 177 } 178 179 ok &= test; 180 test = false; 181 exp = false; 182 try { 183 short attrib = -1; 184 log.println("add following property:\n" + 185 "'', -1, new Object"); 186 oObj.addProperty("", attrib, null); 187 } catch (com.sun.star.lang.IllegalArgumentException ex) { 188 log.println("OK: expected Exception was thrown." + ex.toString()); 189 test = true; 190 exp = true; 191 } catch (PropertyExistException ex) { 192 log.println("ERROR: wrong Exception was thrown while adding following property: " + 193 "'invalidPropertyAttribute', -1, null\n" + 194 "Expected: 'IllegalTypeException'\n" + 195 "Got: 'PropertyExistException\n" + 196 ex.toString()); 197 log.println("... FAILED"); 198 exp = true; 199 } catch (IllegalTypeException ex) { 200 log.println("ERROR: unexpected Exception was thrown while adding following property: " + 201 "'', -1, null\n" + 202 "Expected: 'IllegalArgumentException'\n" + 203 "Got: 'IllegalTypeException\n" + 204 ex.toString()); 205 log.println("... FAILED"); 206 exp = true; 207 } 208 209 if (! exp){ 210 log.println("FAILED: expected exception 'IllegalArgumentException' was not thrown"); 211 } else { 212 if (test) log.println("... OK"); 213 } 214 215 ok &= test; 216 217 tRes.tested("addProperty()", ok ); 218 return; 219 } 220 221 /** 222 * Test calls the method and checks if the returned sequence contanis a propterty which is named 223 * in the object relation <code>XPropertyAccess.propertyNotRemovable</code>. 224 */ _removeProperty()225 public void _removeProperty() { 226 227 requiredMethod("addProperty()"); 228 229 boolean ok = true; 230 boolean test = true; 231 boolean exp = false; 232 233 try { 234 log.println("remove 'myXPropertContainerProperty'"); 235 oObj.removeProperty("myXPropertContainerProperty"); 236 } catch (NotRemoveableException ex) { 237 log.println("ERROR: could not remote property 'myXPropertContainerProperty'" + ex.toString()); 238 log.println("... FAILED"); 239 test = false; 240 } catch (UnknownPropertyException ex) { 241 log.println("ERROR: could not remote property 'myXPropertContainerProperty'" + ex.toString()); 242 log.println("... FAILED"); 243 test = false; 244 } 245 if ( test){ 246 log.println("... OK"); 247 } 248 249 ok &= test; 250 test = false; 251 exp=false; 252 253 try { 254 log.println("remove not removeable property '" + propertyNotRemovable + "'") ; 255 oObj.removeProperty(propertyNotRemovable); 256 } catch (NotRemoveableException ex) { 257 log.println("OK: expected Exception was thrown: " + ex.toString()); 258 test = true; 259 exp = true; 260 } catch (UnknownPropertyException ex) { 261 log.println("ERROR: wrong exception was thrown.\n" + 262 "Expected: 'NotRemoveableException'\n" + 263 "Got: 'UnknownPropertyException'\n" + 264 ex.toString()); 265 log.println("... FAILED"); 266 exp = true; 267 } 268 269 if (! exp){ 270 log.println("FAILED: expected exception 'NotRemoveableException' was not thrown"); 271 } else { 272 if (test) log.println("... OK"); 273 } 274 275 ok &= test; 276 test = false; 277 exp = false; 278 279 try { 280 log.println("remove property 'thisPropertyDoesNotExist'"); 281 oObj.removeProperty("thisPropertyDoesNotExist"); 282 } catch (UnknownPropertyException ex) { 283 log.println("OK: expected Exception was thrown: " + ex.toString()); 284 test = true; 285 exp = true; 286 } catch (NotRemoveableException ex) { 287 log.println("ERROR: wrong exception was thrown.\n" + 288 "Expected: 'UnknownPropertyException'\n" + 289 "Got: 'NotRemoveableException\n" + 290 ex.toString()); 291 log.println("... FAILED"); 292 exp = true; 293 } 294 if (! exp){ 295 log.println("FAILED: expected exception 'UnknownPropertyException' was not thrown"); 296 } else { 297 if (test) log.println("... OK"); 298 } 299 300 tRes.tested("removeProperty()", ok ); 301 return; 302 } 303 304 305 } /// finish class XPropertyContainer 306