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