From: Yegor Kozlov Date: Mon, 16 Apr 2007 10:49:47 +0000 (+0000) Subject: testcases for bugs 38266 and 40738 X-Git-Tag: REL_3_0_RC4~13 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=bc57bba7d991f931efc2df01e7b5f76b21b17730;p=poi.git testcases for bugs 38266 and 40738 git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@529197 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/testcases/org/apache/poi/hssf/data/SimpleWithAutofilter.xls b/src/testcases/org/apache/poi/hssf/data/SimpleWithAutofilter.xls new file mode 100644 index 0000000000..900699c6e0 Binary files /dev/null and b/src/testcases/org/apache/poi/hssf/data/SimpleWithAutofilter.xls differ diff --git a/src/testcases/org/apache/poi/hssf/data/SimpleWithImages.xls b/src/testcases/org/apache/poi/hssf/data/SimpleWithImages.xls new file mode 100644 index 0000000000..aa47dfa9c6 Binary files /dev/null and b/src/testcases/org/apache/poi/hssf/data/SimpleWithImages.xls differ diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java b/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java index 0483871691..75ec3fee60 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java @@ -868,8 +868,52 @@ extends TestCase { assertTrue("No Exceptions while reading file", true); } - + /** + * Test bug 38266: NPE when adding a row break + * + * User's diagnosis: + * 1. Manually (i.e., not using POI) create an Excel Workbook, making sure it + * contains a sheet that doesn't have any row breaks + * 2. Using POI, create a new HSSFWorkbook from the template in step #1 + * 3. Try adding a row break (via sheet.setRowBreak()) to the sheet mentioned in step #1 + * 4. Get a NullPointerException + */ + public void test38266() throws Exception { + String[] files = {"Simple.xls", "SimpleMultiCell.xls", "duprich1.xls"}; + for (int i = 0; i < files.length; i++) { + FileInputStream in = new FileInputStream(new File(cwd, files[i])); + HSSFWorkbook wb = new HSSFWorkbook(in); + in.close(); + + HSSFSheet sheet = wb.getSheetAt( 0 ); + int[] breaks = sheet.getRowBreaks(); + assertNull(breaks); + + //add 3 row breaks + for (int j = 1; j <= 3; j++) { + sheet.setRowBreak(j*20); + } + + assertTrue("No Exceptions while adding row breaks in " + files[i], true); + } + } + + public void test40738() throws Exception { + FileInputStream in = new FileInputStream(new File(cwd, "SimpleWithAutofilter.xls")); + HSSFWorkbook wb = new HSSFWorkbook(in); + in.close(); + + //serialize and read again + ByteArrayOutputStream out = new ByteArrayOutputStream(); + wb.write(out); + out.close(); + wb = new HSSFWorkbook(new ByteArrayInputStream(out.toByteArray())); + assertTrue("No Exceptions while reading file", true); + + } + + }