diff options
Diffstat (limited to 'qadevOOo/tests/java/ifc/beans')
15 files changed, 3260 insertions, 0 deletions
diff --git a/qadevOOo/tests/java/ifc/beans/_XExactName.java b/qadevOOo/tests/java/ifc/beans/_XExactName.java new file mode 100644 index 000000000..033426e22 --- /dev/null +++ b/qadevOOo/tests/java/ifc/beans/_XExactName.java @@ -0,0 +1,84 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +package ifc.beans; + +import lib.MultiMethodTest; +import lib.Status; +import lib.StatusException; + +import com.sun.star.beans.XExactName; + + +public class _XExactName extends MultiMethodTest { + protected String expectedName = ""; + public XExactName oObj = null; + + public void _getExactName() { + String nameFor = expectedName.toLowerCase(); + + log.println("Getting exact name for " + nameFor); + + String getting = oObj.getExactName(nameFor); + + boolean res = true; + + if (getting == null) { + res = false; + } else { + if (!getting.equals(expectedName)) { + log.println("didn't get the expected Name:"); + log.println("getting: " + getting); + log.println("Expected: " + expectedName); + res = false; + } + } + + nameFor = expectedName.toUpperCase(); + + log.println("Getting exact name for " + nameFor); + getting = oObj.getExactName(nameFor); + + if (getting == null) { + res = false; + } else { + if (!getting.equals(expectedName)) { + log.println("didn't get the expected Name:"); + log.println("getting: " + getting); + log.println("Expected: " + expectedName); + res = false; + } + } + + tRes.tested("getExactName()", res); + } + + /** + * Checking if the Object relation expectedName is given + * throw a StatusException if not. + */ + @Override + protected void before() { + expectedName = (String) tEnv.getObjRelation("expectedName"); + + if (expectedName == null) { + throw new StatusException(Status.failed( + "Object relation expectedName is missing")); + } + } +} diff --git a/qadevOOo/tests/java/ifc/beans/_XFastPropertySet.java b/qadevOOo/tests/java/ifc/beans/_XFastPropertySet.java new file mode 100644 index 000000000..8ab74dcda --- /dev/null +++ b/qadevOOo/tests/java/ifc/beans/_XFastPropertySet.java @@ -0,0 +1,236 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +package ifc.beans; + +import java.util.ArrayList; +import java.util.List; +import java.util.Random; +import java.util.Set; + +import lib.MultiMethodTest; +import lib.StatusException; +import util.ValueChanger; + +import com.sun.star.beans.Property; +import com.sun.star.beans.PropertyAttribute; +import com.sun.star.beans.XFastPropertySet; +import com.sun.star.beans.XPropertySet; +import com.sun.star.beans.XPropertySetInfo; +import com.sun.star.uno.UnoRuntime; + +/** +* Testing <code>com.sun.star.beans.XFastPropertySet</code> +* interface methods : +* <ul> +* <li><code> setFastPropertyValue()</code></li> +* <li><code> getFastPropertyValue()</code></li> +* </ul> <p> +* Required relations : +* <ul> +* <li> <code>'XFastPropertySet.ExcludeProps'</code> +* <b>(optional) </b> : java.util.Set. +* Has property names which must be skipped from testing in +* some reasons (for example property accepts restricted set +* of values). +* </li> +* <ul> <p> +* @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(int handle, String name) { + this.handle = handle; + this.name = name; + } + } + + public XFastPropertySet oObj = null; + private final List<Prop> props = new ArrayList<Prop>(); + private Prop prop; + private Set<String> exclude = null ; + + /** + * Retrieves relation. + */ + @Override + protected void before() { + exclude = (Set<String>) tEnv.getObjRelation("XFastPropertySet.ExcludeProps") ; + if (exclude == null) { + exclude = new java.util.HashSet<String>() ; + } + } + + /** + * Test selects random property which can not be VOID and + * is writable, then change property value using <code> + * get/set</code> methods, and checks if value properly changed. + * Has <b> OK </b> status if value after change is not equal to value + * before and no exceptions were thrown. <p> + */ + public void _setFastPropertyValue() { + XPropertySet PS = UnoRuntime.queryInterface + (XPropertySet.class, oObj); + XPropertySetInfo propertySetInfo = PS.getPropertySetInfo(); + + if (propertySetInfo == null) { + log.println("getPropertySetInfo() method returned null"); + tRes.tested("setFastPropertyValue()", false) ; + } + getPropsToTest(propertySetInfo); + + Object gValue = null; + Object sValue = null; + + if ( prop.handle == -1) { + log.println("*** No changeable properties found ***"); + tRes.tested("setFastPropertyValue()", false) ; + } else { + try { + 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 = " + prop.handle); + e.printStackTrace(log); + } catch (com.sun.star.lang.WrappedTargetException e) { + 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 = " + prop.handle); + e.printStackTrace(log); + } catch (com.sun.star.lang.IllegalArgumentException e) { + log.println("Exception occurred while trying to change property with handle = " + prop.handle); + e.printStackTrace(log); + } + + tRes.tested("setFastPropertyValue()",(!gValue.equals(sValue))); + } + } + + /** + * Test selects random property which can not be VOID and + * is writable, then calls the method and checks that + * no exceptions were thrown. <p> + * Has <b> OK </b> status if exceptions were thrown. <p> + */ + public void _getFastPropertyValue() { + XPropertySet PS = UnoRuntime.queryInterface + (XPropertySet.class, oObj); + XPropertySetInfo propertySetInfo = PS.getPropertySetInfo(); + + if (propertySetInfo == null) { + log.println("getPropertySetInfo() method returned null"); + tRes.tested("getFastPropertyValue()", false) ; + } + + getPropsToTest(propertySetInfo); + + try { + oObj.getFastPropertyValue(prop.handle); + tRes.tested("getFastPropertyValue()",true); + } catch (com.sun.star.beans.UnknownPropertyException e) { + log.println("Exception occurred while trying to get property '" + + 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 '" + + prop.handle +"'"); + e.printStackTrace(log); + tRes.tested("getFastPropertyValue()",false); + } + } + + + //Get the properties being tested + private void getPropsToTest(XPropertySetInfo xPSI) { + + Property[] properties = xPSI.getProperties(); + + for (int i = 0; i < properties.length; i++) { + if (exclude.contains(properties[i].Name)) continue ; + Property property = properties[i]; + String name = property.Name; + int handle = property.Handle; + log.println("Checking '" + name + "' with handle = " + handle); + boolean isWritable = + ((property.Attributes & PropertyAttribute.READONLY) == 0); + boolean isNotNull = + ((property.Attributes & PropertyAttribute.MAYBEVOID) == 0); + boolean canChange = false; + if ( isWritable && isNotNull ) + canChange = isChangeable(handle, name); + if ( isWritable && isNotNull && canChange) + props.add(new Prop(handle, name)); + } // endfor + + Random rnd = new Random(); + int nr = rnd.nextInt(props.size()); + prop = props.get(nr); + } + + 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, name); + else + log.println("Property with handle = " + handle + + " is null but 'MAYBEVOID' isn't set"); + if (setValue != null) { + oObj.setFastPropertyValue(handle, setValue); + hasChanged = + (!getProp.equals(oObj.getFastPropertyValue(handle))); + } + else + log.println("Couldn't change Property with handle " + handle); + } catch(com.sun.star.lang.WrappedTargetException e) { + log.println("Property with handle " + handle + " throws exception"); + e.printStackTrace(log); + throw new StatusException("Property with handle " + handle + + " throws exception", e); + } catch(com.sun.star.lang.IllegalArgumentException e) { + log.println("Property with handle " + handle + " throws exception"); + e.printStackTrace(log); + throw new StatusException("Property with handle " + handle + + " throws exception", e); + } catch(com.sun.star.beans.PropertyVetoException e) { + log.println("Property with handle " + handle + " throws exception"); + e.printStackTrace(log); + throw new StatusException("Property with handle " + handle + + " throws exception", e); + } catch(com.sun.star.beans.UnknownPropertyException e) { + log.println("Property with handle " + handle + " throws exception"); + e.printStackTrace(log); + throw new StatusException("Property with handle " + handle + + " throws exception", e); + } + + return hasChanged; + } +} + + diff --git a/qadevOOo/tests/java/ifc/beans/_XHierarchicalPropertySet.java b/qadevOOo/tests/java/ifc/beans/_XHierarchicalPropertySet.java new file mode 100644 index 000000000..c7cc8faf7 --- /dev/null +++ b/qadevOOo/tests/java/ifc/beans/_XHierarchicalPropertySet.java @@ -0,0 +1,143 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +package ifc.beans; + +import lib.MultiMethodTest; +import lib.Status; +import util.ValueChanger; +import util.ValueComparer; + +import com.sun.star.beans.XHierarchicalPropertySet; +import com.sun.star.beans.XHierarchicalPropertySetInfo; + + +public class _XHierarchicalPropertySet extends MultiMethodTest { + public XHierarchicalPropertySet oObj; + + public void _getHierarchicalPropertySetInfo() { + XHierarchicalPropertySetInfo hpsi = oObj.getHierarchicalPropertySetInfo(); + boolean res = true; + + if (hpsi == null) { + log.println( + "The component doesn't provide HierarchicalPropertySetInfo"); + tRes.tested("getHierarchicalPropertySetInfo()", + Status.skipped(true)); + + return; + } + + tRes.tested("getHierarchicalPropertySetInfo()", res); + } + + public void _getHierarchicalPropertyValue() { + String[] pNames = (String[]) tEnv.getObjRelation("PropertyNames"); + String[] pTypes = (String[]) tEnv.getObjRelation("PropertyTypes"); + boolean res = true; + + for (int i = 0; i < pNames.length; i++) { + try { + log.print("Property " + pNames[i]); + + Object getting = oObj.getHierarchicalPropertyValue(pNames[i]); + log.println(" has Value " + getting.toString()); + res &= checkType(pNames[i], pTypes[i], getting); + } catch (com.sun.star.beans.UnknownPropertyException e) { + log.println(" is unknown"); + } catch (com.sun.star.lang.IllegalArgumentException e) { + log.println(" is illegal"); + } catch (com.sun.star.lang.WrappedTargetException e) { + log.println(" throws exception " + e.getMessage()); + } + } + + tRes.tested("getHierarchicalPropertyValue()", res); + } + + public void _setHierarchicalPropertyValue() { + String ro = (String) tEnv.getObjRelation("allReadOnly"); + + if (ro != null) { + log.println(ro); + tRes.tested("setHierarchicalPropertyValue()", Status.skipped(true)); + + return; + } + + boolean res = true; + + String[] pNames = (String[]) tEnv.getObjRelation("PropertyNames"); + + for (int k = 0; k < pNames.length; k++) { + try { + Object oldValue = oObj.getHierarchicalPropertyValue(pNames[k]); + Object newValue = ValueChanger.changePValue(oldValue); + oObj.setHierarchicalPropertyValue(pNames[k], newValue); + + Object getValue = oObj.getHierarchicalPropertyValue(pNames[k]); + boolean localRes = ValueComparer.equalValue(getValue, newValue); + + if (!localRes) { + log.println("Expected " + newValue.toString()); + log.println("Gained " + getValue.toString()); + } + + + //reset Value + oObj.setHierarchicalPropertyValue(pNames[k], oldValue); + + res &= localRes; + } catch (com.sun.star.beans.UnknownPropertyException e) { + log.println("Property is unknown"); + } catch (com.sun.star.lang.IllegalArgumentException e) { + log.println("IllegalArgument "+e.getMessage()); + } catch (com.sun.star.beans.PropertyVetoException e) { + log.println("VetoException "+e.getMessage()); + } catch (com.sun.star.lang.WrappedTargetException e) { + log.println("WrappedTarget "+e.getMessage()); + } + + } + + tRes.tested("setHierarchicalPropertyValue()", res); + } + + protected boolean checkType(String name, String type, Object value) { + boolean result = true; + + if (type.equals("Boolean")) { + result = (value instanceof Boolean); + + if (!result) { + log.println("Wrong Type for property " + name); + log.println("Expected " + type); + log.println("getting " + value.getClass()); + } + } else if (type.equals("Short")) { + result = (value instanceof Short); + + if (!result) { + log.println("Wrong Type for property " + name); + log.println("Expected " + type); + log.println("getting " + value.getClass()); + } + } + + return result; + } +} diff --git a/qadevOOo/tests/java/ifc/beans/_XIntrospection.java b/qadevOOo/tests/java/ifc/beans/_XIntrospection.java new file mode 100644 index 000000000..79d7d1767 --- /dev/null +++ b/qadevOOo/tests/java/ifc/beans/_XIntrospection.java @@ -0,0 +1,53 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +package ifc.beans; + +import lib.MultiMethodTest; + +import com.sun.star.beans.XIntrospection; +import com.sun.star.beans.XIntrospectionAccess; + +/** +* Testing <code>com.sun.star.beans.XIntrospection</code> +* interface methods : +* <ul> +* <li><code> inspect() </code></li> +* </ul> <p> +* Test is multithread compliant. <p> +* @see com.sun.star.beans.XIntrospection +*/ +public class _XIntrospection extends MultiMethodTest { + + public XIntrospection oObj = null; + + /** + * Test inspects the object tested, and checks if it + * has a base <code>XInterface</code> method + * <code>acquire</code>. + */ + public void _inspect() { + boolean result = true; + XIntrospectionAccess xIA = oObj.inspect(oObj); + result = xIA.hasMethod("acquire",1); + tRes.tested("inspect()",result); + } + +} // finish class _XIntrospection + + diff --git a/qadevOOo/tests/java/ifc/beans/_XMultiHierarchicalPropertySet.java b/qadevOOo/tests/java/ifc/beans/_XMultiHierarchicalPropertySet.java new file mode 100644 index 000000000..10b1c8ce9 --- /dev/null +++ b/qadevOOo/tests/java/ifc/beans/_XMultiHierarchicalPropertySet.java @@ -0,0 +1,139 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +package ifc.beans; + +import lib.MultiMethodTest; +import lib.Status; +import util.ValueChanger; +import util.ValueComparer; + +import com.sun.star.beans.XHierarchicalPropertySetInfo; +import com.sun.star.beans.XMultiHierarchicalPropertySet; + + +public class _XMultiHierarchicalPropertySet extends MultiMethodTest { + public XMultiHierarchicalPropertySet oObj; + + public void _getHierarchicalPropertySetInfo() { + XHierarchicalPropertySetInfo hpsi = oObj.getHierarchicalPropertySetInfo(); + boolean res = true; + + if (hpsi == null) { + log.println( + "The component doesn't provide HierarchicalPropertySetInfo"); + tRes.tested("getHierarchicalPropertySetInfo()", + Status.skipped(true)); + + return; + } + + tRes.tested("getMultiHierarchicalPropertySetInfo()", res); + } + + public void _getHierarchicalPropertyValues() { + String[] pNames = (String[]) tEnv.getObjRelation("PropertyNames"); + String[] pTypes = (String[]) tEnv.getObjRelation("PropertyTypes"); + boolean res = true; + + try { + Object[] getting = oObj.getHierarchicalPropertyValues(pNames); + res &= checkType(pNames, pTypes, getting); + } catch (com.sun.star.lang.IllegalArgumentException e) { + log.println("Exception " + e.getMessage()); + } catch (com.sun.star.lang.WrappedTargetException e) { + log.println("Exception " + e.getMessage()); + } + + tRes.tested("getHierarchicalPropertyValues()", res); + } + + public void _setHierarchicalPropertyValues() { + String ro = (String) tEnv.getObjRelation("allReadOnly"); + + if (ro != null) { + log.println(ro); + tRes.tested("setHierarchicalPropertyValues()", + Status.skipped(true)); + + return; + } + + String[] pNames = (String[]) tEnv.getObjRelation("PropertyNames"); + boolean res = true; + + try { + Object[] oldValues = oObj.getHierarchicalPropertyValues(pNames); + Object[] newValues = new Object[oldValues.length]; + + for (int k = 0; k < oldValues.length; k++) { + newValues[k] = ValueChanger.changePValue(oldValues[k]); + } + + oObj.setHierarchicalPropertyValues(pNames, newValues); + + Object[] getValues = oObj.getHierarchicalPropertyValues(pNames); + + for (int k = 0; k < pNames.length; k++) { + boolean localRes = ValueComparer.equalValue(getValues[k], + newValues[k]); + + if (!localRes) { + log.println("didn't work for " + pNames[k]); + log.println("Expected " + newValues[k].toString()); + log.println("Getting " + getValues[k].toString()); + } + //reset properties + oObj.setHierarchicalPropertyValues(pNames, oldValues); + } + } catch (com.sun.star.lang.IllegalArgumentException e) { + log.println("IllegalArgument " + e.getMessage()); + } catch (com.sun.star.beans.PropertyVetoException e) { + log.println("VetoException " + e.getMessage()); + } catch (com.sun.star.lang.WrappedTargetException e) { + log.println("WrappedTarget " + e.getMessage()); + } + + tRes.tested("setHierarchicalPropertyValues()", res); + } + + protected boolean checkType(String[] name, String[] type, Object[] value) { + boolean result = true; + + for (int k = 0; k < name.length; k++) { + if (type[k].equals("Boolean")) { + result &= (value[k] instanceof Boolean); + + if (!(value[k] instanceof Boolean)) { + log.println("Wrong Type for property " + name[k]); + log.println("Expected " + type[k]); + log.println("getting " + value[k].getClass()); + } + } else if (type[k].equals("Short")) { + result &= (value[k] instanceof Short); + + if (!(value[k] instanceof Short)) { + log.println("Wrong Type for property " + name[k]); + log.println("Expected " + type[k]); + log.println("getting " + value[k].getClass()); + } + } + } + + return result; + } +}
\ No newline at end of file diff --git a/qadevOOo/tests/java/ifc/beans/_XMultiPropertySet.java b/qadevOOo/tests/java/ifc/beans/_XMultiPropertySet.java new file mode 100644 index 000000000..e23e3845d --- /dev/null +++ b/qadevOOo/tests/java/ifc/beans/_XMultiPropertySet.java @@ -0,0 +1,363 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +package ifc.beans; + +import java.util.HashSet; +import java.util.ArrayList; +import java.util.Set; +import java.util.StringTokenizer; +import java.util.Arrays; + +import lib.MultiMethodTest; +import lib.Status; +import util.ValueChanger; + +import com.sun.star.beans.Property; +import com.sun.star.beans.PropertyAttribute; +import com.sun.star.beans.PropertyChangeEvent; +import com.sun.star.beans.XMultiPropertySet; +import com.sun.star.beans.XPropertiesChangeListener; +import com.sun.star.beans.XPropertySetInfo; +import com.sun.star.lang.EventObject; + + +/** +* Testing <code>com.sun.star.beans.XMultiPropertySet</code> +* interface methods : +* <ul> +* <li><code> getPropertySetInfo()</code></li> +* <li><code> setPropertyValues()</code></li> +* <li><code> getPropertyValues()</code></li> +* <li><code> addPropertiesChangeListener()</code></li> +* <li><code> removePropertiesChangeListener()</code></li> +* <li><code> firePropertiesChangeEvent()</code></li> +* </ul> <p> +* +* Required relations : +* <ul> +* <li> <code>'XMultiPropertySet.ExcludeProps'</code> +* <b>(optional) </b> : java.util.Set. +* Has property names which must be skipped from testing in +* some reasons (for example property accepts restricted set +* of values). +* </li> +* <ul> <p> +* +* Test is <b> NOT </b> multithread compliant. <p> +* After test completion object environment has to be recreated. +* @see com.sun.star.beans.XMultiPropertySet +*/ +public class _XMultiPropertySet extends MultiMethodTest { + + public XMultiPropertySet oObj = null; + + private boolean propertiesChanged = false; + private XPropertySetInfo propertySetInfo = null; + private String [] testPropsNames = null; + private int testPropsAmount = 0; + private Object[] values = null; + + private Set<String> exclProps = null; + + /** + * Initializes some fields. + */ + @Override + public void before() { + exclProps = (Set<String>) tEnv.getObjRelation("XMultiPropertySet.ExcludeProps"); + if (exclProps == null) exclProps = new HashSet<String>(0); + } + + /** + * Listener implementation which sets a flag when + * listener was called. + */ + public class MyChangeListener implements XPropertiesChangeListener { + public void propertiesChange(PropertyChangeEvent[] e) { + propertiesChanged = true; + } + public void disposing (EventObject obj) {} + } + + private final XPropertiesChangeListener PClistener = + new MyChangeListener(); + + /** + * Test calls the method and checks return value. + * <code>PropertySetInfo</code> object is stored<p> + * Has <b> OK </b> status if the method returns not null value + * and no exceptions were thrown. <p> + */ + public void _getPropertySetInfo() { + boolean bResult = true; + propertySetInfo = oObj.getPropertySetInfo(); + + if (propertySetInfo == null) { + log.println("getPropertySetInfo() method returned null"); + bResult = false; + } + + tRes.tested("getPropertySetInfo()", bResult) ; + } + + + /** + * Test collects all property names and retrieves their values, + * then checks the value returned. Finally it also collects + * bound properties for other methods tests.<p> + * Has <b> OK </b> status if the method returns non null value + * and no exceptions were thrown. <p> + * The following method tests are to be completed successfully before : + * <ul> + * <li> <code> getPropertySetInfo() </code> : to have a list + * of properties.</li> + * </ul> + */ + public void _getPropertyValues() { + requiredMethod("getPropertySetInfo()"); + boolean bResult = true; + + Property[] properties = propertySetInfo.getProperties(); + + ArrayList<String> allFilteredNames = new ArrayList<String>(); + ArrayList<Property> allFilteredProperties = new ArrayList<Property>(); + + String[] skipNames = (String[]) tEnv.getObjRelation("SkipProperties"); + + for (int i = 0; i < properties.length; i++) { + if (skipNames == null || !Arrays.asList(skipNames).contains(properties[i].Name)) + { + allFilteredNames.add(properties[i].Name); + allFilteredProperties.add(properties[i]); + } + } + + String[] arrayAllFilteredNames = allFilteredNames.toArray(new String[allFilteredNames.size()]); + + values = oObj.getPropertyValues(arrayAllFilteredNames); + + bResult &= values!=null; + tRes.tested("getPropertyValues()", bResult) ; + + Property[] arrayFilteredProperties = allFilteredProperties.toArray(new Property[allFilteredProperties.size()]); + + getPropsToTest(arrayFilteredProperties); + } + + /** + * Test adds listener for all bound properties then each property + * is changed and listener call . <p> + * Has <b> OK </b> status if on each property change the listener was + * called and no exceptions were thrown. <p> + * The following method tests are to be completed successfully before : + * <ul> + * <li> <code> getPropertyValues() </code> : to collect bound + * properties.</li> + * </ul> + */ + public void _addPropertiesChangeListener() { + + requiredMethod("getPropertyValues()"); + + // Creating listener + oObj.addPropertiesChangeListener(testPropsNames, PClistener); + + if ((testPropsAmount==1) && (testPropsNames[0].equals("none"))) { + testPropsAmount = 0; + } + + if (testPropsAmount == 0) { + log.println("all properties are read only"); + tRes.tested("addPropertiesChangeListener()", Status.skipped(true)); + return; + } + + // Change one of the property to be sure that this event was caught. + for (int i=0; i<testPropsAmount;i++) { + log.print("Trying to change property " + testPropsNames[i]); + try { + Object[] gValues = oObj.getPropertyValues(testPropsNames); + Object newValue = ValueChanger.changePValue(gValues[i]); + gValues[i] = newValue; + propertiesChanged = false; + oObj.setPropertyValues(testPropsNames, gValues); + log.println(" ... done"); + } catch (com.sun.star.beans.PropertyVetoException e) { + log.println("Exception occurred while trying to change "+ + "property '"+testPropsNames[i] + "' :" + e); + e.printStackTrace(log); + } catch (com.sun.star.lang.IllegalArgumentException e) { + log.println("Exception occurred while trying to change "+ + "property '"+testPropsNames[i] + "' :" + e); + e.printStackTrace(log); + } catch (com.sun.star.lang.WrappedTargetException e) { + log.println("Exception occurred while trying to change "+ + "property '"+testPropsNames[i] + "' :" + e); + e.printStackTrace(log); + } // end of try-catch + } + waitForEventIdle(); + tRes.tested("addPropertiesChangeListener()", propertiesChanged); + } + + /** + * Calls method and check if listener was called. <p> + * Has <b> OK </b> status if the listener was + * called and no exceptions were thrown. <p> + * The following method tests are to be completed successfully before : + * <ul> + * <li> <code> addPropertiesChangeListener() </code> : listener to + * be added.</li> + * </ul> + */ + public void _firePropertiesChangeEvent() { + requiredMethod("addPropertiesChangeListener()"); + propertiesChanged = false ; + + oObj.firePropertiesChangeEvent(testPropsNames, PClistener); + waitForEventIdle(); + + tRes.tested("firePropertiesChangeEvent()", propertiesChanged); + } + + + /** + * Removes listener added before. <p> + * Has <b> OK </b> status no exceptions were thrown. <p> + * The following method tests are to be completed successfully before : + * <ul> + * <li> <code> addPropertiesChangeListener() </code> : listener to + * be added.</li> + * </ul> + */ + public void _removePropertiesChangeListener() { + requiredMethod("firePropertiesChangeEvent()"); + boolean bResult = true; + + oObj.removePropertiesChangeListener(PClistener); + + tRes.tested("removePropertiesChangeListener()", bResult); + } + + + /** + * Changes all properties, then set them to new values, get them + * and checks if their values were changed properly. <p> + * Has <b> OK </b> status if all properties properly changed + * and no exceptions were thrown. <p> + * The following method tests are to be completed successfully before : + * <ul> + * <li> <code> getPropertyValues() </code> : to collect bound + * properties.</li> + * </ul> + */ + public void _setPropertyValues() { + requiredMethod("getPropertyValues()"); + boolean bResult = true; + + if ((testPropsNames.length==1)&&(testPropsNames[0].equals("none"))) { + log.println("all properties are readOnly"); + tRes.tested("setPropertyValues()",Status.skipped(true)); + return; + } + + log.println("Changing all properties"); + Object[] gValues = oObj.getPropertyValues(testPropsNames); + for (int i=0; i<testPropsAmount;i++) { + Object oldValue = gValues[i]; + Object newValue = ValueChanger.changePValue(oldValue); + gValues[i] = newValue; + } + + try { + oObj.setPropertyValues(testPropsNames, gValues); + Object[] newValues = oObj.getPropertyValues(testPropsNames); + for (int i=0; i<testPropsAmount;i++) { + if (newValues[i].equals(gValues[i])) { + bResult = true; + } + } + } catch (com.sun.star.beans.PropertyVetoException e) { + log.println("Exception occurred while setting properties"); + e.printStackTrace(log); + bResult = false; + } catch (com.sun.star.lang.IllegalArgumentException e) { + log.println("Exception occurred while setting properties"); + e.printStackTrace(log); + bResult = false; + } catch (com.sun.star.lang.WrappedTargetException e) { + log.println("Exception occurred while setting properties"); + e.printStackTrace(log); + bResult = false; + } // end of try-catch + + tRes.tested("setPropertyValues()", bResult); + } + + //Get the properties being tested + private void getPropsToTest(Property[] properties) { + + StringBuilder sb = new StringBuilder(); + + for (int i = 0; i < properties.length; i++) { + + Property property = properties[i]; + String name = property.Name; + boolean isWritable = ((property.Attributes & + PropertyAttribute.READONLY) == 0); + boolean isNotNull = ((property.Attributes & + PropertyAttribute.MAYBEVOID) == 0); + boolean isBound = ((property.Attributes & + PropertyAttribute.BOUND) != 0); + boolean isExcluded = exclProps.contains(name); + + //exclude UserDefined, because we can't change XNameContainer + if (name.indexOf("UserDefined")>0 || name.indexOf("Device")>0) { + isWritable=false; + } + + values = oObj.getPropertyValues(new String[]{property.Name}); + + boolean isVoid = util.utils.isVoid(values[0]); + + if ( isWritable && isNotNull && isBound && !isExcluded && !isVoid) { + sb.append(name + ";"); + } + + } // endfor + + String bound = sb.toString(); + + //get an array of bound properties + if (bound.equals("")) bound = "none"; + StringTokenizer ST=new StringTokenizer(bound,";"); + int nr = ST.countTokens(); + testPropsNames = new String[nr]; + for (int i=0; i<nr; i++) testPropsNames[i] = ST.nextToken(); + testPropsAmount = nr; + } + + /* + * Does nothing. + */ + @Override + protected void after() { + disposeEnvironment(); + } +} diff --git a/qadevOOo/tests/java/ifc/beans/_XMultiPropertyStates.java b/qadevOOo/tests/java/ifc/beans/_XMultiPropertyStates.java new file mode 100644 index 000000000..884fb27af --- /dev/null +++ b/qadevOOo/tests/java/ifc/beans/_XMultiPropertyStates.java @@ -0,0 +1,227 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +package ifc.beans; + +import lib.MultiMethodTest; +import lib.Status; +import lib.StatusException; + +import com.sun.star.beans.Property; +import com.sun.star.beans.PropertyAttribute; +import com.sun.star.beans.PropertyState; +import com.sun.star.beans.XMultiPropertyStates; +import com.sun.star.beans.XPropertySet; +import com.sun.star.beans.XPropertySetInfo; +import com.sun.star.uno.UnoRuntime; + +/** +* Testing <code>com.sun.star.beans.XMultiPropertyStates</code> +* interface methods : +* <ul> +* <li><code> getPropertyStates()</code></li> +* <li><code> setAllPropertiesToDefault()</code></li> +* <li><code> getPropertyValues()</code></li> +* <li><code> setPropertiesToDefault()</code></li> +* <li><code> getPropertyDefaults()</code></li> +* </ul> +* @see com.sun.star.beans.XMultiPropertyStates +*/ +public class _XMultiPropertyStates extends MultiMethodTest { + + public XMultiPropertyStates oObj = null; + + private PropertyState[] states = null; + private String[] names = null; + + @Override + public void before() { + names = (String[]) tEnv.getObjRelation("PropertyNames"); + if (names == null) { + throw new StatusException(Status.failed("No PropertyNames given")); + } + + log.println("Totally " + names.length + " properties encountered:"); + log.print("{"); + for (int i = 0; i < names.length; i++) + log.print(names[i] + " "); + log.print("}"); + log.println(""); + } + + + /** + * Test calls the method and checks return value. + * <code>PropertyDefaults</code> are stored<p> + * Has <b> OK </b> status if the method returns not null value + * and no exceptions were thrown. <p> + */ + public void _getPropertyDefaults() { + boolean result = false; + try { + Object[] defaults = oObj.getPropertyDefaults(names); + log.println("Number of default values: " + defaults.length); + result = defaults.length == names.length; + } catch (com.sun.star.beans.UnknownPropertyException e) { + log.println("some properties seem to be unknown: " + e.toString()); + } catch (com.sun.star.lang.WrappedTargetException e) { + log.println("Wrapped target Exception was thrown: " + e.toString()); + } + tRes.tested("getPropertyDefaults()", result) ; + } + + /** + * Test calls the method and checks return value. + * Has <b> OK </b> status if the method returns not null value + * and no exceptions were thrown. <p> + */ + public void _getPropertyStates() { + boolean result = false; + try { + states = oObj.getPropertyStates(names); + result = (states != null) && (states.length == names.length); + if (states != null) { + log.println("Number of states: " + states.length); + } + else { + log.println("Number of states: <null>"); + } + } catch (com.sun.star.beans.UnknownPropertyException e) { + log.println("some properties seem to be unknown: " + e.toString()); + } + tRes.tested("getPropertyStates()", result) ; + } + + /** + * Test calls the method and checks return value. + * Has <b> OK </b> status if the Property + * has default state afterwards. <p> + */ + public void _setPropertiesToDefault() { + requiredMethod("getPropertyStates()"); + // searching for property which currently don't have default value + // and preferable has MAYBEDEFAULT attr + // if no such properties are found then the first one is selected + + String ro = (String) tEnv.getObjRelation("allReadOnly"); + if (ro != null) { + log.println(ro); + tRes.tested("setPropertiesToDefault()",Status.skipped(true)); + return; + } + + boolean mayBeDef = false; + String propName = names[0]; + + for(int i = 0; i < names.length; i++) { + if (!mayBeDef && states[i] != PropertyState.DEFAULT_VALUE ) { + propName = names[i]; + XPropertySet xPropSet = UnoRuntime.queryInterface(XPropertySet.class, oObj); + XPropertySetInfo xPropSetInfo = xPropSet.getPropertySetInfo(); + Property prop = null; + try { + prop = xPropSetInfo.getPropertyByName(names[i]); + } + catch(com.sun.star.beans.UnknownPropertyException e) { + throw new StatusException(e, Status.failed("couldn't get property info")); + } + if ( (prop.Attributes & PropertyAttribute.MAYBEDEFAULT) != 0){ + log.println("Property " + names[i] + + " 'may be default' and doesn't have default value"); + mayBeDef = true; + } + } + } + log.println("The property " + propName + " selected"); + + boolean result = false; + try { + String[] the_first = new String[1]; + the_first[0] = propName; + log.println("Setting " + propName + " to default"); + oObj.setPropertiesToDefault(the_first); + result = oObj.getPropertyStates(the_first)[0].equals(PropertyState.DEFAULT_VALUE); + } catch (com.sun.star.beans.UnknownPropertyException e) { + log.println("some properties seem to be unknown: " + e.toString()); + } + + if (!result) { + log.println("The property didn't change its state to default ..."); + if (mayBeDef) { + log.println(" ... and it may be default - FAILED"); + } else { + log.println(" ... but it may not be default - OK"); + result = true; + } + } + + tRes.tested("setPropertiesToDefault()", result) ; + } + + /** + * Test calls the method and checks return value. + * Has <b> OK </b> status if the all Properties + * have default state afterwards. <p> + */ + public void _setAllPropertiesToDefault() { + requiredMethod("setPropertiesToDefault()"); + boolean result = true; + + try { + oObj.setAllPropertiesToDefault(); + } catch(RuntimeException e) { + log.println("Ignore Runtime Exception: " + e.getMessage()); + } + log.println("Checking that all properties are now in DEFAULT state" + + " excepting may be those which 'can't be default'"); + + try { + states = oObj.getPropertyStates(names); + for (int i = 0; i < states.length; i++) { + boolean part_result = states[i].equals + (PropertyState.DEFAULT_VALUE); + if (!part_result) { + log.println("Property '" + names[i] + + "' wasn't set to default"); + XPropertySet xPropSet = UnoRuntime.queryInterface(XPropertySet.class, oObj); + XPropertySetInfo xPropSetInfo = + xPropSet.getPropertySetInfo(); + Property prop = xPropSetInfo.getPropertyByName(names[i]); + if ( (prop.Attributes & + PropertyAttribute.MAYBEDEFAULT) != 0 ) { + log.println(" ... and it has MAYBEDEFAULT "+ + "attribute - FAILED"); + } else { + log.println(" ... but it has no MAYBEDEFAULT "+ + "attribute - OK"); + part_result = true; + } + } + + result &= part_result; + } + } catch (com.sun.star.beans.UnknownPropertyException e) { + log.println("some properties seem to be unknown: " + e.toString()); + result=false; + } + + tRes.tested("setAllPropertiesToDefault()", result) ; + } + +} + diff --git a/qadevOOo/tests/java/ifc/beans/_XProperty.java b/qadevOOo/tests/java/ifc/beans/_XProperty.java new file mode 100644 index 000000000..cb3886701 --- /dev/null +++ b/qadevOOo/tests/java/ifc/beans/_XProperty.java @@ -0,0 +1,34 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +package ifc.beans; + +import lib.MultiMethodTest; + +import com.sun.star.beans.Property; +import com.sun.star.beans.XProperty; + + +public class _XProperty extends MultiMethodTest { + public XProperty oObj; + + public void _getAsProperty() { + Property prop = oObj.getAsProperty(); + boolean res = (prop.Type != null); + tRes.tested("getAsProperty()", res); + } +}
\ No newline at end of file diff --git a/qadevOOo/tests/java/ifc/beans/_XPropertyAccess.java b/qadevOOo/tests/java/ifc/beans/_XPropertyAccess.java new file mode 100644 index 000000000..697290dc7 --- /dev/null +++ b/qadevOOo/tests/java/ifc/beans/_XPropertyAccess.java @@ -0,0 +1,225 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +package ifc.beans; + +import com.sun.star.beans.PropertyValue; +import com.sun.star.beans.PropertyVetoException; +import com.sun.star.lang.WrappedTargetException; +import lib.MultiMethodTest; +import com.sun.star.beans.UnknownPropertyException; +import com.sun.star.beans.XPropertyAccess; +import lib.Status; +import lib.StatusException; + +/** + * Testing <code>com.sun.star.beans.XPropertyAccess</code> + * interface methods : + * <ul> + * <li><code>getPropertyValues()</code></li> + * <li><code>setPropertyValues()</code></li> + * </ul> + * @see com.sun.star.beans.XPropertyAccess + */ +public class _XPropertyAccess extends MultiMethodTest { + + /** + * oObj filled by MultiMethodTest + */ + public XPropertyAccess oObj = null;// oObj filled by MultiMethodTest + + /** + * object relation X<CODE>PropertyAccess.propertyToChange</CODE><br> + * This relation must be filled from the module. It contains a property which must + * be kind of String property, available at <CODE>getPropertyValues()</CODE> and changeable by + * <CODE>setPropertyValues()</CODE> + */ + public PropertyValue propertyToChange = null; + + /** + * checks if the object relation <CODE>XPropertyAccess.propertyToChange</CODE> + * is available + */ + @Override + public void before() { + propertyToChange = (PropertyValue) tEnv.getObjRelation("XPropertyAccess.propertyToChange"); + if (propertyToChange == null) { + throw new StatusException(Status.failed("Object raltion 'XPropertyAccess.propertyToChange' is null")); + } + } + + /** + * Test calls the method and checks if the returned sequence contains a property which is named + * in the object relation <code>XPropertyAccess.propertyToChange</code>. + */ + public void _getPropertyValues() { + PropertyValue[] properties = oObj.getPropertyValues(); + + boolean ok = true; + + if (properties != null){ + + boolean found = false; + for (int i=0; i < properties.length; i++){ + if (properties[i].Name.equals(propertyToChange.Name)) found = true; + } + if (! found){ + log.println("ERROR: could not find desired property '"+ propertyToChange.Name+"'"); + ok=false; + } + + } else { + log.println("ERROR: the method returned NULL"); + ok =false; + } + + tRes.tested("getPropertyValues()", ok ); + } + + /** + * Test calls the method and checks if: + * <ul> + * <li>the property given by the object relation + * <CODE>XPropertyAccess.propertyToChange</CODE> has changed</LI> + * <li><CODE>com.sun.star.lang.IllegalArgumentException</CODE> was thrown if a <CODE>Integer</CODE> + * value was set to a <CODE>String</CODE> property</LI> + * <li><CODE>com.sun.star.beans.UnknownPropertyException</CODE> was thrown if an invalid property + * was set</LI> + * </ul> + */ + public void _setPropertyValues(){ + + boolean ok = true; + boolean test = true; + boolean exp = false; + + try { + PropertyValue[] newProps = new PropertyValue[1]; + newProps[0] = propertyToChange; + + log.println("try to set property values given by object relation 'XPropertyAccess.propertyToChange'..."); + oObj.setPropertyValues(newProps); + + } catch (UnknownPropertyException ex) { + log.println("ERROR: Exception was thrown while trying to set property value: " + + ex.toString()); + test = false; + } catch (PropertyVetoException ex) { + log.println("ERROR: Exception was thrown while trying to set property value: " + + ex.toString()); + test = false; + } catch (WrappedTargetException ex) { + log.println("ERROR: Exception was thrown while trying to set property value: " + + ex.toString()); + test = false; + } catch (com.sun.star.lang.IllegalArgumentException ex) { + log.println("ERROR: Exception was thrown while trying to set property value: " + + ex.toString()); + test = false; + } + + if ( test){ + log.println("... OK"); + } + + ok &= test; + test = false; + exp = false; + try { + log.println("try to set integer value to string property, " + + "expect 'com.sun.star.lang.IllegalArgumentException'..."); + PropertyValue[] newProps = new PropertyValue[1]; + PropertyValue failedProp = new PropertyValue(); + failedProp.Name = propertyToChange.Name; + failedProp.Value = Integer.valueOf(10); + newProps[0] = failedProp; + oObj.setPropertyValues(newProps); + } catch (PropertyVetoException ex) { + log.println("ERROR: unexpected exception was thrown while trying to set null value: " + + ex.toString()); + exp = true; + } catch (WrappedTargetException ex) { + log.println("ERROR: unexpected exception was thrown while trying to set null value: " + + ex.toString()); + exp = true; + } catch (com.sun.star.lang.IllegalArgumentException ex) { + log.println("OK: expected exception was thrown while trying to set null value: " + + ex.toString()); + test = true; + exp = true; + } catch (UnknownPropertyException ex) { + log.println("ERROR: unexpected exception was thrown while trying to set null value: " + + ex.toString()); + exp = true; + } + + if (! exp){ + log.println("FAILED: expected exception 'UnknownPropertyException' was not thrown"); + } else { + if (test) log.println("... OK"); + } + + ok &= test; + test = false; + exp = false; + try { + + log.println("try to set values with invalid property name. " + + "Expect 'com.sun.star.beans.UnknownPropertyException'..."); + + PropertyValue[] newProps = new PropertyValue[1]; + PropertyValue newProp = new PropertyValue(); + newProp.Name = "XPropertyAccess.InvalidPropertyName"; + newProp.Value = "invalid property"; + newProps[0] = newProp; + + oObj.setPropertyValues(newProps); + + } catch (WrappedTargetException ex) { + log.println("ERROR: unexpected exception was thrown while trying to set invalid value: " + + ex.toString()); + exp = true; + } catch (com.sun.star.lang.IllegalArgumentException ex) { + log.println("ERROR: unexpected exception was thrown while trying to set invalid value: " + + ex.toString()); + exp = true; + } catch (PropertyVetoException ex) { + log.println("ERROR: unexpected exception was thrown while trying to set invalid value: " + + ex.toString()); + exp = true; + } catch (UnknownPropertyException ex) { + log.println("OK: Expected exception was thrown while trying to set invalid value: " + + ex.toString()); + exp = true; + test = true; + } + + ok &= test; + + if (! exp){ + log.println("FAILED: expected exception 'UnknownPropertyException' was not thrown"); + } else { + if (test) log.println("... OK"); + } + + tRes.tested("setPropertyValues()", ok); + } + +} /// finish class XPropertyAccess + + diff --git a/qadevOOo/tests/java/ifc/beans/_XPropertyContainer.java b/qadevOOo/tests/java/ifc/beans/_XPropertyContainer.java new file mode 100644 index 000000000..00fcff66f --- /dev/null +++ b/qadevOOo/tests/java/ifc/beans/_XPropertyContainer.java @@ -0,0 +1,299 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +package ifc.beans; + +import com.sun.star.beans.IllegalTypeException; +import com.sun.star.beans.NotRemoveableException; +import com.sun.star.beans.PropertyExistException; +import com.sun.star.uno.Any; +import lib.MultiMethodTest; +import com.sun.star.beans.UnknownPropertyException; +import com.sun.star.beans.XPropertyContainer; +import lib.Status; +import lib.StatusException; + +/** + * Testing <code>com.sun.star.beans.XPropertyAccess</code> + * interface methods : + * <ul> + * <li><code>addProperty()</code></li> + * <li><code>removeProperty()</code></li> + * </ul> + * @see com.sun.star.beans.XPropertyAccess + */ +public class _XPropertyContainer extends MultiMethodTest { + + /** + * oObj filled by MultiMethodTest + */ + public XPropertyContainer oObj = null;// oObj filled by MultiMethodTest + + /** + * object relation X<CODE>PropertyAccess.propertyNotRemovable</CODE><br> + * This relation must be filled from the module. It contains a property which must + * be a property of the implementation object. + */ + private String propertyNotRemovable = null; + + /** + * checks if the object relation <CODE>XPropertyAccess.propertyNotRemovable</CODE> + * is available + */ + @Override + public void before() { + propertyNotRemovable = (String) tEnv.getObjRelation("XPropertyContainer.propertyNotRemovable"); + if (propertyNotRemovable == null) { + throw new StatusException(Status.failed("Object raltion 'XPropertyAccess.propertyNotRemovable' is null")); + } + } + + + + /** + * Test calls the method and checks if the returned sequence contains a property which is named + * in the object relation <code>XPropertyAccess.propertyNotRemovable</code>. + */ + public void _addProperty() { + + boolean ok = true; + boolean test = true; + boolean exp = false; + + try { + log.println("try to add following property:\n" + + "\t('myXPropertContainerProperty', com.sun.star.beans.PropertyAttribute.MAYBEVOID, null) ..."); + oObj.addProperty("myXPropertContainerProperty" , com.sun.star.beans.PropertyAttribute.MAYBEVOID, null); + } catch (com.sun.star.lang.IllegalArgumentException ex) { + log.println("ERROR: Exception was thrown while adding following property: " + + "('myXPropertContainerProperty', com.sun.star.beans.PropertyAttribute.MAYBEVOID, null) : " + + ex.toString()); + log.println("... FAILED"); + test = false; + } catch (PropertyExistException ex) { + log.println("ERROR: Exception was thrown while adding following property: " + + "('myXPropertContainerProperty', com.sun.star.beans.PropertyAttribute.MAYBEVOID, null) : " + + ex.toString()); + log.println("... FAILED"); + test = false; + } catch (IllegalTypeException ex) { + log.println("ERROR: Exception was thrown while adding following property: " + + "('myXPropertContainerProperty', com.sun.star.beans.PropertyAttribute.MAYBEVOID, null) : " + + ex.toString()); + log.println("... FAILED"); + test = false; + } + + if ( test){ + log.println("... OK"); + } + + ok &= test; + test = false; + exp = false; + try { + log.println("add following property second time:\n" + + "\t('myXPropertContainerProperty', com.sun.star.beans.PropertyAttribute.MAYBEVOID, null) ..."); + oObj.addProperty("myXPropertContainerProperty" , com.sun.star.beans.PropertyAttribute.MAYBEVOID, null); + } catch (com.sun.star.lang.IllegalArgumentException ex) { + log.println("ERROR: wrong Exception was thrown while adding following property: " + + "('myXPropertContainerProperty', com.sun.star.beans.PropertyAttribute.MAYBEVOID, null) : " + + "Expected: 'PropertyExistException'\n" + + "Got: 'IllegalArgumentException\n" + + ex.toString()); + log.println("... FAILED"); + exp = true; + } catch (PropertyExistException ex) { + log.println("OK: expected Exception was thrown." + ex.toString()); + test = true; + exp = true; + } catch (IllegalTypeException ex) { + log.println("ERROR: wrong Exception was thrown while adding following property: " + + "('myXPropertContainerProperty', com.sun.star.beans.PropertyAttribute.MAYBEVOID, null) : " + + "Expected: 'PropertyExistException'\n" + + "Got: 'IllegalTypeException\n" + + ex.toString()); + log.println("... FAILED"); + exp = true; + } + if (! exp){ + log.println("FAILED: expected exception 'UnknownPropertyException' was not thrown"); + } else { + if (test) log.println("... OK"); + } + + ok &= test; + test = false; + exp = false; + try { + log.println("try to add following property:\n" + + "\t('IllegalTypeProperty', com.sun.star.beans.PropertyAttribute.MAYBEVOID, Any.VOID) ..."); + oObj.addProperty("IllegalTypeProperty", com.sun.star.beans.PropertyAttribute.MAYBEVOID, Any.VOID); + } catch (com.sun.star.lang.IllegalArgumentException ex) { + log.println("ERROR: wrong Exception was thrown while adding following property: " + + "'', com.sun.star.beans.PropertyAttribute.MAYBEVOID, null\n" + + "Expected: 'IllegalTypeException'\n" + + "Got: 'IllegalArgumentException\n" + + ex.toString()); + log.println("... FAILED"); + exp = true; + } catch (PropertyExistException ex) { + log.println("ERROR: wrong Exception was thrown while adding following property: " + + "'', com.sun.star.beans.PropertyAttribute.MAYBEVOID, null\n" + + "Expected: 'IllegalArgumentException'\n" + + "Got: 'PropertyExistException\n" + + ex.toString()); + log.println("... FAILED"); + exp = true; + } catch (IllegalTypeException ex) { + log.println("OK: expected Exception was thrown." + ex.toString()); + test = true; + exp = true; + } + + if (! exp){ + log.println("FAILED: expected exception 'IllegalTypeException' was not thrown"); + } else { + if (test) log.println("... OK"); + } + + ok &= test; + test = false; + exp = false; + try { + short attrib = -1; + log.println("add following property:\n" + + "'', -1, new Object"); + oObj.addProperty("", attrib, null); + } catch (com.sun.star.lang.IllegalArgumentException ex) { + log.println("OK: expected Exception was thrown." + ex.toString()); + test = true; + exp = true; + } catch (PropertyExistException ex) { + log.println("ERROR: wrong Exception was thrown while adding following property: " + + "'invalidPropertyAttribute', -1, null\n" + + "Expected: 'IllegalTypeException'\n" + + "Got: 'PropertyExistException\n" + + ex.toString()); + log.println("... FAILED"); + exp = true; + } catch (IllegalTypeException ex) { + log.println("ERROR: unexpected Exception was thrown while adding following property: " + + "'', -1, null\n" + + "Expected: 'IllegalArgumentException'\n" + + "Got: 'IllegalTypeException\n" + + ex.toString()); + log.println("... FAILED"); + exp = true; + } + + if (! exp){ + log.println("FAILED: expected exception 'IllegalArgumentException' was not thrown"); + } else { + if (test) log.println("... OK"); + } + + ok &= test; + + tRes.tested("addProperty()", ok ); + } + + /** + * Test calls the method and checks if the returned sequence contains a property which is named + * in the object relation <code>XPropertyAccess.propertyNotRemovable</code>. + */ + public void _removeProperty() { + + requiredMethod("addProperty()"); + + boolean ok = true; + boolean test = true; + boolean exp = false; + + try { + log.println("remove 'myXPropertContainerProperty'"); + oObj.removeProperty("myXPropertContainerProperty"); + } catch (NotRemoveableException ex) { + log.println("ERROR: could not remote property 'myXPropertContainerProperty'" + ex.toString()); + log.println("... FAILED"); + test = false; + } catch (UnknownPropertyException ex) { + log.println("ERROR: could not remote property 'myXPropertContainerProperty'" + ex.toString()); + log.println("... FAILED"); + test = false; + } + if ( test){ + log.println("... OK"); + } + + ok &= test; + test = false; + exp=false; + + try { + log.println("remove not removable property '" + propertyNotRemovable + "'") ; + oObj.removeProperty(propertyNotRemovable); + } catch (NotRemoveableException ex) { + log.println("OK: expected Exception was thrown: " + ex.toString()); + test = true; + exp = true; + } catch (UnknownPropertyException ex) { + log.println("ERROR: wrong exception was thrown.\n" + + "Expected: 'NotRemoveableException'\n" + + "Got: 'UnknownPropertyException'\n" + + ex.toString()); + log.println("... FAILED"); + exp = true; + } + + if (! exp){ + log.println("FAILED: expected exception 'NotRemoveableException' was not thrown"); + } else { + if (test) log.println("... OK"); + } + + ok &= test; + test = false; + exp = false; + + try { + log.println("remove property 'thisPropertyDoesNotExist'"); + oObj.removeProperty("thisPropertyDoesNotExist"); + } catch (UnknownPropertyException ex) { + log.println("OK: expected Exception was thrown: " + ex.toString()); + test = true; + exp = true; + } catch (NotRemoveableException ex) { + log.println("ERROR: wrong exception was thrown.\n" + + "Expected: 'UnknownPropertyException'\n" + + "Got: 'NotRemoveableException\n" + + ex.toString()); + log.println("... FAILED"); + exp = true; + } + if (! exp){ + log.println("FAILED: expected exception 'UnknownPropertyException' was not thrown"); + } else { + if (test) log.println("... OK"); + } + + tRes.tested("removeProperty()", ok ); + } + + +} /// finish class XPropertyContainer diff --git a/qadevOOo/tests/java/ifc/beans/_XPropertySet.java b/qadevOOo/tests/java/ifc/beans/_XPropertySet.java new file mode 100644 index 000000000..0fe6b2593 --- /dev/null +++ b/qadevOOo/tests/java/ifc/beans/_XPropertySet.java @@ -0,0 +1,645 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +package ifc.beans; + +import java.util.ArrayList; + +import lib.MultiMethodTest; +import util.ValueChanger; +import util.utils; + +import com.sun.star.beans.Property; +import com.sun.star.beans.PropertyAttribute; +import com.sun.star.beans.PropertyChangeEvent; +import com.sun.star.beans.XPropertyChangeListener; +import com.sun.star.beans.XPropertySet; +import com.sun.star.beans.XPropertySetInfo; +import com.sun.star.beans.XVetoableChangeListener; +import com.sun.star.lang.EventObject; + +/** +* Testing <code>com.sun.star.beans.XPropertySet</code> +* interface methods : +* <ul> +* <li><code>getPropertySetInfo()</code></li> +* <li><code>setPropertyValue()</code></li> +* <li><code>getPropertyValue()</code></li> +* <li><code>addPropertyChangeListener()</code></li> +* <li><code>removePropertyChangeListener()</code></li> +* <li><code>addVetoableChangeListener()</code></li> +* <li><code>removeVetoableChangeListener()</code></li> +* </ul> +* @see com.sun.star.beans.XPropertySet +*/ +public class _XPropertySet extends MultiMethodTest { + + public XPropertySet oObj = null; + + /** + * Flag that indicates change listener was called. + */ + private boolean propertyChanged = false; + + /** + * Listener that must be called on bound property changing. + */ + public class MyChangeListener implements XPropertyChangeListener { + /** + * Just set <code>propertyChanged</code> flag to true. + */ + public void propertyChange(PropertyChangeEvent e) { + propertyChanged = true; + } + public void disposing (EventObject obj) {} + } + + private final XPropertyChangeListener PClistener = new MyChangeListener(); + + /** + * Flag that indicates veto listener was called. + */ + private boolean vetoableChanged = false; + + /** + * Listener that must be called on constrained property changing. + */ + public class MyVetoListener implements XVetoableChangeListener { + /** + * Just set <code>vetoableChanged</code> flag to true. + */ + public void vetoableChange(PropertyChangeEvent e) { + vetoableChanged = true; + } + public void disposing (EventObject obj) {} + } + + private final XVetoableChangeListener VClistener = new MyVetoListener(); + + /** + * Structure that collects the properties of different types to test : + * Constrained, Bound and Normal. + */ + private static final class PropsToTest { + ArrayList< String > constrained = new ArrayList< String >(); + ArrayList< String > bound = new ArrayList< String >(); + ArrayList< String > normal = new ArrayList< String >(); + } + + private final PropsToTest PTT = new PropsToTest(); + + /** + * Tests method <code>getPropertySetInfo</code>. After test completed + * call {@link #getPropsToTest} method to retrieve different kinds + * of properties to test then. <p> + * Has OK status if not null <code>XPropertySetInfo</code> + * object returned.<p> + * Since <code>getPropertySetInfo</code> is optional, it may return null, + * if it is not implemented. This method uses then an object relation + * <code>PTT</code> (Properties To Test) to determine available properties. + * All tests for services without <code>getPropertySetInfo</code> must + * provide this object relation. + */ + public void _getPropertySetInfo() { + + XPropertySetInfo propertySetInfo = oObj.getPropertySetInfo(); + + if (propertySetInfo == null) { + log.println("getPropertySetInfo() method returned null"); + tRes.tested("getPropertySetInfo()", true) ; + String[] ptt = (String[]) tEnv.getObjRelation("PTT"); + PTT.normal.clear(); + PTT.bound.clear(); + PTT.constrained.clear(); + PTT.normal.add( ptt[0] ); + PTT.bound.add( ptt[1] ); + PTT.constrained.add( ptt[2] ); + } else { + tRes.tested("getPropertySetInfo()", true ); + getPropsToTest(propertySetInfo); + } + } // end of getPropertySetInfo() + + /** + * Tests change listener which added for bound properties. + * Adds listener to bound property (if it exists), then changes + * its value and check if listener was called. <p> + * Method tests to be successfully completed before : + * <ul> + * <li> <code>getPropertySetInfo</code> : in this method test + * one of bound properties is retrieved. </li> + * </ul> <p> + * Has OK status if NO bound properties exist or if listener + * was successfully called. + */ + public void _addPropertyChangeListener() { + + requiredMethod("getPropertySetInfo()"); + + int count = PTT.bound.size(); + if ( count==0 || PTT.bound.get(0).equals("none") ) { + log.println("*** No bound properties found ***"); + tRes.tested("addPropertyChangeListener()", true) ; + } else { + boolean error = false; + for (int i = 0; i < count; i++) { + String propertyName = PTT.bound.get(i); + propertyChanged = false; + try { + oObj.addPropertyChangeListener(propertyName,PClistener); + Object gValue = oObj.getPropertyValue(propertyName); + log.println("Check bound property: " + propertyName ); + oObj.setPropertyValue(propertyName, + ValueChanger.changePValue(gValue)); + } catch (com.sun.star.beans.PropertyVetoException e) { + log.println("Exception occurred while trying to change "+ + "property '"+ propertyName+"'"); + e.printStackTrace(log); + } catch (com.sun.star.lang.IllegalArgumentException e) { + log.println("Exception occurred while trying to change "+ + "property '"+ propertyName+"'"); + e.printStackTrace(log); + } catch (com.sun.star.beans.UnknownPropertyException e) { + log.println("Exception occurred while trying to change "+ + "property '"+ propertyName+"'"); + e.printStackTrace(log); + } catch (com.sun.star.lang.WrappedTargetException e) { + log.println("Exception occurred while trying to change "+ + "property '"+ propertyName+"'"); + e.printStackTrace(log); + } // end of try-catch + error = error || !propertyChanged; + if (!propertyChanged) { + log.println("propertyChangeListener wasn't called for '"+ + propertyName+"'"); + } + } + tRes.tested("addPropertyChangeListener()", !error); + } + } // end of addPropertyChangeListener() + + /** + * Tests vetoable listener which added for constrained properties. + * Adds listener to constrained property (if it exists), then changes + * its value and check if listener was called. <p> + * Method tests to be successfully completed before : + * <ul> + * <li> <code>getPropertySetInfo</code> : in this method test + * one of constrained properties is retrieved. </li> + * </ul> <p> + * Has OK status if NO constrained properties exist or if listener + * was successfully called. + */ + public void _addVetoableChangeListener() { + + requiredMethod("getPropertySetInfo()"); + + int count = PTT.constrained.size(); + if ( count==0 || PTT.constrained.get(0).equals("none") ) { + log.println("*** No constrained properties found ***"); + tRes.tested("addVetoableChangeListener()", true) ; + } else { + boolean error = false; + for (int i = 0; i < count; i++) { + String propertyName = PTT.constrained.get(i); + vetoableChanged = false; + try { + oObj.addVetoableChangeListener(propertyName,VClistener); + Object gValue = oObj.getPropertyValue(propertyName); + oObj.setPropertyValue(propertyName, + ValueChanger.changePValue(gValue)); + } catch (com.sun.star.beans.PropertyVetoException e) { + log.println("Exception occurred while trying to change "+ + "property '"+ propertyName+"'"); + e.printStackTrace(log); + } catch (com.sun.star.lang.IllegalArgumentException e) { + log.println("Exception occurred while trying to change "+ + "property '"+ propertyName+"'"); + e.printStackTrace(log); + } catch (com.sun.star.beans.UnknownPropertyException e) { + log.println("Exception occurred while trying to change "+ + "property '"+ propertyName+"'"); + e.printStackTrace(log); + } catch (com.sun.star.lang.WrappedTargetException e) { + log.println("Exception occurred while trying to change "+ + "property '"+ propertyName+"'"); + e.printStackTrace(log); + } // end of try-catch + error = error || !vetoableChanged; + if (!vetoableChanged) { + log.println("vetoableChangeListener wasn't called for '"+ + propertyName+"'"); + } + } + tRes.tested("addVetoableChangeListener()",!error); + } + } // end of addVetoableChangeListener() + + + /** + * Tests <code>setPropertyValue</code> method. + * Stores value before call, and compares it with value after + * call. <p> + * Method tests to be successfully completed before : + * <ul> + * <li> <code>getPropertySetInfo</code> : in this method test + * one of normal properties is retrieved. </li> + * </ul> <p> + * Has OK status if NO normal properties exist or if value before + * method call is not equal to value after. + */ + public void _setPropertyValue() { + + requiredMethod("getPropertySetInfo()"); + + Object gValue = null; + Object sValue = null; + + int count = PTT.normal.size(); + if ( count==0 || PTT.normal.get(0).equals("none") ) { + log.println("*** No changeable properties found ***"); + tRes.tested("setPropertyValue()", true) ; + } else { + boolean error = false; + for (int i = 0; i < count; i++) { + String propertyName = PTT.normal.get(i); + try { + log.println("try to change value of property '" + propertyName + "'" ); + gValue = oObj.getPropertyValue(propertyName); + sValue = ValueChanger.changePValue(gValue, propertyName); + oObj.setPropertyValue(propertyName, sValue); + sValue = oObj.getPropertyValue(propertyName); + } catch (com.sun.star.beans.PropertyVetoException e) { + log.println("Exception occurred while trying to change "+ + "property '"+ propertyName+"'"); + e.printStackTrace(log); + } catch (com.sun.star.lang.IllegalArgumentException e) { + log.println("Exception occurred while trying to change "+ + "property '"+ propertyName+"'"); + e.printStackTrace(log); + } catch (com.sun.star.beans.UnknownPropertyException e) { + log.println("Exception occurred while trying to change "+ + "property '"+ propertyName+"'"); + e.printStackTrace(log); + } catch (com.sun.star.lang.WrappedTargetException e) { + log.println("Exception occurred while trying to change "+ + "property '"+ propertyName+"'"); + e.printStackTrace(log); + } // end of try-catch + /* this is stupid: we can't set properties whose semantics we + * don't know to random values in an arbitrary order and + * expect that to actually work. + if( gValue.equals(sValue) ) + { + log.println("setting property '"+ propertyName+"' failed"); + error = true; + } + */ + } + tRes.tested("setPropertyValue()",!error); + } //endif + } // end of setPropertyValue() + + /** + * Tests <code>getPropertyValue</code> method for the given property. + * Returns true if no exceptions occurred + */ + private boolean getSinglePropertyValue( String propertyName ) + { + boolean runOk = false; + try { + oObj.getPropertyValue(propertyName); + runOk = true; + } catch (com.sun.star.beans.UnknownPropertyException e) { + log.println("Exception occurred while trying to get property '"+ + propertyName+"'"); + e.printStackTrace(log); + } catch (com.sun.star.lang.WrappedTargetException e) { + log.println("Exception occurred while trying to get property '"+ + propertyName+"'"); + e.printStackTrace(log); + } + return runOk; + } + + /** + * Tests <code>getPropertyValue</code> method. + * Just call this method and checks for no exceptions <p> + * Method tests to be successfully completed before : + * <ul> + * <li> <code>getPropertySetInfo</code> : in this method test + * one of normal properties is retrieved. </li> + * </ul> <p> + * Has OK status if NO normal properties exist or if no + * exceptions were thrown. + */ + public void _getPropertyValue() { + + requiredMethod("getPropertySetInfo()"); + + int count = PTT.normal.size(); + if ( count==0 || PTT.normal.get(0).equals("none") ) { + Property[] properties = oObj.getPropertySetInfo().getProperties(); + if( properties.length > 0 ) { + String propertyName = properties[0].Name; + log.println("All properties are Read Only"); + log.println("Using: "+propertyName); + tRes.tested("getPropertyValue()", getSinglePropertyValue( propertyName ) ); + } + else { + log.println("*** No properties found ***"); + tRes.tested("getPropertyValue()", true) ; + } + } else { + boolean error = false; + for (int i = 0; i < count; i++) { + String propertyName = PTT.normal.get(i); + boolean runOk = getSinglePropertyValue( propertyName ); + if( !runOk ) + { + error = true; + log.println("getPropertyValue() failed for property '"+propertyName+"'"); + } + } + tRes.tested("getPropertyValue()", !error) ; + } + } + + /** + * Tests <code>removePropertyChangeListener</code> method. + * Removes change listener, then changes bound property value + * and checks if the listener was NOT called. + * Method tests to be successfully completed before : + * <ul> + * <li> <code>addPropertyChangeListener</code> : here listener + * was added. </li> + * </ul> <p> + * Has OK status if NO bound properties exist or if listener + * was not called and no exceptions arose. + */ + public void _removePropertyChangeListener() { + + requiredMethod("addPropertyChangeListener()"); + + int count = PTT.bound.size(); + if ( count==0 || PTT.bound.get(0).equals("none") ) { + log.println("*** No bound properties found ***"); + tRes.tested("removePropertyChangeListener()", true) ; + } else { + + //remove all listeners first + for (int i = 0; i < count; i++) { + String propertyName = PTT.bound.get(i); + try { + oObj.removePropertyChangeListener(propertyName,PClistener); + } catch (Exception e) { + log.println("Exception occurred while removing change listener from"+ + "property '"+ propertyName+"'"); + e.printStackTrace(log); + } + } + + boolean error = false; + for (int i = 0; i < count; i++) { + String propertyName = PTT.bound.get(i); + try { + propertyChanged = false; + oObj.addPropertyChangeListener(propertyName,PClistener); + oObj.removePropertyChangeListener(propertyName,PClistener); + Object gValue = oObj.getPropertyValue(propertyName); + oObj.setPropertyValue(propertyName, + ValueChanger.changePValue(gValue)); + } catch (com.sun.star.beans.PropertyVetoException e) { + log.println("Exception occurred while trying to change "+ + "property '"+ propertyName+"'"); + e.printStackTrace(log); + } catch (com.sun.star.lang.IllegalArgumentException e) { + log.println("Exception occurred while trying to change "+ + "property '"+ propertyName+"'"); + e.printStackTrace(log); + } catch (com.sun.star.beans.UnknownPropertyException e) { + log.println("Exception occurred while trying to change "+ + "property '"+ propertyName+"'"); + e.printStackTrace(log); + } catch (com.sun.star.lang.WrappedTargetException e) { + log.println("Exception occurred while trying to change "+ + "property '"+ propertyName+"'"); + e.printStackTrace(log); + } // end of try-catch + + error = error || propertyChanged; + if (propertyChanged) { + log.println("propertyChangeListener was called after removing"+ + " for '"+propertyName+"'"); + } + } + tRes.tested("removePropertyChangeListener()",!error); + } + } // end of removePropertyChangeListener() + + + /** + * Tests <code>removeVetoableChangeListener</code> method. + * Removes vetoable listener, then changes constrained property value + * and checks if the listener was NOT called. + * Method tests to be successfully completed before : + * <ul> + * <li> <code>addPropertyChangeListener</code> : here vetoable listener + * was added. </li> + * </ul> <p> + * Has OK status if NO constrained properties exist or if listener + * was NOT called and no exceptions arose. + */ + public void _removeVetoableChangeListener() { + + requiredMethod("addVetoableChangeListener()"); + + int count = PTT.constrained.size(); + if ( count==0 || PTT.constrained.get(0).equals("none") ) { + log.println("*** No constrained properties found ***"); + tRes.tested("removeVetoableChangeListener()", true) ; + } else { + + //remove all listeners first + for (int i = 0; i < count; i++) { + String propertyName = PTT.constrained.get(i); + try { + oObj.removeVetoableChangeListener(propertyName,VClistener); + } catch (Exception e) { + log.println("Exception occurred while removing veto listener from"+ + "property '"+ propertyName+"'"); + e.printStackTrace(log); + } + } + + boolean error = false; + for (int i = 0; i < count; i++) { + String propertyName = PTT.constrained.get(i); + vetoableChanged = false; + try { + oObj.addVetoableChangeListener(propertyName,VClistener); + oObj.removeVetoableChangeListener(propertyName,VClistener); + Object gValue = oObj.getPropertyValue(propertyName); + oObj.setPropertyValue(propertyName, + ValueChanger.changePValue(gValue)); + } catch (com.sun.star.beans.PropertyVetoException e) { + log.println("Exception occurred while trying to change "+ + "property '"+ propertyName+"'"); + e.printStackTrace(log); + } catch (com.sun.star.lang.IllegalArgumentException e) { + log.println("Exception occurred while trying to change "+ + "property '"+ propertyName+"'"); + e.printStackTrace(log); + } catch (com.sun.star.beans.UnknownPropertyException e) { + log.println("Exception occurred while trying to change "+ + "property '"+ propertyName+"'"); + e.printStackTrace(log); + } catch (com.sun.star.lang.WrappedTargetException e) { + log.println("Exception occurred while trying to change "+ + "property '"+ propertyName+"'"); + e.printStackTrace(log); + } // end of try-catch + error = error || vetoableChanged; + if (vetoableChanged) { + log.println("vetoableChangeListener was called after "+ + "removing for '"+propertyName+"'"); + } + } + tRes.tested("removeVetoableChangeListener()",!error); + } + } // end of removeVetoableChangeListener() + + /** + * Gets the properties being tested. Searches and stores by one + * property of each kind (Bound, Vetoable, Normal). + */ + public void getPropsToTest(XPropertySetInfo xPSI) { + + Property[] properties = xPSI.getProperties(); + // some properties should not be changed in a unspecific way + String[] skip = {"PrinterName", "CharRelief", "IsLayerMode"}; + + for (int i = 0; i < properties.length; i++) { + + Property property = properties[i]; + String name = property.Name; + + boolean cont = false; + for (int j = 0; j < skip.length; j++) { + if (name.equals(skip[j])){ + log.println("skipping '" + name + "'"); + cont = true; + } + } + + if (cont) continue; + + boolean isWritable = ((property.Attributes & + PropertyAttribute.READONLY) == 0); + boolean isNotNull = ((property.Attributes & + PropertyAttribute.MAYBEVOID) == 0); + boolean isBound = ((property.Attributes & + PropertyAttribute.BOUND) != 0); + boolean isConstr = ((property.Attributes & + PropertyAttribute.CONSTRAINED) != 0); + boolean canChange = false; + + if ( !isWritable ) log.println("Property '"+name+"' is READONLY"); + + if (name.endsWith("URL")) isWritable = false; + if (name.startsWith("Fill")) isWritable = false; + if (name.startsWith("Font")) isWritable = false; + if (name.startsWith("IsNumbering")) isWritable = false; + if (name.startsWith("LayerName")) isWritable = false; + if (name.startsWith("Line")) isWritable = false; + if (name.startsWith("TextWriting")) isWritable = false; + + if ( isWritable && isNotNull ) canChange = isChangeable(name); + + if ( isWritable && isNotNull && isBound && canChange) { + PTT.bound.add(name); + } + + if ( isWritable && isNotNull && isConstr && canChange) { + PTT.constrained.add(name); + } + + if ( isWritable && isNotNull && canChange) { + PTT.normal.add(name); + } + + + } // endfor + } + + public boolean isChangeable(String name) { + boolean hasChanged = false; + try { + Object getProp = oObj.getPropertyValue(name); + log.println("Getting: "+getProp); + if (name.equals("xinterfaceA")) { + System.out.println("drin"); + } + + Object setValue = null; + if (getProp != null) { + if (!utils.isVoid(getProp)) + setValue = ValueChanger.changePValue(getProp); + else log.println("Property '"+name+ + "' is void but MAYBEVOID isn't set"); + } else log.println("Property '"+name+"'is null and can't be changed"); + if (name.equals("LineStyle")) setValue = null; + if (setValue != null) { + log.println("Setting to :"+setValue); + oObj.setPropertyValue(name, setValue); + hasChanged = (! getProp.equals(oObj.getPropertyValue(name))); + } else log.println("Couldn't change Property '"+name+"'"); + } catch (com.sun.star.beans.PropertyVetoException e) { + log.println("'" + name + "' throws exception '" + e + "'"); + e.printStackTrace(log); + } catch (com.sun.star.lang.IllegalArgumentException e) { + log.println("'" + name + "' throws exception '" + e + "'"); + e.printStackTrace(log); + } catch (com.sun.star.beans.UnknownPropertyException e) { + log.println("'" + name + "' throws exception '" + e + "'"); + e.printStackTrace(log); + } catch (com.sun.star.lang.WrappedTargetException e) { + log.println("'" + name + "' throws exception '" + e + "'"); + e.printStackTrace(log); + } catch (com.sun.star.uno.RuntimeException e) { + log.println("'" + name + "' throws exception '" + e + "'"); + e.printStackTrace(log); + } catch (java.lang.ArrayIndexOutOfBoundsException e) { + log.println("'" + name + "' throws exception '" + e + "'"); + e.printStackTrace(log); + } + + return hasChanged; + } + + /** + * Forces environment recreation. + */ + @Override + protected void after() { + disposeEnvironment(); + } + + +} // finish class _XPropertySet + diff --git a/qadevOOo/tests/java/ifc/beans/_XPropertySetInfo.java b/qadevOOo/tests/java/ifc/beans/_XPropertySetInfo.java new file mode 100644 index 000000000..dc6ad368f --- /dev/null +++ b/qadevOOo/tests/java/ifc/beans/_XPropertySetInfo.java @@ -0,0 +1,115 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +package ifc.beans; + +import lib.MultiMethodTest; + +import com.sun.star.beans.Property; +import com.sun.star.beans.UnknownPropertyException; +import com.sun.star.beans.XPropertySetInfo; + +/** +* Testing <code>com.sun.star.beans.XPropertySetInfo</code> +* interface methods : +* <ul> +* <li><code>getProperties()</code></li> +* <li><code>getPropertyByName()</code></li> +* <li><code>hasPropertyByName()</code></li> +* </ul> +* @see com.sun.star.beans.XPropertySetInfo +*/ +public class _XPropertySetInfo extends MultiMethodTest { + + public XPropertySetInfo oObj = null;// oObj filled by MultiMethodTest + + public Property IsThere = null; + + /** + * Test calls the method and stores one of the properties.<p> + * Has <b> OK </b> status if the method successfully returns + * value that isn't null.<p> + */ + public void _getProperties() { + Property[] properties = oObj.getProperties(); + IsThere = properties[0]; + tRes.tested("getProperties()", ( properties != null )); + } + + /** + * Test calls the method with property name that certainly present + * in the property set and again calls the method with property name + * that certainly doesn't present in the property set.<p> + * Has <b> OK </b> status if the method in one case successfully + * returns value that isn't null and no exceptions were thrown and + * in other case exception was thrown.<p> + * The following method tests are to be completed successfully before : + * <ul> + * <li> <code>getProperties()</code> : to have a property that certainly + * present in the property set</li> + * </ul> + */ + public void _getPropertyByName() { + requiredMethod("getProperties()"); + boolean result; + try { + Property prop = oObj.getPropertyByName(IsThere.Name); + result = (prop != null); + } catch (com.sun.star.beans.UnknownPropertyException e) { + log.println("Exception occurred while testing" + + " getPropertyByName with existing property"); + e.printStackTrace(log); + result = false; + } + + try { + oObj.getPropertyByName("Jupp"); + log.println("No Exception thrown while testing"+ + " getPropertyByName with non existing property"); + result = false; + } + catch (UnknownPropertyException e) { + result = true; + } + tRes.tested("getPropertyByName()", result); + } + + /** + * Test calls the method with property name that certainly present + * in the property set and again calls the method with property name + * that certainly doesn't present in the property set.<p> + * Has <b> OK </b> status if the method successfully returns true in + * one case and false in other case.<p> + * The following method tests are to be completed successfully before : + * <ul> + * <li> <code>getProperties()</code> : to have a property that certainly + * present in the property set</li> + * </ul> + */ + public void _hasPropertyByName() { + requiredMethod("getProperties()"); + tRes.tested("hasPropertyByName()", + ( + (oObj.hasPropertyByName(IsThere.Name)) && + (!oObj.hasPropertyByName("Jupp")) ) + ); + } + +} /// finish class XPropertySetInfo + + diff --git a/qadevOOo/tests/java/ifc/beans/_XPropertyState.java b/qadevOOo/tests/java/ifc/beans/_XPropertyState.java new file mode 100644 index 000000000..ca7337a74 --- /dev/null +++ b/qadevOOo/tests/java/ifc/beans/_XPropertyState.java @@ -0,0 +1,266 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +package ifc.beans; + +import lib.MultiMethodTest; +import lib.Status; +import lib.StatusException; + +import com.sun.star.beans.Property; +import com.sun.star.beans.PropertyAttribute; +import com.sun.star.beans.PropertyState; +import com.sun.star.beans.XPropertySet; +import com.sun.star.beans.XPropertySetInfo; +import com.sun.star.beans.XPropertyState; +import com.sun.star.uno.Any; +import com.sun.star.uno.UnoRuntime; + + +/** +* Testing <code>com.sun.star.beans.XPropertyState</code> +* interface methods : +* <ul> +* <li><code> getPropertyState()</code></li> +* <li><code> getPropertyStates()</code></li> +* <li><code> setPropertyToDefault()</code></li> +* <li><code> getPropertyDefault()</code></li> +* </ul> +* Test is <b> NOT </b> multithread compliant. <p> +* After test completion object environment has to be recreated. <p> +* <b>Note:</b> object tested must also implement +* <code>com.sun.star.beans.XPropertySet</code> interface. +* @see com.sun.star.beans.XPropertyState +*/ +public class _XPropertyState extends MultiMethodTest { + + public XPropertyState oObj = null; + + private XPropertySet oPS = null ; + private XPropertySetInfo propertySetInfo = null; + private Property[] properties = null ; + private String pName = null ; + private Object propDef = null ; + + /** + * Queries object for <code>XPropertySet</code> interface and + * initializes some fields used by all methods. <p> + * + * Searches property which is not READONLY and MAYBEDEFAULT, if + * such property is not found, then uses property with only + * READONLY attribute. This property name is stored and is used + * by all tests. + * + * @throws StatusException If <code>XPropertySet</code> is not + * implemented by object. + */ + @Override + public void before() throws StatusException { + oPS = UnoRuntime.queryInterface( XPropertySet.class, oObj ); + if (oPS == null) + throw new StatusException + ("XPropertySet interface isn't implemented.", + new NullPointerException + ("XPropertySet interface isn't implemented.")) ; + + propertySetInfo = oPS.getPropertySetInfo(); + properties = propertySetInfo.getProperties(); + Property prop = null; + for (int i=0;i<properties.length;i++) { + try { + prop = propertySetInfo.getPropertyByName + (properties[i].Name); + } catch (com.sun.star.beans.UnknownPropertyException e) { + log.println("Unknown Property "+prop.Name); + } + boolean readOnly = (prop.Attributes & + PropertyAttribute.READONLY) != 0; + boolean maybeDefault = (prop.Attributes & + PropertyAttribute.MAYBEDEFAULT) != 0; + if (!readOnly && maybeDefault) { + pName = properties[i].Name; + log.println("Property '" + pName + "' has attributes "+ + prop.Attributes); + break ; + } else + if (!readOnly) { + pName = properties[i].Name; + log.println("Property '" + pName + + "' is not readonly, may be used ..."); + } else { + log.println("Skipping property '" + properties[i].Name + + "' Readonly: " + readOnly + ", MaybeDefault: " + + maybeDefault); + } + } + + } + + /** + * Test calls the method and checks that no exceptions were thrown. <p> + * Has <b> OK </b> status if no exceptions were thrown. <p> + */ + public void _getPropertyDefault(){ + boolean result = true ; + String localName = pName; + if (localName == null) { + localName = propertySetInfo.getProperties()[0].Name; + } + try { + propDef = oObj.getPropertyDefault(localName); + log.println("Default property value is : '" + propDef + "'"); + } catch (com.sun.star.beans.UnknownPropertyException e) { + log.println("Exception " + e + + "occurred while getting Property default"); + result=false; + } catch (com.sun.star.lang.WrappedTargetException e) { + log.println("Exception " + e + + "occurred while getting Property default"); + result=false; + } + tRes.tested("getPropertyDefault()", result); + } + + /** + * Test calls the method and checks return value and that + * no exceptions were thrown. <p> + * Has <b> OK </b> status if the method returns not null value + * and no exceptions were thrown. <p> + */ + public void _getPropertyState(){ + boolean result = true ; + + String localName = pName; + if (localName == null) { + localName = propertySetInfo.getProperties()[0].Name; + } + + try { + PropertyState ps = oObj.getPropertyState(localName); + if (ps == null) { + log.println("!!! Returned value == null") ; + result = false ; + } + } catch (com.sun.star.beans.UnknownPropertyException e) { + log.println("Exception " + e + + "occurred while getting Property state"); + result = false; + } + tRes.tested("getPropertyState()", result); + } + + /** + * Test calls the method with array of one property name + * and checks return value and that no exceptions were thrown. <p> + * Has <b> OK </b> status if the method returns array with one + * PropertyState and no exceptions were thrown. <p> + */ + public void _getPropertyStates(){ + boolean result = true ; + + String localName = pName; + if (localName == null) { + localName = propertySetInfo.getProperties()[0].Name; + } + + try { + PropertyState[] ps = oObj.getPropertyStates + (new String[] {localName}); + if (ps == null) { + log.println("!!! Returned value == null") ; + result = false ; + } else { + if (ps.length != 1) { + log.println("!!! Array length returned is invalid - " + + ps.length) ; + result = false ; + } + } + } catch (com.sun.star.beans.UnknownPropertyException e) { + log.println("Exception " + e + + "occurred while getting Property state"); + result = false; + } + + tRes.tested("getPropertyStates()", result); + } + + + /** + * Sets the property to default, then compares the current property + * value to value received by method <code>getPropertyDefault</code>. + * Has <b> OK </b> status if the current property value equals to + * default property. <p> + * The following method tests are to be completed successfully before : + * <ul> + * <li> <code>getPropertyDefault</code>: we have to know what is + * default value</li></ul> + */ + public void _setPropertyToDefault(){ + requiredMethod("getPropertyDefault()") ; + + if (pName == null) { + log.println("all found properties are read only"); + tRes.tested("setPropertyToDefault()",Status.skipped(true)); + return; + } + + boolean result = true ; + try { + try { + oObj.setPropertyToDefault(pName); + } + catch(RuntimeException e) { + System.out.println("Ignoring RuntimeException: " + e.getMessage()); + } + if ((properties[0].Attributes & + PropertyAttribute.MAYBEDEFAULT) != 0) { + Object actualDef = propDef ; + if (propDef instanceof Any) { + actualDef = ((Any)propDef).getObject() ; + } + Object actualVal = oPS.getPropertyValue(pName) ; + if (actualVal instanceof Any) { + actualVal = ((Any)actualVal).getObject() ; + } + result = util.ValueComparer.equalValue + (actualDef,actualVal) ; + log.println("Default value = '" + actualDef + + "', returned value = '" + + actualVal + "' for property " + pName) ; + } + } catch (com.sun.star.beans.UnknownPropertyException e) { + log.println("Exception " + e + + "occurred while setting Property to default"); + result=false; + } catch (com.sun.star.lang.WrappedTargetException e) { + log.println("Exception " + e + + "occurred while testing property value"); + result=false; + } + + tRes.tested("setPropertyToDefault()", result); + } + + @Override + public void after() { + disposeEnvironment() ; + } + + }// EOF _XPropertyState + diff --git a/qadevOOo/tests/java/ifc/beans/_XPropertyWithState.java b/qadevOOo/tests/java/ifc/beans/_XPropertyWithState.java new file mode 100644 index 000000000..9f93e0020 --- /dev/null +++ b/qadevOOo/tests/java/ifc/beans/_XPropertyWithState.java @@ -0,0 +1,101 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +package ifc.beans; + +import com.sun.star.beans.PropertyState; +import lib.MultiMethodTest; + +import com.sun.star.beans.XPropertyWithState; +import lib.Status; +import lib.StatusException; + +/** +* Testing <code>com.sun.star.beans.XPropertyWithState</code> +* interface methods : +* <ul> +* <li><code> getDefaultAsProperty()</code></li> +* <li><code> getStateAsProperty()</code></li> +* <li><code> setToDefaultAsProperty()</code></li> +* </ul> <p> +* @see com.sun.star.beans.XPropertyWithState +*/ + +public class _XPropertyWithState extends MultiMethodTest { + + /** + * the test object + */ + public XPropertyWithState oObj; + + + /** + * Test calls the method. + * Test has ok status if no + * <CODE>com.sun.star.lang.WrappedTargetException</CODE> + * was thrown + */ + public void _getDefaultAsProperty() { + try{ + + oObj.getDefaultAsProperty(); + + } catch (com.sun.star.lang.WrappedTargetException e){ + throw new StatusException(e, Status.failed("'com.sun.star.lang.WrappedTargetException' was thrown")); + } + + tRes.tested("getDefaultAsProperty()", true); + } + + /** + * Test is ok if <CODE>getStateAsProperty()</CODE> returns + * as <CODE>PropertyState</CODE> which is not <CODE>null</CODE> + */ + public void _getStateAsProperty() { + + boolean res = true; + + PropertyState propState = oObj.getStateAsProperty(); + + if (propState == null) { + log.println("the returned PropertyState is null -> FALSE"); + res = false; + } + + tRes.tested("getStateAsProperty()", res); + } + + /** + * Test calls the method. + * Test has ok status if no + * <CODE>com.sun.star.lang.WrappedTargetException</CODE> + * was thrown + */ + public void _setToDefaultAsProperty() { + try{ + + oObj.setToDefaultAsProperty(); + + } catch (com.sun.star.lang.WrappedTargetException e){ + throw new StatusException(e, Status.failed("'com.sun.star.lang.WrappedTargetException' was thrown")); + } + + tRes.tested("setToDefaultAsProperty()", true); + } + +} diff --git a/qadevOOo/tests/java/ifc/beans/_XTolerantMultiPropertySet.java b/qadevOOo/tests/java/ifc/beans/_XTolerantMultiPropertySet.java new file mode 100644 index 000000000..6860c8690 --- /dev/null +++ b/qadevOOo/tests/java/ifc/beans/_XTolerantMultiPropertySet.java @@ -0,0 +1,330 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +package ifc.beans; + +import com.sun.star.beans.GetDirectPropertyTolerantResult; +import com.sun.star.beans.GetPropertyTolerantResult; +import com.sun.star.beans.Property; +import com.sun.star.beans.PropertyAttribute; +import com.sun.star.beans.PropertyState; +import com.sun.star.beans.SetPropertyTolerantFailed; +import com.sun.star.beans.XPropertySet; +import com.sun.star.beans.XPropertyState; +import com.sun.star.beans.XTolerantMultiPropertySet; +import com.sun.star.uno.UnoRuntime; + +import java.util.ArrayList; +import java.util.Collections; + +import lib.MultiMethodTest; +import lib.Status; +import lib.StatusException; + +import util.ValueChanger; +import util.ValueComparer; + + +public class _XTolerantMultiPropertySet extends MultiMethodTest { + public XTolerantMultiPropertySet oObj; + protected String[] namesOfDirectProperties = null; + protected String[] namesOfProperties = null; + protected Object[] valuesOfProperties = null; + protected Property[] properties = null; + protected XPropertyState pState = null; + protected XPropertySet PS = null; + + + /* + * Queries XPropertySet from the given Component and gets XPropertySetInfo + * from it to get the PropertyNames available and their Values<br> + * Then queries XPropertyState from the given Component + * to get the direct properties<br> + * Throws a lib StatusException if the Component doesn't support XPropertySet or XPropertyState + */ + @Override + public void before() { + PS = UnoRuntime.queryInterface(XPropertySet.class, + tEnv.getTestObject()); + + if (PS == null) { + throw new StatusException(Status.failed( + "Component doesn't provide the needed XPropertySet")); + } + + pState = UnoRuntime.queryInterface( + XPropertyState.class, tEnv.getTestObject()); + + if (pState == null) { + throw new StatusException(Status.failed( + "Component doesn't provide the needed XPropertyState")); + } + + properties = PS.getPropertySetInfo().getProperties(); + namesOfProperties = getProperties(); + valuesOfProperties = getPropertyValues(namesOfProperties); + } + + /* + * Calls the method getDirectPropertyValuesTolerant() and compares the resulting + * sequence with the one gained as direct values in the before() method.<br> + * Has OK state if both sequences equal. + */ + public void _getDirectPropertyValuesTolerant() { + namesOfDirectProperties = getDirectProperties(properties); + + GetDirectPropertyTolerantResult[] GDPR = oObj.getDirectPropertyValuesTolerant( + namesOfProperties); + + boolean res = (GDPR.length == namesOfDirectProperties.length); + + if (!res) { + log.println("Found: "); + + for (int i = 0; i < GDPR.length; i++) { + log.println("\t" + GDPR[i].Name); + } + + log.println("Expected: "); + + for (int i = 0; i < namesOfDirectProperties.length; i++) { + log.println("\t" + namesOfDirectProperties[i]); + } + } else { + for (int i = 0; i < GDPR.length; i++) { + boolean localres = GDPR[i].Name.equals( + namesOfDirectProperties[i]); + + if (!localres) { + log.println("Found: "); + log.println("\t" + GDPR[i].Name); + log.println("Expected: "); + log.println("\t" + namesOfDirectProperties[i]); + } + + res &= localres; + } + } + + tRes.tested("getDirectPropertyValuesTolerant()", res); + } + + public void _getPropertyValuesTolerant() { + requiredMethod("getDirectPropertyValuesTolerant()"); + GetPropertyTolerantResult[] GPR = oObj.getPropertyValuesTolerant( + namesOfProperties); + + boolean res = (GPR.length == namesOfProperties.length); + + if (!res) { + log.println("Length of sequences differs"); + log.println("Found: " + GPR.length); + log.println("Expected: " + namesOfProperties.length); + } else { + for (int i = 0; i < GPR.length; i++) { + boolean localres = true; + + if (!(GPR[i].Value instanceof com.sun.star.uno.Any)) { + localres = ValueComparer.equalValue(GPR[i].Value, + valuesOfProperties[i]); + + } + + if (!localres) { + log.println("Values differ for : " + + namesOfProperties[i]); + log.println("\t" + GPR[i].Value); + log.println("Expected: "); + log.println("\t" + valuesOfProperties[i]); + } + + res &= localres; + } + } + + tRes.tested("getPropertyValuesTolerant()", res); + } + + public void _setPropertyValuesTolerant() { + requiredMethod("getPropertyValuesTolerant()"); + + SetPropertyTolerantFailed[] SPTF = oObj.setPropertyValuesTolerant(namesOfProperties, + getNewValues(valuesOfProperties)); + + //read only properties will throw a PropertyVetoException if they are set + int failures = 0; + + for (int k = 0; k < SPTF.length; k++) { + if (SPTF[k].Result == com.sun.star.beans.TolerantPropertySetResultType.PROPERTY_VETO) { + failures++; + } + } + + int roProps = getCountOfReadOnlyProperties(); + + boolean res = (failures == roProps); + + if (!res) { + log.println("Failures: " + failures); + log.println("Count of R/O properties: " + roProps); + + for (int i = 0; i < SPTF.length; i++) { + if (SPTF[i].Result == com.sun.star.beans.TolerantPropertySetResultType.PROPERTY_VETO) { + failures++; + log.println("Failed for " + SPTF[i].Name); + log.println("\t Result: " + SPTF[i].Result); + } + } + } else { + for (int i = 0; i < SPTF.length; i++) { + boolean localres = true; + GetPropertyTolerantResult[] GPR = oObj.getPropertyValuesTolerant( + namesOfProperties); + + if ((!(GPR[i].Value instanceof com.sun.star.uno.Any)) && + (SPTF[i].Result == com.sun.star.beans.TolerantPropertySetResultType.SUCCESS)) { + localres = ValueComparer.equalValue(GPR[i].Value, + valuesOfProperties[i]); + } + + if (!localres) { + log.println("Values differ for : " + + namesOfProperties[i]); + log.println("\t" + GPR[i].Value); + log.println("Expected: "); + log.println("\t" + valuesOfProperties[i]); + } + + res &= localres; + } + } + + tRes.tested("setPropertyValuesTolerant()", res); + } + + /* + * This method returns a sorted list of property names + * contained in a given sequence of properties that additionally + * have the state DIRECT_VALUE + */ + protected String[] getDirectProperties(Property[] props) { + ArrayList<String> direct = new ArrayList<String>(); + + for (int i = 0; i < props.length; i++) { + String pName = props[i].Name; + + try { + PropertyState state = pState.getPropertyState(pName); + + if (state.equals(PropertyState.DIRECT_VALUE) && isUsable(pName)) + direct.add(pName); + } catch (com.sun.star.beans.UnknownPropertyException e) { + log.println("Property '" + pName + "'"); + } + } + + Collections.sort(direct); + + Object[] obj = direct.toArray(); + String[] ret = new String[obj.length]; + + for (int i = 0; i < obj.length; i++) { + ret[i] = (String) obj[i]; + } + + return ret; + } + + private boolean isUsable(String name) { + boolean isUsable=true; + if (name.startsWith("TextWriting")) isUsable = false; + if (name.startsWith("MetaFile")) isUsable = false; + return isUsable; + } + + /* + * This method returns a sorted list of property names + * contained in a given sequence of properties + */ + protected String[] getProperties() { + ArrayList<String> names = new ArrayList<String>(); + + for (int i = 0; i < properties.length; i++) { + String pName = properties[i].Name; + if (isUsable(pName)) names.add(pName); + } + + Collections.sort(names); + + Object[] obj = names.toArray(); + String[] ret = new String[obj.length]; + + for (int i = 0; i < obj.length; i++) { + ret[i] = (String) obj[i]; + } + + return ret; + } + + /* + * Returns the values of a given array of properties in an Object array + */ + protected Object[] getPropertyValues(String[] propertyNames) { + Object[] values = new Object[propertyNames.length]; + + for (int i = 0; i < propertyNames.length; i++) { + try { + values[i] = PS.getPropertyValue(propertyNames[i]); + } catch (com.sun.star.beans.UnknownPropertyException e) { + e.printStackTrace(log); + } catch (com.sun.star.lang.WrappedTargetException e) { + e.printStackTrace(log); + } + } + + return values; + } + + protected int getCountOfReadOnlyProperties() { + int ro = 0; + + for (int i = 0; i < properties.length; i++) { + Property property = properties[i]; + boolean isWritable = ((property.Attributes & PropertyAttribute.READONLY) == 0); + + if (!isWritable) { + ro++; + } + } + + return ro; + } + + protected Object[] getNewValues(Object[] oldValues) { + Object[] newValues = new Object[oldValues.length]; + + for (int i = 0; i < oldValues.length; i++) { + if (oldValues[i] instanceof com.sun.star.uno.Any) { + newValues[i] = oldValues[i]; + } else { + newValues[i] = ValueChanger.changePValue(oldValues[i]); + } + } + + return newValues; + } +} |