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