commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t.@apache.org
Subject svn commit: r1302231 - in /commons/proper/codec/trunk/src/test/java/org/apache/commons/codec/binary: Base32InputStreamTest.java Base64InputStreamTest.java
Date Sun, 18 Mar 2012 21:45:43 GMT
Author: tn
Date: Sun Mar 18 21:45:43 2012
New Revision: 1302231

URL: http://svn.apache.org/viewvc?rev=1302231&view=rev
Log:
[CODEC-130] Added unit test for Base32InputStream, improved Base64 unit test.

Modified:
    commons/proper/codec/trunk/src/test/java/org/apache/commons/codec/binary/Base32InputStreamTest.java
    commons/proper/codec/trunk/src/test/java/org/apache/commons/codec/binary/Base64InputStreamTest.java

Modified: commons/proper/codec/trunk/src/test/java/org/apache/commons/codec/binary/Base32InputStreamTest.java
URL: http://svn.apache.org/viewvc/commons/proper/codec/trunk/src/test/java/org/apache/commons/codec/binary/Base32InputStreamTest.java?rev=1302231&r1=1302230&r2=1302231&view=diff
==============================================================================
--- commons/proper/codec/trunk/src/test/java/org/apache/commons/codec/binary/Base32InputStreamTest.java
(original)
+++ commons/proper/codec/trunk/src/test/java/org/apache/commons/codec/binary/Base32InputStreamTest.java
Sun Mar 18 21:45:43 2012
@@ -24,10 +24,12 @@ import static org.junit.Assert.assertTru
 import static org.junit.Assert.fail;
 
 import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.Arrays;
 
+import org.junit.Ignore;
 import org.junit.Test;
 
 public class Base32InputStreamTest {
@@ -38,6 +40,31 @@ public class Base32InputStreamTest {
 
     private final static byte[] LF = { (byte) '\n' };
 
+    private static final String STRING_FIXTURE = "Hello World";
+
+    /**
+     * Tests the problem reported in CODEC-130. Missing / wrong implementation of skip.
+     */
+    @Test
+    @Ignore
+    public void testCodec130() throws IOException {
+        ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        Base32OutputStream base32os = new Base32OutputStream(bos);
+
+        base32os.write(StringUtils.getBytesUtf8(STRING_FIXTURE));
+        base32os.close();
+
+        ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
+        Base32InputStream ins = new Base32InputStream(bis);
+
+        // we skip the first character read from the reader
+        ins.skip(1);
+        byte[] decodedBytes = Base32TestData.streamToBytes(ins, new byte[64]);
+        String str = StringUtils.newStringUtf8(decodedBytes);
+
+        assertEquals(STRING_FIXTURE.substring(1), str);
+    }
+
     /**
      * Tests the bug reported in CODEC-105. Bad interactions with InputStream when reading
one byte at a time.
      */

Modified: commons/proper/codec/trunk/src/test/java/org/apache/commons/codec/binary/Base64InputStreamTest.java
URL: http://svn.apache.org/viewvc/commons/proper/codec/trunk/src/test/java/org/apache/commons/codec/binary/Base64InputStreamTest.java?rev=1302231&r1=1302230&r2=1302231&view=diff
==============================================================================
--- commons/proper/codec/trunk/src/test/java/org/apache/commons/codec/binary/Base64InputStreamTest.java
(original)
+++ commons/proper/codec/trunk/src/test/java/org/apache/commons/codec/binary/Base64InputStreamTest.java
Sun Mar 18 21:45:43 2012
@@ -61,21 +61,16 @@ public class Base64InputStreamTest {
         ByteArrayOutputStream bos = new ByteArrayOutputStream();
         Base64OutputStream base64os = new Base64OutputStream(bos);
 
-        base64os.write(STRING_FIXTURE.getBytes());
+        base64os.write(StringUtils.getBytesUtf8(STRING_FIXTURE));
+        base64os.close();
 
         ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
         Base64InputStream ins = new Base64InputStream(bis);
 
         // we skip the first character read from the reader
         ins.skip(1);
-        StringBuffer sb = new StringBuffer();
-        int len = 0;
-        byte[] bytes = new byte[10];
-        while ((len = ins.read(bytes)) != -1) {
-            String s = new String(bytes, 0, len, "iso-8859-1");
-            sb.append(s);
-        }
-        String str = sb.toString();
+        byte[] decodedBytes = Base64TestData.streamToBytes(ins, new byte[64]);
+        String str = StringUtils.newStringUtf8(decodedBytes);
 
         assertEquals(STRING_FIXTURE.substring(1), str);
     }



Mime
View raw message