|
39 | 39 | */ |
40 | 40 | public class HexTest extends TestCase { |
41 | 41 |
|
| 42 | + private static final String BAD_ENCODING_NAME = "UNKNOWN"; |
42 | 43 | private final static boolean LOG = true; |
43 | 44 |
|
44 | 45 | public HexTest(String name) { |
45 | 46 | super(name); |
46 | 47 | } |
47 | 48 |
|
| 49 | + private boolean charsetSanityCheck(String name) { |
| 50 | + final String source = "the quick brown dog jumped over the lazy fox"; |
| 51 | + try { |
| 52 | + byte[] bytes = source.getBytes(name); |
| 53 | + String str = new String(bytes, name); |
| 54 | + boolean equals = source.equals(str); |
| 55 | + if (equals == false) { |
| 56 | + // Here with: |
| 57 | + // |
| 58 | + // Java Sun 1.4.2_19 x86 32-bits on Windows XP |
| 59 | + // JIS_X0212-1990 |
| 60 | + // x-JIS0208 |
| 61 | + // |
| 62 | + // Java Sun 1.5.0_17 x86 32-bits on Windows XP |
| 63 | + // JIS_X0212-1990 |
| 64 | + // x-IBM834 |
| 65 | + // x-JIS0208 |
| 66 | + // x-MacDingbat |
| 67 | + // x-MacSymbol |
| 68 | + // |
| 69 | + // Java Sun 1.6.0_14 x86 32-bits |
| 70 | + // JIS_X0212-1990 |
| 71 | + // x-IBM834 |
| 72 | + // x-JIS0208 |
| 73 | + // x-MacDingbat |
| 74 | + // x-MacSymbol |
| 75 | + // |
| 76 | + log("FAILED charsetSanityCheck=Interesting Java charset oddity: Roundtrip failed for " + name); |
| 77 | + } |
| 78 | + return equals; |
| 79 | + } catch (UnsupportedEncodingException e) { |
| 80 | + // Should NEVER happen since we are getting the name from the Charset class. |
| 81 | + if (LOG) { |
| 82 | + log("FAILED charsetSanityCheck=" + name + ", e=" + e); |
| 83 | + log(e); |
| 84 | + } |
| 85 | + return false; |
| 86 | + } catch (UnsupportedOperationException e) { |
| 87 | + // Caught here with: |
| 88 | + // x-JISAutoDetect on Windows XP and Java Sun 1.4.2_19 x86 32-bits |
| 89 | + // x-JISAutoDetect on Windows XP and Java Sun 1.5.0_17 x86 32-bits |
| 90 | + // x-JISAutoDetect on Windows XP and Java Sun 1.6.0_14 x86 32-bits |
| 91 | + if (LOG) { |
| 92 | + log("FAILED charsetSanityCheck=" + name + ", e=" + e); |
| 93 | + log(e); |
| 94 | + } |
| 95 | + return false; |
| 96 | + } |
| 97 | + } |
| 98 | + |
48 | 99 | /** |
49 | 100 | * @param data |
50 | 101 | */ |
@@ -123,56 +174,37 @@ private void testCustomCharset(String name, String parent) throws UnsupportedEnc |
123 | 174 | assertEquals(name, sourceString, actualStringFromBytes); |
124 | 175 | } |
125 | 176 |
|
126 | | - private boolean charsetSanityCheck(String name) { |
127 | | - final String source = "the quick brown dog jumped over the lazy fox"; |
| 177 | + public void testCustomCharsetBadNameEncodeByteArray() { |
128 | 178 | try { |
129 | | - byte[] bytes = source.getBytes(name); |
130 | | - String str = new String(bytes, name); |
131 | | - boolean equals = source.equals(str); |
132 | | - if (equals == false) { |
133 | | - // Here with: |
134 | | - // |
135 | | - // Java Sun 1.4.2_19 x86 32-bits on Windows XP |
136 | | - // JIS_X0212-1990 |
137 | | - // x-JIS0208 |
138 | | - // |
139 | | - // Java Sun 1.5.0_17 x86 32-bits on Windows XP |
140 | | - // JIS_X0212-1990 |
141 | | - // x-IBM834 |
142 | | - // x-JIS0208 |
143 | | - // x-MacDingbat |
144 | | - // x-MacSymbol |
145 | | - // |
146 | | - // Java Sun 1.6.0_14 x86 32-bits |
147 | | - // JIS_X0212-1990 |
148 | | - // x-IBM834 |
149 | | - // x-JIS0208 |
150 | | - // x-MacDingbat |
151 | | - // x-MacSymbol |
152 | | - // |
153 | | - log("FAILED charsetSanityCheck=Interesting Java charset oddity: Roundtrip failed for " + name); |
154 | | - } |
155 | | - return equals; |
156 | | - } catch (UnsupportedEncodingException e) { |
157 | | - // Should NEVER happen since we are getting the name from the Charset class. |
158 | | - if (LOG) { |
159 | | - log("FAILED charsetSanityCheck=" + name + ", e=" + e); |
160 | | - log(e); |
161 | | - } |
162 | | - return false; |
163 | | - } catch (UnsupportedOperationException e) { |
164 | | - // Caught here with: |
165 | | - // x-JISAutoDetect on Windows XP and Java Sun 1.4.2_19 x86 32-bits |
166 | | - // x-JISAutoDetect on Windows XP and Java Sun 1.5.0_17 x86 32-bits |
167 | | - // x-JISAutoDetect on Windows XP and Java Sun 1.6.0_14 x86 32-bits |
168 | | - if (LOG) { |
169 | | - log("FAILED charsetSanityCheck=" + name + ", e=" + e); |
170 | | - log(e); |
171 | | - } |
172 | | - return false; |
| 179 | + new Hex(BAD_ENCODING_NAME).encode("Hello World".getBytes()); |
| 180 | + fail("Expected " + IllegalStateException.class.getName()); |
| 181 | + } catch (IllegalStateException e) { |
| 182 | + // Expected |
173 | 183 | } |
174 | 184 | } |
175 | 185 |
|
| 186 | + public void testCustomCharsetBadNameEncodeObject() { |
| 187 | + try { |
| 188 | + new Hex(BAD_ENCODING_NAME).encode("Hello World"); |
| 189 | + fail("Expected " + EncoderException.class.getName()); |
| 190 | + } catch (EncoderException e) { |
| 191 | + // Expected |
| 192 | + } |
| 193 | + } |
| 194 | + |
| 195 | + public void testCustomCharsetBadNameDecodeObject() { |
| 196 | + try { |
| 197 | + new Hex(BAD_ENCODING_NAME).decode("Hello World".getBytes()); |
| 198 | + fail("Expected " + DecoderException.class.getName()); |
| 199 | + } catch (DecoderException e) { |
| 200 | + // Expected |
| 201 | + } |
| 202 | + } |
| 203 | + |
| 204 | + public void testCustomCharsetToString() { |
| 205 | + assertTrue(new Hex().toString().indexOf(Hex.DEFAULT_CHARSET_NAME) >= 0); |
| 206 | + } |
| 207 | + |
176 | 208 | public void testDecodeArrayOddCharacters() { |
177 | 209 | try { |
178 | 210 | new Hex().decode(new byte[]{65}); |
|
0 commit comments