mirror of https://github.com/apache/poi.git
Bug 64393: Adjust relational operators to handle MissingArgEval correctly
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1877815 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
d2ad752e1c
commit
ff919eb0e4
|
@ -86,11 +86,11 @@ public abstract class RelationalOperationEval extends Fixed2ArgFunction implemen
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int doCompare(ValueEval va, ValueEval vb) {
|
private static int doCompare(ValueEval va, ValueEval vb) {
|
||||||
// special cases when one operand is blank
|
// special cases when one operand is blank or missing
|
||||||
if (va == BlankEval.instance) {
|
if (va == BlankEval.instance || va instanceof MissingArgEval) {
|
||||||
return compareBlank(vb);
|
return compareBlank(vb);
|
||||||
}
|
}
|
||||||
if (vb == BlankEval.instance) {
|
if (vb == BlankEval.instance || vb instanceof MissingArgEval) {
|
||||||
return -compareBlank(va);
|
return -compareBlank(va);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -131,7 +131,7 @@ public abstract class RelationalOperationEval extends Fixed2ArgFunction implemen
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int compareBlank(ValueEval v) {
|
private static int compareBlank(ValueEval v) {
|
||||||
if (v == BlankEval.instance) {
|
if (v == BlankEval.instance || v instanceof MissingArgEval) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (v instanceof BoolEval) {
|
if (v instanceof BoolEval) {
|
||||||
|
|
|
@ -18,6 +18,8 @@
|
||||||
package org.apache.poi.ss.formula.eval;
|
package org.apache.poi.ss.formula.eval;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
@ -54,6 +56,66 @@ public final class TestMissingArgEval {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCompareMissingArgs() throws IOException {
|
||||||
|
try (HSSFWorkbook wb = new HSSFWorkbook()) {
|
||||||
|
HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb);
|
||||||
|
HSSFSheet sheet = wb.createSheet("Sheet1");
|
||||||
|
HSSFCell cell = sheet.createRow(0).createCell(0);
|
||||||
|
|
||||||
|
cell.setCellFormula("iferror(0/0,)<0");
|
||||||
|
fe.clearAllCachedResultValues();
|
||||||
|
CellValue cv = fe.evaluate(cell);
|
||||||
|
assertFalse(cv.getBooleanValue());
|
||||||
|
|
||||||
|
cell.setCellFormula("iferror(0/0,)<=0");
|
||||||
|
fe.clearAllCachedResultValues();
|
||||||
|
cv = fe.evaluate(cell);
|
||||||
|
assertTrue(cv.getBooleanValue());
|
||||||
|
|
||||||
|
cell.setCellFormula("iferror(0/0,)=0");
|
||||||
|
fe.clearAllCachedResultValues();
|
||||||
|
cv = fe.evaluate(cell);
|
||||||
|
assertTrue(cv.getBooleanValue());
|
||||||
|
|
||||||
|
cell.setCellFormula("iferror(0/0,)>=0");
|
||||||
|
fe.clearAllCachedResultValues();
|
||||||
|
cv = fe.evaluate(cell);
|
||||||
|
assertTrue(cv.getBooleanValue());
|
||||||
|
|
||||||
|
cell.setCellFormula("iferror(0/0,)>0");
|
||||||
|
fe.clearAllCachedResultValues();
|
||||||
|
cv = fe.evaluate(cell);
|
||||||
|
assertFalse(cv.getBooleanValue());
|
||||||
|
|
||||||
|
// invert above for code coverage
|
||||||
|
cell.setCellFormula("0<iferror(0/0,)");
|
||||||
|
fe.clearAllCachedResultValues();
|
||||||
|
cv = fe.evaluate(cell);
|
||||||
|
assertFalse(cv.getBooleanValue());
|
||||||
|
|
||||||
|
cell.setCellFormula("0<=iferror(0/0,)");
|
||||||
|
fe.clearAllCachedResultValues();
|
||||||
|
cv = fe.evaluate(cell);
|
||||||
|
assertTrue(cv.getBooleanValue());
|
||||||
|
|
||||||
|
cell.setCellFormula("0=iferror(0/0,)");
|
||||||
|
fe.clearAllCachedResultValues();
|
||||||
|
cv = fe.evaluate(cell);
|
||||||
|
assertTrue(cv.getBooleanValue());
|
||||||
|
|
||||||
|
cell.setCellFormula("0>=iferror(0/0,)");
|
||||||
|
fe.clearAllCachedResultValues();
|
||||||
|
cv = fe.evaluate(cell);
|
||||||
|
assertTrue(cv.getBooleanValue());
|
||||||
|
|
||||||
|
cell.setCellFormula("0>iferror(0/0,)");
|
||||||
|
fe.clearAllCachedResultValues();
|
||||||
|
cv = fe.evaluate(cell);
|
||||||
|
assertFalse(cv.getBooleanValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCountFuncs() throws IOException {
|
public void testCountFuncs() throws IOException {
|
||||||
try (HSSFWorkbook wb = new HSSFWorkbook()) {
|
try (HSSFWorkbook wb = new HSSFWorkbook()) {
|
||||||
|
|
Loading…
Reference in New Issue