1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _XChartData.java,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
32 import com
.sun
.star
.chart
.ChartDataChangeEvent
;
33 import com
.sun
.star
.chart
.XChartData
;
34 import com
.sun
.star
.chart
.XChartDataArray
;
35 import com
.sun
.star
.chart
.XChartDataChangeEventListener
;
36 import com
.sun
.star
.lang
.EventObject
;
37 import com
.sun
.star
.uno
.UnoRuntime
;
39 import lib
.MultiMethodTest
;
43 * Testing <code>com.sun.star.chart.XChartData</code>
46 * <li><code> addChartDataChangeEventListener()</code></li>
47 * <li><code> removeChartDataChangeEventListener()</code></li>
48 * <li><code> getNotANumber()</code></li>
49 * <li><code> isNotANumber()</code></li>
51 * @see com.sun.star.chart.XChartData
53 public class _XChartData
extends MultiMethodTest
{
54 public XChartData oObj
= null;
55 boolean result
= true;
57 XChartDataArray dataArray
= null;
58 boolean[] dataChanged
= new boolean[2];
59 XChartDataChangeEventListener listener1
= new MyEventListener();
60 XChartDataChangeEventListener listener2
= new MyEventListener2();
63 * Test calls the method adding two listeners and then changes data. <p>
64 * Has <b> OK </b> status if after data were changed
65 * listeners were called. <p>
67 public void _addChartDataChangeEventListener() {
68 dataChanged
[0] = false;
69 dataChanged
[1] = false;
71 oObj
.addChartDataChangeEventListener(listener1
);
72 oObj
.addChartDataChangeEventListener(listener2
);
74 dataArray
= (XChartDataArray
) UnoRuntime
.queryInterface(
75 XChartDataArray
.class, oObj
);
77 double[][] data
= dataArray
.getData();
79 dataArray
.setData(data
);
81 if (!dataChanged
[0]) {
82 log
.println("ChartDataChangeEventListener1 " +
83 "isn't called after changing data");
86 if (!dataChanged
[1]) {
87 log
.println("ChartDataChangeEventListener2 " +
88 "isn't called after changing data");
91 tRes
.tested("addChartDataChangeEventListener()",
92 dataChanged
[0] && dataChanged
[1]);
96 * Test calls the method for one listener, changes data,
97 * calls the method for other listener and again changes data. <p>
98 * Has <b> OK </b> status if listener is not called after removing. <p>
99 * The following method tests are to be completed successfully before :
101 * <li> <code>addChartDataChangeEventListener</code> : to have listeners
102 * that must be removed by the method </li>
105 public void _removeChartDataChangeEventListener() {
106 requiredMethod("addChartDataChangeEventListener()");
108 dataChanged
[0] = false;
109 dataChanged
[1] = false;
111 oObj
.removeChartDataChangeEventListener(listener1
);
112 dataArray
= (XChartDataArray
) UnoRuntime
.queryInterface(
113 XChartDataArray
.class, oObj
);
115 double[][] data
= dataArray
.getData();
117 dataArray
.setData(data
);
118 oObj
.removeChartDataChangeEventListener(listener2
);
120 if (dataChanged
[0]) {
121 log
.println("ChartDataChangeEventListener1 is " +
122 "called after removing listener");
125 tRes
.tested("removeChartDataChangeEventListener()",
126 ((!dataChanged
[0]) && (dataChanged
[1])));
130 * Test calls the method and checks returned value. <p>
131 * Has <b> OK </b> status if the return value isn't equal to 1. <p>
133 public void _getNotANumber() {
136 nan
= oObj
.getNotANumber();
137 log
.println("Current NotANumber is " + nan
);
140 tRes
.tested("getNotANumber()", result
);
144 * Test calls the method with NAN value and with non NAN value. <p>
145 * Has <b> OK </b> status if the method returns true for NAN value and
146 * returns false for other value<p>
147 * The following method tests are to be completed successfully before :
149 * <li> <code>getNotANumber</code> : to have the current NAN value </li>
152 public void _isNotANumber() {
153 requiredMethod("getNotANumber()");
156 result
= (oObj
.isNotANumber(nan
) && !oObj
.isNotANumber(nan
+ 1));
158 tRes
.tested("isNotANumber()", result
);
162 * Forces environment recreation.
164 protected void after() {
165 disposeEnvironment();
168 class MyEventListener
implements XChartDataChangeEventListener
{
169 public void disposing(EventObject oEvent
) {
170 System
.out
.println("Listener1 disposed");
173 public void chartDataChanged(ChartDataChangeEvent ev
) {
174 dataChanged
[0] = true;
178 class MyEventListener2
implements XChartDataChangeEventListener
{
179 public void disposing(EventObject oEvent
) {
180 System
.out
.println("Listener2 disposed");
183 public void chartDataChanged(ChartDataChangeEvent ev
) {
184 dataChanged
[1] = true;