diff options
author | PJ Fanning <fanningpj@apache.org> | 2021-08-07 13:23:28 +0000 |
---|---|---|
committer | PJ Fanning <fanningpj@apache.org> | 2021-08-07 13:23:28 +0000 |
commit | f15474f1bae6079a0d55f8d3ef53b2651267864f (patch) | |
tree | bc4320bde0d8a85ac6d11c89cc26854f4bfe97ce /poi | |
parent | 87ea84cf48cc115994b4dfa2f2c6ee00febe1d92 (diff) | |
download | poi-f15474f1bae6079a0d55f8d3ef53b2651267864f.tar.gz poi-f15474f1bae6079a0d55f8d3ef53b2651267864f.zip |
add test
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1892075 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'poi')
-rw-r--r-- | poi/src/test/java/org/apache/poi/ss/formula/functions/TestTimeValue.java | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/poi/src/test/java/org/apache/poi/ss/formula/functions/TestTimeValue.java b/poi/src/test/java/org/apache/poi/ss/formula/functions/TestTimeValue.java index 480a58b8fe..0a125bd80b 100644 --- a/poi/src/test/java/org/apache/poi/ss/formula/functions/TestTimeValue.java +++ b/poi/src/test/java/org/apache/poi/ss/formula/functions/TestTimeValue.java @@ -17,12 +17,16 @@ package org.apache.poi.ss.formula.functions; +import org.apache.poi.hssf.usermodel.*; import org.apache.poi.ss.formula.eval.*; +import org.apache.poi.ss.usermodel.CellType; +import org.apache.poi.ss.usermodel.CellValue; import org.apache.poi.util.LocaleUtil; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; +import java.io.IOException; import java.util.Locale; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -73,6 +77,18 @@ final class TestTimeValue { "Math.E evals to invalid"); } + @Test + void testTimeValueInHSSF() throws IOException { + try (HSSFWorkbook wb = new HSSFWorkbook()) { + HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb); + HSSFSheet sheet = wb.createSheet(); + HSSFRow row = sheet.createRow(0); + row.createCell(0).setCellValue("8/22/2011 12:00"); + HSSFCell cell = row.createCell(1); + confirmNumericResult(fe, cell, "TIMEVALUE(A1)", 0.5); + } + } + private ValueEval invokeTimeValue(ValueEval text) { return new TimeValue().evaluate(0, 0, text); } @@ -93,4 +109,12 @@ final class TestTimeValue { assertEquals(ErrorEval.class, result.getClass()); assertEquals(ErrorEval.VALUE_INVALID.getErrorCode(), ((ErrorEval) result).getErrorCode()); } + + private static void confirmNumericResult(HSSFFormulaEvaluator fe, HSSFCell cell, String formulaText, double expectedResult) { + cell.setCellFormula(formulaText); + fe.notifyUpdateCell(cell); + CellValue result = fe.evaluate(cell); + assertEquals(result.getCellType(), CellType.NUMERIC); + assertEquals(expectedResult, result.getNumberValue()); + } } |