1 36 package org.columba.ristretto.coder; 37 38 import java.nio.charset.Charset ; 39 40 import junit.framework.TestCase; 41 42 public class EncodedWordTest extends TestCase { 43 44 48 public EncodedWordTest(String arg0) { 49 super(arg0); 50 } 51 52 public void testDecodeNone() { 53 String input = "This is a simple Test"; 54 55 StringBuffer result = EncodedWord.decode(input); 56 assertTrue(result.toString().equals(input)); 57 } 58 59 public void testDecodeSimple() { 60 String input = "This is a =?iso-8859-1?q?s=FCmple?= Test"; 61 62 StringBuffer result = EncodedWord.decode(input); 63 assertTrue(result.toString().equals("This is a s\u00fcmple Test")); 64 } 65 66 public void testDecodeWhitespaceNone() { 67 String input = "=?ISO-8859-1?Q?a?==?ISO-8859-1?Q?b?="; 68 69 StringBuffer result = EncodedWord.decode(input); 70 assertTrue(result.toString().equals("ab")); 71 } 72 73 public void testDecodeWhitespaceMulti() { 74 String input = "=?ISO-8859-1?Q?a?= =?ISO-8859-1?Q?b?="; 75 76 StringBuffer result = EncodedWord.decode(input); 77 assertTrue(result.toString().equals("ab")); 78 } 79 80 public void testDecodeSimpleWithWS() { 81 String input = "This is a =?iso-8859-1?q?s=FCmple_?=Test"; 82 83 StringBuffer result = EncodedWord.decode(input); 84 assertTrue(result.toString().equals("This is a s\u00fcmple Test")); 85 } 86 87 public void testDecodeBase64() { 88 String input = 89 "=?ISO-8859-1?B?SWYgeW91IGNhbiByZWFkIHRoaXMgeW8=?==?ISO-8859-2?B?dSB1bmRlcnN0YW5kIHRoZSBleGFtcGxlLg==?="; 90 91 StringBuffer result = EncodedWord.decode(input); 92 assertTrue( 93 result.toString().equals( 94 "If you can read this you understand the example.")); 95 } 96 97 public void testEncodeNone() { 98 String input = "This is a test"; 99 100 StringBuffer result = 101 EncodedWord.encode( 102 input, 103 Charset.forName("ISO-8859-1"), 104 EncodedWord.QUOTED_PRINTABLE); 105 assertTrue(result.toString().equals("This is a test")); 106 } 107 108 public void testEncodeSimple() { 109 String input = "This is a s\u00fcmple test"; 110 111 StringBuffer result = 112 EncodedWord.encode( 113 input, 114 Charset.forName("ISO-8859-1"), 115 EncodedWord.QUOTED_PRINTABLE); 116 assertTrue( 117 result.toString().equals( 118 "This is a =?ISO-8859-1?q?s=FCmple_?=test")); 119 } 120 121 public void testEncodeCombined() { 122 String input = "This is a s\u00fcmple s\u00fcmple test"; 123 124 StringBuffer result = 125 EncodedWord.encode( 126 input, 127 Charset.forName("ISO-8859-1"), 128 EncodedWord.QUOTED_PRINTABLE); 129 assertTrue( 130 result.toString().equals( 131 "This is a =?ISO-8859-1?q?s=FCmple_s=FCmple_?=test")); 132 } 133 134 public void testEncodeSimpleBase64() { 135 String input = "This is a s\u00fcmple test"; 136 137 StringBuffer result = 138 EncodedWord.encode( 139 input, 140 Charset.forName("ISO-8859-1"), 141 EncodedWord.BASE64); 142 assertTrue( 143 result.toString().equals( 144 "This is a =?ISO-8859-1?b?c/xtcGxlIA==?=test")); 145 } 146 147 public void testEncodeBase64EOF() { 148 String input = "This is a s\u00fcmple "; 149 150 StringBuffer result = 151 EncodedWord.encode( 152 input, 153 Charset.forName("ISO-8859-1"), 154 EncodedWord.BASE64); 155 assertTrue( 156 result.toString().equals( 157 "This is a =?ISO-8859-1?b?c/xtcGxlIA==?=")); 158 } 159 160 161 public void testEncodelong() { 162 String input = 163 "This is a s\u00fcmplebutmegalongencodedwordsothatthesecondencodedwordmustbe s\u00fcmple test"; 164 165 StringBuffer result = 166 EncodedWord.encode( 167 input, 168 Charset.forName("ISO-8859-1"), 169 EncodedWord.QUOTED_PRINTABLE); 170 assertTrue( 171 result.toString().equals( 172 "This is a =?ISO-8859-1?q?s=FCmplebutmegalongencodedwordsothatthesecondencodedwordmustbe_?==?ISO-8859-1?q?s=FCmple_?=test")); 173 } 174 175 176 177 } 178 | Popular Tags |