jdk/test/java/awt/font/FontNames/GetLCIDFromLocale.java
author yan
Thu, 13 Aug 2015 14:20:36 +0300
changeset 32286 5ffa8d8b4a2d
child 36899 e766024a0873
permissions -rw-r--r--
8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine Reviewed-by: alexsch, serb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
32286
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
     1
/*
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
     2
 * Copyright (c) 2002, 2015, Oracle and/or its affiliates. All rights reserved.
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
     4
 *
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
    10
 *
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
    15
 * accompanied this code).
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
    16
 *
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
    20
 *
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
    23
 * questions.
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
    24
 */
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
    25
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
    26
/*
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
    27
 * @test
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
    28
 * @bug 4351212
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
    29
 * @modules java.desktop/sun.font
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
    30
 * @summary Verify that new getLCIDFromLocale method works
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
    31
 */
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
    32
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
    33
import java.lang.reflect.Method;
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
    34
import java.util.Locale;
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
    35
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
    36
public class GetLCIDFromLocale {
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
    37
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
    38
     static Method getLCIDMethod = null;
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
    39
     public static void main(String args[]) {
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
    40
        try {
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
    41
            Class ttClass = Class.forName("sun.font.TrueTypeFont");
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
    42
            getLCIDMethod =
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
    43
                ttClass.getDeclaredMethod("getLCIDFromLocale",
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
    44
                                           java.util.Locale.class);
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
    45
            getLCIDMethod.setAccessible(true); // its private
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
    46
        } catch (Exception e) {
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
    47
            e.printStackTrace();
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
    48
            throw new RuntimeException("Reflection failed");
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
    49
        }
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
    50
        if (getLCIDMethod == null) {
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
    51
            throw new RuntimeException("No method found");
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
    52
        }
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
    53
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
    54
        test(Locale.US, 0x0409);
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
    55
        test(Locale.GERMAN, 0x0407);
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
    56
        test(Locale.GERMANY, 0x0407);
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
    57
        test(new Locale("de", "AT"), 0x0c07);
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
    58
        test(new Locale("ar"), 0x0401);
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
    59
        test(new Locale("ar", "SA"), 0x0401);
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
    60
        test(new Locale("ar", "EG"), 0x0c01);
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
    61
        test(new Locale("??"), 0x0409);
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
    62
        test(new Locale("??", "??"), 0x0409);
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
    63
        test(Locale.KOREA, 0x0412);
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
    64
    }
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
    65
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
    66
    private static void test(Locale locale, int expectedLCID) {
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
    67
        try {
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
    68
            short lcid = (Short)getLCIDMethod.invoke(null, locale);
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
    69
            System.out.println("lcid="+lcid+" expected="+expectedLCID);
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
    70
            if (lcid != expectedLCID) {
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
    71
                 throw new RuntimeException();
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
    72
            }
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
    73
        } catch (Exception e) {
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
    74
            e.printStackTrace();
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
    75
            throw new RuntimeException("Method invocation exception");
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
    76
        }
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
    77
    }
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
    78
}