Package org.apache.poi.hssf.record.formula

Examples of org.apache.poi.hssf.record.formula.IntPtg


  public void testSpaceAtStartOfFormula() {
    // Simulating cell formula of "= 4" (note space)
    // The same Ptg array can be observed if an excel file is saved with that exact formula

    AttrPtg spacePtg = AttrPtg.createSpace(AttrPtg.SpaceType.SPACE_BEFORE, 1);
    Ptg[] ptgs = { spacePtg, new IntPtg(4), };
    String formulaString;
    try {
      formulaString = FormulaParser.toFormulaString(null, ptgs);
    } catch (IllegalStateException e) {
      if(e.getMessage().equalsIgnoreCase("too much stuff left on the stack")) {
        throw new AssertionFailedError("Identified bug 44609");
      }
      // else some unexpected error
      throw e;
    }
    // FormulaParser strips spaces anyway
    assertEquals("4", formulaString);

    ptgs = new Ptg[] { new IntPtg(3), spacePtg, new IntPtg(4), spacePtg, AddPtg.instance, };
    formulaString = FormulaParser.toFormulaString(null, ptgs);
    assertEquals("3+4", formulaString);
  }
View Full Code Here


  public void testTooFewOperandArgs() {
    // Simulating badly encoded cell formula of "=/1"
    // Not sure if Excel could ever produce this
    Ptg[] ptgs = {
        // Excel would probably have put tMissArg here
        new IntPtg(1),
        DividePtg.instance,
    };
    try {
      FormulaParser.toFormulaString(null, ptgs);
      fail("Expected exception was not thrown");
View Full Code Here

    FormulaParser fp = new FormulaParser(simpleif, null);
    fp.parse();
    Ptg[] asts = fp.getRPNPtg();
    assertEquals(9, asts.length);
   
    IntPtg op1 = (IntPtg) asts[0];
    IntPtg op2 = (IntPtg) asts[1];
    EqualPtg eq = (EqualPtg) asts[2];   
    AttrPtg ifPtg = (AttrPtg) asts[3];
    IntPtg res1 = (IntPtg) asts[4];
       
    AttrPtg ptgGoto= (AttrPtg) asts[5];   
    assertEquals("Goto 1 Length", (short)10, ptgGoto.getData());
   
    IntPtg res2 = (IntPtg) asts[6];   
    AttrPtg ptgGoto2 = (AttrPtg) asts[7];   
    assertEquals("Goto 2 Length", (short)3, ptgGoto2.getData());
   
    assertEquals("If FALSE offset", (short)7, ifPtg.getData());
   
View Full Code Here

    assertTrue("IF Attr set correctly", (asts[3] instanceof AttrPtg));
    AttrPtg ifFunc = (AttrPtg)asts[3];
    assertTrue("It is not an if", ifFunc.isOptimizedIf());
   
    assertTrue("Single Value is not an IntPtg", (asts[4] instanceof IntPtg));
    IntPtg intPtg = (IntPtg)asts[4];
    assertEquals("Result", (short)10, intPtg.getValue());
   
    assertTrue("Ptg is not a Variable Function", (asts[6] instanceof FuncVarPtg));
    FuncVarPtg funcPtg = (FuncVarPtg)asts[6];
    assertEquals("Arguments", 2, funcPtg.getNumberOfOperands());
   
View Full Code Here

   * the whole formula which converts tAttrSum to tFuncVar("SUM") )
   */
  public void testAttrSum() {

    Ptg[] ptgs = {
      new IntPtg(42),
      AttrPtg.SUM,
    };

    ValueEval result = evaluateFormula(ptgs);
    assertEquals(42, ((NumberEval)result).getNumberValue(), 0.0);
View Full Code Here

   * the whole formula which converts tAttrSum to tFuncVar("SUM") )
   */
  public void testMemFunc() {

    Ptg[] ptgs = {
      new IntPtg(42),
      AttrPtg.SUM,
    };

    ValueEval result = evaluateFormula(ptgs);
    assertEquals(42, ((NumberEval)result).getNumberValue(), 0.0);
View Full Code Here

    assertTrue("IF Attr set correctly", (ptgs[3] instanceof AttrPtg));
    AttrPtg ifFunc = (AttrPtg)ptgs[3];
    assertTrue("It is not an if", ifFunc.isOptimizedIf());

    assertTrue("Single Value is not an IntPtg", (ptgs[4] instanceof IntPtg));
    IntPtg intPtg = (IntPtg)ptgs[4];
    assertEquals("Result", (short)10, intPtg.getValue());

    assertTrue("Ptg is not a Variable Function", (ptgs[6] instanceof FuncVarPtg));
    FuncVarPtg funcPtg = (FuncVarPtg)ptgs[6];
    assertEquals("Arguments", 2, funcPtg.getNumberOfOperands());
  }
View Full Code Here

    assertTrue("IF Attr set correctly", (ptgs[3] instanceof AttrPtg));
    AttrPtg ifFunc = (AttrPtg)ptgs[3];
    assertTrue("It is not an if", ifFunc.isOptimizedIf());

    assertTrue("Single Value is not an IntPtg", (ptgs[4] instanceof IntPtg));
    IntPtg intPtg = (IntPtg)ptgs[4];
    assertEquals("Result", (short)10, intPtg.getValue());

    assertTrue("Ptg is not a Variable Function", (ptgs[6] instanceof FuncVarPtg));
    FuncVarPtg funcPtg = (FuncVarPtg)ptgs[6];
    assertEquals("Arguments", 2, funcPtg.getNumberOfOperands());
  }
View Full Code Here

   * the whole formula which converts tAttrSum to tFuncVar("SUM") )
   */
  public void testAttrSum() {

    Ptg[] ptgs = {
      new IntPtg(42),
      AttrPtg.SUM,
    };

    ValueEval result = new WorkbookEvaluator(null).evaluateFormula(0, 0, 0, ptgs, null);
    assertEquals(42, ((NumberEval)result).getNumberValue(), 0.0);
View Full Code Here

   * the whole formula which converts tAttrSum to tFuncVar("SUM") )
   */
  public void testMemFunc() {

    Ptg[] ptgs = {
      new IntPtg(42),
      AttrPtg.SUM,
    };

    ValueEval result = new WorkbookEvaluator(null).evaluateFormula(0, 0, 0, ptgs, null);
    assertEquals(42, ((NumberEval)result).getNumberValue(), 0.0);
View Full Code Here

TOP

Related Classes of org.apache.poi.hssf.record.formula.IntPtg

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.