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

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


    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

    assertEquals(ptgClass, result.getClass());
    return result;
  }

  public void testParseNumber() {
    IntPtg ip;

    // bug 33160
    ip = (IntPtg) parseSingleToken("40", IntPtg.class);
    assertEquals(40, ip.getValue());
    ip = (IntPtg) parseSingleToken("40000", IntPtg.class);
    assertEquals(40000, ip.getValue());

    // check the upper edge of the IntPtg range:
    ip = (IntPtg) parseSingleToken("65535", IntPtg.class);
    assertEquals(65535, ip.getValue());
    NumberPtg np = (NumberPtg) parseSingleToken("65536", NumberPtg.class);
    assertEquals(65536, np.getValue(), 0);

    np = (NumberPtg) parseSingleToken("65534.6", NumberPtg.class);
    assertEquals(65534.6, np.getValue(), 0);
View Full Code Here

  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

  private static void confirmUnary(String formulaText, double val, Class<?>...expectedTokenTypes) {
    Ptg[] ptgs = parseFormula(formulaText);
    confirmTokenClasses(ptgs, expectedTokenTypes);
    Ptg ptg0 = ptgs[0];
    if (ptg0 instanceof IntPtg) {
      IntPtg intPtg = (IntPtg) ptg0;
      assertEquals((int)val, intPtg.getValue());
    } else if (ptg0 instanceof NumberPtg) {
      NumberPtg numberPtg = (NumberPtg) ptg0;
      assertEquals(val, numberPtg.getValue(), 0.0);
    } else {
      fail("bad ptg0 " + ptg0);
View Full Code Here

    assertEquals(ptgClass, result.getClass());
    return result;
  }

  public void testParseNumber() {
    IntPtg ip;

    // bug 33160
    ip = (IntPtg) parseSingleToken("40", IntPtg.class);
    assertEquals(40, ip.getValue());
    ip = (IntPtg) parseSingleToken("40000", IntPtg.class);
    assertEquals(40000, ip.getValue());

    // check the upper edge of the IntPtg range:
    ip = (IntPtg) parseSingleToken("65535", IntPtg.class);
    assertEquals(65535, ip.getValue());
    NumberPtg np = (NumberPtg) parseSingleToken("65536", NumberPtg.class);
    assertEquals(65536, np.getValue(), 0);

    np = (NumberPtg) parseSingleToken("65534.6", NumberPtg.class);
    assertEquals(65534.6, np.getValue(), 0);
View Full Code Here

  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 = toFormulaString(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 = toFormulaString(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 {
      toFormulaString(ptgs);
      fail("Expected exception was not thrown");
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

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.