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.table;
25 
26 import lib.MultiMethodTest;
27 
28 import com.sun.star.table.CellContentType;
29 import com.sun.star.table.XCell;
30 
31 
32 /**
33 * Testing <code>com.sun.star.table.XCell</code>
34 * interface methods :
35 * <ul>
36 *  <li><code> getFormula()</code></li>
37 *  <li><code> setFormula()</code></li>
38 *  <li><code> getValue()</code></li>
39 *  <li><code> setValue()</code></li>
40 *  <li><code> getType()</code></li>
41 *  <li><code> getError()</code></li>
42 * </ul> <p>
43 * Test is <b> NOT </b> multithread compilant. <p>
44 * @see com.sun.star.table.XCell
45 */
46 public class _XCell extends MultiMethodTest {
47   public XCell oObj = null;
48 
49     /**
50     * First time errors checked when a proper formula is entered.
51     * Second time an incorrect formula entered and errors are checked.<p>
52     * Has <b> OK </b> status if in the first case error code 0 returned,
53     * and in the second case none-zerro code returned. <p>
54     * The following method tests are to be completed successfully before :
55     * <ul>
56     *  <li> <code> setFormula() </code> : the method must set proper
57     *   formula into cell, so there must be no errors </li>
58     * </ul>
59     */
_getError()60     public void _getError() {
61         requiredMethod("setFormula()") ;
62 
63         boolean result = true;
64 
65         if (oObj.getError() != 0) {
66             result = false ;
67             log.println("getError(): Expected error code is 0, but returned " +
68                  oObj.getError()) ;
69         }
70         oObj.setFormula("=sqrt(-2)") ; // incorrect formula
71         if (oObj.getError() == 0) {
72             result = false ;
73             log.println("getError(): # Non zero error code expected,"+
74                 " but 0 returned") ;
75         }
76 
77         tRes.tested("getError()", result);
78     } // end getError()
79 
80     /**
81     * Sets a formula and then gets it. <p>
82     * Has <b> OK </b> status if the formula set are the same as get. <p>
83     */
_getFormula()84     public void _getFormula() {
85         boolean result = true;
86 
87         String formula = "";
88         log.println("getFormula()");
89         oObj.setFormula("=2+2");
90 
91         formula = (String) oObj.getFormula();
92 
93         result &= formula.endsWith("2+2");
94         tRes.tested("getFormula()", result);
95     } // end getFormula()
96 
97     /**
98     * Gets the type and check it. <p>
99     * Has <b> OK </b> status if the type is one of valid values. <p>
100     */
_getType()101     public void _getType() {
102         boolean result = true;
103         result = true ;
104         log.println("getType() ...");
105 
106         if(oObj.getType() == CellContentType.EMPTY) result &= true ;
107         else if (oObj.getType() == CellContentType.VALUE) result &= true ;
108         else if (oObj.getType() == CellContentType.TEXT) result &= true ;
109         else if (oObj.getType() == CellContentType.FORMULA) result &= true ;
110         else result = false;
111 
112         tRes.tested ("getType()", result) ;
113     } // end getType()
114 
115     /**
116     * Test calls the method. <p>
117     * Has <b> OK </b> status if the method successfully returns
118     * and no exceptions were thrown. <p>
119     */
_getValue()120     public void _getValue() {
121         boolean result = true;
122         double value = 0;
123         log.println("getValue() ...");
124 
125         value = (double) oObj.getValue();
126 
127         tRes.tested("getValue()",result);
128     } // end getValue()
129 
130     /**
131     * Sets a formula and then gets it. <p>
132     * Has <b> OK </b> status if the formula set are the same as get. <p>
133     */
_setFormula()134     public void _setFormula() {
135         boolean result = true;
136         String formula = "";
137         log.println("setFormula() ...");
138 
139         oObj.setFormula("=2/6") ;
140 
141         formula = (String) oObj.getFormula();
142 
143         result &= formula.endsWith("2/6");
144         tRes.tested ("setFormula()", result) ;
145     } // end setFormula
146 
147     /**
148     * Sets a value and then gets it. <p>
149     * Has <b> OK </b> status if the value set is equal to value get. <p>
150     */
_setValue()151     public void _setValue() {
152         boolean result = true;
153         double cellValue = 0;
154         log.println("setValue() ...");
155 
156         oObj.setValue(222.333) ;
157         cellValue = (double) oObj.getValue() ;
158 
159         result &= (cellValue == 222.333);
160         tRes.tested("setValue()", result);
161        } // end setValue()
162 }
163 
164