1*ef39d40dSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*ef39d40dSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*ef39d40dSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*ef39d40dSAndrew Rist  * distributed with this work for additional information
6*ef39d40dSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*ef39d40dSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*ef39d40dSAndrew Rist  * "License"); you may not use this file except in compliance
9*ef39d40dSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*ef39d40dSAndrew Rist  *
11*ef39d40dSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*ef39d40dSAndrew Rist  *
13*ef39d40dSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*ef39d40dSAndrew Rist  * software distributed under the License is distributed on an
15*ef39d40dSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*ef39d40dSAndrew Rist  * KIND, either express or implied.  See the License for the
17*ef39d40dSAndrew Rist  * specific language governing permissions and limitations
18*ef39d40dSAndrew Rist  * under the License.
19*ef39d40dSAndrew Rist  *
20*ef39d40dSAndrew Rist  *************************************************************/
21*ef39d40dSAndrew Rist 
22*ef39d40dSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir package ifc.chart;
25cdf0e10cSrcweir 
26cdf0e10cSrcweir import com.sun.star.beans.XPropertySet;
27cdf0e10cSrcweir import lib.MultiMethodTest;
28cdf0e10cSrcweir import lib.Status;
29cdf0e10cSrcweir import lib.StatusException;
30cdf0e10cSrcweir 
31cdf0e10cSrcweir import com.sun.star.chart.XChartDataArray;
32cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime;
33cdf0e10cSrcweir 
34cdf0e10cSrcweir /**
35cdf0e10cSrcweir * Testing <code>com.sun.star.chart.XChartDataArray</code>
36cdf0e10cSrcweir * interface methods :
37cdf0e10cSrcweir * <ul>
38cdf0e10cSrcweir *  <li><code> getColumnDescriptions()</code></li>
39cdf0e10cSrcweir *  <li><code> getData()</code></li>
40cdf0e10cSrcweir *  <li><code> getRowDescriptions()</code></li>
41cdf0e10cSrcweir *  <li><code> setColumnDescriptions()</code></li>
42cdf0e10cSrcweir *  <li><code> setData()</code></li>
43cdf0e10cSrcweir *  <li><code> setRowDescriptions()</code></li>
44cdf0e10cSrcweir * </ul> <p>
45cdf0e10cSrcweir * @see com.sun.star.chart.XChartDataArray
46cdf0e10cSrcweir */
47cdf0e10cSrcweir public class _XChartDataArray extends MultiMethodTest {
48cdf0e10cSrcweir 
49cdf0e10cSrcweir     public XChartDataArray    oObj = null;
50cdf0e10cSrcweir     boolean    bResult = true;
51cdf0e10cSrcweir     String[] colDscs = new String[3];
52cdf0e10cSrcweir     String[] rowDscs = new String[3];
53cdf0e10cSrcweir     double[][] data = null;
54cdf0e10cSrcweir     private boolean mbExcludeSetRowAndSetColumn = false;
55cdf0e10cSrcweir     private String msExcludeMessage;
56cdf0e10cSrcweir 
before()57cdf0e10cSrcweir     protected void before() {
58cdf0e10cSrcweir         Object o = tEnv.getObjRelation("CRDESC");
59cdf0e10cSrcweir         if (o != null) {
60cdf0e10cSrcweir             mbExcludeSetRowAndSetColumn = true;
61cdf0e10cSrcweir             msExcludeMessage = (String)o;
62cdf0e10cSrcweir         }
63cdf0e10cSrcweir         if (!mbExcludeSetRowAndSetColumn) {
64cdf0e10cSrcweir             XPropertySet xProp = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, oObj);
65cdf0e10cSrcweir             if(xProp != null) {
66cdf0e10cSrcweir                 try {
67cdf0e10cSrcweir                     boolean columnAsLabel = ((Boolean)xProp.getPropertyValue("ChartColumnAsLabel")).booleanValue();
68cdf0e10cSrcweir                     boolean rowAsLabel = ((Boolean)xProp.getPropertyValue("ChartRowAsLabel")).booleanValue();
69cdf0e10cSrcweir                     if (!columnAsLabel) {
70cdf0e10cSrcweir                         xProp.setPropertyValue("ChartColumnAsLabel", Boolean.TRUE);
71cdf0e10cSrcweir                     }
72cdf0e10cSrcweir                     if (!rowAsLabel) {
73cdf0e10cSrcweir                         xProp.setPropertyValue("ChartRowAsLabel", Boolean.TRUE);
74cdf0e10cSrcweir                     }
75cdf0e10cSrcweir                 }
76cdf0e10cSrcweir                 catch(Exception e) {
77cdf0e10cSrcweir                     // ignore
78cdf0e10cSrcweir                 }
79cdf0e10cSrcweir             }
80cdf0e10cSrcweir         }
81cdf0e10cSrcweir     }
82cdf0e10cSrcweir 
83cdf0e10cSrcweir     /**
84cdf0e10cSrcweir     * Test calls the method and restores new values. <p>
85cdf0e10cSrcweir     * Has <b> OK </b> status if the method successfully returns. <p>
86cdf0e10cSrcweir     */
_setColumnDescriptions()87cdf0e10cSrcweir     public void _setColumnDescriptions() {
88cdf0e10cSrcweir         bResult = true;
89cdf0e10cSrcweir 
90cdf0e10cSrcweir         colDscs = oObj.getColumnDescriptions();
91cdf0e10cSrcweir         if (mbExcludeSetRowAndSetColumn) {
92cdf0e10cSrcweir             log.println(msExcludeMessage);
93cdf0e10cSrcweir             throw new StatusException(Status.skipped(true));
94cdf0e10cSrcweir         }
95cdf0e10cSrcweir         for (int i = 0; i < colDscs.length; i++) {
96cdf0e10cSrcweir             colDscs[i] = "Col" + i;
97cdf0e10cSrcweir         }
98cdf0e10cSrcweir         oObj.setColumnDescriptions(colDscs);
99cdf0e10cSrcweir 
100cdf0e10cSrcweir         tRes.tested("setColumnDescriptions()", bResult);
101cdf0e10cSrcweir     }
102cdf0e10cSrcweir 
103cdf0e10cSrcweir     /**
104cdf0e10cSrcweir     * Test calls the method and restores new values. <p>
105cdf0e10cSrcweir     * Has <b> OK </b> status if the method successfully returns. <p>
106cdf0e10cSrcweir     * The following method tests are to be completed successfully before :
107cdf0e10cSrcweir     * <ul>
108cdf0e10cSrcweir     *  <li> <code> setColumnDescriptions </code></li>
109cdf0e10cSrcweir     * </ul>
110cdf0e10cSrcweir     */
_setRowDescriptions()111cdf0e10cSrcweir     public void _setRowDescriptions() {
112cdf0e10cSrcweir         bResult = true;
113cdf0e10cSrcweir 
114cdf0e10cSrcweir         rowDscs = oObj.getRowDescriptions();
115cdf0e10cSrcweir         if (mbExcludeSetRowAndSetColumn) {
116cdf0e10cSrcweir             log.println(msExcludeMessage);
117cdf0e10cSrcweir             throw new StatusException(Status.skipped(true));
118cdf0e10cSrcweir         }
119cdf0e10cSrcweir         for (int i = 0; i < rowDscs.length; i++) {
120cdf0e10cSrcweir             rowDscs[i] = "Row" + i;
121cdf0e10cSrcweir         }
122cdf0e10cSrcweir         oObj.setRowDescriptions(rowDscs);
123cdf0e10cSrcweir 
124cdf0e10cSrcweir         tRes.tested("setRowDescriptions()", bResult);
125cdf0e10cSrcweir     }
126cdf0e10cSrcweir 
127cdf0e10cSrcweir     /**
128cdf0e10cSrcweir     * Test calls the method and restores new values. <p>
129cdf0e10cSrcweir     * Has <b> OK </b> status if the method successfully returns. <p>
130cdf0e10cSrcweir     * The following method tests are to be completed successfully before :
131cdf0e10cSrcweir     * <ul>
132cdf0e10cSrcweir     *  <li> <code> setRowDescriptions </code></li>
133cdf0e10cSrcweir     * </ul>
134cdf0e10cSrcweir     */
_setData()135cdf0e10cSrcweir     public void _setData() {
136cdf0e10cSrcweir         rowDscs = oObj.getRowDescriptions();
137cdf0e10cSrcweir         colDscs = oObj.getColumnDescriptions();
138cdf0e10cSrcweir 
139cdf0e10cSrcweir         bResult = true;
140cdf0e10cSrcweir         double[][] _data = oObj.getData();
141cdf0e10cSrcweir         data = _data;
142cdf0e10cSrcweir 
143cdf0e10cSrcweir         for (int i = 0; i < rowDscs.length; i++) {
144cdf0e10cSrcweir             for (int j = 0; j < colDscs.length; j++)
145cdf0e10cSrcweir                 data[i][j] = i * (j + 1);
146cdf0e10cSrcweir         }
147cdf0e10cSrcweir         oObj.setData(data);
148cdf0e10cSrcweir 
149cdf0e10cSrcweir         tRes.tested("setData()", bResult);
150cdf0e10cSrcweir     }
151cdf0e10cSrcweir 
152cdf0e10cSrcweir     /**
153cdf0e10cSrcweir     * Test calls the method and compare returned values with values restored
154cdf0e10cSrcweir     * after method <code>setColumnDescriptions</code>. <p>
155cdf0e10cSrcweir     * Has <b> OK </b> status if the returned values equils to restored values. <p>
156cdf0e10cSrcweir     * The following method tests are to be completed successfully before :
157cdf0e10cSrcweir     * <ul>
158cdf0e10cSrcweir     *  <li> <code> setData </code> : to set and restore new values </li>
159cdf0e10cSrcweir     * </ul>
160cdf0e10cSrcweir     */
_getColumnDescriptions()161cdf0e10cSrcweir     public void _getColumnDescriptions() {
162cdf0e10cSrcweir         requiredMethod("setColumnDescriptions()");
163cdf0e10cSrcweir         bResult = true;
164cdf0e10cSrcweir 
165cdf0e10cSrcweir         String[] dscs = oObj.getColumnDescriptions();
166cdf0e10cSrcweir         bResult &= dscs.length == colDscs.length;
167cdf0e10cSrcweir         if (bResult) {
168cdf0e10cSrcweir             for (int i = 0; i < dscs.length; i++) {
169cdf0e10cSrcweir                 bResult &= dscs[i].equals(colDscs[i]);
170cdf0e10cSrcweir             }
171cdf0e10cSrcweir         }
172cdf0e10cSrcweir 
173cdf0e10cSrcweir         tRes.tested("getColumnDescriptions()", bResult);
174cdf0e10cSrcweir     }
175cdf0e10cSrcweir 
176cdf0e10cSrcweir     /**
177cdf0e10cSrcweir     * Test calls the method and compare returned values with values restored
178cdf0e10cSrcweir     * after method <code>setRowDescriptions</code>. <p>
179cdf0e10cSrcweir     * Has <b> OK </b> status if the returned values equils to restored values. <p>
180cdf0e10cSrcweir     * The following method tests are to be completed successfully before :
181cdf0e10cSrcweir     * <ul>
182cdf0e10cSrcweir     *  <li> <code> setData </code> : to set and restore new values </li>
183cdf0e10cSrcweir     * </ul>
184cdf0e10cSrcweir     */
_getRowDescriptions()185cdf0e10cSrcweir     public void _getRowDescriptions() {
186cdf0e10cSrcweir         requiredMethod("setRowDescriptions()");
187cdf0e10cSrcweir         bResult = true;
188cdf0e10cSrcweir 
189cdf0e10cSrcweir         String[] dscs = oObj.getRowDescriptions();
190cdf0e10cSrcweir         bResult &= dscs.length == rowDscs.length;
191cdf0e10cSrcweir         if (bResult) {
192cdf0e10cSrcweir             for (int i = 0; i < dscs.length; i++) {
193cdf0e10cSrcweir                 bResult &= dscs[i].equals(rowDscs[i]);
194cdf0e10cSrcweir             }
195cdf0e10cSrcweir         }
196cdf0e10cSrcweir 
197cdf0e10cSrcweir         tRes.tested("getRowDescriptions()", bResult);
198cdf0e10cSrcweir     }
199cdf0e10cSrcweir 
200cdf0e10cSrcweir     /**
201cdf0e10cSrcweir     * Test calls the method and compare returned values with values restored
202cdf0e10cSrcweir     * after method <code>setData</code>. <p>
203cdf0e10cSrcweir     * Has <b> OK </b> status if the returned values equils to restored values. <p>
204cdf0e10cSrcweir     * The following method tests are to be completed successfully before :
205cdf0e10cSrcweir     * <ul>
206cdf0e10cSrcweir     *  <li> <code> setData </code> : to set and restore new values </li>
207cdf0e10cSrcweir     * </ul>
208cdf0e10cSrcweir     */
_getData()209cdf0e10cSrcweir     public void _getData() {
210cdf0e10cSrcweir         requiredMethod("setData()");
211cdf0e10cSrcweir         bResult = true;
212cdf0e10cSrcweir 
213cdf0e10cSrcweir         double[][] _data = oObj.getData();
214cdf0e10cSrcweir         data = _data;
215cdf0e10cSrcweir         for (int i = 0; i < rowDscs.length; i++) {
216cdf0e10cSrcweir             for (int j = 0; j < colDscs.length; j++) {
217cdf0e10cSrcweir                 bResult &= data[i][j] == _data[i][j];
218cdf0e10cSrcweir             }
219cdf0e10cSrcweir         }
220cdf0e10cSrcweir 
221cdf0e10cSrcweir         tRes.tested("getData()", bResult);
222cdf0e10cSrcweir     }
223cdf0e10cSrcweir 
after()224cdf0e10cSrcweir     protected void after() {
225cdf0e10cSrcweir         disposeEnvironment();
226cdf0e10cSrcweir     }
227cdf0e10cSrcweir }
228cdf0e10cSrcweir 
229cdf0e10cSrcweir 
230