Move non-HSSF specific bug tests into BaseTestBugzillaIssues from HSSF TestBugs, so they can be tested automatically on XSSF too

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1632837 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Nick Burch 2014-10-18 20:10:31 +00:00
parent 508f36d702
commit 14fb9a55ee
2 changed files with 127 additions and 118 deletions

View File

@ -65,7 +65,6 @@ import org.apache.poi.ss.formula.ptg.Ptg;
import org.apache.poi.ss.usermodel.BaseTestBugzillaIssues;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.DataFormat;
import org.apache.poi.ss.usermodel.DataFormatter;
import org.apache.poi.ss.usermodel.FormulaEvaluator;
import org.apache.poi.ss.usermodel.Name;
@ -143,21 +142,6 @@ public final class TestBugs extends BaseTestBugzillaIssues {
writeOutAndReadBack(wb);
}
/** test hyperlinks
* open resulting file in excel, and check that there is a link to Google
*/
@Test
public void bug15353() {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("My sheet");
HSSFRow row = sheet.createRow( 0 );
HSSFCell cell = row.createCell( 0 );
cell.setCellFormula("HYPERLINK(\"http://google.com\",\"Google\")");
writeOutAndReadBack(wb);
}
/** test reading of a formula with a name and a cell ref in one
**/
@Test
@ -2219,44 +2203,6 @@ public final class TestBugs extends BaseTestBugzillaIssues {
assertEquals(54.0+24.0-60, s.getRow(7).getCell(0).getNumericCellValue(), 0);
}
/**
* HLookup and VLookup with optional arguments
*/
@Test
public void bug51024() throws Exception {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet s = wb.createSheet();
HSSFRow r1 = s.createRow(0);
HSSFRow r2 = s.createRow(1);
r1.createCell(0).setCellValue("v A1");
r2.createCell(0).setCellValue("v A2");
r1.createCell(1).setCellValue("v B1");
HSSFCell c = r1.createCell(4);
HSSFFormulaEvaluator eval = new HSSFFormulaEvaluator(wb);
c.setCellFormula("VLOOKUP(\"v A1\", A1:B2, 1)");
assertEquals("v A1", eval.evaluate(c).getStringValue());
c.setCellFormula("VLOOKUP(\"v A1\", A1:B2, 1, 1)");
assertEquals("v A1", eval.evaluate(c).getStringValue());
c.setCellFormula("VLOOKUP(\"v A1\", A1:B2, 1, )");
assertEquals("v A1", eval.evaluate(c).getStringValue());
c.setCellFormula("HLOOKUP(\"v A1\", A1:B2, 1)");
assertEquals("v A1", eval.evaluate(c).getStringValue());
c.setCellFormula("HLOOKUP(\"v A1\", A1:B2, 1, 1)");
assertEquals("v A1", eval.evaluate(c).getStringValue());
c.setCellFormula("HLOOKUP(\"v A1\", A1:B2, 1, )");
assertEquals("v A1", eval.evaluate(c).getStringValue());
}
/**
* Mixture of Ascii and Unicode strings in a
* NameComment record
@ -2516,70 +2462,6 @@ public final class TestBugs extends BaseTestBugzillaIssues {
}
}
@Test
public void stackoverflow23114397() throws Exception {
Workbook wb = new HSSFWorkbook();
DataFormat format = wb.getCreationHelper().createDataFormat();
// How close the sizing should be, given that not all
// systems will have quite the same fonts on them
float fontAccuracy = 0.22f;
// x%
CellStyle iPercent = wb.createCellStyle();
iPercent.setDataFormat(format.getFormat("0%"));
// x.x%
CellStyle d1Percent = wb.createCellStyle();
d1Percent.setDataFormat(format.getFormat("0.0%"));
// x.xx%
CellStyle d2Percent = wb.createCellStyle();
d2Percent.setDataFormat(format.getFormat("0.00%"));
Sheet s = wb.createSheet();
Row r1 = s.createRow(0);
for (int i=0; i<3; i++) {
r1.createCell(i, Cell.CELL_TYPE_NUMERIC).setCellValue(0);
}
for (int i=3; i<6; i++) {
r1.createCell(i, Cell.CELL_TYPE_NUMERIC).setCellValue(1);
}
for (int i=6; i<9; i++) {
r1.createCell(i, Cell.CELL_TYPE_NUMERIC).setCellValue(0.12345);
}
for (int i=9; i<12; i++) {
r1.createCell(i, Cell.CELL_TYPE_NUMERIC).setCellValue(1.2345);
}
for (int i=0; i<12; i+=3) {
r1.getCell(i+0).setCellStyle(iPercent);
r1.getCell(i+1).setCellStyle(d1Percent);
r1.getCell(i+2).setCellStyle(d2Percent);
}
for (int i=0; i<12; i++) {
s.autoSizeColumn(i);
}
// Check the 0(.00)% ones
assertAlmostEquals(980, s.getColumnWidth(0), fontAccuracy);
assertAlmostEquals(1400, s.getColumnWidth(1), fontAccuracy);
assertAlmostEquals(1700, s.getColumnWidth(2), fontAccuracy);
// Check the 100(.00)% ones
assertAlmostEquals(1500, s.getColumnWidth(3), fontAccuracy);
assertAlmostEquals(1950, s.getColumnWidth(4), fontAccuracy);
assertAlmostEquals(2225, s.getColumnWidth(5), fontAccuracy);
// Check the 12(.34)% ones
assertAlmostEquals(1225, s.getColumnWidth(6), fontAccuracy);
assertAlmostEquals(1650, s.getColumnWidth(7), fontAccuracy);
assertAlmostEquals(1950, s.getColumnWidth(8), fontAccuracy);
// Check the 123(.45)% ones
assertAlmostEquals(1500, s.getColumnWidth(9), fontAccuracy);
assertAlmostEquals(1950, s.getColumnWidth(10), fontAccuracy);
assertAlmostEquals(2225, s.getColumnWidth(11), fontAccuracy);
}
@Test
public void bug56450() {
HSSFWorkbook wb = openSample("56450.xls");

View File

@ -400,4 +400,131 @@ public abstract class BaseTestBugzillaIssues {
assertEquals(0, paneInfo.getHorizontalSplitTopRow());
}
/**
* Test hyperlinks
* open resulting file in excel, and check that there is a link to Google
*/
@Test
public void bug15353() {
String hyperlinkF = "HYPERLINK(\"http://google.com\",\"Google\")";
Workbook wb = _testDataProvider.createWorkbook();
Sheet sheet = wb.createSheet("My sheet");
Row row = sheet.createRow( 0 );
Cell cell = row.createCell( 0 );
cell.setCellFormula(hyperlinkF);
assertEquals(hyperlinkF, cell.getCellFormula());
wb = _testDataProvider.writeOutAndReadBack(wb);
sheet = wb.getSheet("My Sheet");
row = sheet.getRow( 0 );
cell = row.getCell( 0 );
assertEquals(hyperlinkF, cell.getCellFormula());
}
/**
* HLookup and VLookup with optional arguments
*/
@Test
public void bug51024() throws Exception {
Workbook wb = _testDataProvider.createWorkbook();
Sheet s = wb.createSheet();
Row r1 = s.createRow(0);
Row r2 = s.createRow(1);
r1.createCell(0).setCellValue("v A1");
r2.createCell(0).setCellValue("v A2");
r1.createCell(1).setCellValue("v B1");
Cell c = r1.createCell(4);
FormulaEvaluator eval = wb.getCreationHelper().createFormulaEvaluator();
c.setCellFormula("VLOOKUP(\"v A1\", A1:B2, 1)");
assertEquals("v A1", eval.evaluate(c).getStringValue());
c.setCellFormula("VLOOKUP(\"v A1\", A1:B2, 1, 1)");
assertEquals("v A1", eval.evaluate(c).getStringValue());
c.setCellFormula("VLOOKUP(\"v A1\", A1:B2, 1, )");
assertEquals("v A1", eval.evaluate(c).getStringValue());
c.setCellFormula("HLOOKUP(\"v A1\", A1:B2, 1)");
assertEquals("v A1", eval.evaluate(c).getStringValue());
c.setCellFormula("HLOOKUP(\"v A1\", A1:B2, 1, 1)");
assertEquals("v A1", eval.evaluate(c).getStringValue());
c.setCellFormula("HLOOKUP(\"v A1\", A1:B2, 1, )");
assertEquals("v A1", eval.evaluate(c).getStringValue());
}
@Test
public void stackoverflow23114397() throws Exception {
Workbook wb = _testDataProvider.createWorkbook();
DataFormat format = wb.getCreationHelper().createDataFormat();
// How close the sizing should be, given that not all
// systems will have quite the same fonts on them
float fontAccuracy = 0.22f;
// x%
CellStyle iPercent = wb.createCellStyle();
iPercent.setDataFormat(format.getFormat("0%"));
// x.x%
CellStyle d1Percent = wb.createCellStyle();
d1Percent.setDataFormat(format.getFormat("0.0%"));
// x.xx%
CellStyle d2Percent = wb.createCellStyle();
d2Percent.setDataFormat(format.getFormat("0.00%"));
Sheet s = wb.createSheet();
Row r1 = s.createRow(0);
for (int i=0; i<3; i++) {
r1.createCell(i, Cell.CELL_TYPE_NUMERIC).setCellValue(0);
}
for (int i=3; i<6; i++) {
r1.createCell(i, Cell.CELL_TYPE_NUMERIC).setCellValue(1);
}
for (int i=6; i<9; i++) {
r1.createCell(i, Cell.CELL_TYPE_NUMERIC).setCellValue(0.12345);
}
for (int i=9; i<12; i++) {
r1.createCell(i, Cell.CELL_TYPE_NUMERIC).setCellValue(1.2345);
}
for (int i=0; i<12; i+=3) {
r1.getCell(i+0).setCellStyle(iPercent);
r1.getCell(i+1).setCellStyle(d1Percent);
r1.getCell(i+2).setCellStyle(d2Percent);
}
for (int i=0; i<12; i++) {
s.autoSizeColumn(i);
}
// Check the 0(.00)% ones
assertAlmostEquals(980, s.getColumnWidth(0), fontAccuracy);
assertAlmostEquals(1400, s.getColumnWidth(1), fontAccuracy);
assertAlmostEquals(1700, s.getColumnWidth(2), fontAccuracy);
// Check the 100(.00)% ones
assertAlmostEquals(1500, s.getColumnWidth(3), fontAccuracy);
assertAlmostEquals(1950, s.getColumnWidth(4), fontAccuracy);
assertAlmostEquals(2225, s.getColumnWidth(5), fontAccuracy);
// Check the 12(.34)% ones
assertAlmostEquals(1225, s.getColumnWidth(6), fontAccuracy);
assertAlmostEquals(1650, s.getColumnWidth(7), fontAccuracy);
assertAlmostEquals(1950, s.getColumnWidth(8), fontAccuracy);
// Check the 123(.45)% ones
assertAlmostEquals(1500, s.getColumnWidth(9), fontAccuracy);
assertAlmostEquals(1950, s.getColumnWidth(10), fontAccuracy);
assertAlmostEquals(2225, s.getColumnWidth(11), fontAccuracy);
}
}