diff options
author | Nick Burch <nick@apache.org> | 2014-11-30 17:09:03 +0000 |
---|---|---|
committer | Nick Burch <nick@apache.org> | 2014-11-30 17:09:03 +0000 |
commit | 42bb3f2194c23bffd60f7598d8055065e7c5754e (patch) | |
tree | a05c22b1025abde8503211bc522df99201eea241 /src/testcases/org/apache | |
parent | 25f72b69786bac3838dffeaca94be3327cbe6652 (diff) | |
download | poi-42bb3f2194c23bffd60f7598d8055065e7c5754e.tar.gz poi-42bb3f2194c23bffd60f7598d8055065e7c5754e.zip |
Correct older biff detection, and add unit tests for HSSFWorkbook giving helpful exceptions on the older formats
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1642568 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/testcases/org/apache')
-rw-r--r-- | src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java index a37751dec3..2fabba9def 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java @@ -23,6 +23,7 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +import static org.apache.poi.POITestCase.assertContains; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -40,6 +41,7 @@ import org.apache.poi.ddf.EscherBSERecord; import org.apache.poi.hpsf.ClassID; import org.apache.poi.hssf.HSSFITestDataProvider; import org.apache.poi.hssf.HSSFTestDataSamples; +import org.apache.poi.hssf.OldExcelFormatException; import org.apache.poi.hssf.model.HSSFFormulaParser; import org.apache.poi.hssf.model.InternalSheet; import org.apache.poi.hssf.model.InternalWorkbook; @@ -561,6 +563,40 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook { assertTrue(clsid1.equals(clsid2)); } + + /** + * If we try to open an old (pre-97) workbook, we get a helpful + * Exception give to explain what we've done wrong + */ + @Test + public void helpfulExceptionOnOldFiles() throws Exception { + InputStream excel4 = POIDataSamples.getSpreadSheetInstance().openResourceAsStream("testEXCEL_4.xls"); + try { + new HSSFWorkbook(excel4); + fail("Shouldn't be able to load an Excel 4 file"); + } catch (OldExcelFormatException e) { + assertContains(e.getMessage(), "BIFF4"); + } + excel4.close(); + + InputStream excel5 = POIDataSamples.getSpreadSheetInstance().openResourceAsStream("testEXCEL_5.xls"); + try { + new HSSFWorkbook(excel5); + fail("Shouldn't be able to load an Excel 5 file"); + } catch (OldExcelFormatException e) { + assertContains(e.getMessage(), "BIFF5"); + } + excel5.close(); + + InputStream excel95 = POIDataSamples.getSpreadSheetInstance().openResourceAsStream("testEXCEL_95.xls"); + try { + new HSSFWorkbook(excel95); + fail("Shouldn't be able to load an Excel 95 file"); + } catch (OldExcelFormatException e) { + assertContains(e.getMessage(), "BIFF5"); + } + excel95.close(); + } /** * Tests that we can work with both {@link POIFSFileSystem} |