View Javadoc

1   /*
2    * ====================================================================
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *   http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing,
14   * software distributed under the License is distributed on an
15   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16   * KIND, either express or implied.  See the License for the
17   * specific language governing permissions and limitations
18   * under the License.
19   * ====================================================================
20   *
21   * This software consists of voluntary contributions made by many
22   * individuals on behalf of the Apache Software Foundation.  For more
23   * information on the Apache Software Foundation, please see
24   * <http://www.apache.org/>.
25   *
26   */
27  package org.apache.http.client.utils;
28  
29  import org.junit.Assert;
30  import org.junit.Test;
31  
32  public class TestRfc3492Idn {
33  
34      /**
35       * Some of the sample strings from RFC 3492
36       */
37      @Test
38      public void testDecode() throws Exception {
39          final Rfc3492Idn idn = new Rfc3492Idn();
40          // (A) Arabic
41          Assert.assertEquals("\u0644\u064A\u0647\u0645\u0627\u0628\u062A\u0643\u0644" +
42                       "\u0645\u0648\u0634\u0639\u0631\u0628\u064A\u061F",
43                       idn.decode("egbpdaj6bu4bxfgehfvwxn"));
44  
45          // (B) Chinese (simplified)
46          Assert.assertEquals("\u4ED6\u4EEC\u4E3A\u4EC0\u4E48\u4E0D\u8BF4\u4E2D\u6587",
47                       idn.decode("ihqwcrb4cv8a8dqg056pqjye"));
48  
49          // (I) Russian (Cyrillic)
50          Assert.assertEquals("\u043F\u043E\u0447\u0435\u043C\u0443\u0436\u0435\u043E"+
51                       "\u043D\u0438\u043D\u0435\u0433\u043E\u0432\u043E\u0440"+
52                       "\u044F\u0442\u043F\u043E\u0440\u0443\u0441\u0441\u043A"+
53                       "\u0438",
54                       idn.decode("b1abfaaepdrnnbgefbaDotcwatmq2g4l"));
55  
56          // (P) Maji<de>Koi<suru>5<byou><mae>
57          Assert.assertEquals("\u004D\u0061\u006A\u0069\u3067\u004B\u006F\u0069\u3059" +
58                       "\u308B\u0035\u79D2\u524D",
59                       idn.decode("MajiKoi5-783gue6qz075azm5e"));
60  
61      }
62  
63      @Test
64      public void testToUnicode() throws Exception {
65          final Rfc3492Idn idn = new Rfc3492Idn();
66          // (A) Arabic
67          Assert.assertEquals("\u0644\u064A\u0647\u0645\u0627\u0628\u062A\u0643\u0644" +
68                       "\u0645\u0648\u0634\u0639\u0631\u0628\u064A\u061F",
69                       idn.toUnicode("xn--egbpdaj6bu4bxfgehfvwxn"));
70  
71          // some real-world domains
72          Assert.assertEquals("www.z\u00fcrich.ch",
73                       idn.toUnicode("www.xn--zrich-kva.ch"));
74  
75          Assert.assertEquals("www.g\u00e4ggelig\u00e4\u00e4l.ch",
76                       idn.toUnicode("www.xn--gggeligl-0zaga.ch"));
77      }
78  
79  }