< prev index next >

test/jdk/java/text/Format/NumberFormat/CurrencyFormat.java

Print this page
rev 57525 : 8227313: Support monetary grouping separator in DecimalFormat/DecimalFormatSymbols
Reviewed-by: joehw

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2020, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.

@@ -21,14 +21,15 @@
  * questions.
  */
 
 /*
  * @test
- * @bug 4290801 4942982 5102005 8008577 8021121 8210153
+ * @bug 4290801 4942982 5102005 8008577 8021121 8210153 8227313
  * @summary Basic tests for currency formatting.
  * @modules jdk.localedata
- * @run main/othervm -Djava.locale.providers=JRE,SPI CurrencyFormat
+ * @run main/othervm -Djava.locale.providers=COMPAT CurrencyFormat COMPAT
+ * @run main/othervm -Djava.locale.providers=CLDR CurrencyFormat CLDR
  */
 
 import java.io.File;
 import java.io.FileInputStream;
 import java.util.Currency;

@@ -40,11 +41,14 @@
 import java.text.NumberFormat;
 import java.text.SimpleDateFormat;
 
 public class CurrencyFormat {
 
+    private static boolean isCompat;
+
     public static void main(String[] args) throws Exception {
+        isCompat = "COMPAT".equals(args[0]);
         testFormatting();
         testSymbols();
     }
 
     static void testFormatting() {

@@ -52,11 +56,14 @@
         Locale[] locales = {
             Locale.US,
             Locale.JAPAN,
             Locale.GERMANY,
             Locale.ITALY,
-            new Locale("it", "IT", "EURO") };
+            new Locale("it", "IT", "EURO"),
+            Locale.forLanguageTag("de-AT"),
+            Locale.forLanguageTag("fr-CH"),
+        };
         Currency[] currencies = {
             null,
             Currency.getInstance("USD"),
             Currency.getInstance("JPY"),
             Currency.getInstance("DEM"),

@@ -66,18 +73,29 @@
             {"$1,234.56", "$1,234.56", "JPY1,235", "DEM1,234.56", "EUR1,234.56"},
             {"\uFFE51,235", "USD1,234.56", "\uFFE51,235", "DEM1,234.56", "EUR1,234.56"},
             {"1.234,56 \u20AC", "1.234,56 USD", "1.235 JPY", "1.234,56 DM", "1.234,56 \u20AC"},
             {"\u20AC 1.234,56", "USD 1.234,56", "JPY 1.235", "DEM 1.234,56", "\u20AC 1.234,56"},
             {"\u20AC 1.234,56", "USD 1.234,56", "JPY 1.235", "DEM 1.234,56", "\u20AC 1.234,56"},
+            {"\u20AC 1.234,56", "USD 1.234,56", "JPY 1.235", "DEM 1.234,56", "\u20AC 1.234,56"},
+            {"SFr. 1'234.56", "USD 1'234.56", "JPY 1'235", "DEM 1'234.56", "EUR 1'234.56"},
+        };
+        String[][] expecteds_cldr = {
+            {"$1,234.56", "$1,234.56", "\u00a51,235", "DEM1,234.56", "\u20ac1,234.56"},
+            {"\uFFE51,235", "$1,234.56", "\uFFE51,235", "DEM1,234.56", "\u20ac1,234.56"},
+            {"1.234,56\u00a0\u20ac", "1.234,56\u00a0$", "1.235\u00a0\u00a5", "1.234,56\u00a0DM", "1.234,56\u00a0\u20ac"},
+            {"1.234,56\u00a0\u20ac", "1.234,56\u00a0USD", "1.235\u00a0JPY", "1.234,56\u00a0DEM", "1.234,56\u00a0\u20ac"},
+            {"1.234,56\u00a0\u20ac", "1.234,56\u00a0USD", "1.235\u00a0JPY", "1.234,56\u00a0DEM", "1.234,56\u00a0\u20ac"},
+            {"\u20ac\u00a01.234,56", "$\u00a01.234,56", "\u00a5\u00a01.235", "DM\u00a01.234,56", "\u20ac\u00a01.234,56"},
+            {"1\u202f234.56\u00a0CHF", "1\u202f234.56\u00a0$US", "1\u202f235\u00a0JPY", "1\u202f234.56\u00a0DEM", "1\u202f234.56\u00a0\u20ac"},
         };
 
         for (int i = 0; i < locales.length; i++) {
             Locale locale = locales[i];
             NumberFormat format = NumberFormat.getCurrencyInstance(locale);
             for (int j = 0; j < currencies.length; j++) {
                 Currency currency = currencies[j];
-                String expected = expecteds[i][j];
+                String expected = isCompat ? expecteds[i][j] : expecteds_cldr[i][j];
                 if (currency != null) {
                     format.setCurrency(currency);
                     int digits = currency.getDefaultFractionDigits();
                     format.setMinimumFractionDigits(digits);
                     format.setMaximumFractionDigits(digits);

@@ -97,10 +115,15 @@
             throw new RuntimeException();
         }
     }
 
     static void testSymbols() throws Exception {
+        if (!isCompat) {
+            // For COMPAT only.
+            return;
+        }
+
         FileInputStream stream = new FileInputStream(new File(System.getProperty("test.src", "."), "CurrencySymbols.properties"));
         Properties props = new Properties();
         props.load(stream);
         SimpleDateFormat format = null;
 
< prev index next >