Skip to content

Commit 2697108

Browse files
committed
Added unit test for CODEC-130.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/codec/trunk@1301974 13f79535-47bb-0310-9956-ffa450edef68
1 parent 45acec7 commit 2697108

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

src/test/java/org/apache/commons/codec/binary/Base64InputStreamTest.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,16 @@
2424
import static org.junit.Assert.assertTrue;
2525
import static org.junit.Assert.fail;
2626

27+
import java.io.BufferedInputStream;
2728
import java.io.BufferedReader;
2829
import java.io.ByteArrayInputStream;
30+
import java.io.ByteArrayOutputStream;
2931
import java.io.IOException;
3032
import java.io.InputStream;
3133
import java.io.InputStreamReader;
3234
import java.util.Arrays;
3335

36+
import org.junit.Ignore;
3437
import org.junit.Test;
3538

3639
/**
@@ -50,6 +53,34 @@ public class Base64InputStreamTest {
5053

5154
private static final String STRING_FIXTURE = "Hello World";
5255

56+
/**
57+
* Tests the problem reported in CODEC-130. Missing / wrong implementation of skip.
58+
*/
59+
@Test
60+
@Ignore
61+
public void testCodec130() throws IOException {
62+
ByteArrayOutputStream bos = new ByteArrayOutputStream();
63+
Base64OutputStream base64os = new Base64OutputStream(bos);
64+
65+
base64os.write("Hello World!".getBytes());
66+
67+
ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
68+
Base64InputStream ins = new Base64InputStream(bis);
69+
70+
// we skip the first character read from the reader
71+
ins.skip(1);
72+
StringBuffer sb = new StringBuffer();
73+
int len = 0;
74+
byte[] bytes = new byte[10];
75+
while ((len = ins.read(bytes)) != -1) {
76+
String s = new String(bytes, 0, len, "iso-8859-1");
77+
sb.append(s);
78+
}
79+
String str = sb.toString();
80+
81+
assertEquals("ello World!", str);
82+
}
83+
5384
/**
5485
* Tests the bug reported in CODEC-105. Bad interactions with InputStream when reading one byte at a time.
5586
*/

0 commit comments

Comments
 (0)