1 36 package org.columba.ristretto.coder; 37 38 import java.io.ByteArrayInputStream ; 39 import java.io.IOException ; 40 import java.io.InputStream ; 41 import java.io.UnsupportedEncodingException ; 42 43 import junit.framework.TestCase; 44 45 public class QuotedPrintableDecoderInputStreamTest extends TestCase { 46 47 public void testDecodeNone() { 48 try { 49 String input = "This is a\tTest"; 50 InputStream in = new QuotedPrintableDecoderInputStream( new ByteArrayInputStream ( input.getBytes("ISO-8859-1"))); 51 52 StringBuffer result = new StringBuffer (); 53 int next = in.read(); 54 while( next != -1 ) { 55 result.append((char) next); 56 next = in.read(); 57 } 58 59 assertTrue(result.toString().equals("This is a\tTest")); 60 } catch (UnsupportedEncodingException e) { 61 e.printStackTrace(); 62 } catch (IOException e) { 63 e.printStackTrace(); 64 } 65 } 66 67 public void testDecodeSimple() { 68 try { 69 String input = "This is a =DCest"; InputStream in = new QuotedPrintableDecoderInputStream( new ByteArrayInputStream ( input.getBytes("ISO-8859-1"))); 71 72 StringBuffer result = new StringBuffer (); 73 int next = in.read(); 74 while( next != -1 ) { 75 result.append((char) next); 76 next = in.read(); 77 } 78 79 assertTrue(result.toString().equals("This is a \u00dcest")); 80 } catch (UnsupportedEncodingException e) { 81 e.printStackTrace(); 82 } catch (IOException e) { 83 e.printStackTrace(); 84 } 85 } 86 87 88 public void testDecodeSoftlinebreak() { 89 try { 90 String input = "This is a =\r\n=DCest"; 91 InputStream in = new QuotedPrintableDecoderInputStream( new ByteArrayInputStream ( input.getBytes("ISO-8859-1"))); 92 93 StringBuffer result = new StringBuffer (); 94 int next = in.read(); 95 while( next != -1 ) { 96 result.append((char) next); 97 next = in.read(); 98 } 99 100 assertTrue(result.toString().equals("This is a \u00dcest")); 101 } catch (UnsupportedEncodingException e) { 102 e.printStackTrace(); 103 } catch (IOException e) { 104 e.printStackTrace(); 105 } 106 } 107 } 108 | Popular Tags |