< prev index next >

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

Print this page


   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 8042125
  26  * @summary Check full coverage encode/decode for ISO-2022-JP
  27  * @modules jdk.charsets
  28  */
  29 
  30 /*
  31  * Tests the NIO converter for J2RE >= 1.4.1
  32  * since the default converter used by String
  33  * API is the NIO converter sun.nio.cs.ext.ISO2022_JP
  34  */
  35 
  36 import java.io.*;
  37 import java.util.Arrays;
  38 
  39 public class TestISO2022JP {
  40 
  41     private final static String US_ASCII =
  42         "\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007" +
  43         "\b\t\n\u000B\f\r" +
  44         "\u0010\u0011\u0012\u0013\u0014\u0015\u0016\u0017" +
  45         "\u0018\u0019\u001A\u001C\u001D\u001E\u001F" +


 629                throw new Exception("MSISO2022JP Encoder error");
 630         }
 631         // Test for 10 non-roundtrip characters in ms932 iso2022jp
 632         encoded = new byte[] {
 633             (byte)0x1B, (byte)0x24, (byte)0x42,
 634             (byte)0x22, (byte)0x4C,
 635             (byte)0x22, (byte)0x5D,
 636             (byte)0x22, (byte)0x65,
 637             (byte)0x22, (byte)0x69,
 638             (byte)0x2D, (byte)0x70,
 639             (byte)0x2D, (byte)0x71,
 640             (byte)0x2D, (byte)0x77,
 641             (byte)0x2D, (byte)0x7A,
 642             (byte)0x2D, (byte)0x7B,
 643             (byte)0x2D, (byte)0x7C,
 644             (byte)0x1B, (byte)0x28, (byte)0x42,
 645         };
 646         String expectedStr = "\uffe2\u22a5\u221a\u222b\u2252\u2261\u2220\u2235\u2229\u222a";
 647         if (!new String(encoded, "x-windows-iso2022jp").equals(expectedStr)) {
 648                throw new Exception("MSISO2022JP Decoder error");












 649         }
 650     }
 651 }
   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 8042125 8211382
  26  * @summary Check full coverage encode/decode for ISO-2022-JP
  27  * @modules jdk.charsets
  28  */
  29 
  30 /*
  31  * Tests the NIO converter for J2RE >= 1.4.1
  32  * since the default converter used by String
  33  * API is the NIO converter sun.nio.cs.ext.ISO2022_JP
  34  */
  35 
  36 import java.io.*;
  37 import java.util.Arrays;
  38 
  39 public class TestISO2022JP {
  40 
  41     private final static String US_ASCII =
  42         "\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007" +
  43         "\b\t\n\u000B\f\r" +
  44         "\u0010\u0011\u0012\u0013\u0014\u0015\u0016\u0017" +
  45         "\u0018\u0019\u001A\u001C\u001D\u001E\u001F" +


 629                throw new Exception("MSISO2022JP Encoder error");
 630         }
 631         // Test for 10 non-roundtrip characters in ms932 iso2022jp
 632         encoded = new byte[] {
 633             (byte)0x1B, (byte)0x24, (byte)0x42,
 634             (byte)0x22, (byte)0x4C,
 635             (byte)0x22, (byte)0x5D,
 636             (byte)0x22, (byte)0x65,
 637             (byte)0x22, (byte)0x69,
 638             (byte)0x2D, (byte)0x70,
 639             (byte)0x2D, (byte)0x71,
 640             (byte)0x2D, (byte)0x77,
 641             (byte)0x2D, (byte)0x7A,
 642             (byte)0x2D, (byte)0x7B,
 643             (byte)0x2D, (byte)0x7C,
 644             (byte)0x1B, (byte)0x28, (byte)0x42,
 645         };
 646         String expectedStr = "\uffe2\u22a5\u221a\u222b\u2252\u2261\u2220\u2235\u2229\u222a";
 647         if (!new String(encoded, "x-windows-iso2022jp").equals(expectedStr)) {
 648                throw new Exception("MSISO2022JP Decoder error");
 649         }
 650         // Test for 11 iso2022jp decoder
 651         encoded = new byte[] {
 652             (byte)0x1B, (byte)0x28, (byte)0x49, (byte)0x60,
 653             (byte)0x1B, (byte)0x28, (byte)0x42,
 654         };
 655         String unexpectedStr = "\uffa0";
 656         expectedStr = "\ufffd";
 657         if (new String(encoded, "ISO2022JP").equals(unexpectedStr)) {
 658                throw new Exception("ISO2022JP Decoder error: \\uFFA0");
 659         } else if (!new String(encoded, "ISO2022JP").equals(expectedStr)) {
 660                throw new Exception("ISO2022JP Decoder error: \\uFFFD");
 661         }
 662     }
 663 }
< prev index next >