1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 package ifc.beans; 28 29 import lib.MultiMethodTest; 30 import lib.Status; 31 import util.ValueChanger; 32 import util.ValueComparer; 33 34 import com.sun.star.beans.XHierarchicalPropertySetInfo; 35 import com.sun.star.beans.XMultiHierarchicalPropertySet; 36 37 38 public class _XMultiHierarchicalPropertySet extends MultiMethodTest { 39 public XMultiHierarchicalPropertySet oObj; 40 41 public void _getHierarchicalPropertySetInfo() { 42 XHierarchicalPropertySetInfo hpsi = oObj.getHierarchicalPropertySetInfo(); 43 boolean res = true; 44 45 if (hpsi != null) { 46 res = checkHPSI(hpsi); 47 } else { 48 log.println( 49 "The component doesn't provide HierarchicalPropertySetInfo"); 50 tRes.tested("getHierarchicalPropertySetInfo()", 51 Status.skipped(true)); 52 53 return; 54 } 55 56 tRes.tested("getMultiHierarchicalPropertySetInfo()", res); 57 } 58 59 public void _getHierarchicalPropertyValues() { 60 String[] pNames = (String[]) tEnv.getObjRelation("PropertyNames"); 61 String[] pTypes = (String[]) tEnv.getObjRelation("PropertyTypes"); 62 boolean res = true; 63 64 try { 65 Object[] getting = oObj.getHierarchicalPropertyValues(pNames); 66 res &= checkType(pNames, pTypes, getting); 67 } catch (com.sun.star.lang.IllegalArgumentException e) { 68 log.println("Exception " + e.getMessage()); 69 } catch (com.sun.star.lang.WrappedTargetException e) { 70 log.println("Exception " + e.getMessage()); 71 } 72 73 tRes.tested("getHierarchicalPropertyValues()", res); 74 } 75 76 public void _setHierarchicalPropertyValues() { 77 String ro = (String) tEnv.getObjRelation("allReadOnly"); 78 79 if (ro != null) { 80 log.println(ro); 81 tRes.tested("setHierarchicalPropertyValues()", 82 Status.skipped(true)); 83 84 return; 85 } 86 87 String[] pNames = (String[]) tEnv.getObjRelation("PropertyNames"); 88 boolean res = true; 89 90 try { 91 Object[] oldValues = oObj.getHierarchicalPropertyValues(pNames); 92 Object[] newValues = new Object[oldValues.length]; 93 94 for (int k = 0; k < oldValues.length; k++) { 95 newValues[k] = ValueChanger.changePValue(oldValues[k]); 96 } 97 98 oObj.setHierarchicalPropertyValues(pNames, newValues); 99 100 Object[] getValues = oObj.getHierarchicalPropertyValues(pNames); 101 102 for (int k = 0; k < pNames.length; k++) { 103 boolean localRes = ValueComparer.equalValue(getValues[k], 104 newValues[k]); 105 106 if (!localRes) { 107 log.println("didn't work for " + pNames[k]); 108 log.println("Expected " + newValues[k].toString()); 109 log.println("Getting " + getValues[k].toString()); 110 } 111 //reset properties 112 oObj.setHierarchicalPropertyValues(pNames, oldValues); 113 } 114 } catch (com.sun.star.lang.IllegalArgumentException e) { 115 log.println("IllegalArgument " + e.getMessage()); 116 } catch (com.sun.star.beans.PropertyVetoException e) { 117 log.println("VetoException " + e.getMessage()); 118 } catch (com.sun.star.lang.WrappedTargetException e) { 119 log.println("WrappedTarget " + e.getMessage()); 120 } 121 122 tRes.tested("setHierarchicalPropertyValues()", res); 123 } 124 125 protected boolean checkHPSI(XHierarchicalPropertySetInfo hpsi) { 126 log.println("Checking the resulting HierarchicalPropertySetInfo"); 127 log.println("### NOT yet implemented"); 128 129 return true; 130 } 131 132 protected boolean checkType(String[] name, String[] type, Object[] value) { 133 boolean result = true; 134 135 for (int k = 0; k < name.length; k++) { 136 if (type[k].equals("Boolean")) { 137 result &= (value[k] instanceof Boolean); 138 139 if (!(value[k] instanceof Boolean)) { 140 log.println("Wrong Type for property " + name[k]); 141 log.println("Expected " + type[k]); 142 log.println("getting " + value[k].getClass()); 143 } 144 } else if (type[k].equals("Short")) { 145 result &= (value[k] instanceof Short); 146 147 if (!(value[k] instanceof Short)) { 148 log.println("Wrong Type for property " + name[k]); 149 log.println("Expected " + type[k]); 150 log.println("getting " + value[k].getClass()); 151 } 152 } 153 } 154 155 return result; 156 } 157 }