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