1 /*
2 * Copyright (c) 2010, 2016, 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 */
27 import java.io.File;
28 import java.io.FileInputStream;
29 import java.io.InputStreamReader;
30 import java.io.ObjectInputStream;
31 import java.io.ObjectOutputStream;
32 import java.net.URISyntaxException;
33 import java.net.URL;
34 import java.text.DecimalFormatSymbols;
35 import java.util.ArrayList;
36 import java.util.Arrays;
37 import java.util.Calendar;
38 import java.util.IllformedLocaleException;
39 import java.util.List;
40 import java.util.Locale;
41 import java.util.Locale.Builder;
42 import java.util.Set;
43
44 /**
45 * @test
46 * @bug 6875847 6992272 7002320 7015500 7023613 7032820 7033504 7004603
47 * 7044019 8008577
48 * @summary test API changes to Locale
49 * @library /java/text/testlib
50 * @modules jdk.localedata
51 * @compile LocaleEnhanceTest.java
52 * @run main/othervm -Djava.locale.providers=JRE,SPI -esa LocaleEnhanceTest
53 */
54 public class LocaleEnhanceTest extends IntlTest {
55
56 public static void main(String[] args) throws Exception {
57 List<String> argList = new ArrayList<String>();
58 argList.addAll(Arrays.asList(args));
59 argList.add("-nothrow");
60 new LocaleEnhanceTest().run(argList.toArray(new String[argList.size()]));
61 }
62
63 public LocaleEnhanceTest() {
64 }
65
66 ///
67 /// Generic sanity tests
1015 .build();
1016
1017 Set<String> uattrs = locale.getUnicodeLocaleAttributes();
1018 assertEquals("number of attributes", 2, uattrs.size());
1019 assertTrue("attribute abc", uattrs.contains("abc"));
1020 assertTrue("attribute def", uattrs.contains("def"));
1021
1022 // remove attribute
1023 locale = builder.removeUnicodeLocaleAttribute("xxx")
1024 .build();
1025
1026 assertEquals("remove bogus", 2, uattrs.size());
1027
1028 // add duplicate
1029 locale = builder.addUnicodeLocaleAttribute("abc")
1030 .build();
1031 assertEquals("add duplicate", 2, uattrs.size());
1032
1033 // null attribute throws NPE
1034 new BuilderNPE("null attribute") { public void call() { b.addUnicodeLocaleAttribute(null); }};
1035
1036 // illformed attribute throws IllformedLocaleException
1037 new BuilderILE("invalid attribute") { public void call() { b.addUnicodeLocaleAttribute("ca"); }};
1038 }
1039
1040 public void testBuildersetUnicodeLocaleKeyword() {
1041 // Note: most behavior is tested in testBuilderSetExtension
1042 Builder builder = new Builder();
1043 Locale locale = builder
1044 .setUnicodeLocaleKeyword("co", "japanese")
1045 .setUnicodeLocaleKeyword("nu", "thai")
1046 .build();
1047 assertEquals("co", "japanese", locale.getUnicodeLocaleType("co"));
1048 assertEquals("nu", "thai", locale.getUnicodeLocaleType("nu"));
1049 assertEquals("keys", 2, locale.getUnicodeLocaleKeys().size());
1050
1051 // can clear a keyword by setting to null, others remain
1052 String result = builder
1053 .setUnicodeLocaleKeyword("co", null)
1054 .build()
|
1 /*
2 * Copyright (c) 2010, 2017, 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 */
27 import java.io.File;
28 import java.io.FileInputStream;
29 import java.io.InputStreamReader;
30 import java.io.ObjectInputStream;
31 import java.io.ObjectOutputStream;
32 import java.net.URISyntaxException;
33 import java.net.URL;
34 import java.text.DecimalFormatSymbols;
35 import java.util.ArrayList;
36 import java.util.Arrays;
37 import java.util.Calendar;
38 import java.util.IllformedLocaleException;
39 import java.util.List;
40 import java.util.Locale;
41 import java.util.Locale.Builder;
42 import java.util.Set;
43
44 /**
45 * @test
46 * @bug 6875847 6992272 7002320 7015500 7023613 7032820 7033504 7004603
47 * 7044019 8008577 8176853
48 * @summary test API changes to Locale
49 * @library /java/text/testlib
50 * @modules jdk.localedata
51 * @compile LocaleEnhanceTest.java
52 * @run main/othervm -Djava.locale.providers=JRE,SPI -esa LocaleEnhanceTest
53 */
54 public class LocaleEnhanceTest extends IntlTest {
55
56 public static void main(String[] args) throws Exception {
57 List<String> argList = new ArrayList<String>();
58 argList.addAll(Arrays.asList(args));
59 argList.add("-nothrow");
60 new LocaleEnhanceTest().run(argList.toArray(new String[argList.size()]));
61 }
62
63 public LocaleEnhanceTest() {
64 }
65
66 ///
67 /// Generic sanity tests
1015 .build();
1016
1017 Set<String> uattrs = locale.getUnicodeLocaleAttributes();
1018 assertEquals("number of attributes", 2, uattrs.size());
1019 assertTrue("attribute abc", uattrs.contains("abc"));
1020 assertTrue("attribute def", uattrs.contains("def"));
1021
1022 // remove attribute
1023 locale = builder.removeUnicodeLocaleAttribute("xxx")
1024 .build();
1025
1026 assertEquals("remove bogus", 2, uattrs.size());
1027
1028 // add duplicate
1029 locale = builder.addUnicodeLocaleAttribute("abc")
1030 .build();
1031 assertEquals("add duplicate", 2, uattrs.size());
1032
1033 // null attribute throws NPE
1034 new BuilderNPE("null attribute") { public void call() { b.addUnicodeLocaleAttribute(null); }};
1035 new BuilderNPE("null attribute removal") { public void call() { b.removeUnicodeLocaleAttribute(null); }};
1036
1037 // illformed attribute throws IllformedLocaleException
1038 new BuilderILE("invalid attribute") { public void call() { b.addUnicodeLocaleAttribute("ca"); }};
1039 }
1040
1041 public void testBuildersetUnicodeLocaleKeyword() {
1042 // Note: most behavior is tested in testBuilderSetExtension
1043 Builder builder = new Builder();
1044 Locale locale = builder
1045 .setUnicodeLocaleKeyword("co", "japanese")
1046 .setUnicodeLocaleKeyword("nu", "thai")
1047 .build();
1048 assertEquals("co", "japanese", locale.getUnicodeLocaleType("co"));
1049 assertEquals("nu", "thai", locale.getUnicodeLocaleType("nu"));
1050 assertEquals("keys", 2, locale.getUnicodeLocaleKeys().size());
1051
1052 // can clear a keyword by setting to null, others remain
1053 String result = builder
1054 .setUnicodeLocaleKeyword("co", null)
1055 .build()
|