Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / qadevOOo / tests / java / ifc / beans / _XPropertyAccess.java
blob37b835431b8da90c0a9ddd77b435ea5997dfa8e7
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
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.
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).
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.
26 ************************************************************************/
28 package ifc.beans;
30 import com.sun.star.beans.PropertyValue;
31 import com.sun.star.beans.PropertyVetoException;
32 import com.sun.star.lang.WrappedTargetException;
33 import lib.MultiMethodTest;
34 import com.sun.star.beans.UnknownPropertyException;
35 import com.sun.star.beans.XPropertyAccess;
36 import lib.Status;
37 import lib.StatusException;
39 /**
40 * Testing <code>com.sun.star.beans.XPropertyAccess</code>
41 * interface methods :
42 * <ul>
43 * <li><code>getPropertyValues()</code></li>
44 * <li><code>setPropertyValues()</code></li>
45 * </ul>
46 * @see com.sun.star.beans.XPropertyAccess
48 public class _XPropertyAccess extends MultiMethodTest {
50 /**
51 * oObj filled by MultiMethodTest
53 public XPropertyAccess oObj = null;// oObj filled by MultiMethodTest
55 /**
56 * object relation X<CODE>PropertyAccess.propertyToChange</CODE><br>
57 * This relation must be filled from the module. It contains a property which must
58 * be kind of String property, available at <CODE>getPropertyValues()</CODE> and changeable by
59 * <CODE>setPropertyValues()</CODE>
61 public PropertyValue propertyToChange = null;
63 /**
64 * checks if the object relation <CODE>XPropertyAccess.propertyToChange</CODE>
65 * is available
67 public void before() {
68 propertyToChange = (PropertyValue) tEnv.getObjRelation("XPropertyAccess.propertyToChange");
69 if (propertyToChange == null) {
70 throw new StatusException(Status.failed("Object raltion 'XPropertyAccess.propertyToChange' is null"));
74 /**
75 * Test calls the method and checks if the returned sequenze contanis a propterty which is named
76 * in the object relation <code>XPropertyAccess.propertyToChange</code>.
78 public void _getPropertyValues() {
79 PropertyValue[] properties = oObj.getPropertyValues();
81 boolean ok = true;
83 if (properties != null){
85 boolean found = false;
86 for (int i=0; i < properties.length; i++){
87 if (properties[i].Name.equals(propertyToChange.Name)) found = true;
89 if (! found){
90 log.println("ERROR: could not find desired property '"+ propertyToChange.Name+"'");
91 ok=false;
94 } else {
95 log.println("ERROR: the method returned NULL");
96 ok =false;
99 tRes.tested("getPropertyValues()", ok );
100 return;
104 * Test calls the method and checks if:
105 * <ul>
106 * <li>the property given by the object relation
107 * <CODE>XPropertyAccess.propertyToChange</CODE> has changed</LI>
108 * <li><CODE>com.sun.star.lang.IllegalArgumentException</CODE> was thrown if a <CODE>Integer</CODE>
109 * value was set to a <CODE>String</CODE> property</LI>
110 * <li><CODE>com.sun.star.beans.UnknownPropertyException</CODE> was throen if an invalid property
111 * was set</LI>
112 * </ul>
114 public void _setPropertyValues(){
116 boolean ok = true;
117 boolean test = true;
118 boolean exp = false;
120 try {
121 PropertyValue[] newProps = new PropertyValue[1];
122 newProps[0] = propertyToChange;
124 log.println("try to set property vlaues given by object relation 'XPropertyAccess.propertyToChange'...");
125 oObj.setPropertyValues(newProps);
127 } catch (UnknownPropertyException ex) {
128 log.println("ERROR: Exception was thrown while trying to set property value: " +
129 ex.toString());
130 test = false;
131 } catch (PropertyVetoException ex) {
132 log.println("ERROR: Exception was thrown while trying to set property value: " +
133 ex.toString());
134 test = false;
135 } catch (WrappedTargetException ex) {
136 log.println("ERROR: Exception was thrown while trying to set property value: " +
137 ex.toString());
138 test = false;
139 } catch (com.sun.star.lang.IllegalArgumentException ex) {
140 log.println("ERROR: Exception was thrown while trying to set property value: " +
141 ex.toString());
142 test = false;
145 if ( test){
146 log.println("... OK");
149 ok &= test;
150 test = false;
151 exp = false;
152 try {
153 log.println("try to set integer value to string property, " +
154 "expect 'com.sun.star.lang.IllegalArgumentException'...");
155 PropertyValue[] newProps = new PropertyValue[1];
156 PropertyValue failedProp = new PropertyValue();
157 failedProp.Name = propertyToChange.Name;
158 failedProp.Value = new Integer(10);
159 newProps[0] = failedProp;
160 oObj.setPropertyValues(newProps);
161 } catch (PropertyVetoException ex) {
162 log.println("ERROR: unexptected exception was thrown while trying to set null value: " +
163 ex.toString());
164 exp = true;
165 } catch (WrappedTargetException ex) {
166 log.println("ERROR: unexptected exception was thrown while trying to set null value: " +
167 ex.toString());
168 exp = true;
169 } catch (com.sun.star.lang.IllegalArgumentException ex) {
170 log.println("OK: exptected exception was thrown while trying to set null value: " +
171 ex.toString());
172 test = true;
173 exp = true;
174 } catch (UnknownPropertyException ex) {
175 log.println("ERROR: unexptected exception was thrown while trying to set null value: " +
176 ex.toString());
177 exp = true;
180 if (! exp){
181 log.println("FAILED: expected exception 'UnknownPropertyException' was not thrown");
182 } else {
183 if (test) log.println("... OK");
186 ok &= test;
187 test = false;
188 exp = false;
189 try {
191 log.println("try to set values with invalid property name. " +
192 "Expect 'com.sun.star.beans.UnknownPropertyException'...");
194 PropertyValue[] newProps = new PropertyValue[1];
195 PropertyValue newProp = new PropertyValue();
196 newProp.Name = "XPropertyAccess.InvalidPropertyName";
197 newProp.Value = "invalid property";
198 newProps[0] = newProp;
200 oObj.setPropertyValues(newProps);
202 } catch (WrappedTargetException ex) {
203 log.println("ERROR: unexptected exception was thrown while trying to set invalid value: " +
204 ex.toString());
205 exp = true;
206 } catch (com.sun.star.lang.IllegalArgumentException ex) {
207 log.println("ERROR: unexptected exception was thrown while trying to set invalid value: " +
208 ex.toString());
209 exp = true;
210 } catch (PropertyVetoException ex) {
211 log.println("ERROR: unexptected exception was thrown while trying to set invalid value: " +
212 ex.toString());
213 exp = true;
214 } catch (UnknownPropertyException ex) {
215 log.println("OK: Exptected exception was thrown while trying to set invalid value: " +
216 ex.toString());
217 exp = true;
218 test = true;
221 ok &= test;
223 if (! exp){
224 log.println("FAILED: expected exception 'UnknownPropertyException' was not thrown");
225 } else {
226 if (test) log.println("... OK");
229 tRes.tested("setPropertyValues()", ok);
230 return;
234 } /// finish class XPropertyAccess