1 /* 2 * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /* @test 25 * @summary Unit test for charset containment 26 * @bug 6798572 27 * @modules jdk.charsets 28 */ 29 30 package test.java.nio.charset.Charset; 31 32 import java.nio.charset.*; 33 34 35 public class Contains { 36 ck(Charset cs1, Charset cs2, boolean cont)37 static void ck(Charset cs1, Charset cs2, boolean cont) throws Exception { 38 if ((cs1.contains(cs2)) != cont) 39 throw new Exception("Wrong answer: " 40 + cs1.name() + " contains " + cs2.name()); 41 System.err.println(cs1.name() 42 + (cont ? " contains " : " does not contain ") 43 + cs2.name()); 44 } 45 main(String[] args)46 public static void main(String[] args) throws Exception { 47 48 Charset us_ascii = Charset.forName("US-ASCII"); 49 Charset iso_8859_1 = Charset.forName("ISO-8859-1"); 50 Charset iso_8859_15 = Charset.forName("ISO-8859-15"); 51 Charset utf_8 = Charset.forName("UTF-8"); 52 Charset utf_16be = Charset.forName("UTF-16BE"); 53 Charset cp1252 = Charset.forName("CP1252"); 54 55 ck(us_ascii, us_ascii, true); 56 ck(us_ascii, iso_8859_1, false); 57 ck(us_ascii, iso_8859_15, false); 58 ck(us_ascii, utf_8, false); 59 ck(us_ascii, utf_16be, false); 60 ck(us_ascii, cp1252, false); 61 62 ck(iso_8859_1, us_ascii, true); 63 ck(iso_8859_1, iso_8859_1, true); 64 ck(iso_8859_1, iso_8859_15, false); 65 ck(iso_8859_1, utf_8, false); 66 ck(iso_8859_1, utf_16be, false); 67 ck(iso_8859_1, cp1252, false); 68 69 ck(iso_8859_15, us_ascii, true); 70 ck(iso_8859_15, iso_8859_1, false); 71 ck(iso_8859_15, iso_8859_15, true); 72 ck(iso_8859_15, utf_8, false); 73 ck(iso_8859_15, utf_16be, false); 74 ck(iso_8859_15, cp1252, false); 75 76 ck(utf_8, us_ascii, true); 77 ck(utf_8, iso_8859_1, true); 78 ck(utf_8, iso_8859_15, true); 79 ck(utf_8, utf_8, true); 80 ck(utf_8, utf_16be, true); 81 ck(utf_8, cp1252, true); 82 83 ck(utf_16be, us_ascii, true); 84 ck(utf_16be, iso_8859_1, true); 85 ck(utf_16be, iso_8859_15, true); 86 ck(utf_16be, utf_8, true); 87 ck(utf_16be, utf_16be, true); 88 ck(utf_16be, cp1252, true); 89 90 ck(cp1252, us_ascii, true); 91 ck(cp1252, iso_8859_1, false); 92 ck(cp1252, iso_8859_15, false); 93 ck(cp1252, utf_8, false); 94 ck(cp1252, utf_16be, false); 95 ck(cp1252, cp1252, true); 96 97 checkUTF(); 98 } 99 checkUTF()100 static void checkUTF() throws Exception { 101 for (String utfName : utfNames) 102 for (String csName : charsetNames) 103 ck(Charset.forName(utfName), 104 Charset.forName(csName), 105 true); 106 } 107 108 static String[] utfNames = {"utf-16", 109 "utf-8", 110 "utf-16le", 111 "utf-16be", 112 "x-utf-16le-bom"}; 113 114 static String[] charsetNames = { 115 "US-ASCII", 116 "UTF-8", 117 "UTF-16", 118 "UTF-16BE", 119 "UTF-16LE", 120 "x-UTF-16LE-BOM", 121 "GBK", 122 "GB18030", 123 "ISO-8859-1", 124 "ISO-8859-15", 125 "ISO-8859-2", 126 "ISO-8859-3", 127 "ISO-8859-4", 128 "ISO-8859-5", 129 "ISO-8859-6", 130 "ISO-8859-7", 131 "ISO-8859-8", 132 "ISO-8859-9", 133 "ISO-8859-13", 134 // Android-removed: Remove charset not supported by ICU4C. 135 //"JIS_X0201", 136 //"x-JIS0208", 137 //"JIS_X0212-1990", 138 "GB2312", 139 "EUC-KR", 140 "x-EUC-TW", 141 "EUC-JP", 142 // Android-removed: Remove charset not supported by ICU4C. 143 //"x-euc-jp-linux", 144 "KOI8-R", 145 "TIS-620", 146 "x-ISCII91", 147 "windows-1251", 148 "windows-1252", 149 "windows-1253", 150 "windows-1254", 151 "windows-1255", 152 "windows-1256", 153 "windows-1257", 154 "windows-1258", 155 "windows-932", 156 // Android-removed: Remove charset not supported by ICU4C. 157 //"x-mswin-936", 158 "x-windows-949", 159 "x-windows-950", 160 "windows-31j", 161 "Big5", 162 "Big5-HKSCS", 163 "x-MS950-HKSCS", 164 "ISO-2022-JP", 165 "ISO-2022-KR", 166 // Android-removed: Remove charset not supported by ICU4C. 167 //"x-ISO-2022-CN-CNS", 168 //"x-ISO-2022-CN-GB", 169 "Big5-HKSCS", 170 // Android-removed: Remove charset not supported by ICU4C. 171 //"x-Johab", 172 "Shift_JIS" 173 }; 174 } 175