[bug-65915] possible issue in boolean function support

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1898425 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
PJ Fanning 2022-02-25 19:18:37 +00:00
parent 18a5720eeb
commit 2a9a201742
2 changed files with 16 additions and 9 deletions

View File

@ -139,14 +139,7 @@ public abstract class BooleanFunction implements Function,ArrayFunction {
@Override @Override
public ValueEval evaluateArray(ValueEval[] args, int srcRowIndex, int srcColumnIndex) { public ValueEval evaluateArray(ValueEval[] args, int srcRowIndex, int srcColumnIndex) {
if (args.length == 1) { return evaluate(args, srcRowIndex, srcColumnIndex);
return evaluateOneArrayArg(args[0], srcRowIndex, srcColumnIndex,
vA -> evaluate(new ValueEval[]{vA}, srcRowIndex, srcColumnIndex));
} else if (args.length == 2) {
return evaluateTwoArrayArgs(args[0], args[1], srcRowIndex, srcColumnIndex,
(vA, vB) -> evaluate(new ValueEval[]{vA, vB}, srcRowIndex, srcColumnIndex));
}
return ErrorEval.VALUE_INVALID;
} }
private static ValueEval evaluateFalse(ValueEval[] args, int srcRowIndex, int srcColumnIndex) { private static ValueEval evaluateFalse(ValueEval[] args, int srcRowIndex, int srcColumnIndex) {

View File

@ -98,7 +98,21 @@ final class TestOrFunction {
HSSFSheet sheet = wb.createSheet(); HSSFSheet sheet = wb.createSheet();
HSSFRow row = sheet.createRow(0); HSSFRow row = sheet.createRow(0);
HSSFCell cell = row.createCell(0); HSSFCell cell = row.createCell(0);
sheet.setArrayFormula("INDEX({1},1,IF(OR(FALSE,FALSE),1,1))", new CellRangeAddress(0, 0, 0, 0)); sheet.setArrayFormula("INDEX({1},1,IF(OR(FALSE,FALSE),0,1))", new CellRangeAddress(0, 0, 0, 0));
fe.evaluateAll();
assertEquals(1.0, cell.getNumericCellValue());
}
}
@Test
void testBug65915Array3Function() throws IOException {
//https://bz.apache.org/bugzilla/show_bug.cgi?id=65915
try (HSSFWorkbook wb = new HSSFWorkbook()) {
HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb);
HSSFSheet sheet = wb.createSheet();
HSSFRow row = sheet.createRow(0);
HSSFCell cell = row.createCell(0);
sheet.setArrayFormula("INDEX({1},1,IF(OR(1=2,2=3,3=4),0,1))", new CellRangeAddress(0, 0, 0, 0));
fe.evaluateAll(); fe.evaluateAll();
assertEquals(1.0, cell.getNumericCellValue()); assertEquals(1.0, cell.getNumericCellValue());
} }