1 36 package org.columba.ristretto.coder; 37 38 import java.io.ByteArrayInputStream ; 39 import java.io.IOException ; 40 import java.io.InputStream ; 41 42 import junit.framework.TestCase; 43 44 public class CanonizeFilterInputStreamTest extends TestCase { 45 46 public void testCR() throws IOException { 47 String test = "This is a test\r"; 48 StringBuffer result = new StringBuffer (); 49 InputStream in = new CanonizeFilterInputStream( new ByteArrayInputStream (test.getBytes())); 50 51 int read = in.read(); 52 while( read != -1 ) { 53 result.append((char)read); 54 read = in.read(); 55 } 56 57 assertTrue( "This is a test\r\n".equals( result.toString() )); 58 } 59 60 public void testLF() throws IOException { 61 String test = "This is a test\n"; 62 StringBuffer result = new StringBuffer (); 63 InputStream in = new CanonizeFilterInputStream( new ByteArrayInputStream (test.getBytes())); 64 65 int read = in.read(); 66 while( read != -1 ) { 67 result.append((char)read); 68 read = in.read(); 69 } 70 71 assertTrue( "This is a test\r\n".equals( result.toString() )); 72 } 73 74 public void testCRLF() throws IOException { 75 String test = "This is a test\r\n"; 76 StringBuffer result = new StringBuffer (); 77 InputStream in = new CanonizeFilterInputStream( new ByteArrayInputStream (test.getBytes())); 78 79 int read = in.read(); 80 while( read != -1 ) { 81 result.append((char)read); 82 read = in.read(); 83 } 84 85 assertTrue( "This is a test\r\n".equals( result.toString() )); 86 } 87 88 public void testEOF() throws IOException { 89 String test = "This is a test\r\n"; 90 StringBuffer result = new StringBuffer (); 91 InputStream in = new CanonizeFilterInputStream( new ByteArrayInputStream (test.getBytes())); 92 byte[] buffer = new byte[30]; 93 94 95 int read = in.read(buffer); 96 97 assertTrue(read == 16); 98 99 read = in.read(buffer); 100 assertTrue(read == -1); 101 } 102 103 104 } 105 | Popular Tags |