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 com.sun.star.beans.XPropertySet; 31 import lib.MultiMethodTest; 32 import lib.Status; 33 import lib.StatusException; 34 35 import com.sun.star.chart.XChartDataArray; 36 import com.sun.star.uno.UnoRuntime; 37 38 /** 39 * Testing <code>com.sun.star.chart.XChartDataArray</code> 40 * interface methods : 41 * <ul> 42 * <li><code> getColumnDescriptions()</code></li> 43 * <li><code> getData()</code></li> 44 * <li><code> getRowDescriptions()</code></li> 45 * <li><code> setColumnDescriptions()</code></li> 46 * <li><code> setData()</code></li> 47 * <li><code> setRowDescriptions()</code></li> 48 * </ul> <p> 49 * @see com.sun.star.chart.XChartDataArray 50 */ 51 public class _XChartDataArray extends MultiMethodTest { 52 53 public XChartDataArray oObj = null; 54 boolean bResult = true; 55 String[] colDscs = new String[3]; 56 String[] rowDscs = new String[3]; 57 double[][] data = null; 58 private boolean mbExcludeSetRowAndSetColumn = false; 59 private String msExcludeMessage; 60 61 protected void before() { 62 Object o = tEnv.getObjRelation("CRDESC"); 63 if (o != null) { 64 mbExcludeSetRowAndSetColumn = true; 65 msExcludeMessage = (String)o; 66 } 67 if (!mbExcludeSetRowAndSetColumn) { 68 XPropertySet xProp = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, oObj); 69 if(xProp != null) { 70 try { 71 boolean columnAsLabel = ((Boolean)xProp.getPropertyValue("ChartColumnAsLabel")).booleanValue(); 72 boolean rowAsLabel = ((Boolean)xProp.getPropertyValue("ChartRowAsLabel")).booleanValue(); 73 if (!columnAsLabel) { 74 xProp.setPropertyValue("ChartColumnAsLabel", Boolean.TRUE); 75 } 76 if (!rowAsLabel) { 77 xProp.setPropertyValue("ChartRowAsLabel", Boolean.TRUE); 78 } 79 } 80 catch(Exception e) { 81 // ignore 82 } 83 } 84 } 85 } 86 87 /** 88 * Test calls the method and restores new values. <p> 89 * Has <b> OK </b> status if the method successfully returns. <p> 90 */ 91 public void _setColumnDescriptions() { 92 bResult = true; 93 94 colDscs = oObj.getColumnDescriptions(); 95 if (mbExcludeSetRowAndSetColumn) { 96 log.println(msExcludeMessage); 97 throw new StatusException(Status.skipped(true)); 98 } 99 for (int i = 0; i < colDscs.length; i++) { 100 colDscs[i] = "Col" + i; 101 } 102 oObj.setColumnDescriptions(colDscs); 103 104 tRes.tested("setColumnDescriptions()", bResult); 105 } 106 107 /** 108 * Test calls the method and restores new values. <p> 109 * Has <b> OK </b> status if the method successfully returns. <p> 110 * The following method tests are to be completed successfully before : 111 * <ul> 112 * <li> <code> setColumnDescriptions </code></li> 113 * </ul> 114 */ 115 public void _setRowDescriptions() { 116 bResult = true; 117 118 rowDscs = oObj.getRowDescriptions(); 119 if (mbExcludeSetRowAndSetColumn) { 120 log.println(msExcludeMessage); 121 throw new StatusException(Status.skipped(true)); 122 } 123 for (int i = 0; i < rowDscs.length; i++) { 124 rowDscs[i] = "Row" + i; 125 } 126 oObj.setRowDescriptions(rowDscs); 127 128 tRes.tested("setRowDescriptions()", bResult); 129 } 130 131 /** 132 * Test calls the method and restores new values. <p> 133 * Has <b> OK </b> status if the method successfully returns. <p> 134 * The following method tests are to be completed successfully before : 135 * <ul> 136 * <li> <code> setRowDescriptions </code></li> 137 * </ul> 138 */ 139 public void _setData() { 140 rowDscs = oObj.getRowDescriptions(); 141 colDscs = oObj.getColumnDescriptions(); 142 143 bResult = true; 144 double[][] _data = oObj.getData(); 145 data = _data; 146 147 for (int i = 0; i < rowDscs.length; i++) { 148 for (int j = 0; j < colDscs.length; j++) 149 data[i][j] = i * (j + 1); 150 } 151 oObj.setData(data); 152 153 tRes.tested("setData()", bResult); 154 } 155 156 /** 157 * Test calls the method and compare returned values with values restored 158 * after method <code>setColumnDescriptions</code>. <p> 159 * Has <b> OK </b> status if the returned values equils to restored values. <p> 160 * The following method tests are to be completed successfully before : 161 * <ul> 162 * <li> <code> setData </code> : to set and restore new values </li> 163 * </ul> 164 */ 165 public void _getColumnDescriptions() { 166 requiredMethod("setColumnDescriptions()"); 167 bResult = true; 168 169 String[] dscs = oObj.getColumnDescriptions(); 170 bResult &= dscs.length == colDscs.length; 171 if (bResult) { 172 for (int i = 0; i < dscs.length; i++) { 173 bResult &= dscs[i].equals(colDscs[i]); 174 } 175 } 176 177 tRes.tested("getColumnDescriptions()", bResult); 178 } 179 180 /** 181 * Test calls the method and compare returned values with values restored 182 * after method <code>setRowDescriptions</code>. <p> 183 * Has <b> OK </b> status if the returned values equils to restored values. <p> 184 * The following method tests are to be completed successfully before : 185 * <ul> 186 * <li> <code> setData </code> : to set and restore new values </li> 187 * </ul> 188 */ 189 public void _getRowDescriptions() { 190 requiredMethod("setRowDescriptions()"); 191 bResult = true; 192 193 String[] dscs = oObj.getRowDescriptions(); 194 bResult &= dscs.length == rowDscs.length; 195 if (bResult) { 196 for (int i = 0; i < dscs.length; i++) { 197 bResult &= dscs[i].equals(rowDscs[i]); 198 } 199 } 200 201 tRes.tested("getRowDescriptions()", bResult); 202 } 203 204 /** 205 * Test calls the method and compare returned values with values restored 206 * after method <code>setData</code>. <p> 207 * Has <b> OK </b> status if the returned values equils to restored values. <p> 208 * The following method tests are to be completed successfully before : 209 * <ul> 210 * <li> <code> setData </code> : to set and restore new values </li> 211 * </ul> 212 */ 213 public void _getData() { 214 requiredMethod("setData()"); 215 bResult = true; 216 217 double[][] _data = oObj.getData(); 218 data = _data; 219 for (int i = 0; i < rowDscs.length; i++) { 220 for (int j = 0; j < colDscs.length; j++) { 221 bResult &= data[i][j] == _data[i][j]; 222 } 223 } 224 225 tRes.tested("getData()", bResult); 226 } 227 228 protected void after() { 229 disposeEnvironment(); 230 } 231 } 232 233 234