Enable more of the POIFS DocumetnInputStream tests to check NPOIFS as well
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1131988 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
e9249b28c2
commit
f93b671b69
@ -191,11 +191,15 @@ public final class TestDocumentInputStream extends TestCase {
|
||||
* test simple read method
|
||||
*/
|
||||
public void testReadSingleByte() throws IOException {
|
||||
DocumentInputStream stream = new DocumentInputStream(_workbook_o);
|
||||
DocumentInputStream[] streams = new DocumentInputStream[] {
|
||||
new DocumentInputStream(_workbook_o),
|
||||
new NDocumentInputStream(_workbook_n)
|
||||
};
|
||||
for(DocumentInputStream stream : streams) {
|
||||
int remaining = _workbook_size;
|
||||
|
||||
for (int j = 0; j < _workbook_size; j++)
|
||||
{
|
||||
// Try and read each byte in turn
|
||||
for (int j = 0; j < _workbook_size; j++) {
|
||||
int b = stream.read();
|
||||
assertTrue("checking sign of " + j, b >= 0);
|
||||
assertEquals("validating byte " + j, _workbook_data[ j ],
|
||||
@ -204,34 +208,35 @@ public final class TestDocumentInputStream extends TestCase {
|
||||
assertEquals("checking remaining after reading byte " + j,
|
||||
remaining, stream.available());
|
||||
}
|
||||
|
||||
// Ensure we fell off the end
|
||||
assertEquals(-1, stream.read());
|
||||
|
||||
// Check that after close we can no longer read
|
||||
stream.close();
|
||||
try
|
||||
{
|
||||
try {
|
||||
stream.read();
|
||||
fail("Should have caught IOException");
|
||||
}
|
||||
catch (IOException ignored)
|
||||
{
|
||||
|
||||
} catch (IOException ignored) {
|
||||
// as expected
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test buffered read
|
||||
*/
|
||||
public void testBufferRead() throws IOException {
|
||||
DocumentInputStream stream = new DocumentInputStream(_workbook_o);
|
||||
|
||||
try
|
||||
{
|
||||
DocumentInputStream[] streams = new DocumentInputStream[] {
|
||||
new DocumentInputStream(_workbook_o),
|
||||
new NDocumentInputStream(_workbook_n)
|
||||
};
|
||||
for(DocumentInputStream stream : streams) {
|
||||
// Need to give a byte array to read
|
||||
try {
|
||||
stream.read(null);
|
||||
fail("Should have caught NullPointerException");
|
||||
}
|
||||
catch (NullPointerException ignored)
|
||||
{
|
||||
|
||||
} catch (NullPointerException ignored) {
|
||||
// as expected
|
||||
}
|
||||
|
||||
@ -271,24 +276,24 @@ public final class TestDocumentInputStream extends TestCase {
|
||||
}
|
||||
assertEquals(-1, stream.read(buffer));
|
||||
stream.close();
|
||||
try
|
||||
{
|
||||
try {
|
||||
stream.read(buffer);
|
||||
fail("Should have caught IOException");
|
||||
}
|
||||
catch (IOException ignored)
|
||||
{
|
||||
|
||||
} catch (IOException ignored) {
|
||||
// as expected
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test complex buffered read
|
||||
*/
|
||||
public void testComplexBufferRead() throws IOException {
|
||||
DocumentInputStream stream = new DocumentInputStream(_workbook_o);
|
||||
|
||||
DocumentInputStream[] streams = new DocumentInputStream[] {
|
||||
new DocumentInputStream(_workbook_o),
|
||||
new NDocumentInputStream(_workbook_n)
|
||||
};
|
||||
for(DocumentInputStream stream : streams) {
|
||||
try {
|
||||
stream.read(null, 0, 1);
|
||||
fail("Should have caught NullPointerException");
|
||||
@ -297,34 +302,22 @@ public final class TestDocumentInputStream extends TestCase {
|
||||
}
|
||||
|
||||
// test illegal offsets and lengths
|
||||
try
|
||||
{
|
||||
try {
|
||||
stream.read(new byte[ 5 ], -4, 0);
|
||||
fail("Should have caught IndexOutOfBoundsException");
|
||||
}
|
||||
catch (IndexOutOfBoundsException ignored)
|
||||
{
|
||||
|
||||
} catch (IndexOutOfBoundsException ignored) {
|
||||
// as expected
|
||||
}
|
||||
try
|
||||
{
|
||||
try {
|
||||
stream.read(new byte[ 5 ], 0, -4);
|
||||
fail("Should have caught IndexOutOfBoundsException");
|
||||
}
|
||||
catch (IndexOutOfBoundsException ignored)
|
||||
{
|
||||
|
||||
} catch (IndexOutOfBoundsException ignored) {
|
||||
// as expected
|
||||
}
|
||||
try
|
||||
{
|
||||
try {
|
||||
stream.read(new byte[ 5 ], 0, 6);
|
||||
fail("Should have caught IndexOutOfBoundsException");
|
||||
}
|
||||
catch (IndexOutOfBoundsException ignored)
|
||||
{
|
||||
|
||||
} catch (IndexOutOfBoundsException ignored) {
|
||||
// as expected
|
||||
}
|
||||
|
||||
@ -376,31 +369,31 @@ public final class TestDocumentInputStream extends TestCase {
|
||||
{
|
||||
assertEquals("byte " + j, 0, buffer[ j ]);
|
||||
}
|
||||
|
||||
assertEquals(-1, stream.read(buffer, 0, 1));
|
||||
stream.close();
|
||||
try
|
||||
{
|
||||
try {
|
||||
stream.read(buffer, 0, 1);
|
||||
fail("Should have caught IOException");
|
||||
}
|
||||
catch (IOException ignored)
|
||||
{
|
||||
|
||||
} catch (IOException ignored) {
|
||||
// as expected
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that we can skip within the stream
|
||||
*/
|
||||
public void testSkip() throws IOException {
|
||||
DocumentInputStream stream = new DocumentInputStream(_workbook_o);
|
||||
|
||||
DocumentInputStream[] streams = new DocumentInputStream[] {
|
||||
new DocumentInputStream(_workbook_o),
|
||||
new NDocumentInputStream(_workbook_n)
|
||||
};
|
||||
for(DocumentInputStream stream : streams) {
|
||||
assertEquals(_workbook_size, stream.available());
|
||||
int count = stream.available();
|
||||
|
||||
while (stream.available() >= _buffer_size)
|
||||
{
|
||||
while (stream.available() >= _buffer_size) {
|
||||
assertEquals(_buffer_size, stream.skip(_buffer_size));
|
||||
count -= _buffer_size;
|
||||
assertEquals(count, stream.available());
|
||||
@ -418,6 +411,7 @@ public final class TestDocumentInputStream extends TestCase {
|
||||
stream.skip(2 + ( long ) Integer.MAX_VALUE));
|
||||
assertEquals(0, stream.available());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that we can read files at multiple levels down the tree
|
||||
|
Loading…
Reference in New Issue
Block a user