diff options
Diffstat (limited to 'src/testcases/org/apache/poi/ss/formula/functions')
2 files changed, 52 insertions, 4 deletions
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/BaseTestFunctionsFromSpreadsheet.java b/src/testcases/org/apache/poi/ss/formula/functions/BaseTestFunctionsFromSpreadsheet.java index 88b52493ea..7b899350c1 100644 --- a/src/testcases/org/apache/poi/ss/formula/functions/BaseTestFunctionsFromSpreadsheet.java +++ b/src/testcases/org/apache/poi/ss/formula/functions/BaseTestFunctionsFromSpreadsheet.java @@ -78,6 +78,8 @@ public abstract class BaseTestFunctionsFromSpreadsheet { public int formulasRowIdx; @Parameter(value = 4) public HSSFFormulaEvaluator evaluator; + @Parameter(value = 5) + public int precisionColumnIndex; @@ -92,7 +94,7 @@ public abstract class BaseTestFunctionsFromSpreadsheet { HSSFSheet sheet = workbook.getSheetAt(sheetIdx); processFunctionGroup(data, sheet, SS.START_TEST_CASES_ROW_INDEX, filename); } - + workbook.close(); return data; @@ -101,6 +103,14 @@ public abstract class BaseTestFunctionsFromSpreadsheet { private static void processFunctionGroup(List<Object[]> data, HSSFSheet sheet, final int startRowIndex, String filename) { HSSFFormulaEvaluator evaluator = new HSSFFormulaEvaluator(sheet.getWorkbook()); + int precisionColumnIndex = -1; + HSSFRow precisionRow = sheet.getWorkbook().getSheetAt(0).getRow(11); + HSSFCell precisionCell = precisionRow == null ? null : precisionRow.getCell(0); + if(precisionCell != null && precisionCell.getCellType() == CellType.NUMERIC){ + precisionColumnIndex = (int)precisionCell.getNumericCellValue(); + } + + String currentGroupComment = ""; final int maxRows = sheet.getLastRowNum()+1; for(int rowIndex=startRowIndex; rowIndex<maxRows; rowIndex++) { @@ -131,7 +141,7 @@ public abstract class BaseTestFunctionsFromSpreadsheet { testName = evalCell.getCellFormula(); } - data.add(new Object[]{testName, filename, sheet, rowIndex, evaluator}); + data.add(new Object[]{testName, filename, sheet, rowIndex, evaluator, precisionColumnIndex}); } fail("Missing end marker '" + SS.TEST_CASES_END_MARKER + "' on sheet '" + sheet.getSheetName() + "'"); } @@ -141,7 +151,8 @@ public abstract class BaseTestFunctionsFromSpreadsheet { HSSFRow r = sheet.getRow(formulasRowIdx); HSSFCell evalCell = r.getCell(SS.COLUMN_INDEX_EVALUATION); HSSFCell expectedCell = r.getCell(SS.COLUMN_INDEX_EXPECTED_RESULT); - + HSSFCell precisionCell = r.getCell(precisionColumnIndex); + CellReference cr = new CellReference(sheet.getSheetName(), formulasRowIdx, evalCell.getColumnIndex(), false, false); String msg = String.format(Locale.ROOT, "In %s %s {=%s} '%s'" , filename, cr.formatAsString(), evalCell.getCellFormula(), testName); @@ -175,7 +186,9 @@ public abstract class BaseTestFunctionsFromSpreadsheet { case FORMULA: // will never be used, since we will call method after formula evaluation fail("Cannot expect formula as result of formula evaluation: " + msg); case NUMERIC: - assertEquals(expectedCell.getNumericCellValue(), actualValue.getNumberValue(), 0.0); + double precision = precisionCell != null && precisionCell.getCellType() == CellType.NUMERIC + ? precisionCell.getNumericCellValue() : 0.0; + assertEquals(expectedCell.getNumericCellValue(), actualValue.getNumberValue(), precision); break; case STRING: assertEquals(msg, expectedCell.getRichStringCellValue().getString(), actualValue.getStringValue()); @@ -197,6 +210,12 @@ public abstract class BaseTestFunctionsFromSpreadsheet { HSSFSheet sheet = workbook.getSheetAt(0); String specifiedClassName = sheet.getRow(2).getCell(0).getRichStringCellValue().getString(); assertEquals("Test class name in spreadsheet comment", clazz.getName(), specifiedClassName); + + HSSFRow precisionRow = sheet.getRow(11); + HSSFCell precisionCell = precisionRow == null ? null : precisionRow.getCell(0); + if(precisionCell != null && precisionCell.getCellType() == CellType.NUMERIC){ + + } } /** diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestDateTimeToNumberFromSpreadsheet.java b/src/testcases/org/apache/poi/ss/formula/functions/TestDateTimeToNumberFromSpreadsheet.java new file mode 100755 index 0000000000..87f709d91d --- /dev/null +++ b/src/testcases/org/apache/poi/ss/formula/functions/TestDateTimeToNumberFromSpreadsheet.java @@ -0,0 +1,29 @@ +/* ==================================================================== + 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.ss.formula.functions; + +import org.junit.runners.Parameterized.Parameters; + +import java.util.Collection; + +public class TestDateTimeToNumberFromSpreadsheet extends BaseTestFunctionsFromSpreadsheet { + @Parameters(name="{0}") + public static Collection<Object[]> data() throws Exception { + return data(TestDateTimeToNumberFromSpreadsheet.class, "DateTimeToNumberTestCases.xls"); + } +}
\ No newline at end of file |