You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by sebb <se...@gmail.com> on 2011/07/18 19:11:02 UTC
Re: svn commit: r1147907 - /commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/ReaderInputStreamTest.java
On 18 July 2011 15:51, <gg...@apache.org> wrote:
> Author: ggregory
> Date: Mon Jul 18 14:51:14 2011
> New Revision: 1147907
>
> URL: http://svn.apache.org/viewvc?rev=1147907&view=rev
> Log:
> Tests https://issues.apache.org/jira/browse/IO-277 (@Ignore'd). Port to JUnit 4.
>
> Modified:
> commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/ReaderInputStreamTest.java
>
> Modified: commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/ReaderInputStreamTest.java
> URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/ReaderInputStreamTest.java?rev=1147907&r1=1147906&r2=1147907&view=diff
> ==============================================================================
> --- commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/ReaderInputStreamTest.java (original)
> +++ commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/ReaderInputStreamTest.java Mon Jul 18 14:51:14 2011
> @@ -16,13 +16,19 @@
> */
> package org.apache.commons.io.input;
>
> +import static org.junit.Assert.assertEquals;
> +import static org.junit.Assert.assertTrue;
> +
> +import java.io.CharArrayReader;
> import java.io.IOException;
> import java.io.StringReader;
> +import java.nio.charset.Charset;
> import java.util.Random;
>
> -import junit.framework.TestCase;
> +import org.junit.Ignore;
> +import org.junit.Test;
>
> -public class ReaderInputStreamTest extends TestCase {
> +public class ReaderInputStreamTest {
> private static final String TEST_STRING = "\u00e0 peine arriv\u00e9s nous entr\u00e2mes dans sa chambre";
> private static final String LARGE_TEST_STRING;
>
> @@ -73,29 +79,61 @@ public class ReaderInputStreamTest exten
> }
> }
>
> + @Test
> public void testUTF8WithSingleByteRead() throws IOException {
> testWithSingleByteRead(TEST_STRING, "UTF-8");
> }
>
> + @Test
> public void testLargeUTF8WithSingleByteRead() throws IOException {
> testWithSingleByteRead(LARGE_TEST_STRING, "UTF-8");
> }
>
> + @Test
> public void testUTF8WithBufferedRead() throws IOException {
> testWithBufferedRead(TEST_STRING, "UTF-8");
> }
>
> + @Test
> public void testLargeUTF8WithBufferedRead() throws IOException {
> testWithBufferedRead(LARGE_TEST_STRING, "UTF-8");
> }
>
> + @Test
> public void testUTF16WithSingleByteRead() throws IOException {
> testWithSingleByteRead(TEST_STRING, "UTF-16");
> }
>
> + @Test
> public void testReadZero() throws Exception {
> ReaderInputStream r = new ReaderInputStream(new StringReader("test"));
> byte[] bytes = new byte[30];
> assertEquals(0, r.read(bytes, 0, 0));
> }
> +
> + /**
> + * Tests https://issues.apache.org/jira/browse/IO-277
> + *
> + * @throws IOException
> + */
> + @Test
> + @Ignore
> + public void testCharsetMismatchInfiniteLoop() throws IOException {
> + // Input is UTF-8 bytes: 0xE0 0xB2 0xA0
> + byte[] input = new byte[] { (byte) 0xE0, (byte) 0xB2, (byte) 0xA0 };
> + char[] inputChars = new char[] { (char) 0xE0, (char) 0xB2, (char) 0xA0 };
> + System.out.println("Input: " + new String(input, Charset.forName("UTF-8")));
This does not compile on Java 1.5, because the ctor is 1.6+.
Could use
System.out.println("Input: " + new String(input, "UTF-8"));
instead, but tests should not have unnecessary output.
I suggest deleting "input" and the println statement.
> +
> + // Charset charset = Charset.forName("UTF-8"); // works
> + Charset charset = Charset.forName("ASCII"); // infinite loop
> +
> + ReaderInputStream stream = new ReaderInputStream(new CharArrayReader(inputChars), charset);
> + try {
> + while (stream.read() != -1) {
> + }
> + } finally {
> + stream.close();
> + }
> +
> + }
> }
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org
Re: svn commit: r1147907 - /commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/ReaderInputStreamTest.java
Posted by sebb <se...@gmail.com>.
On 18 July 2011 18:19, Gary Gregory <ga...@gmail.com> wrote:
> On Mon, Jul 18, 2011 at 1:11 PM, sebb <se...@gmail.com> wrote:
>
>> On 18 July 2011 15:51, <gg...@apache.org> wrote:
>> > Author: ggregory
>> > Date: Mon Jul 18 14:51:14 2011
>> > New Revision: 1147907
>> >
>> > URL: http://svn.apache.org/viewvc?rev=1147907&view=rev
>> > Log:
>> > Tests https://issues.apache.org/jira/browse/IO-277 (@Ignore'd). Port to
>> JUnit 4.
>> >
>> > Modified:
>> >
>> commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/ReaderInputStreamTest.java
>> >
>> > Modified:
>> commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/ReaderInputStreamTest.java
>> > URL:
>> http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/ReaderInputStreamTest.java?rev=1147907&r1=1147906&r2=1147907&view=diff
>> >
>> ==============================================================================
>> > ---
>> commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/ReaderInputStreamTest.java
>> (original)
>> > +++
>> commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/ReaderInputStreamTest.java
>> Mon Jul 18 14:51:14 2011
>> > @@ -16,13 +16,19 @@
>> > */
>> > package org.apache.commons.io.input;
>> >
>> > +import static org.junit.Assert.assertEquals;
>> > +import static org.junit.Assert.assertTrue;
>> > +
>> > +import java.io.CharArrayReader;
>> > import java.io.IOException;
>> > import java.io.StringReader;
>> > +import java.nio.charset.Charset;
>> > import java.util.Random;
>> >
>> > -import junit.framework.TestCase;
>> > +import org.junit.Ignore;
>> > +import org.junit.Test;
>> >
>> > -public class ReaderInputStreamTest extends TestCase {
>> > +public class ReaderInputStreamTest {
>> > private static final String TEST_STRING = "\u00e0 peine arriv\u00e9s
>> nous entr\u00e2mes dans sa chambre";
>> > private static final String LARGE_TEST_STRING;
>> >
>> > @@ -73,29 +79,61 @@ public class ReaderInputStreamTest exten
>> > }
>> > }
>> >
>> > + @Test
>> > public void testUTF8WithSingleByteRead() throws IOException {
>> > testWithSingleByteRead(TEST_STRING, "UTF-8");
>> > }
>> >
>> > + @Test
>> > public void testLargeUTF8WithSingleByteRead() throws IOException {
>> > testWithSingleByteRead(LARGE_TEST_STRING, "UTF-8");
>> > }
>> >
>> > + @Test
>> > public void testUTF8WithBufferedRead() throws IOException {
>> > testWithBufferedRead(TEST_STRING, "UTF-8");
>> > }
>> >
>> > + @Test
>> > public void testLargeUTF8WithBufferedRead() throws IOException {
>> > testWithBufferedRead(LARGE_TEST_STRING, "UTF-8");
>> > }
>> >
>> > + @Test
>> > public void testUTF16WithSingleByteRead() throws IOException {
>> > testWithSingleByteRead(TEST_STRING, "UTF-16");
>> > }
>> >
>> > + @Test
>> > public void testReadZero() throws Exception {
>> > ReaderInputStream r = new ReaderInputStream(new
>> StringReader("test"));
>> > byte[] bytes = new byte[30];
>> > assertEquals(0, r.read(bytes, 0, 0));
>> > }
>> > +
>> > + /**
>> > + * Tests https://issues.apache.org/jira/browse/IO-277
>> > + *
>> > + * @throws IOException
>> > + */
>> > + @Test
>> > + @Ignore
>> > + public void testCharsetMismatchInfiniteLoop() throws IOException {
>> > + // Input is UTF-8 bytes: 0xE0 0xB2 0xA0
>> > + byte[] input = new byte[] { (byte) 0xE0, (byte) 0xB2, (byte)
>> 0xA0 };
>> > + char[] inputChars = new char[] { (char) 0xE0, (char) 0xB2,
>> (char) 0xA0 };
>> > + System.out.println("Input: " + new String(input,
>> Charset.forName("UTF-8")));
>>
>> This does not compile on Java 1.5, because the ctor is 1.6+.
>>
>> Could use
>>
>> System.out.println("Input: " + new String(input, "UTF-8"));
>>
>> instead, but tests should not have unnecessary output.
>>
>> I suggest deleting "input" and the println statement.
>>
>
> Good catch, thank you Sebb. In SVN now.
Actually it was Continuum that alerted me to the issue ...
>
> Gary
>
>
>>
>> > +
>> > + // Charset charset = Charset.forName("UTF-8"); // works
>> > + Charset charset = Charset.forName("ASCII"); // infinite loop
>> > +
>> > + ReaderInputStream stream = new ReaderInputStream(new
>> CharArrayReader(inputChars), charset);
>> > + try {
>> > + while (stream.read() != -1) {
>> > + }
>> > + } finally {
>> > + stream.close();
>> > + }
>> > +
>> > + }
>> > }
>> >
>> >
>> >
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
>> For additional commands, e-mail: dev-help@commons.apache.org
>>
>>
>
>
> --
> Thank you,
> Gary
>
> http://garygregory.wordpress.com/
> http://garygregory.com/
> http://people.apache.org/~ggregory/
> http://twitter.com/GaryGregory
>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org
Re: svn commit: r1147907 - /commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/ReaderInputStreamTest.java
Posted by Gary Gregory <ga...@gmail.com>.
On Mon, Jul 18, 2011 at 1:11 PM, sebb <se...@gmail.com> wrote:
> On 18 July 2011 15:51, <gg...@apache.org> wrote:
> > Author: ggregory
> > Date: Mon Jul 18 14:51:14 2011
> > New Revision: 1147907
> >
> > URL: http://svn.apache.org/viewvc?rev=1147907&view=rev
> > Log:
> > Tests https://issues.apache.org/jira/browse/IO-277 (@Ignore'd). Port to
> JUnit 4.
> >
> > Modified:
> >
> commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/ReaderInputStreamTest.java
> >
> > Modified:
> commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/ReaderInputStreamTest.java
> > URL:
> http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/ReaderInputStreamTest.java?rev=1147907&r1=1147906&r2=1147907&view=diff
> >
> ==============================================================================
> > ---
> commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/ReaderInputStreamTest.java
> (original)
> > +++
> commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/ReaderInputStreamTest.java
> Mon Jul 18 14:51:14 2011
> > @@ -16,13 +16,19 @@
> > */
> > package org.apache.commons.io.input;
> >
> > +import static org.junit.Assert.assertEquals;
> > +import static org.junit.Assert.assertTrue;
> > +
> > +import java.io.CharArrayReader;
> > import java.io.IOException;
> > import java.io.StringReader;
> > +import java.nio.charset.Charset;
> > import java.util.Random;
> >
> > -import junit.framework.TestCase;
> > +import org.junit.Ignore;
> > +import org.junit.Test;
> >
> > -public class ReaderInputStreamTest extends TestCase {
> > +public class ReaderInputStreamTest {
> > private static final String TEST_STRING = "\u00e0 peine arriv\u00e9s
> nous entr\u00e2mes dans sa chambre";
> > private static final String LARGE_TEST_STRING;
> >
> > @@ -73,29 +79,61 @@ public class ReaderInputStreamTest exten
> > }
> > }
> >
> > + @Test
> > public void testUTF8WithSingleByteRead() throws IOException {
> > testWithSingleByteRead(TEST_STRING, "UTF-8");
> > }
> >
> > + @Test
> > public void testLargeUTF8WithSingleByteRead() throws IOException {
> > testWithSingleByteRead(LARGE_TEST_STRING, "UTF-8");
> > }
> >
> > + @Test
> > public void testUTF8WithBufferedRead() throws IOException {
> > testWithBufferedRead(TEST_STRING, "UTF-8");
> > }
> >
> > + @Test
> > public void testLargeUTF8WithBufferedRead() throws IOException {
> > testWithBufferedRead(LARGE_TEST_STRING, "UTF-8");
> > }
> >
> > + @Test
> > public void testUTF16WithSingleByteRead() throws IOException {
> > testWithSingleByteRead(TEST_STRING, "UTF-16");
> > }
> >
> > + @Test
> > public void testReadZero() throws Exception {
> > ReaderInputStream r = new ReaderInputStream(new
> StringReader("test"));
> > byte[] bytes = new byte[30];
> > assertEquals(0, r.read(bytes, 0, 0));
> > }
> > +
> > + /**
> > + * Tests https://issues.apache.org/jira/browse/IO-277
> > + *
> > + * @throws IOException
> > + */
> > + @Test
> > + @Ignore
> > + public void testCharsetMismatchInfiniteLoop() throws IOException {
> > + // Input is UTF-8 bytes: 0xE0 0xB2 0xA0
> > + byte[] input = new byte[] { (byte) 0xE0, (byte) 0xB2, (byte)
> 0xA0 };
> > + char[] inputChars = new char[] { (char) 0xE0, (char) 0xB2,
> (char) 0xA0 };
> > + System.out.println("Input: " + new String(input,
> Charset.forName("UTF-8")));
>
> This does not compile on Java 1.5, because the ctor is 1.6+.
>
> Could use
>
> System.out.println("Input: " + new String(input, "UTF-8"));
>
> instead, but tests should not have unnecessary output.
>
> I suggest deleting "input" and the println statement.
>
Good catch, thank you Sebb. In SVN now.
Gary
>
> > +
> > + // Charset charset = Charset.forName("UTF-8"); // works
> > + Charset charset = Charset.forName("ASCII"); // infinite loop
> > +
> > + ReaderInputStream stream = new ReaderInputStream(new
> CharArrayReader(inputChars), charset);
> > + try {
> > + while (stream.read() != -1) {
> > + }
> > + } finally {
> > + stream.close();
> > + }
> > +
> > + }
> > }
> >
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
>
--
Thank you,
Gary
http://garygregory.wordpress.com/
http://garygregory.com/
http://people.apache.org/~ggregory/
http://twitter.com/GaryGregory