1 /*
2  * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * This code is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 2 only, as
7  * published by the Free Software Foundation.
8  *
9  * This code is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12  * version 2 for more details (a copy is included in the LICENSE file that
13  * accompanied this code).
14  *
15  * You should have received a copy of the GNU General Public License version
16  * 2 along with this work; if not, write to the Free Software Foundation,
17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18  *
19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20  * or visit www.oracle.com if you need additional information or have any
21  * questions.
22  */
23 
24 /*
25  *
26  * @test
27  * @bug 8215181 8230284 8231273
28  * @summary Tests the "u-cf" extension
29  * @modules jdk.localedata
30  * @run testng/othervm -Djava.locale.providers=CLDR CurrencyFormatTests
31  */
32 
33 import static org.testng.Assert.assertEquals;
34 
35 import java.text.NumberFormat;
36 import java.util.Locale;
37 
38 import org.testng.annotations.DataProvider;
39 import org.testng.annotations.Test;
40 
41 /**
42  * Test NumberFormat with BCP47 u-cf extensions. Note that this test depends
43  * on the particular CLDR release. Results may vary on other CLDR releases.
44  */
45 @Test
46 public class CurrencyFormatTests {
47 
48     @DataProvider(name="getInstanceData")
getInstanceData()49     Object[][] getInstanceData() {
50         return new Object[][] {
51             // Locale, amount, expected
52             // US dollar
53             {Locale.US, -100, "-$100.00"},
54             {Locale.forLanguageTag("en-US-u-cf-standard"), -100, "-$100.00"},
55             {Locale.forLanguageTag("en-US-u-cf-account"), -100, "($100.00)"},
56             {Locale.forLanguageTag("en-US-u-cf-bogus"), -100, "-$100.00"},
57 
58             // Euro
59             {Locale.forLanguageTag("en-AT"), -100, "-\u20ac\u00a0100,00"},
60             {Locale.forLanguageTag("en-AT-u-cf-standard"), -100, "-\u20ac\u00a0100,00"},
61             {Locale.forLanguageTag("en-AT-u-cf-account"), -100, "-\u20ac\u00a0100,00"},
62             {Locale.forLanguageTag("en-AT-u-cf-bogus"), -100, "-\u20ac\u00a0100,00"},
63 
64             // Rupee
65             {Locale.forLanguageTag("en-IN"), -100, "-\u20b9100.00"},
66             {Locale.forLanguageTag("en-IN-u-cf-standard"), -100, "-\u20b9100.00"},
67             {Locale.forLanguageTag("en-IN-u-cf-account"), -100, "(\u20b9100.00)"},
68             {Locale.forLanguageTag("en-IN-u-cf-bogus"), -100, "-\u20b9100.00"},
69 
70             // Swiss franc
71             {Locale.forLanguageTag("en-CH"), -100, "CHF-100.00"},
72             {Locale.forLanguageTag("en-CH-u-cf-standard"), -100, "CHF-100.00"},
73             {Locale.forLanguageTag("en-CH-u-cf-account"), -100, "CHF-100.00"},
74             {Locale.forLanguageTag("en-CH-u-cf-bogus"), -100, "CHF-100.00"},
75 
76             // Region override
77             {Locale.forLanguageTag("en-US-u-rg-CHZZZZ"), -100, "CHF-100.00"},
78             {Locale.forLanguageTag("en-US-u-rg-CHZZZZ-cf-standard"), -100, "CHF-100.00"},
79             {Locale.forLanguageTag("en-US-u-rg-CHZZZZ-cf-account"), -100, "CHF-100.00"},
80             {Locale.forLanguageTag("en-US-u-rg-CHZZZZ-cf-bogus"), -100, "CHF-100.00"},
81 
82             // Numbering systems
83             // explicit
84             {Locale.forLanguageTag("zh-CN-u-nu-arab"), -100, "\u061c-\u00a5\u0661\u0660\u0660\u066b\u0660\u0660"},
85             {Locale.forLanguageTag("zh-CN-u-nu-arab-cf-standard"), -100, "\u061c-\u00a5\u0661\u0660\u0660\u066b\u0660\u0660"},
86             {Locale.forLanguageTag("zh-CN-u-nu-arab-cf-account"), -100, "\u061c-\u00a5\u0661\u0660\u0660\u066b\u0660\u0660"},
87             {Locale.forLanguageTag("zh-CN-u-nu-arab-cf-bogus"), -100, "\u061c-\u00a5\u0661\u0660\u0660\u066b\u0660\u0660"},
88             // implicit
89             {Locale.forLanguageTag("zh-CN"), -100, "-\u00a5100.00"},
90             {Locale.forLanguageTag("zh-CN-u-cf-standard"), -100, "-\u00a5100.00"},
91             {Locale.forLanguageTag("zh-CN-u-cf-account"), -100, "(\u00a5100.00)"},
92             {Locale.forLanguageTag("zh-CN-u-cf-bogus"), -100, "-\u00a5100.00"},
93             {Locale.forLanguageTag("ar-SA"), -100, "\u061c-\u0661\u0660\u0660\u066b\u0660\u0660\u00a0\u0631.\u0633.\u200f"},
94             {Locale.forLanguageTag("ar-SA-u-cf-standard"), -100, "\u061c-\u0661\u0660\u0660\u066b\u0660\u0660\u00a0\u0631.\u0633.\u200f"},
95             {Locale.forLanguageTag("ar-SA-u-cf-account"), -100, "\u061c-\u0661\u0660\u0660\u066b\u0660\u0660\u00a0\u0631.\u0633.\u200f"},
96             {Locale.forLanguageTag("ar-SA-u-cf-bogus"), -100, "\u061c-\u0661\u0660\u0660\u066b\u0660\u0660\u00a0\u0631.\u0633.\u200f"},
97         };
98     }
99 
100     @Test(dataProvider="getInstanceData")
test_getInstance(Locale locale, int amount, String expected)101     public void test_getInstance(Locale locale, int amount, String expected) {
102         assertEquals(NumberFormat.getCurrencyInstance(locale).format(amount), expected);
103     }
104 }
105