commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r1406222 - /commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/CharSequenceInputStreamTest.java
Date Tue, 06 Nov 2012 17:02:39 GMT
Author: sebb
Date: Tue Nov  6 17:02:39 2012
New Revision: 1406222

URL: http://svn.apache.org/viewvc?rev=1406222&view=rev
Log:
IO-356 CharSequenceInputStream#reset() behaves incorrectly in case when buffer size is not
dividable by data size
Add test case showing the issue

Modified:
    commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/CharSequenceInputStreamTest.java

Modified: commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/CharSequenceInputStreamTest.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/CharSequenceInputStreamTest.java?rev=1406222&r1=1406221&r2=1406222&view=diff
==============================================================================
--- commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/CharSequenceInputStreamTest.java
(original)
+++ commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/CharSequenceInputStreamTest.java
Tue Nov  6 17:02:39 2012
@@ -16,6 +16,7 @@
  */
 package org.apache.commons.io.input;
 
+import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 
@@ -39,6 +40,8 @@ public class CharSequenceInputStreamTest
         LARGE_TEST_STRING = buffer.toString();
     }
     
+    private static final String ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
+
     private Random random = new Random();
     
     private void testWithSingleByteRead(String testString, String charsetName) throws IOException
{
@@ -164,4 +167,27 @@ public class CharSequenceInputStreamTest
         assertTrue(r.markSupported());
     }
 
+    private void testIO_356(int bufferSize, int dataSize) throws Exception {
+        CharSequenceInputStream is = new CharSequenceInputStream(ALPHABET, "UTF-8", bufferSize);
+
+        is.mark(dataSize);
+
+        byte[] data1 = new byte[dataSize];
+        is.read(data1);
+
+        is.reset(); // should allow data to be re-read
+
+        byte[] data2 = new byte[dataSize];
+        is.read(data2);
+
+        is.close();
+        assertArrayEquals("bufferSize="+bufferSize+" dataSize="+dataSize, data1, data2);
// data buffers should be identical
+    }
+    
+    @Test
+    public void testIO_356() throws Exception {
+        testIO_356(10, 10); // OK
+        testIO_356(10, 20); // OK
+        testIO_356(10, 13); // fails
+    }
 }



Mime
View raw message