ASF Bugzilla – Attachment 16573 Details for
Bug 31310
Error reading header signature
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
Invalid Header Test Case
TestHeader.java (text/plain), 1.77 KB, created by
Shawn Clowater
on 2005-10-03 19:33:04 UTC
(
hide
)
Description:
Invalid Header Test Case
Filename:
MIME Type:
Creator:
Shawn Clowater
Created:
2005-10-03 19:33:04 UTC
Size:
1.77 KB
patch
obsolete
>import junit.framework.TestCase; >import org.apache.poi.hssf.usermodel.HSSFWorkbook; >import org.apache.poi.poifs.filesystem.POIFSFileSystem; > >import java.io.*; > >public class TestHeader extends TestCase { > private File file; > private HSSFWorkbook workbook; > private ByteArrayOutputStream byteArrayOutputStream; > > public void setUp() throws Exception { > workbook = new HSSFWorkbook(); > workbook.createSheet("This is only a simple test"); > byteArrayOutputStream = new ByteArrayOutputStream(); > workbook.write(byteArrayOutputStream); > byteArrayOutputStream.close(); > > //this is only included so that if you put a break point on the test you can see that the file is created and opens file in excel > file = new File("headerTest.xls"); > FileOutputStream fileOutputStream = new FileOutputStream(file); > workbook.write(fileOutputStream); > fileOutputStream.close(); > } > > public void tearDown() throws Exception { > file.deleteOnExit(); > } > > public void testHeaderFails() throws Exception { > //this should fail with the invalid sig error > try { > new HSSFWorkbook(new POIFSFileSystem(new ByteArrayInputStream(workbook.getBytes()))); > fail("Expected exception not thrown"); > } catch (IOException io) { > //this is expected > io.printStackTrace(); > } > } > > public void testHeaderPasses() throws Exception { > //this should pass > HSSFWorkbook workbook = new HSSFWorkbook(new POIFSFileSystem(new ByteArrayInputStream(byteArrayOutputStream.toByteArray()))); > assertTrue(workbook.getNumberOfSheets() == 1); > assertEquals(workbook.getSheetName(0), "This is only a simple test"); > } >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 31310
:
12803
| 16573