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 }