1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 package ifc.beans;
28 
29 import lib.MultiMethodTest;
30 import lib.Status;
31 import util.ValueChanger;
32 import util.ValueComparer;
33 
34 import com.sun.star.beans.XHierarchicalPropertySet;
35 import com.sun.star.beans.XHierarchicalPropertySetInfo;
36 
37 
38 public class _XHierarchicalPropertySet extends MultiMethodTest {
39     public XHierarchicalPropertySet oObj;
40 
41     public void _getHierarchicalPropertySetInfo() {
42         XHierarchicalPropertySetInfo hpsi = oObj.getHierarchicalPropertySetInfo();
43         boolean res = true;
44 
45         if (hpsi != null) {
46             res = checkHPSI(hpsi);
47         } else {
48             log.println(
49                     "The component doesn't provide HierarchicalPropertySetInfo");
50             tRes.tested("getHierarchicalPropertySetInfo()",
51                         Status.skipped(true));
52 
53             return;
54         }
55 
56         tRes.tested("getHierarchicalPropertySetInfo()", res);
57     }
58 
59     public void _getHierarchicalPropertyValue() {
60         String[] pNames = (String[]) tEnv.getObjRelation("PropertyNames");
61         String[] pTypes = (String[]) tEnv.getObjRelation("PropertyTypes");
62         boolean res = true;
63 
64         for (int i = 0; i < pNames.length; i++) {
65             try {
66                 log.print("Property " + pNames[i]);
67 
68                 Object getting = oObj.getHierarchicalPropertyValue(pNames[i]);
69                 log.println(" has Value " + getting.toString());
70                 res &= checkType(pNames[i], pTypes[i], getting);
71             } catch (com.sun.star.beans.UnknownPropertyException e) {
72                 log.println(" is unknown");
73             } catch (com.sun.star.lang.IllegalArgumentException e) {
74                 log.println(" is illegal");
75             } catch (com.sun.star.lang.WrappedTargetException e) {
76                 log.println(" throws expeption " + e.getMessage());
77             }
78         }
79 
80         tRes.tested("getHierarchicalPropertyValue()", res);
81     }
82 
83     public void _setHierarchicalPropertyValue() {
84         String ro = (String) tEnv.getObjRelation("allReadOnly");
85 
86         if (ro != null) {
87             log.println(ro);
88             tRes.tested("setHierarchicalPropertyValue()", Status.skipped(true));
89 
90             return;
91         }
92 
93         boolean res = true;
94 
95         String[] pNames = (String[]) tEnv.getObjRelation("PropertyNames");
96 
97         for (int k = 0; k < pNames.length; k++) {
98             try {
99                 Object oldValue = oObj.getHierarchicalPropertyValue(pNames[k]);
100                 Object newValue = ValueChanger.changePValue(oldValue);
101                 oObj.setHierarchicalPropertyValue(pNames[k], newValue);
102 
103                 Object getValue = oObj.getHierarchicalPropertyValue(pNames[k]);
104                 boolean localRes = ValueComparer.equalValue(getValue, newValue);
105 
106                 if (!localRes) {
107                     log.println("Expected " + newValue.toString());
108                     log.println("Gained " + getValue.toString());
109                 }
110 
111 
112                 //reset Value
113                 oObj.setHierarchicalPropertyValue(pNames[k], oldValue);
114 
115                 res &= localRes;
116             } catch (com.sun.star.beans.UnknownPropertyException e) {
117                 log.println("Property is unknown");
118             } catch (com.sun.star.lang.IllegalArgumentException e) {
119                 log.println("IllegalArgument "+e.getMessage());
120             } catch (com.sun.star.beans.PropertyVetoException e) {
121                 log.println("VetoException "+e.getMessage());
122             } catch (com.sun.star.lang.WrappedTargetException e) {
123                 log.println("WrappedTarget "+e.getMessage());
124             }
125 
126         }
127 
128         tRes.tested("setHierarchicalPropertyValue()", res);
129     }
130 
131     protected boolean checkHPSI(XHierarchicalPropertySetInfo hpsi) {
132         log.println("Checking the resulting HierarchicalPropertySetInfo");
133         log.println("### NOT yet implemented");
134 
135         return true;
136     }
137 
138     protected boolean checkType(String name, String type, Object value) {
139         boolean result = true;
140 
141         if (type.equals("Boolean")) {
142             result = (value instanceof Boolean);
143 
144             if (!result) {
145                 log.println("Wrong Type for property " + name);
146                 log.println("Expected " + type);
147                 log.println("getting " + value.getClass());
148             }
149         } else if (type.equals("Short")) {
150             result = (value instanceof Short);
151 
152             if (!result) {
153                 log.println("Wrong Type for property " + name);
154                 log.println("Expected " + type);
155                 log.println("getting " + value.getClass());
156             }
157         }
158 
159         return result;
160     }
161 }