jdk/test/java/awt/font/Threads/FontThread.java
author vlivanov
Wed, 02 Mar 2016 15:42:03 +0300
changeset 36349 6cc8e6f596b2
parent 5506 202f599c92aa
permissions -rw-r--r--
8151020: [TESTBUG] UnsafeGetStableArrayElement::testL_* fail intermittently Reviewed-by: zmajo, shade
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
532
6eb7f9aa0b05 6640532: Graphics.getFontMetrics() throws NullPointerException
prr
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3111
diff changeset
     2
 * Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved.
532
6eb7f9aa0b05 6640532: Graphics.getFontMetrics() throws NullPointerException
prr
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6eb7f9aa0b05 6640532: Graphics.getFontMetrics() throws NullPointerException
prr
parents:
diff changeset
     4
 *
6eb7f9aa0b05 6640532: Graphics.getFontMetrics() throws NullPointerException
prr
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
6eb7f9aa0b05 6640532: Graphics.getFontMetrics() throws NullPointerException
prr
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
6eb7f9aa0b05 6640532: Graphics.getFontMetrics() throws NullPointerException
prr
parents:
diff changeset
     7
 * published by the Free Software Foundation.
6eb7f9aa0b05 6640532: Graphics.getFontMetrics() throws NullPointerException
prr
parents:
diff changeset
     8
 *
6eb7f9aa0b05 6640532: Graphics.getFontMetrics() throws NullPointerException
prr
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
6eb7f9aa0b05 6640532: Graphics.getFontMetrics() throws NullPointerException
prr
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
6eb7f9aa0b05 6640532: Graphics.getFontMetrics() throws NullPointerException
prr
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
6eb7f9aa0b05 6640532: Graphics.getFontMetrics() throws NullPointerException
prr
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
6eb7f9aa0b05 6640532: Graphics.getFontMetrics() throws NullPointerException
prr
parents:
diff changeset
    13
 * accompanied this code).
6eb7f9aa0b05 6640532: Graphics.getFontMetrics() throws NullPointerException
prr
parents:
diff changeset
    14
 *
6eb7f9aa0b05 6640532: Graphics.getFontMetrics() throws NullPointerException
prr
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
6eb7f9aa0b05 6640532: Graphics.getFontMetrics() throws NullPointerException
prr
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
6eb7f9aa0b05 6640532: Graphics.getFontMetrics() throws NullPointerException
prr
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
6eb7f9aa0b05 6640532: Graphics.getFontMetrics() throws NullPointerException
prr
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3111
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3111
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3111
diff changeset
    21
 * questions.
532
6eb7f9aa0b05 6640532: Graphics.getFontMetrics() throws NullPointerException
prr
parents:
diff changeset
    22
 */
6eb7f9aa0b05 6640532: Graphics.getFontMetrics() throws NullPointerException
prr
parents:
diff changeset
    23
6eb7f9aa0b05 6640532: Graphics.getFontMetrics() throws NullPointerException
prr
parents:
diff changeset
    24
6eb7f9aa0b05 6640532: Graphics.getFontMetrics() throws NullPointerException
prr
parents:
diff changeset
    25
/* @test
6eb7f9aa0b05 6640532: Graphics.getFontMetrics() throws NullPointerException
prr
parents:
diff changeset
    26
 * @summary verify thread interruption doesn't affect font file reading.
6eb7f9aa0b05 6640532: Graphics.getFontMetrics() throws NullPointerException
prr
parents:
diff changeset
    27
 * @bug 6640532
6eb7f9aa0b05 6640532: Graphics.getFontMetrics() throws NullPointerException
prr
parents:
diff changeset
    28
 */
6eb7f9aa0b05 6640532: Graphics.getFontMetrics() throws NullPointerException
prr
parents:
diff changeset
    29
6eb7f9aa0b05 6640532: Graphics.getFontMetrics() throws NullPointerException
prr
parents:
diff changeset
    30
import java.awt.*;
6eb7f9aa0b05 6640532: Graphics.getFontMetrics() throws NullPointerException
prr
parents:
diff changeset
    31
6eb7f9aa0b05 6640532: Graphics.getFontMetrics() throws NullPointerException
prr
parents:
diff changeset
    32
public class FontThread extends Thread {
6eb7f9aa0b05 6640532: Graphics.getFontMetrics() throws NullPointerException
prr
parents:
diff changeset
    33
6eb7f9aa0b05 6640532: Graphics.getFontMetrics() throws NullPointerException
prr
parents:
diff changeset
    34
    String fontName = "Dialog";
6eb7f9aa0b05 6640532: Graphics.getFontMetrics() throws NullPointerException
prr
parents:
diff changeset
    35
    static FontThread thread1;
6eb7f9aa0b05 6640532: Graphics.getFontMetrics() throws NullPointerException
prr
parents:
diff changeset
    36
    static FontThread thread2;
6eb7f9aa0b05 6640532: Graphics.getFontMetrics() throws NullPointerException
prr
parents:
diff changeset
    37
    static FontThread thread3;
6eb7f9aa0b05 6640532: Graphics.getFontMetrics() throws NullPointerException
prr
parents:
diff changeset
    38
6eb7f9aa0b05 6640532: Graphics.getFontMetrics() throws NullPointerException
prr
parents:
diff changeset
    39
    public static void main(String args[]) throws Exception {
6eb7f9aa0b05 6640532: Graphics.getFontMetrics() throws NullPointerException
prr
parents:
diff changeset
    40
        thread1 = new FontThread("SansSerif");
6eb7f9aa0b05 6640532: Graphics.getFontMetrics() throws NullPointerException
prr
parents:
diff changeset
    41
        thread2 = new FontThread("Serif");
6eb7f9aa0b05 6640532: Graphics.getFontMetrics() throws NullPointerException
prr
parents:
diff changeset
    42
        thread3 = new FontThread("Monospaced");
6eb7f9aa0b05 6640532: Graphics.getFontMetrics() throws NullPointerException
prr
parents:
diff changeset
    43
        thread1.dometrics(60); // load classes first
6eb7f9aa0b05 6640532: Graphics.getFontMetrics() throws NullPointerException
prr
parents:
diff changeset
    44
        thread1.start();
6eb7f9aa0b05 6640532: Graphics.getFontMetrics() throws NullPointerException
prr
parents:
diff changeset
    45
        thread2.start();
6eb7f9aa0b05 6640532: Graphics.getFontMetrics() throws NullPointerException
prr
parents:
diff changeset
    46
        thread3.start();
6eb7f9aa0b05 6640532: Graphics.getFontMetrics() throws NullPointerException
prr
parents:
diff changeset
    47
        InterruptThread ithread = new InterruptThread();
6eb7f9aa0b05 6640532: Graphics.getFontMetrics() throws NullPointerException
prr
parents:
diff changeset
    48
        ithread.setDaemon(true);
6eb7f9aa0b05 6640532: Graphics.getFontMetrics() throws NullPointerException
prr
parents:
diff changeset
    49
        ithread.start();
6eb7f9aa0b05 6640532: Graphics.getFontMetrics() throws NullPointerException
prr
parents:
diff changeset
    50
        thread1.join();
6eb7f9aa0b05 6640532: Graphics.getFontMetrics() throws NullPointerException
prr
parents:
diff changeset
    51
        thread2.join();
6eb7f9aa0b05 6640532: Graphics.getFontMetrics() throws NullPointerException
prr
parents:
diff changeset
    52
        thread3.join();
6eb7f9aa0b05 6640532: Graphics.getFontMetrics() throws NullPointerException
prr
parents:
diff changeset
    53
    }
6eb7f9aa0b05 6640532: Graphics.getFontMetrics() throws NullPointerException
prr
parents:
diff changeset
    54
6eb7f9aa0b05 6640532: Graphics.getFontMetrics() throws NullPointerException
prr
parents:
diff changeset
    55
    FontThread(String font) {
6eb7f9aa0b05 6640532: Graphics.getFontMetrics() throws NullPointerException
prr
parents:
diff changeset
    56
        super();
6eb7f9aa0b05 6640532: Graphics.getFontMetrics() throws NullPointerException
prr
parents:
diff changeset
    57
        this.fontName = font;
6eb7f9aa0b05 6640532: Graphics.getFontMetrics() throws NullPointerException
prr
parents:
diff changeset
    58
    }
6eb7f9aa0b05 6640532: Graphics.getFontMetrics() throws NullPointerException
prr
parents:
diff changeset
    59
6eb7f9aa0b05 6640532: Graphics.getFontMetrics() throws NullPointerException
prr
parents:
diff changeset
    60
    public void run() {
6eb7f9aa0b05 6640532: Graphics.getFontMetrics() throws NullPointerException
prr
parents:
diff changeset
    61
        System.out.println("started "+fontName); System.out.flush();
6eb7f9aa0b05 6640532: Graphics.getFontMetrics() throws NullPointerException
prr
parents:
diff changeset
    62
        dometrics(4000);
6eb7f9aa0b05 6640532: Graphics.getFontMetrics() throws NullPointerException
prr
parents:
diff changeset
    63
        System.out.println("done "+fontName); System.out.flush();
6eb7f9aa0b05 6640532: Graphics.getFontMetrics() throws NullPointerException
prr
parents:
diff changeset
    64
    }
6eb7f9aa0b05 6640532: Graphics.getFontMetrics() throws NullPointerException
prr
parents:
diff changeset
    65
6eb7f9aa0b05 6640532: Graphics.getFontMetrics() throws NullPointerException
prr
parents:
diff changeset
    66
    private void dometrics(int max) {
6eb7f9aa0b05 6640532: Graphics.getFontMetrics() throws NullPointerException
prr
parents:
diff changeset
    67
        Font f = new Font(fontName, Font.PLAIN, 12);
6eb7f9aa0b05 6640532: Graphics.getFontMetrics() throws NullPointerException
prr
parents:
diff changeset
    68
        FontMetrics fm = Toolkit.getDefaultToolkit().getFontMetrics(f);
6eb7f9aa0b05 6640532: Graphics.getFontMetrics() throws NullPointerException
prr
parents:
diff changeset
    69
        for (char i=0;i<max;i++) {
6eb7f9aa0b05 6640532: Graphics.getFontMetrics() throws NullPointerException
prr
parents:
diff changeset
    70
            if (f.canDisplay(i)) fm.charWidth(i);
6eb7f9aa0b05 6640532: Graphics.getFontMetrics() throws NullPointerException
prr
parents:
diff changeset
    71
        }
6eb7f9aa0b05 6640532: Graphics.getFontMetrics() throws NullPointerException
prr
parents:
diff changeset
    72
    }
6eb7f9aa0b05 6640532: Graphics.getFontMetrics() throws NullPointerException
prr
parents:
diff changeset
    73
6eb7f9aa0b05 6640532: Graphics.getFontMetrics() throws NullPointerException
prr
parents:
diff changeset
    74
    static class InterruptThread extends Thread {
6eb7f9aa0b05 6640532: Graphics.getFontMetrics() throws NullPointerException
prr
parents:
diff changeset
    75
        public void run() {
6eb7f9aa0b05 6640532: Graphics.getFontMetrics() throws NullPointerException
prr
parents:
diff changeset
    76
            while (true) {
6eb7f9aa0b05 6640532: Graphics.getFontMetrics() throws NullPointerException
prr
parents:
diff changeset
    77
                try {
6eb7f9aa0b05 6640532: Graphics.getFontMetrics() throws NullPointerException
prr
parents:
diff changeset
    78
                    Thread.sleep(1);
6eb7f9aa0b05 6640532: Graphics.getFontMetrics() throws NullPointerException
prr
parents:
diff changeset
    79
                } catch (InterruptedException e) {
6eb7f9aa0b05 6640532: Graphics.getFontMetrics() throws NullPointerException
prr
parents:
diff changeset
    80
                }
6eb7f9aa0b05 6640532: Graphics.getFontMetrics() throws NullPointerException
prr
parents:
diff changeset
    81
                thread1.interrupt();
6eb7f9aa0b05 6640532: Graphics.getFontMetrics() throws NullPointerException
prr
parents:
diff changeset
    82
                thread2.interrupt();
6eb7f9aa0b05 6640532: Graphics.getFontMetrics() throws NullPointerException
prr
parents:
diff changeset
    83
                thread3.interrupt();
6eb7f9aa0b05 6640532: Graphics.getFontMetrics() throws NullPointerException
prr
parents:
diff changeset
    84
            }
6eb7f9aa0b05 6640532: Graphics.getFontMetrics() throws NullPointerException
prr
parents:
diff changeset
    85
        }
6eb7f9aa0b05 6640532: Graphics.getFontMetrics() throws NullPointerException
prr
parents:
diff changeset
    86
    }
6eb7f9aa0b05 6640532: Graphics.getFontMetrics() throws NullPointerException
prr
parents:
diff changeset
    87
}