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