1 /* 2 * Copyright (c) 2008, 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 * @bug 4513767 4961027 6217210 26 * @summary Checks canonical names match between old and (NIO) core charsets 27 * @modules jdk.charsets 28 */ 29 import java.io.InputStreamReader; 30 import java.io.IOException; 31 32 public class CheckHistoricalNames { 33 static int failed = 0; 34 public static void main (String[] args) throws Exception { 35 checkHistoricalName("ASCII"); 36 checkHistoricalName("Cp1252"); 37 checkHistoricalName("ISO8859_1"); 38 checkHistoricalName("UnicodeBigUnmarked"); 39 checkHistoricalName("UnicodeLittle"); 40 checkHistoricalName("UnicodeLittleUnmarked"); 41 checkHistoricalName("UTF8"); 42 checkHistoricalName("UTF-16"); 43 44 checkMappedName("UnicodeBig", "UTF-16"); 45 checkMappedName("US-ASCII", "ASCII"); 46 checkMappedName("ISO-8859-1", "ISO8859_1"); 47 checkMappedName("UTF-8", "UTF8"); 48 checkMappedName("UTF-16BE", "UnicodeBigUnmarked"); 49 checkMappedName("UTF-16LE", "UnicodeLittleUnmarked"); 50 277 checkHistoricalName("MacRomania"); 278 checkHistoricalName("MacSymbol"); 279 checkHistoricalName("MacThai"); 280 checkHistoricalName("MacTurkish"); 281 checkHistoricalName("MacUkraine"); 282 283 checkMappedName("x-MacArabic", "MacArabic"); 284 checkMappedName("x-MacCentralEurope", "MacCentralEurope"); 285 checkMappedName("x-MacCroatian", "MacCroatian"); 286 checkMappedName("x-MacCyrillic", "MacCyrillic"); 287 checkMappedName("x-MacDingbat", "MacDingbat"); 288 checkMappedName("x-MacGreek", "MacGreek"); 289 checkMappedName("x-MacHebrew", "MacHebrew"); 290 checkMappedName("x-MacIceland", "MacIceland"); 291 checkMappedName("x-MacRoman", "MacRoman"); 292 checkMappedName("x-MacRomania", "MacRomania"); 293 checkMappedName("x-MacSymbol", "MacSymbol"); 294 checkMappedName("x-MacThai", "MacThai"); 295 checkMappedName("x-MacTurkish", "MacTurkish"); 296 checkMappedName("x-MacUkraine", "MacUkraine"); 297 298 if (failed != 0) 299 throw new Exception("Test Failed: " + failed); 300 else 301 System.out.println("Test Passed!"); 302 } 303 304 private static void checkHistoricalName(String name) throws Exception { 305 checkMappedName(name, name); 306 } 307 308 private static void checkMappedName(String alias, String canonical) 309 throws Exception { 310 InputStreamReader reader = new InputStreamReader(System.in, alias); 311 if (!reader.getEncoding().equals(canonical)) { 312 System.out.println("Failed canonical names : mismatch for " + alias 313 + " - expected " + canonical 314 + ", got " + reader.getEncoding()); 315 failed++; 316 } 317 } 318 } | 1 /* 2 * Copyright (c) 2008, 2020, 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 * @bug 4513767 4961027 6217210 8242541 26 * @summary Checks canonical names match between old and (NIO) core charsets 27 * @modules jdk.charsets 28 */ 29 import java.io.InputStreamReader; 30 import java.io.IOException; 31 import java.nio.charset.Charset; 32 import java.nio.charset.UnsupportedCharsetException; 33 34 public class CheckHistoricalNames { 35 static int failed = 0; 36 public static void main (String[] args) throws Exception { 37 checkHistoricalName("ASCII"); 38 checkHistoricalName("Cp1252"); 39 checkHistoricalName("ISO8859_1"); 40 checkHistoricalName("UnicodeBigUnmarked"); 41 checkHistoricalName("UnicodeLittle"); 42 checkHistoricalName("UnicodeLittleUnmarked"); 43 checkHistoricalName("UTF8"); 44 checkHistoricalName("UTF-16"); 45 46 checkMappedName("UnicodeBig", "UTF-16"); 47 checkMappedName("US-ASCII", "ASCII"); 48 checkMappedName("ISO-8859-1", "ISO8859_1"); 49 checkMappedName("UTF-8", "UTF8"); 50 checkMappedName("UTF-16BE", "UnicodeBigUnmarked"); 51 checkMappedName("UTF-16LE", "UnicodeLittleUnmarked"); 52 279 checkHistoricalName("MacRomania"); 280 checkHistoricalName("MacSymbol"); 281 checkHistoricalName("MacThai"); 282 checkHistoricalName("MacTurkish"); 283 checkHistoricalName("MacUkraine"); 284 285 checkMappedName("x-MacArabic", "MacArabic"); 286 checkMappedName("x-MacCentralEurope", "MacCentralEurope"); 287 checkMappedName("x-MacCroatian", "MacCroatian"); 288 checkMappedName("x-MacCyrillic", "MacCyrillic"); 289 checkMappedName("x-MacDingbat", "MacDingbat"); 290 checkMappedName("x-MacGreek", "MacGreek"); 291 checkMappedName("x-MacHebrew", "MacHebrew"); 292 checkMappedName("x-MacIceland", "MacIceland"); 293 checkMappedName("x-MacRoman", "MacRoman"); 294 checkMappedName("x-MacRomania", "MacRomania"); 295 checkMappedName("x-MacSymbol", "MacSymbol"); 296 checkMappedName("x-MacThai", "MacThai"); 297 checkMappedName("x-MacTurkish", "MacTurkish"); 298 checkMappedName("x-MacUkraine", "MacUkraine"); 299 checkCharsetAndHistoricalName(); 300 301 if (failed != 0) 302 throw new Exception("Test Failed: " + failed); 303 else 304 System.out.println("Test Passed!"); 305 } 306 307 private static void checkHistoricalName(String name) throws Exception { 308 checkMappedName(name, name); 309 } 310 311 private static void checkMappedName(String alias, String canonical) 312 throws Exception { 313 InputStreamReader reader = new InputStreamReader(System.in, alias); 314 if (!reader.getEncoding().equals(canonical)) { 315 System.out.println("Failed canonical names : mismatch for " + alias 316 + " - expected " + canonical 317 + ", got " + reader.getEncoding()); 318 failed++; 319 } 320 } 321 322 private static void checkCharsetAndHistoricalName() { 323 for (Charset cs : Charset.availableCharsets().values()) { 324 InputStreamReader isr = new InputStreamReader(System.in, cs); 325 String encoding = isr.getEncoding(); 326 try { 327 Charset csHist = Charset.forName(encoding); 328 if (!cs.equals(csHist)) { 329 System.out.println("Failed charset name" 330 + " - expected " + cs.name() 331 + ", got " + csHist.name()); 332 failed++; 333 } 334 } catch (UnsupportedCharsetException uce) { 335 System.out.println("Failed : charset - "+ cs.name() 336 + ", missing alias entry - " + encoding); 337 failed++; 338 } 339 } 340 } 341 } |