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 complex.dataPilot;
25 
26 import com.sun.star.sheet.XDataPilotTable;
27 import com.sun.star.table.CellAddress;
28 import com.sun.star.table.CellRangeAddress;
29 import com.sun.star.table.XCell;
30 // import lib.Status;
31 //import lib.StatusException;
32 import lib.TestParameters;
33 // import share.LogWriter;
34 
35 /**
36 * Testing <code>com.sun.star.sheet.XDataPilotTable</code>
37 * interface methods :
38 * <ul>
39 *  <li><code> getOutputRange()</code></li>
40 *  <li><code> refresh()</code></li>
41 * </ul> <p>
42 * This test needs the following object relations :
43 * <ul>
44 *  <li> <code>'OUTPUTRANGE'</code> (of type <code>CellAddress</code>):
45 *   to check value returned by method <code>getOutputRange()</code> </li>
46 *  <li> <code>'CELLFORCHANGE'</code> (of type <code>XCell</code>):
47 *   to check the method refresh(value of this cell will be changed)</li>
48 *  <li> <code>'CELLFORCHECK'</code> (of type <code>XCell</code>):
49 * to check the method refresh (value of this cell must be changed after refresh
50 * call) </li><ul> <p>
51 * @see com.sun.star.sheet.XDataPilotTable
52 * @see com.sun.star.table.CellAddress
53 */
54 public class _XDataPilotTable {
55 
56     public XDataPilotTable oObj = null;
57     XCell xCellForChange = null;
58     XCell xCellForCheck = null;
59     CellAddress OutputRange = null;
60     int changeValue = 0;
61 
62     /**
63      * The test parameters
64      */
65     private TestParameters param = null;
66 
67     /**
68      * The log writer
69      */
70     // private LogWriter log = null;
71 
72     /**
73      * Constructor: gets the object to test, a logger and the test parameters
74      * @param xObj The test object
75 
76      * @param param The test parameters
77      */
_XDataPilotTable(XDataPilotTable xObj , TestParameters param)78     public _XDataPilotTable(XDataPilotTable xObj/*,
79                                     LogWriter log*/, TestParameters param) {
80         oObj = xObj;
81         // this.log = log;
82         this.param = param;
83     }
84 
before()85     public boolean before() {
86         xCellForChange = (XCell)param.get("CELLFORCHANGE");
87         xCellForCheck = (XCell)param.get("CELLFORCHECK");
88         OutputRange = (CellAddress)param.get("OUTPUTRANGE");
89         changeValue = ((Integer)param.get("CHANGEVALUE")).intValue();
90 
91         if (xCellForChange == null || OutputRange == null ||
92                 xCellForCheck == null) {
93             System.out.println("Relation not found");
94             return false;
95         }
96         return true;
97     }
98     /**
99     * Test calls the method and checks returned value using value obtained by
100     * object relation <code>'OUTPUTRANGE'</code>. <p>
101     * Has <b> OK </b> status if values are equal. <p>
102      * @return
103      */
_getOutputRange()104     public boolean _getOutputRange(){
105         boolean bResult = true;
106         CellRangeAddress objRange = oObj.getOutputRange();
107         bResult &= OutputRange.Sheet == objRange.Sheet;
108         bResult &= OutputRange.Row == objRange.StartRow;
109         bResult &= OutputRange.Column == objRange.StartColumn;
110         return bResult;
111     }
112 
113     /**
114     * Test sets new value of the cell obtained by object relation
115     * 'CELLFORCHANGE', and checks value of the cell obtained by object
116     * relation 'CELLFORCHECK'.<p>
117     * Has <b>OK</b> status if value of the cell obtained by object relation
118     * 'CELLFORCHECK' is changed. <p>
119      * @return
120      */
_refresh()121     public boolean _refresh(){
122         xCellForChange.setValue(changeValue);
123         double oldData = xCellForCheck.getValue();
124         oObj.refresh();
125         double newData = xCellForCheck.getValue();
126         System.out.println("Old data:" + oldData + "; new data:" + newData);
127 
128         return oldData != newData;
129     }
130 }
131 
132