1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir package ifc.beans; 29*cdf0e10cSrcweir 30*cdf0e10cSrcweir import com.sun.star.beans.PropertyValue; 31*cdf0e10cSrcweir import com.sun.star.beans.PropertyVetoException; 32*cdf0e10cSrcweir import com.sun.star.lang.WrappedTargetException; 33*cdf0e10cSrcweir import lib.MultiMethodTest; 34*cdf0e10cSrcweir import com.sun.star.beans.UnknownPropertyException; 35*cdf0e10cSrcweir import com.sun.star.beans.XPropertyAccess; 36*cdf0e10cSrcweir import lib.Status; 37*cdf0e10cSrcweir import lib.StatusException; 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir /** 40*cdf0e10cSrcweir * Testing <code>com.sun.star.beans.XPropertyAccess</code> 41*cdf0e10cSrcweir * interface methods : 42*cdf0e10cSrcweir * <ul> 43*cdf0e10cSrcweir * <li><code>getPropertyValues()</code></li> 44*cdf0e10cSrcweir * <li><code>setPropertyValues()</code></li> 45*cdf0e10cSrcweir * </ul> 46*cdf0e10cSrcweir * @see com.sun.star.beans.XPropertyAccess 47*cdf0e10cSrcweir */ 48*cdf0e10cSrcweir public class _XPropertyAccess extends MultiMethodTest { 49*cdf0e10cSrcweir 50*cdf0e10cSrcweir /** 51*cdf0e10cSrcweir * oObj filled by MultiMethodTest 52*cdf0e10cSrcweir */ 53*cdf0e10cSrcweir public XPropertyAccess oObj = null;// oObj filled by MultiMethodTest 54*cdf0e10cSrcweir 55*cdf0e10cSrcweir /** 56*cdf0e10cSrcweir * object relation X<CODE>PropertyAccess.propertyToChange</CODE><br> 57*cdf0e10cSrcweir * This relation must be filled from the module. It contains a property which must 58*cdf0e10cSrcweir * be kind of String property, available at <CODE>getPropertyValues()</CODE> and changeable by 59*cdf0e10cSrcweir * <CODE>setPropertyValues()</CODE> 60*cdf0e10cSrcweir */ 61*cdf0e10cSrcweir public PropertyValue propertyToChange = null; 62*cdf0e10cSrcweir 63*cdf0e10cSrcweir /** 64*cdf0e10cSrcweir * checks if the object relation <CODE>XPropertyAccess.propertyToChange</CODE> 65*cdf0e10cSrcweir * is available 66*cdf0e10cSrcweir */ 67*cdf0e10cSrcweir public void before() { 68*cdf0e10cSrcweir propertyToChange = (PropertyValue) tEnv.getObjRelation("XPropertyAccess.propertyToChange"); 69*cdf0e10cSrcweir if (propertyToChange == null) { 70*cdf0e10cSrcweir throw new StatusException(Status.failed("Object raltion 'XPropertyAccess.propertyToChange' is null")); 71*cdf0e10cSrcweir } 72*cdf0e10cSrcweir } 73*cdf0e10cSrcweir 74*cdf0e10cSrcweir /** 75*cdf0e10cSrcweir * Test calls the method and checks if the returned sequenze contanis a propterty which is named 76*cdf0e10cSrcweir * in the object relation <code>XPropertyAccess.propertyToChange</code>. 77*cdf0e10cSrcweir */ 78*cdf0e10cSrcweir public void _getPropertyValues() { 79*cdf0e10cSrcweir PropertyValue[] properties = oObj.getPropertyValues(); 80*cdf0e10cSrcweir 81*cdf0e10cSrcweir boolean ok = true; 82*cdf0e10cSrcweir 83*cdf0e10cSrcweir if (properties != null){ 84*cdf0e10cSrcweir 85*cdf0e10cSrcweir boolean found = false; 86*cdf0e10cSrcweir for (int i=0; i < properties.length; i++){ 87*cdf0e10cSrcweir if (properties[i].Name.equals(propertyToChange.Name)) found = true; 88*cdf0e10cSrcweir } 89*cdf0e10cSrcweir if (! found){ 90*cdf0e10cSrcweir log.println("ERROR: could not find desired property '"+ propertyToChange.Name+"'"); 91*cdf0e10cSrcweir ok=false; 92*cdf0e10cSrcweir } 93*cdf0e10cSrcweir 94*cdf0e10cSrcweir } else { 95*cdf0e10cSrcweir log.println("ERROR: the method returned NULL"); 96*cdf0e10cSrcweir ok =false; 97*cdf0e10cSrcweir } 98*cdf0e10cSrcweir 99*cdf0e10cSrcweir tRes.tested("getPropertyValues()", ok ); 100*cdf0e10cSrcweir return; 101*cdf0e10cSrcweir } 102*cdf0e10cSrcweir 103*cdf0e10cSrcweir /** 104*cdf0e10cSrcweir * Test calls the method and checks if: 105*cdf0e10cSrcweir * <ul> 106*cdf0e10cSrcweir * <li>the property given by the object relation 107*cdf0e10cSrcweir * <CODE>XPropertyAccess.propertyToChange</CODE> has changed</LI> 108*cdf0e10cSrcweir * <li><CODE>com.sun.star.lang.IllegalArgumentException</CODE> was thrown if a <CODE>Integer</CODE> 109*cdf0e10cSrcweir * value was set to a <CODE>String</CODE> property</LI> 110*cdf0e10cSrcweir * <li><CODE>com.sun.star.beans.UnknownPropertyException</CODE> was throen if an invalid property 111*cdf0e10cSrcweir * was set</LI> 112*cdf0e10cSrcweir * </ul> 113*cdf0e10cSrcweir */ 114*cdf0e10cSrcweir public void _setPropertyValues(){ 115*cdf0e10cSrcweir 116*cdf0e10cSrcweir boolean ok = true; 117*cdf0e10cSrcweir boolean test = true; 118*cdf0e10cSrcweir boolean exp = false; 119*cdf0e10cSrcweir 120*cdf0e10cSrcweir try { 121*cdf0e10cSrcweir PropertyValue[] newProps = new PropertyValue[1]; 122*cdf0e10cSrcweir newProps[0] = propertyToChange; 123*cdf0e10cSrcweir 124*cdf0e10cSrcweir log.println("try to set property vlaues given by object relation 'XPropertyAccess.propertyToChange'..."); 125*cdf0e10cSrcweir oObj.setPropertyValues(newProps); 126*cdf0e10cSrcweir 127*cdf0e10cSrcweir } catch (UnknownPropertyException ex) { 128*cdf0e10cSrcweir log.println("ERROR: Exception was thrown while trying to set property value: " + 129*cdf0e10cSrcweir ex.toString()); 130*cdf0e10cSrcweir test = false; 131*cdf0e10cSrcweir } catch (PropertyVetoException ex) { 132*cdf0e10cSrcweir log.println("ERROR: Exception was thrown while trying to set property value: " + 133*cdf0e10cSrcweir ex.toString()); 134*cdf0e10cSrcweir test = false; 135*cdf0e10cSrcweir } catch (WrappedTargetException ex) { 136*cdf0e10cSrcweir log.println("ERROR: Exception was thrown while trying to set property value: " + 137*cdf0e10cSrcweir ex.toString()); 138*cdf0e10cSrcweir test = false; 139*cdf0e10cSrcweir } catch (com.sun.star.lang.IllegalArgumentException ex) { 140*cdf0e10cSrcweir log.println("ERROR: Exception was thrown while trying to set property value: " + 141*cdf0e10cSrcweir ex.toString()); 142*cdf0e10cSrcweir test = false; 143*cdf0e10cSrcweir } 144*cdf0e10cSrcweir 145*cdf0e10cSrcweir if ( test){ 146*cdf0e10cSrcweir log.println("... OK"); 147*cdf0e10cSrcweir } 148*cdf0e10cSrcweir 149*cdf0e10cSrcweir ok &= test; 150*cdf0e10cSrcweir test = false; 151*cdf0e10cSrcweir exp = false; 152*cdf0e10cSrcweir try { 153*cdf0e10cSrcweir log.println("try to set integer value to string property, " + 154*cdf0e10cSrcweir "expect 'com.sun.star.lang.IllegalArgumentException'..."); 155*cdf0e10cSrcweir PropertyValue[] newProps = new PropertyValue[1]; 156*cdf0e10cSrcweir PropertyValue failedProp = new PropertyValue(); 157*cdf0e10cSrcweir failedProp.Name = propertyToChange.Name; 158*cdf0e10cSrcweir failedProp.Value = new Integer(10); 159*cdf0e10cSrcweir newProps[0] = failedProp; 160*cdf0e10cSrcweir oObj.setPropertyValues(newProps); 161*cdf0e10cSrcweir } catch (PropertyVetoException ex) { 162*cdf0e10cSrcweir log.println("ERROR: unexptected exception was thrown while trying to set null value: " + 163*cdf0e10cSrcweir ex.toString()); 164*cdf0e10cSrcweir exp = true; 165*cdf0e10cSrcweir } catch (WrappedTargetException ex) { 166*cdf0e10cSrcweir log.println("ERROR: unexptected exception was thrown while trying to set null value: " + 167*cdf0e10cSrcweir ex.toString()); 168*cdf0e10cSrcweir exp = true; 169*cdf0e10cSrcweir } catch (com.sun.star.lang.IllegalArgumentException ex) { 170*cdf0e10cSrcweir log.println("OK: exptected exception was thrown while trying to set null value: " + 171*cdf0e10cSrcweir ex.toString()); 172*cdf0e10cSrcweir test = true; 173*cdf0e10cSrcweir exp = true; 174*cdf0e10cSrcweir } catch (UnknownPropertyException ex) { 175*cdf0e10cSrcweir log.println("ERROR: unexptected exception was thrown while trying to set null value: " + 176*cdf0e10cSrcweir ex.toString()); 177*cdf0e10cSrcweir exp = true; 178*cdf0e10cSrcweir } 179*cdf0e10cSrcweir 180*cdf0e10cSrcweir if (! exp){ 181*cdf0e10cSrcweir log.println("FAILED: expected exception 'UnknownPropertyException' was not thrown"); 182*cdf0e10cSrcweir } else { 183*cdf0e10cSrcweir if (test) log.println("... OK"); 184*cdf0e10cSrcweir } 185*cdf0e10cSrcweir 186*cdf0e10cSrcweir ok &= test; 187*cdf0e10cSrcweir test = false; 188*cdf0e10cSrcweir exp = false; 189*cdf0e10cSrcweir try { 190*cdf0e10cSrcweir 191*cdf0e10cSrcweir log.println("try to set values with invalid property name. " + 192*cdf0e10cSrcweir "Expect 'com.sun.star.beans.UnknownPropertyException'..."); 193*cdf0e10cSrcweir 194*cdf0e10cSrcweir PropertyValue[] newProps = new PropertyValue[1]; 195*cdf0e10cSrcweir PropertyValue newProp = new PropertyValue(); 196*cdf0e10cSrcweir newProp.Name = "XPropertyAccess.InvalidPropertyName"; 197*cdf0e10cSrcweir newProp.Value = "invalid property"; 198*cdf0e10cSrcweir newProps[0] = newProp; 199*cdf0e10cSrcweir 200*cdf0e10cSrcweir oObj.setPropertyValues(newProps); 201*cdf0e10cSrcweir 202*cdf0e10cSrcweir } catch (WrappedTargetException ex) { 203*cdf0e10cSrcweir log.println("ERROR: unexptected exception was thrown while trying to set invalid value: " + 204*cdf0e10cSrcweir ex.toString()); 205*cdf0e10cSrcweir exp = true; 206*cdf0e10cSrcweir } catch (com.sun.star.lang.IllegalArgumentException ex) { 207*cdf0e10cSrcweir log.println("ERROR: unexptected exception was thrown while trying to set invalid value: " + 208*cdf0e10cSrcweir ex.toString()); 209*cdf0e10cSrcweir exp = true; 210*cdf0e10cSrcweir } catch (PropertyVetoException ex) { 211*cdf0e10cSrcweir log.println("ERROR: unexptected exception was thrown while trying to set invalid value: " + 212*cdf0e10cSrcweir ex.toString()); 213*cdf0e10cSrcweir exp = true; 214*cdf0e10cSrcweir } catch (UnknownPropertyException ex) { 215*cdf0e10cSrcweir log.println("OK: Exptected exception was thrown while trying to set invalid value: " + 216*cdf0e10cSrcweir ex.toString()); 217*cdf0e10cSrcweir exp = true; 218*cdf0e10cSrcweir test = true; 219*cdf0e10cSrcweir } 220*cdf0e10cSrcweir 221*cdf0e10cSrcweir ok &= test; 222*cdf0e10cSrcweir 223*cdf0e10cSrcweir if (! exp){ 224*cdf0e10cSrcweir log.println("FAILED: expected exception 'UnknownPropertyException' was not thrown"); 225*cdf0e10cSrcweir } else { 226*cdf0e10cSrcweir if (test) log.println("... OK"); 227*cdf0e10cSrcweir } 228*cdf0e10cSrcweir 229*cdf0e10cSrcweir tRes.tested("setPropertyValues()", ok); 230*cdf0e10cSrcweir return; 231*cdf0e10cSrcweir 232*cdf0e10cSrcweir } 233*cdf0e10cSrcweir 234*cdf0e10cSrcweir } /// finish class XPropertyAccess 235*cdf0e10cSrcweir 236*cdf0e10cSrcweir 237