Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/text/Format/DateFormat/Bug4823811.java
47182 views
/*1* Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/**24* @test25* @bug 482381126* @summary Confirm that text which includes numbers with a trailing minus sign is parsed correctly.27* @run main/othervm -Duser.timezone=GMT+09:00 Bug482381128*/2930import java.text.*;31import java.util.*;3233public class Bug4823811 {3435private static Locale localeEG = new Locale("ar", "EG");36private static Locale localeUS = Locale.US;3738private static String JuneInArabic = "\u064a\u0648\u0646\u064a\u0648";39private static String JulyInArabic = "\u064a\u0648\u0644\u064a\u0648";40private static String JuneInEnglish = "June";41private static String JulyInEnglish = "July";4243private static String BORDER =44"============================================================";4546/*47* I don't use static import here intentionally so that this test program48* can be run on JDK 1.4.2.49*/50private static int ERA = Calendar.ERA;51private static int BC = GregorianCalendar.BC;52// private static int JAN = Calendar.JANUARY;53// private static int FEB = Calendar.FEBRUARY;54// private static int MAR = Calendar.MARCH;55private static int APR = Calendar.APRIL;56private static int MAY = Calendar.MAY;57private static int JUN = Calendar.JUNE;58private static int JUL = Calendar.JULY;59// private static int AUG = Calendar.AUGUST;60// private static int SEP = Calendar.SEPTEMBER;61// private static int OCT = Calendar.OCTOBER;62// private static int NOV = Calendar.NOVEMBER;63// private static int DEC = Calendar.DECEMBER;6465private static String[] patterns = {66"yyyy MMMM d H m s",67"yyyy MM dd hh mm ss",6869/*70* Because 1-based HOUR_OF_DAY, 1-based HOUR, MONTH, and YEAR fields71* are parsed using different code from the code for other numeric72* fields, I prepared YEAR-preceding patterns and SECOND-preceding73* patterns.74*/75"yyyy M d h m s",76" yyyy M d h m s",77"yyyy M d h m s ",7879"s m h d M yyyy",80" s m h d M yyyy",81"s m h d M yyyy ",82};8384private static char originalMinusSign1 = ':';85private static char originalMinusSign2 = '\uff0d'; // fullwidth minus86private static String[] delimiters = {"-", "/", ":", "/", "\uff0d", "/"};87private static String[][] specialDelimiters = {88// for Arabic formatter and modified English formatter89{"--", "-/", "::", ":/", "\uff0d\uff0d", "\uff0d/"},9091// for English formatter and modified Arabic formatter92{"--", "/-", "::", "/:", "\uff0d\uff0d", "/\uff0d"},93};9495/*96* Format:97* +-------------------------------------------------------------------+98* | Input | Output |99* +---------------------+---------------------------------------------|100* | datesEG & datesUS | formattedDatesEG & formattedDatesUS |101* +-------------------------------------------------------------------+102*103* Parse:104* +-------------------------------------------------------------------+105* | Input | Output |106* |---------------------+---------------------------------------------|107* | datesToParse | datesEG & datesUS |108* +-------------------------------------------------------------------+109*/110private static String[][] datesToParse = {111// "JUNE" and "JULY" are replaced with a localized month name later.112{"2008 JULY 20 3 12 83",113"2008 JULY 20 3 12 83",114"2008 JULY 20 3 12 83"},115116{"2008 07 20 03 12 83",117"2008 07 20 03 12 83",118"2008 07 20 03 12 83"},119120{"2008 7 20 3 12 83",121"2008 7 20 3 12 83",122"2008 7 20 3 12 83"},123124{" 2008 7 20 3 12 83",125" 2008 7 20 3 12 83",126" 2008 7 20 3 12 83",127"2008 7 20 3 12 83"},128129{"2008 7 20 3 12 83 ",130"2008 7 20 3 12 83 ",131"2008 7 20 3 12 83"},132133{"83 12 3 20 7 2008",134"83 12 3 20 7 2008",135"83 12 3 20 7 2008"},136137{" 83 12 3 20 7 2008",138" 83 12 3 20 7 2008",139" 83 12 3 20 7 2008",140"83 12 3 20 7 2008"},141142{"83 12 3 20 7 2008 ",143"83 12 3 20 7 2008 ",144"83 12 3 20 7 2008"},145};146147// For formatting148private static String[][] formattedDatesEG = {149{"2008 JULY 20 3 13 23",150"2009 JULY 20 3 13 23",151null},152153{"2008 07 20 03 13 23",154"2009 07 20 03 13 23",155"2007 05 20 03 13 23"},156157{"2008 7 20 3 13 23",158"2009 6 10 3 13 23",159"2007 4 10 3 13 23"},160161{" 2008 7 20 3 13 23",162null,163" 2009 7 20 3 13 23",164null},165166{"2008 7 20 3 13 23 ",167"2008 7 20 3 10 37 ",168null},169170{"23 13 3 20 7 2008",171"37 10 9 19 7 2008",172"23 49 8 19 7 2008"},173174{" 23 13 3 20 7 2008",175null,176" 37 10 3 20 7 2008",177null},178179{"23 13 3 20 7 2008 ",180"23 13 3 20 7 2009 ",181null},182};183184private static String[][] formattedDatesUS = {185{"2008 JULY 20 3 13 23",186null,187"2008 JUNE 10 3 13 23"},188189{"2008 07 20 03 13 23",190"2007 05 20 03 13 23",191"2008 06 10 03 13 23"},192193{"2008 7 20 3 13 23",194"2007 5 19 9 13 23",195"2008 6 9 9 13 23"},196197{" 2008 7 20 3 13 23",198" 2009 7 20 3 13 23",199" 2007 5 20 3 13 23",200null},201202{"2008 7 20 3 13 23 ",203"2008 7 20 3 13 23 ",204null},205206{"23 13 3 20 7 2008",207"23 49 2 10 6 2008",208"23 13 9 9 6 2008"},209210{" 23 13 3 20 7 2008",211" 37 10 3 20 7 2008",212" 23 49 2 20 7 2008",213null},214215{"23 13 3 20 7 2008 ",216"23 13 3 20 7 2008 ",217null},218};219220private static GregorianCalendar[][] datesEG = {221{new GregorianCalendar( 2008, JUL, 20, 3, 12, 83),222new GregorianCalendar(-2008, JUL, 20, 3, 12, 83),223null},224225{new GregorianCalendar( 2008, JUL, 20, 3, 12, 83),226new GregorianCalendar(-2008, JUL, 20, 3, 12, 83),227new GregorianCalendar( 2007, MAY, 20, 3, 12, 83)},228229{new GregorianCalendar( 2008, JUL, 20, 3, 12, 83),230new GregorianCalendar(-2008, JUL, -20, 3, 12, 83),231new GregorianCalendar( 2007, APR, 10, 3, 12, 83)},232233{new GregorianCalendar( 2008, JUL, 20, 3, 12, 83),234null,235new GregorianCalendar(-2008, JUL, 20, 3, 12, 83),236null},237238{new GregorianCalendar( 2008, JUL, 20, 3, 12, 83),239new GregorianCalendar( 2008, JUL, 20, 3, 12, -83),240null},241242{new GregorianCalendar( 2008, JUL, 20, 3, 12, 83),243new GregorianCalendar( 2008, JUL, 20, -3, 12, -83),244new GregorianCalendar( 2008, JUL, 20, -3, -12, 83)},245246{new GregorianCalendar( 2008, JUL, 20, 3, 12, 83),247null,248new GregorianCalendar( 2008, JUL, 20, 3, 12, -83),249null},250251{new GregorianCalendar( 2008, JUL, 20, 3, 12, 83),252new GregorianCalendar(-2008, JUL, 20, 3, 12, 83),253null},254};255256private static GregorianCalendar[][] datesUS = {257{new GregorianCalendar( 2008, JUL, 20, 3, 12, 83),258null,259new GregorianCalendar( 2008, JUN, 10, 3, 12, 83)},260261{new GregorianCalendar( 2008, JUL, 20, 3, 12, 83),262new GregorianCalendar( 2007, MAY, 20, 3, 12, 83),263new GregorianCalendar( 2008, JUN, 10, 3, 12, 83)},264265{new GregorianCalendar( 2008, JUL, 20, 3, 12, 83),266new GregorianCalendar( 2007, MAY, 20, -3, 12, 83),267new GregorianCalendar( 2008, JUL, -20, -3, 12, 83)},268269{new GregorianCalendar( 2008, JUL, 20, 3, 12, 83),270new GregorianCalendar(-2008, JUL, 20, 3, 12, 83),271new GregorianCalendar( 2007, MAY, 20, 3, 12, 83),272null},273274{new GregorianCalendar( 2008, JUL, 20, 3, 12, 83),275new GregorianCalendar( 2008, JUL, 20, 3, 12, 83),276null},277278{new GregorianCalendar( 2008, JUL, 20, 3, 12, 83),279new GregorianCalendar( 2008, JUL, -20, 3, -12, 83),280new GregorianCalendar( 2008, JUL, -20, -3, 12, 83)},281282{new GregorianCalendar( 2008, JUL, 20, 3, 12, 83),283new GregorianCalendar( 2008, JUL, 20, 3, 12, -83),284new GregorianCalendar( 2008, JUL, 20, 3, -12, 83),285null},286287{new GregorianCalendar( 2008, JUL, 20, 3, 12, 83),288new GregorianCalendar( 2008, JUL, 20, 3, 12, 83),289null},290};291292/* flags */293private static boolean err = false;294private static boolean verbose = false;295296297public static void main(String[] args) {298if (args.length == 1 && args[0].equals("-v")) {299verbose = true;300}301302Locale defaultLocale = Locale.getDefault();303TimeZone defaultTimeZone = TimeZone.getDefault();304305TimeZone.setDefault(TimeZone.getTimeZone("Asia/Tokyo"));306307try {308/*309* Test SimpleDateFormat.parse() and format() for original310* SimpleDateFormat instances311*/312testDateFormat1();313314/*315* Test SimpleDateFormat.parse() and format() for modified316* SimpleDateFormat instances using an original minus sign,317* pattern, and diffenrent month names in DecimalFormat318*/319testDateFormat2();320321/*322* Test SimpleDateFormat.parse() and format() for modified323* SimpleDateFormat instances using a fullwidth minus sign324*/325testDateFormat3();326327/*328* Just to confirm that regressions aren't introduced in329* DecimalFormat. This cannot happen, though. Because I didn't330* change DecimalFormat at all.331*/332testNumberFormat();333}334catch (Exception e) {335err = true;336System.err.println("Unexpected exception: " + e);337}338finally {339Locale.setDefault(defaultLocale);340TimeZone.setDefault(defaultTimeZone);341342if (err) {343System.err.println(BORDER + " Test failed.");344throw new RuntimeException("Date/Number formatting/parsing error.");345} else {346System.out.println(BORDER + " Test passed.");347}348}349}350351352//353// DateFormat test354//355private static void testDateFormat1() {356for (int i = 0; i < patterns.length; i++) {357System.out.println(BORDER);358for (int j = 0; j <= 1; j++) {359// Generate a pattern360String pattern = patterns[i].replaceAll(" ", delimiters[j]);361System.out.println("Pattern=\"" + pattern + "\"");362363System.out.println("*** DateFormat.format test in ar_EG");364testDateFormatFormattingInRTL(pattern, i, j, null, localeEG, false);365366System.out.println("*** DateFormat.parse test in ar_EG");367testDateFormatParsingInRTL(pattern, i, j, null, localeEG, false);368369System.out.println("*** DateFormat.format test in en_US");370testDateFormatFormattingInLTR(pattern, i, j, null, localeUS, true);371372System.out.println("*** DateFormat.parse test in en_US");373testDateFormatParsingInLTR(pattern, i, j, null, localeUS, true);374}375}376}377378private static void testDateFormat2() {379/*380* modified ar_EG Date&Time formatter :381* minus sign: ':'382* pattern: "#,##0.###"383* month names: In Arabic384*385* modified en_US Date&Time formatter :386* minus sign: ':'387* pattern: "#,##0.###;#,##0.###-"388* month names: In English389*/390DecimalFormat dfEG = (DecimalFormat)NumberFormat.getInstance(localeEG);391DecimalFormat dfUS = (DecimalFormat)NumberFormat.getInstance(localeUS);392393DecimalFormatSymbols dfsEG = dfEG.getDecimalFormatSymbols();394DecimalFormatSymbols dfsUS = dfUS.getDecimalFormatSymbols();395dfsEG.setMinusSign(originalMinusSign1);396dfsUS.setMinusSign(originalMinusSign1);397dfEG.setDecimalFormatSymbols(dfsUS);398dfUS.setDecimalFormatSymbols(dfsEG);399400String patternEG = dfEG.toPattern();401String patternUS = dfUS.toPattern();402403dfEG.applyPattern(patternUS);404dfUS.applyPattern(patternEG);405406for (int i = 0; i < patterns.length; i++) {407System.out.println(BORDER);408for (int j = 2; j <= 3; j++) {409// Generate a pattern410String pattern = patterns[i].replaceAll(" ", delimiters[j]);411System.out.println("Pattern=\"" + pattern + "\"");412413System.out.println("*** DateFormat.format test in modified en_US");414testDateFormatFormattingInRTL(pattern, i, j, dfUS, localeUS, true);415416System.out.println("*** DateFormat.parse test in modified en_US");417testDateFormatParsingInRTL(pattern, i, j, dfUS, localeUS, true);418419System.out.println("*** DateFormat.format test in modified ar_EG");420testDateFormatFormattingInLTR(pattern, i, j, dfEG, localeEG, false);421422System.out.println("*** DateFormat.parse test in modified ar_EG");423testDateFormatParsingInLTR(pattern, i, j, dfEG, localeEG, false);424}425}426}427428private static void testDateFormat3() {429/*430* modified ar_EG Date&Time formatter :431* minus sign: '\uff0d' // fullwidth minus432* pattern: "#,##0.###;#,##0.###-"433* month names: In Arabic434*435* modified en_US Date&Time formatter :436* minus sign: '\uff0d' // fullwidth minus437* pattern: "#,##0.###"438* month names: In English439*/440DecimalFormat dfEG = (DecimalFormat)NumberFormat.getInstance(localeEG);441DecimalFormat dfUS = (DecimalFormat)NumberFormat.getInstance(localeUS);442443DecimalFormatSymbols dfsEG = dfEG.getDecimalFormatSymbols();444DecimalFormatSymbols dfsUS = dfUS.getDecimalFormatSymbols();445dfsEG.setMinusSign(originalMinusSign2);446dfsUS.setMinusSign(originalMinusSign2);447dfEG.setDecimalFormatSymbols(dfsEG);448dfUS.setDecimalFormatSymbols(dfsUS);449450for (int i = 0; i < patterns.length; i++) {451System.out.println(BORDER);452for (int j = 4; j <= 5; j++) {453// Generate a pattern454String pattern = patterns[i].replaceAll(" ", delimiters[j]);455System.out.println("Pattern=\"" + pattern + "\"");456457System.out.println("*** DateFormat.format test in modified ar_EG");458testDateFormatFormattingInRTL(pattern, i, j, dfEG, localeEG, false);459460System.out.println("*** DateFormat.parse test in modified ar_EG");461testDateFormatParsingInRTL(pattern, i, j, dfEG, localeEG, false);462463System.out.println("*** DateFormat.format test in modified en_US");464testDateFormatFormattingInLTR(pattern, i, j, dfUS, localeUS, true);465466System.out.println("*** DateFormat.parse test in modified en_US");467testDateFormatParsingInLTR(pattern, i, j, dfUS, localeUS, true);468}469}470}471472private static void testDateFormatFormattingInRTL(String pattern,473int basePattern,474int delimiter,475NumberFormat nf,476Locale locale,477boolean useEnglishMonthName) {478Locale.setDefault(locale);479480SimpleDateFormat sdf = new SimpleDateFormat(pattern);481if (nf != null) {482sdf.setNumberFormat(nf);483}484for (int i = 0; i < datesToParse[basePattern].length; i++) {485if (datesEG[basePattern][i] == null) {486continue;487}488489String expected = formattedDatesEG[basePattern][i]490.replaceAll("JUNE", (useEnglishMonthName ?491JuneInEnglish : JuneInArabic))492.replaceAll("JULY", (useEnglishMonthName ?493JulyInEnglish : JulyInArabic))494.replaceAll(" ", delimiters[delimiter]);495testDateFormatFormatting(sdf, pattern, datesEG[basePattern][i],496expected, locale.toString());497}498}499500private static void testDateFormatFormattingInLTR(String pattern,501int basePattern,502int delimiter,503NumberFormat nf,504Locale locale,505boolean useEnglishMonthName) {506Locale.setDefault(locale);507508SimpleDateFormat sdf = new SimpleDateFormat(pattern);509if (nf != null) {510sdf.setNumberFormat(nf);511}512for (int i = 0; i < datesToParse[basePattern].length; i++) {513if (datesUS[basePattern][i] == null) {514continue;515}516517String expected = formattedDatesUS[basePattern][i]518.replaceAll("JUNE", (useEnglishMonthName ?519JuneInEnglish : JuneInArabic))520.replaceAll("JULY", (useEnglishMonthName ?521JulyInEnglish : JulyInArabic))522.replaceAll(" ", delimiters[delimiter]);523testDateFormatFormatting(sdf, pattern, datesUS[basePattern][i],524expected, locale.toString());525}526}527528private static void testDateFormatFormatting(SimpleDateFormat sdf,529String pattern,530GregorianCalendar givenGC,531String expected,532String locale) {533Date given = givenGC.getTime();534String str = sdf.format(given);535if (expected.equals(str)) {536if (verbose) {537System.out.print(" Passed: SimpleDateFormat(");538System.out.print(locale + ", \"" + pattern + "\").format(");539System.out.println(given + ")");540541System.out.print(" ---> \"" + str + "\" ");542System.out.println((givenGC.get(ERA) == BC) ? "(BC)" : "(AD)");543}544} else {545err = true;546547System.err.print(" Failed: Unexpected SimpleDateFormat(");548System.out.print(locale + ", \"" + pattern + "\").format(");549System.out.println(given + ") result.");550551System.out.println(" Expected: \"" + expected + "\"");552553System.out.print(" Got: \"" + str + "\" ");554System.out.println((givenGC.get(ERA) == BC) ? "(BC)" : "(AD)");555}556}557558private static void testDateFormatParsingInRTL(String pattern,559int basePattern,560int delimiter,561NumberFormat nf,562Locale locale,563boolean useEnglishMonthName) {564Locale.setDefault(locale);565566SimpleDateFormat sdf = new SimpleDateFormat(pattern);567if (nf != null) {568sdf.setNumberFormat(nf);569}570for (int i = 0; i < datesToParse[basePattern].length; i++) {571String given = datesToParse[basePattern][i]572.replaceAll(" ", specialDelimiters[0][delimiter])573.replaceAll(" ", delimiters[delimiter]);574575testDateFormatParsing(sdf, pattern,576given.replaceAll("JULY", (useEnglishMonthName ?577JulyInEnglish : JulyInArabic)),578datesEG[basePattern][i], locale.toString());579}580}581582private static void testDateFormatParsingInLTR(String pattern,583int basePattern,584int delimiter,585NumberFormat nf,586Locale locale,587boolean useEnglishMonthName) {588Locale.setDefault(locale);589590SimpleDateFormat sdf = new SimpleDateFormat(pattern);591if (nf != null) {592sdf.setNumberFormat(nf);593}594for (int i = 0; i < datesToParse[basePattern].length; i++) {595String given = datesToParse[basePattern][i]596.replaceAll(" ", specialDelimiters[1][delimiter])597.replaceAll(" ", delimiters[delimiter]);598599testDateFormatParsing(sdf, pattern,600given.replaceAll("JULY", (useEnglishMonthName ?601JulyInEnglish : JulyInArabic)),602datesUS[basePattern][i], locale.toString());603}604}605606private static void testDateFormatParsing(SimpleDateFormat sdf,607String pattern,608String given,609GregorianCalendar expectedGC,610String locale) {611try {612Date d = sdf.parse(given);613if (expectedGC == null) {614err = true;615System.err.print(" Failed: SimpleDateFormat(" + locale);616System.err.print(", \"" + pattern + "\").parse(\"" + given);617System.err.println("\") should have thrown ParseException");618} else if (expectedGC.getTime().equals(d)) {619if (verbose) {620System.out.print(" Passed: SimpleDateFormat(" + locale);621System.out.print(", \"" + pattern + "\").parse(\"" + given);622System.out.println("\")");623624System.out.print(" ---> " + d + " (" + d.getTime());625System.out.println(")");626}627} else {628err = true;629System.err.print(" Failed: SimpleDateFormat(" + locale);630System.err.print(", \"" + pattern + "\").parse(\"" + given);631System.err.println("\")");632633System.err.print(" Expected: " + expectedGC.getTime());634System.err.println(" (" + d.getTime() + ")");635636System.err.print(" Got: " + d + " (" + d.getTime());637System.err.println(")");638639System.err.print(" Pattern: \"");640System.err.print(((DecimalFormat)sdf.getNumberFormat()).toPattern());641System.err.println("\"");642}643}644catch (ParseException pe) {645if (expectedGC == null) {646if (verbose) {647System.out.print(" Passed: SimpleDateFormat(" + locale);648System.out.print(", \"" + pattern + "\").parse(\"" + given);649System.out.println("\")");650651System.out.println(" threw ParseException as expected");652}653} else {654err = true;655System.err.println(" Failed: Unexpected exception with");656657System.err.print(" SimpleDateFormat(" + locale);658System.err.print(", \"" + pattern + "\").parse(\"");659System.err.println(given + "\"):");660661System.err.println(" " + pe);662663System.err.print(" Pattern: \"");664System.err.print(((DecimalFormat)sdf.getNumberFormat()).toPattern());665System.err.println("\"");666667System.err.print(" Month 0: ");668System.err.println(sdf.getDateFormatSymbols().getMonths()[0]);669}670}671}672673674//675// NumberFormat test676//677private static void testNumberFormat() {678NumberFormat nfEG = NumberFormat.getInstance(localeEG);679NumberFormat nfUS = NumberFormat.getInstance(localeUS);680681System.out.println("*** DecimalFormat.format test in ar_EG");682testNumberFormatFormatting(nfEG, -123456789, "123,456,789-", "ar_EG");683testNumberFormatFormatting(nfEG, -456, "456-", "ar_EG");684685System.out.println("*** DecimalFormat.parse test in ar_EG");686testNumberFormatParsing(nfEG, "123-", new Long(-123), "ar_EG");687testNumberFormatParsing(nfEG, "123--", new Long(-123), "ar_EG");688testNumberFormatParsingCheckException(nfEG, "-123", 0, "ar_EG");689690System.out.println("*** DecimalFormat.format test in en_US");691testNumberFormatFormatting(nfUS, -123456789, "-123,456,789", "en_US");692testNumberFormatFormatting(nfUS, -456, "-456", "en_US");693694System.out.println("*** DecimalFormat.parse test in en_US");695testNumberFormatParsing(nfUS, "123-", new Long(123), "en_US");696testNumberFormatParsing(nfUS, "-123", new Long(-123), "en_US");697testNumberFormatParsingCheckException(nfUS, "--123", 0, "en_US");698}699700private static void testNumberFormatFormatting(NumberFormat nf,701int given,702String expected,703String locale) {704String str = nf.format(given);705if (expected.equals(str)) {706if (verbose) {707System.out.print(" Passed: NumberFormat(" + locale);708System.out.println(").format(" + given + ")");709710System.out.println(" ---> \"" + str + "\"");711}712} else {713err = true;714System.err.print(" Failed: Unexpected NumberFormat(" + locale);715System.err.println(").format(" + given + ") result.");716717System.err.println(" Expected: \"" + expected + "\"");718719System.err.println(" Got: \"" + str + "\"");720}721}722723private static void testNumberFormatParsing(NumberFormat nf,724String given,725Number expected,726String locale) {727try {728Number n = nf.parse(given);729if (n.equals(expected)) {730if (verbose) {731System.out.print(" Passed: NumberFormat(" + locale);732System.out.println(").parse(\"" + given + "\")");733734System.out.println(" ---> " + n);735}736} else {737err = true;738System.err.print(" Failed: Unexpected NumberFormat(" + locale);739System.err.println(").parse(\"" + given + "\") result.");740741System.err.println(" Expected: " + expected);742743System.err.println(" Got: " + n);744}745}746catch (ParseException pe) {747err = true;748System.err.print(" Failed: Unexpected exception with NumberFormat(");749System.err.println(locale + ").parse(\"" + given + "\") :");750751System.err.println(" " + pe);752}753}754755private static void testNumberFormatParsingCheckException(NumberFormat nf,756String given,757int expected,758String locale) {759try {760Number n = nf.parse(given);761err = true;762763System.err.print(" Failed: NumberFormat(" + locale);764System.err.println(").parse(\"" + given + "\")");765766System.err.println(" should have thrown ParseException");767}768catch (ParseException pe) {769int errorOffset = pe.getErrorOffset();770if (errorOffset == expected) {771if (verbose) {772System.out.print(" Passed: NumberFormat(" + locale);773System.out.println(").parse(\"" + given + "\")");774775System.out.print(" threw ParseException as expected, and its errorOffset was correct: ");776System.out.println(errorOffset);777}778} else {779err = true;780System.err.print(" Failed: NumberFormat(" + locale);781System.err.println(").parse(\"" + given + "\")");782783System.err.print(" threw ParseException as expected, but its errorOffset was incorrect: ");784System.err.println(errorOffset);785}786}787}788789}790791792