jdk/test/java/lang/String/ToUpperCase.java
author jbachorik
Tue, 21 Jan 2014 13:04:55 +0100
changeset 22353 d09e3ff5fd63
parent 5506 202f599c92aa
child 25652 3fa5768212c4
permissions -rw-r--r--
8032377: test/java/lang/management/ThreadMXBean/ThreadBlockedCount.java still fails intermittently Reviewed-by: dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 2000, 2003, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
    @test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
    @bug 4219630 4304573 4533872 4900935
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
    @summary toUpperCase should upper-case German sharp s correctly even if
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
             it's the only character in the string. should also uppercase
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
             all of the 1:M char mappings correctly.  Also it should handle
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
             Locale specific (lt, tr, and az) uppercasings and supplementary
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
             characters correctly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.util.Locale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
public class ToUpperCase {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
    public static void main(String[] args) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
        Locale turkish = new Locale("tr", "TR");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
        Locale lt = new Locale("lt"); // Lithanian
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
        Locale az = new Locale("az"); // Azeri
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
        test("\u00DF", turkish, "SS");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
        test("a\u00DF", turkish, "ASS");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
        test("i", turkish, "\u0130");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
        test("i", az, "\u0130");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
        test("\u0131", turkish, "I");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
        test("\u00DF", Locale.GERMANY, "SS");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
        test("a\u00DF", Locale.GERMANY, "ASS");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
        test("i", Locale.GERMANY, "I");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
        // test some of the 1:M uppercase mappings
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
        test("abc\u00DF", Locale.US, "ABC\u0053\u0053");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        test("\u0149abc", Locale.US, "\u02BC\u004EABC");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
        test("\u0149abc", turkish, "\u02BC\u004EABC");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        test("\u1F52", Locale.US, "\u03A5\u0313\u0300");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        test("\u0149\u1F52", Locale.US, "\u02BC\u004E\u03A5\u0313\u0300");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        test("\u1F54ZZZ", Locale.US, "\u03A5\u0313\u0301ZZZ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        test("\u1F54ZZZ", turkish, "\u03A5\u0313\u0301ZZZ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        test("a\u00DF\u1F56", Locale.US, "ASS\u03A5\u0313\u0342");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        test("\u1FAD", turkish, "\u1F6D\u0399");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        test("i\u1FC7", turkish, "\u0130\u0397\u0342\u0399");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        test("i\u1FC7", az, "\u0130\u0397\u0342\u0399");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        test("i\u1FC7", Locale.US, "I\u0397\u0342\u0399");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        test("\uFB04", Locale.US, "\u0046\u0046\u004C");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        test("\uFB17AbCdEfi", turkish, "\u0544\u053DABCDEF\u0130");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        test("\uFB17AbCdEfi", az, "\u0544\u053DABCDEF\u0130");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        // Remove DOT ABOVE after "i" in Lithuanian
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        test("i\u0307", lt, "I");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        test("\u0307", lt, "\u0307");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        test("\u0307i", lt, "\u0307I");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        test("j\u0307", lt, "J");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        test("abci\u0307def", lt, "ABCIDEF");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        test("a\u0307", lt, "A\u0307");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        test("abc\u0307def", lt, "ABC\u0307DEF");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        test("i\u0307", Locale.US, "I\u0307");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        test("i\u0307", turkish, "\u0130\u0307");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        // Supplementary character tests
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        // U+10400 ("\uD801\uDC00"): DESERET CAPITAL LETTER LONG I
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        // U+10401 ("\uD801\uDC01"): DESERET CAPITAL LETTER LONG E
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        // U+10402 ("\uD801\uDC02"): DESERET CAPITAL LETTER LONG A
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        // U+10428 ("\uD801\uDC28"): DESERET SMALL LETTER LONG I
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        // U+10429 ("\uD801\uDC29"): DESERET SMALL LETTER LONG E
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        // U+1042A ("\uD801\uDC2A"): DESERET SMALL LETTER LONG A
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        // valid code point tests:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        test("\uD801\uDC28\uD801\uDC29\uD801\uDC2A", Locale.US, "\uD801\uDC00\uD801\uDC01\uD801\uDC02");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        test("\uD801\uDC28a\uD801\uDC29b\uD801\uDC2Ac", Locale.US, "\uD801\uDC00A\uD801\uDC01B\uD801\uDC02C");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        // invalid code point tests:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        test("\uD800\uD800\uD801a\uDC00\uDC00\uDC00b", Locale.US, "\uD800\uD800\uD801A\uDC00\uDC00\uDC00B");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    static void test(String in, Locale locale, String expected) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        String result = in.toUpperCase(locale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        if (!result.equals(expected)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            System.err.println("input: " + in + ", locale: " + locale +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
                    ", expected: " + expected + ", actual: " + result);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
            throw new RuntimeException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
}