Path: blob/master/test/jdk/sun/nio/cs/CheckCaseInsensitiveEncAliases.java
41149 views
/*1* Copyright (c) 2008, 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* @bug 4216191 4721369 480728325@summary Test to validate case insensitivity of encoding alias names26*/2728// Fixed since 1.4.0 by virtue of NIO charset lookup mechanism29// which is by design case insensitive3031import java.lang.*;32import java.io.*;3334public class CheckCaseInsensitiveEncAliases35{36public static void main(String args[]) throws Exception37{38// Try various encoding names in mixed cases39// Tests subset of encoding names provided within bugID 42161914041// Various forms of US-ASCII42tryToEncode( "ANSI_X3.4-1968" );43tryToEncode( "iso-ir-6" );44tryToEncode( "ANSI_X3.4-1986" );45tryToEncode( "ISO_646.irv:1991" );46tryToEncode( "ASCII" );47tryToEncode( "ascii" );48tryToEncode( "Ascii" );49tryToEncode( "Ascii7" );50tryToEncode( "ascii7" );51tryToEncode( "ISO646-US" );52tryToEncode( "US-ASCII" );53tryToEncode( "us-ascii" );54tryToEncode( "US-Ascii" );55tryToEncode( "us" );56tryToEncode( "IBM367" );57tryToEncode( "cp367" );58tryToEncode( "csASCII" );5960// Variants on Unicode61tryToEncode( "Unicode" );62tryToEncode( "UNICODE" );63tryToEncode( "unicode" );6465// Variants on Big566tryToEncode( "Big5" );67tryToEncode( "big5" );68tryToEncode( "bIg5" );69tryToEncode( "biG5" );70tryToEncode( "bIG5" );7172// Variants of Cp125273tryToEncode( "Cp1252" );74tryToEncode( "cp1252" );75tryToEncode( "CP1252" );7677// Variants of PCK78tryToEncode( "pck" );79tryToEncode( "Pck" );8081}828384public static final String ENCODE_STRING = "Encode me";8586public static void tryToEncode( String encoding) throws Exception87{88try89{90byte[] bytes = ENCODE_STRING.getBytes( encoding );91System.out.println( "Encoding \"" + encoding + "\" recognized" );92}93catch( UnsupportedEncodingException e )94{95throw new Exception("Encoding \"" + encoding + "\" NOT recognized");96}97}98}99100101