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