aboutsummaryrefslogtreecommitdiffstats
path: root/src/testcases/org/apache
diff options
context:
space:
mode:
Diffstat (limited to 'src/testcases/org/apache')
-rw-r--r--src/testcases/org/apache/poi/poifs/filesystem/TestOffice2007XMLException.java47
1 files changed, 43 insertions, 4 deletions
diff --git a/src/testcases/org/apache/poi/poifs/filesystem/TestOffice2007XMLException.java b/src/testcases/org/apache/poi/poifs/filesystem/TestOffice2007XMLException.java
index d475b7aad0..d5d92bd6bb 100644
--- a/src/testcases/org/apache/poi/poifs/filesystem/TestOffice2007XMLException.java
+++ b/src/testcases/org/apache/poi/poifs/filesystem/TestOffice2007XMLException.java
@@ -17,12 +17,16 @@
package org.apache.poi.poifs.filesystem;
-import junit.framework.TestCase;
-
-import java.io.*;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.PushbackInputStream;
+import java.util.Arrays;
import org.apache.poi.hssf.HSSFTestDataSamples;
+import junit.framework.TestCase;
+
/**
* Class to test that POIFS complains when given an Office 2007 XML document
*
@@ -38,7 +42,7 @@ public class TestOffice2007XMLException extends TestCase {
InputStream in = openSampleStream("sample.xlsx");
try {
- new POIFSFileSystem(in);
+ new POIFSFileSystem(in).close();
fail("expected exception was not thrown");
} catch(OfficeXmlFileException e) {
// expected during successful test
@@ -72,4 +76,39 @@ public class TestOffice2007XMLException extends TestCase {
in.close();
}
}
+
+ public void testFileCorruption() throws Exception {
+
+ // create test InputStream
+ byte[] testData = { (byte)1, (byte)2, (byte)3 };
+ InputStream testInput = new ByteArrayInputStream(testData);
+
+ // detect header
+ InputStream in = new PushbackInputStream(testInput, 10);
+ assertFalse(POIFSFileSystem.hasPOIFSHeader(in));
+
+ // check if InputStream is still intact
+ byte[] test = new byte[3];
+ in.read(test);
+ assertTrue(Arrays.equals(testData, test));
+ assertEquals(-1, in.read());
+ }
+
+
+ public void testFileCorruptionOPOIFS() throws Exception {
+
+ // create test InputStream
+ byte[] testData = { (byte)1, (byte)2, (byte)3 };
+ InputStream testInput = new ByteArrayInputStream(testData);
+
+ // detect header
+ InputStream in = new PushbackInputStream(testInput, 10);
+ assertFalse(OPOIFSFileSystem.hasPOIFSHeader(in));
+
+ // check if InputStream is still intact
+ byte[] test = new byte[3];
+ in.read(test);
+ assertTrue(Arrays.equals(testData, test));
+ assertEquals(-1, in.read());
+ }
}