< prev index next >

test/sun/nio/cs/TestISO2022JP.java

Print this page
rev 13451 : 8211382: ISO2022JP and GB18030 NIO converter issues
Reviewed-by: sherman, rriggs
   1 /*
   2  * Copyright (c) 2008, 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 4626545 4879522 4913711 4119445
  26    @summary Check full coverage encode/decode for ISO-2022-JP
  27  */
  28 
  29 /*
  30  * Tests the NIO converter for J2RE >= 1.4.1
  31  * since the default converter used by String
  32  * API is the NIO converter sun.nio.cs.ext.ISO2022_JP
  33  */
  34 
  35 import java.io.*;
  36 public class TestISO2022JP {
  37 
  38     private final static String US_ASCII =
  39         "\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007" +
  40         "\b\t\n\u000B\f\r" +
  41         "\u0010\u0011\u0012\u0013\u0014\u0015\u0016\u0017" +
  42         "\u0018\u0019\u001A\u001C\u001D\u001E\u001F" +
  43         "\u0020\u0021\"\u0023\u0024\u0025\u0026\'" +
  44         "\u0028\u0029\u002A\u002B\u002C\u002D\u002E\u002F" +
  45         "\u0030\u0031\u0032\u0033\u0034\u0035\u0036\u0037" +


 590         decoded2 = new String(repeatingEscapes, "ISO-2022-JP-2");
 591         if (!decoded2.equals(MIXEDCONTENT)) {
 592             throw new Exception("ISO-2022-JP-2 Decoder error");
 593         }
 594 
 595         // Test for bugID 4913711
 596         // ISO-2022-JP encoding of a single input char yields
 597         // 8 output bytes. Prior to fix for 4913711 the
 598         // max bytes per char value was underspecified as 5.0
 599         // and the code below would have thrown a BufferOverflow
 600         // exception. This test validates the fix for 4913711
 601 
 602         String testStr3 = "\u3042";
 603         byte[] expected = { (byte)0x1b, (byte)0x24, (byte)0x42,
 604                             (byte)0x24, (byte)0x22, (byte)0x1b,
 605                             (byte)0x28, (byte)0x42 };
 606         byte[] encoded = testStr3.getBytes("ISO-2022-JP");
 607         for (int i = 0; i < expected.length; i++) {
 608             if (encoded[i] != expected[i])
 609                throw new Exception("ISO-2022-JP Decoder error");













 610         }
 611     }
 612 }
   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 4626545 4879522 4913711 4119445 8211382
  26    @summary Check full coverage encode/decode for ISO-2022-JP
  27  */
  28 
  29 /*
  30  * Tests the NIO converter for J2RE >= 1.4.1
  31  * since the default converter used by String
  32  * API is the NIO converter sun.nio.cs.ext.ISO2022_JP
  33  */
  34 
  35 import java.io.*;
  36 public class TestISO2022JP {
  37 
  38     private final static String US_ASCII =
  39         "\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007" +
  40         "\b\t\n\u000B\f\r" +
  41         "\u0010\u0011\u0012\u0013\u0014\u0015\u0016\u0017" +
  42         "\u0018\u0019\u001A\u001C\u001D\u001E\u001F" +
  43         "\u0020\u0021\"\u0023\u0024\u0025\u0026\'" +
  44         "\u0028\u0029\u002A\u002B\u002C\u002D\u002E\u002F" +
  45         "\u0030\u0031\u0032\u0033\u0034\u0035\u0036\u0037" +


 590         decoded2 = new String(repeatingEscapes, "ISO-2022-JP-2");
 591         if (!decoded2.equals(MIXEDCONTENT)) {
 592             throw new Exception("ISO-2022-JP-2 Decoder error");
 593         }
 594 
 595         // Test for bugID 4913711
 596         // ISO-2022-JP encoding of a single input char yields
 597         // 8 output bytes. Prior to fix for 4913711 the
 598         // max bytes per char value was underspecified as 5.0
 599         // and the code below would have thrown a BufferOverflow
 600         // exception. This test validates the fix for 4913711
 601 
 602         String testStr3 = "\u3042";
 603         byte[] expected = { (byte)0x1b, (byte)0x24, (byte)0x42,
 604                             (byte)0x24, (byte)0x22, (byte)0x1b,
 605                             (byte)0x28, (byte)0x42 };
 606         byte[] encoded = testStr3.getBytes("ISO-2022-JP");
 607         for (int i = 0; i < expected.length; i++) {
 608             if (encoded[i] != expected[i])
 609                throw new Exception("ISO-2022-JP Decoder error");
 610         }
 611 
 612         // Test for 11 iso2022jp decoder
 613         encoded = new byte[] {
 614             (byte)0x1B, (byte)0x28, (byte)0x49, (byte)0x60,
 615             (byte)0x1B, (byte)0x28, (byte)0x42,
 616         };
 617         String unexpectedStr = "\uffa0";
 618         String expectedStr = "\ufffd";
 619         if (new String(encoded, "ISO2022JP").equals(unexpectedStr)) {
 620                throw new Exception("ISO2022JP Decoder error: \\uFFA0");
 621         } else if (!new String(encoded, "ISO2022JP").equals(expectedStr)) {
 622                throw new Exception("ISO2022JP Decoder error: \\uFFFD");
 623         }
 624     }
 625 }
< prev index next >