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