Java Code Examples for sun.util.resources.LocaleData#getBundle()
The following examples show how to use
sun.util.resources.LocaleData#getBundle() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NumberRegression.java From dragonwell8_jdk with GNU General Public License v2.0 | 4 votes |
/** * Locale data should use generic currency symbol * * 1) Make sure that all currency formats use the generic currency symbol. * 2) Make sure we get the same results using the generic symbol or a * hard-coded one. */ public void Test4122840() { Locale[] locales = NumberFormat.getAvailableLocales(); for (int i = 0; i < locales.length; i++) { ResourceBundle rb = LocaleData.getBundle("sun.text.resources.FormatData", locales[i]); // // Get the currency pattern for this locale. We have to fish it // out of the ResourceBundle directly, since DecimalFormat.toPattern // will return the localized symbol, not \00a4 // String[] numPatterns = (String[])rb.getObject("NumberPatterns"); String pattern = numPatterns[1]; if (pattern.indexOf("\u00A4") == -1 ) { errln("Currency format for " + locales[i] + " does not contain generic currency symbol:" + pattern ); } // Create a DecimalFormat using the pattern we got and format a number DecimalFormatSymbols symbols = DecimalFormatSymbols.getInstance(locales[i]); DecimalFormat fmt1 = new DecimalFormat(pattern, symbols); String result1 = fmt1.format(1.111); // // Now substitute in the locale's currency symbol and create another // pattern. Replace the decimal separator with the monetary separator. // char decSep = symbols.getDecimalSeparator(); char monSep = symbols.getMonetaryDecimalSeparator(); StringBuffer buf = new StringBuffer(pattern); for (int j = 0; j < buf.length(); j++) { if (buf.charAt(j) == '\u00a4') { String cur = "'" + symbols.getCurrencySymbol() + "'"; buf.replace(j, j+1, cur); j += cur.length() - 1; } } symbols.setDecimalSeparator(monSep); DecimalFormat fmt2 = new DecimalFormat(buf.toString(), symbols); String result2 = fmt2.format(1.111); if (!result1.equals(result2)) { errln("Results for " + locales[i] + " differ: " + result1 + " vs " + result2); } } }
Example 2
Source File: TimeZoneTest.java From dragonwell8_jdk with GNU General Public License v2.0 | 4 votes |
/** * Test the basic functionality of the getDisplayName() API. * * Bug 4112869 * Bug 4028006 * * See also API change request A41. * * 4/21/98 - make smarter, so the test works if the ext resources * are present or not. */ public void TestDisplayName() { TimeZone zone = TimeZone.getTimeZone("PST"); String name = zone.getDisplayName(Locale.ENGLISH); logln("PST->" + name); if (!name.equals("Pacific Standard Time")) errln("Fail: Expected \"Pacific Standard Time\""); //***************************************************************** // THE FOLLOWING LINES MUST BE UPDATED IF THE LOCALE DATA CHANGES // THE FOLLOWING LINES MUST BE UPDATED IF THE LOCALE DATA CHANGES // THE FOLLOWING LINES MUST BE UPDATED IF THE LOCALE DATA CHANGES //***************************************************************** Object[] DATA = { new Boolean(false), new Integer(TimeZone.SHORT), "PST", new Boolean(true), new Integer(TimeZone.SHORT), "PDT", new Boolean(false), new Integer(TimeZone.LONG), "Pacific Standard Time", new Boolean(true), new Integer(TimeZone.LONG), "Pacific Daylight Time", }; for (int i=0; i<DATA.length; i+=3) { name = zone.getDisplayName(((Boolean)DATA[i]).booleanValue(), ((Integer)DATA[i+1]).intValue(), Locale.ENGLISH); if (!name.equals(DATA[i+2])) errln("Fail: Expected " + DATA[i+2] + "; got " + name); } // Make sure that we don't display the DST name by constructing a fake // PST zone that has DST all year long. SimpleTimeZone zone2 = new SimpleTimeZone(0, "PST"); zone2.setStartRule(Calendar.JANUARY, 1, 0); zone2.setEndRule(Calendar.DECEMBER, 31, 0); logln("Modified PST inDaylightTime->" + zone2.inDaylightTime(new Date())); name = zone2.getDisplayName(Locale.ENGLISH); logln("Modified PST->" + name); if (!name.equals("Pacific Standard Time")) errln("Fail: Expected \"Pacific Standard Time\""); // Make sure we get the default display format for Locales // with no display name data. Locale zh_CN = Locale.SIMPLIFIED_CHINESE; name = zone.getDisplayName(zh_CN); //***************************************************************** // THE FOLLOWING LINE MUST BE UPDATED IF THE LOCALE DATA CHANGES // THE FOLLOWING LINE MUST BE UPDATED IF THE LOCALE DATA CHANGES // THE FOLLOWING LINE MUST BE UPDATED IF THE LOCALE DATA CHANGES //***************************************************************** logln("PST(zh_CN)->" + name); // Now be smart -- check to see if zh resource is even present. // If not, we expect the en fallback behavior. ResourceBundle enRB = LocaleData.getBundle("sun.util.resources.TimeZoneNames", Locale.ENGLISH); ResourceBundle zhRB = LocaleData.getBundle("sun.util.resources.TimeZoneNames", zh_CN); boolean noZH = enRB == zhRB; if (noZH) { logln("Warning: Not testing the zh_CN behavior because resource is absent"); if (!name.equals("Pacific Standard Time")) errln("Fail: Expected Pacific Standard Time"); } else if (!name.equals("Pacific Standard Time") && !name.equals("\u592a\u5e73\u6d0b\u6807\u51c6\u65f6\u95f4") && !name.equals("GMT-08:00") && !name.equals("GMT-8:00") && !name.equals("GMT-0800") && !name.equals("GMT-800")) { errln("Fail: Expected GMT-08:00 or something similar"); errln("************************************************************"); errln("THE ABOVE FAILURE MAY JUST MEAN THE LOCALE DATA HAS CHANGED"); errln("************************************************************"); } // Now try a non-existent zone zone2 = new SimpleTimeZone(90*60*1000, "xyzzy"); name = zone2.getDisplayName(Locale.ENGLISH); logln("GMT+90min->" + name); if (!name.equals("GMT+01:30") && !name.equals("GMT+1:30") && !name.equals("GMT+0130") && !name.equals("GMT+130")) errln("Fail: Expected GMT+01:30 or something similar"); }
Example 3
Source File: NumberRegression.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
/** * Locale data should use generic currency symbol * * 1) Make sure that all currency formats use the generic currency symbol. * 2) Make sure we get the same results using the generic symbol or a * hard-coded one. */ public void Test4122840() { Locale[] locales = NumberFormat.getAvailableLocales(); for (int i = 0; i < locales.length; i++) { ResourceBundle rb = LocaleData.getBundle("sun.text.resources.FormatData", locales[i]); // // Get the currency pattern for this locale. We have to fish it // out of the ResourceBundle directly, since DecimalFormat.toPattern // will return the localized symbol, not \00a4 // String[] numPatterns = (String[])rb.getObject("NumberPatterns"); String pattern = numPatterns[1]; if (pattern.indexOf("\u00A4") == -1 ) { errln("Currency format for " + locales[i] + " does not contain generic currency symbol:" + pattern ); } // Create a DecimalFormat using the pattern we got and format a number DecimalFormatSymbols symbols = DecimalFormatSymbols.getInstance(locales[i]); DecimalFormat fmt1 = new DecimalFormat(pattern, symbols); String result1 = fmt1.format(1.111); // // Now substitute in the locale's currency symbol and create another // pattern. Replace the decimal separator with the monetary separator. // char decSep = symbols.getDecimalSeparator(); char monSep = symbols.getMonetaryDecimalSeparator(); StringBuffer buf = new StringBuffer(pattern); for (int j = 0; j < buf.length(); j++) { if (buf.charAt(j) == '\u00a4') { String cur = "'" + symbols.getCurrencySymbol() + "'"; buf.replace(j, j+1, cur); j += cur.length() - 1; } } symbols.setDecimalSeparator(monSep); DecimalFormat fmt2 = new DecimalFormat(buf.toString(), symbols); String result2 = fmt2.format(1.111); if (!result1.equals(result2)) { errln("Results for " + locales[i] + " differ: " + result1 + " vs " + result2); } } }
Example 4
Source File: TimeZoneTest.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
/** * Test the basic functionality of the getDisplayName() API. * * Bug 4112869 * Bug 4028006 * * See also API change request A41. * * 4/21/98 - make smarter, so the test works if the ext resources * are present or not. */ public void TestDisplayName() { TimeZone zone = TimeZone.getTimeZone("PST"); String name = zone.getDisplayName(Locale.ENGLISH); logln("PST->" + name); if (!name.equals("Pacific Standard Time")) errln("Fail: Expected \"Pacific Standard Time\""); //***************************************************************** // THE FOLLOWING LINES MUST BE UPDATED IF THE LOCALE DATA CHANGES // THE FOLLOWING LINES MUST BE UPDATED IF THE LOCALE DATA CHANGES // THE FOLLOWING LINES MUST BE UPDATED IF THE LOCALE DATA CHANGES //***************************************************************** Object[] DATA = { new Boolean(false), new Integer(TimeZone.SHORT), "PST", new Boolean(true), new Integer(TimeZone.SHORT), "PDT", new Boolean(false), new Integer(TimeZone.LONG), "Pacific Standard Time", new Boolean(true), new Integer(TimeZone.LONG), "Pacific Daylight Time", }; for (int i=0; i<DATA.length; i+=3) { name = zone.getDisplayName(((Boolean)DATA[i]).booleanValue(), ((Integer)DATA[i+1]).intValue(), Locale.ENGLISH); if (!name.equals(DATA[i+2])) errln("Fail: Expected " + DATA[i+2] + "; got " + name); } // Make sure that we don't display the DST name by constructing a fake // PST zone that has DST all year long. SimpleTimeZone zone2 = new SimpleTimeZone(0, "PST"); zone2.setStartRule(Calendar.JANUARY, 1, 0); zone2.setEndRule(Calendar.DECEMBER, 31, 0); logln("Modified PST inDaylightTime->" + zone2.inDaylightTime(new Date())); name = zone2.getDisplayName(Locale.ENGLISH); logln("Modified PST->" + name); if (!name.equals("Pacific Standard Time")) errln("Fail: Expected \"Pacific Standard Time\""); // Make sure we get the default display format for Locales // with no display name data. Locale zh_CN = Locale.SIMPLIFIED_CHINESE; name = zone.getDisplayName(zh_CN); //***************************************************************** // THE FOLLOWING LINE MUST BE UPDATED IF THE LOCALE DATA CHANGES // THE FOLLOWING LINE MUST BE UPDATED IF THE LOCALE DATA CHANGES // THE FOLLOWING LINE MUST BE UPDATED IF THE LOCALE DATA CHANGES //***************************************************************** logln("PST(zh_CN)->" + name); // Now be smart -- check to see if zh resource is even present. // If not, we expect the en fallback behavior. ResourceBundle enRB = LocaleData.getBundle("sun.util.resources.TimeZoneNames", Locale.ENGLISH); ResourceBundle zhRB = LocaleData.getBundle("sun.util.resources.TimeZoneNames", zh_CN); boolean noZH = enRB == zhRB; if (noZH) { logln("Warning: Not testing the zh_CN behavior because resource is absent"); if (!name.equals("Pacific Standard Time")) errln("Fail: Expected Pacific Standard Time"); } else if (!name.equals("Pacific Standard Time") && !name.equals("\u592a\u5e73\u6d0b\u6807\u51c6\u65f6\u95f4") && !name.equals("GMT-08:00") && !name.equals("GMT-8:00") && !name.equals("GMT-0800") && !name.equals("GMT-800")) { errln("Fail: Expected GMT-08:00 or something similar"); errln("************************************************************"); errln("THE ABOVE FAILURE MAY JUST MEAN THE LOCALE DATA HAS CHANGED"); errln("************************************************************"); } // Now try a non-existent zone zone2 = new SimpleTimeZone(90*60*1000, "xyzzy"); name = zone2.getDisplayName(Locale.ENGLISH); logln("GMT+90min->" + name); if (!name.equals("GMT+01:30") && !name.equals("GMT+1:30") && !name.equals("GMT+0130") && !name.equals("GMT+130")) errln("Fail: Expected GMT+01:30 or something similar"); }
Example 5
Source File: NumberRegression.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
/** * Locale data should use generic currency symbol * * 1) Make sure that all currency formats use the generic currency symbol. * 2) Make sure we get the same results using the generic symbol or a * hard-coded one. */ public void Test4122840() { Locale[] locales = NumberFormat.getAvailableLocales(); for (int i = 0; i < locales.length; i++) { ResourceBundle rb = LocaleData.getBundle("sun.text.resources.FormatData", locales[i]); // // Get the currency pattern for this locale. We have to fish it // out of the ResourceBundle directly, since DecimalFormat.toPattern // will return the localized symbol, not \00a4 // String[] numPatterns = (String[])rb.getObject("NumberPatterns"); String pattern = numPatterns[1]; if (pattern.indexOf("\u00A4") == -1 ) { errln("Currency format for " + locales[i] + " does not contain generic currency symbol:" + pattern ); } // Create a DecimalFormat using the pattern we got and format a number DecimalFormatSymbols symbols = DecimalFormatSymbols.getInstance(locales[i]); DecimalFormat fmt1 = new DecimalFormat(pattern, symbols); String result1 = fmt1.format(1.111); // // Now substitute in the locale's currency symbol and create another // pattern. Replace the decimal separator with the monetary separator. // char decSep = symbols.getDecimalSeparator(); char monSep = symbols.getMonetaryDecimalSeparator(); StringBuffer buf = new StringBuffer(pattern); for (int j = 0; j < buf.length(); j++) { if (buf.charAt(j) == '\u00a4') { String cur = "'" + symbols.getCurrencySymbol() + "'"; buf.replace(j, j+1, cur); j += cur.length() - 1; } } symbols.setDecimalSeparator(monSep); DecimalFormat fmt2 = new DecimalFormat(buf.toString(), symbols); String result2 = fmt2.format(1.111); if (!result1.equals(result2)) { errln("Results for " + locales[i] + " differ: " + result1 + " vs " + result2); } } }
Example 6
Source File: TimeZoneTest.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
/** * Test the basic functionality of the getDisplayName() API. * * Bug 4112869 * Bug 4028006 * * See also API change request A41. * * 4/21/98 - make smarter, so the test works if the ext resources * are present or not. */ public void TestDisplayName() { TimeZone zone = TimeZone.getTimeZone("PST"); String name = zone.getDisplayName(Locale.ENGLISH); logln("PST->" + name); if (!name.equals("Pacific Standard Time")) errln("Fail: Expected \"Pacific Standard Time\""); //***************************************************************** // THE FOLLOWING LINES MUST BE UPDATED IF THE LOCALE DATA CHANGES // THE FOLLOWING LINES MUST BE UPDATED IF THE LOCALE DATA CHANGES // THE FOLLOWING LINES MUST BE UPDATED IF THE LOCALE DATA CHANGES //***************************************************************** Object[] DATA = { new Boolean(false), new Integer(TimeZone.SHORT), "PST", new Boolean(true), new Integer(TimeZone.SHORT), "PDT", new Boolean(false), new Integer(TimeZone.LONG), "Pacific Standard Time", new Boolean(true), new Integer(TimeZone.LONG), "Pacific Daylight Time", }; for (int i=0; i<DATA.length; i+=3) { name = zone.getDisplayName(((Boolean)DATA[i]).booleanValue(), ((Integer)DATA[i+1]).intValue(), Locale.ENGLISH); if (!name.equals(DATA[i+2])) errln("Fail: Expected " + DATA[i+2] + "; got " + name); } // Make sure that we don't display the DST name by constructing a fake // PST zone that has DST all year long. SimpleTimeZone zone2 = new SimpleTimeZone(0, "PST"); zone2.setStartRule(Calendar.JANUARY, 1, 0); zone2.setEndRule(Calendar.DECEMBER, 31, 0); logln("Modified PST inDaylightTime->" + zone2.inDaylightTime(new Date())); name = zone2.getDisplayName(Locale.ENGLISH); logln("Modified PST->" + name); if (!name.equals("Pacific Standard Time")) errln("Fail: Expected \"Pacific Standard Time\""); // Make sure we get the default display format for Locales // with no display name data. Locale zh_CN = Locale.SIMPLIFIED_CHINESE; name = zone.getDisplayName(zh_CN); //***************************************************************** // THE FOLLOWING LINE MUST BE UPDATED IF THE LOCALE DATA CHANGES // THE FOLLOWING LINE MUST BE UPDATED IF THE LOCALE DATA CHANGES // THE FOLLOWING LINE MUST BE UPDATED IF THE LOCALE DATA CHANGES //***************************************************************** logln("PST(zh_CN)->" + name); // Now be smart -- check to see if zh resource is even present. // If not, we expect the en fallback behavior. ResourceBundle enRB = LocaleData.getBundle("sun.util.resources.TimeZoneNames", Locale.ENGLISH); ResourceBundle zhRB = LocaleData.getBundle("sun.util.resources.TimeZoneNames", zh_CN); boolean noZH = enRB == zhRB; if (noZH) { logln("Warning: Not testing the zh_CN behavior because resource is absent"); if (!name.equals("Pacific Standard Time")) errln("Fail: Expected Pacific Standard Time"); } else if (!name.equals("Pacific Standard Time") && !name.equals("\u592a\u5e73\u6d0b\u6807\u51c6\u65f6\u95f4") && !name.equals("GMT-08:00") && !name.equals("GMT-8:00") && !name.equals("GMT-0800") && !name.equals("GMT-800")) { errln("Fail: Expected GMT-08:00 or something similar"); errln("************************************************************"); errln("THE ABOVE FAILURE MAY JUST MEAN THE LOCALE DATA HAS CHANGED"); errln("************************************************************"); } // Now try a non-existent zone zone2 = new SimpleTimeZone(90*60*1000, "xyzzy"); name = zone2.getDisplayName(Locale.ENGLISH); logln("GMT+90min->" + name); if (!name.equals("GMT+01:30") && !name.equals("GMT+1:30") && !name.equals("GMT+0130") && !name.equals("GMT+130")) errln("Fail: Expected GMT+01:30 or something similar"); }
Example 7
Source File: NumberRegression.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
/** * Locale data should use generic currency symbol * * 1) Make sure that all currency formats use the generic currency symbol. * 2) Make sure we get the same results using the generic symbol or a * hard-coded one. */ public void Test4122840() { Locale[] locales = NumberFormat.getAvailableLocales(); for (int i = 0; i < locales.length; i++) { ResourceBundle rb = LocaleData.getBundle("sun.text.resources.FormatData", locales[i]); // // Get the currency pattern for this locale. We have to fish it // out of the ResourceBundle directly, since DecimalFormat.toPattern // will return the localized symbol, not \00a4 // String[] numPatterns = (String[])rb.getObject("NumberPatterns"); String pattern = numPatterns[1]; if (pattern.indexOf("\u00A4") == -1 ) { errln("Currency format for " + locales[i] + " does not contain generic currency symbol:" + pattern ); } // Create a DecimalFormat using the pattern we got and format a number DecimalFormatSymbols symbols = DecimalFormatSymbols.getInstance(locales[i]); DecimalFormat fmt1 = new DecimalFormat(pattern, symbols); String result1 = fmt1.format(1.111); // // Now substitute in the locale's currency symbol and create another // pattern. Replace the decimal separator with the monetary separator. // char decSep = symbols.getDecimalSeparator(); char monSep = symbols.getMonetaryDecimalSeparator(); StringBuffer buf = new StringBuffer(pattern); for (int j = 0; j < buf.length(); j++) { if (buf.charAt(j) == '\u00a4') { String cur = "'" + symbols.getCurrencySymbol() + "'"; buf.replace(j, j+1, cur); j += cur.length() - 1; } } symbols.setDecimalSeparator(monSep); DecimalFormat fmt2 = new DecimalFormat(buf.toString(), symbols); String result2 = fmt2.format(1.111); if (!result1.equals(result2)) { errln("Results for " + locales[i] + " differ: " + result1 + " vs " + result2); } } }
Example 8
Source File: TimeZoneTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
/** * Test the basic functionality of the getDisplayName() API. * * Bug 4112869 * Bug 4028006 * * See also API change request A41. * * 4/21/98 - make smarter, so the test works if the ext resources * are present or not. */ public void TestDisplayName() { TimeZone zone = TimeZone.getTimeZone("PST"); String name = zone.getDisplayName(Locale.ENGLISH); logln("PST->" + name); if (!name.equals("Pacific Standard Time")) errln("Fail: Expected \"Pacific Standard Time\""); //***************************************************************** // THE FOLLOWING LINES MUST BE UPDATED IF THE LOCALE DATA CHANGES // THE FOLLOWING LINES MUST BE UPDATED IF THE LOCALE DATA CHANGES // THE FOLLOWING LINES MUST BE UPDATED IF THE LOCALE DATA CHANGES //***************************************************************** Object[] DATA = { new Boolean(false), new Integer(TimeZone.SHORT), "PST", new Boolean(true), new Integer(TimeZone.SHORT), "PDT", new Boolean(false), new Integer(TimeZone.LONG), "Pacific Standard Time", new Boolean(true), new Integer(TimeZone.LONG), "Pacific Daylight Time", }; for (int i=0; i<DATA.length; i+=3) { name = zone.getDisplayName(((Boolean)DATA[i]).booleanValue(), ((Integer)DATA[i+1]).intValue(), Locale.ENGLISH); if (!name.equals(DATA[i+2])) errln("Fail: Expected " + DATA[i+2] + "; got " + name); } // Make sure that we don't display the DST name by constructing a fake // PST zone that has DST all year long. SimpleTimeZone zone2 = new SimpleTimeZone(0, "PST"); zone2.setStartRule(Calendar.JANUARY, 1, 0); zone2.setEndRule(Calendar.DECEMBER, 31, 0); logln("Modified PST inDaylightTime->" + zone2.inDaylightTime(new Date())); name = zone2.getDisplayName(Locale.ENGLISH); logln("Modified PST->" + name); if (!name.equals("Pacific Standard Time")) errln("Fail: Expected \"Pacific Standard Time\""); // Make sure we get the default display format for Locales // with no display name data. Locale zh_CN = Locale.SIMPLIFIED_CHINESE; name = zone.getDisplayName(zh_CN); //***************************************************************** // THE FOLLOWING LINE MUST BE UPDATED IF THE LOCALE DATA CHANGES // THE FOLLOWING LINE MUST BE UPDATED IF THE LOCALE DATA CHANGES // THE FOLLOWING LINE MUST BE UPDATED IF THE LOCALE DATA CHANGES //***************************************************************** logln("PST(zh_CN)->" + name); // Now be smart -- check to see if zh resource is even present. // If not, we expect the en fallback behavior. ResourceBundle enRB = LocaleData.getBundle("sun.util.resources.TimeZoneNames", Locale.ENGLISH); ResourceBundle zhRB = LocaleData.getBundle("sun.util.resources.TimeZoneNames", zh_CN); boolean noZH = enRB == zhRB; if (noZH) { logln("Warning: Not testing the zh_CN behavior because resource is absent"); if (!name.equals("Pacific Standard Time")) errln("Fail: Expected Pacific Standard Time"); } else if (!name.equals("Pacific Standard Time") && !name.equals("\u592a\u5e73\u6d0b\u6807\u51c6\u65f6\u95f4") && !name.equals("GMT-08:00") && !name.equals("GMT-8:00") && !name.equals("GMT-0800") && !name.equals("GMT-800")) { errln("Fail: Expected GMT-08:00 or something similar"); errln("************************************************************"); errln("THE ABOVE FAILURE MAY JUST MEAN THE LOCALE DATA HAS CHANGED"); errln("************************************************************"); } // Now try a non-existent zone zone2 = new SimpleTimeZone(90*60*1000, "xyzzy"); name = zone2.getDisplayName(Locale.ENGLISH); logln("GMT+90min->" + name); if (!name.equals("GMT+01:30") && !name.equals("GMT+1:30") && !name.equals("GMT+0130") && !name.equals("GMT+130")) errln("Fail: Expected GMT+01:30 or something similar"); }
Example 9
Source File: NumberRegression.java From jdk8u_jdk with GNU General Public License v2.0 | 4 votes |
/** * Locale data should use generic currency symbol * * 1) Make sure that all currency formats use the generic currency symbol. * 2) Make sure we get the same results using the generic symbol or a * hard-coded one. */ public void Test4122840() { Locale[] locales = NumberFormat.getAvailableLocales(); for (int i = 0; i < locales.length; i++) { ResourceBundle rb = LocaleData.getBundle("sun.text.resources.FormatData", locales[i]); // // Get the currency pattern for this locale. We have to fish it // out of the ResourceBundle directly, since DecimalFormat.toPattern // will return the localized symbol, not \00a4 // String[] numPatterns = (String[])rb.getObject("NumberPatterns"); String pattern = numPatterns[1]; if (pattern.indexOf("\u00A4") == -1 ) { errln("Currency format for " + locales[i] + " does not contain generic currency symbol:" + pattern ); } // Create a DecimalFormat using the pattern we got and format a number DecimalFormatSymbols symbols = DecimalFormatSymbols.getInstance(locales[i]); DecimalFormat fmt1 = new DecimalFormat(pattern, symbols); String result1 = fmt1.format(1.111); // // Now substitute in the locale's currency symbol and create another // pattern. Replace the decimal separator with the monetary separator. // char decSep = symbols.getDecimalSeparator(); char monSep = symbols.getMonetaryDecimalSeparator(); StringBuffer buf = new StringBuffer(pattern); for (int j = 0; j < buf.length(); j++) { if (buf.charAt(j) == '\u00a4') { String cur = "'" + symbols.getCurrencySymbol() + "'"; buf.replace(j, j+1, cur); j += cur.length() - 1; } } symbols.setDecimalSeparator(monSep); DecimalFormat fmt2 = new DecimalFormat(buf.toString(), symbols); String result2 = fmt2.format(1.111); if (!result1.equals(result2)) { errln("Results for " + locales[i] + " differ: " + result1 + " vs " + result2); } } }
Example 10
Source File: TimeZoneTest.java From jdk8u_jdk with GNU General Public License v2.0 | 4 votes |
/** * Test the basic functionality of the getDisplayName() API. * * Bug 4112869 * Bug 4028006 * * See also API change request A41. * * 4/21/98 - make smarter, so the test works if the ext resources * are present or not. */ public void TestDisplayName() { TimeZone zone = TimeZone.getTimeZone("PST"); String name = zone.getDisplayName(Locale.ENGLISH); logln("PST->" + name); if (!name.equals("Pacific Standard Time")) errln("Fail: Expected \"Pacific Standard Time\""); //***************************************************************** // THE FOLLOWING LINES MUST BE UPDATED IF THE LOCALE DATA CHANGES // THE FOLLOWING LINES MUST BE UPDATED IF THE LOCALE DATA CHANGES // THE FOLLOWING LINES MUST BE UPDATED IF THE LOCALE DATA CHANGES //***************************************************************** Object[] DATA = { new Boolean(false), new Integer(TimeZone.SHORT), "PST", new Boolean(true), new Integer(TimeZone.SHORT), "PDT", new Boolean(false), new Integer(TimeZone.LONG), "Pacific Standard Time", new Boolean(true), new Integer(TimeZone.LONG), "Pacific Daylight Time", }; for (int i=0; i<DATA.length; i+=3) { name = zone.getDisplayName(((Boolean)DATA[i]).booleanValue(), ((Integer)DATA[i+1]).intValue(), Locale.ENGLISH); if (!name.equals(DATA[i+2])) errln("Fail: Expected " + DATA[i+2] + "; got " + name); } // Make sure that we don't display the DST name by constructing a fake // PST zone that has DST all year long. SimpleTimeZone zone2 = new SimpleTimeZone(0, "PST"); zone2.setStartRule(Calendar.JANUARY, 1, 0); zone2.setEndRule(Calendar.DECEMBER, 31, 0); logln("Modified PST inDaylightTime->" + zone2.inDaylightTime(new Date())); name = zone2.getDisplayName(Locale.ENGLISH); logln("Modified PST->" + name); if (!name.equals("Pacific Standard Time")) errln("Fail: Expected \"Pacific Standard Time\""); // Make sure we get the default display format for Locales // with no display name data. Locale zh_CN = Locale.SIMPLIFIED_CHINESE; name = zone.getDisplayName(zh_CN); //***************************************************************** // THE FOLLOWING LINE MUST BE UPDATED IF THE LOCALE DATA CHANGES // THE FOLLOWING LINE MUST BE UPDATED IF THE LOCALE DATA CHANGES // THE FOLLOWING LINE MUST BE UPDATED IF THE LOCALE DATA CHANGES //***************************************************************** logln("PST(zh_CN)->" + name); // Now be smart -- check to see if zh resource is even present. // If not, we expect the en fallback behavior. ResourceBundle enRB = LocaleData.getBundle("sun.util.resources.TimeZoneNames", Locale.ENGLISH); ResourceBundle zhRB = LocaleData.getBundle("sun.util.resources.TimeZoneNames", zh_CN); boolean noZH = enRB == zhRB; if (noZH) { logln("Warning: Not testing the zh_CN behavior because resource is absent"); if (!name.equals("Pacific Standard Time")) errln("Fail: Expected Pacific Standard Time"); } else if (!name.equals("Pacific Standard Time") && !name.equals("\u592a\u5e73\u6d0b\u6807\u51c6\u65f6\u95f4") && !name.equals("GMT-08:00") && !name.equals("GMT-8:00") && !name.equals("GMT-0800") && !name.equals("GMT-800")) { errln("Fail: Expected GMT-08:00 or something similar"); errln("************************************************************"); errln("THE ABOVE FAILURE MAY JUST MEAN THE LOCALE DATA HAS CHANGED"); errln("************************************************************"); } // Now try a non-existent zone zone2 = new SimpleTimeZone(90*60*1000, "xyzzy"); name = zone2.getDisplayName(Locale.ENGLISH); logln("GMT+90min->" + name); if (!name.equals("GMT+01:30") && !name.equals("GMT+1:30") && !name.equals("GMT+0130") && !name.equals("GMT+130")) errln("Fail: Expected GMT+01:30 or something similar"); }