1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 package ifc.table; 29 30 import lib.MultiMethodTest; 31 32 import com.sun.star.table.CellContentType; 33 import com.sun.star.table.XCell; 34 35 36 /** 37 * Testing <code>com.sun.star.table.XCell</code> 38 * interface methods : 39 * <ul> 40 * <li><code> getFormula()</code></li> 41 * <li><code> setFormula()</code></li> 42 * <li><code> getValue()</code></li> 43 * <li><code> setValue()</code></li> 44 * <li><code> getType()</code></li> 45 * <li><code> getError()</code></li> 46 * </ul> <p> 47 * Test is <b> NOT </b> multithread compilant. <p> 48 * @see com.sun.star.table.XCell 49 */ 50 public class _XCell extends MultiMethodTest { 51 public XCell oObj = null; 52 53 /** 54 * First time errors checked when a proper formula is entered. 55 * Second time an incorrect formula entered and errors are checked.<p> 56 * Has <b> OK </b> status if in the first case error code 0 returned, 57 * and in the second case none-zerro code returned. <p> 58 * The following method tests are to be completed successfully before : 59 * <ul> 60 * <li> <code> setFormula() </code> : the method must set proper 61 * formula into cell, so there must be no errors </li> 62 * </ul> 63 */ 64 public void _getError() { 65 requiredMethod("setFormula()") ; 66 67 boolean result = true; 68 69 if (oObj.getError() != 0) { 70 result = false ; 71 log.println("getError(): Expected error code is 0, but returned " + 72 oObj.getError()) ; 73 } 74 oObj.setFormula("=sqrt(-2)") ; // incorrect formula 75 if (oObj.getError() == 0) { 76 result = false ; 77 log.println("getError(): # Non zero error code expected,"+ 78 " but 0 returned") ; 79 } 80 81 tRes.tested("getError()", result); 82 } // end getError() 83 84 /** 85 * Sets a formula and then gets it. <p> 86 * Has <b> OK </b> status if the formula set are the same as get. <p> 87 */ 88 public void _getFormula() { 89 boolean result = true; 90 91 String formula = ""; 92 log.println("getFormula()"); 93 oObj.setFormula("=2+2"); 94 95 formula = (String) oObj.getFormula(); 96 97 result &= formula.endsWith("2+2"); 98 tRes.tested("getFormula()", result); 99 } // end getFormula() 100 101 /** 102 * Gets the type and check it. <p> 103 * Has <b> OK </b> status if the type is one of valid values. <p> 104 */ 105 public void _getType() { 106 boolean result = true; 107 result = true ; 108 log.println("getType() ..."); 109 110 if(oObj.getType() == CellContentType.EMPTY) result &= true ; 111 else if (oObj.getType() == CellContentType.VALUE) result &= true ; 112 else if (oObj.getType() == CellContentType.TEXT) result &= true ; 113 else if (oObj.getType() == CellContentType.FORMULA) result &= true ; 114 else result = false; 115 116 tRes.tested ("getType()", result) ; 117 } // end getType() 118 119 /** 120 * Test calls the method. <p> 121 * Has <b> OK </b> status if the method successfully returns 122 * and no exceptions were thrown. <p> 123 */ 124 public void _getValue() { 125 boolean result = true; 126 double value = 0; 127 log.println("getValue() ..."); 128 129 value = (double) oObj.getValue(); 130 131 tRes.tested("getValue()",result); 132 } // end getValue() 133 134 /** 135 * Sets a formula and then gets it. <p> 136 * Has <b> OK </b> status if the formula set are the same as get. <p> 137 */ 138 public void _setFormula() { 139 boolean result = true; 140 String formula = ""; 141 log.println("setFormula() ..."); 142 143 oObj.setFormula("=2/6") ; 144 145 formula = (String) oObj.getFormula(); 146 147 result &= formula.endsWith("2/6"); 148 tRes.tested ("setFormula()", result) ; 149 } // end setFormula 150 151 /** 152 * Sets a value and then gets it. <p> 153 * Has <b> OK </b> status if the value set is equal to value get. <p> 154 */ 155 public void _setValue() { 156 boolean result = true; 157 double cellValue = 0; 158 log.println("setValue() ..."); 159 160 oObj.setValue(222.333) ; 161 cellValue = (double) oObj.getValue() ; 162 163 result &= (cellValue == 222.333); 164 tRes.tested("setValue()", result); 165 } // end setValue() 166 } 167 168