1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir package ifc.chart;
29*cdf0e10cSrcweir 
30*cdf0e10cSrcweir import com.sun.star.beans.XPropertySet;
31*cdf0e10cSrcweir import lib.MultiMethodTest;
32*cdf0e10cSrcweir import lib.Status;
33*cdf0e10cSrcweir import lib.StatusException;
34*cdf0e10cSrcweir 
35*cdf0e10cSrcweir import com.sun.star.chart.XChartDataArray;
36*cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime;
37*cdf0e10cSrcweir 
38*cdf0e10cSrcweir /**
39*cdf0e10cSrcweir * Testing <code>com.sun.star.chart.XChartDataArray</code>
40*cdf0e10cSrcweir * interface methods :
41*cdf0e10cSrcweir * <ul>
42*cdf0e10cSrcweir *  <li><code> getColumnDescriptions()</code></li>
43*cdf0e10cSrcweir *  <li><code> getData()</code></li>
44*cdf0e10cSrcweir *  <li><code> getRowDescriptions()</code></li>
45*cdf0e10cSrcweir *  <li><code> setColumnDescriptions()</code></li>
46*cdf0e10cSrcweir *  <li><code> setData()</code></li>
47*cdf0e10cSrcweir *  <li><code> setRowDescriptions()</code></li>
48*cdf0e10cSrcweir * </ul> <p>
49*cdf0e10cSrcweir * @see com.sun.star.chart.XChartDataArray
50*cdf0e10cSrcweir */
51*cdf0e10cSrcweir public class _XChartDataArray extends MultiMethodTest {
52*cdf0e10cSrcweir 
53*cdf0e10cSrcweir     public XChartDataArray    oObj = null;
54*cdf0e10cSrcweir     boolean    bResult = true;
55*cdf0e10cSrcweir     String[] colDscs = new String[3];
56*cdf0e10cSrcweir     String[] rowDscs = new String[3];
57*cdf0e10cSrcweir     double[][] data = null;
58*cdf0e10cSrcweir     private boolean mbExcludeSetRowAndSetColumn = false;
59*cdf0e10cSrcweir     private String msExcludeMessage;
60*cdf0e10cSrcweir 
61*cdf0e10cSrcweir     protected void before() {
62*cdf0e10cSrcweir         Object o = tEnv.getObjRelation("CRDESC");
63*cdf0e10cSrcweir         if (o != null) {
64*cdf0e10cSrcweir             mbExcludeSetRowAndSetColumn = true;
65*cdf0e10cSrcweir             msExcludeMessage = (String)o;
66*cdf0e10cSrcweir         }
67*cdf0e10cSrcweir         if (!mbExcludeSetRowAndSetColumn) {
68*cdf0e10cSrcweir             XPropertySet xProp = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, oObj);
69*cdf0e10cSrcweir             if(xProp != null) {
70*cdf0e10cSrcweir                 try {
71*cdf0e10cSrcweir                     boolean columnAsLabel = ((Boolean)xProp.getPropertyValue("ChartColumnAsLabel")).booleanValue();
72*cdf0e10cSrcweir                     boolean rowAsLabel = ((Boolean)xProp.getPropertyValue("ChartRowAsLabel")).booleanValue();
73*cdf0e10cSrcweir                     if (!columnAsLabel) {
74*cdf0e10cSrcweir                         xProp.setPropertyValue("ChartColumnAsLabel", Boolean.TRUE);
75*cdf0e10cSrcweir                     }
76*cdf0e10cSrcweir                     if (!rowAsLabel) {
77*cdf0e10cSrcweir                         xProp.setPropertyValue("ChartRowAsLabel", Boolean.TRUE);
78*cdf0e10cSrcweir                     }
79*cdf0e10cSrcweir                 }
80*cdf0e10cSrcweir                 catch(Exception e) {
81*cdf0e10cSrcweir                     // ignore
82*cdf0e10cSrcweir                 }
83*cdf0e10cSrcweir             }
84*cdf0e10cSrcweir         }
85*cdf0e10cSrcweir     }
86*cdf0e10cSrcweir 
87*cdf0e10cSrcweir     /**
88*cdf0e10cSrcweir     * Test calls the method and restores new values. <p>
89*cdf0e10cSrcweir     * Has <b> OK </b> status if the method successfully returns. <p>
90*cdf0e10cSrcweir     */
91*cdf0e10cSrcweir     public void _setColumnDescriptions() {
92*cdf0e10cSrcweir         bResult = true;
93*cdf0e10cSrcweir 
94*cdf0e10cSrcweir         colDscs = oObj.getColumnDescriptions();
95*cdf0e10cSrcweir         if (mbExcludeSetRowAndSetColumn) {
96*cdf0e10cSrcweir             log.println(msExcludeMessage);
97*cdf0e10cSrcweir             throw new StatusException(Status.skipped(true));
98*cdf0e10cSrcweir         }
99*cdf0e10cSrcweir         for (int i = 0; i < colDscs.length; i++) {
100*cdf0e10cSrcweir             colDscs[i] = "Col" + i;
101*cdf0e10cSrcweir         }
102*cdf0e10cSrcweir         oObj.setColumnDescriptions(colDscs);
103*cdf0e10cSrcweir 
104*cdf0e10cSrcweir         tRes.tested("setColumnDescriptions()", bResult);
105*cdf0e10cSrcweir     }
106*cdf0e10cSrcweir 
107*cdf0e10cSrcweir     /**
108*cdf0e10cSrcweir     * Test calls the method and restores new values. <p>
109*cdf0e10cSrcweir     * Has <b> OK </b> status if the method successfully returns. <p>
110*cdf0e10cSrcweir     * The following method tests are to be completed successfully before :
111*cdf0e10cSrcweir     * <ul>
112*cdf0e10cSrcweir     *  <li> <code> setColumnDescriptions </code></li>
113*cdf0e10cSrcweir     * </ul>
114*cdf0e10cSrcweir     */
115*cdf0e10cSrcweir     public void _setRowDescriptions() {
116*cdf0e10cSrcweir         bResult = true;
117*cdf0e10cSrcweir 
118*cdf0e10cSrcweir         rowDscs = oObj.getRowDescriptions();
119*cdf0e10cSrcweir         if (mbExcludeSetRowAndSetColumn) {
120*cdf0e10cSrcweir             log.println(msExcludeMessage);
121*cdf0e10cSrcweir             throw new StatusException(Status.skipped(true));
122*cdf0e10cSrcweir         }
123*cdf0e10cSrcweir         for (int i = 0; i < rowDscs.length; i++) {
124*cdf0e10cSrcweir             rowDscs[i] = "Row" + i;
125*cdf0e10cSrcweir         }
126*cdf0e10cSrcweir         oObj.setRowDescriptions(rowDscs);
127*cdf0e10cSrcweir 
128*cdf0e10cSrcweir         tRes.tested("setRowDescriptions()", bResult);
129*cdf0e10cSrcweir     }
130*cdf0e10cSrcweir 
131*cdf0e10cSrcweir     /**
132*cdf0e10cSrcweir     * Test calls the method and restores new values. <p>
133*cdf0e10cSrcweir     * Has <b> OK </b> status if the method successfully returns. <p>
134*cdf0e10cSrcweir     * The following method tests are to be completed successfully before :
135*cdf0e10cSrcweir     * <ul>
136*cdf0e10cSrcweir     *  <li> <code> setRowDescriptions </code></li>
137*cdf0e10cSrcweir     * </ul>
138*cdf0e10cSrcweir     */
139*cdf0e10cSrcweir     public void _setData() {
140*cdf0e10cSrcweir         rowDscs = oObj.getRowDescriptions();
141*cdf0e10cSrcweir         colDscs = oObj.getColumnDescriptions();
142*cdf0e10cSrcweir 
143*cdf0e10cSrcweir         bResult = true;
144*cdf0e10cSrcweir         double[][] _data = oObj.getData();
145*cdf0e10cSrcweir         data = _data;
146*cdf0e10cSrcweir 
147*cdf0e10cSrcweir         for (int i = 0; i < rowDscs.length; i++) {
148*cdf0e10cSrcweir             for (int j = 0; j < colDscs.length; j++)
149*cdf0e10cSrcweir                 data[i][j] = i * (j + 1);
150*cdf0e10cSrcweir         }
151*cdf0e10cSrcweir         oObj.setData(data);
152*cdf0e10cSrcweir 
153*cdf0e10cSrcweir         tRes.tested("setData()", bResult);
154*cdf0e10cSrcweir     }
155*cdf0e10cSrcweir 
156*cdf0e10cSrcweir     /**
157*cdf0e10cSrcweir     * Test calls the method and compare returned values with values restored
158*cdf0e10cSrcweir     * after method <code>setColumnDescriptions</code>. <p>
159*cdf0e10cSrcweir     * Has <b> OK </b> status if the returned values equils to restored values. <p>
160*cdf0e10cSrcweir     * The following method tests are to be completed successfully before :
161*cdf0e10cSrcweir     * <ul>
162*cdf0e10cSrcweir     *  <li> <code> setData </code> : to set and restore new values </li>
163*cdf0e10cSrcweir     * </ul>
164*cdf0e10cSrcweir     */
165*cdf0e10cSrcweir     public void _getColumnDescriptions() {
166*cdf0e10cSrcweir         requiredMethod("setColumnDescriptions()");
167*cdf0e10cSrcweir         bResult = true;
168*cdf0e10cSrcweir 
169*cdf0e10cSrcweir         String[] dscs = oObj.getColumnDescriptions();
170*cdf0e10cSrcweir         bResult &= dscs.length == colDscs.length;
171*cdf0e10cSrcweir         if (bResult) {
172*cdf0e10cSrcweir             for (int i = 0; i < dscs.length; i++) {
173*cdf0e10cSrcweir                 bResult &= dscs[i].equals(colDscs[i]);
174*cdf0e10cSrcweir             }
175*cdf0e10cSrcweir         }
176*cdf0e10cSrcweir 
177*cdf0e10cSrcweir         tRes.tested("getColumnDescriptions()", bResult);
178*cdf0e10cSrcweir     }
179*cdf0e10cSrcweir 
180*cdf0e10cSrcweir     /**
181*cdf0e10cSrcweir     * Test calls the method and compare returned values with values restored
182*cdf0e10cSrcweir     * after method <code>setRowDescriptions</code>. <p>
183*cdf0e10cSrcweir     * Has <b> OK </b> status if the returned values equils to restored values. <p>
184*cdf0e10cSrcweir     * The following method tests are to be completed successfully before :
185*cdf0e10cSrcweir     * <ul>
186*cdf0e10cSrcweir     *  <li> <code> setData </code> : to set and restore new values </li>
187*cdf0e10cSrcweir     * </ul>
188*cdf0e10cSrcweir     */
189*cdf0e10cSrcweir     public void _getRowDescriptions() {
190*cdf0e10cSrcweir         requiredMethod("setRowDescriptions()");
191*cdf0e10cSrcweir         bResult = true;
192*cdf0e10cSrcweir 
193*cdf0e10cSrcweir         String[] dscs = oObj.getRowDescriptions();
194*cdf0e10cSrcweir         bResult &= dscs.length == rowDscs.length;
195*cdf0e10cSrcweir         if (bResult) {
196*cdf0e10cSrcweir             for (int i = 0; i < dscs.length; i++) {
197*cdf0e10cSrcweir                 bResult &= dscs[i].equals(rowDscs[i]);
198*cdf0e10cSrcweir             }
199*cdf0e10cSrcweir         }
200*cdf0e10cSrcweir 
201*cdf0e10cSrcweir         tRes.tested("getRowDescriptions()", bResult);
202*cdf0e10cSrcweir     }
203*cdf0e10cSrcweir 
204*cdf0e10cSrcweir     /**
205*cdf0e10cSrcweir     * Test calls the method and compare returned values with values restored
206*cdf0e10cSrcweir     * after method <code>setData</code>. <p>
207*cdf0e10cSrcweir     * Has <b> OK </b> status if the returned values equils to restored values. <p>
208*cdf0e10cSrcweir     * The following method tests are to be completed successfully before :
209*cdf0e10cSrcweir     * <ul>
210*cdf0e10cSrcweir     *  <li> <code> setData </code> : to set and restore new values </li>
211*cdf0e10cSrcweir     * </ul>
212*cdf0e10cSrcweir     */
213*cdf0e10cSrcweir     public void _getData() {
214*cdf0e10cSrcweir         requiredMethod("setData()");
215*cdf0e10cSrcweir         bResult = true;
216*cdf0e10cSrcweir 
217*cdf0e10cSrcweir         double[][] _data = oObj.getData();
218*cdf0e10cSrcweir         data = _data;
219*cdf0e10cSrcweir         for (int i = 0; i < rowDscs.length; i++) {
220*cdf0e10cSrcweir             for (int j = 0; j < colDscs.length; j++) {
221*cdf0e10cSrcweir                 bResult &= data[i][j] == _data[i][j];
222*cdf0e10cSrcweir             }
223*cdf0e10cSrcweir         }
224*cdf0e10cSrcweir 
225*cdf0e10cSrcweir         tRes.tested("getData()", bResult);
226*cdf0e10cSrcweir     }
227*cdf0e10cSrcweir 
228*cdf0e10cSrcweir     protected void after() {
229*cdf0e10cSrcweir         disposeEnvironment();
230*cdf0e10cSrcweir     }
231*cdf0e10cSrcweir }
232*cdf0e10cSrcweir 
233*cdf0e10cSrcweir 
234