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 @test
26 @bug 4219630 4304573 4533872 4900935 8042589
27 @summary toUpperCase should upper-case German sharp s correctly even if
28 it's the only character in the string. should also uppercase
29 all of the 1:M char mappings correctly. Also it should handle
30 Locale specific (lt, tr, and az) uppercasings and supplementary
31 characters correctly.
32 */
33
34 import java.util.Locale;
35
36 public class ToUpperCase {
37
38 public static void main(String[] args) {
39 Locale turkish = new Locale("tr", "TR");
40 Locale lt = new Locale("lt"); // Lithanian
41 Locale az = new Locale("az"); // Azeri
42
43 test("\u00DF", turkish, "SS");
44 test("a\u00DF", turkish, "ASS");
45 test("i", turkish, "\u0130");
46 test("i", az, "\u0130");
80 // Supplementary character tests
81 //
82 // U+10400 ("\uD801\uDC00"): DESERET CAPITAL LETTER LONG I
83 // U+10401 ("\uD801\uDC01"): DESERET CAPITAL LETTER LONG E
84 // U+10402 ("\uD801\uDC02"): DESERET CAPITAL LETTER LONG A
85 // U+10428 ("\uD801\uDC28"): DESERET SMALL LETTER LONG I
86 // U+10429 ("\uD801\uDC29"): DESERET SMALL LETTER LONG E
87 // U+1042A ("\uD801\uDC2A"): DESERET SMALL LETTER LONG A
88 //
89 // valid code point tests:
90 test("\uD801\uDC28\uD801\uDC29\uD801\uDC2A", Locale.US, "\uD801\uDC00\uD801\uDC01\uD801\uDC02");
91 test("\uD801\uDC28a\uD801\uDC29b\uD801\uDC2Ac", Locale.US, "\uD801\uDC00A\uD801\uDC01B\uD801\uDC02C");
92 // invalid code point tests:
93 test("\uD800\uD800\uD801a\uDC00\uDC00\uDC00b", Locale.US, "\uD800\uD800\uD801A\uDC00\uDC00\uDC00B");
94
95 // lower/uppercase + surrogates
96 test("a\uD801\uDC44", Locale.ROOT, "A\uD801\uDC1c");
97 test("A\uD801\uDC44", Locale.ROOT, "A\uD801\uDC1c");
98 test("a\uD801\uDC28\uD801\uDC29\uD801\uDC2A", Locale.US, "A\uD801\uDC00\uD801\uDC01\uD801\uDC02");
99 test("A\uD801\uDC28a\uD801\uDC29b\uD801\uDC2Ac", Locale.US, "A\uD801\uDC00A\uD801\uDC01B\uD801\uDC02C");
100 }
101
102 static void test(String in, Locale locale, String expected) {
103 String result = in.toUpperCase(locale);
104 if (!result.equals(expected)) {
105 System.err.println("input: " + in + ", locale: " + locale +
106 ", expected: " + expected + ", actual: " + result);
107 throw new RuntimeException();
108 }
109 }
110 }
|
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 @test
26 @bug 4219630 4304573 4533872 4900935 8042589 8054307
27 @summary toUpperCase should upper-case German sharp s correctly even if
28 it's the only character in the string. should also uppercase
29 all of the 1:M char mappings correctly. Also it should handle
30 Locale specific (lt, tr, and az) uppercasings and supplementary
31 characters correctly.
32 */
33
34 import java.util.Locale;
35
36 public class ToUpperCase {
37
38 public static void main(String[] args) {
39 Locale turkish = new Locale("tr", "TR");
40 Locale lt = new Locale("lt"); // Lithanian
41 Locale az = new Locale("az"); // Azeri
42
43 test("\u00DF", turkish, "SS");
44 test("a\u00DF", turkish, "ASS");
45 test("i", turkish, "\u0130");
46 test("i", az, "\u0130");
80 // Supplementary character tests
81 //
82 // U+10400 ("\uD801\uDC00"): DESERET CAPITAL LETTER LONG I
83 // U+10401 ("\uD801\uDC01"): DESERET CAPITAL LETTER LONG E
84 // U+10402 ("\uD801\uDC02"): DESERET CAPITAL LETTER LONG A
85 // U+10428 ("\uD801\uDC28"): DESERET SMALL LETTER LONG I
86 // U+10429 ("\uD801\uDC29"): DESERET SMALL LETTER LONG E
87 // U+1042A ("\uD801\uDC2A"): DESERET SMALL LETTER LONG A
88 //
89 // valid code point tests:
90 test("\uD801\uDC28\uD801\uDC29\uD801\uDC2A", Locale.US, "\uD801\uDC00\uD801\uDC01\uD801\uDC02");
91 test("\uD801\uDC28a\uD801\uDC29b\uD801\uDC2Ac", Locale.US, "\uD801\uDC00A\uD801\uDC01B\uD801\uDC02C");
92 // invalid code point tests:
93 test("\uD800\uD800\uD801a\uDC00\uDC00\uDC00b", Locale.US, "\uD800\uD800\uD801A\uDC00\uDC00\uDC00B");
94
95 // lower/uppercase + surrogates
96 test("a\uD801\uDC44", Locale.ROOT, "A\uD801\uDC1c");
97 test("A\uD801\uDC44", Locale.ROOT, "A\uD801\uDC1c");
98 test("a\uD801\uDC28\uD801\uDC29\uD801\uDC2A", Locale.US, "A\uD801\uDC00\uD801\uDC01\uD801\uDC02");
99 test("A\uD801\uDC28a\uD801\uDC29b\uD801\uDC2Ac", Locale.US, "A\uD801\uDC00A\uD801\uDC01B\uD801\uDC02C");
100
101 // test latin1 only case
102 StringBuilder src = new StringBuilder(0x100);
103 StringBuilder exp = new StringBuilder(0x100);
104 for (int cp = 0; cp < 0x100; cp++) {
105 int upperCase = Character.toUpperCase(cp);
106 if (upperCase == -1) { //Character.ERROR
107 continue;
108 }
109 src.appendCodePoint(cp);
110 if (cp == '\u00df') {
111 exp.append("SS"); // need Character.toUpperCaseEx()
112 } else {
113 exp.appendCodePoint(upperCase);
114 }
115 }
116 test(src.toString(), Locale.US, exp.toString());
117
118 // test non-latin1 -> latin1
119 src = new StringBuilder(0x100).append("ABC");
120 exp = new StringBuilder(0x100).append("ABC");
121 for (int cp = 0x100; cp < 0x10000; cp++) {
122 int upperCase = Character.toUpperCase(cp);
123 if (upperCase < 0x100) {
124 src.appendCodePoint(cp);
125 exp.appendCodePoint(upperCase);
126 }
127 }
128 test(src.toString(), Locale.US, exp.toString());
129
130 }
131
132 static void test(String in, Locale locale, String expected) {
133 test0(in, locale,expected);
134 // trigger different code paths
135 for (String[] ss : new String[][] {
136 new String[] {"abc", "ABC"},
137 new String[] {"AbC", "ABC"},
138 new String[] {"ABC", "ABC"},
139 new String[] {"AB\u4e00", "AB\u4e00"},
140 new String[] {"ab\u4e00", "AB\u4e00"},
141 new String[] {"aB\u4e00", "AB\u4e00"},
142 new String[] {"AB\uD800\uDC00", "AB\uD800\uDC00"},
143 new String[] {"Ab\uD800\uDC00", "AB\uD800\uDC00"},
144 new String[] {"ab\uD800\uDC00", "AB\uD800\uDC00"},
145 new String[] {"AB\uD801\uDC44", "AB\uD801\uDC1C"},
146 new String[] {"Ab\uD801\uDC44", "AB\uD801\uDC1C"},
147 new String[] {"ab\uD801\uDC44", "AB\uD801\uDC1C"},
148 }) {
149 test0(ss[0] + " " + in, locale, ss[1] + " " + expected);
150 test0(in + " " + ss[0], locale, expected + " " + ss[1]);
151 }
152 }
153
154 static void test0(String in, Locale locale, String expected) {
155 String result = in.toUpperCase(locale);
156 if (!result.equals(expected)) {
157 System.err.println("input: " + in + ", locale: " + locale +
158 ", expected: " + expected + ", actual: " + result);
159 throw new RuntimeException();
160 }
161 }
162 }
|