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.chart;
24 
25 import com.sun.star.chart.ChartDataChangeEvent;
26 import com.sun.star.chart.XChartData;
27 import com.sun.star.chart.XChartDataArray;
28 import com.sun.star.chart.XChartDataChangeEventListener;
29 import com.sun.star.lang.EventObject;
30 import com.sun.star.uno.UnoRuntime;
31 
32 import lib.MultiMethodTest;
33 
34 
35 /**
36 * Testing <code>com.sun.star.chart.XChartData</code>
37 * interface methods :
38 * <ul>
39 *  <li><code> addChartDataChangeEventListener()</code></li>
40 *  <li><code> removeChartDataChangeEventListener()</code></li>
41 *  <li><code> getNotANumber()</code></li>
42 *  <li><code> isNotANumber()</code></li>
43 * </ul> <p>
44 * @see com.sun.star.chart.XChartData
45 */
46 public class _XChartData extends MultiMethodTest {
47     public XChartData oObj = null;
48     boolean result = true;
49     double nan = 0;
50     XChartDataArray dataArray = null;
51     boolean[] dataChanged = new boolean[2];
52     XChartDataChangeEventListener listener1 = new MyEventListener();
53     XChartDataChangeEventListener listener2 = new MyEventListener2();
54 
55     /**
56     * Test calls the method adding two listeners and then changes data. <p>
57     * Has <b> OK </b> status if after data were changed
58     * listeners were called. <p>
59     */
_addChartDataChangeEventListener()60     public void _addChartDataChangeEventListener() {
61         dataChanged[0] = false;
62         dataChanged[1] = false;
63 
64         oObj.addChartDataChangeEventListener(listener1);
65         oObj.addChartDataChangeEventListener(listener2);
66 
67         dataArray = (XChartDataArray) UnoRuntime.queryInterface(
68                             XChartDataArray.class, oObj);
69 
70         double[][] data = dataArray.getData();
71         data[0][0] += 0.1;
72         dataArray.setData(data);
73 
74         if (!dataChanged[0]) {
75             log.println("ChartDataChangeEventListener1 " +
76                         "isn't called after changing data");
77         }
78 
79         if (!dataChanged[1]) {
80             log.println("ChartDataChangeEventListener2 " +
81                         "isn't called after changing data");
82         }
83 
84         tRes.tested("addChartDataChangeEventListener()",
85                     dataChanged[0] && dataChanged[1]);
86     }
87 
88     /**
89     * Test calls the method for one listener, changes data,
90     * calls the method for other listener and again changes data. <p>
91     * Has <b> OK </b> status if listener is not called after removing. <p>
92     * The following method tests are to be completed successfully before :
93     * <ul>
94     *  <li> <code>addChartDataChangeEventListener</code> : to have listeners
95     *  that must be removed by the method </li>
96     * </ul>
97     */
_removeChartDataChangeEventListener()98     public void _removeChartDataChangeEventListener() {
99         requiredMethod("addChartDataChangeEventListener()");
100 
101         dataChanged[0] = false;
102         dataChanged[1] = false;
103 
104         oObj.removeChartDataChangeEventListener(listener1);
105         dataArray = (XChartDataArray) UnoRuntime.queryInterface(
106                             XChartDataArray.class, oObj);
107 
108         double[][] data = dataArray.getData();
109         data[0][0] += 0.1;
110         dataArray.setData(data);
111         oObj.removeChartDataChangeEventListener(listener2);
112 
113         if (dataChanged[0]) {
114             log.println("ChartDataChangeEventListener1 is " +
115                         "called after removing listener");
116         }
117 
118         tRes.tested("removeChartDataChangeEventListener()",
119                     ((!dataChanged[0]) && (dataChanged[1])));
120     }
121 
122     /**
123     * Test calls the method and checks returned value. <p>
124     * Has <b> OK </b> status if the return value isn't equal to 1. <p>
125     */
_getNotANumber()126     public void _getNotANumber() {
127         result = true;
128 
129         nan = oObj.getNotANumber();
130         log.println("Current NotANumber is " + nan);
131         result = nan != 1;
132 
133         tRes.tested("getNotANumber()", result);
134     }
135 
136     /**
137     * Test calls the method with NAN value and with non NAN value. <p>
138     * Has <b> OK </b> status if the method returns true for NAN value and
139     * returns false for other value<p>
140     * The following method tests are to be completed successfully before :
141     * <ul>
142     *  <li> <code>getNotANumber</code> : to have the current NAN value </li>
143     * </ul>
144     */
_isNotANumber()145     public void _isNotANumber() {
146         requiredMethod("getNotANumber()");
147         result = true;
148 
149         result = (oObj.isNotANumber(nan) && !oObj.isNotANumber(nan + 1));
150 
151         tRes.tested("isNotANumber()", result);
152     }
153 
154     /**
155     * Forces environment recreation.
156     */
after()157     protected void after() {
158         disposeEnvironment();
159     }
160 
161     class MyEventListener implements XChartDataChangeEventListener {
disposing(EventObject oEvent)162         public void disposing(EventObject oEvent) {
163             System.out.println("Listener1 disposed");
164         }
165 
chartDataChanged(ChartDataChangeEvent ev)166         public void chartDataChanged(ChartDataChangeEvent ev) {
167             dataChanged[0] = true;
168         }
169     }
170 
171     class MyEventListener2 implements XChartDataChangeEventListener {
disposing(EventObject oEvent)172         public void disposing(EventObject oEvent) {
173             System.out.println("Listener2 disposed");
174         }
175 
chartDataChanged(ChartDataChangeEvent ev)176         public void chartDataChanged(ChartDataChangeEvent ev) {
177             dataChanged[1] = true;
178         }
179     }
180 }