View Javadoc

1   /*
2    * Copyright (c) 2009 QOS.ch All rights reserved.
3    * 
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   * 
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   * 
14   * THE SOFTWARE IS PROVIDED "AS  IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  package ch.qos.cal10n.util;
23  
24  import static org.junit.Assert.assertEquals;
25  
26  import java.io.FileInputStream;
27  import java.io.IOException;
28  import java.io.InputStreamReader;
29  import java.io.Reader;
30  import java.util.HashMap;
31  import java.util.Map;
32  
33  import org.junit.Test;
34  
35  import ch.qos.cal10n.Cal10nTestConstants;
36  
37  /**
38   * 
39   * @author Ceki Gülcü
40   * 
41   */
42  public class ResourceBundleEncodingTest {
43  
44    // Useful links:
45  
46    // http://www.terena.org/activities/multiling/ml-docs/iso-8859.html
47  
48    Map<String, String> map = new HashMap<String, String>();
49    Map<String, String> witness = new HashMap<String, String>();
50  
51    // encoding for Greek "ISO8859_7"
52    @Test
53    public void greek_ISO8859_7() throws IOException {
54      FileInputStream fis = new FileInputStream(Cal10nTestConstants.TEST_CLASSES
55          + "/encodingsISO8859/a_el_GR.properties");
56      Reader reader = new InputStreamReader(fis, "ISO8859_7");
57      Parser parser = new Parser(reader, map);
58      parser.parseAndPopulate();
59  
60      String alpha = "\u03b1";
61      witness.put("A", alpha);
62  
63      // char alphaChar = alpha.charAt(0);
64      // System.out.println("alphaChar="+((int) alphaChar));
65      // String suspected = map.get("A");
66      // char suspectedChar = suspected.charAt(0);
67      // System.out.println("suspectedChar="+((int) suspectedChar));
68  
69      assertEquals(witness, map);
70    }
71  
72    // encoding for Turkish "ISO8859_3"
73    @Test
74    public void turkishISO8859_3() throws IOException {
75      FileInputStream fis = new FileInputStream(Cal10nTestConstants.TEST_CLASSES
76          + "/encodingsISO8859/a_tr_TR.properties");
77      Reader reader = new InputStreamReader(fis, "ISO8859_3");
78      Parser parser = new Parser(reader, map);
79      parser.parseAndPopulate();
80  
81      // 0xBA 0x015F # LATIN SMALL LETTER S WITH CEDILLA
82      char sCedilla = '\u015F';
83  
84      // 0xB9 0x0131 # LATIN SMALL LETTER DOTLESS I
85      char iDotless = '\u0131';
86  
87      // nisan pronounced (nIshan)
88      String witnessValue = "n" + iDotless + sCedilla + "an";
89      witness.put("A", witnessValue);
90      assertEquals(witness, map);
91    }
92    
93    @Test
94    public void greek_UTF8() throws IOException {
95      FileInputStream fis = new FileInputStream(Cal10nTestConstants.TEST_CLASSES
96          + "/encodingsUTF8/a_el_GR.properties");
97      Reader reader = new InputStreamReader(fis, "UTF8");
98      Parser parser = new Parser(reader, map);
99      parser.parseAndPopulate();
100 
101     String alpha = "\u03b1";
102     witness.put("A", alpha);
103 
104     assertEquals(witness, map);
105   }
106   
107   @Test
108   public void turkishUTF8() throws IOException {
109     FileInputStream fis = new FileInputStream(Cal10nTestConstants.TEST_CLASSES
110         + "/encodingsUTF8/a_tr_TR.properties");
111     Reader reader = new InputStreamReader(fis, "UTF8");
112     Parser parser = new Parser(reader, map);
113     parser.parseAndPopulate();
114 
115     // 0xBA 0x015F # LATIN SMALL LETTER S WITH CEDILLA
116     char sCedilla = '\u015F';
117 
118     // 0xB9 0x0131 # LATIN SMALL LETTER DOTLESS I
119     char iDotless = '\u0131';
120 
121     // nisan pronounced (nIshan)
122     String witnessValue = "n" + iDotless + sCedilla + "an";
123     witness.put("A", witnessValue);
124     assertEquals(witness, map);
125   }
126 }