aboutsummaryrefslogtreecommitdiffstats
path: root/src/testcases/org/apache/poi/util
diff options
context:
space:
mode:
authorJosh Micich <josh@apache.org>2009-11-15 00:27:59 +0000
committerJosh Micich <josh@apache.org>2009-11-15 00:27:59 +0000
commitd26eb6a54d4108397732e4ca68073c8af623509b (patch)
tree9a6099ec426a0d571f3189497fe3ad73624dca9a /src/testcases/org/apache/poi/util
parentb31ca01a5c53aa129984d0982a6b85a8bea3b0ae (diff)
downloadpoi-d26eb6a54d4108397732e4ca68073c8af623509b.tar.gz
poi-d26eb6a54d4108397732e4ca68073c8af623509b.zip
fixed bug in LittleEndianByteArrayInputStream.readFully()
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@836298 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/testcases/org/apache/poi/util')
-rw-r--r--src/testcases/org/apache/poi/util/TestLittleEndianStreams.java27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/testcases/org/apache/poi/util/TestLittleEndianStreams.java b/src/testcases/org/apache/poi/util/TestLittleEndianStreams.java
index f2661b7273..26f9b4cf6b 100644
--- a/src/testcases/org/apache/poi/util/TestLittleEndianStreams.java
+++ b/src/testcases/org/apache/poi/util/TestLittleEndianStreams.java
@@ -19,7 +19,9 @@ package org.apache.poi.util;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
+import java.util.Arrays;
+import junit.framework.AssertionFailedError;
import junit.framework.TestCase;
/**
@@ -50,4 +52,29 @@ public final class TestLittleEndianStreams extends TestCase {
assertEquals(1234567890123456789L, lei.readLong());
assertEquals(123.456, lei.readDouble(), 0.0);
}
+
+ /**
+ * Up until svn r836101 {@link LittleEndianByteArrayInputStream#readFully(byte[], int, int)}
+ * had an error which resulted in the data being read and written back to the source byte
+ * array.
+ */
+ public void testReadFully() {
+ byte[] srcBuf = HexRead.readFromString("99 88 77 66 55 44 33");
+ LittleEndianInput lei = new LittleEndianByteArrayInputStream(srcBuf);
+
+ // do initial read to increment the read index beyond zero
+ assertEquals(0x8899, lei.readUShort());
+
+ byte[] actBuf = new byte[4];
+ lei.readFully(actBuf);
+
+ if (actBuf[0] == 0x00 && srcBuf[0] == 0x77 && srcBuf[3] == 0x44) {
+ throw new AssertionFailedError("Identified bug in readFully() - source buffer was modified");
+ }
+
+ byte[] expBuf = HexRead.readFromString("77 66 55 44");
+ assertTrue(Arrays.equals(actBuf, expBuf));
+ assertEquals(0x33, lei.readUByte());
+ assertEquals(0, lei.available());
+ }
}