jdk/test/java/awt/font/FontNames/LocaleFamilyNames.java
author prr
Fri, 21 Jan 2011 08:04:04 -0800
changeset 7950 dc8f97e15f9b
child 9035 1255eb81cc2f
permissions -rw-r--r--
6892138: Windows GDI platform font lookup apis affect start-up for small UI apps Reviewed-by: igor, jgodinez
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7950
dc8f97e15f9b 6892138: Windows GDI platform font lookup apis affect start-up for small UI apps
prr
parents:
diff changeset
     1
/*
dc8f97e15f9b 6892138: Windows GDI platform font lookup apis affect start-up for small UI apps
prr
parents:
diff changeset
     2
 * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
dc8f97e15f9b 6892138: Windows GDI platform font lookup apis affect start-up for small UI apps
prr
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
dc8f97e15f9b 6892138: Windows GDI platform font lookup apis affect start-up for small UI apps
prr
parents:
diff changeset
     4
 *
dc8f97e15f9b 6892138: Windows GDI platform font lookup apis affect start-up for small UI apps
prr
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
dc8f97e15f9b 6892138: Windows GDI platform font lookup apis affect start-up for small UI apps
prr
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
dc8f97e15f9b 6892138: Windows GDI platform font lookup apis affect start-up for small UI apps
prr
parents:
diff changeset
     7
 * published by the Free Software Foundation.
dc8f97e15f9b 6892138: Windows GDI platform font lookup apis affect start-up for small UI apps
prr
parents:
diff changeset
     8
 *
dc8f97e15f9b 6892138: Windows GDI platform font lookup apis affect start-up for small UI apps
prr
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
dc8f97e15f9b 6892138: Windows GDI platform font lookup apis affect start-up for small UI apps
prr
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
dc8f97e15f9b 6892138: Windows GDI platform font lookup apis affect start-up for small UI apps
prr
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
dc8f97e15f9b 6892138: Windows GDI platform font lookup apis affect start-up for small UI apps
prr
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
dc8f97e15f9b 6892138: Windows GDI platform font lookup apis affect start-up for small UI apps
prr
parents:
diff changeset
    13
 * accompanied this code).
dc8f97e15f9b 6892138: Windows GDI platform font lookup apis affect start-up for small UI apps
prr
parents:
diff changeset
    14
 *
dc8f97e15f9b 6892138: Windows GDI platform font lookup apis affect start-up for small UI apps
prr
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
dc8f97e15f9b 6892138: Windows GDI platform font lookup apis affect start-up for small UI apps
prr
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
dc8f97e15f9b 6892138: Windows GDI platform font lookup apis affect start-up for small UI apps
prr
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
dc8f97e15f9b 6892138: Windows GDI platform font lookup apis affect start-up for small UI apps
prr
parents:
diff changeset
    18
 *
dc8f97e15f9b 6892138: Windows GDI platform font lookup apis affect start-up for small UI apps
prr
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
dc8f97e15f9b 6892138: Windows GDI platform font lookup apis affect start-up for small UI apps
prr
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
dc8f97e15f9b 6892138: Windows GDI platform font lookup apis affect start-up for small UI apps
prr
parents:
diff changeset
    21
 * questions.
dc8f97e15f9b 6892138: Windows GDI platform font lookup apis affect start-up for small UI apps
prr
parents:
diff changeset
    22
 */
dc8f97e15f9b 6892138: Windows GDI platform font lookup apis affect start-up for small UI apps
prr
parents:
diff changeset
    23
dc8f97e15f9b 6892138: Windows GDI platform font lookup apis affect start-up for small UI apps
prr
parents:
diff changeset
    24
/*
dc8f97e15f9b 6892138: Windows GDI platform font lookup apis affect start-up for small UI apps
prr
parents:
diff changeset
    25
 * @test
dc8f97e15f9b 6892138: Windows GDI platform font lookup apis affect start-up for small UI apps
prr
parents:
diff changeset
    26
 * @bug 4935798 6521210 6901159
dc8f97e15f9b 6892138: Windows GDI platform font lookup apis affect start-up for small UI apps
prr
parents:
diff changeset
    27
 * @summary Tests that all family names that are reported in all locales
dc8f97e15f9b 6892138: Windows GDI platform font lookup apis affect start-up for small UI apps
prr
parents:
diff changeset
    28
 * correspond to some font returned from getAllFonts().
dc8f97e15f9b 6892138: Windows GDI platform font lookup apis affect start-up for small UI apps
prr
parents:
diff changeset
    29
 * @run main LocaleFamilyNames
dc8f97e15f9b 6892138: Windows GDI platform font lookup apis affect start-up for small UI apps
prr
parents:
diff changeset
    30
 */
dc8f97e15f9b 6892138: Windows GDI platform font lookup apis affect start-up for small UI apps
prr
parents:
diff changeset
    31
import java.awt.*;
dc8f97e15f9b 6892138: Windows GDI platform font lookup apis affect start-up for small UI apps
prr
parents:
diff changeset
    32
import java.util.*;
dc8f97e15f9b 6892138: Windows GDI platform font lookup apis affect start-up for small UI apps
prr
parents:
diff changeset
    33
dc8f97e15f9b 6892138: Windows GDI platform font lookup apis affect start-up for small UI apps
prr
parents:
diff changeset
    34
public class LocaleFamilyNames {
dc8f97e15f9b 6892138: Windows GDI platform font lookup apis affect start-up for small UI apps
prr
parents:
diff changeset
    35
    public static void main(String[] args) throws Exception {
dc8f97e15f9b 6892138: Windows GDI platform font lookup apis affect start-up for small UI apps
prr
parents:
diff changeset
    36
dc8f97e15f9b 6892138: Windows GDI platform font lookup apis affect start-up for small UI apps
prr
parents:
diff changeset
    37
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
dc8f97e15f9b 6892138: Windows GDI platform font lookup apis affect start-up for small UI apps
prr
parents:
diff changeset
    38
dc8f97e15f9b 6892138: Windows GDI platform font lookup apis affect start-up for small UI apps
prr
parents:
diff changeset
    39
        Font[] all_fonts = ge.getAllFonts();
dc8f97e15f9b 6892138: Windows GDI platform font lookup apis affect start-up for small UI apps
prr
parents:
diff changeset
    40
dc8f97e15f9b 6892138: Windows GDI platform font lookup apis affect start-up for small UI apps
prr
parents:
diff changeset
    41
        Locale[] all_locales = Locale.getAvailableLocales();
dc8f97e15f9b 6892138: Windows GDI platform font lookup apis affect start-up for small UI apps
prr
parents:
diff changeset
    42
dc8f97e15f9b 6892138: Windows GDI platform font lookup apis affect start-up for small UI apps
prr
parents:
diff changeset
    43
        HashSet all_families = new HashSet();
dc8f97e15f9b 6892138: Windows GDI platform font lookup apis affect start-up for small UI apps
prr
parents:
diff changeset
    44
        for (int i=0; i<all_fonts.length; i++) {
dc8f97e15f9b 6892138: Windows GDI platform font lookup apis affect start-up for small UI apps
prr
parents:
diff changeset
    45
            all_families.add(all_fonts[i].getFamily());
dc8f97e15f9b 6892138: Windows GDI platform font lookup apis affect start-up for small UI apps
prr
parents:
diff changeset
    46
            for (int j=0; j<all_locales.length;j++) {
dc8f97e15f9b 6892138: Windows GDI platform font lookup apis affect start-up for small UI apps
prr
parents:
diff changeset
    47
              all_families.add(all_fonts[i].getFamily(all_locales[j]));
dc8f97e15f9b 6892138: Windows GDI platform font lookup apis affect start-up for small UI apps
prr
parents:
diff changeset
    48
            }
dc8f97e15f9b 6892138: Windows GDI platform font lookup apis affect start-up for small UI apps
prr
parents:
diff changeset
    49
dc8f97e15f9b 6892138: Windows GDI platform font lookup apis affect start-up for small UI apps
prr
parents:
diff changeset
    50
        }
dc8f97e15f9b 6892138: Windows GDI platform font lookup apis affect start-up for small UI apps
prr
parents:
diff changeset
    51
dc8f97e15f9b 6892138: Windows GDI platform font lookup apis affect start-up for small UI apps
prr
parents:
diff changeset
    52
dc8f97e15f9b 6892138: Windows GDI platform font lookup apis affect start-up for small UI apps
prr
parents:
diff changeset
    53
        for (int i=0; i<all_locales.length; i++) {
dc8f97e15f9b 6892138: Windows GDI platform font lookup apis affect start-up for small UI apps
prr
parents:
diff changeset
    54
            String[] families_for_locale =
dc8f97e15f9b 6892138: Windows GDI platform font lookup apis affect start-up for small UI apps
prr
parents:
diff changeset
    55
                 ge.getAvailableFontFamilyNames(all_locales[i]);
dc8f97e15f9b 6892138: Windows GDI platform font lookup apis affect start-up for small UI apps
prr
parents:
diff changeset
    56
            for (int j=0; j<families_for_locale.length; j++) {
dc8f97e15f9b 6892138: Windows GDI platform font lookup apis affect start-up for small UI apps
prr
parents:
diff changeset
    57
                if ( !all_families.contains(families_for_locale[j]) ) {
dc8f97e15f9b 6892138: Windows GDI platform font lookup apis affect start-up for small UI apps
prr
parents:
diff changeset
    58
                    System.out.println("LOCALE: [" + all_locales[i]+"]");
dc8f97e15f9b 6892138: Windows GDI platform font lookup apis affect start-up for small UI apps
prr
parents:
diff changeset
    59
                    System.out.print("NO FONT HAS " +
dc8f97e15f9b 6892138: Windows GDI platform font lookup apis affect start-up for small UI apps
prr
parents:
diff changeset
    60
                                       "THE FOLLOWING FAMILY NAME:");
dc8f97e15f9b 6892138: Windows GDI platform font lookup apis affect start-up for small UI apps
prr
parents:
diff changeset
    61
                    System.out.println("["+families_for_locale[j]+"]");
dc8f97e15f9b 6892138: Windows GDI platform font lookup apis affect start-up for small UI apps
prr
parents:
diff changeset
    62
                    throw new Exception("test failed");
dc8f97e15f9b 6892138: Windows GDI platform font lookup apis affect start-up for small UI apps
prr
parents:
diff changeset
    63
                }
dc8f97e15f9b 6892138: Windows GDI platform font lookup apis affect start-up for small UI apps
prr
parents:
diff changeset
    64
            }
dc8f97e15f9b 6892138: Windows GDI platform font lookup apis affect start-up for small UI apps
prr
parents:
diff changeset
    65
        }
dc8f97e15f9b 6892138: Windows GDI platform font lookup apis affect start-up for small UI apps
prr
parents:
diff changeset
    66
    }
dc8f97e15f9b 6892138: Windows GDI platform font lookup apis affect start-up for small UI apps
prr
parents:
diff changeset
    67
}