2115N/A/*
2362N/A * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
2115N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2115N/A *
2115N/A * This code is free software; you can redistribute it and/or modify it
2115N/A * under the terms of the GNU General Public License version 2 only, as
2115N/A * published by the Free Software Foundation.
2115N/A *
2115N/A * This code is distributed in the hope that it will be useful, but WITHOUT
2115N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2115N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
2115N/A * version 2 for more details (a copy is included in the LICENSE file that
2115N/A * accompanied this code).
2115N/A *
2115N/A * You should have received a copy of the GNU General Public License version
2115N/A * 2 along with this work; if not, write to the Free Software Foundation,
2115N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2115N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
2115N/A */
2115N/A
2115N/A/* @test
2115N/A * @summary Unit test for charset containment
2115N/A * @bug 6798572
2115N/A */
2115N/A
2115N/Aimport java.nio.charset.*;
2115N/A
2115N/A
2115N/Apublic class Contains {
2115N/A
2115N/A static void ck(Charset cs1, Charset cs2, boolean cont) throws Exception {
2115N/A if ((cs1.contains(cs2)) != cont)
2115N/A throw new Exception("Wrong answer: "
2115N/A + cs1.name() + " contains " + cs2.name());
2115N/A System.err.println(cs1.name()
2115N/A + (cont ? " contains " : " does not contain ")
2115N/A + cs2.name());
2115N/A }
2115N/A
2115N/A public static void main(String[] args) throws Exception {
2115N/A
2115N/A Charset us_ascii = Charset.forName("US-ASCII");
2115N/A Charset iso_8859_1 = Charset.forName("ISO-8859-1");
2115N/A Charset iso_8859_15 = Charset.forName("ISO-8859-15");
2115N/A Charset utf_8 = Charset.forName("UTF-8");
2115N/A Charset utf_16be = Charset.forName("UTF-16BE");
2115N/A Charset cp1252 = Charset.forName("CP1252");
2115N/A
2115N/A ck(us_ascii, us_ascii, true);
2115N/A ck(us_ascii, iso_8859_1, false);
2115N/A ck(us_ascii, iso_8859_15, false);
2115N/A ck(us_ascii, utf_8, false);
2115N/A ck(us_ascii, utf_16be, false);
2115N/A ck(us_ascii, cp1252, false);
2115N/A
2115N/A ck(iso_8859_1, us_ascii, true);
2115N/A ck(iso_8859_1, iso_8859_1, true);
2115N/A ck(iso_8859_1, iso_8859_15, false);
2115N/A ck(iso_8859_1, utf_8, false);
2115N/A ck(iso_8859_1, utf_16be, false);
2115N/A ck(iso_8859_1, cp1252, false);
2115N/A
2115N/A ck(iso_8859_15, us_ascii, true);
2115N/A ck(iso_8859_15, iso_8859_1, false);
2115N/A ck(iso_8859_15, iso_8859_15, true);
2115N/A ck(iso_8859_15, utf_8, false);
2115N/A ck(iso_8859_15, utf_16be, false);
2115N/A ck(iso_8859_15, cp1252, false);
2115N/A
2115N/A ck(utf_8, us_ascii, true);
2115N/A ck(utf_8, iso_8859_1, true);
2115N/A ck(utf_8, iso_8859_15, true);
2115N/A ck(utf_8, utf_8, true);
2115N/A ck(utf_8, utf_16be, true);
2115N/A ck(utf_8, cp1252, true);
2115N/A
2115N/A ck(utf_16be, us_ascii, true);
2115N/A ck(utf_16be, iso_8859_1, true);
2115N/A ck(utf_16be, iso_8859_15, true);
2115N/A ck(utf_16be, utf_8, true);
2115N/A ck(utf_16be, utf_16be, true);
2115N/A ck(utf_16be, cp1252, true);
2115N/A
2115N/A ck(cp1252, us_ascii, true);
2115N/A ck(cp1252, iso_8859_1, false);
2115N/A ck(cp1252, iso_8859_15, false);
2115N/A ck(cp1252, utf_8, false);
2115N/A ck(cp1252, utf_16be, false);
2115N/A ck(cp1252, cp1252, true);
2115N/A
2115N/A checkUTF();
2115N/A }
2115N/A
2115N/A static void checkUTF() throws Exception {
2115N/A for (String utfName : utfNames)
2115N/A for (String csName : charsetNames)
2115N/A ck(Charset.forName(utfName),
2115N/A Charset.forName(csName),
2115N/A true);
2115N/A }
2115N/A
2115N/A static String[] utfNames = {"utf-16",
2115N/A "utf-8",
2115N/A "utf-16le",
2115N/A "utf-16be",
2115N/A "x-utf-16le-bom"};
2115N/A
2115N/A static String[] charsetNames = {
2115N/A "US-ASCII",
2115N/A "UTF-8",
2115N/A "UTF-16",
2115N/A "UTF-16BE",
2115N/A "UTF-16LE",
2115N/A "x-UTF-16LE-BOM",
2115N/A "GBK",
2115N/A "GB18030",
2115N/A "ISO-8859-1",
2115N/A "ISO-8859-15",
2115N/A "ISO-8859-2",
2115N/A "ISO-8859-3",
2115N/A "ISO-8859-4",
2115N/A "ISO-8859-5",
2115N/A "ISO-8859-6",
2115N/A "ISO-8859-7",
2115N/A "ISO-8859-8",
2115N/A "ISO-8859-9",
2115N/A "ISO-8859-13",
2115N/A "JIS_X0201",
2115N/A "x-JIS0208",
2115N/A "JIS_X0212-1990",
2115N/A "GB2312",
2115N/A "EUC-KR",
2115N/A "x-EUC-TW",
2115N/A "EUC-JP",
2115N/A "x-euc-jp-linux",
2115N/A "KOI8-R",
2115N/A "TIS-620",
2115N/A "x-ISCII91",
2115N/A "windows-1251",
2115N/A "windows-1252",
2115N/A "windows-1253",
2115N/A "windows-1254",
2115N/A "windows-1255",
2115N/A "windows-1256",
2115N/A "windows-1257",
2115N/A "windows-1258",
2115N/A "windows-932",
2115N/A "x-mswin-936",
2115N/A "x-windows-949",
2115N/A "x-windows-950",
2115N/A "windows-31j",
2115N/A "Big5",
2115N/A "Big5-HKSCS",
2115N/A "x-MS950-HKSCS",
2115N/A "ISO-2022-JP",
2115N/A "ISO-2022-KR",
2115N/A "x-ISO-2022-CN-CNS",
2115N/A "x-ISO-2022-CN-GB",
2115N/A "Big5-HKSCS",
2115N/A "x-Johab",
2115N/A "Shift_JIS"
2115N/A };
2115N/A}