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

Source Code of org.apache.poi.hssf.record.formula.functions.TestLen

/* ====================================================================
   Licensed to the Apache Software Foundation (ASF) under one or more
   contributor license agreements.  See the NOTICE file distributed with
   this work for additional information regarding copyright ownership.
   The ASF licenses this file to You under the Apache License, Version 2.0
   (the "License"); you may not use this file except in compliance with
   the License.  You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
==================================================================== */

package org.apache.poi.hssf.record.formula.functions;

import junit.framework.TestCase;

import org.apache.poi.hssf.record.formula.eval.BlankEval;
import org.apache.poi.hssf.record.formula.eval.BoolEval;
import org.apache.poi.hssf.record.formula.eval.ErrorEval;
import org.apache.poi.hssf.record.formula.eval.Eval;
import org.apache.poi.hssf.record.formula.eval.NumberEval;
import org.apache.poi.hssf.record.formula.eval.StringEval;
/**
* Tests for Excel function LEN()
*
* @author Josh Micich
*/
public final class TestLen extends TestCase {

 
  private static Eval invokeLen(Eval text) {
    Eval[] args = new Eval[] { text, };
    return new Len().evaluate(args, -1, (short)-1);
  }

  private void confirmLen(Eval text, int expected) {
    Eval result = invokeLen(text);
    assertEquals(NumberEval.class, result.getClass());
    assertEquals(expected, ((NumberEval)result).getNumberValue(), 0);
  }

  private void confirmLen(Eval text, ErrorEval expectedError) {
    Eval result = invokeLen(text);
    assertEquals(ErrorEval.class, result.getClass());
    assertEquals(expectedError.getErrorCode(), ((ErrorEval)result).getErrorCode());
  }
 
  public void testBasic() {
   
    confirmLen(new StringEval("galactic"), 8);
  }
 
  /**
   * Valid cases where text arg is not exactly a string
   */
  public void testUnusualArgs() {
   
    // text (first) arg type is number, other args are strings with fractional digits
    confirmLen(new NumberEval(123456), 6);
    confirmLen(BoolEval.FALSE, 5);
    confirmLen(BoolEval.TRUE, 4);
    confirmLen(BlankEval.INSTANCE, 0);
  }

  public void testErrors() {
    confirmLen(ErrorEval.NAME_INVALID, ErrorEval.NAME_INVALID);
  }
}
TOP

Related Classes of org.apache.poi.hssf.record.formula.functions.TestLen

TOP
Copyright © 2018 www.massapi.com. 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.