merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / ifc / beans / _XHierarchicalPropertySet.java
blobe1634d7a0716314fb01bf235aaca7fbe66862bc5
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: _XHierarchicalPropertySet.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.XHierarchicalPropertySet;
38 import com.sun.star.beans.XHierarchicalPropertySetInfo;
41 public class _XHierarchicalPropertySet extends MultiMethodTest {
42 public XHierarchicalPropertySet 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("getHierarchicalPropertySetInfo()", res);
62 public void _getHierarchicalPropertyValue() {
63 String[] pNames = (String[]) tEnv.getObjRelation("PropertyNames");
64 String[] pTypes = (String[]) tEnv.getObjRelation("PropertyTypes");
65 boolean res = true;
67 for (int i = 0; i < pNames.length; i++) {
68 try {
69 log.print("Property " + pNames[i]);
71 Object getting = oObj.getHierarchicalPropertyValue(pNames[i]);
72 log.println(" has Value " + getting.toString());
73 res &= checkType(pNames[i], pTypes[i], getting);
74 } catch (com.sun.star.beans.UnknownPropertyException e) {
75 log.println(" is unknown");
76 } catch (com.sun.star.lang.IllegalArgumentException e) {
77 log.println(" is illegal");
78 } catch (com.sun.star.lang.WrappedTargetException e) {
79 log.println(" throws expeption " + e.getMessage());
83 tRes.tested("getHierarchicalPropertyValue()", res);
86 public void _setHierarchicalPropertyValue() {
87 String ro = (String) tEnv.getObjRelation("allReadOnly");
89 if (ro != null) {
90 log.println(ro);
91 tRes.tested("setHierarchicalPropertyValue()", Status.skipped(true));
93 return;
96 boolean res = true;
98 String[] pNames = (String[]) tEnv.getObjRelation("PropertyNames");
100 for (int k = 0; k < pNames.length; k++) {
101 try {
102 Object oldValue = oObj.getHierarchicalPropertyValue(pNames[k]);
103 Object newValue = ValueChanger.changePValue(oldValue);
104 oObj.setHierarchicalPropertyValue(pNames[k], newValue);
106 Object getValue = oObj.getHierarchicalPropertyValue(pNames[k]);
107 boolean localRes = ValueComparer.equalValue(getValue, newValue);
109 if (!localRes) {
110 log.println("Expected " + newValue.toString());
111 log.println("Gained " + getValue.toString());
115 //reset Value
116 oObj.setHierarchicalPropertyValue(pNames[k], oldValue);
118 res &= localRes;
119 } catch (com.sun.star.beans.UnknownPropertyException e) {
120 log.println("Property is unknown");
121 } catch (com.sun.star.lang.IllegalArgumentException e) {
122 log.println("IllegalArgument "+e.getMessage());
123 } catch (com.sun.star.beans.PropertyVetoException e) {
124 log.println("VetoException "+e.getMessage());
125 } catch (com.sun.star.lang.WrappedTargetException e) {
126 log.println("WrappedTarget "+e.getMessage());
131 tRes.tested("setHierarchicalPropertyValue()", res);
134 protected boolean checkHPSI(XHierarchicalPropertySetInfo hpsi) {
135 log.println("Checking the resulting HierarchicalPropertySetInfo");
136 log.println("### NOT yet implemented");
138 return true;
141 protected boolean checkType(String name, String type, Object value) {
142 boolean result = true;
144 if (type.equals("Boolean")) {
145 result = (value instanceof Boolean);
147 if (!result) {
148 log.println("Wrong Type for property " + name);
149 log.println("Expected " + type);
150 log.println("getting " + value.getClass());
152 } else if (type.equals("Short")) {
153 result = (value instanceof Short);
155 if (!result) {
156 log.println("Wrong Type for property " + name);
157 log.println("Expected " + type);
158 log.println("getting " + value.getClass());
162 return result;