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