jdk/test/java/awt/font/FontNames/GetLCIDFromLocale.java
author alanb
Thu, 01 Dec 2016 08:57:53 +0000
changeset 42338 a60f280f803c
parent 36899 e766024a0873
permissions -rw-r--r--
8169069: Module system implementation refresh (11/2016) Reviewed-by: plevart, chegar, psandoz, mchung, alanb, dfuchs, naoto, coffeys, weijun Contributed-by: alan.bateman@oracle.com, mandy.chung@oracle.com, claes.redestad@oracle.com, mark.reinhold@oracle.com
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
36899
e766024a0873 8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents: 32286
diff changeset
     7
 * published by the Free Software Foundation.
32286
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
     8
 *
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
     9
 * 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
    10
 * 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
    11
 * 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
    12
 * 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
    13
 * accompanied this code).
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
    14
 *
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
    15
 * 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
    16
 * 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
    17
 * 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
    18
 *
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
    19
 * 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
    20
 * 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
    21
 * questions.
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
    22
 */
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
    23
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
 * @test
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
    26
 * @bug 4351212
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36899
diff changeset
    27
 * @modules java.desktop/sun.font:open
32286
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
    28
 * @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
    29
 */
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
    30
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
    31
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
    32
import java.util.Locale;
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
    33
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
    34
public class GetLCIDFromLocale {
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
     static Method getLCIDMethod = null;
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
    37
     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
    38
        try {
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
    39
            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
    40
            getLCIDMethod =
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
    41
                ttClass.getDeclaredMethod("getLCIDFromLocale",
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
    42
                                           java.util.Locale.class);
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
    43
            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
    44
        } catch (Exception e) {
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
    45
            e.printStackTrace();
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
    46
            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
    47
        }
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
    48
        if (getLCIDMethod == null) {
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
    49
            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
    50
        }
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
    51
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
    52
        test(Locale.US, 0x0409);
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
    53
        test(Locale.GERMAN, 0x0407);
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
    54
        test(Locale.GERMANY, 0x0407);
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
    55
        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
    56
        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
    57
        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
    58
        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
    59
        test(new Locale("??"), 0x0409);
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
    60
        test(new Locale("??", "??"), 0x0409);
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
    61
        test(Locale.KOREA, 0x0412);
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
    62
    }
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
    63
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
    64
    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
    65
        try {
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
    66
            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
    67
            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
    68
            if (lcid != expectedLCID) {
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
    69
                 throw new RuntimeException();
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
    70
            }
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
    71
        } catch (Exception e) {
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
    72
            e.printStackTrace();
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
    73
            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
    74
        }
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
    75
    }
5ffa8d8b4a2d 8132958: [TEST_BUG] Part 1: update client tests failing after changes in setAccessible(true) routine
yan
parents:
diff changeset
    76
}