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