< prev index next >

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

Print this page


   1 /*
   2  * Copyright (c) 2008, 2013, 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
  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     }


 204         }
 205 
 206 
 207         // Test IBM943C, where \ and ~ are encoded to 0x5c and 0x7e
 208         // and [yen] and [overscore] are encoded to 0x5c and 0x7e
 209         charset = Charset.forName("IBM943C");
 210         expectedBytes = new byte[] {0x5c, 0x7e, 0x5c, 0x7e};
 211         expectedStringfromBytes = "\\~\\~";
 212         bb = charset.encode(original);
 213         ba = new byte[bb.remaining()];
 214         bb.get(ba, 0, ba.length);
 215         if(!Arrays.equals(ba, expectedBytes)) {
 216             throw new Exception("IBM943C failed to encode");
 217         }
 218         cb = charset.decode(ByteBuffer.wrap(expectedBytes));
 219         if(!cb.toString().equals(expectedStringfromBytes)) {
 220             throw new Exception("IBM943C failed to decode");
 221         }
 222     }
 223 
















 224     public static void main (String[] args) throws Exception {
 225         bug6577466();
 226         // need to be tested before any other IBM949C test case
 227         bug6639450();
 228         bug6371437();
 229         bug6371422();
 230         bug6371416();
 231         bug6371619();
 232         bug6371431();
 233         bug6569191();
 234         bug8202329();

 235     }
 236 }
   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     }


 204         }
 205 
 206 
 207         // Test IBM943C, where \ and ~ are encoded to 0x5c and 0x7e
 208         // and [yen] and [overscore] are encoded to 0x5c and 0x7e
 209         charset = Charset.forName("IBM943C");
 210         expectedBytes = new byte[] {0x5c, 0x7e, 0x5c, 0x7e};
 211         expectedStringfromBytes = "\\~\\~";
 212         bb = charset.encode(original);
 213         ba = new byte[bb.remaining()];
 214         bb.get(ba, 0, ba.length);
 215         if(!Arrays.equals(ba, expectedBytes)) {
 216             throw new Exception("IBM943C failed to encode");
 217         }
 218         cb = charset.decode(ByteBuffer.wrap(expectedBytes));
 219         if(!cb.toString().equals(expectedStringfromBytes)) {
 220             throw new Exception("IBM943C failed to decode");
 221         }
 222     }
 223 
 224     private static void bug8212794 () throws Exception {
 225         Charset cs = Charset.forName("x-IBM964");
 226         byte[] ba = new byte[]{(byte)0x5c, (byte)0x90, (byte)0xa1, (byte)0xa1};
 227         char[] ca = new char[]{'\\', '\u0090', '\u3000'};
 228         ByteBuffer bb = ByteBuffer.wrap(ba);
 229         CharBuffer cb = cs.decode(bb);
 230         if(!Arrays.equals(ca, Arrays.copyOf(cb.array(), cb.limit()))) {
 231             throw new Exception("IBM964 failed to decode");
 232         }
 233         cb = CharBuffer.wrap(ca);
 234         bb = cs.encode(cb);
 235         if(!Arrays.equals(ba, Arrays.copyOf(bb.array(), bb.limit()))) {
 236             throw new Exception("IBM964 failed to encode");
 237         }
 238     }
 239 
 240     public static void main (String[] args) throws Exception {
 241         bug6577466();
 242         // need to be tested before any other IBM949C test case
 243         bug6639450();
 244         bug6371437();
 245         bug6371422();
 246         bug6371416();
 247         bug6371619();
 248         bug6371431();
 249         bug6569191();
 250         bug8202329();
 251         bug8212794();
 252     }
 253 }
< prev index next >