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 
24 package ifc.chart;
25 
26 import lib.MultiPropertyTest;
27 import lib.Status;
28 import lib.StatusException;
29 
30 import com.sun.star.beans.XPropertySet;
31 import com.sun.star.chart.XChartDocument;
32 import com.sun.star.chart.XDiagram;
33 import com.sun.star.uno.UnoRuntime;
34 
35 /**
36 * Testing <code>com.sun.star.chart.ChartAxisZSupplier</code>
37 * service properties :
38 * <ul>
39 *  <li><code> HasZAxis</code></li>
40 *  <li><code> HasZAxisDescription</code></li>
41 *  <li><code> HasZAxisGrid</code></li>
42 *  <li><code> HasZAxisHelpGrid</code></li>
43 *  <li><code> HasZAxisTitle</code></li>
44 * </ul> <p>
45 * This test needs the following object relations :
46 * <ul>
47 *  <li> <code>'CHARTDOC'</code> (of type <code>XChartDocument</code>):
48 *  to have reference to chart document </li>
49 *  <li> <code>'BAR'</code> (of type <code>XDiagram</code>):
50 *  relation that use as parameter for method setDiagram of chart document</li>
51 * </ul> <p>
52 * @see com.sun.star.chart.ChartAxisZSupplier
53 */
54 public class _ChartAxisZSupplier extends MultiPropertyTest {
55 
56     /**
57     * Retrieves object relations and prepares a chart document.
58     * @throws StatusException if one of relations not found.
59     */
before()60     protected void before() {
61         log.println("Setting Diagram type to BarDiagram");
62         XChartDocument doc = (XChartDocument) tEnv.getObjRelation("CHARTDOC");
63         if (doc == null) throw new StatusException(Status.failed
64             ("Relation 'CHARTDOC' not found"));
65 
66         XDiagram bar = (XDiagram) tEnv.getObjRelation("BAR");
67         if (bar == null) throw new StatusException(Status.failed
68             ("Relation 'BAR' not found"));
69 
70         doc.setDiagram(bar);
71         log.println("Set it to 3D");
72         oObj = (XPropertySet)
73             UnoRuntime.queryInterface( XPropertySet.class, doc.getDiagram() );
74         try {
75             oObj.setPropertyValue("Dim3D", new Boolean(true));
76         } catch(com.sun.star.lang.WrappedTargetException e) {
77             log.println("Exception while set property value");
78             e.printStackTrace(log);
79             throw new StatusException("Exception while set property value", e);
80         } catch(com.sun.star.lang.IllegalArgumentException e) {
81             log.println("Exception while set property value");
82             e.printStackTrace(log);
83             throw new StatusException("Exception while set property value", e);
84         } catch(com.sun.star.beans.PropertyVetoException e) {
85             log.println("Exception while set property value");
86             e.printStackTrace(log);
87             throw new StatusException("Exception while set property value", e);
88         } catch(com.sun.star.beans.UnknownPropertyException e) {
89             log.println("Exception while set property value");
90             e.printStackTrace(log);
91             throw new StatusException("Exception while set property value", e);
92         }
93     }
94 
_HasZAxis()95     public void _HasZAxis() {
96         try {
97             log.println("Property HasZAxis");
98             boolean res = ((Boolean)oObj.getPropertyValue(
99                                             "HasZAxis")).booleanValue();
100             if (!res)
101                 oObj.setPropertyValue("HasZAxis", Boolean.TRUE);
102             // test connected property HasZAxisDescription
103             if (!((Boolean)oObj.getPropertyValue(
104                                         "HasZAxisDescription")).booleanValue())
105                 oObj.setPropertyValue("HasZAxisDescription", Boolean.TRUE);
106 
107             oObj.setPropertyValue("HasZAxis", Boolean.FALSE);
108             boolean setVal = ((Boolean)oObj.getPropertyValue(
109                                                 "HasZAxis")).booleanValue();
110             log.println("Start value: " + setVal);
111             // description should also be false now
112             setVal |= ((Boolean)oObj.getPropertyValue(
113                                      "HasZAxisDescription")).booleanValue();
114             log.println("Connected value axis description: " + setVal);
115 
116             oObj.setPropertyValue("HasZAxis", Boolean.TRUE);
117             setVal |= !((Boolean)oObj.getPropertyValue(
118                                                 "HasZAxis")).booleanValue();
119             log.println("Changed value: " + !setVal);
120 
121             // description should be true again
122             setVal |= !((Boolean)oObj.getPropertyValue(
123                                      "HasZAxisDescription")).booleanValue();
124             log.println("Changed connected value axis description: " + !setVal);
125 
126             tRes.tested("HasZAxis", !setVal);
127             // leave axis untouched
128             oObj.setPropertyValue("HasZAxis", new Boolean(res));
129         }
130         catch (com.sun.star.lang.WrappedTargetException e) {
131             log.println(e.getMessage());
132             e.printStackTrace(log);
133             tRes.tested("HasZAxis", false);
134         }
135         catch (com.sun.star.lang.IllegalArgumentException e) {
136             log.println(e.getMessage());
137             e.printStackTrace(log);
138             tRes.tested("HasZAxis", false);
139         }
140         catch (com.sun.star.beans.UnknownPropertyException e) {
141             log.println(e.getMessage());
142             e.printStackTrace(log);
143             tRes.tested("HasZAxis", false);
144         }
145         catch (com.sun.star.beans.PropertyVetoException e) {
146             log.println(e.getMessage());
147             e.printStackTrace(log);
148             tRes.tested("HasZAxis", false);
149         }
150     }
151 
_HasZAxisDescription()152     public void _HasZAxisDescription() {
153         requiredMethod("HasZAxis");
154         try {
155             log.println("Property HasZAxisDescription");
156             if (!((Boolean)oObj.getPropertyValue("HasZAxis")).booleanValue())
157                 oObj.setPropertyValue("HasZAxis", Boolean.TRUE);
158 
159             boolean res = ((Boolean)oObj.getPropertyValue(
160                                         "HasZAxisDescription")).booleanValue();
161             log.println("Start value: " + res);
162 
163             oObj.setPropertyValue("HasZAxisDescription", new Boolean(!res));
164             boolean setValue = ((Boolean)oObj.getPropertyValue(
165                                         "HasZAxisDescription")).booleanValue();
166             log.println("Changed value: " + setValue);
167             tRes.tested("HasZAxisDescription", res != setValue);
168         }
169         catch (com.sun.star.lang.WrappedTargetException e) {
170             log.println(e.getMessage());
171             e.printStackTrace(log);
172             tRes.tested("HasZAxisDescription", false);
173         }
174         catch (com.sun.star.lang.IllegalArgumentException e) {
175             log.println(e.getMessage());
176             e.printStackTrace(log);
177             tRes.tested("HasZAxisDescription", false);
178         }
179         catch (com.sun.star.beans.UnknownPropertyException e) {
180             log.println(e.getMessage());
181             e.printStackTrace(log);
182             tRes.tested("HasZAxisDescription", false);
183         }
184         catch (com.sun.star.beans.PropertyVetoException e) {
185             log.println(e.getMessage());
186             e.printStackTrace(log);
187             tRes.tested("HasZAxisDescription", false);
188         }
189     }
190 
191 
192     /**
193     * Forces environment recreation.
194     */
after()195     protected void after() {
196         disposeEnvironment();
197     }
198 
199 } // EOF ChartAxisZSupplier
200 
201