LocaleDataTest.java revision 2048
/*
* Copyright (c) 2007 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @test
* @bug 4052473 4052679 4055602 4066550 4067619 4068012 4068073 4070174 4070452
* 4070178 4070450 4070695 4070725 4070795 4071003 4071183 4071782 4072013
* 4072388 4072773 4075404 4084356 4087238 4092361 4094033 4094371 4098518
* 4099810 4103218 4103220 4103861 4112136 4113638 4113654 4117054 4122468
* 4122840 4139860 4156708 4175306 4215747 4209960 4290801 4900884 4942982
* 4518811 4945388 4936845 4794068 4461740 4965260 4984277 4826794 5032580
* 5102005 5074431 6182685 6208712 6277020 6245766 6351682 6386647 6379382
* 6414459 6455680 6498742 6558863 6488119 6547501 6497154 6558856 6481177
* 6379214 6485516 6486607 4225362 4494727 6533691 6531591 6531593 6570259
* 6509039 6609737 6610748 6645271 6507067
* @summary Verify locale data
*
*/
/*
*
* (C) Copyright Taligent, Inc. 1996, 1997 - All Rights Reserved
* (C) Copyright IBM Corp. 1996 - 1998 - All Rights Reserved
*
* Portions copyright (c) 2007 Sun Microsystems, Inc.
* All Rights Reserved.
*
* The original version of this source code and documentation
* is copyrighted and owned by Taligent, Inc., a wholly-owned
* subsidiary of IBM. These materials are provided under terms
* of a License Agreement between Taligent and Sun. This technology
* is protected by multiple US and International patents.
*
* This notice and attribution to Taligent may not be removed.
* Taligent is a registered trademark of Taligent, Inc.
*
* Permission to use, copy, modify, and distribute this software
* and its documentation for NON-COMMERCIAL purposes and without
* fee is hereby granted provided that this copyright notice
* appears in all copies. Please refer to the file "copyright.html"
* for further important copyright and licensing information.
*
* SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
* THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
* TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
* ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
* DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
*
*/
/* This test is a generalized test for verifying changes to the locale data.
* It is driven by an external file that specifies the particular pieces of locale
* pairs delimited by newline characters, with the keys separated from the values
* by = signs. The keys are similar in syntax to a Unix pathname, with keys at
* successive levels of containment in the resource-data hierarchy separated by
* slashes. The file is in ISO 8859-1 encoding, with control characters and
* non-ASCII characters denoted with backslash-u escape sequences. The program also allows
* blank lines and comment lines to be interspersed with the data. Comment lines
* begin with '#'.
*
* A data file for this test would look something like this:<pre>
* FormatData//MonthNames/0=January
* FormatData//MonthNames/1=February
* LocaleNames//US=United States
* LocaleNames//FR=France
* FormatData/fr_FR/MonthNames/0=janvier
* FormatData/fr_FR/MonthNames/1=f\u00e9vrier
* LocaleNames/fr_FR/US=\u00c9tats-Unis
* LocaleNames/fr_FR/FR=France</pre>
*
* The command-line syntax of this test is
* <tt>java LocaleDataTest [-w] [{ -s | <filename> }]</tt>
*
* This program always sends its results to standard output. If -w is not specified,
* this program prints out only the differences between the data file and the actual
* resource data. If -w is specified, the program prints out every entry, comment,
* and blank line from the data file. Where there is a difference between the data
* file and the resource data, the data is the data from the resources. This feature
* can be used to quickly generate a new data file.
*
* The user can specify an optional filename or -s. If the user specifies a filename,
* the program uses that file as the data file. If the user specifies -s, the program
* reads its input from standard input rather than from a file. If the user specifies
* neither, the program reads its input from a file called LocaleData in the same
* directory the program itself resides in.
*
* The -nothrow option prevents the program from throwing an exception when it
* gets an error. -w implies -nothrow.
*
* Other command-line options can be specified, but are ignored.
*
* It's important to note what this test will NOT test. Certain changes to the locale
* data are meant to have certain effects on the internationalization frameworks. For
* instance, we could ensure round-trip formatting/parsing integrity for the full
* patterns include sufficient data. The test of this is not whether changes were
* made to the locale data; it's whether using this data gives round-trip integrity.
* Likewise, changing the currency patterns to use \u00a4 instead of local currency
* symbols isn't something that can be tested by this test; instead, you want to
* actually format currency values and make sure the proper currency symbol was used.
*
* This test by itself doesn't do an exhaustive comparison of locale data. It is
* possible to do this manually, however: Use the GenerateKeyList tool to produce
* a complete list of keys for the two versions of the locales you want to compare,
* and then diff them. This will flag additions and deletions. Generate a data file
* for the base version of the data using the -w option and the output from
* GenerateKeyList, and then use the resultant file as the data file when you run
* this test against the new version of the data.
*/
public class LocaleDataTest
{
// set up our flags and our input and output streams based on the
// command-line arguments (exceptions generated here will propagate out
// to the environment)
boolean writeNewFile = false;
boolean doThrow = true;
writeNewFile = true;
doThrow = false;
}
doThrow = false;
"ISO8859_1")));
}
}
"ISO8859_1")), true);
// perform the actual test
// write out the error count, and throw an exception out into the environment
// if there were any errors
if (errorCount != 0) {
if (!writeNewFile)
if (doThrow)
}
else if (!writeNewFile)
}
throws Exception {
int errorCount = 0;
if (writeNewFile)
}
else {
if (index == -1) {
expectedValue = "";
}
else {
expectedValue = "";
else
}
++errorCount;
}
}
return errorCount;
}
boolean writeNewFile) throws Exception {
}
}
if (index == -1)
}
else
qualifier = "";
try {
} else {
}
}
catch (MissingResourceException e) {
}
}
}
if (slash == -1) {
}
}
else {
}
}
}
if (retrievedValue == null)
retrievedValue = "<MISSING!>";
if (writeNewFile)
else {
}
return false;
}
else {
if (writeNewFile)
}
return true;
}
}
class EscapeReader extends FilterReader {
super(in);
}
public int read() throws IOException {
if (b.length() > 1)
else
return result;
}
else {
if (result != '\\')
return result;
else {
buffer = new StringBuffer();
if (result == 'u') {
for (int i = 0; i < 4; i++) {
if (result == -1)
break;
}
return result;
}
return '\\';
}
}
}
int p = start;
int c = 0;
while (c != -1 && p < end) {
c = read();
if (c != -1)
cbuf[p++] = (char)c;
}
if (c == -1 && p == start)
return -1;
else
return p - start;
}
}
class EscapeWriter extends FilterWriter {
super(out);
}
public void write(int c) throws IOException {
if ((c >= ' ' && c <= '\u007e') || c == '\r' || c == '\n')
super.write(c);
else {
super.write('\\');
super.write('u');
}
}
}
}
}