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