mirror of https://github.com/apache/poi.git
Adjust/enhance tests for bug 62275 some more
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1849836 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
d3dc9b0338
commit
a6e9421d18
|
@ -17,26 +17,122 @@
|
||||||
|
|
||||||
package org.apache.poi.ss.formula.functions;
|
package org.apache.poi.ss.formula.functions;
|
||||||
|
|
||||||
|
import org.apache.poi.ss.usermodel.Cell;
|
||||||
import org.apache.poi.ss.usermodel.CellType;
|
import org.apache.poi.ss.usermodel.CellType;
|
||||||
|
import org.apache.poi.ss.usermodel.CellValue;
|
||||||
|
import org.apache.poi.ss.usermodel.CreationHelper;
|
||||||
import org.apache.poi.ss.usermodel.FormulaEvaluator;
|
import org.apache.poi.ss.usermodel.FormulaEvaluator;
|
||||||
|
import org.apache.poi.ss.usermodel.Row;
|
||||||
|
import org.apache.poi.ss.usermodel.Sheet;
|
||||||
import org.apache.poi.ss.usermodel.Workbook;
|
import org.apache.poi.ss.usermodel.Workbook;
|
||||||
import org.apache.poi.xssf.XSSFTestDataSamples;
|
import org.apache.poi.xssf.XSSFTestDataSamples;
|
||||||
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test the VLOOKUP function
|
* Test the VLOOKUP function
|
||||||
*/
|
*/
|
||||||
public class TestVlookup extends TestCase {
|
public class TestVlookup {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFullColumnAreaRef61841() {
|
public void testFullColumnAreaRef61841() throws IOException {
|
||||||
final Workbook wb = XSSFTestDataSamples.openSampleWorkbook("VLookupFullColumn.xlsx");
|
try (Workbook wb = XSSFTestDataSamples.openSampleWorkbook("VLookupFullColumn.xlsx")) {
|
||||||
FormulaEvaluator feval = wb.getCreationHelper().createFormulaEvaluator();
|
FormulaEvaluator feval = wb.getCreationHelper().createFormulaEvaluator();
|
||||||
feval.evaluateAll();
|
feval.evaluateAll();
|
||||||
assertEquals("Wrong lookup value", "Value1", feval.evaluate(wb.getSheetAt(0).getRow(3).getCell(1)).getStringValue());
|
assertEquals("Wrong lookup value", "Value1",
|
||||||
assertEquals("Lookup should return #N/A", CellType.ERROR, feval.evaluate(wb.getSheetAt(0).getRow(4).getCell(1)).getCellType());
|
feval.evaluate(wb.getSheetAt(0).getRow(3).getCell(1)).getStringValue());
|
||||||
|
assertEquals("Lookup should return #N/A",
|
||||||
|
CellType.ERROR, feval.evaluate(wb.getSheetAt(0).getRow(4).getCell(1)).getCellType());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void bug62275_true() throws IOException {
|
||||||
|
try (Workbook wb = new XSSFWorkbook()) {
|
||||||
|
Sheet sheet = wb.createSheet();
|
||||||
|
Row row = sheet.createRow(0);
|
||||||
|
|
||||||
|
Cell cell = row.createCell(0);
|
||||||
|
cell.setCellFormula("vlookup(A2,B1:B5,2,true)");
|
||||||
|
|
||||||
|
CreationHelper createHelper = wb.getCreationHelper();
|
||||||
|
FormulaEvaluator eval = createHelper.createFormulaEvaluator();
|
||||||
|
CellValue value = eval.evaluate(cell);
|
||||||
|
|
||||||
|
assertFalse(value.getBooleanValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void bug62275_false() throws IOException {
|
||||||
|
try (Workbook wb = new XSSFWorkbook()) {
|
||||||
|
Sheet sheet = wb.createSheet();
|
||||||
|
Row row = sheet.createRow(0);
|
||||||
|
|
||||||
|
Cell cell = row.createCell(0);
|
||||||
|
cell.setCellFormula("vlookup(A2,B1:B5,2,false)");
|
||||||
|
|
||||||
|
CreationHelper crateHelper = wb.getCreationHelper();
|
||||||
|
FormulaEvaluator eval = crateHelper.createFormulaEvaluator();
|
||||||
|
CellValue value = eval.evaluate(cell);
|
||||||
|
|
||||||
|
assertFalse(value.getBooleanValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void bug62275_empty_3args() throws IOException {
|
||||||
|
try (Workbook wb = new XSSFWorkbook()) {
|
||||||
|
Sheet sheet = wb.createSheet();
|
||||||
|
Row row = sheet.createRow(0);
|
||||||
|
|
||||||
|
Cell cell = row.createCell(0);
|
||||||
|
cell.setCellFormula("vlookup(A2,B1:B5,2,)");
|
||||||
|
|
||||||
|
CreationHelper crateHelper = wb.getCreationHelper();
|
||||||
|
FormulaEvaluator eval = crateHelper.createFormulaEvaluator();
|
||||||
|
CellValue value = eval.evaluate(cell);
|
||||||
|
|
||||||
|
assertFalse(value.getBooleanValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void bug62275_empty_2args() throws IOException {
|
||||||
|
try (Workbook wb = new XSSFWorkbook()) {
|
||||||
|
Sheet sheet = wb.createSheet();
|
||||||
|
Row row = sheet.createRow(0);
|
||||||
|
|
||||||
|
Cell cell = row.createCell(0);
|
||||||
|
cell.setCellFormula("vlookup(A2,B1:B5,,)");
|
||||||
|
|
||||||
|
CreationHelper crateHelper = wb.getCreationHelper();
|
||||||
|
FormulaEvaluator eval = crateHelper.createFormulaEvaluator();
|
||||||
|
CellValue value = eval.evaluate(cell);
|
||||||
|
|
||||||
|
assertFalse(value.getBooleanValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void bug62275_empty_1arg() throws IOException {
|
||||||
|
try (Workbook wb = new XSSFWorkbook()) {
|
||||||
|
Sheet sheet = wb.createSheet();
|
||||||
|
Row row = sheet.createRow(0);
|
||||||
|
|
||||||
|
Cell cell = row.createCell(0);
|
||||||
|
cell.setCellFormula("vlookup(A2,,,)");
|
||||||
|
|
||||||
|
CreationHelper crateHelper = wb.getCreationHelper();
|
||||||
|
FormulaEvaluator eval = crateHelper.createFormulaEvaluator();
|
||||||
|
CellValue value = eval.evaluate(cell);
|
||||||
|
|
||||||
|
assertFalse(value.getBooleanValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,6 @@ import org.apache.poi.hssf.HSSFTestDataSamples;
|
||||||
import org.apache.poi.ss.usermodel.BaseTestFormulaEvaluator;
|
import org.apache.poi.ss.usermodel.BaseTestFormulaEvaluator;
|
||||||
import org.apache.poi.ss.usermodel.Cell;
|
import org.apache.poi.ss.usermodel.Cell;
|
||||||
import org.apache.poi.ss.usermodel.CellValue;
|
import org.apache.poi.ss.usermodel.CellValue;
|
||||||
import org.apache.poi.ss.usermodel.CreationHelper;
|
|
||||||
import org.apache.poi.ss.usermodel.FormulaEvaluator;
|
import org.apache.poi.ss.usermodel.FormulaEvaluator;
|
||||||
import org.apache.poi.ss.usermodel.Row;
|
import org.apache.poi.ss.usermodel.Row;
|
||||||
import org.apache.poi.ss.usermodel.Sheet;
|
import org.apache.poi.ss.usermodel.Sheet;
|
||||||
|
@ -253,7 +252,7 @@ public final class TestXSSFFormulaEvaluation extends BaseTestFormulaEvaluator {
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
@Ignore
|
@Ignore
|
||||||
public void testCachedReferencesToOtherWorkbooks() throws Exception {
|
public void testCachedReferencesToOtherWorkbooks() {
|
||||||
// TODO
|
// TODO
|
||||||
fail("unit test not written yet");
|
fail("unit test not written yet");
|
||||||
}
|
}
|
||||||
|
@ -388,7 +387,7 @@ public final class TestXSSFFormulaEvaluation extends BaseTestFormulaEvaluator {
|
||||||
verifyAllFormulasInWorkbookCanBeEvaluated("StructuredRefs-lots-with-lookups.xlsx");
|
verifyAllFormulasInWorkbookCanBeEvaluated("StructuredRefs-lots-with-lookups.xlsx");
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: use junit4 parameterization
|
// FIXME: use junit4 parametrization
|
||||||
private static void verifyAllFormulasInWorkbookCanBeEvaluated(String sampleWorkbook) throws IOException {
|
private static void verifyAllFormulasInWorkbookCanBeEvaluated(String sampleWorkbook) throws IOException {
|
||||||
XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook(sampleWorkbook);
|
XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook(sampleWorkbook);
|
||||||
XSSFFormulaEvaluator.evaluateAllFormulaCells(wb);
|
XSSFFormulaEvaluator.evaluateAllFormulaCells(wb);
|
||||||
|
@ -442,33 +441,16 @@ public final class TestXSSFFormulaEvaluation extends BaseTestFormulaEvaluator {
|
||||||
// assertEquals("D 67.10", cell.getStringCellValue());
|
// assertEquals("D 67.10", cell.getStringCellValue());
|
||||||
|
|
||||||
CellValue value = evaluator.evaluate(cell);
|
CellValue value = evaluator.evaluate(cell);
|
||||||
assertEquals("D 67.10", value.getStringValue());
|
assertEquals("D 67.10",
|
||||||
|
value.getStringValue());
|
||||||
|
|
||||||
assertEquals("D 0,068", evaluator.evaluate(wb.getSheetAt(0).getRow(1).getCell(1)));
|
assertEquals("D 0,068",
|
||||||
|
evaluator.evaluate(wb.getSheetAt(0).getRow(1).getCell(1)).getStringValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* see bug 62275
|
|
||||||
* @throws IOException
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void testBug62275() throws IOException {
|
|
||||||
try (Workbook wb = new XSSFWorkbook()) {
|
|
||||||
Sheet sheet = wb.createSheet();
|
|
||||||
Row row = sheet.createRow(0);
|
|
||||||
|
|
||||||
Cell cell = row.createCell(0);
|
|
||||||
cell.setCellFormula("vlookup(A2,B1:B5,2,true)");
|
|
||||||
|
|
||||||
CreationHelper createHelper = wb.getCreationHelper();
|
|
||||||
FormulaEvaluator eval = createHelper.createFormulaEvaluator();
|
|
||||||
eval.evaluate(cell);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* see bug 62834, handle when a shared formula range doesn't contain only formula cells
|
* see bug 62834, handle when a shared formula range doesn't contain only formula cells
|
||||||
* @throws IOException
|
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testBug62834() throws IOException {
|
public void testBug62834() throws IOException {
|
||||||
|
|
Loading…
Reference in New Issue