/libreoffice-3.6.0.2/javaunohelper/test/com/sun/star/lib/uno/helper/PropertySet_Test.java
Java | 1693 lines | 1513 code | 122 blank | 58 comment | 425 complexity | 3fa07b3bee4a7c8b123777cb1b7a3fa9 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, LGPL-2.1, AGPL-1.0, BSD-3-Clause-No-Nuclear-License-2014, GPL-3.0, LGPL-3.0
Large files files are truncated, but you can click here to view the full file
- /*************************************************************************
- *
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * Copyright 2000, 2010 Oracle and/or its affiliates.
- *
- * OpenOffice.org - a multi-platform office productivity suite
- *
- * This file is part of OpenOffice.org.
- *
- * OpenOffice.org is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License version 3
- * only, as published by the Free Software Foundation.
- *
- * OpenOffice.org is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License version 3 for more details
- * (a copy is included in the LICENSE file that accompanied this code).
- *
- * You should have received a copy of the GNU Lesser General Public License
- * version 3 along with OpenOffice.org. If not, see
- * <http://www.openoffice.org/license.html>
- * for a copy of the LGPLv3 License.
- *
- ************************************************************************/
- package com.sun.star.lib.uno.helper;
- import com.sun.star.lang.EventObject;
- import com.sun.star.lang.DisposedException;
- import com.sun.star.uno.Type;
- import com.sun.star.uno.TypeClass;
- import com.sun.star.uno.XInterface;
- import com.sun.star.uno.UnoRuntime;
- import com.sun.star.uno.Any;
- import com.sun.star.uno.XWeak;
- import com.sun.star.beans.XPropertySet;
- import com.sun.star.beans.UnknownPropertyException;
- import com.sun.star.beans.Property;
- import com.sun.star.beans.PropertyAttribute;
- import com.sun.star.beans.XPropertyChangeListener;
- import com.sun.star.beans.PropertyVetoException;
- import com.sun.star.beans.PropertyChangeEvent;
- import com.sun.star.beans.XVetoableChangeListener;
- import com.sun.star.beans.XPropertySetInfo;
- import com.sun.star.beans.XPropertiesChangeListener;
- import java.util.Arrays;
- public class PropertySet_Test
- {
- /** Creates a new instance of PropertySet_Test */
- public PropertySet_Test()
- {
- }
- public boolean convertPropertyValue()
- {
- System.out.println("PropertySet.convertPropertyValue");
- boolean[] r= new boolean[50];
- int i= 0;
- TestClass cl= new TestClass();
- try {
- r[i++]= cl.test_convertPropertyValue();
- }catch(java.lang.Exception e){
- i++;
- }
- boolean bOk= true;
- for (int c= 0; c < i; c++)
- bOk= bOk && r[c];
- if (bOk == false)
- System.out.println("Failed");
- else
- System.out.println("Ok");
- return bOk;
- }
- public boolean setPropertyValueNoBroadcast()
- {
- System.out.println("PropertySet.setValueNoBroadcast");
- boolean[] r= new boolean[50];
- int i= 0;
- TestClass cl= new TestClass();
- try {
- r[i++]= cl.test_setPropertyValueNoBroadcast();
- }catch(java.lang.Exception e){
- i++;
- }
- boolean bOk= true;
- for (int c= 0; c < i; c++)
- bOk= bOk && r[c];
- if (bOk == false)
- System.out.println("Failed");
- else
- System.out.println("Ok");
- return bOk;
- }
- public boolean setPropertyValue()
- {
- System.out.println("PropertySet.setPropertyValue");
- boolean[] r= new boolean[150];
- int i= 0;
- TestClass cl= new TestClass();
- try {
- cl.resetPropertyMembers();
- Object value;
- Object ret;
- value= new Boolean(true);
- cl.setPropertyValue("PropBoolA", value);
- ret= cl.getPropertyValue("PropBoolA");
- r[i++]= ((Boolean) ret).equals( (Boolean) value);
- value= new Character('A');
- cl.setPropertyValue("PropCharA",value);
- ret= cl.getPropertyValue("PropCharA");
- r[i++]= ((Character) ret).equals((Character) value);
- value= new Byte((byte) 111);
- cl.setPropertyValue("PropByteA",value);
- ret= cl.getPropertyValue("PropByteA");
- r[i++]= ((Byte) ret).equals((Byte) value);
- value= new Short((short)112);
- cl.setPropertyValue("PropShortA", value);
- ret= cl.getPropertyValue("PropShortA");
- r[i++]= ((Short) ret).equals((Short) value);
- value= new Integer(113);
- cl.setPropertyValue("PropIntA", value);
- ret= cl.getPropertyValue("PropIntA");
- r[i++]= ((Integer) ret).equals((Integer) value);
- value= new Long(115);
- cl.setPropertyValue("PropLongA", value);
- ret= cl.getPropertyValue("PropLongA");
- r[i++]= ((Long) ret).equals((Long) value);
- value= new Float(3.14);
- cl.setPropertyValue("PropFloatA", value);
- ret= cl.getPropertyValue("PropFloatA");
- r[i++]= ((Float) ret).equals((Float) value);
- value= new Double(3.145);
- cl.setPropertyValue("PropDoubleA",value);
- ret= cl.getPropertyValue("PropDoubleA");
- r[i++]= ((Double) ret).equals((Double) value);
- value= new String("string");
- cl.setPropertyValue("PropStringA",value);
- ret= cl.getPropertyValue("PropStringA");
- r[i++]= ((String) ret).equals((String) value);
- value= new ComponentBase();
- cl.setPropertyValue("PropXInterfaceA",value);
- ret= cl.getPropertyValue("PropXInterfaceA");
- r[i++]= ((XInterface) ret).equals((XInterface) value);
- value= new ComponentBase();
- cl.setPropertyValue("PropXWeakA",value);
- ret= cl.getPropertyValue("PropXWeakA");
- r[i++]= ((XWeak) ret).equals((XWeak) value);
- value = com.sun.star.beans.PropertyState.AMBIGUOUS_VALUE;
- cl.setPropertyValue("PropEnum",value);
- ret= cl.getPropertyValue("PropEnum");
- r[i++]= ret == value;
- value= new byte[]{1,2,3};
- cl.setPropertyValue("PropArrayByteA", value);
- ret= cl.getPropertyValue("PropArrayByteA");
- r[i++]= ((byte[]) ret).equals((byte[]) value);
- value= new Type(String.class);
- cl.setPropertyValue("PropTypeA", value);
- ret= cl.getPropertyValue("PropTypeA");
- r[i++]= ((Type) ret).equals(value);
- // test protected,package,private members
- value= new Boolean(true);
- cl.setPropertyValue("PropBoolB", value);
- ret= cl.getPropertyValue("PropBoolB");
- r[i++]= ((Boolean) ret).equals((Boolean) value);
- cl.setPropertyValue("PropBoolC", value);
- ret= cl.getPropertyValue("PropBoolC");
- r[i++]= ((Boolean) ret).equals((Boolean) value);
- try{
- cl.setPropertyValue("PropBoolD", value);
- i++;
- }catch (Exception e)
- {
- r[i++]= true;
- }
- cl.resetPropertyMembers();
- value= new Boolean(true);
- cl.setPropertyValue("PropObjectA", value);
- ret= cl.getPropertyValue("PropObjectA");
- r[i++]= ((Boolean) ret).equals((Boolean) value);
- value= new Character('A');
- cl.setPropertyValue("PropObjectA",value);
- ret= cl.getPropertyValue("PropObjectA");
- r[i++]= ((Character) ret).equals((Character) value);
- value= new Byte((byte) 111);
- cl.setPropertyValue("PropObjectA",value);
- ret= cl.getPropertyValue("PropObjectA");
- r[i++]= ((Byte) ret).equals((Byte) value);
- value= new Short((short)112);
- cl.setPropertyValue("PropObjectA", value);
- ret= cl.getPropertyValue("PropObjectA");
- r[i++]= ((Short) ret).equals((Short) value);
- value= new Integer(113);
- cl.setPropertyValue("PropObjectA", value);
- ret= cl.getPropertyValue("PropObjectA");
- r[i++]= ((Integer) ret).equals((Integer) value);
- value= new Long(115);
- cl.setPropertyValue("PropObjectA", value);
- ret= cl.getPropertyValue("PropObjectA");
- r[i++]= ((Long) ret).equals((Long) value);
- value= new Float(3.14);
- cl.setPropertyValue("PropObjectA", value);
- ret= cl.getPropertyValue("PropObjectA");
- r[i++]= ((Float) ret).equals((Float) value);
- value= new Double(3.145);
- cl.setPropertyValue("PropObjectA",value);
- ret= cl.getPropertyValue("PropObjectA");
- r[i++]= ((Double) ret).equals((Double) value);
- value= new String("string");
- cl.setPropertyValue("PropObjectA",value);
- ret= cl.getPropertyValue("PropObjectA");
- r[i++]= ((String) ret).equals((String) value);
- value= new ComponentBase();
- cl.setPropertyValue("PropObjectA",value);
- ret= cl.getPropertyValue("PropObjectA");
- r[i++]= ((XInterface) ret).equals((XInterface) value);
- value= new ComponentBase();
- cl.setPropertyValue("PropObjectA",value);
- ret= cl.getPropertyValue("PropObjectA");
- r[i++]= ((XWeak) ret).equals((XWeak) value);
- value= new byte[]{1,2,3};
- cl.setPropertyValue("PropObjectA", value);
- ret= cl.getPropertyValue("PropObjectA");
- r[i++]= ((byte[]) ret).equals((byte[]) value);
- value= new Type(String.class);
- cl.setPropertyValue("PropObjectA", value);
- ret= cl.getPropertyValue("PropObjectA");
- r[i++]= ((Type) ret).equals(value);
- cl.setPropertyValue("PropObjectA", new Any( new Type(byte.class), new Byte((byte)1)));
- ret= cl.getPropertyValue("PropObjectA");
- r[i++]= ((Byte) ret).byteValue() == 1;
- cl.resetPropertyMembers();
- value= new Boolean(true);
- cl.setPropertyValue("PropAnyA", value);
- ret= cl.getPropertyValue("PropAnyA");
- r[i++]= ret instanceof Any && util.anyEquals(value, ret);
- value= new Character('A');
- cl.setPropertyValue("PropAnyA",value);
- ret= cl.getPropertyValue("PropAnyA");
- r[i++]= ret instanceof Any && util.anyEquals(value, ret);
- value= new Byte((byte) 111);
- cl.setPropertyValue("PropAnyA",value);
- ret= cl.getPropertyValue("PropAnyA");
- r[i++]= ret instanceof Any && util.anyEquals(value, ret);
- value= new Short((short)112);
- cl.setPropertyValue("PropAnyA", value);
- ret= cl.getPropertyValue("PropAnyA");
- r[i++]= ret instanceof Any && util.anyEquals(value, ret);
- value= new Integer(113);
- cl.setPropertyValue("PropAnyA", value);
- ret= cl.getPropertyValue("PropAnyA");
- r[i++]= ret instanceof Any && util.anyEquals(value, ret);
- value= new Long(115);
- cl.setPropertyValue("PropAnyA", value);
- ret= cl.getPropertyValue("PropAnyA");
- r[i++]= ret instanceof Any && util.anyEquals(value, ret);
- value= new Float(3.14);
- cl.setPropertyValue("PropAnyA", value);
- ret= cl.getPropertyValue("PropAnyA");
- r[i++]= ret instanceof Any && util.anyEquals(value, ret);
- value= new Double(3.145);
- cl.setPropertyValue("PropAnyA",value);
- ret= cl.getPropertyValue("PropAnyA");
- r[i++]= ret instanceof Any && util.anyEquals(value, ret);
- value= new String("string");
- cl.setPropertyValue("PropAnyA",value);
- ret= cl.getPropertyValue("PropAnyA");
- r[i++]= ret instanceof Any && util.anyEquals(value, ret);
- value= new ComponentBase();
- cl.setPropertyValue("PropAnyA",value);
- ret= cl.getPropertyValue("PropAnyA");
- r[i++]= ret instanceof Any && util.anyEquals(value, ret);
- value= new ComponentBase();
- cl.setPropertyValue("PropAnyA",value);
- ret= cl.getPropertyValue("PropAnyA");
- r[i++]= ret instanceof Any && util.anyEquals(value, ret);
- value= new byte[]{1,2,3};
- cl.setPropertyValue("PropAnyA", value);
- ret= cl.getPropertyValue("PropAnyA");
- r[i++]= ret instanceof Any && util.anyEquals(value, ret);
- value= new Type(String.class);
- cl.setPropertyValue("PropAnyA", value);
- ret= cl.getPropertyValue("PropAnyA");
- r[i++]= ret instanceof Any && util.anyEquals(value, ret);
- cl.resetPropertyMembers();
- value= new Any(new Type(boolean.class), new Boolean(true));
- cl.setPropertyValue("PropBoolA", value);
- ret= cl.getPropertyValue("PropBoolA");
- r[i++]= ret instanceof Boolean && util.anyEquals(value, ret);
- value= new Any (new Type(char.class), new Character('A'));
- cl.setPropertyValue("PropCharA",value);
- ret= cl.getPropertyValue("PropCharA");
- r[i++]= ret instanceof Character && util.anyEquals(value, ret);
- value= new Any(new Type(byte.class), new Byte((byte) 111));
- cl.setPropertyValue("PropByteA",value);
- ret= cl.getPropertyValue("PropByteA");
- r[i++]= ret instanceof Byte && util.anyEquals(value, ret);
- value= new Any(new Type(short.class), new Short((short)112));
- cl.setPropertyValue("PropShortA", value);
- ret= cl.getPropertyValue("PropShortA");
- r[i++]= ret instanceof Short && util.anyEquals(value, ret);
- value= new Any(new Type(int.class), new Integer(113));
- cl.setPropertyValue("PropIntA", value);
- ret= cl.getPropertyValue("PropIntA");
- r[i++]= ret instanceof Integer && util.anyEquals(value, ret);
- value= new Any(new Type(long.class), new Long(115));
- cl.setPropertyValue("PropLongA", value);
- ret= cl.getPropertyValue("PropLongA");
- r[i++]= ret instanceof Long && util.anyEquals(value, ret);
- value= new Any(new Type(float.class), new Float(3.14));
- cl.setPropertyValue("PropFloatA", value);
- ret= cl.getPropertyValue("PropFloatA");
- r[i++]= ret instanceof Float && util.anyEquals(value, ret);
- value= new Any(new Type(double.class),new Double(3.145));
- cl.setPropertyValue("PropDoubleA",value);
- ret= cl.getPropertyValue("PropDoubleA");
- r[i++]= ret instanceof Double && util.anyEquals(value, ret);
- value= new Any(new Type(String.class), new String("string"));
- cl.setPropertyValue("PropStringA",value);
- ret= cl.getPropertyValue("PropStringA");
- r[i++]= ret instanceof String && util.anyEquals(value, ret);
- value= new Any(new Type(ComponentBase.class), new ComponentBase());
- cl.setPropertyValue("PropXInterfaceA",value);
- ret= cl.getPropertyValue("PropXInterfaceA");
- r[i++]= ret instanceof ComponentBase && util.anyEquals(value, ret);
- value= new Any( new Type(ComponentBase.class), new ComponentBase());
- cl.setPropertyValue("PropXWeakA",value);
- ret= cl.getPropertyValue("PropXWeakA");
- r[i++]= ret instanceof ComponentBase && util.anyEquals(value, ret);
- value= new Any(new Type(byte[].class), new byte[]{1,2,3});
- cl.setPropertyValue("PropArrayByteA", value);
- ret= cl.getPropertyValue("PropArrayByteA");
- r[i++]= ret instanceof byte[] && util.anyEquals(value, ret);
- value= new Any(new Type(Type.class), new Type(String.class));
- cl.setPropertyValue("PropTypeA", value);
- ret= cl.getPropertyValue("PropTypeA");
- r[i++]= ret instanceof Type && util.anyEquals(value, ret);
- cl.resetPropertyMembers();
- value= new Any(new Type(boolean.class), new Boolean(true));
- cl.setPropertyValue("PropAnyA", value);
- ret= cl.getPropertyValue("PropAnyA");
- r[i++]= ret instanceof Any && util.anyEquals(value, ret);
- value= new Any (new Type(char.class), new Character('A'));
- cl.setPropertyValue("PropAnyA",value);
- ret= cl.getPropertyValue("PropAnyA");
- r[i++]= ret instanceof Any && util.anyEquals(value, ret);
- value= new Any(new Type(byte.class), new Byte((byte) 111));
- cl.setPropertyValue("PropAnyA",value);
- ret= cl.getPropertyValue("PropAnyA");
- r[i++]= ret instanceof Any && util.anyEquals(value, ret);
- value= new Any(new Type(short.class), new Short((short)112));
- cl.setPropertyValue("PropAnyA", value);
- ret= cl.getPropertyValue("PropAnyA");
- r[i++]= ret instanceof Any && util.anyEquals(value, ret);
- value= new Any(new Type(int.class), new Integer(113));
- cl.setPropertyValue("PropAnyA", value);
- ret= cl.getPropertyValue("PropAnyA");
- r[i++]= ret instanceof Any && util.anyEquals(value, ret);
- value= new Any(new Type(long.class), new Long(115));
- cl.setPropertyValue("PropAnyA", value);
- ret= cl.getPropertyValue("PropAnyA");
- r[i++]= ret instanceof Any && util.anyEquals(value, ret);
- value= new Any(new Type(float.class), new Float(3.14));
- cl.setPropertyValue("PropAnyA", value);
- ret= cl.getPropertyValue("PropAnyA");
- r[i++]= ret instanceof Any && util.anyEquals(value, ret);
- value= new Any(new Type(double.class),new Double(3.145));
- cl.setPropertyValue("PropAnyA",value);
- ret= cl.getPropertyValue("PropAnyA");
- r[i++]= ret instanceof Any && util.anyEquals(value, ret);
- value= new Any(new Type(String.class), new String("string"));
- cl.setPropertyValue("PropAnyA",value);
- ret= cl.getPropertyValue("PropAnyA");
- r[i++]= ret instanceof Any && util.anyEquals(value, ret);
- value= new Any(new Type(ComponentBase.class), new ComponentBase());
- cl.setPropertyValue("PropAnyA",value);
- ret= cl.getPropertyValue("PropAnyA");
- r[i++]= ret instanceof Any && util.anyEquals(value, ret);
- value= new Any( new Type(ComponentBase.class), new ComponentBase());
- cl.setPropertyValue("PropAnyA",value);
- ret= cl.getPropertyValue("PropAnyA");
- r[i++]= ret instanceof Any && util.anyEquals(value, ret);
- value= new Any(new Type(byte[].class), new byte[]{1,2,3});
- cl.setPropertyValue("PropAnyA", value);
- ret= cl.getPropertyValue("PropAnyA");
- r[i++]= ret instanceof Any && util.anyEquals(value, ret);
- value= new Any(new Type(Type.class), new Type(String.class));
- cl.setPropertyValue("PropAnyA", value);
- ret= cl.getPropertyValue("PropAnyA");
- r[i++]= ret instanceof Any && util.anyEquals(value, ret);
- // ------------------------------------------------------------------------------
- cl.resetPropertyMembers();
- value= new Boolean(true);
- cl.setPropertyValue("PropBoolClass", value);
- ret= cl.getPropertyValue("PropBoolClass");
- r[i++]= ((Boolean) ret).equals( (Boolean) value);
- value= new Character('A');
- cl.setPropertyValue("PropCharClass",value);
- ret= cl.getPropertyValue("PropCharClass");
- r[i++]= ((Character) ret).equals((Character) value);
- value= new Byte((byte) 111);
- cl.setPropertyValue("PropByteClass",value);
- ret= cl.getPropertyValue("PropByteClass");
- r[i++]= ((Byte) ret).equals((Byte) value);
- value= new Short((short)112);
- cl.setPropertyValue("PropShortClass", value);
- ret= cl.getPropertyValue("PropShortClass");
- r[i++]= ((Short) ret).equals((Short) value);
- value= new Integer(113);
- cl.setPropertyValue("PropIntClass", value);
- ret= cl.getPropertyValue("PropIntClass");
- r[i++]= ((Integer) ret).equals((Integer) value);
- value= new Long(115);
- cl.setPropertyValue("PropLongClass", value);
- ret= cl.getPropertyValue("PropLongClass");
- r[i++]= ((Long) ret).equals((Long) value);
- value= new Float(3.14);
- cl.setPropertyValue("PropFloatClass", value);
- ret= cl.getPropertyValue("PropFloatClass");
- r[i++]= ((Float) ret).equals((Float) value);
- value= new Double(3.145);
- cl.setPropertyValue("PropDoubleClass",value);
- ret= cl.getPropertyValue("PropDoubleClass");
- r[i++]= ((Double) ret).equals((Double) value);
- cl.resetPropertyMembers();
- cl.resetPropertyMembers();
- value= new Any(new Type(boolean.class), new Boolean(true));
- cl.setPropertyValue("PropBoolClass", value);
- ret= cl.getPropertyValue("PropBoolClass");
- r[i++]= ret instanceof Boolean && util.anyEquals(value, ret);
- value= new Any (new Type(char.class), new Character('A'));
- cl.setPropertyValue("PropCharClass",value);
- ret= cl.getPropertyValue("PropCharClass");
- r[i++]= ret instanceof Character && util.anyEquals(value, ret);
- value= new Any(new Type(byte.class), new Byte((byte) 111));
- cl.setPropertyValue("PropByteClass",value);
- ret= cl.getPropertyValue("PropByteClass");
- r[i++]= ret instanceof Byte && util.anyEquals(value, ret);
- value= new Any(new Type(short.class), new Short((short)112));
- cl.setPropertyValue("PropShortClass", value);
- ret= cl.getPropertyValue("PropShortClass");
- r[i++]= ret instanceof Short && util.anyEquals(value, ret);
- value= new Any(new Type(int.class), new Integer(113));
- cl.setPropertyValue("PropIntClass", value);
- ret= cl.getPropertyValue("PropIntClass");
- r[i++]= ret instanceof Integer && util.anyEquals(value, ret);
- value= new Any(new Type(long.class), new Long(115));
- cl.setPropertyValue("PropLongClass", value);
- ret= cl.getPropertyValue("PropLongClass");
- r[i++]= ret instanceof Long && util.anyEquals(value, ret);
- value= new Any(new Type(float.class), new Float(3.14));
- cl.setPropertyValue("PropFloatClass", value);
- ret= cl.getPropertyValue("PropFloatClass");
- r[i++]= ret instanceof Float && util.anyEquals(value, ret);
- value= new Any(new Type(double.class),new Double(3.145));
- cl.setPropertyValue("PropDoubleClass",value);
- ret= cl.getPropertyValue("PropDoubleClass");
- r[i++]= ret instanceof Double && util.anyEquals(value, ret);
- value= new Any(new Type(String.class), new String("string"));
- // PropertyAttribute.READONLY
- cl.propBoolA.Attributes= PropertyAttribute.READONLY;
- try{
- cl.setPropertyValue("PropBoolA", new Boolean(true));
- i++;
- }catch (com.sun.star.beans.PropertyVetoException e)
- {
- r[i++]= true;
- }
- cl.propBoolA.Attributes= 0;
- // MAYBEVOID
- cl.resetPropertyMembers();
- // first MAYBEVOID not set
- //primitive members: must not work
- cl.boolPropA= false;
- try {
- cl.setPropertyValue("PropBoolA", null); i++;
- } catch (com.sun.star.lang.IllegalArgumentException e) {
- r[i++]= true;
- }
- try {
- cl.setPropertyValue("PropBoolA", new Any(new Type(boolean.class), null)); i++;
- } catch (com.sun.star.lang.IllegalArgumentException e) {
- r[i++]= true;
- }
- cl.propBoolA.Attributes= PropertyAttribute.MAYBEVOID;
- try{
- cl.setPropertyValue("PropBoolA", null); i++;
- } catch (com.sun.star.lang.IllegalArgumentException e) {
- r[i++]= true;
- }
- cl.propBoolA.Attributes= 0;
- cl.propBoolClass.Attributes= PropertyAttribute.MAYBEVOID;
- cl.boolClassProp= null;
- cl.setPropertyValue("PropBoolClass", null);
- r[i++]= cl.boolClassProp == null;
- // the returned value must be a void any
- Object objAny= cl.getPropertyValue("PropBoolClass");
- r[i++]= util.isVoidAny( objAny);
- cl.boolClassProp= new Boolean(true);
- cl.setPropertyValue("PropBoolClass", null);
- r[i++]= cl.boolClassProp == null;
- cl.boolClassProp= new Boolean(false);
- cl.setPropertyValue("PropBoolClass", new Any(new Type(boolean.class),null));
- r[i++]= cl.boolClassProp == null;
- cl.propXWeakA.Attributes= PropertyAttribute.MAYBEVOID;
- cl.setPropertyValue("PropXWeakA", null);
- r[i++]= util.isVoidAny(cl.getPropertyValue("PropXWeakA"));
- cl.propXWeakA.Attributes= 0;
- cl.anyPropA= null;
- try{
- cl.setPropertyValue("PropAnyA", null); i++;
- }catch (com.sun.star.lang.IllegalArgumentException e) {
- r[i++]= true;
- }
- cl.anyPropA= null;
- cl.propAnyA.Attributes= PropertyAttribute.MAYBEVOID;
- Type _t= new Type(Object.class);
- cl.setPropertyValue("PropAnyA", null);
- r[i++]= cl.anyPropA.getType().equals(new Type(void.class)) &&
- cl.anyPropA.getObject() == null;
- cl.anyPropA= new Any(new Type(byte.class),new Byte((byte) 111));
- cl.setPropertyValue("PropAnyA", null);
- r[i++]= cl.anyPropA.getType().equals(new Type(byte.class)) &&
- cl.anyPropA.getObject() == null;
- cl.anyPropA= null;
- try{
- cl.setPropertyValue("PropAnyA", new Object()); i++;
- }catch (com.sun.star.lang.IllegalArgumentException e)
- {
- r[i++]= true;
- }
- cl.propObjectA.Attributes= 0;
- try{
- cl.setPropertyValue("PropObjectA", null); i++;
- }catch (com.sun.star.lang.IllegalArgumentException e)
- {
- r[i++]= true;
- }
- try{
- cl.setPropertyValue("PropObjectA", new Any( new Type(byte.class), null)); i++;
- } catch (com.sun.star.lang.IllegalArgumentException e)
- {
- r[i++]= true;
- }
- cl.propObjectA.Attributes= PropertyAttribute.MAYBEVOID;
- cl.propObjectA= null;
- cl.setPropertyValue("PropObjectA", null);
- r[i++]= cl.propObjectA == null;
- cl.propObjectA= null;
- cl.setPropertyValue("PropObjectA", new Any( new Type(byte.class), null));
- r[i++]= cl.propObjectA == null;
- //
- }catch(java.lang.Exception e){
- i++;
- }
- boolean bOk= true;
- for (int c= 0; c < i; c++)
- bOk= bOk && r[c];
- if (bOk == false)
- System.out.println("Failed");
- else
- System.out.println("Ok");
- return bOk;
- }
- public boolean addPropertyChangeListener()
- {
- System.out.println("PropertySet.addPropertyChangeListener,\n" +
- "PropertySet.removePropertChangeListener," +
- "PropertySet.addVetoableChangeListener, \n" +
- "PropertySet.removeVetoableChangeListener" +
- "Notification of listeners");
- boolean[] r= new boolean[50];
- int i= 0;
- try {
- TestClass cl= new TestClass();
- Listener li= new Listener();
- cl.addPropertyChangeListener("PropByteA", li);
- Byte val1= new Byte((byte)115);
- cl.setPropertyValue("PropByteA", val1);
- r[i++]= li.nChangeCalled == 0 && li.nVetoCalled == 0;
- cl.propByteA.Attributes = PropertyAttribute.BOUND;
- cl.addPropertyChangeListener("PropByteA", li);
- Byte val2= new Byte((byte)116);
- cl.setPropertyValue("PropByteA", val2);
- r[i++]= li.nChangeCalled == 1 && li.nVetoCalled == 0;
- r[i++]= li.evt.OldValue.equals(val1) && li.evt.NewValue.equals(val2) && li.evt.Source == cl;
- li.reset();
- Listener li2= new Listener();
- cl.addPropertyChangeListener("PropByteA", li2);
- Byte val3= new Byte((byte) 117);
- cl.setPropertyValue("PropByteA", val3);
- r[i++]= li.nChangeCalled == 1 && li.nVetoCalled == 0
- && li2.nChangeCalled == 1 && li2.nVetoCalled == 0;
- r[i++]= li.evt.OldValue.equals(val2) && li.evt.NewValue.equals(val3) && li.evt.Source == cl
- && li2.evt.OldValue.equals(val2) && li2.evt.NewValue.equals(val3) && li2.evt.Source == cl ;
- li.reset();
- li2.reset();
- Listener li3= new Listener();
- val1= new Byte((byte)118);
- cl.addPropertyChangeListener("", li3);
- cl.setPropertyValue("PropByteA", val1);
- r[i++]= li.nChangeCalled == 1 && li.nVetoCalled == 0
- && li2.nChangeCalled == 1 && li2.nVetoCalled == 0
- && li3.nChangeCalled == 1 && li3.nVetoCalled == 0;
- r[i++]= li.evt.OldValue.equals(val3) && li.evt.NewValue.equals(val1) && li.evt.Source == cl;
- r[i++]= li2.evt.OldValue.equals(val3) && li2.evt.NewValue.equals(val1) && li2.evt.Source == cl;
- r[i++]= li3.evt.OldValue.equals(val3) && li3.evt.NewValue.equals(val1) && li3.evt.Source == cl ;
- li.reset();
- li2.reset();
- li3.reset();
- cl.removePropertyChangeListener("PropByteA",li);
- cl.setPropertyValue("PropByteA", val1);
- r[i++]= li.nChangeCalled == 0 && li.nVetoCalled == 0
- && li2.nChangeCalled == 1 && li2.nVetoCalled == 0
- && li3.nChangeCalled == 1 && li3.nVetoCalled == 0;
- cl.removePropertyChangeListener("PropByteA", li2);
- li.reset();
- li2.reset();
- li3.reset();
- cl.setPropertyValue("PropByteA", val1);
- r[i++]= li.nChangeCalled == 0 && li.nVetoCalled == 0
- && li2.nChangeCalled == 0 && li2.nVetoCalled == 0
- && li3.nChangeCalled == 1 && li3.nVetoCalled == 0;
- cl.removePropertyChangeListener("", li3);
- li.reset();
- li2.reset();
- li3.reset();
- cl.setPropertyValue("PropByteA", val2);
- r[i++]= li.nChangeCalled == 0 && li.nVetoCalled == 0
- && li2.nChangeCalled == 0 && li2.nVetoCalled == 0
- && li3.nChangeCalled == 0 && li3.nVetoCalled == 0;
- cl.addPropertyChangeListener("PropByteA", li);
- cl.addPropertyChangeListener("PropByteA", li2);
- cl.addPropertyChangeListener("", li3);
- cl.dispose();
- li.reset();
- li2.reset();
- li3.reset();
- try {
- cl.setPropertyValue("PropByteA", val2); i++;
- }catch (DisposedException e)
- {
- r[i++]= true;
- }
- //Vetoable tests
- cl= new TestClass();
- li.reset();
- li2.reset();
- li3.reset();
- cl.addVetoableChangeListener("PropByteA", li);
- val1= new Byte((byte)115);
- cl.setPropertyValue("PropByteA", val1);
- r[i++]= li.nChangeCalled == 0 && li.nVetoCalled == 0;
- cl.propByteA.Attributes = PropertyAttribute.CONSTRAINED;
- cl.addVetoableChangeListener("PropByteA", li);
- val2= new Byte((byte)116);
- li.reset();
- cl.setPropertyValue("PropByteA", val2);
- r[i++]= li.nChangeCalled == 0 && li.nVetoCalled == 1;
- r[i++]= li.evt.OldValue.equals(val1) && li.evt.NewValue.equals(val2) && li.evt.Source == cl;
- li.reset();
- li2.reset();
- li3.reset();
- cl.addVetoableChangeListener("PropByteA", li2);
- val3= new Byte((byte) 117);
- cl.setPropertyValue("PropByteA", val3);
- r[i++]= li.nChangeCalled == 0 && li.nVetoCalled == 1
- && li2.nChangeCalled == 0 && li2.nVetoCalled == 1;
- r[i++]= li.evt.OldValue.equals(val2) && li.evt.NewValue.equals(val3) && li.evt.Source == cl
- && li2.evt.OldValue.equals(val2) && li2.evt.NewValue.equals(val3) && li2.evt.Source == cl ;
- li.reset();
- li2.reset();
- li3.reset();
- val1= new Byte((byte)118);
- cl.addVetoableChangeListener("", li3);
- cl.setPropertyValue("PropByteA", val1);
- r[i++]= li.nChangeCalled == 0 && li.nVetoCalled == 1
- && li2.nChangeCalled == 0 && li2.nVetoCalled == 1
- && li3.nChangeCalled == 0 && li3.nVetoCalled == 1;
- r[i++]= li.evt.OldValue.equals(val3) && li.evt.NewValue.equals(val1) && li.evt.Source == cl;
- r[i++]= li2.evt.OldValue.equals(val3) && li2.evt.NewValue.equals(val1) && li2.evt.Source == cl;
- r[i++]= li3.evt.OldValue.equals(val3) && li3.evt.NewValue.equals(val1) && li3.evt.Source == cl ;
- li.reset();
- li2.reset();
- li3.reset();
- // Test Veto Exception
- cl.setPropertyValue("PropByteA", val1);
- li.bVeto= true;
- try {
- cl.setPropertyValue("PropByteA", val2);i++;
- } catch (PropertyVetoException e)
- {
- r[i++]= true;
- }
- r[i++]= cl.bytePropA == val1.byteValue();
- li.bVeto= false;
- li.reset();
- li2.reset();
- li3.reset();
- cl.removeVetoableChangeListener("PropByteA",li);
- cl.setPropertyValue("PropByteA", val1);
- r[i++]= li.nChangeCalled == 0 && li.nVetoCalled == 0
- && li2.nChangeCalled == 0 && li2.nVetoCalled == 1
- && li3.nChangeCalled == 0 && li3.nVetoCalled == 1;
- cl.removeVetoableChangeListener("PropByteA", li2);
- li.reset();
- li2.reset();
- li3.reset();
- cl.setPropertyValue("PropByteA", val1);
- r[i++]= li.nChangeCalled == 0 && li.nVetoCalled == 0
- && li2.nChangeCalled == 0 && li2.nVetoCalled == 0
- && li3.nChangeCalled == 0 && li3.nVetoCalled == 1;
- cl.removeVetoableChangeListener("", li3);
- li.reset();
- li2.reset();
- li3.reset();
- cl.setPropertyValue("PropByteA", val2);
- r[i++]= li.nChangeCalled == 0 && li.nVetoCalled == 0
- && li2.nChangeCalled == 0 && li2.nVetoCalled == 0
- && li3.nChangeCalled == 0 && li3.nVetoCalled == 0;
- cl.addVetoableChangeListener("PropByteA", li);
- cl.addVetoableChangeListener("PropByteA", li2);
- cl.addVetoableChangeListener("", li3);
- cl.dispose();
- li.reset();
- li2.reset();
- li3.reset();
- try {
- cl.setPropertyValue("PropByteA", val2);
- }catch (DisposedException e)
- {
- r[i++]= true;
- }
- }catch (Exception e)
- {
- i++;
- }
- boolean bOk= true;
- for (int c= 0; c < i; c++)
- bOk= bOk && r[c];
- if (bOk == false)
- System.out.println("Failed");
- else
- System.out.println("Ok");
- return bOk;
- }
- public boolean getPropertySetInfo()
- {
- System.out.println("PropertySet.getPropertySetInfo");
- boolean[] r= new boolean[50];
- int i= 0;
- TestClass cl= new TestClass();
- try {
- XPropertySetInfo info= cl.getPropertySetInfo();
- Property[] arProps= info.getProperties();
- Property[] arRegProps= cl.getRegisteredProperties();
- r[i++]= arProps.length == arRegProps.length;
- for (int j= 0; j < arProps.length; j++)
- {
- boolean bFound= false;
- for (int k= 0; k < arRegProps.length; k++)
- {
- if (arProps[j] == arRegProps[k])
- {
- bFound= true;
- break;
- }
- }
- if ( !bFound)
- r[i++]= false;
- }
- for (int j= 0; j < arRegProps.length; j++)
- {
- Property prop= info.getPropertyByName(arRegProps[j].Name);
- if (prop != arRegProps[j])
- r[i++]= false;
- if (! info.hasPropertyByName(arRegProps[j].Name))
- r[i++]= false;
- }
- }catch(java.lang.Exception e){
- System.out.println(e.getMessage());
- i++;
- }
- boolean bOk= true;
- for (int c= 0; c < i; c++)
- bOk= bOk && r[c];
- if (bOk == false)
- System.out.println("Failed");
- else
- System.out.println("Ok");
- return bOk;
- }
- public boolean setFastPropertyValue()
- {
- System.out.println("PropertySet.setFastPropertyValue");
- boolean[] r= new boolean[50];
- int i= 0;
- TestClass cl= new TestClass();
- try {
- cl.setFastPropertyValue(5, new Integer(111));
- r[i++]= cl.intPropA == 111;
- try {
- cl.setFastPropertyValue(-1, new Integer(1)); i++;
- } catch(UnknownPropertyException e)
- {
- r[i++]= true;
- }
- }catch(java.lang.Exception e){
- System.out.println(e.getMessage());
- i++;
- }
- boolean bOk= true;
- for (int c= 0; c < i; c++)
- bOk= bOk && r[c];
- if (bOk == false)
- System.out.println("Failed");
- else
- System.out.println("Ok");
- return bOk;
- }
- public boolean getFastPropertyValue()
- {
- System.out.println("PropertySet.setFastPropertyValue");
- boolean[] r= new boolean[50];
- int i= 0;
- TestClass cl= new TestClass();
- try {
- cl.setFastPropertyValue(5, new Integer(111));
- Integer aInt= (Integer) cl.getFastPropertyValue(5);
- r[i++]= aInt.intValue() == 111;
- }catch(java.lang.Exception e){
- System.out.println(e.getMessage());
- i++;
- }
- boolean bOk= true;
- for (int c= 0; c < i; c++)
- bOk= bOk && r[c];
- if (bOk == false)
- System.out.println("Failed");
- else
- System.out.println("Ok");
- return bOk;
- }
- public boolean setPropertyValues()
- {
- System.out.println("PropertySet.setPropertyValues");
- boolean[] r= new boolean[50];
- int i= 0;
- TestClass cl= new TestClass();
- try {
- cl.setPropertyValues(new String[0], new Object[0]);
- String[] arNames= new String[] {"PropCharA","PropIntClass","PropObjectA"};
- Character aChar= new Character('A');
- Integer aInt= new Integer(111);
- Byte aByte= new Byte((byte)11);
- Object[] values= new Object[]{aChar, aInt, aByte};
- cl.setPropertyValues(arNames, values);
- r[i++]= cl.charPropA == 'A' && cl.intClassProp.intValue() == 111 && ((Byte)cl.objectPropA).byteValue() == 11;
- arNames= new String[] {"blabla","PropIntClass","PropObjectA"};
- cl.resetPropertyMembers();
- cl.setPropertyValues(arNames, values);
- r[i++]= cl.intClassProp.intValue() == 111 && ((Byte)cl.objectPropA).byteValue() == 11;
- }catch(java.lang.Exception e){
- System.out.println(e.getMessage());
- i++;
- }
- boolean bOk= true;
- for (int c= 0; c < i; c++)
- bOk= bOk && r[c];
- if (bOk == false)
- System.out.println("Failed");
- else
- System.out.println("Ok");
- return bOk;
- }
- public boolean getPropertyValues()
- {
- System.out.println("PropertySet.getPropertyValues");
- boolean[] r= new boolean[50];
- int i= 0;
- TestClass cl= new TestClass();
- try {
- cl.charPropA= 'A';
- cl.intClassProp= new Integer(111);
- cl.objectPropA= new Byte((byte)11);
- Object[] values= cl.getPropertyValues(new String[] {"PropCharA","PropIntClass","PropObjectA"});
- r[i++]= ((Character) values[0]).charValue() == 'A' && ((Integer) values[1]).intValue() == 111
- && ((Byte) values[2]).byteValue() == 11;
- }catch(java.lang.Exception e){
- System.out.println(e.getMessage());
- i++;
- }
- boolean bOk= true;
- for (int c= 0; c < i; c++)
- bOk= bOk && r[c];
- if (bOk == false)
- System.out.println("Failed");
- else
- System.out.println("Ok");
- return bOk;
- }
- // Currently the listeners are always notified if one of properties has changed.
- // The property names in the first argument are ignored.
- public boolean addPropertiesChangeListener()
- {
- System.out.println("PropertySet.addPropertiesChangeListener\n" +
- "PropertySet.removePropertiesChangeListener\n" +
- "notification of such listeners");
- boolean[] r= new boolean[50];
- int i= 0;
- TestClass cl= new TestClass();
- try {
- Listener li1= new Listener();
- Listener li2= new Listener();
- cl.addPropertiesChangeListener(new String[]{"PropCharA"}, li1);
- cl.setPropertyValue("PropCharA", new Character('B'));
- r[i++]= li1.nPropertiesChange == 0;
- cl.propCharA.Attributes= PropertyAttribute.BOUND;
- cl.setPropertyValue("PropCharA", new Character('C'));
- r[i++]= li1.nPropertiesChange == 1;
- PropertyChangeEvent evt= li1.arEvt[0];
- r[i++]= evt.PropertyName.equals("PropCharA") && ((Character)evt.OldValue).charValue() == 'B'
- && ((Character) evt.NewValue).charValue() == 'C';
- li1.reset();
- cl.removePropertiesChangeListener(li1);
- cl.setPropertyValue("PropCharA", new Character('F'));
- r[i++]= li1.nPropertiesChange == 0;
- }catch(java.lang.Exception e){
- System.out.println(e.getMessage());
- i++;
- }
- boolean bOk= true;
- for (int c= 0; c < i; c++)
- bOk= bOk && r[c];
- if (bOk == false)
- System.out.println("Failed");
- else
- System.out.println("Ok");
- return bOk;
- }
- public boolean firePropertiesChangeEvent()
- {
- System.out.println("PropertySet.firePropertiesChangeEvent");
- boolean[] r= new boolean[50];
- int i= 0;
- TestClass cl= new TestClass();
- try {
- Listener li1= new Listener();
- cl.intClassProp= new Integer(111);
- cl.charPropA= 'A';
- cl.firePropertiesChangeEvent(new String[]{"PropCharA","PropIntClass"}, li1);
- r[i++]= li1.nPropertiesChange == 1;
- PropertyChangeEvent[] arEvt= li1.arEvt;
- r[i++]= arEvt[0].PropertyName.equals("PropCharA")
- && ((Character) arEvt[0].OldValue).charValue() == 'A'
- && ((Character) arEvt[0].NewValue).charValue() == 'A';
- r[i++]= arEvt[1].PropertyName.equals("PropIntClass")
- && ((Integer) arEvt[1].OldValue).intValue() == 111
- && ((Integer) arEvt[1].NewValue).intValue() == 111;
- }catch(java.lang.Exception e){
- System.out.println(e.getMessage());
- i++;
- }
- boolean bOk= true;
- for (int c= 0; c < i; c++)
- bOk= bOk && r[c];
- if (bOk == false)
- System.out.println("Failed");
- else
- System.out.println("Ok");
- return bOk;
- }
- public boolean registerProperty1()
- {
- TestClass2 cl= new TestClass2();
- return cl.test_registerProperty1();
- }
- public boolean registerProperty2()
- {
- TestClass2 cl= new TestClass2();
- return cl.test_registerProperty2();
- }
- public static boolean test()
- {
- PropertySet_Test test= new PropertySet_Test();
- boolean r[]= new boolean[50];
- int i= 0;
- r[i++]= test.convertPropertyValue();
- r[i++]= test.setPropertyValueNoBroadcast();
- r[i++]= test.setPropertyValue();
- r[i++]= test.addPropertyChangeListener();
- r[i++]= test.getPropertySetInfo();
- r[i++]= test.setFastPropertyValue();
- r[i++]= test.getFastPropertyValue();
- r[i++]= test.setPropertyValues();
- r[i++]= test.getPropertyValues();
- r[i++]= test.addPropertiesChangeListener();
- r[i++]= test.firePropertiesChangeEvent();
- r[i++]= test.registerProperty1();
- r[i++]= test.registerProperty2();
- boolean bOk= true;
- for (int c= 0; c < i; c++)
- bOk= bOk && r[c];
- if (bOk == false)
- System.out.println("Errors occurred!");
- else
- System.out.println("No errors.");
- return bOk;
- }
- public static void main(String[] args)
- {
- test();
- }
- }
- class TestClass extends PropertySet
- {
- public Property propBoolA= new Property("PropBoolA", 1, new Type(Boolean.TYPE), (short)0);
- public boolean boolPropA;
- public Property propCharA= new Property("PropCharA", 2, new Type(Character.TYPE), (short) 0);
- public char charPropA;
- public Property propByteA= new Property("PropByteA", 3, new Type(Byte.TYPE), (short) 0);
- public byte bytePropA;
- public Property propShortA= new Property("PropShortA", 4, new Type(Short.TYPE), (short) 0);
- public short shortPropA;
- public Property propIntA= new Property("PropIntA", 5, new Type(Integer.TYPE), (short) 0);
- public int intPropA;
- public Property propLongA= new Property("PropLongA", 6, new Type(Long.TYPE), (short) 0);
- public long longPropA;
- public Property propFloatA= new Property("PropFloatA", 7, new Type(Float.TYPE), (short) 0);
- public float floatPropA;
- public Property propDoubleA= new Property("PropDoubleA", 8, new Type(Double.TYPE), (short) 0);
- public double doublePropA;
- public Property propStringA= new Property("PropStringA", 9, new Type(String.class), (short) 0);
- public String stringPropA;
- public Property propArrayByteA= new Property("PropArrayByteA", 10, new Type(byte[].class), (short) 0);
- public byte[] arBytePropA;
- public Property propTypeA= new Property("PropTypeA", 11, new Type(Type.class), (short) 0);
- public Type typePropA;
- public Property propObjectA= new Property("PropObjectA",12, new Type(Object.class), (short) 0);
- public Object objectPropA;
- public Property propAnyA= new Property("PropAnyA", 13, new Type(Any.class), (short) 0);
- public Any anyPropA;
- public Property propXInterfaceA= new Property("PropXInterfaceA", 13, new Type(Any.class), (short) 0);
- public XInterface xInterfacePropA;
- public Property propXWeakA= new Property("PropXWeakA", 13, new Type(Any.class), (short) 0);
- public XWeak xWeakPropA;
- public Property propEnum =
- new Property("PropEnum", 14, new Type("com.sun.star.beans.PropertyState", TypeClass.ENUM), (short)0);
- public com.sun.star.beans.PropertyState enumPropertyState = com.sun.star.beans.PropertyState.DEFAULT_VALUE;
- // Test private, protected, package access, Anys as arguments and members, members whith a value
- public Property propBoolB= new Property("PropBoolB", 101, new Type(Boolean.TYPE), (short) 0);
- protected boolean boolPropB;
- public Property propBoolC= new Property("PropBoolC", 201, new Type(Boolean.TYPE), (short) 0);
- boolean boolPropC;
- public Property propBoolD= new Property("PropBoolD", 301, new Type(Boolean.TYPE), (short) 0);
- private boolean boolPropD;
- public Property propBoolClass= new Property("PropBoolClass", 1001, new Type(Boolean.class), (short) 0);
- public Boolean boolClassProp;
- public Property propCharClass= new Property("PropCharClass", 1002, new Type(Character.class), (short) 0);
- public Character charClassProp;
- public Property propByteClass= new Property("PropByteClass", 1003, new Type(Byte.class), (short) 0);
- public Byte byteClassProp;
- public Property propShortClass= new Property("PropShortClass", 1004, new Type(Short.class), (short) 0);
- public Short shortClassProp;
- public Property propIntClass= new Property("PropIntClass", 1005, new Type(Integer.class), (short) 0);
- public Integer intClassProp;
- public Property propLongClass= new Property("PropLongClass", 1006, new Type(Long.class), (short) 0);
- public Long longClassProp;
- public Property propFloatClass= new Property("PropFloatClass", 1007, new Type(Float.class), (short) 0);
- public Float floatClassProp;
- public Property propDoubleClass= new Property("PropDoubleClass", 1008, new Type(Double.class), (short) 0);
- public Double doubleClas…
Large files files are truncated, but you can click here to view the full file