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