< prev index next >

test/sun/text/resources/LocaleDataTest.java

Print this page


   1 /*
   2  * Copyright (c) 2007, 2016, 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 4052473 4052679 4055602 4066550 4067619 4068012 4068073 4070174 4070452
  26  *      4070178 4070450 4070695 4070725 4070795 4071003 4071183 4071782 4072013
  27  *      4072388 4072773 4075404 4084356 4087238 4092361 4094033 4094371 4098518
  28  *      4099810 4103218 4103220 4103861 4112136 4113638 4113654 4117054 4122468
  29  *      4122840 4139860 4156708 4175306 4215747 4209960 4290801 4900884 4942982
  30  *      4518811 4945388 4936845 4794068 4461740 4965260 4984277 4826794 5032580
  31  *      5102005 5074431 6182685 6208712 6277020 6245766 6351682 6386647 6379382
  32  *      6414459 6455680 6498742 6558863 6488119 6547501 6497154 6558856 6481177
  33  *      6379214 6485516 6486607 4225362 4494727 6533691 6531591 6531593 6570259
  34  *      6509039 6609737 6610748 6645271 6507067 6873931 6450945 6645268 6646611
  35  *      6645405 6650730 6910489 6573250 6870908 6585666 6716626 6914413 6916787
  36  *      6919624 6998391 7019267 7020960 7025837 7020583 7036905 7066203 7101495
  37  *      7003124 7085757 7028073 7171028 7189611 8000983 7195759 8004489 8006509
  38  *      7114053 7074882 7040556 8008577 8013836 8021121 6192407 6931564 8027695
  39  *      8017142 8037343 8055222 8042126 8074791 8075173 8080774 8129361 8134916
  40  *      8145136 8145952 8164784 8037111 8081643 7037368
  41  * @summary Verify locale data
  42  * @modules java.base/sun.util.resources
  43  * @modules jdk.localedata
  44  * @run main LocaleDataTest
  45  * @run main LocaleDataTest -cldr
  46  *
  47  */
  48 
  49 /*
  50  *
  51  * (C) Copyright Taligent, Inc. 1996, 1997 - All Rights Reserved
  52  * (C) Copyright IBM Corp. 1996 - 1998 - All Rights Reserved
  53  *
  54  * Portions copyright (c) 2007 Sun Microsystems, Inc.
  55  * All Rights Reserved.
  56  *
  57  * The original version of this source code and documentation
  58  * is copyrighted and owned by Taligent, Inc., a wholly-owned
  59  * subsidiary of IBM. These materials are provided under terms
  60  * of a License Agreement between Taligent and Sun. This technology


  82  *    It is driven by an external file that specifies the particular pieces of locale
  83  *    data to check.  That file is in .properties file format: a series of key/value
  84  *    pairs delimited by newline characters, with the keys separated from the values
  85  *    by = signs.  The keys are similar in syntax to a Unix pathname, with keys at
  86  *    successive levels of containment in the resource-data hierarchy separated by
  87  *    slashes.  The file is in ISO 8859-1 encoding, with control characters and
  88  *    non-ASCII characters denoted with backslash-u escape sequences.  The program also allows
  89  *    blank lines and comment lines to be interspersed with the data.  Comment lines
  90  *    begin with '#'.
  91  *
  92  *    A data file for this test would look something like this:<pre>
  93  *        FormatData//MonthNames/0=January
  94  *        FormatData//MonthNames/1=February
  95  *        LocaleNames//US=United States
  96  *        LocaleNames//FR=France
  97  *        FormatData/fr_FR/MonthNames/0=janvier
  98  *        FormatData/fr_FR/MonthNames/1=f\u00e9vrier
  99  *        LocaleNames/fr_FR/US=\u00c9tats-Unis
 100  *        LocaleNames/fr_FR/FR=France</pre>
 101  *
 102  *    You can use language tag with '-' in locale field like this:<pre>
 103  *        LocaleNames/sr-Latn/SR=Surinam







 104  *        FormatData/sr-Latn-BA/DayNames/2=utorak</pre>
 105  *
 106  *    The command-line syntax of this test is
 107  *        <tt>java LocaleDataTest [-w] [{ -s | <filename> }] [-cldr]</tt>
 108  *
 109  *    This program always sends its results to standard output.   If -w is not specified,
 110  *    this program prints out only the differences between the data file and the actual
 111  *    resource data.  If -w is specified, the program prints out every entry, comment,
 112  *    and blank line from the data file.  Where there is a difference between the data
 113  *    file and the resource data, the data is the data from the resources.  This feature
 114  *    can be used to quickly generate a new data file.
 115  *
 116  *    The user can specify an optional filename or -s.  If the user specifies a filename,
 117  *    the program uses that file as the data file.  If the user specifies -s, the program
 118  *    reads its input from standard input rather than from a file.  If the user specifies
 119  *    neither, the program reads its input from a file called LocaleData in the same
 120  *    directory the program itself resides in.
 121  *
 122  *    The -nothrow option prevents the program from throwing an exception when it
 123  *    gets an error.  -w implies -nothrow.


 259         return errorCount;
 260     }
 261 
 262     static boolean processLine(String key, String expectedValue, PrintWriter out,
 263                     boolean writeNewFile) throws Exception {
 264         String rbName, localeName, resTag, qualifier;
 265         String language = "", country = "", variant = "";
 266         int index, oldIndex;
 267 
 268         index = key.indexOf("/");
 269         if (index == -1 || index + 1 == key.length())
 270             throw new Exception("Malformed input file: no slashes in \"" + key + "\"");
 271         rbName = key.substring(0, index);
 272 
 273         oldIndex = index + 1;
 274         index = key.indexOf("/", oldIndex);
 275         if (index == -1 || index + 1 == key.length())
 276             throw new Exception("Malformed input file: \"" + key + "\" is missing locale name");
 277         localeName = key.substring(oldIndex, index);
 278         boolean use_tag = localeName.indexOf("-") != -1;
 279 
 280         if (use_tag == false && localeName.length() > 0) {
 281             language = localeName.substring(0, 2);
 282             if (localeName.length() > 3) {
 283                 country = localeName.substring(3, 5);
 284                 if (localeName.length() > 5)
 285                     variant = localeName.substring(6);











 286             }
 287         }
 288 
 289         oldIndex = index + 1;
 290         index = key.indexOf("/", oldIndex);
 291         if (index == -1)
 292             index = key.length();
 293         resTag = key.substring(oldIndex, index);
 294 
 295         // TimeZone name may have "/" in it, for example "Asia/Taipei", so use "Asia\/Taipei in LocaleData.
 296         if(resTag.endsWith("\\")) {
 297             resTag = resTag.substring(0, resTag.length() - 1);
 298             oldIndex = index;
 299             index = key.indexOf("/", oldIndex + 1);
 300             if (index == -1) index = key.length();
 301             resTag += key.substring(oldIndex, index);
 302         }
 303 
 304         if (index < key.length() - 1)
 305             qualifier = key.substring(index + 1);
 306         else
 307             qualifier = "";
 308 


   1 /*
   2  * Copyright (c) 2007, 2017, 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 4052473 4052679 4055602 4066550 4067619 4068012 4068073 4070174 4070452
  26  *      4070178 4070450 4070695 4070725 4070795 4071003 4071183 4071782 4072013
  27  *      4072388 4072773 4075404 4084356 4087238 4092361 4094033 4094371 4098518
  28  *      4099810 4103218 4103220 4103861 4112136 4113638 4113654 4117054 4122468
  29  *      4122840 4139860 4156708 4175306 4215747 4209960 4290801 4900884 4942982
  30  *      4518811 4945388 4936845 4794068 4461740 4965260 4984277 4826794 5032580
  31  *      5102005 5074431 6182685 6208712 6277020 6245766 6351682 6386647 6379382
  32  *      6414459 6455680 6498742 6558863 6488119 6547501 6497154 6558856 6481177
  33  *      6379214 6485516 6486607 4225362 4494727 6533691 6531591 6531593 6570259
  34  *      6509039 6609737 6610748 6645271 6507067 6873931 6450945 6645268 6646611
  35  *      6645405 6650730 6910489 6573250 6870908 6585666 6716626 6914413 6916787
  36  *      6919624 6998391 7019267 7020960 7025837 7020583 7036905 7066203 7101495
  37  *      7003124 7085757 7028073 7171028 7189611 8000983 7195759 8004489 8006509
  38  *      7114053 7074882 7040556 8008577 8013836 8021121 6192407 6931564 8027695
  39  *      8017142 8037343 8055222 8042126 8074791 8075173 8080774 8129361 8134916
  40  *      8145136 8145952 8164784 8037111 8081643 7037368 8178872
  41  * @summary Verify locale data
  42  * @modules java.base/sun.util.resources
  43  * @modules jdk.localedata
  44  * @run main LocaleDataTest
  45  * @run main LocaleDataTest -cldr
  46  *
  47  */
  48 
  49 /*
  50  *
  51  * (C) Copyright Taligent, Inc. 1996, 1997 - All Rights Reserved
  52  * (C) Copyright IBM Corp. 1996 - 1998 - All Rights Reserved
  53  *
  54  * Portions copyright (c) 2007 Sun Microsystems, Inc.
  55  * All Rights Reserved.
  56  *
  57  * The original version of this source code and documentation
  58  * is copyrighted and owned by Taligent, Inc., a wholly-owned
  59  * subsidiary of IBM. These materials are provided under terms
  60  * of a License Agreement between Taligent and Sun. This technology


  82  *    It is driven by an external file that specifies the particular pieces of locale
  83  *    data to check.  That file is in .properties file format: a series of key/value
  84  *    pairs delimited by newline characters, with the keys separated from the values
  85  *    by = signs.  The keys are similar in syntax to a Unix pathname, with keys at
  86  *    successive levels of containment in the resource-data hierarchy separated by
  87  *    slashes.  The file is in ISO 8859-1 encoding, with control characters and
  88  *    non-ASCII characters denoted with backslash-u escape sequences.  The program also allows
  89  *    blank lines and comment lines to be interspersed with the data.  Comment lines
  90  *    begin with '#'.
  91  *
  92  *    A data file for this test would look something like this:<pre>
  93  *        FormatData//MonthNames/0=January
  94  *        FormatData//MonthNames/1=February
  95  *        LocaleNames//US=United States
  96  *        LocaleNames//FR=France
  97  *        FormatData/fr_FR/MonthNames/0=janvier
  98  *        FormatData/fr_FR/MonthNames/1=f\u00e9vrier
  99  *        LocaleNames/fr_FR/US=\u00c9tats-Unis
 100  *        LocaleNames/fr_FR/FR=France</pre>
 101  *
 102  *    Second field which designates locale is in the form of:
 103  *    1) Legacy locale notation using '_' as a locale component(language/country/variant) separator.
 104  *    language is a mandatory component. country and variant are optional, however, 
 105  *    variant cannot exist without country. So for example, while "ja"/"ja_JP"/"ja_JP_JP" are valid,
 106  *    "_JP"/"ja__JP" are invalid.
 107  *
 108  *    2) BCP47 language tag notation in which we can specify language tag with '-' as a subtag
 109  *       separator. Language tag can be specified with '-' in locale field like this:
 110  *       <pre>LocaleNames/sr-Latn/SR=Surinam
 111  *        FormatData/sr-Latn-BA/DayNames/2=utorak</pre>
 112  *
 113  *    The command-line syntax of this test is
 114  *        <tt>java LocaleDataTest [-w] [{ -s | <filename> }] [-cldr]</tt>
 115  *
 116  *    This program always sends its results to standard output.   If -w is not specified,
 117  *    this program prints out only the differences between the data file and the actual
 118  *    resource data.  If -w is specified, the program prints out every entry, comment,
 119  *    and blank line from the data file.  Where there is a difference between the data
 120  *    file and the resource data, the data is the data from the resources.  This feature
 121  *    can be used to quickly generate a new data file.
 122  *
 123  *    The user can specify an optional filename or -s.  If the user specifies a filename,
 124  *    the program uses that file as the data file.  If the user specifies -s, the program
 125  *    reads its input from standard input rather than from a file.  If the user specifies
 126  *    neither, the program reads its input from a file called LocaleData in the same
 127  *    directory the program itself resides in.
 128  *
 129  *    The -nothrow option prevents the program from throwing an exception when it
 130  *    gets an error.  -w implies -nothrow.


 266         return errorCount;
 267     }
 268 
 269     static boolean processLine(String key, String expectedValue, PrintWriter out,
 270                     boolean writeNewFile) throws Exception {
 271         String rbName, localeName, resTag, qualifier;
 272         String language = "", country = "", variant = "";
 273         int index, oldIndex;
 274 
 275         index = key.indexOf("/");
 276         if (index == -1 || index + 1 == key.length())
 277             throw new Exception("Malformed input file: no slashes in \"" + key + "\"");
 278         rbName = key.substring(0, index);
 279 
 280         oldIndex = index + 1;
 281         index = key.indexOf("/", oldIndex);
 282         if (index == -1 || index + 1 == key.length())
 283             throw new Exception("Malformed input file: \"" + key + "\" is missing locale name");
 284         localeName = key.substring(oldIndex, index);
 285         boolean use_tag = localeName.indexOf("-") != -1;

 286         if (use_tag == false && localeName.length() > 0) {
 287             String[] locDetails = localeName.split("_");
 288             switch (locDetails.length) {
 289                 case 1:
 290                     language = locDetails[0];
 291                     break;
 292                 case 2:
 293                     language = locDetails[0];
 294                     country = locDetails[1];
 295                     break;
 296                 case 3:
 297                     language = locDetails[0];
 298                     country = locDetails[1];
 299                     variant = locDetails[2];
 300                     break;
 301                 default:
 302                     throw new Exception("locale not specified properly " + locDetails);
 303             }
 304         }

 305         oldIndex = index + 1;
 306         index = key.indexOf("/", oldIndex);
 307         if (index == -1)
 308             index = key.length();
 309         resTag = key.substring(oldIndex, index);
 310 
 311         // TimeZone name may have "/" in it, for example "Asia/Taipei", so use "Asia\/Taipei in LocaleData.
 312         if(resTag.endsWith("\\")) {
 313             resTag = resTag.substring(0, resTag.length() - 1);
 314             oldIndex = index;
 315             index = key.indexOf("/", oldIndex + 1);
 316             if (index == -1) index = key.length();
 317             resTag += key.substring(oldIndex, index);
 318         }
 319 
 320         if (index < key.length() - 1)
 321             qualifier = key.substring(index + 1);
 322         else
 323             qualifier = "";
 324 


< prev index next >