Path: blob/master/test/jdk/java/nio/charset/Charset/Contains.java
41155 views
/*1* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/* @test24* @summary Unit test for charset containment25* @bug 679857226* @modules jdk.charsets27*/2829import java.nio.charset.*;303132public class Contains {3334static void ck(Charset cs1, Charset cs2, boolean cont) throws Exception {35if ((cs1.contains(cs2)) != cont)36throw new Exception("Wrong answer: "37+ cs1.name() + " contains " + cs2.name());38System.err.println(cs1.name()39+ (cont ? " contains " : " does not contain ")40+ cs2.name());41}4243public static void main(String[] args) throws Exception {4445Charset us_ascii = Charset.forName("US-ASCII");46Charset iso_8859_1 = Charset.forName("ISO-8859-1");47Charset iso_8859_15 = Charset.forName("ISO-8859-15");48Charset utf_8 = Charset.forName("UTF-8");49Charset utf_16be = Charset.forName("UTF-16BE");50Charset cp1252 = Charset.forName("CP1252");5152ck(us_ascii, us_ascii, true);53ck(us_ascii, iso_8859_1, false);54ck(us_ascii, iso_8859_15, false);55ck(us_ascii, utf_8, false);56ck(us_ascii, utf_16be, false);57ck(us_ascii, cp1252, false);5859ck(iso_8859_1, us_ascii, true);60ck(iso_8859_1, iso_8859_1, true);61ck(iso_8859_1, iso_8859_15, false);62ck(iso_8859_1, utf_8, false);63ck(iso_8859_1, utf_16be, false);64ck(iso_8859_1, cp1252, false);6566ck(iso_8859_15, us_ascii, true);67ck(iso_8859_15, iso_8859_1, false);68ck(iso_8859_15, iso_8859_15, true);69ck(iso_8859_15, utf_8, false);70ck(iso_8859_15, utf_16be, false);71ck(iso_8859_15, cp1252, false);7273ck(utf_8, us_ascii, true);74ck(utf_8, iso_8859_1, true);75ck(utf_8, iso_8859_15, true);76ck(utf_8, utf_8, true);77ck(utf_8, utf_16be, true);78ck(utf_8, cp1252, true);7980ck(utf_16be, us_ascii, true);81ck(utf_16be, iso_8859_1, true);82ck(utf_16be, iso_8859_15, true);83ck(utf_16be, utf_8, true);84ck(utf_16be, utf_16be, true);85ck(utf_16be, cp1252, true);8687ck(cp1252, us_ascii, true);88ck(cp1252, iso_8859_1, false);89ck(cp1252, iso_8859_15, false);90ck(cp1252, utf_8, false);91ck(cp1252, utf_16be, false);92ck(cp1252, cp1252, true);9394checkUTF();95}9697static void checkUTF() throws Exception {98for (String utfName : utfNames)99for (String csName : charsetNames)100ck(Charset.forName(utfName),101Charset.forName(csName),102true);103}104105static String[] utfNames = {"utf-16",106"utf-8",107"utf-16le",108"utf-16be",109"x-utf-16le-bom"};110111static String[] charsetNames = {112"US-ASCII",113"UTF-8",114"UTF-16",115"UTF-16BE",116"UTF-16LE",117"x-UTF-16LE-BOM",118"GBK",119"GB18030",120"ISO-8859-1",121"ISO-8859-15",122"ISO-8859-2",123"ISO-8859-3",124"ISO-8859-4",125"ISO-8859-5",126"ISO-8859-6",127"ISO-8859-7",128"ISO-8859-8",129"ISO-8859-9",130"ISO-8859-13",131"JIS_X0201",132"x-JIS0208",133"JIS_X0212-1990",134"GB2312",135"EUC-KR",136"x-EUC-TW",137"EUC-JP",138"x-euc-jp-linux",139"KOI8-R",140"TIS-620",141"x-ISCII91",142"windows-1251",143"windows-1252",144"windows-1253",145"windows-1254",146"windows-1255",147"windows-1256",148"windows-1257",149"windows-1258",150"windows-932",151"x-mswin-936",152"x-windows-949",153"x-windows-950",154"windows-31j",155"Big5",156"Big5-HKSCS",157"x-MS950-HKSCS",158"ISO-2022-JP",159"ISO-2022-KR",160"x-ISO-2022-CN-CNS",161"x-ISO-2022-CN-GB",162"Big5-HKSCS",163"x-Johab",164"Shift_JIS"165};166}167168169