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