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