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
28 * @summary Tests the "u-cf" extension
29 * @modules jdk.localedata
30 * @run testng/othervm 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")
49 Object[][] getInstanceData() {
50 return new Object[][] {
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, "-\u20b9\u00a0100.00"},
66 {Locale.forLanguageTag("en-IN-u-cf-standard"), -100, "-\u20b9\u00a0100.00"},
67 {Locale.forLanguageTag("en-IN-u-cf-account"), -100, "(\u20b9100.00)"},
68 {Locale.forLanguageTag("en-IN-u-cf-bogus"), -100, "-\u20b9\u00a0100.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 }
83
84 @Test(dataProvider="getInstanceData")
85 public void test_getInstance(Locale locale, int amount, String expected) {
86 assertEquals(NumberFormat.getCurrencyInstance(locale).format(amount), expected);
87 }
88 }
|
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
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")
49 Object[][] getInstanceData() {
50 return new Object[][] {
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, "-\u20b9\u00a0100.00"},
66 {Locale.forLanguageTag("en-IN-u-cf-standard"), -100, "-\u20b9\u00a0100.00"},
67 {Locale.forLanguageTag("en-IN-u-cf-account"), -100, "(\u20b9100.00)"},
68 {Locale.forLanguageTag("en-IN-u-cf-bogus"), -100, "-\u20b9\u00a0100.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-\uffe5\u0661\u0660\u0660\u066b\u0660\u0660"},
85 {Locale.forLanguageTag("zh-CN-u-nu-arab-cf-standard"), -100, "\u061c-\uffe5\u0661\u0660\u0660\u066b\u0660\u0660"},
86 {Locale.forLanguageTag("zh-CN-u-nu-arab-cf-account"), -100, "\u061c-\uffe5\u0661\u0660\u0660\u066b\u0660\u0660"},
87 {Locale.forLanguageTag("zh-CN-u-nu-arab-cf-bogus"), -100, "\u061c-\uffe5\u0661\u0660\u0660\u066b\u0660\u0660"},
88 // implicit
89 {Locale.forLanguageTag("zh-CN"), -100, "-\uffe5100.00"},
90 {Locale.forLanguageTag("zh-CN-u-cf-standard"), -100, "-\uffe5100.00"},
91 {Locale.forLanguageTag("zh-CN-u-cf-account"), -100, "(\uffe5100.00)"},
92 {Locale.forLanguageTag("zh-CN-u-cf-bogus"), -100, "-\uffe5100.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")
101 public void test_getInstance(Locale locale, int amount, String expected) {
102 assertEquals(NumberFormat.getCurrencyInstance(locale).format(amount), expected);
103 }
104 }
|