Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/nio/charset/Charset/Contains.java
38821 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*/2728import java.nio.charset.*;293031public class Contains {3233static void ck(Charset cs1, Charset cs2, boolean cont) throws Exception {34if ((cs1.contains(cs2)) != cont)35throw new Exception("Wrong answer: "36+ cs1.name() + " contains " + cs2.name());37System.err.println(cs1.name()38+ (cont ? " contains " : " does not contain ")39+ cs2.name());40}4142public static void main(String[] args) throws Exception {4344Charset us_ascii = Charset.forName("US-ASCII");45Charset iso_8859_1 = Charset.forName("ISO-8859-1");46Charset iso_8859_15 = Charset.forName("ISO-8859-15");47Charset utf_8 = Charset.forName("UTF-8");48Charset utf_16be = Charset.forName("UTF-16BE");49Charset cp1252 = Charset.forName("CP1252");5051ck(us_ascii, us_ascii, true);52ck(us_ascii, iso_8859_1, false);53ck(us_ascii, iso_8859_15, false);54ck(us_ascii, utf_8, false);55ck(us_ascii, utf_16be, false);56ck(us_ascii, cp1252, false);5758ck(iso_8859_1, us_ascii, true);59ck(iso_8859_1, iso_8859_1, true);60ck(iso_8859_1, iso_8859_15, false);61ck(iso_8859_1, utf_8, false);62ck(iso_8859_1, utf_16be, false);63ck(iso_8859_1, cp1252, false);6465ck(iso_8859_15, us_ascii, true);66ck(iso_8859_15, iso_8859_1, false);67ck(iso_8859_15, iso_8859_15, true);68ck(iso_8859_15, utf_8, false);69ck(iso_8859_15, utf_16be, false);70ck(iso_8859_15, cp1252, false);7172ck(utf_8, us_ascii, true);73ck(utf_8, iso_8859_1, true);74ck(utf_8, iso_8859_15, true);75ck(utf_8, utf_8, true);76ck(utf_8, utf_16be, true);77ck(utf_8, cp1252, true);7879ck(utf_16be, us_ascii, true);80ck(utf_16be, iso_8859_1, true);81ck(utf_16be, iso_8859_15, true);82ck(utf_16be, utf_8, true);83ck(utf_16be, utf_16be, true);84ck(utf_16be, cp1252, true);8586ck(cp1252, us_ascii, true);87ck(cp1252, iso_8859_1, false);88ck(cp1252, iso_8859_15, false);89ck(cp1252, utf_8, false);90ck(cp1252, utf_16be, false);91ck(cp1252, cp1252, true);9293checkUTF();94}9596static void checkUTF() throws Exception {97for (String utfName : utfNames)98for (String csName : charsetNames)99ck(Charset.forName(utfName),100Charset.forName(csName),101true);102}103104static String[] utfNames = {"utf-16",105"utf-8",106"utf-16le",107"utf-16be",108"x-utf-16le-bom"};109110static String[] charsetNames = {111"US-ASCII",112"UTF-8",113"UTF-16",114"UTF-16BE",115"UTF-16LE",116"x-UTF-16LE-BOM",117"GBK",118"GB18030",119"ISO-8859-1",120"ISO-8859-15",121"ISO-8859-2",122"ISO-8859-3",123"ISO-8859-4",124"ISO-8859-5",125"ISO-8859-6",126"ISO-8859-7",127"ISO-8859-8",128"ISO-8859-9",129"ISO-8859-13",130"JIS_X0201",131"x-JIS0208",132"JIS_X0212-1990",133"GB2312",134"EUC-KR",135"x-EUC-TW",136"EUC-JP",137"x-euc-jp-linux",138"KOI8-R",139"TIS-620",140"x-ISCII91",141"windows-1251",142"windows-1252",143"windows-1253",144"windows-1254",145"windows-1255",146"windows-1256",147"windows-1257",148"windows-1258",149"windows-932",150"x-mswin-936",151"x-windows-949",152"x-windows-950",153"windows-31j",154"Big5",155"Big5-HKSCS",156"x-MS950-HKSCS",157"ISO-2022-JP",158"ISO-2022-KR",159"x-ISO-2022-CN-CNS",160"x-ISO-2022-CN-GB",161"Big5-HKSCS",162"x-Johab",163"Shift_JIS"164};165}166167168