From 7ca657e5eeb883d2a90ef80456f48a7df6e27cba Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Tue, 13 Jan 2015 15:14:07 +0100 Subject: css.form.component.{CheckBox,RadioButton} DefaultState property values ...must be in the range 0--2; avoid setting bad values from generic qadevOOo property set tests, and throw an IllegalArgumentException if bad values do get set. Change-Id: Ia4a97d0fac326b3ca2ce254946dc4d418e9dd5a7 --- qadevOOo/runner/util/ValueChanger.java | 17 +++++-- .../tests/java/ifc/beans/_XFastPropertySet.java | 54 ++++++++++++++-------- qadevOOo/tests/java/ifc/beans/_XPropertySet.java | 2 +- 3 files changed, 49 insertions(+), 24 deletions(-) (limited to 'qadevOOo') diff --git a/qadevOOo/runner/util/ValueChanger.java b/qadevOOo/runner/util/ValueChanger.java index 87cc2e712cc6..197de43c81d6 100644 --- a/qadevOOo/runner/util/ValueChanger.java +++ b/qadevOOo/runner/util/ValueChanger.java @@ -32,7 +32,7 @@ import com.sun.star.uno.AnyConverter; public class ValueChanger { // Method to change a Value, thought for properties - public static Object changePValue(Object oldValue) { + public static Object changePValue(Object oldValue, String name) { Object newValue = null; @@ -57,8 +57,15 @@ public class ValueChanger { long oldlong = ((Long) oldValue).longValue(); newValue = Long.valueOf(oldlong + 15); } else if (oldValue instanceof Short) { - short oldshort = ((Short) oldValue).shortValue(); - newValue = Short.valueOf((short) (oldshort + 1)); + short n = ((Short) oldValue).shortValue(); + // css.form.component.{CheckBox,RadioButton} DefaultState properties + // must have values in the range 0--2: + if ("DefaultState".equals(name) && n == 2) { + --n; + } else { + ++n; + } + newValue = Short.valueOf(n); } else if (oldValue instanceof Byte) { byte oldbyte = ((Byte) oldValue).byteValue(); newValue = Byte.valueOf((byte) (oldbyte + 1)); @@ -1000,6 +1007,10 @@ public class ValueChanger { } // end of Change PValue + public static Object changePValue(Object oldValue) { + return changePValue(oldValue, null); + } + /** * Checks if the passed value is the API structure. The value assumed to be * a structure if there are no public methods, and all public fields are not diff --git a/qadevOOo/tests/java/ifc/beans/_XFastPropertySet.java b/qadevOOo/tests/java/ifc/beans/_XFastPropertySet.java index 925b20e9e494..b0b645a62552 100644 --- a/qadevOOo/tests/java/ifc/beans/_XFastPropertySet.java +++ b/qadevOOo/tests/java/ifc/beans/_XFastPropertySet.java @@ -53,10 +53,24 @@ import com.sun.star.uno.UnoRuntime; * @see com.sun.star.beans.XFastPropertySet */ public class _XFastPropertySet extends MultiMethodTest { + private static final class Prop { + public final int handle; + public final String name; + + public Prop() { + handle = -1; + name = null; + } + + public Prop(int handle, String name) { + this.handle = handle; + this.name = name; + } + }; public XFastPropertySet oObj = null; - private final List handles = new ArrayList(); - private int handle = -1; + private final List props = new ArrayList(); + private Prop prop; private Set exclude = null ; /** @@ -91,26 +105,26 @@ public class _XFastPropertySet extends MultiMethodTest { Object gValue = null; Object sValue = null; - if ( handle == -1) { + if ( prop.handle == -1) { log.println("*** No changeable properties found ***"); tRes.tested("setFastPropertyValue()", false) ; } else { try { - gValue = oObj.getFastPropertyValue(handle); - sValue = ValueChanger.changePValue(gValue); - oObj.setFastPropertyValue(handle, sValue); - sValue = oObj.getFastPropertyValue(handle); + gValue = oObj.getFastPropertyValue(prop.handle); + sValue = ValueChanger.changePValue(gValue, prop.name); + oObj.setFastPropertyValue(prop.handle, sValue); + sValue = oObj.getFastPropertyValue(prop.handle); } catch (com.sun.star.beans.UnknownPropertyException e) { - log.println("Exception occurred while trying to change property with handle = " + handle); + log.println("Exception occurred while trying to change property with handle = " + prop.handle); e.printStackTrace(log); } catch (com.sun.star.lang.WrappedTargetException e) { - log.println("Exception occurred while trying to change property with handle = " + handle); + log.println("Exception occurred while trying to change property with handle = " + prop.handle); e.printStackTrace(log); } catch (com.sun.star.beans.PropertyVetoException e) { - log.println("Exception occurred while trying to change property with handle = " + handle); + log.println("Exception occurred while trying to change property with handle = " + prop.handle); e.printStackTrace(log); } catch (com.sun.star.lang.IllegalArgumentException e) { - log.println("Exception occurred while trying to change property with handle = " + handle); + log.println("Exception occurred while trying to change property with handle = " + prop.handle); e.printStackTrace(log); } @@ -137,16 +151,16 @@ public class _XFastPropertySet extends MultiMethodTest { getPropsToTest(propertySetInfo); try { - oObj.getFastPropertyValue(handle); + oObj.getFastPropertyValue(prop.handle); tRes.tested("getFastPropertyValue()",true); } catch (com.sun.star.beans.UnknownPropertyException e) { log.println("Exception occurred while trying to get property '" - + handle +"'"); + + prop.handle +"'"); e.printStackTrace(log); tRes.tested("getFastPropertyValue()",false); } catch (com.sun.star.lang.WrappedTargetException e) { log.println("Exception occurred while trying to get property '" - + handle +"'"); + + prop.handle +"'"); e.printStackTrace(log); tRes.tested("getFastPropertyValue()",false); } @@ -170,24 +184,24 @@ public class _XFastPropertySet extends MultiMethodTest { ((property.Attributes & PropertyAttribute.MAYBEVOID) == 0); boolean canChange = false; if ( isWritable && isNotNull ) - canChange = isChangeable(handle); + canChange = isChangeable(handle, name); if ( isWritable && isNotNull && canChange) - handles.add(Integer.valueOf(handle)); + props.add(new Prop(handle, name)); } // endfor Random rnd = new Random(); - int nr = rnd.nextInt(handles.size()); - handle = handles.get(nr).intValue(); + int nr = rnd.nextInt(props.size()); + prop = props.get(nr); } - private boolean isChangeable(int handle) { + private boolean isChangeable(int handle, String name) { boolean hasChanged = false; try { Object getProp = oObj.getFastPropertyValue(handle); Object setValue = null; if (getProp != null) - setValue = ValueChanger.changePValue(getProp); + setValue = ValueChanger.changePValue(getProp, name); else log.println("Property with handle = " + handle + " is null but 'MAYBEVOID' isn't set"); diff --git a/qadevOOo/tests/java/ifc/beans/_XPropertySet.java b/qadevOOo/tests/java/ifc/beans/_XPropertySet.java index 630983caa9bd..76aac038c6ed 100644 --- a/qadevOOo/tests/java/ifc/beans/_XPropertySet.java +++ b/qadevOOo/tests/java/ifc/beans/_XPropertySet.java @@ -281,7 +281,7 @@ public class _XPropertySet extends MultiMethodTest { try { log.println("try to change value of property '" + propertyName + "'" ); gValue = oObj.getPropertyValue(propertyName); - sValue = ValueChanger.changePValue(gValue); + sValue = ValueChanger.changePValue(gValue, propertyName); oObj.setPropertyValue(propertyName, sValue); sValue = oObj.getPropertyValue(propertyName); } catch (com.sun.star.beans.PropertyVetoException e) { -- cgit