Path: blob/master/test/jdk/java/text/Format/DateFormat/Bug4823811.java
41152 views
/*1* Copyright (c) 2008, 2016, 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 4823811 800857726* @summary Confirm that text which includes numbers with a trailing minus sign is parsed correctly.27* @modules jdk.localedata28* @run main/othervm -Duser.timezone=GMT+09:00 -Djava.locale.providers=JRE,SPI Bug482381129*/3031import java.text.*;32import java.util.*;3334public class Bug4823811 {3536private static Locale localeEG = new Locale("ar", "EG");37private static Locale localeUS = Locale.US;3839private static String JuneInArabic = "\u064a\u0648\u0646\u064a\u0648";40private static String JulyInArabic = "\u064a\u0648\u0644\u064a\u0648";41private static String JuneInEnglish = "June";42private static String JulyInEnglish = "July";4344private static String BORDER =45"============================================================";4647/*48* I don't use static import here intentionally so that this test program49* can be run on JDK 1.4.2.50*/51private static int ERA = Calendar.ERA;52private static int BC = GregorianCalendar.BC;53// private static int JAN = Calendar.JANUARY;54// private static int FEB = Calendar.FEBRUARY;55// private static int MAR = Calendar.MARCH;56private static int APR = Calendar.APRIL;57private static int MAY = Calendar.MAY;58private static int JUN = Calendar.JUNE;59private static int JUL = Calendar.JULY;60// private static int AUG = Calendar.AUGUST;61// private static int SEP = Calendar.SEPTEMBER;62// private static int OCT = Calendar.OCTOBER;63// private static int NOV = Calendar.NOVEMBER;64// private static int DEC = Calendar.DECEMBER;6566private static String[] patterns = {67"yyyy MMMM d H m s",68"yyyy MM dd hh mm ss",6970/*71* Because 1-based HOUR_OF_DAY, 1-based HOUR, MONTH, and YEAR fields72* are parsed using different code from the code for other numeric73* fields, I prepared YEAR-preceding patterns and SECOND-preceding74* patterns.75*/76"yyyy M d h m s",77" yyyy M d h m s",78"yyyy M d h m s ",7980"s m h d M yyyy",81" s m h d M yyyy",82"s m h d M yyyy ",83};8485private static char originalMinusSign1 = ':';86private static char originalMinusSign2 = '\uff0d'; // fullwidth minus87private static String[] delimiters = {"-", "/", ":", "/", "\uff0d", "/"};88private static String[][] specialDelimiters = {89// for Arabic formatter and modified English formatter90{"--", "-/", "::", ":/", "\uff0d\uff0d", "\uff0d/"},9192// for English formatter and modified Arabic formatter93{"--", "/-", "::", "/:", "\uff0d\uff0d", "/\uff0d"},94};9596/*97* Format:98* +-------------------------------------------------------------------+99* | Input | Output |100* +---------------------+---------------------------------------------|101* | datesEG & datesUS | formattedDatesEG & formattedDatesUS |102* +-------------------------------------------------------------------+103*104* Parse:105* +-------------------------------------------------------------------+106* | Input | Output |107* |---------------------+---------------------------------------------|108* | datesToParse | datesEG & datesUS |109* +-------------------------------------------------------------------+110*/111private static String[][] datesToParse = {112// "JUNE" and "JULY" are replaced with a localized month name later.113{"2008 JULY 20 3 12 83",114"2008 JULY 20 3 12 83",115"2008 JULY 20 3 12 83"},116117{"2008 07 20 03 12 83",118"2008 07 20 03 12 83",119"2008 07 20 03 12 83"},120121{"2008 7 20 3 12 83",122"2008 7 20 3 12 83",123"2008 7 20 3 12 83"},124125{" 2008 7 20 3 12 83",126" 2008 7 20 3 12 83",127" 2008 7 20 3 12 83",128"2008 7 20 3 12 83"},129130{"2008 7 20 3 12 83 ",131"2008 7 20 3 12 83 ",132"2008 7 20 3 12 83"},133134{"83 12 3 20 7 2008",135"83 12 3 20 7 2008",136"83 12 3 20 7 2008"},137138{" 83 12 3 20 7 2008",139" 83 12 3 20 7 2008",140" 83 12 3 20 7 2008",141"83 12 3 20 7 2008"},142143{"83 12 3 20 7 2008 ",144"83 12 3 20 7 2008 ",145"83 12 3 20 7 2008"},146};147148// For formatting149private static String[][] formattedDatesEG = {150{"2008 JULY 20 3 13 23",151"2009 JULY 20 3 13 23",152null},153154{"2008 07 20 03 13 23",155"2009 07 20 03 13 23",156"2007 05 20 03 13 23"},157158{"2008 7 20 3 13 23",159"2009 6 10 3 13 23",160"2007 4 10 3 13 23"},161162{" 2008 7 20 3 13 23",163null,164" 2009 7 20 3 13 23",165null},166167{"2008 7 20 3 13 23 ",168"2008 7 20 3 10 37 ",169null},170171{"23 13 3 20 7 2008",172"37 10 9 19 7 2008",173"23 49 8 19 7 2008"},174175{" 23 13 3 20 7 2008",176null,177" 37 10 3 20 7 2008",178null},179180{"23 13 3 20 7 2008 ",181"23 13 3 20 7 2009 ",182null},183};184185private static String[][] formattedDatesUS = {186{"2008 JULY 20 3 13 23",187null,188"2008 JUNE 10 3 13 23"},189190{"2008 07 20 03 13 23",191"2007 05 20 03 13 23",192"2008 06 10 03 13 23"},193194{"2008 7 20 3 13 23",195"2007 5 19 9 13 23",196"2008 6 9 9 13 23"},197198{" 2008 7 20 3 13 23",199" 2009 7 20 3 13 23",200" 2007 5 20 3 13 23",201null},202203{"2008 7 20 3 13 23 ",204"2008 7 20 3 13 23 ",205null},206207{"23 13 3 20 7 2008",208"23 49 2 10 6 2008",209"23 13 9 9 6 2008"},210211{" 23 13 3 20 7 2008",212" 37 10 3 20 7 2008",213" 23 49 2 20 7 2008",214null},215216{"23 13 3 20 7 2008 ",217"23 13 3 20 7 2008 ",218null},219};220221private static GregorianCalendar[][] datesEG = {222{new GregorianCalendar( 2008, JUL, 20, 3, 12, 83),223new GregorianCalendar(-2008, JUL, 20, 3, 12, 83),224null},225226{new GregorianCalendar( 2008, JUL, 20, 3, 12, 83),227new GregorianCalendar(-2008, JUL, 20, 3, 12, 83),228new GregorianCalendar( 2007, MAY, 20, 3, 12, 83)},229230{new GregorianCalendar( 2008, JUL, 20, 3, 12, 83),231new GregorianCalendar(-2008, JUL, -20, 3, 12, 83),232new GregorianCalendar( 2007, APR, 10, 3, 12, 83)},233234{new GregorianCalendar( 2008, JUL, 20, 3, 12, 83),235null,236new GregorianCalendar(-2008, JUL, 20, 3, 12, 83),237null},238239{new GregorianCalendar( 2008, JUL, 20, 3, 12, 83),240new GregorianCalendar( 2008, JUL, 20, 3, 12, -83),241null},242243{new GregorianCalendar( 2008, JUL, 20, 3, 12, 83),244new GregorianCalendar( 2008, JUL, 20, -3, 12, -83),245new GregorianCalendar( 2008, JUL, 20, -3, -12, 83)},246247{new GregorianCalendar( 2008, JUL, 20, 3, 12, 83),248null,249new GregorianCalendar( 2008, JUL, 20, 3, 12, -83),250null},251252{new GregorianCalendar( 2008, JUL, 20, 3, 12, 83),253new GregorianCalendar(-2008, JUL, 20, 3, 12, 83),254null},255};256257private static GregorianCalendar[][] datesUS = {258{new GregorianCalendar( 2008, JUL, 20, 3, 12, 83),259null,260new GregorianCalendar( 2008, JUN, 10, 3, 12, 83)},261262{new GregorianCalendar( 2008, JUL, 20, 3, 12, 83),263new GregorianCalendar( 2007, MAY, 20, 3, 12, 83),264new GregorianCalendar( 2008, JUN, 10, 3, 12, 83)},265266{new GregorianCalendar( 2008, JUL, 20, 3, 12, 83),267new GregorianCalendar( 2007, MAY, 20, -3, 12, 83),268new GregorianCalendar( 2008, JUL, -20, -3, 12, 83)},269270{new GregorianCalendar( 2008, JUL, 20, 3, 12, 83),271new GregorianCalendar(-2008, JUL, 20, 3, 12, 83),272new GregorianCalendar( 2007, MAY, 20, 3, 12, 83),273null},274275{new GregorianCalendar( 2008, JUL, 20, 3, 12, 83),276new GregorianCalendar( 2008, JUL, 20, 3, 12, 83),277null},278279{new GregorianCalendar( 2008, JUL, 20, 3, 12, 83),280new GregorianCalendar( 2008, JUL, -20, 3, -12, 83),281new GregorianCalendar( 2008, JUL, -20, -3, 12, 83)},282283{new GregorianCalendar( 2008, JUL, 20, 3, 12, 83),284new GregorianCalendar( 2008, JUL, 20, 3, 12, -83),285new GregorianCalendar( 2008, JUL, 20, 3, -12, 83),286null},287288{new GregorianCalendar( 2008, JUL, 20, 3, 12, 83),289new GregorianCalendar( 2008, JUL, 20, 3, 12, 83),290null},291};292293/* flags */294private static boolean err = false;295private static boolean verbose = false;296297298public static void main(String[] args) {299if (args.length == 1 && args[0].equals("-v")) {300verbose = true;301}302303Locale defaultLocale = Locale.getDefault();304TimeZone defaultTimeZone = TimeZone.getDefault();305306TimeZone.setDefault(TimeZone.getTimeZone("Asia/Tokyo"));307308try {309/*310* Test SimpleDateFormat.parse() and format() for original311* SimpleDateFormat instances312*/313testDateFormat1();314315/*316* Test SimpleDateFormat.parse() and format() for modified317* SimpleDateFormat instances using an original minus sign,318* pattern, and diffenrent month names in DecimalFormat319*/320testDateFormat2();321322/*323* Test SimpleDateFormat.parse() and format() for modified324* SimpleDateFormat instances using a fullwidth minus sign325*/326testDateFormat3();327328/*329* Just to confirm that regressions aren't introduced in330* DecimalFormat. This cannot happen, though. Because I didn't331* change DecimalFormat at all.332*/333testNumberFormat();334}335catch (Exception e) {336err = true;337System.err.println("Unexpected exception: " + e);338}339finally {340Locale.setDefault(defaultLocale);341TimeZone.setDefault(defaultTimeZone);342343if (err) {344System.err.println(BORDER + " Test failed.");345throw new RuntimeException("Date/Number formatting/parsing error.");346} else {347System.out.println(BORDER + " Test passed.");348}349}350}351352353//354// DateFormat test355//356private static void testDateFormat1() {357for (int i = 0; i < patterns.length; i++) {358System.out.println(BORDER);359for (int j = 0; j <= 1; j++) {360// Generate a pattern361String pattern = patterns[i].replaceAll(" ", delimiters[j]);362System.out.println("Pattern=\"" + pattern + "\"");363364System.out.println("*** DateFormat.format test in ar_EG");365testDateFormatFormattingInRTL(pattern, i, j, null, localeEG, false);366367System.out.println("*** DateFormat.parse test in ar_EG");368testDateFormatParsingInRTL(pattern, i, j, null, localeEG, false);369370System.out.println("*** DateFormat.format test in en_US");371testDateFormatFormattingInLTR(pattern, i, j, null, localeUS, true);372373System.out.println("*** DateFormat.parse test in en_US");374testDateFormatParsingInLTR(pattern, i, j, null, localeUS, true);375}376}377}378379private static void testDateFormat2() {380/*381* modified ar_EG Date&Time formatter :382* minus sign: ':'383* pattern: "#,##0.###"384* month names: In Arabic385*386* modified en_US Date&Time formatter :387* minus sign: ':'388* pattern: "#,##0.###;#,##0.###-"389* month names: In English390*/391DecimalFormat dfEG = (DecimalFormat)NumberFormat.getInstance(localeEG);392DecimalFormat dfUS = (DecimalFormat)NumberFormat.getInstance(localeUS);393394DecimalFormatSymbols dfsEG = dfEG.getDecimalFormatSymbols();395DecimalFormatSymbols dfsUS = dfUS.getDecimalFormatSymbols();396dfsEG.setMinusSign(originalMinusSign1);397dfsUS.setMinusSign(originalMinusSign1);398dfEG.setDecimalFormatSymbols(dfsUS);399dfUS.setDecimalFormatSymbols(dfsEG);400401String patternEG = dfEG.toPattern();402String patternUS = dfUS.toPattern();403404dfEG.applyPattern(patternUS);405dfUS.applyPattern(patternEG);406407for (int i = 0; i < patterns.length; i++) {408System.out.println(BORDER);409for (int j = 2; j <= 3; j++) {410// Generate a pattern411String pattern = patterns[i].replaceAll(" ", delimiters[j]);412System.out.println("Pattern=\"" + pattern + "\"");413414System.out.println("*** DateFormat.format test in modified en_US");415testDateFormatFormattingInRTL(pattern, i, j, dfUS, localeUS, true);416417System.out.println("*** DateFormat.parse test in modified en_US");418testDateFormatParsingInRTL(pattern, i, j, dfUS, localeUS, true);419420System.out.println("*** DateFormat.format test in modified ar_EG");421testDateFormatFormattingInLTR(pattern, i, j, dfEG, localeEG, false);422423System.out.println("*** DateFormat.parse test in modified ar_EG");424testDateFormatParsingInLTR(pattern, i, j, dfEG, localeEG, false);425}426}427}428429private static void testDateFormat3() {430/*431* modified ar_EG Date&Time formatter :432* minus sign: '\uff0d' // fullwidth minus433* pattern: "#,##0.###;#,##0.###-"434* month names: In Arabic435*436* modified en_US Date&Time formatter :437* minus sign: '\uff0d' // fullwidth minus438* pattern: "#,##0.###"439* month names: In English440*/441DecimalFormat dfEG = (DecimalFormat)NumberFormat.getInstance(localeEG);442DecimalFormat dfUS = (DecimalFormat)NumberFormat.getInstance(localeUS);443444DecimalFormatSymbols dfsEG = dfEG.getDecimalFormatSymbols();445DecimalFormatSymbols dfsUS = dfUS.getDecimalFormatSymbols();446dfsEG.setMinusSign(originalMinusSign2);447dfsUS.setMinusSign(originalMinusSign2);448dfEG.setDecimalFormatSymbols(dfsEG);449dfUS.setDecimalFormatSymbols(dfsUS);450451for (int i = 0; i < patterns.length; i++) {452System.out.println(BORDER);453for (int j = 4; j <= 5; j++) {454// Generate a pattern455String pattern = patterns[i].replaceAll(" ", delimiters[j]);456System.out.println("Pattern=\"" + pattern + "\"");457458System.out.println("*** DateFormat.format test in modified ar_EG");459testDateFormatFormattingInRTL(pattern, i, j, dfEG, localeEG, false);460461System.out.println("*** DateFormat.parse test in modified ar_EG");462testDateFormatParsingInRTL(pattern, i, j, dfEG, localeEG, false);463464System.out.println("*** DateFormat.format test in modified en_US");465testDateFormatFormattingInLTR(pattern, i, j, dfUS, localeUS, true);466467System.out.println("*** DateFormat.parse test in modified en_US");468testDateFormatParsingInLTR(pattern, i, j, dfUS, localeUS, true);469}470}471}472473private static void testDateFormatFormattingInRTL(String pattern,474int basePattern,475int delimiter,476NumberFormat nf,477Locale locale,478boolean useEnglishMonthName) {479Locale.setDefault(locale);480481SimpleDateFormat sdf = new SimpleDateFormat(pattern);482if (nf != null) {483sdf.setNumberFormat(nf);484}485for (int i = 0; i < datesToParse[basePattern].length; i++) {486if (datesEG[basePattern][i] == null) {487continue;488}489490String expected = formattedDatesEG[basePattern][i]491.replaceAll("JUNE", (useEnglishMonthName ?492JuneInEnglish : JuneInArabic))493.replaceAll("JULY", (useEnglishMonthName ?494JulyInEnglish : JulyInArabic))495.replaceAll(" ", delimiters[delimiter]);496testDateFormatFormatting(sdf, pattern, datesEG[basePattern][i],497expected, locale.toString());498}499}500501private static void testDateFormatFormattingInLTR(String pattern,502int basePattern,503int delimiter,504NumberFormat nf,505Locale locale,506boolean useEnglishMonthName) {507Locale.setDefault(locale);508509SimpleDateFormat sdf = new SimpleDateFormat(pattern);510if (nf != null) {511sdf.setNumberFormat(nf);512}513for (int i = 0; i < datesToParse[basePattern].length; i++) {514if (datesUS[basePattern][i] == null) {515continue;516}517518String expected = formattedDatesUS[basePattern][i]519.replaceAll("JUNE", (useEnglishMonthName ?520JuneInEnglish : JuneInArabic))521.replaceAll("JULY", (useEnglishMonthName ?522JulyInEnglish : JulyInArabic))523.replaceAll(" ", delimiters[delimiter]);524testDateFormatFormatting(sdf, pattern, datesUS[basePattern][i],525expected, locale.toString());526}527}528529private static void testDateFormatFormatting(SimpleDateFormat sdf,530String pattern,531GregorianCalendar givenGC,532String expected,533String locale) {534Date given = givenGC.getTime();535String str = sdf.format(given);536if (expected.equals(str)) {537if (verbose) {538System.out.print(" Passed: SimpleDateFormat(");539System.out.print(locale + ", \"" + pattern + "\").format(");540System.out.println(given + ")");541542System.out.print(" ---> \"" + str + "\" ");543System.out.println((givenGC.get(ERA) == BC) ? "(BC)" : "(AD)");544}545} else {546err = true;547548System.err.print(" Failed: Unexpected SimpleDateFormat(");549System.out.print(locale + ", \"" + pattern + "\").format(");550System.out.println(given + ") result.");551552System.out.println(" Expected: \"" + expected + "\"");553554System.out.print(" Got: \"" + str + "\" ");555System.out.println((givenGC.get(ERA) == BC) ? "(BC)" : "(AD)");556}557}558559private static void testDateFormatParsingInRTL(String pattern,560int basePattern,561int delimiter,562NumberFormat nf,563Locale locale,564boolean useEnglishMonthName) {565Locale.setDefault(locale);566567SimpleDateFormat sdf = new SimpleDateFormat(pattern);568if (nf != null) {569sdf.setNumberFormat(nf);570}571for (int i = 0; i < datesToParse[basePattern].length; i++) {572String given = datesToParse[basePattern][i]573.replaceAll(" ", specialDelimiters[0][delimiter])574.replaceAll(" ", delimiters[delimiter]);575576testDateFormatParsing(sdf, pattern,577given.replaceAll("JULY", (useEnglishMonthName ?578JulyInEnglish : JulyInArabic)),579datesEG[basePattern][i], locale.toString());580}581}582583private static void testDateFormatParsingInLTR(String pattern,584int basePattern,585int delimiter,586NumberFormat nf,587Locale locale,588boolean useEnglishMonthName) {589Locale.setDefault(locale);590591SimpleDateFormat sdf = new SimpleDateFormat(pattern);592if (nf != null) {593sdf.setNumberFormat(nf);594}595for (int i = 0; i < datesToParse[basePattern].length; i++) {596String given = datesToParse[basePattern][i]597.replaceAll(" ", specialDelimiters[1][delimiter])598.replaceAll(" ", delimiters[delimiter]);599600testDateFormatParsing(sdf, pattern,601given.replaceAll("JULY", (useEnglishMonthName ?602JulyInEnglish : JulyInArabic)),603datesUS[basePattern][i], locale.toString());604}605}606607private static void testDateFormatParsing(SimpleDateFormat sdf,608String pattern,609String given,610GregorianCalendar expectedGC,611String locale) {612try {613Date d = sdf.parse(given);614if (expectedGC == null) {615err = true;616System.err.print(" Failed: SimpleDateFormat(" + locale);617System.err.print(", \"" + pattern + "\").parse(\"" + given);618System.err.println("\") should have thrown ParseException");619} else if (expectedGC.getTime().equals(d)) {620if (verbose) {621System.out.print(" Passed: SimpleDateFormat(" + locale);622System.out.print(", \"" + pattern + "\").parse(\"" + given);623System.out.println("\")");624625System.out.print(" ---> " + d + " (" + d.getTime());626System.out.println(")");627}628} else {629err = true;630System.err.print(" Failed: SimpleDateFormat(" + locale);631System.err.print(", \"" + pattern + "\").parse(\"" + given);632System.err.println("\")");633634System.err.print(" Expected: " + expectedGC.getTime());635System.err.println(" (" + d.getTime() + ")");636637System.err.print(" Got: " + d + " (" + d.getTime());638System.err.println(")");639640System.err.print(" Pattern: \"");641System.err.print(((DecimalFormat)sdf.getNumberFormat()).toPattern());642System.err.println("\"");643}644}645catch (ParseException pe) {646if (expectedGC == null) {647if (verbose) {648System.out.print(" Passed: SimpleDateFormat(" + locale);649System.out.print(", \"" + pattern + "\").parse(\"" + given);650System.out.println("\")");651652System.out.println(" threw ParseException as expected");653}654} else {655err = true;656System.err.println(" Failed: Unexpected exception with");657658System.err.print(" SimpleDateFormat(" + locale);659System.err.print(", \"" + pattern + "\").parse(\"");660System.err.println(given + "\"):");661662System.err.println(" " + pe);663664System.err.print(" Pattern: \"");665System.err.print(((DecimalFormat)sdf.getNumberFormat()).toPattern());666System.err.println("\"");667668System.err.print(" Month 0: ");669System.err.println(sdf.getDateFormatSymbols().getMonths()[0]);670}671}672}673674675//676// NumberFormat test677//678private static void testNumberFormat() {679NumberFormat nfEG = NumberFormat.getInstance(localeEG);680NumberFormat nfUS = NumberFormat.getInstance(localeUS);681682System.out.println("*** DecimalFormat.format test in ar_EG");683testNumberFormatFormatting(nfEG, -123456789, "123,456,789-", "ar_EG");684testNumberFormatFormatting(nfEG, -456, "456-", "ar_EG");685686System.out.println("*** DecimalFormat.parse test in ar_EG");687testNumberFormatParsing(nfEG, "123-", -123L, "ar_EG");688testNumberFormatParsing(nfEG, "123--",-123L, "ar_EG");689testNumberFormatParsingCheckException(nfEG, "-123", 0, "ar_EG");690691System.out.println("*** DecimalFormat.format test in en_US");692testNumberFormatFormatting(nfUS, -123456789, "-123,456,789", "en_US");693testNumberFormatFormatting(nfUS, -456, "-456", "en_US");694695System.out.println("*** DecimalFormat.parse test in en_US");696testNumberFormatParsing(nfUS, "123-", 123L, "en_US");697testNumberFormatParsing(nfUS, "-123",-123L, "en_US");698testNumberFormatParsingCheckException(nfUS, "--123", 0, "en_US");699}700701private static void testNumberFormatFormatting(NumberFormat nf,702int given,703String expected,704String locale) {705String str = nf.format(given);706if (expected.equals(str)) {707if (verbose) {708System.out.print(" Passed: NumberFormat(" + locale);709System.out.println(").format(" + given + ")");710711System.out.println(" ---> \"" + str + "\"");712}713} else {714err = true;715System.err.print(" Failed: Unexpected NumberFormat(" + locale);716System.err.println(").format(" + given + ") result.");717718System.err.println(" Expected: \"" + expected + "\"");719720System.err.println(" Got: \"" + str + "\"");721}722}723724private static void testNumberFormatParsing(NumberFormat nf,725String given,726Number expected,727String locale) {728try {729Number n = nf.parse(given);730if (n.equals(expected)) {731if (verbose) {732System.out.print(" Passed: NumberFormat(" + locale);733System.out.println(").parse(\"" + given + "\")");734735System.out.println(" ---> " + n);736}737} else {738err = true;739System.err.print(" Failed: Unexpected NumberFormat(" + locale);740System.err.println(").parse(\"" + given + "\") result.");741742System.err.println(" Expected: " + expected);743744System.err.println(" Got: " + n);745}746}747catch (ParseException pe) {748err = true;749System.err.print(" Failed: Unexpected exception with NumberFormat(");750System.err.println(locale + ").parse(\"" + given + "\") :");751752System.err.println(" " + pe);753}754}755756private static void testNumberFormatParsingCheckException(NumberFormat nf,757String given,758int expected,759String locale) {760try {761Number n = nf.parse(given);762err = true;763764System.err.print(" Failed: NumberFormat(" + locale);765System.err.println(").parse(\"" + given + "\")");766767System.err.println(" should have thrown ParseException");768}769catch (ParseException pe) {770int errorOffset = pe.getErrorOffset();771if (errorOffset == expected) {772if (verbose) {773System.out.print(" Passed: NumberFormat(" + locale);774System.out.println(").parse(\"" + given + "\")");775776System.out.print(" threw ParseException as expected, and its errorOffset was correct: ");777System.out.println(errorOffset);778}779} else {780err = true;781System.err.print(" Failed: NumberFormat(" + locale);782System.err.println(").parse(\"" + given + "\")");783784System.err.print(" threw ParseException as expected, but its errorOffset was incorrect: ");785System.err.println(errorOffset);786}787}788}789790}791792793