< prev index next >

test/jdk/sun/nio/cs/TestIBMBugs.java

Print this page


   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);


 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 }
   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 6371437 6371422 6371416 6371619 5058184 6371431 6639450 6569191 6577466 8212794 8220281 8235834
  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);


 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     private static void bug8235834 () throws Exception {
 327         byte[] byteIBM943c2b = new byte[] {
 328             (byte)0x81, (byte)0x5C, (byte)0x81, (byte)0x60,
 329             (byte)0x81, (byte)0x61, (byte)0x81, (byte)0x7C,
 330             (byte)0x88, (byte)0xA0, (byte)0x89, (byte)0x8B,
 331             (byte)0x89, (byte)0xA8, (byte)0x8A, (byte)0x9A,
 332             (byte)0x8B, (byte)0xA0, (byte)0x8B, (byte)0xEB,
 333             (byte)0x8C, (byte)0x71, (byte)0x8C, (byte)0x74,
 334             (byte)0x8C, (byte)0xB2, (byte)0x8D, (byte)0x8D,
 335             (byte)0x8D, (byte)0xF2, (byte)0x8E, (byte)0xC6,
 336             (byte)0x8F, (byte)0x4A, (byte)0x8F, (byte)0xD3,
 337             (byte)0x8F, (byte)0xDD, (byte)0x90, (byte)0xE4,
 338             (byte)0x91, (byte)0x7E, (byte)0x91, (byte)0x89,
 339             (byte)0x91, (byte)0xCB, (byte)0x92, (byte)0x5C,
 340             (byte)0x92, (byte)0xCD, (byte)0x93, (byte)0x55,
 341             (byte)0x93, (byte)0x5E, (byte)0x93, (byte)0x98,
 342             (byte)0x93, (byte)0xC0, (byte)0x94, (byte)0x58,
 343             (byte)0x94, (byte)0x8D, (byte)0x94, (byte)0xAC,
 344             (byte)0x94, (byte)0xAE, (byte)0x96, (byte)0x6A,
 345             (byte)0x96, (byte)0xCB, (byte)0x97, (byte)0x89,
 346             (byte)0x98, (byte)0x58, (byte)0x9B, (byte)0xA0,
 347             (byte)0x9D, (byte)0xB7, (byte)0x9E, (byte)0x94,
 348             (byte)0xE3, (byte)0x79, (byte)0xE4, (byte)0x45,
 349             (byte)0xE8, (byte)0xF6, (byte)0xFA, (byte)0x55,
 350             (byte)0xFA, (byte)0x59, 
 351         };
 352         String strIBM943c2b1 =
 353             "\u2015\uFF5E\u2225\uFF0D\u555E\u7130\u9DD7\u5699" +
 354             "\u4FE0\u8EC0\u7E6B\u8346\u9E7C\u9EB4\u6805\u5C62" +
 355             "\u7E61\u8523\u91AC\u87EC\u6414\u7626\u9A52\u7C1E" +
 356             "\u6451\u5861\u985A\u79B1\u7006\u56CA\u525D\u6F51" +
 357             "\u91B1\u9830\u9EB5\u840A\u881F\u5C5B\u6522\u688E" +
 358             "\u7E48\u8141\u9839\uFFE4\uF86F";
 359         String strIBM943c2b2 =
 360             "\u2014\u301C\u2016\u2212\u5516\u7114\u9D0E\u565B" +
 361             "\u4FA0\u8EAF\u7E4B\u834A\u9E78\u9EB9\u67F5\u5C61" +
 362             "\u7E4D\u848B\u91A4\u8749\u63BB\u75E9\u9A28\u7BAA" +
 363             "\u63B4\u586B\u985B\u7977\u6D9C\u56A2\u5265\u6E8C" +
 364             "\u9197\u982C\u9EBA\u83B1\u874B\u5C4F\u6505\u688D" +
 365             "\u7E66\u80FC\u983D\u00A6\u2116";
 366         Charset csIBM943 = Charset.forName("x-IBM943");
 367         if (!Arrays.equals(byteIBM943c2b, strIBM943c2b1.getBytes(csIBM943))) {
 368             throw new Exception(csIBM943.name()+" failed to encode");
 369         }
 370         if (!strIBM943c2b2.equals(new String(byteIBM943c2b, csIBM943))) {
 371             throw new Exception(csIBM943.name()+" failed to round-tip conversion");
 372         }
 373         Charset csIBM943C = Charset.forName("x-IBM943C");
 374         if (!Arrays.equals(byteIBM943c2b, strIBM943c2b1.getBytes(csIBM943C))) {
 375             throw new Exception(csIBM943C.name()+" failed to encode");
 376         }
 377         if (!strIBM943c2b2.equals(new String(byteIBM943c2b, csIBM943C))) {
 378             throw new Exception(csIBM943C.name()+" failed to round-tip conversion");
 379         }
 380     }
 381 
 382     public static void main (String[] args) throws Exception {
 383         bug6577466();
 384         // need to be tested before any other IBM949C test case
 385         bug6639450();
 386         bug6371437();
 387         bug6371422();
 388         bug6371416();
 389         bug6371619();
 390         bug6371431();
 391         bug6569191();
 392         bug8202329();
 393         bug8212794();
 394         bug8213618();
 395         bug8220281();
 396         bug8235834();
 397     }
 398 }
< prev index next >