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.uno.UnoRuntime;
33 
34 /**
35 * Testing <code>com.sun.star.chart.ChartAxisYSupplier</code>
36 * service properties :
37 * <ul>
38 *  <li><code> HasYAxis</code></li>
39 *  <li><code> HasYAxisDescription</code></li>
40 *  <li><code> HasYAxisGrid</code></li>
41 *  <li><code> HasYAxisHelpGrid</code></li>
42 *  <li><code> HasYAxisTitle</code></li>
43 * </ul> <p>
44 * This test needs the following object relations :
45 * <ul>
46 *  <li> <code>'CHARTDOC'</code> (of type <code>XChartDocument</code>):
47 *  to have reference to chart document </li>
48 * </ul> <p>
49 * @see com.sun.star.chart.ChartAxisYSupplier
50 */
51 public class _ChartAxisYSupplier extends MultiPropertyTest {
52 
53     /**
54     * Retrieves object relations and prepares a chart document.
55     * @throws StatusException if one of relations not found.
56     */
before()57     protected void before() {
58         XChartDocument doc = (XChartDocument) tEnv.getObjRelation("CHARTDOC");
59         if (doc == null) throw new StatusException(Status.failed
60             ("Relation 'CHARTDOC' not found"));
61 
62         oObj = (XPropertySet)
63             UnoRuntime.queryInterface( XPropertySet.class, doc.getDiagram() );
64     }
65 
_HasYAxis()66     public void _HasYAxis() {
67         try {
68             log.println("Property HasYAxis");
69             boolean res = ((Boolean)oObj.getPropertyValue(
70                                             "HasYAxis")).booleanValue();
71             if (!res)
72                 oObj.setPropertyValue("HasYAxis", Boolean.TRUE);
73             // test connected property HasYAxisDescription
74             if (!((Boolean)oObj.getPropertyValue(
75                                         "HasYAxisDescription")).booleanValue())
76                 oObj.setPropertyValue("HasYAxisDescription", Boolean.TRUE);
77 
78             oObj.setPropertyValue("HasYAxis", Boolean.FALSE);
79             boolean setVal = ((Boolean)oObj.getPropertyValue(
80                                                 "HasYAxis")).booleanValue();
81             log.println("Start value: " + setVal);
82             // description should also be false now
83             setVal |= ((Boolean)oObj.getPropertyValue(
84                                      "HasYAxisDescription")).booleanValue();
85             log.println("Connected value axis description: " + setVal);
86 
87             oObj.setPropertyValue("HasYAxis", Boolean.TRUE);
88             setVal |= !((Boolean)oObj.getPropertyValue(
89                                                 "HasYAxis")).booleanValue();
90             log.println("Changed value: " + !setVal);
91 
92             // description should be true again
93             setVal |= !((Boolean)oObj.getPropertyValue(
94                                      "HasYAxisDescription")).booleanValue();
95             log.println("Changed connected value axis description: "+!setVal);
96 
97             tRes.tested("HasYAxis", !setVal);
98             // leave axis untouched
99             oObj.setPropertyValue("HasYAxis", new Boolean(res));
100         }
101         catch (com.sun.star.lang.WrappedTargetException e) {
102             log.println(e.getMessage());
103             e.printStackTrace(log);
104             tRes.tested("HasYAxis", false);
105         }
106         catch (com.sun.star.lang.IllegalArgumentException e) {
107             log.println(e.getMessage());
108             e.printStackTrace(log);
109             tRes.tested("HasYAxis", false);
110         }
111         catch (com.sun.star.beans.UnknownPropertyException e) {
112             log.println(e.getMessage());
113             e.printStackTrace(log);
114             tRes.tested("HasYAxis", false);
115         }
116         catch (com.sun.star.beans.PropertyVetoException e) {
117             log.println(e.getMessage());
118             e.printStackTrace(log);
119             tRes.tested("HasYAxis", false);
120         }
121     }
122 
_HasYAxisDescription()123     public void _HasYAxisDescription() {
124         requiredMethod("HasYAxis");
125         try {
126             log.println("Property HasYAxisDescription");
127             if (!((Boolean)oObj.getPropertyValue("HasYAxis")).booleanValue())
128                 oObj.setPropertyValue("HasYAxis", Boolean.TRUE);
129 
130             boolean res = ((Boolean)oObj.getPropertyValue(
131                                         "HasYAxisDescription")).booleanValue();
132             log.println("Start value: " + res);
133 
134             oObj.setPropertyValue("HasYAxisDescription", new Boolean(!res));
135             boolean setValue = ((Boolean)oObj.getPropertyValue(
136                                         "HasYAxisDescription")).booleanValue();
137             log.println("Changed value: " + setValue);
138             tRes.tested("HasYAxisDescription", res != setValue);
139         }
140         catch (com.sun.star.lang.WrappedTargetException e) {
141             log.println(e.getMessage());
142             e.printStackTrace(log);
143             tRes.tested("HasYAxisDescription", false);
144         }
145         catch (com.sun.star.lang.IllegalArgumentException e) {
146             log.println(e.getMessage());
147             e.printStackTrace(log);
148             tRes.tested("HasYAxisDescription", false);
149         }
150         catch (com.sun.star.beans.UnknownPropertyException e) {
151             log.println(e.getMessage());
152             e.printStackTrace(log);
153             tRes.tested("HasYAxisDescription", false);
154         }
155         catch (com.sun.star.beans.PropertyVetoException e) {
156             log.println(e.getMessage());
157             e.printStackTrace(log);
158             tRes.tested("HasYAxisDescription", false);
159         }
160     }
161 
162 } // EOF ChartAxisYSupplier
163 
164