1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 package ifc.beans; 24 25 import lib.MultiMethodTest; 26 import lib.Status; 27 import util.ValueChanger; 28 import util.ValueComparer; 29 30 import com.sun.star.beans.XHierarchicalPropertySetInfo; 31 import com.sun.star.beans.XMultiHierarchicalPropertySet; 32 33 34 public class _XMultiHierarchicalPropertySet extends MultiMethodTest { 35 public XMultiHierarchicalPropertySet oObj; 36 _getHierarchicalPropertySetInfo()37 public void _getHierarchicalPropertySetInfo() { 38 XHierarchicalPropertySetInfo hpsi = oObj.getHierarchicalPropertySetInfo(); 39 boolean res = true; 40 41 if (hpsi != null) { 42 res = checkHPSI(hpsi); 43 } else { 44 log.println( 45 "The component doesn't provide HierarchicalPropertySetInfo"); 46 tRes.tested("getHierarchicalPropertySetInfo()", 47 Status.skipped(true)); 48 49 return; 50 } 51 52 tRes.tested("getMultiHierarchicalPropertySetInfo()", res); 53 } 54 _getHierarchicalPropertyValues()55 public void _getHierarchicalPropertyValues() { 56 String[] pNames = (String[]) tEnv.getObjRelation("PropertyNames"); 57 String[] pTypes = (String[]) tEnv.getObjRelation("PropertyTypes"); 58 boolean res = true; 59 60 try { 61 Object[] getting = oObj.getHierarchicalPropertyValues(pNames); 62 res &= checkType(pNames, pTypes, getting); 63 } catch (com.sun.star.lang.IllegalArgumentException e) { 64 log.println("Exception " + e.getMessage()); 65 } catch (com.sun.star.lang.WrappedTargetException e) { 66 log.println("Exception " + e.getMessage()); 67 } 68 69 tRes.tested("getHierarchicalPropertyValues()", res); 70 } 71 _setHierarchicalPropertyValues()72 public void _setHierarchicalPropertyValues() { 73 String ro = (String) tEnv.getObjRelation("allReadOnly"); 74 75 if (ro != null) { 76 log.println(ro); 77 tRes.tested("setHierarchicalPropertyValues()", 78 Status.skipped(true)); 79 80 return; 81 } 82 83 String[] pNames = (String[]) tEnv.getObjRelation("PropertyNames"); 84 boolean res = true; 85 86 try { 87 Object[] oldValues = oObj.getHierarchicalPropertyValues(pNames); 88 Object[] newValues = new Object[oldValues.length]; 89 90 for (int k = 0; k < oldValues.length; k++) { 91 newValues[k] = ValueChanger.changePValue(oldValues[k]); 92 } 93 94 oObj.setHierarchicalPropertyValues(pNames, newValues); 95 96 Object[] getValues = oObj.getHierarchicalPropertyValues(pNames); 97 98 for (int k = 0; k < pNames.length; k++) { 99 boolean localRes = ValueComparer.equalValue(getValues[k], 100 newValues[k]); 101 102 if (!localRes) { 103 log.println("didn't work for " + pNames[k]); 104 log.println("Expected " + newValues[k].toString()); 105 log.println("Getting " + getValues[k].toString()); 106 } 107 //reset properties 108 oObj.setHierarchicalPropertyValues(pNames, oldValues); 109 } 110 } catch (com.sun.star.lang.IllegalArgumentException e) { 111 log.println("IllegalArgument " + e.getMessage()); 112 } catch (com.sun.star.beans.PropertyVetoException e) { 113 log.println("VetoException " + e.getMessage()); 114 } catch (com.sun.star.lang.WrappedTargetException e) { 115 log.println("WrappedTarget " + e.getMessage()); 116 } 117 118 tRes.tested("setHierarchicalPropertyValues()", res); 119 } 120 checkHPSI(XHierarchicalPropertySetInfo hpsi)121 protected boolean checkHPSI(XHierarchicalPropertySetInfo hpsi) { 122 log.println("Checking the resulting HierarchicalPropertySetInfo"); 123 log.println("### NOT yet implemented"); 124 125 return true; 126 } 127 checkType(String[] name, String[] type, Object[] value)128 protected boolean checkType(String[] name, String[] type, Object[] value) { 129 boolean result = true; 130 131 for (int k = 0; k < name.length; k++) { 132 if (type[k].equals("Boolean")) { 133 result &= (value[k] instanceof Boolean); 134 135 if (!(value[k] instanceof Boolean)) { 136 log.println("Wrong Type for property " + name[k]); 137 log.println("Expected " + type[k]); 138 log.println("getting " + value[k].getClass()); 139 } 140 } else if (type[k].equals("Short")) { 141 result &= (value[k] instanceof Short); 142 143 if (!(value[k] instanceof Short)) { 144 log.println("Wrong Type for property " + name[k]); 145 log.println("Expected " + type[k]); 146 log.println("getting " + value[k].getClass()); 147 } 148 } 149 } 150 151 return result; 152 } 153 }