Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / ifc / chart / _XChartDataArray.java
blob2cfaedb62aaab7437c2eb84aea9becf902b57159
1 /*
2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 package ifc.chart;
21 import com.sun.star.beans.XPropertySet;
22 import lib.MultiMethodTest;
23 import lib.Status;
24 import lib.StatusException;
26 import com.sun.star.chart.XChartDataArray;
27 import com.sun.star.uno.UnoRuntime;
29 /**
30 * Testing <code>com.sun.star.chart.XChartDataArray</code>
31 * interface methods :
32 * <ul>
33 * <li><code> getColumnDescriptions()</code></li>
34 * <li><code> getData()</code></li>
35 * <li><code> getRowDescriptions()</code></li>
36 * <li><code> setColumnDescriptions()</code></li>
37 * <li><code> setData()</code></li>
38 * <li><code> setRowDescriptions()</code></li>
39 * </ul> <p>
40 * @see com.sun.star.chart.XChartDataArray
42 public class _XChartDataArray extends MultiMethodTest {
44 public XChartDataArray oObj = null;
45 boolean bResult = true;
46 String[] colDscs = new String[3];
47 String[] rowDscs = new String[3];
48 double[][] data = null;
49 private boolean mbExcludeSetRowAndSetColumn = false;
50 private String msExcludeMessage;
52 @Override
53 protected void before() {
54 Object o = tEnv.getObjRelation("CRDESC");
55 if (o != null) {
56 mbExcludeSetRowAndSetColumn = true;
57 msExcludeMessage = (String)o;
59 if (mbExcludeSetRowAndSetColumn) {
60 return;
62 XPropertySet xProp = UnoRuntime.queryInterface(XPropertySet.class, oObj);
63 if(xProp != null) {
64 try {
65 boolean columnAsLabel = ((Boolean)xProp.getPropertyValue("ChartColumnAsLabel")).booleanValue();
66 boolean rowAsLabel = ((Boolean)xProp.getPropertyValue("ChartRowAsLabel")).booleanValue();
67 if (!columnAsLabel) {
68 xProp.setPropertyValue("ChartColumnAsLabel", Boolean.TRUE);
70 if (!rowAsLabel) {
71 xProp.setPropertyValue("ChartRowAsLabel", Boolean.TRUE);
74 catch(Exception e) {
75 // ignore
80 /**
81 * Test calls the method and restores new values. <p>
82 * Has <b> OK </b> status if the method successfully returns. <p>
84 public void _setColumnDescriptions() {
85 bResult = true;
87 colDscs = oObj.getColumnDescriptions();
88 if (mbExcludeSetRowAndSetColumn) {
89 log.println(msExcludeMessage);
90 throw new StatusException(Status.skipped(true));
92 for (int i = 0; i < colDscs.length; i++) {
93 colDscs[i] = "Col" + i;
95 oObj.setColumnDescriptions(colDscs);
97 tRes.tested("setColumnDescriptions()", bResult);
101 * Test calls the method and restores new values. <p>
102 * Has <b> OK </b> status if the method successfully returns. <p>
103 * The following method tests are to be completed successfully before :
104 * <ul>
105 * <li> <code> setColumnDescriptions </code></li>
106 * </ul>
108 public void _setRowDescriptions() {
109 bResult = true;
111 rowDscs = oObj.getRowDescriptions();
112 if (mbExcludeSetRowAndSetColumn) {
113 log.println(msExcludeMessage);
114 throw new StatusException(Status.skipped(true));
116 for (int i = 0; i < rowDscs.length; i++) {
117 rowDscs[i] = "Row" + i;
119 oObj.setRowDescriptions(rowDscs);
121 tRes.tested("setRowDescriptions()", bResult);
125 * Test calls the method and restores new values. <p>
126 * Has <b> OK </b> status if the method successfully returns. <p>
127 * The following method tests are to be completed successfully before :
128 * <ul>
129 * <li> <code> setRowDescriptions </code></li>
130 * </ul>
132 public void _setData() {
133 rowDscs = oObj.getRowDescriptions();
134 colDscs = oObj.getColumnDescriptions();
136 bResult = true;
137 double[][] _data = oObj.getData();
138 data = _data;
139 if(rowDscs.length != 0 && rowDscs.length != data.length)
140 bResult = false;
141 if(colDscs.length != 0 && colDscs.length != data[0].length)
142 bResult = false;
143 for (int i = 0; i < data.length; i++) {
144 for (int j = 0; j < data[i].length; j++)
145 data[i][j] = i * (j + 1);
147 oObj.setData(data);
149 tRes.tested("setData()", bResult);
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>
161 public void _getColumnDescriptions() {
162 requiredMethod("setColumnDescriptions()");
163 bResult = true;
165 String[] dscs = oObj.getColumnDescriptions();
166 bResult &= dscs.length == colDscs.length;
167 if (bResult) {
168 for (int i = 0; i < dscs.length; i++) {
169 log.println("Col " + i + ": got " + dscs[i] + " expected: " + colDscs[i]);
170 bResult &= dscs[i].equals(colDscs[i]);
174 tRes.tested("getColumnDescriptions()", bResult);
178 * Test calls the method and compare returned values with values restored
179 * after method <code>setRowDescriptions</code>. <p>
180 * Has <b> OK </b> status if the returned values equils to restored values. <p>
181 * The following method tests are to be completed successfully before :
182 * <ul>
183 * <li> <code> setData </code> : to set and restore new values </li>
184 * </ul>
186 public void _getRowDescriptions() {
187 requiredMethod("setRowDescriptions()");
188 bResult = true;
190 String[] dscs = oObj.getRowDescriptions();
191 bResult &= dscs.length == rowDscs.length;
192 if (bResult) {
193 for (int i = 0; i < dscs.length; i++) {
194 log.println("Row " + i + ": got " + dscs[i] + " expected: " + rowDscs[i]);
195 bResult &= dscs[i].equals(rowDscs[i]);
199 tRes.tested("getRowDescriptions()", bResult);
203 * Test calls the method and compare returned values with values restored
204 * after method <code>setData</code>. <p>
205 * Has <b> OK </b> status if the returned values equils to restored values. <p>
206 * The following method tests are to be completed successfully before :
207 * <ul>
208 * <li> <code> setData </code> : to set and restore new values </li>
209 * </ul>
211 public void _getData() {
212 requiredMethod("setData()");
213 bResult = true;
215 double[][] _data = oObj.getData();
216 data = _data;
217 if(rowDscs.length != 0 && rowDscs.length != data.length)
218 bResult = false;
219 if(colDscs.length != 0 && colDscs.length != data[0].length)
220 bResult = false;
221 for (int i = 0; i < data.length; i++) {
222 for (int j = 0; j < data[i].length; j++) {
223 bResult &= data[i][j] == _data[i][j];
227 tRes.tested("getData()", bResult);
230 @Override
231 protected void after() {
232 disposeEnvironment();