< prev index next >

test/jdk/java/lang/Character/UnicodeBlock/CheckBlocks.java

Print this page
rev 54996 : 8221431: Support for Unicode 12.1
Reviewed-by:
   1 /*
   2  * Copyright (c) 2007, 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 4830803 4886934 6565620 6959267 7070436 7198195 8032446 8072600 8202771
  29  * @summary  Check that the UnicodeBlock forName() method works as expected and block ranges are correct for all Unicode characters.



  30  * @run main CheckBlocks
  31  * @author John O'Conner
  32  */
  33 
  34 import java.lang.Character.UnicodeBlock;
  35 import java.lang.reflect.Field;
  36 import java.io.BufferedReader;
  37 import java.io.File;
  38 import java.io.FileReader;
  39 import java.util.HashSet;
  40 import java.util.Locale;
  41 
  42 public class CheckBlocks {
  43 
  44     static boolean err = false;
  45     static Class<?> clazzUnicodeBlock;
  46 
  47     public static void main(String[] args) throws Exception {
  48         generateBlockList();
  49 


 259                     break;
 260             }
 261         }
 262     }
 263 
 264     private static void validateBlock(String blkName) {
 265         for (Block block : blocks) {
 266             String blockName = block.getName();
 267             if (blockName.equals(blkName)) {
 268                 return;
 269             }
 270         }
 271         err = true;
 272         System.err.println(blkName + " is not a valid Unicode Block.");
 273     }
 274 
 275     // List of all Unicode blocks, their start, and end codepoints.
 276     public static HashSet<Block> blocks = new HashSet<>();
 277 
 278     private static void generateBlockList() throws Exception {
 279         File blockData = new File(System.getProperty("test.src", "."),
 280                 "Blocks.txt");
 281         try (BufferedReader f = new BufferedReader(new FileReader(blockData))) {
 282             String line;
 283             while ((line = f.readLine()) != null) {
 284                 if (line.length() == 0 || line.charAt(0) == '#') {
 285                     continue;
 286                 }
 287 
 288                 int index1 = line.indexOf('.');
 289                 int begin = Integer.parseInt(line.substring(0, index1), 16);
 290                 int index2 = line.indexOf(';');
 291                 int end = Integer.parseInt(line.substring(index1 + 2, index2), 16);
 292                 String name = line.substring(index2 + 1).trim();
 293 
 294                 System.out.println("  Adding a Block(" + Integer.toHexString(begin) + ", " + Integer.toHexString(end)
 295                         + ", " + name + ")");
 296                 blocks.add(new Block(begin, end, name));
 297             }
 298         }
 299     }
 300 }


   1 /*
   2  * Copyright (c) 2007, 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 4830803 4886934 6565620 6959267 7070436 7198195 8032446 8072600 8202771
  29  *      8221431
  30  * @summary  Check that the UnicodeBlock forName() method works as expected
  31  *      and block ranges are correct for all Unicode characters.
  32  * @library /lib/testlibrary/java/lang
  33  * @run main CheckBlocks
  34  * @author John O'Conner
  35  */
  36 
  37 import java.lang.Character.UnicodeBlock;
  38 import java.lang.reflect.Field;
  39 import java.io.BufferedReader;
  40 import java.io.File;
  41 import java.io.FileReader;
  42 import java.util.HashSet;
  43 import java.util.Locale;
  44 
  45 public class CheckBlocks {
  46 
  47     static boolean err = false;
  48     static Class<?> clazzUnicodeBlock;
  49 
  50     public static void main(String[] args) throws Exception {
  51         generateBlockList();
  52 


 262                     break;
 263             }
 264         }
 265     }
 266 
 267     private static void validateBlock(String blkName) {
 268         for (Block block : blocks) {
 269             String blockName = block.getName();
 270             if (blockName.equals(blkName)) {
 271                 return;
 272             }
 273         }
 274         err = true;
 275         System.err.println(blkName + " is not a valid Unicode Block.");
 276     }
 277 
 278     // List of all Unicode blocks, their start, and end codepoints.
 279     public static HashSet<Block> blocks = new HashSet<>();
 280 
 281     private static void generateBlockList() throws Exception {
 282         File blockData = UCDFiles.BLOCKS.toFile();

 283         try (BufferedReader f = new BufferedReader(new FileReader(blockData))) {
 284             String line;
 285             while ((line = f.readLine()) != null) {
 286                 if (line.length() == 0 || line.charAt(0) == '#') {
 287                     continue;
 288                 }
 289 
 290                 int index1 = line.indexOf('.');
 291                 int begin = Integer.parseInt(line.substring(0, index1), 16);
 292                 int index2 = line.indexOf(';');
 293                 int end = Integer.parseInt(line.substring(index1 + 2, index2), 16);
 294                 String name = line.substring(index2 + 1).trim();
 295 
 296                 System.out.println("  Adding a Block(" + Integer.toHexString(begin) + ", " + Integer.toHexString(end)
 297                         + ", " + name + ")");
 298                 blocks.add(new Block(begin, end, name));
 299             }
 300         }
 301     }
 302 }


< prev index next >