1 /* 2 * Copyright (c) 2008, 2018, 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 6371437 6371422 6371416 6371619 5058184 6371431 6639450 6569191 6577466 8212794 26 * @summary Check if the problems reported in above bugs have been fixed 27 * @modules jdk.charsets 28 */ 29 30 import java.io.*; 31 import java.nio.*; 32 import java.nio.charset.*; 33 import java.util.Arrays; 34 35 public class TestIBMBugs { 36 37 private static void bug6371437() throws Exception { 38 CharsetEncoder converter = Charset.forName("Cp933").newEncoder(); 39 converter = converter.onMalformedInput(CodingErrorAction.REPORT); 40 converter = converter.onUnmappableCharacter(CodingErrorAction.REPORT); 41 CharBuffer in = CharBuffer.wrap(new char[] { (char)4352 }); 42 try { 43 ByteBuffer out = converter.encode(in); 44 } catch (CharacterCodingException e) { } 45 } 46 47 private static void bug6371422() throws Exception { 48 String[] charsets = { "Cp949", "Cp949C" }; 49 for (int n = 0; n < charsets.length; n++) { 50 String charset = charsets[n]; 51 CharsetEncoder converter = Charset.forName(charset).newEncoder(); 52 converter = converter.onMalformedInput(CodingErrorAction.REPORT); 53 converter = converter.onUnmappableCharacter(CodingErrorAction.REPORT); 233 throw new Exception("IBM943C failed to decode"); 234 } 235 } 236 237 private static void bug8212794 () throws Exception { 238 Charset cs = Charset.forName("x-IBM964"); 239 byte[] ba = new byte[] {(byte)0x5c, (byte)0x90, (byte)0xa1, (byte)0xa1}; 240 char[] ca = new char[] {'\\', '\u0090', '\u3000'}; 241 ByteBuffer bb = ByteBuffer.wrap(ba); 242 CharBuffer cb = cs.decode(bb); 243 if(!Arrays.equals(ca, Arrays.copyOf(cb.array(), cb.limit()))) { 244 throw new Exception("IBM964 failed to decode"); 245 } 246 cb = CharBuffer.wrap(ca); 247 bb = cs.encode(cb); 248 if(!Arrays.equals(ba, Arrays.copyOf(bb.array(), bb.limit()))) { 249 throw new Exception("IBM964 failed to encode"); 250 } 251 } 252 253 public static void main (String[] args) throws Exception { 254 bug6577466(); 255 // need to be tested before any other IBM949C test case 256 bug6639450(); 257 bug6371437(); 258 bug6371422(); 259 bug6371416(); 260 bug6371619(); 261 bug6371431(); 262 bug6569191(); 263 bug8202329(); 264 bug8212794(); 265 bug8213618(); 266 } 267 } | 1 /* 2 * Copyright (c) 2008, 2019, 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 6371437 6371422 6371416 6371619 5058184 6371431 6639450 6569191 6577466 8212794 8220281 26 * @summary Check if the problems reported in above bugs have been fixed 27 * @modules jdk.charsets 28 */ 29 30 import java.io.*; 31 import java.nio.*; 32 import java.nio.charset.*; 33 import java.util.Arrays; 34 import java.util.Locale; 35 import java.util.HashSet; 36 37 public class TestIBMBugs { 38 39 private static void bug6371437() throws Exception { 40 CharsetEncoder converter = Charset.forName("Cp933").newEncoder(); 41 converter = converter.onMalformedInput(CodingErrorAction.REPORT); 42 converter = converter.onUnmappableCharacter(CodingErrorAction.REPORT); 43 CharBuffer in = CharBuffer.wrap(new char[] { (char)4352 }); 44 try { 45 ByteBuffer out = converter.encode(in); 46 } catch (CharacterCodingException e) { } 47 } 48 49 private static void bug6371422() throws Exception { 50 String[] charsets = { "Cp949", "Cp949C" }; 51 for (int n = 0; n < charsets.length; n++) { 52 String charset = charsets[n]; 53 CharsetEncoder converter = Charset.forName(charset).newEncoder(); 54 converter = converter.onMalformedInput(CodingErrorAction.REPORT); 55 converter = converter.onUnmappableCharacter(CodingErrorAction.REPORT); 235 throw new Exception("IBM943C failed to decode"); 236 } 237 } 238 239 private static void bug8212794 () throws Exception { 240 Charset cs = Charset.forName("x-IBM964"); 241 byte[] ba = new byte[] {(byte)0x5c, (byte)0x90, (byte)0xa1, (byte)0xa1}; 242 char[] ca = new char[] {'\\', '\u0090', '\u3000'}; 243 ByteBuffer bb = ByteBuffer.wrap(ba); 244 CharBuffer cb = cs.decode(bb); 245 if(!Arrays.equals(ca, Arrays.copyOf(cb.array(), cb.limit()))) { 246 throw new Exception("IBM964 failed to decode"); 247 } 248 cb = CharBuffer.wrap(ca); 249 bb = cs.encode(cb); 250 if(!Arrays.equals(ba, Arrays.copyOf(bb.array(), bb.limit()))) { 251 throw new Exception("IBM964 failed to encode"); 252 } 253 } 254 255 private static void bug8220281 () throws Exception { 256 if (System.getProperty("os.name").contains("AIX")) { 257 /* Following AIX codesets are used for Java default charset. */ 258 /* They should be in sun.nio.cs package on AIX platform. */ 259 String[] codesets = new String[] { 260 "IBM-950", "BIG5-HKSCS", "GB18030", "IBM-1046", 261 "IBM-1124", "IBM-1129", "IBM-1252", "IBM-856", 262 "IBM-858", "IBM-921", "IBM-922", "IBM-932", "IBM-943C", 263 "IBM-eucCN", "IBM-eucJP", "IBM-eucKR", "IBM-eucTW", 264 "ISO8859-1", "ISO8859-15", "ISO8859-2", "ISO8859-4", 265 "ISO8859-5", "ISO8859-6", "ISO8859-7", "ISO8859-8", 266 "ISO8859-9", "TIS-620", "UTF-8", }; 267 String[] charsets = new String[] { 268 "x-IBM950", "Big5-HKSCS", "GB18030", "x-IBM1046", 269 "x-IBM1124", "x-IBM1129", "windows-1252", "x-IBM856", 270 "IBM00858", "x-IBM921", "x-IBM922", "x-IBM942C", 271 "x-IBM943C", "x-IBM1383", "x-IBM29626C", "x-IBM970", 272 "x-IBM964", "ISO-8859-1", "ISO-8859-15", "ISO-8859-2", 273 "ISO-8859-4", "ISO-8859-5", "ISO-8859-6", "ISO-8859-7", 274 "ISO-8859-8", "ISO-8859-9", "TIS-620", "UTF-8", }; 275 for(int i = 0; i < codesets.length; i++) { 276 Charset cs0 = Charset.forName(codesets[i]); 277 if (!"sun.nio.cs".equals(cs0.getClass().getPackage().getName())) { 278 throw new Exception(cs0.getClass().getCanonicalName()+" faild"); 279 } 280 Charset cs1 = Charset.forName(charsets[i]); 281 if (!cs0.equals(cs1)) { 282 throw new Exception(codesets[i]+"("+cs0.name()+") failed"); 283 } 284 } 285 } 286 for(Charset cs : Charset.availableCharsets().values()) { 287 String csName = cs.name().toLowerCase(Locale.ENGLISH); 288 String suffix = null; 289 HashSet<String> aliases = new HashSet<String>(); 290 for(String s : cs.aliases()) { 291 aliases.add(s.toLowerCase(Locale.ENGLISH)); 292 } 293 aliases.add(csName); 294 if (csName.startsWith("x-ibm-")) { 295 suffix = csName.replaceAll("x-ibm-0*", ""); 296 } else if (csName.startsWith("x-ibm")) { 297 suffix = csName.replaceAll("x-ibm0*", ""); 298 } else if (csName.startsWith("ibm-")) { 299 suffix = csName.replaceAll("ibm-0*", ""); 300 } else if (csName.startsWith("ibm")) { 301 suffix = csName.replaceAll("ibm0*", ""); 302 } 303 if ("ibm-thai".equals(csName)) { 304 suffix = "838"; 305 } 306 if (null != suffix) { 307 while (suffix.length() < 3) { 308 suffix = "0"+suffix; 309 } 310 if (!aliases.contains("cp"+suffix)) { 311 throw new Exception(cs.name()+"\t"+"cp"+suffix); 312 } 313 if (!aliases.contains("ibm"+suffix)) { 314 throw new Exception(cs.name()+"\t"+"ibm"+suffix); 315 } 316 if (!aliases.contains("ibm-"+suffix)) { 317 throw new Exception(cs.name()+"\t"+"ibm-"+suffix); 318 } 319 if (!aliases.contains(suffix)) { 320 throw new Exception(cs.name()+"\t"+suffix); 321 } 322 } 323 } 324 } 325 326 public static void main (String[] args) throws Exception { 327 bug6577466(); 328 // need to be tested before any other IBM949C test case 329 bug6639450(); 330 bug6371437(); 331 bug6371422(); 332 bug6371416(); 333 bug6371619(); 334 bug6371431(); 335 bug6569191(); 336 bug8202329(); 337 bug8212794(); 338 bug8213618(); 339 bug8220281(); 340 } 341 } |