< prev index next >

test/jdk/java/lang/Character/CheckUnicode.java

Print this page
rev 54996 : 8221431: Support for Unicode 12.1
Reviewed-by:
   1 /*
   2  * Copyright (c) 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.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 /**
  27  * @test
  28  * @bug      4114080 6565620 6959267 7070436 7198195 8032446 8072600
  29  * @summary  Make sure the attributes of Unicode characters, as
  30  * returned by the Character API, are as expected.  Do this by
  31  * comparing them to a baseline file together with a list of
  32  * known diffs.

  33  * @build UnicodeSpec CharCheck
  34  * @run main CheckUnicode
  35  * @author Alan Liu
  36  * @author John O'Conner
  37  */
  38 
  39 import java.io.*;
  40 
  41 public class CheckUnicode {
  42     public static void main(String args[]) throws Exception {
  43 
  44         // 1. Check that the dumped property files for planes 0, 1, 2, 3, 14, 15, and 16
  45         //    are the  same as in the current Character properties.
  46                 int[] planes = {0, 1, 2, 3, 14, 15, 16};
  47                 String[] fileNames = {"charprop00.bin", "charprop01.bin", "charprop02.bin", "charprop03.bin",
  48                                         "charprop0E.bin", "charprop0F.bin", "charprop10.bin" };
  49 
  50         // Read in the Unicode 4.0 data
  51 
  52                 for (int x=0; x < planes.length && x < fileNames.length; ++x) {
  53                 File unicodeProp = new File(System.getProperty("test.src", "."), fileNames[x]);
  54                 ObjectInputStream ois = new ObjectInputStream(new FileInputStream(unicodeProp));
  55                 // Find differences -- should be none
  56                 int diffs = CharCheck.load(planes[x], ois);
  57                 if (diffs != 0) {
  58                     throw new RuntimeException("Bug 4114080 - Unicode properties have changed " +
  59                                        "in an unexpected way");
  60             }
  61                 }
  62 
  63 
  64 
  65 
  66         // 2. Check that the current 4.0 spec file is handled by the current
  67         // version of Character.
  68         File unicodeSpec = new File(System.getProperty("test.src", "."), "UnicodeData.txt");
  69                 for (int x=0; x<planes.length; ++x) {
  70                 int diffs = CharCheck.check(planes[x], unicodeSpec);
  71                 if (diffs != 0) {
  72                     throw new RuntimeException("Bug 4114080 - Unicode properties have changed " +
  73                                                "in an unexpected way");
  74                 }
  75                 }
  76 
  77         // 3. Check that Java identifiers are recognized correctly.
  78         // test a few characters that are good id starts
  79         char[] idStartChar = {'$', '\u20AC', 'a', 'A', 'z', 'Z', '_', '\u0E3F',
  80             '\u1004', '\u10A0', '\u3400', '\u4E00', '\uAC00' };
  81         for (int x = 0; x < idStartChar.length; x++) {
  82             if (Character.isJavaIdentifierStart(idStartChar[x]) != true) {
  83                 throw new RuntimeException("Java id start characters are not recognized.");
  84             }
  85         }
  86 
  87         // test a few characters that are good id parts
  88         char[] idPartChar = {'0', '9', '\u0000', '\u0008', '\u000E', '\u007F'};
  89         for (int x=0; x< idStartChar.length; x++) {
  90             if (Character.isJavaIdentifierPart(idStartChar[x]) != true) {
  91                 throw new RuntimeException("Java id part characters are not recognized.");
  92             }
  93         }
  94         for (int x=0; x<idPartChar.length; x++) {
  95             if (Character.isJavaIdentifierPart(idPartChar[x]) != true) {
  96                 throw new RuntimeException("Java id part characters are not recognized.");
  97             }
  98         }
  99 
 100         // now do some negative checks
 101         for (int x=0; x< idPartChar.length; x++) {
 102             if (Character.isJavaIdentifierStart(idPartChar[x]) != false) {
 103                 throw new RuntimeException("These Java id part characters" +
 104                     "should not be start characters.");
 105             }
 106         }
 107 
 108 
 109 
 110     }
 111 }
   1 /*
   2  * Copyright (c) 2018, 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.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 /**
  27  * @test
  28  * @bug      4114080 6565620 6959267 7070436 7198195 8032446 8072600 8221431
  29  * @summary  Make sure the attributes of Unicode characters, as
  30  * returned by the Character API, are as expected.  Do this by
  31  * comparing them to a baseline file together with a list of
  32  * known diffs.
  33  * @library /lib/testlibrary/java/lang
  34  * @build UnicodeSpec CharCheck
  35  * @run main CheckUnicode
  36  * @author Alan Liu
  37  * @author John O'Conner
  38  */
  39 
  40 import java.io.*;
  41 
  42 public class CheckUnicode {
  43     public static void main(String args[]) throws Exception {
  44 
  45         // 1. Check that the current 12.1 spec file is handled by the current






















  46         // version of Character.
  47         File unicodeSpec = UCDFiles.UNICODE_DATA.toFile();
  48         for (int x = 0; x < 16; ++x) {
  49             int diffs = CharCheck.check(x, unicodeSpec);
  50             if (diffs != 0) {
  51                 throw new RuntimeException("Unicode properties have changed " +
  52                                            "in an unexpected way");
  53             }
  54         }
  55 
  56         // 2. Check that Java identifiers are recognized correctly.
  57         // test a few characters that are good id starts
  58         char[] idStartChar = {'$', '\u20AC', 'a', 'A', 'z', 'Z', '_', '\u0E3F',
  59             '\u1004', '\u10A0', '\u3400', '\u4E00', '\uAC00' };
  60         for (int x = 0; x < idStartChar.length; x++) {
  61             if (Character.isJavaIdentifierStart(idStartChar[x]) != true) {
  62                 throw new RuntimeException("Java id start characters are not recognized.");
  63             }
  64         }
  65 
  66         // test a few characters that are good id parts
  67         char[] idPartChar = {'0', '9', '\u0000', '\u0008', '\u000E', '\u007F'};
  68         for (int x=0; x< idStartChar.length; x++) {
  69             if (Character.isJavaIdentifierPart(idStartChar[x]) != true) {
  70                 throw new RuntimeException("Java id part characters are not recognized.");
  71             }
  72         }
  73         for (int x=0; x<idPartChar.length; x++) {
  74             if (Character.isJavaIdentifierPart(idPartChar[x]) != true) {
  75                 throw new RuntimeException("Java id part characters are not recognized.");
  76             }
  77         }
  78 
  79         // now do some negative checks
  80         for (int x=0; x< idPartChar.length; x++) {
  81             if (Character.isJavaIdentifierStart(idPartChar[x]) != false) {
  82                 throw new RuntimeException("These Java id part characters" +
  83                     "should not be start characters.");
  84             }
  85         }



  86     }
  87 }
< prev index next >