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