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