jdk/test/java/lang/Character/CheckProp.java
author jbachorik
Tue, 21 Jan 2014 13:04:55 +0100
changeset 22353 d09e3ff5fd63
parent 14411 65913e68c0a6
child 31680 88c53c2293b4
permissions -rw-r--r--
8032377: test/java/lang/management/ThreadMXBean/ThreadBlockedCount.java still fails intermittently Reviewed-by: dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
9535
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
     1
/*
14342
8435a30053c1 7197491: update copyright year to match last edit in jdk8 jdk repository
alanb
parents: 12300
diff changeset
     2
 * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
9535
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
     4
 *
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
     7
 * published by the Free Software Foundation.
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
     8
 *
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    13
 * accompanied this code).
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    14
 *
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    18
 *
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    21
 * questions.
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    22
 */
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    23
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    24
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    25
/**
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    26
 * @test
14411
65913e68c0a6 7198195: Support Unicode 6.2.0
peytoia
parents: 14342
diff changeset
    27
 * @bug 7037261 7070436 7198195
9535
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    28
 * @summary  Check j.l.Character.isLowerCase/isUppercase/isAlphabetic/isIdeographic
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    29
 */
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    30
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    31
import java.util.regex.*;
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    32
import java.util.*;
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    33
import java.io.*;
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    34
import static java.lang.Character.*;
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    35
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    36
public class CheckProp {
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    37
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    38
    public static void main(String[] args) throws IOException {
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    39
        File fPropList = new File(System.getProperty("test.src", "."), "PropList.txt");
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    40
        int i, j;
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    41
        BufferedReader sbfr = new BufferedReader(new FileReader(fPropList));
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    42
        Matcher m = Pattern.compile("(\\p{XDigit}+)(?:\\.{2}(\\p{XDigit}+))?\\s*;\\s+(\\w+)\\s+#.*").matcher("");
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    43
        Map<String, ArrayList<Integer>> propMap =  new LinkedHashMap<>();
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    44
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    45
        String line = null;
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    46
        int lineNo = 0;
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    47
        while ((line = sbfr.readLine()) != null) {
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    48
            lineNo++;
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    49
            if (line.length() <= 1 || line.charAt(0) == '#') {
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    50
                continue;
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    51
            }
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    52
            m.reset(line);
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    53
            if (m.matches()) {
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    54
                int start = Integer.parseInt(m.group(1), 16);
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    55
                int end = (m.group(2)==null)?start
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    56
                          :Integer.parseInt(m.group(2), 16);
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    57
                String name = m.group(3);
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    58
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    59
                ArrayList<Integer> list = propMap.get(name);
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    60
                if (list == null) {
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    61
                    list = new ArrayList<Integer>();
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    62
                    propMap.put(name, list);
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    63
                }
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    64
                while (start <= end)
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    65
                    list.add(start++);
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    66
            } else {
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    67
                System.out.printf("Warning: Unrecognized line %d <%s>%n", lineNo, line);
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    68
            }
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    69
        }
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    70
        sbfr.close();
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    71
        //for (String name: propMap.keySet()) {
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    72
        //    System.out.printf("%s    %d%n", name, propMap.get(name).size());
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    73
        //}
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    74
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    75
        Integer[] otherLowercase = propMap.get("Other_Lowercase").toArray(new Integer[0]);
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    76
        Integer[] otherUppercase = propMap.get("Other_Uppercase").toArray(new Integer[0]);
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    77
        Integer[] otherAlphabetic = propMap.get("Other_Alphabetic").toArray(new Integer[0]);
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    78
        Integer[] ideographic = propMap.get("Ideographic").toArray(new Integer[0]);
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    79
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    80
        int fails = 0;
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    81
        for (int cp = MIN_CODE_POINT; cp < MAX_CODE_POINT; cp++) {
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    82
            int type = getType(cp);
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    83
            if (isLowerCase(cp) !=
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    84
                (type == LOWERCASE_LETTER ||
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    85
                 Arrays.binarySearch(otherLowercase, cp) >= 0))
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    86
            {
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    87
                fails++;
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    88
                System.err.printf("Wrong isLowerCase(U+%04x)\n", cp);
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    89
            }
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    90
            if (isUpperCase(cp) !=
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    91
                (type == UPPERCASE_LETTER ||
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    92
                 Arrays.binarySearch(otherUppercase, cp) >= 0))
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    93
            {
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    94
                fails++;
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    95
                System.err.printf("Wrong isUpperCase(U+%04x)\n", cp);
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    96
            }
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    97
            if (isAlphabetic(cp) !=
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    98
                (type == UPPERCASE_LETTER || type == LOWERCASE_LETTER ||
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    99
                 type == TITLECASE_LETTER || type == MODIFIER_LETTER  ||
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
   100
                 type == OTHER_LETTER     || type == OTHER_LETTER ||
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
   101
                 type == LETTER_NUMBER ||
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
   102
                 Arrays.binarySearch(otherAlphabetic, cp) >=0))
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
   103
            {
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
   104
                fails++;
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
   105
                System.err.printf("Wrong isAlphabetic(U+%04x)\n", cp);
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
   106
            }
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
   107
            if (isIdeographic(cp) !=
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
   108
                (Arrays.binarySearch(ideographic, cp) >= 0))
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
   109
            {
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
   110
                fails++;
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
   111
                System.err.printf("Wrong isIdeographic(U+%04x)\n", cp);
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
   112
            }
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
   113
        }
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
   114
        if (fails != 0)
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
   115
            throw new RuntimeException("CheckProp failed=" + fails);
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
   116
    }
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
   117
}