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 java.util.Vector;
31*cdf0e10cSrcweir 
32*cdf0e10cSrcweir import lib.MultiMethodTest;
33*cdf0e10cSrcweir import util.ValueChanger;
34*cdf0e10cSrcweir import util.utils;
35*cdf0e10cSrcweir 
36*cdf0e10cSrcweir import com.sun.star.beans.Property;
37*cdf0e10cSrcweir import com.sun.star.beans.PropertyAttribute;
38*cdf0e10cSrcweir import com.sun.star.beans.PropertyChangeEvent;
39*cdf0e10cSrcweir import com.sun.star.beans.XPropertyChangeListener;
40*cdf0e10cSrcweir import com.sun.star.beans.XPropertySet;
41*cdf0e10cSrcweir import com.sun.star.beans.XPropertySetInfo;
42*cdf0e10cSrcweir import com.sun.star.beans.XVetoableChangeListener;
43*cdf0e10cSrcweir import com.sun.star.lang.EventObject;
44*cdf0e10cSrcweir 
45*cdf0e10cSrcweir /**
46*cdf0e10cSrcweir * Testing <code>com.sun.star.beans.XPropertySet</code>
47*cdf0e10cSrcweir * interface methods :
48*cdf0e10cSrcweir * <ul>
49*cdf0e10cSrcweir *  <li><code>getPropertySetInfo()</code></li>
50*cdf0e10cSrcweir *  <li><code>setPropertyValue()</code></li>
51*cdf0e10cSrcweir *  <li><code>getPropertyValue()</code></li>
52*cdf0e10cSrcweir *  <li><code>addPropertyChangeListener()</code></li>
53*cdf0e10cSrcweir *  <li><code>removePropertyChangeListener()</code></li>
54*cdf0e10cSrcweir *  <li><code>addVetoableChangeListener()</code></li>
55*cdf0e10cSrcweir *  <li><code>removeVetoableChangeListener()</code></li>
56*cdf0e10cSrcweir * </ul>
57*cdf0e10cSrcweir * @see com.sun.star.beans.XPropertySet
58*cdf0e10cSrcweir */
59*cdf0e10cSrcweir public class _XPropertySet extends MultiMethodTest {
60*cdf0e10cSrcweir 
61*cdf0e10cSrcweir     public XPropertySet oObj = null;
62*cdf0e10cSrcweir 
63*cdf0e10cSrcweir     /**
64*cdf0e10cSrcweir     * Flag that indicates change listener was called.
65*cdf0e10cSrcweir     */
66*cdf0e10cSrcweir     private boolean propertyChanged = false;
67*cdf0e10cSrcweir 
68*cdf0e10cSrcweir     /**
69*cdf0e10cSrcweir     * Listener that must be called on bound property changing.
70*cdf0e10cSrcweir     */
71*cdf0e10cSrcweir     public class MyChangeListener implements XPropertyChangeListener {
72*cdf0e10cSrcweir          /**
73*cdf0e10cSrcweir          * Just set <code>propertyChanged</code> flag to true.
74*cdf0e10cSrcweir          */
75*cdf0e10cSrcweir          public void propertyChange(PropertyChangeEvent e) {
76*cdf0e10cSrcweir             propertyChanged = true;
77*cdf0e10cSrcweir          }
78*cdf0e10cSrcweir          public void disposing (EventObject obj) {}
79*cdf0e10cSrcweir     };
80*cdf0e10cSrcweir 
81*cdf0e10cSrcweir     private final XPropertyChangeListener PClistener = new MyChangeListener();
82*cdf0e10cSrcweir 
83*cdf0e10cSrcweir     /**
84*cdf0e10cSrcweir     * Flag that indicates veto listener was called.
85*cdf0e10cSrcweir     */
86*cdf0e10cSrcweir     private boolean vetoableChanged = false;
87*cdf0e10cSrcweir 
88*cdf0e10cSrcweir     /**
89*cdf0e10cSrcweir     * Listener that must be called on constrained property changing.
90*cdf0e10cSrcweir     */
91*cdf0e10cSrcweir     public class MyVetoListener implements XVetoableChangeListener {
92*cdf0e10cSrcweir          /**
93*cdf0e10cSrcweir          * Just set <code>vetoableChanged</code> flag to true.
94*cdf0e10cSrcweir          */
95*cdf0e10cSrcweir          public void vetoableChange(PropertyChangeEvent e) {
96*cdf0e10cSrcweir             vetoableChanged = true;
97*cdf0e10cSrcweir          }
98*cdf0e10cSrcweir          public void disposing (EventObject obj) {}
99*cdf0e10cSrcweir     };
100*cdf0e10cSrcweir 
101*cdf0e10cSrcweir     private final XVetoableChangeListener VClistener = new MyVetoListener();
102*cdf0e10cSrcweir 
103*cdf0e10cSrcweir     /**
104*cdf0e10cSrcweir     * Structure that collects the properties of different types to test :
105*cdf0e10cSrcweir     * Constrained, Bound and Normal.
106*cdf0e10cSrcweir     */
107*cdf0e10cSrcweir     private final class PropsToTest {
108*cdf0e10cSrcweir         Vector< String > constrained = new Vector< String >();
109*cdf0e10cSrcweir         Vector< String > bound = new Vector< String >();
110*cdf0e10cSrcweir         Vector< String > normal = new Vector< String >();
111*cdf0e10cSrcweir     }
112*cdf0e10cSrcweir 
113*cdf0e10cSrcweir     private final PropsToTest PTT = new PropsToTest();
114*cdf0e10cSrcweir 
115*cdf0e10cSrcweir     /**
116*cdf0e10cSrcweir     * Tests method <code>getPropertySetInfo</code>. After test completed
117*cdf0e10cSrcweir     * call {@link #getPropsToTest} method to retrieve different kinds
118*cdf0e10cSrcweir     * of properties to test then. <p>
119*cdf0e10cSrcweir     * Has OK status if not null <code>XPropertySetInfo</code>
120*cdf0e10cSrcweir     * object returned.<p>
121*cdf0e10cSrcweir     * Since <code>getPropertySetInfo</code> is optional, it may return null,
122*cdf0e10cSrcweir     * if it is not implemented. This method uses then an object relation
123*cdf0e10cSrcweir     * <code>PTT</code> (Properties To Test) to determine available properties.
124*cdf0e10cSrcweir     * All tests for services without <code>getPropertySetInfo</code> must
125*cdf0e10cSrcweir     * provide this object relation.
126*cdf0e10cSrcweir     */
127*cdf0e10cSrcweir     public void _getPropertySetInfo() {
128*cdf0e10cSrcweir 
129*cdf0e10cSrcweir         XPropertySetInfo propertySetInfo = oObj.getPropertySetInfo();
130*cdf0e10cSrcweir 
131*cdf0e10cSrcweir         if (propertySetInfo == null) {
132*cdf0e10cSrcweir             log.println("getPropertySetInfo() method returned null");
133*cdf0e10cSrcweir             tRes.tested("getPropertySetInfo()", true) ;
134*cdf0e10cSrcweir             String[] ptt = (String[]) tEnv.getObjRelation("PTT");
135*cdf0e10cSrcweir             PTT.normal.clear();
136*cdf0e10cSrcweir             PTT.bound.clear();
137*cdf0e10cSrcweir             PTT.constrained.clear();
138*cdf0e10cSrcweir             PTT.normal.add( ptt[0] );
139*cdf0e10cSrcweir             PTT.bound.add( ptt[1] );
140*cdf0e10cSrcweir             PTT.constrained.add( ptt[2] );
141*cdf0e10cSrcweir         } else {
142*cdf0e10cSrcweir             tRes.tested("getPropertySetInfo()", true );
143*cdf0e10cSrcweir             getPropsToTest(propertySetInfo);
144*cdf0e10cSrcweir         }
145*cdf0e10cSrcweir 
146*cdf0e10cSrcweir         return;
147*cdf0e10cSrcweir 
148*cdf0e10cSrcweir     } // end of getPropertySetInfo()
149*cdf0e10cSrcweir 
150*cdf0e10cSrcweir     /**
151*cdf0e10cSrcweir     * Tests change listener which added for bound properties.
152*cdf0e10cSrcweir     * Adds listener to bound property (if it exists), then changes
153*cdf0e10cSrcweir     * its value and check if listener was called. <p>
154*cdf0e10cSrcweir     * Method tests to be successfully completed before :
155*cdf0e10cSrcweir     * <ul>
156*cdf0e10cSrcweir     *  <li> <code>getPropertySetInfo</code> : in this method test
157*cdf0e10cSrcweir     *    one of bound properties is retrieved. </li>
158*cdf0e10cSrcweir     * </ul> <p>
159*cdf0e10cSrcweir     * Has OK status if NO bound properties exist or if listener
160*cdf0e10cSrcweir     * was successfully called.
161*cdf0e10cSrcweir     */
162*cdf0e10cSrcweir     public void _addPropertyChangeListener() {
163*cdf0e10cSrcweir 
164*cdf0e10cSrcweir         requiredMethod("getPropertySetInfo()");
165*cdf0e10cSrcweir 
166*cdf0e10cSrcweir         int count = PTT.bound.size();
167*cdf0e10cSrcweir         if ( count==0 || PTT.bound.get(0).equals("none") ) {
168*cdf0e10cSrcweir             log.println("*** No bound properties found ***");
169*cdf0e10cSrcweir             tRes.tested("addPropertyChangeListener()", true) ;
170*cdf0e10cSrcweir         } else {
171*cdf0e10cSrcweir             boolean error = false;
172*cdf0e10cSrcweir             for (int i = 0; i < count; i++) {
173*cdf0e10cSrcweir                 String propertyName = PTT.bound.get(i);
174*cdf0e10cSrcweir                 propertyChanged = false;
175*cdf0e10cSrcweir                 try {
176*cdf0e10cSrcweir                     oObj.addPropertyChangeListener(propertyName,PClistener);
177*cdf0e10cSrcweir                     Object gValue = oObj.getPropertyValue(propertyName);
178*cdf0e10cSrcweir                     log.println("Check bound property: " + propertyName );
179*cdf0e10cSrcweir                     oObj.setPropertyValue(propertyName,
180*cdf0e10cSrcweir                         ValueChanger.changePValue(gValue));
181*cdf0e10cSrcweir                 } catch (com.sun.star.beans.PropertyVetoException e) {
182*cdf0e10cSrcweir                     log.println("Exception occured while trying to change "+
183*cdf0e10cSrcweir                         "property '"+ propertyName+"'");
184*cdf0e10cSrcweir                     e.printStackTrace(log);
185*cdf0e10cSrcweir                 } catch (com.sun.star.lang.IllegalArgumentException e) {
186*cdf0e10cSrcweir                     log.println("Exception occured while trying to change "+
187*cdf0e10cSrcweir                         "property '"+ propertyName+"'");
188*cdf0e10cSrcweir                     e.printStackTrace(log);
189*cdf0e10cSrcweir                 } catch (com.sun.star.beans.UnknownPropertyException e) {
190*cdf0e10cSrcweir                     log.println("Exception occured while trying to change "+
191*cdf0e10cSrcweir                         "property '"+ propertyName+"'");
192*cdf0e10cSrcweir                     e.printStackTrace(log);
193*cdf0e10cSrcweir                 } catch (com.sun.star.lang.WrappedTargetException e) {
194*cdf0e10cSrcweir                     log.println("Exception occured while trying to change "+
195*cdf0e10cSrcweir                         "property '"+ propertyName+"'");
196*cdf0e10cSrcweir                     e.printStackTrace(log);
197*cdf0e10cSrcweir                 } // end of try-catch
198*cdf0e10cSrcweir                 error = error || !propertyChanged;
199*cdf0e10cSrcweir                 if (!propertyChanged) {
200*cdf0e10cSrcweir                     log.println("propertyChangeListener wasn't called for '"+
201*cdf0e10cSrcweir                         propertyName+"'");
202*cdf0e10cSrcweir                 }
203*cdf0e10cSrcweir             }
204*cdf0e10cSrcweir             tRes.tested("addPropertyChangeListener()", !error);
205*cdf0e10cSrcweir         }
206*cdf0e10cSrcweir 
207*cdf0e10cSrcweir         return;
208*cdf0e10cSrcweir 
209*cdf0e10cSrcweir     } // end of addPropertyChangeListener()
210*cdf0e10cSrcweir 
211*cdf0e10cSrcweir     /**
212*cdf0e10cSrcweir     * Tests vetoable listener which added for constrained properties.
213*cdf0e10cSrcweir     * Adds listener to constrained property (if it exists), then changes
214*cdf0e10cSrcweir     * its value and check if listener was called. <p>
215*cdf0e10cSrcweir     * Method tests to be successfully completed before :
216*cdf0e10cSrcweir     * <ul>
217*cdf0e10cSrcweir     *  <li> <code>getPropertySetInfo</code> : in this method test
218*cdf0e10cSrcweir     *    one of constrained properties is retrieved. </li>
219*cdf0e10cSrcweir     * </ul> <p>
220*cdf0e10cSrcweir     * Has OK status if NO constrained properties exist or if listener
221*cdf0e10cSrcweir     * was successfully called.
222*cdf0e10cSrcweir     */
223*cdf0e10cSrcweir     public void _addVetoableChangeListener() {
224*cdf0e10cSrcweir 
225*cdf0e10cSrcweir         requiredMethod("getPropertySetInfo()");
226*cdf0e10cSrcweir 
227*cdf0e10cSrcweir         int count = PTT.constrained.size();
228*cdf0e10cSrcweir         if ( count==0 || PTT.constrained.get(0).equals("none") ) {
229*cdf0e10cSrcweir             log.println("*** No constrained properties found ***");
230*cdf0e10cSrcweir             tRes.tested("addVetoableChangeListener()", true) ;
231*cdf0e10cSrcweir         } else {
232*cdf0e10cSrcweir             boolean error = false;
233*cdf0e10cSrcweir             for (int i = 0; i < count; i++) {
234*cdf0e10cSrcweir                 String propertyName = PTT.constrained.get(i);
235*cdf0e10cSrcweir                 vetoableChanged = false;
236*cdf0e10cSrcweir                 try {
237*cdf0e10cSrcweir                     oObj.addVetoableChangeListener(propertyName,VClistener);
238*cdf0e10cSrcweir                     Object gValue = oObj.getPropertyValue(propertyName);
239*cdf0e10cSrcweir                     oObj.setPropertyValue(propertyName,
240*cdf0e10cSrcweir                         ValueChanger.changePValue(gValue));
241*cdf0e10cSrcweir                 } catch (com.sun.star.beans.PropertyVetoException e) {
242*cdf0e10cSrcweir                     log.println("Exception occured while trying to change "+
243*cdf0e10cSrcweir                         "property '"+ propertyName+"'");
244*cdf0e10cSrcweir                     e.printStackTrace(log);
245*cdf0e10cSrcweir                 } catch (com.sun.star.lang.IllegalArgumentException e) {
246*cdf0e10cSrcweir                     log.println("Exception occured while trying to change "+
247*cdf0e10cSrcweir                         "property '"+ propertyName+"'");
248*cdf0e10cSrcweir                     e.printStackTrace(log);
249*cdf0e10cSrcweir                 } catch (com.sun.star.beans.UnknownPropertyException e) {
250*cdf0e10cSrcweir                     log.println("Exception occured while trying to change "+
251*cdf0e10cSrcweir                         "property '"+ propertyName+"'");
252*cdf0e10cSrcweir                     e.printStackTrace(log);
253*cdf0e10cSrcweir                 } catch (com.sun.star.lang.WrappedTargetException e) {
254*cdf0e10cSrcweir                     log.println("Exception occured while trying to change "+
255*cdf0e10cSrcweir                         "property '"+ propertyName+"'");
256*cdf0e10cSrcweir                     e.printStackTrace(log);
257*cdf0e10cSrcweir                 } // end of try-catch
258*cdf0e10cSrcweir                 error = error || !vetoableChanged;
259*cdf0e10cSrcweir                 if (!vetoableChanged) {
260*cdf0e10cSrcweir                     log.println("vetoableChangeListener wasn't called for '"+
261*cdf0e10cSrcweir                         propertyName+"'");
262*cdf0e10cSrcweir                 }
263*cdf0e10cSrcweir             }
264*cdf0e10cSrcweir             tRes.tested("addVetoableChangeListener()",!error);
265*cdf0e10cSrcweir         }
266*cdf0e10cSrcweir 
267*cdf0e10cSrcweir         return;
268*cdf0e10cSrcweir 
269*cdf0e10cSrcweir     } // end of addVetoableChangeListener()
270*cdf0e10cSrcweir 
271*cdf0e10cSrcweir 
272*cdf0e10cSrcweir     /**
273*cdf0e10cSrcweir     * Tests <code>setPropertyValue</code> method.
274*cdf0e10cSrcweir     * Stores value before call, and compares it with value after
275*cdf0e10cSrcweir     * call. <p>
276*cdf0e10cSrcweir     * Method tests to be successfully completed before :
277*cdf0e10cSrcweir     * <ul>
278*cdf0e10cSrcweir     *  <li> <code>getPropertySetInfo</code> : in this method test
279*cdf0e10cSrcweir     *    one of normal properties is retrieved. </li>
280*cdf0e10cSrcweir     * </ul> <p>
281*cdf0e10cSrcweir     * Has OK status if NO normal properties exist or if value before
282*cdf0e10cSrcweir     * method call is not equal to value after.
283*cdf0e10cSrcweir     */
284*cdf0e10cSrcweir     public void _setPropertyValue() {
285*cdf0e10cSrcweir 
286*cdf0e10cSrcweir         requiredMethod("getPropertySetInfo()");
287*cdf0e10cSrcweir 
288*cdf0e10cSrcweir         Object gValue = null;
289*cdf0e10cSrcweir         Object sValue = null;
290*cdf0e10cSrcweir 
291*cdf0e10cSrcweir         int count = PTT.normal.size();
292*cdf0e10cSrcweir         if ( count==0 || PTT.normal.get(0).equals("none") ) {
293*cdf0e10cSrcweir             log.println("*** No changeable properties found ***");
294*cdf0e10cSrcweir             tRes.tested("setPropertyValue()", true) ;
295*cdf0e10cSrcweir         } else {
296*cdf0e10cSrcweir             boolean error = false;
297*cdf0e10cSrcweir             for (int i = 0; i < count; i++) {
298*cdf0e10cSrcweir                 String propertyName = PTT.normal.get(i);
299*cdf0e10cSrcweir                 try {
300*cdf0e10cSrcweir                     log.println("try to change value of property '" + propertyName + "'" );
301*cdf0e10cSrcweir                     gValue = oObj.getPropertyValue(propertyName);
302*cdf0e10cSrcweir                     sValue = ValueChanger.changePValue(gValue);
303*cdf0e10cSrcweir                     oObj.setPropertyValue(propertyName, sValue);
304*cdf0e10cSrcweir                     sValue = oObj.getPropertyValue(propertyName);
305*cdf0e10cSrcweir                 } catch (com.sun.star.beans.PropertyVetoException e) {
306*cdf0e10cSrcweir                     log.println("Exception occured while trying to change "+
307*cdf0e10cSrcweir                         "property '"+ propertyName+"'");
308*cdf0e10cSrcweir                     e.printStackTrace(log);
309*cdf0e10cSrcweir                 } catch (com.sun.star.lang.IllegalArgumentException e) {
310*cdf0e10cSrcweir                     log.println("Exception occured while trying to change "+
311*cdf0e10cSrcweir                         "property '"+ propertyName+"'");
312*cdf0e10cSrcweir                     e.printStackTrace(log);
313*cdf0e10cSrcweir                 } catch (com.sun.star.beans.UnknownPropertyException e) {
314*cdf0e10cSrcweir                     log.println("Exception occured while trying to change "+
315*cdf0e10cSrcweir                         "property '"+ propertyName+"'");
316*cdf0e10cSrcweir                     e.printStackTrace(log);
317*cdf0e10cSrcweir                 } catch (com.sun.star.lang.WrappedTargetException e) {
318*cdf0e10cSrcweir                     log.println("Exception occured while trying to change "+
319*cdf0e10cSrcweir                         "property '"+ propertyName+"'");
320*cdf0e10cSrcweir                     e.printStackTrace(log);
321*cdf0e10cSrcweir                 } // end of try-catch
322*cdf0e10cSrcweir                 if( gValue.equals(sValue) )
323*cdf0e10cSrcweir                 {
324*cdf0e10cSrcweir                     log.println("setting property '"+ propertyName+"' failed");
325*cdf0e10cSrcweir                     error = true;
326*cdf0e10cSrcweir                 }
327*cdf0e10cSrcweir             }
328*cdf0e10cSrcweir             tRes.tested("setPropertyValue()",!error);
329*cdf0e10cSrcweir         } //endif
330*cdf0e10cSrcweir 
331*cdf0e10cSrcweir         return;
332*cdf0e10cSrcweir 
333*cdf0e10cSrcweir     } // end of setPropertyValue()
334*cdf0e10cSrcweir 
335*cdf0e10cSrcweir     /**
336*cdf0e10cSrcweir     * Tests <code>getPropertyValue</code> method for the given property.
337*cdf0e10cSrcweir     * Returns true if no exceptions occured
338*cdf0e10cSrcweir     */
339*cdf0e10cSrcweir     private boolean getSinglePropertyValue( String propertyName )
340*cdf0e10cSrcweir     {
341*cdf0e10cSrcweir         boolean runOk = false;
342*cdf0e10cSrcweir         try {
343*cdf0e10cSrcweir             oObj.getPropertyValue(propertyName);
344*cdf0e10cSrcweir             runOk = true;
345*cdf0e10cSrcweir         } catch (com.sun.star.beans.UnknownPropertyException e) {
346*cdf0e10cSrcweir             log.println("Exception occured while trying to get property '"+
347*cdf0e10cSrcweir                  propertyName+"'");
348*cdf0e10cSrcweir             e.printStackTrace(log);
349*cdf0e10cSrcweir         } catch (com.sun.star.lang.WrappedTargetException e) {
350*cdf0e10cSrcweir             log.println("Exception occured while trying to get property '"+
351*cdf0e10cSrcweir                 propertyName+"'");
352*cdf0e10cSrcweir             e.printStackTrace(log);
353*cdf0e10cSrcweir         }
354*cdf0e10cSrcweir         return runOk;
355*cdf0e10cSrcweir     }
356*cdf0e10cSrcweir 
357*cdf0e10cSrcweir     /**
358*cdf0e10cSrcweir     * Tests <code>getPropertyValue</code> method.
359*cdf0e10cSrcweir     * Just call this method and checks for no exceptions <p>
360*cdf0e10cSrcweir     * Method tests to be successfully completed before :
361*cdf0e10cSrcweir     * <ul>
362*cdf0e10cSrcweir     *  <li> <code>getPropertySetInfo</code> : in this method test
363*cdf0e10cSrcweir     *    one of normal properties is retrieved. </li>
364*cdf0e10cSrcweir     * </ul> <p>
365*cdf0e10cSrcweir     * Has OK status if NO normal properties exist or if no
366*cdf0e10cSrcweir     * exceptions were thrown.
367*cdf0e10cSrcweir     */
368*cdf0e10cSrcweir     public void _getPropertyValue() {
369*cdf0e10cSrcweir 
370*cdf0e10cSrcweir         requiredMethod("getPropertySetInfo()");
371*cdf0e10cSrcweir 
372*cdf0e10cSrcweir         int count = PTT.normal.size();
373*cdf0e10cSrcweir         if ( count==0 || PTT.normal.get(0).equals("none") ) {
374*cdf0e10cSrcweir             Property[] properties = oObj.getPropertySetInfo().getProperties();
375*cdf0e10cSrcweir             if( properties.length > 0 ) {
376*cdf0e10cSrcweir                 String propertyName = properties[0].Name;
377*cdf0e10cSrcweir                 log.println("All properties are Read Only");
378*cdf0e10cSrcweir                 log.println("Using: "+propertyName);
379*cdf0e10cSrcweir                 tRes.tested("getPropertyValue()", getSinglePropertyValue( propertyName ) );
380*cdf0e10cSrcweir             }
381*cdf0e10cSrcweir             else {
382*cdf0e10cSrcweir                 log.println("*** No properties found ***");
383*cdf0e10cSrcweir                 tRes.tested("getPropertyValue()", true) ;
384*cdf0e10cSrcweir             }
385*cdf0e10cSrcweir         } else {
386*cdf0e10cSrcweir             boolean error = false;
387*cdf0e10cSrcweir             for (int i = 0; i < count; i++) {
388*cdf0e10cSrcweir                 String propertyName = PTT.normal.get(i);
389*cdf0e10cSrcweir                 boolean runOk = getSinglePropertyValue( propertyName );
390*cdf0e10cSrcweir                 if( !runOk )
391*cdf0e10cSrcweir                 {
392*cdf0e10cSrcweir                     error = true;
393*cdf0e10cSrcweir                     log.println("getPropertyValue() failed for property '"+propertyName+"'");
394*cdf0e10cSrcweir                 }
395*cdf0e10cSrcweir             }
396*cdf0e10cSrcweir             tRes.tested("getPropertyValue()", !error) ;
397*cdf0e10cSrcweir         }
398*cdf0e10cSrcweir 
399*cdf0e10cSrcweir         return;
400*cdf0e10cSrcweir     }
401*cdf0e10cSrcweir 
402*cdf0e10cSrcweir     /**
403*cdf0e10cSrcweir     * Tests <code>removePropertyChangeListener</code> method.
404*cdf0e10cSrcweir     * Removes change listener, then changes bound property value
405*cdf0e10cSrcweir     * and checks if the listener was NOT called.
406*cdf0e10cSrcweir     * Method tests to be successfully completed before :
407*cdf0e10cSrcweir     * <ul>
408*cdf0e10cSrcweir     *  <li> <code>addPropertyChangeListener</code> : here listener
409*cdf0e10cSrcweir     *   was added. </li>
410*cdf0e10cSrcweir     * </ul> <p>
411*cdf0e10cSrcweir     * Has OK status if NO bound properties exist or if listener
412*cdf0e10cSrcweir     * was not called and no exceptions arose.
413*cdf0e10cSrcweir     */
414*cdf0e10cSrcweir     public void _removePropertyChangeListener() {
415*cdf0e10cSrcweir 
416*cdf0e10cSrcweir         requiredMethod("addPropertyChangeListener()");
417*cdf0e10cSrcweir 
418*cdf0e10cSrcweir         int count = PTT.bound.size();
419*cdf0e10cSrcweir         if ( count==0 || PTT.bound.get(0).equals("none") ) {
420*cdf0e10cSrcweir             log.println("*** No bound properties found ***");
421*cdf0e10cSrcweir             tRes.tested("removePropertyChangeListener()", true) ;
422*cdf0e10cSrcweir         } else {
423*cdf0e10cSrcweir 
424*cdf0e10cSrcweir             //remove all listeners first
425*cdf0e10cSrcweir             for (int i = 0; i < count; i++) {
426*cdf0e10cSrcweir                 String propertyName = PTT.bound.get(i);
427*cdf0e10cSrcweir                 try {
428*cdf0e10cSrcweir                     oObj.removePropertyChangeListener(propertyName,PClistener);
429*cdf0e10cSrcweir                 } catch (Exception e) {
430*cdf0e10cSrcweir                     log.println("Exception occured while removing change listener from"+
431*cdf0e10cSrcweir                         "property '"+ propertyName+"'");
432*cdf0e10cSrcweir                     e.printStackTrace(log);
433*cdf0e10cSrcweir                 }
434*cdf0e10cSrcweir             }
435*cdf0e10cSrcweir 
436*cdf0e10cSrcweir             boolean error = false;
437*cdf0e10cSrcweir             for (int i = 0; i < count; i++) {
438*cdf0e10cSrcweir                 String propertyName = PTT.bound.get(i);
439*cdf0e10cSrcweir                 try {
440*cdf0e10cSrcweir                     propertyChanged = false;
441*cdf0e10cSrcweir                     oObj.addPropertyChangeListener(propertyName,PClistener);
442*cdf0e10cSrcweir                     oObj.removePropertyChangeListener(propertyName,PClistener);
443*cdf0e10cSrcweir                     Object gValue = oObj.getPropertyValue(propertyName);
444*cdf0e10cSrcweir                     oObj.setPropertyValue(propertyName,
445*cdf0e10cSrcweir                         ValueChanger.changePValue(gValue));
446*cdf0e10cSrcweir                 } catch (com.sun.star.beans.PropertyVetoException e) {
447*cdf0e10cSrcweir                     log.println("Exception occured while trying to change "+
448*cdf0e10cSrcweir                         "property '"+ propertyName+"'");
449*cdf0e10cSrcweir                     e.printStackTrace(log);
450*cdf0e10cSrcweir                 } catch (com.sun.star.lang.IllegalArgumentException e) {
451*cdf0e10cSrcweir                     log.println("Exception occured while trying to change "+
452*cdf0e10cSrcweir                         "property '"+ propertyName+"'");
453*cdf0e10cSrcweir                     e.printStackTrace(log);
454*cdf0e10cSrcweir                 } catch (com.sun.star.beans.UnknownPropertyException e) {
455*cdf0e10cSrcweir                     log.println("Exception occured while trying to change "+
456*cdf0e10cSrcweir                         "property '"+ propertyName+"'");
457*cdf0e10cSrcweir                     e.printStackTrace(log);
458*cdf0e10cSrcweir                 } catch (com.sun.star.lang.WrappedTargetException e) {
459*cdf0e10cSrcweir                     log.println("Exception occured while trying to change "+
460*cdf0e10cSrcweir                         "property '"+ propertyName+"'");
461*cdf0e10cSrcweir                     e.printStackTrace(log);
462*cdf0e10cSrcweir                 } // end of try-catch
463*cdf0e10cSrcweir 
464*cdf0e10cSrcweir                 error = error || propertyChanged;
465*cdf0e10cSrcweir                 if (propertyChanged) {
466*cdf0e10cSrcweir                     log.println("propertyChangeListener was called after removing"+
467*cdf0e10cSrcweir                         " for '"+propertyName+"'");
468*cdf0e10cSrcweir                 }
469*cdf0e10cSrcweir             }
470*cdf0e10cSrcweir             tRes.tested("removePropertyChangeListener()",!error);
471*cdf0e10cSrcweir         }
472*cdf0e10cSrcweir 
473*cdf0e10cSrcweir         return;
474*cdf0e10cSrcweir 
475*cdf0e10cSrcweir     } // end of removePropertyChangeListener()
476*cdf0e10cSrcweir 
477*cdf0e10cSrcweir 
478*cdf0e10cSrcweir     /**
479*cdf0e10cSrcweir     * Tests <code>removeVetoableChangeListener</code> method.
480*cdf0e10cSrcweir     * Removes vetoable listener, then changes constrained property value
481*cdf0e10cSrcweir     * and checks if the listener was NOT called.
482*cdf0e10cSrcweir     * Method tests to be successfully completed before :
483*cdf0e10cSrcweir     * <ul>
484*cdf0e10cSrcweir     *  <li> <code>addPropertyChangeListener</code> : here vetoable listener
485*cdf0e10cSrcweir     *   was added. </li>
486*cdf0e10cSrcweir     * </ul> <p>
487*cdf0e10cSrcweir     * Has OK status if NO constrained properties exist or if listener
488*cdf0e10cSrcweir     * was NOT called and no exceptions arose.
489*cdf0e10cSrcweir     */
490*cdf0e10cSrcweir     public void _removeVetoableChangeListener() {
491*cdf0e10cSrcweir 
492*cdf0e10cSrcweir         requiredMethod("addVetoableChangeListener()");
493*cdf0e10cSrcweir 
494*cdf0e10cSrcweir         int count = PTT.constrained.size();
495*cdf0e10cSrcweir         if ( count==0 || PTT.constrained.get(0).equals("none") ) {
496*cdf0e10cSrcweir             log.println("*** No constrained properties found ***");
497*cdf0e10cSrcweir             tRes.tested("removeVetoableChangeListener()", true) ;
498*cdf0e10cSrcweir         } else {
499*cdf0e10cSrcweir 
500*cdf0e10cSrcweir             //remove all listeners first
501*cdf0e10cSrcweir             for (int i = 0; i < count; i++) {
502*cdf0e10cSrcweir                 String propertyName = PTT.constrained.get(i);
503*cdf0e10cSrcweir                 try {
504*cdf0e10cSrcweir                     oObj.removeVetoableChangeListener(propertyName,VClistener);
505*cdf0e10cSrcweir                 } catch (Exception e) {
506*cdf0e10cSrcweir                     log.println("Exception occured while removing veto listener from"+
507*cdf0e10cSrcweir                         "property '"+ propertyName+"'");
508*cdf0e10cSrcweir                     e.printStackTrace(log);
509*cdf0e10cSrcweir                 }
510*cdf0e10cSrcweir             }
511*cdf0e10cSrcweir 
512*cdf0e10cSrcweir             boolean error = false;
513*cdf0e10cSrcweir             for (int i = 0; i < count; i++) {
514*cdf0e10cSrcweir                 String propertyName = PTT.constrained.get(i);
515*cdf0e10cSrcweir                 vetoableChanged = false;
516*cdf0e10cSrcweir                 try {
517*cdf0e10cSrcweir                     oObj.addVetoableChangeListener(propertyName,VClistener);
518*cdf0e10cSrcweir                     oObj.removeVetoableChangeListener(propertyName,VClistener);
519*cdf0e10cSrcweir                     Object gValue = oObj.getPropertyValue(propertyName);
520*cdf0e10cSrcweir                     oObj.setPropertyValue(propertyName,
521*cdf0e10cSrcweir                         ValueChanger.changePValue(gValue));
522*cdf0e10cSrcweir                 } catch (com.sun.star.beans.PropertyVetoException e) {
523*cdf0e10cSrcweir                     log.println("Exception occured while trying to change "+
524*cdf0e10cSrcweir                         "property '"+ propertyName+"'");
525*cdf0e10cSrcweir                     e.printStackTrace(log);
526*cdf0e10cSrcweir                 } catch (com.sun.star.lang.IllegalArgumentException e) {
527*cdf0e10cSrcweir                     log.println("Exception occured while trying to change "+
528*cdf0e10cSrcweir                         "property '"+ propertyName+"'");
529*cdf0e10cSrcweir                     e.printStackTrace(log);
530*cdf0e10cSrcweir                 } catch (com.sun.star.beans.UnknownPropertyException e) {
531*cdf0e10cSrcweir                     log.println("Exception occured while trying to change "+
532*cdf0e10cSrcweir                         "property '"+ propertyName+"'");
533*cdf0e10cSrcweir                     e.printStackTrace(log);
534*cdf0e10cSrcweir                 } catch (com.sun.star.lang.WrappedTargetException e) {
535*cdf0e10cSrcweir                     log.println("Exception occured while trying to change "+
536*cdf0e10cSrcweir                         "property '"+ propertyName+"'");
537*cdf0e10cSrcweir                     e.printStackTrace(log);
538*cdf0e10cSrcweir                 } // end of try-catch
539*cdf0e10cSrcweir                 error = error || vetoableChanged;
540*cdf0e10cSrcweir                 if (vetoableChanged) {
541*cdf0e10cSrcweir                     log.println("vetoableChangeListener was called after "+
542*cdf0e10cSrcweir                         "removing for '"+propertyName+"'");
543*cdf0e10cSrcweir                 }
544*cdf0e10cSrcweir             }
545*cdf0e10cSrcweir             tRes.tested("removeVetoableChangeListener()",!error);
546*cdf0e10cSrcweir         }
547*cdf0e10cSrcweir 
548*cdf0e10cSrcweir         return;
549*cdf0e10cSrcweir 
550*cdf0e10cSrcweir     } // end of removeVetoableChangeListener()
551*cdf0e10cSrcweir 
552*cdf0e10cSrcweir     /**
553*cdf0e10cSrcweir     * Gets the properties being tested. Searches and stores by one
554*cdf0e10cSrcweir     * property of each kind (Bound, Vetoable, Normal).
555*cdf0e10cSrcweir     */
556*cdf0e10cSrcweir     public void getPropsToTest(XPropertySetInfo xPSI) {
557*cdf0e10cSrcweir 
558*cdf0e10cSrcweir         Property[] properties = xPSI.getProperties();
559*cdf0e10cSrcweir         // some properties should not be changed in a unspecific way
560*cdf0e10cSrcweir         String[] skip = {"PrinterName", "CharRelief", "IsLayerMode"};
561*cdf0e10cSrcweir 
562*cdf0e10cSrcweir         for (int i = 0; i < properties.length; i++) {
563*cdf0e10cSrcweir 
564*cdf0e10cSrcweir             Property property = properties[i];
565*cdf0e10cSrcweir             String name = property.Name;
566*cdf0e10cSrcweir 
567*cdf0e10cSrcweir             boolean cont = false;
568*cdf0e10cSrcweir             for (int j = 0; j < skip.length; j++) {
569*cdf0e10cSrcweir                 if (name.equals(skip[j])){
570*cdf0e10cSrcweir                     log.println("skipping '" + name + "'");
571*cdf0e10cSrcweir                     cont = true;
572*cdf0e10cSrcweir                 }
573*cdf0e10cSrcweir             }
574*cdf0e10cSrcweir 
575*cdf0e10cSrcweir             if (cont) continue;
576*cdf0e10cSrcweir 
577*cdf0e10cSrcweir             if (name.equals(oObj))
578*cdf0e10cSrcweir             log.println("Checking '"+name+"'");
579*cdf0e10cSrcweir             boolean isWritable = ((property.Attributes &
580*cdf0e10cSrcweir                 PropertyAttribute.READONLY) == 0);
581*cdf0e10cSrcweir             boolean isNotNull = ((property.Attributes &
582*cdf0e10cSrcweir                 PropertyAttribute.MAYBEVOID) == 0);
583*cdf0e10cSrcweir             boolean isBound = ((property.Attributes &
584*cdf0e10cSrcweir                 PropertyAttribute.BOUND) != 0);
585*cdf0e10cSrcweir             boolean isConstr = ((property.Attributes &
586*cdf0e10cSrcweir                 PropertyAttribute.CONSTRAINED) != 0);
587*cdf0e10cSrcweir             boolean canChange = false;
588*cdf0e10cSrcweir 
589*cdf0e10cSrcweir             if ( !isWritable ) log.println("Property '"+name+"' is READONLY");
590*cdf0e10cSrcweir 
591*cdf0e10cSrcweir             if (name.endsWith("URL")) isWritable = false;
592*cdf0e10cSrcweir             if (name.startsWith("Fill")) isWritable = false;
593*cdf0e10cSrcweir             if (name.startsWith("Font")) isWritable = false;
594*cdf0e10cSrcweir             if (name.startsWith("IsNumbering")) isWritable = false;
595*cdf0e10cSrcweir             if (name.startsWith("LayerName")) isWritable = false;
596*cdf0e10cSrcweir             if (name.startsWith("Line")) isWritable = false;
597*cdf0e10cSrcweir             if (name.startsWith("TextWriting")) isWritable = false;
598*cdf0e10cSrcweir 
599*cdf0e10cSrcweir             //if (name.equals("xinterfaceA") || name.equals("xtypeproviderA")
600*cdf0e10cSrcweir             //|| name.equals("arAnyA")) isWritable=false;
601*cdf0e10cSrcweir 
602*cdf0e10cSrcweir             if ( isWritable && isNotNull ) canChange = isChangeable(name);
603*cdf0e10cSrcweir 
604*cdf0e10cSrcweir             if ( isWritable && isNotNull && isBound && canChange) {
605*cdf0e10cSrcweir                 PTT.bound.add(name);
606*cdf0e10cSrcweir             }
607*cdf0e10cSrcweir 
608*cdf0e10cSrcweir             if ( isWritable && isNotNull && isConstr && canChange) {
609*cdf0e10cSrcweir                 PTT.constrained.add(name);
610*cdf0e10cSrcweir             }
611*cdf0e10cSrcweir 
612*cdf0e10cSrcweir             if ( isWritable && isNotNull && canChange) {
613*cdf0e10cSrcweir                 PTT.normal.add(name);
614*cdf0e10cSrcweir             }
615*cdf0e10cSrcweir 
616*cdf0e10cSrcweir 
617*cdf0e10cSrcweir         } // endfor
618*cdf0e10cSrcweir     }
619*cdf0e10cSrcweir 
620*cdf0e10cSrcweir     public boolean isChangeable(String name) {
621*cdf0e10cSrcweir         boolean hasChanged = false;
622*cdf0e10cSrcweir         try {
623*cdf0e10cSrcweir             Object getProp = oObj.getPropertyValue(name);
624*cdf0e10cSrcweir             log.println("Getting: "+getProp);
625*cdf0e10cSrcweir             if (name.equals("xinterfaceA")) {
626*cdf0e10cSrcweir                 System.out.println("drin");
627*cdf0e10cSrcweir             }
628*cdf0e10cSrcweir 
629*cdf0e10cSrcweir             Object setValue = null;
630*cdf0e10cSrcweir             if (getProp != null) {
631*cdf0e10cSrcweir                 if (!utils.isVoid(getProp))
632*cdf0e10cSrcweir                     setValue = ValueChanger.changePValue(getProp);
633*cdf0e10cSrcweir                 else log.println("Property '"+name+
634*cdf0e10cSrcweir                     "' is void but MAYBEVOID isn't set");
635*cdf0e10cSrcweir             } else log.println("Property '"+name+"'is null and can't be changed");
636*cdf0e10cSrcweir             if (name.equals("LineStyle")) setValue = null;
637*cdf0e10cSrcweir             if (setValue != null) {
638*cdf0e10cSrcweir                 log.println("Setting to :"+setValue);
639*cdf0e10cSrcweir                 oObj.setPropertyValue(name, setValue);
640*cdf0e10cSrcweir                 hasChanged = (! getProp.equals(oObj.getPropertyValue(name)));
641*cdf0e10cSrcweir             } else log.println("Couldn't change Property '"+name+"'");
642*cdf0e10cSrcweir         } catch (com.sun.star.beans.PropertyVetoException e) {
643*cdf0e10cSrcweir             log.println("'" + name + "' throws exception '" + e + "'");
644*cdf0e10cSrcweir             e.printStackTrace(log);
645*cdf0e10cSrcweir         } catch (com.sun.star.lang.IllegalArgumentException e) {
646*cdf0e10cSrcweir             log.println("'" + name + "' throws exception '" + e + "'");
647*cdf0e10cSrcweir             e.printStackTrace(log);
648*cdf0e10cSrcweir         } catch (com.sun.star.beans.UnknownPropertyException e) {
649*cdf0e10cSrcweir             log.println("'" + name + "' throws exception '" + e + "'");
650*cdf0e10cSrcweir             e.printStackTrace(log);
651*cdf0e10cSrcweir         } catch (com.sun.star.lang.WrappedTargetException e) {
652*cdf0e10cSrcweir             log.println("'" + name + "' throws exception '" + e + "'");
653*cdf0e10cSrcweir             e.printStackTrace(log);
654*cdf0e10cSrcweir         } catch (com.sun.star.uno.RuntimeException e) {
655*cdf0e10cSrcweir             log.println("'" + name + "' throws exception '" + e + "'");
656*cdf0e10cSrcweir             e.printStackTrace(log);
657*cdf0e10cSrcweir         } catch (java.lang.ArrayIndexOutOfBoundsException e) {
658*cdf0e10cSrcweir             log.println("'" + name + "' throws exception '" + e + "'");
659*cdf0e10cSrcweir             e.printStackTrace(log);
660*cdf0e10cSrcweir         }
661*cdf0e10cSrcweir 
662*cdf0e10cSrcweir         return hasChanged;
663*cdf0e10cSrcweir     }
664*cdf0e10cSrcweir 
665*cdf0e10cSrcweir     /**
666*cdf0e10cSrcweir     * Forces environment recreation.
667*cdf0e10cSrcweir     */
668*cdf0e10cSrcweir     protected void after() {
669*cdf0e10cSrcweir         disposeEnvironment();
670*cdf0e10cSrcweir     }
671*cdf0e10cSrcweir 
672*cdf0e10cSrcweir 
673*cdf0e10cSrcweir }  // finish class _XPropertySet
674*cdf0e10cSrcweir 
675