diff options
author | Dominik Stadler <centic@apache.org> | 2015-04-03 15:55:21 +0000 |
---|---|---|
committer | Dominik Stadler <centic@apache.org> | 2015-04-03 15:55:21 +0000 |
commit | 690abbe5547df702ce83cf2fe63a3bc4c00f1df6 (patch) | |
tree | 64cfa6d626bea40dbc7f9b39be6d25e0f86ba501 /src/testcases | |
parent | 563cab96816fb36879b2f3df4fe2e0ce17457e58 (diff) | |
download | poi-690abbe5547df702ce83cf2fe63a3bc4c00f1df6.tar.gz poi-690abbe5547df702ce83cf2fe63a3bc4c00f1df6.zip |
Bug 56579: Throw exception if max string length of 32767 chars is exceeded in XSSF and SXSSF.
Add verification testcase for bug 57008.
Move some unit tests to the Bsae-Test-Class to verify things for all SS-implementations.
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1671096 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/testcases')
-rw-r--r-- | src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java | 33 | ||||
-rw-r--r-- | src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java | 72 |
2 files changed, 72 insertions, 33 deletions
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java index 066c12e7f1..7c78fb0674 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java @@ -30,7 +30,6 @@ import org.apache.poi.hssf.record.DBCellRecord; import org.apache.poi.hssf.record.FormulaRecord; import org.apache.poi.hssf.record.Record; import org.apache.poi.hssf.record.StringRecord; -import org.apache.poi.ss.SpreadsheetVersion; import org.apache.poi.ss.usermodel.BaseTestCell; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.FormulaError; @@ -355,38 +354,6 @@ public final class TestHSSFCell extends BaseTestCell { assertEquals(DBCellRecord.class, dbcr.getClass()); } - /** - * The maximum length of cell contents (text) is 32,767 characters. - * @throws IOException - */ - public void testMaxTextLength() throws IOException{ - HSSFWorkbook wb = new HSSFWorkbook(); - HSSFSheet sheet = wb.createSheet(); - HSSFCell cell = sheet.createRow(0).createCell(0); - - int maxlen = SpreadsheetVersion.EXCEL97.getMaxTextLength(); - assertEquals(32767, maxlen); - - StringBuffer b = new StringBuffer() ; - - // 32767 is okay - for( int i = 0 ; i < maxlen ; i++ ) - { - b.append( "X" ) ; - } - cell.setCellValue(b.toString()); - - b.append("X"); - // 32768 produces an invalid XLS file - try { - cell.setCellValue(b.toString()); - fail("Expected exception"); - } catch (IllegalArgumentException e){ - assertEquals("The maximum length of cell contents (text) is 32,767 characters", e.getMessage()); - } - wb.close(); - } - /** * HSSF prior to version 3.7 had a bug: it could write a NaN but could not read such a file back. */ diff --git a/src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java b/src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java index 35e95ab049..533a973974 100644 --- a/src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java +++ b/src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java @@ -25,6 +25,7 @@ import junit.framework.TestCase; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.ss.ITestDataProvider; +import org.apache.poi.ss.SpreadsheetVersion; /** * Common superclass for testing implementations of @@ -695,4 +696,75 @@ public abstract class BaseTestCell extends TestCase { wb.close(); } + + public void test57008() throws IOException { + Workbook wb = _testDataProvider.createWorkbook(); + Sheet sheet = wb.createSheet(); + + Row row0 = sheet.createRow(0); + Cell cell0 = row0.createCell(0); + cell0.setCellValue("row 0, cell 0 _x0046_ without changes"); + + Cell cell1 = row0.createCell(1); + cell1.setCellValue("row 0, cell 1 _x005fx0046_ with changes"); + + Cell cell2 = row0.createCell(2); + cell2.setCellValue("hgh_x0041_**_x0100_*_x0101_*_x0190_*_x0200_*_x0300_*_x0427_*"); + + checkUnicodeValues(wb); + +// String fname = "/tmp/Test_xNNNN_inCell" + (wb instanceof HSSFWorkbook ? ".xls" : ".xlsx"); +// FileOutputStream out = new FileOutputStream(fname); +// try { +// wb.write(out); +// } finally { +// out.close(); +// } + + Workbook wbBack = _testDataProvider.writeOutAndReadBack(wb); + checkUnicodeValues(wbBack); + } + + private void checkUnicodeValues(Workbook wb) { + assertEquals((wb instanceof HSSFWorkbook ? "row 0, cell 0 _x0046_ without changes" : "row 0, cell 0 F without changes"), + wb.getSheetAt(0).getRow(0).getCell(0).toString()); + assertEquals((wb instanceof HSSFWorkbook ? "row 0, cell 1 _x005fx0046_ with changes" : "row 0, cell 1 _x005fx0046_ with changes"), + wb.getSheetAt(0).getRow(0).getCell(1).toString()); + assertEquals((wb instanceof HSSFWorkbook ? "hgh_x0041_**_x0100_*_x0101_*_x0190_*_x0200_*_x0300_*_x0427_*" : "hghA**\u0100*\u0101*\u0190*\u0200*\u0300*\u0427*"), + wb.getSheetAt(0).getRow(0).getCell(2).toString()); + } + + /** + * The maximum length of cell contents (text) is 32,767 characters. + * @throws IOException + */ + public void testMaxTextLength() throws IOException{ + Workbook wb = _testDataProvider.createWorkbook(); + Sheet sheet = wb.createSheet(); + Cell cell = sheet.createRow(0).createCell(0); + + int maxlen = wb instanceof HSSFWorkbook ? + SpreadsheetVersion.EXCEL97.getMaxTextLength() + : SpreadsheetVersion.EXCEL2007.getMaxTextLength(); + assertEquals(32767, maxlen); + + StringBuffer b = new StringBuffer() ; + + // 32767 is okay + for( int i = 0 ; i < maxlen ; i++ ) + { + b.append( "X" ) ; + } + cell.setCellValue(b.toString()); + + b.append("X"); + // 32768 produces an invalid XLS file + try { + cell.setCellValue(b.toString()); + fail("Expected exception"); + } catch (IllegalArgumentException e){ + assertEquals("The maximum length of cell contents (text) is 32,767 characters", e.getMessage()); + } + wb.close(); + } } |