|
1 | 1 | /* |
2 | | - * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//codec/src/test/org/apache/commons/codec/net/URLCodecTest.java,v 1.1 2003/07/11 20:14:37 tobrien Exp $ |
3 | | - * $Revision: 1.1 $ |
4 | | - * $Date: 2003/07/11 20:14:37 $ |
| 2 | + * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//codec/src/test/org/apache/commons/codec/net/URLCodecTest.java,v 1.2 2003/07/31 20:09:21 tobrien Exp $ |
| 3 | + * $Revision: 1.2 $ |
| 4 | + * $Date: 2003/07/31 20:09:21 $ |
5 | 5 | * |
6 | 6 | * ==================================================================== |
7 | 7 | * |
|
71 | 71 | */ |
72 | 72 |
|
73 | 73 | public class URLCodecTest extends TestCase { |
| 74 | + |
| 75 | + static final int SWISS_GERMAN_STUFF_UNICODE [] = { |
| 76 | + 0x47, 0x72, 0xFC, 0x65, 0x7A, 0x69, 0x5F, 0x7A, 0xE4, 0x6D, 0xE4 |
| 77 | + }; |
| 78 | + |
| 79 | + static final int RUSSIAN_STUFF_UNICODE [] = { |
| 80 | + 0x412, 0x441, 0x435, 0x43C, 0x5F, 0x43F, 0x440, 0x438, |
| 81 | + 0x432, 0x435, 0x442 |
| 82 | + }; |
74 | 83 |
|
75 | 84 | public URLCodecTest(String name) { |
76 | 85 | super(name); |
77 | 86 | } |
78 | 87 |
|
| 88 | + private String constructString(int [] unicodeChars) { |
| 89 | + StringBuffer buffer = new StringBuffer(); |
| 90 | + if (unicodeChars != null) { |
| 91 | + for (int i = 0; i < unicodeChars.length; i++) { |
| 92 | + buffer.append((char)unicodeChars[i]); |
| 93 | + } |
| 94 | + } |
| 95 | + return buffer.toString(); |
| 96 | + } |
| 97 | + |
| 98 | + public void testUTF8RoundTrip() throws Exception { |
| 99 | + |
| 100 | + String ru_msg = constructString(RUSSIAN_STUFF_UNICODE); |
| 101 | + String ch_msg = constructString(SWISS_GERMAN_STUFF_UNICODE); |
| 102 | + |
| 103 | + URLCodec codec = new URLCodec(); |
| 104 | + |
| 105 | + assertEquals( |
| 106 | + "%D0%92%D1%81%D0%B5%D0%BC_%D0%BF%D1%80%D0%B8%D0%B2%D0%B5%D1%82", |
| 107 | + codec.encode(ru_msg, "UTF-8") |
| 108 | + ); |
| 109 | + assertEquals("Gr%C3%BCezi_z%C3%A4m%C3%A4", codec.encode(ch_msg, "UTF-8")); |
| 110 | + |
| 111 | + assertEquals(ru_msg, codec.decode(codec.encode(ru_msg, "UTF-8"), "UTF-8")); |
| 112 | + assertEquals(ch_msg, codec.decode(codec.encode(ch_msg, "UTF-8"), "UTF-8")); |
| 113 | + } |
79 | 114 |
|
80 | 115 | public void testBasicEncodeDecode() throws Exception { |
81 | 116 | URLCodec urlcodec = new URLCodec(); |
|
0 commit comments