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.XHierarchicalPropertySet;
31 import com.sun.star.beans.XHierarchicalPropertySetInfo;
32 
33 
34 public class _XHierarchicalPropertySet extends MultiMethodTest {
35     public XHierarchicalPropertySet 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("getHierarchicalPropertySetInfo()", res);
53     }
54 
_getHierarchicalPropertyValue()55     public void _getHierarchicalPropertyValue() {
56         String[] pNames = (String[]) tEnv.getObjRelation("PropertyNames");
57         String[] pTypes = (String[]) tEnv.getObjRelation("PropertyTypes");
58         boolean res = true;
59 
60         for (int i = 0; i < pNames.length; i++) {
61             try {
62                 log.print("Property " + pNames[i]);
63 
64                 Object getting = oObj.getHierarchicalPropertyValue(pNames[i]);
65                 log.println(" has Value " + getting.toString());
66                 res &= checkType(pNames[i], pTypes[i], getting);
67             } catch (com.sun.star.beans.UnknownPropertyException e) {
68                 log.println(" is unknown");
69             } catch (com.sun.star.lang.IllegalArgumentException e) {
70                 log.println(" is illegal");
71             } catch (com.sun.star.lang.WrappedTargetException e) {
72                 log.println(" throws expeption " + e.getMessage());
73             }
74         }
75 
76         tRes.tested("getHierarchicalPropertyValue()", res);
77     }
78 
_setHierarchicalPropertyValue()79     public void _setHierarchicalPropertyValue() {
80         String ro = (String) tEnv.getObjRelation("allReadOnly");
81 
82         if (ro != null) {
83             log.println(ro);
84             tRes.tested("setHierarchicalPropertyValue()", Status.skipped(true));
85 
86             return;
87         }
88 
89         boolean res = true;
90 
91         String[] pNames = (String[]) tEnv.getObjRelation("PropertyNames");
92 
93         for (int k = 0; k < pNames.length; k++) {
94             try {
95                 Object oldValue = oObj.getHierarchicalPropertyValue(pNames[k]);
96                 Object newValue = ValueChanger.changePValue(oldValue);
97                 oObj.setHierarchicalPropertyValue(pNames[k], newValue);
98 
99                 Object getValue = oObj.getHierarchicalPropertyValue(pNames[k]);
100                 boolean localRes = ValueComparer.equalValue(getValue, newValue);
101 
102                 if (!localRes) {
103                     log.println("Expected " + newValue.toString());
104                     log.println("Gained " + getValue.toString());
105                 }
106 
107 
108                 //reset Value
109                 oObj.setHierarchicalPropertyValue(pNames[k], oldValue);
110 
111                 res &= localRes;
112             } catch (com.sun.star.beans.UnknownPropertyException e) {
113                 log.println("Property is unknown");
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         }
123 
124         tRes.tested("setHierarchicalPropertyValue()", res);
125     }
126 
checkHPSI(XHierarchicalPropertySetInfo hpsi)127     protected boolean checkHPSI(XHierarchicalPropertySetInfo hpsi) {
128         log.println("Checking the resulting HierarchicalPropertySetInfo");
129         log.println("### NOT yet implemented");
130 
131         return true;
132     }
133 
checkType(String name, String type, Object value)134     protected boolean checkType(String name, String type, Object value) {
135         boolean result = true;
136 
137         if (type.equals("Boolean")) {
138             result = (value instanceof Boolean);
139 
140             if (!result) {
141                 log.println("Wrong Type for property " + name);
142                 log.println("Expected " + type);
143                 log.println("getting " + value.getClass());
144             }
145         } else if (type.equals("Short")) {
146             result = (value instanceof Short);
147 
148             if (!result) {
149                 log.println("Wrong Type for property " + name);
150                 log.println("Expected " + type);
151                 log.println("getting " + value.getClass());
152             }
153         }
154 
155         return result;
156     }
157 }