test/jdk/sun/java2d/ClassCastExceptionForInvalidSurface.java
author lancea
Thu, 14 Nov 2019 10:54:32 -0500
changeset 59083 3e4d8b5856f3
parent 47216 71c04702a3d5
permissions -rw-r--r--
8234080: jdk/nio/zipfs/CRCWriteTest.java fails Reviewed-by: clanger, amlu
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
39013
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
     1
/*
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
     2
 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
     4
 *
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
     7
 * published by the Free Software Foundation.
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
     8
 *
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
    13
 * accompanied this code).
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
    14
 *
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
    18
 *
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
    21
 * questions.
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
    22
 */
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
    23
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
    24
import java.awt.Font;
39028
0b738aef65d0 8158495: CCE: sun.java2d.NullSurfaceData cannot be cast to sun.java2d.opengl.OGLSurfaceData
avu
parents: 39013
diff changeset
    25
import java.awt.Graphics2D;
39013
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
    26
import java.awt.GraphicsConfiguration;
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
    27
import java.awt.GraphicsEnvironment;
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
    28
import java.awt.Image;
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
    29
import java.awt.Rectangle;
39028
0b738aef65d0 8158495: CCE: sun.java2d.NullSurfaceData cannot be cast to sun.java2d.opengl.OGLSurfaceData
avu
parents: 39013
diff changeset
    30
import java.awt.RenderingHints;
39013
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
    31
import java.awt.font.FontRenderContext;
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
    32
import java.awt.font.GlyphVector;
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
    33
import java.awt.image.BufferedImage;
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
    34
import java.awt.image.VolatileImage;
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
    35
import java.util.concurrent.ArrayBlockingQueue;
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
    36
import java.util.concurrent.BlockingQueue;
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
    37
import java.util.concurrent.TimeUnit;
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
    38
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
    39
import static java.awt.image.BufferedImage.TYPE_INT_ARGB;
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
    40
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
    41
/**
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
    42
 * @test
40128
e635645d2a8a 8160974: [TESTBUG] Mark more headful tests with @key headful.
goetz
parents: 39028
diff changeset
    43
 * @key headful
39013
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
    44
 * @bug 8158072 7172749
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
    45
 */
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
    46
public final class ClassCastExceptionForInvalidSurface {
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
    47
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
    48
    static GraphicsEnvironment ge
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
    49
            = GraphicsEnvironment.getLocalGraphicsEnvironment();
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
    50
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
    51
    static GraphicsConfiguration gc
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
    52
            = ge.getDefaultScreenDevice().getDefaultConfiguration();
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
    53
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
    54
    static volatile VolatileImage vi = gc.createCompatibleVolatileImage(10, 10);
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
    55
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
    56
    static volatile Throwable failed;
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
    57
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
    58
    static BlockingQueue<VolatileImage> list = new ArrayBlockingQueue<>(50);
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
    59
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
    60
    // Will run the test no more than 15 seconds
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
    61
    static long endtime = System.nanoTime() + TimeUnit.SECONDS.toNanos(15);
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
    62
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
    63
    public static void main(final String[] args) throws InterruptedException {
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
    64
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
    65
        // Catch all uncaught exceptions and treat them as test failure
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
    66
        Thread.setDefaultUncaughtExceptionHandler((t, e) -> failed = e);
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
    67
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
    68
        // Data for rendering
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
    69
        BufferedImage bi = new BufferedImage(10, 10, TYPE_INT_ARGB);
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
    70
        FontRenderContext frc = new FontRenderContext(null, false, false);
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
    71
        Font font = new Font("Serif", Font.PLAIN, 12);
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
    72
        GlyphVector gv = font.createGlyphVector(frc, new char[]{'a', '1'});
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
    73
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
    74
        Thread t1 = new Thread(() -> {
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
    75
            while (!isComplete()) {
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
    76
                vi = gc.createCompatibleVolatileImage(10, 10);
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
    77
                if (!list.offer(vi)) {
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
    78
                    vi.flush();
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
    79
                }
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
    80
            }
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
    81
            list.forEach(Image::flush);
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
    82
        });
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
    83
        Thread t2 = new Thread(() -> {
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
    84
            while (!isComplete()) {
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
    85
                VolatileImage vi = list.poll();
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
    86
                if (vi != null) {
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
    87
                    vi.flush();
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
    88
                }
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
    89
            }
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
    90
        });
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
    91
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
    92
        Thread t3 = new Thread(() -> {
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
    93
            while (!isComplete()) {
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
    94
                vi.createGraphics().drawImage(bi, 1, 1, null);
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
    95
            }
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
    96
        });
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
    97
        Thread t4 = new Thread(() -> {
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
    98
            while (!isComplete()) {
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
    99
                vi.createGraphics().drawGlyphVector(gv, 0, 0);
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
   100
                vi.createGraphics().drawOval(0, 0, 10, 10);
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
   101
                vi.createGraphics().drawLine(0, 0, 10, 10);
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
   102
                vi.createGraphics().drawString("123", 1, 1);
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
   103
                vi.createGraphics().draw(new Rectangle(0, 0, 10, 10));
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
   104
                vi.createGraphics().fillOval(0, 0, 10, 10);
39028
0b738aef65d0 8158495: CCE: sun.java2d.NullSurfaceData cannot be cast to sun.java2d.opengl.OGLSurfaceData
avu
parents: 39013
diff changeset
   105
                final Graphics2D graphics = vi.createGraphics();
0b738aef65d0 8158495: CCE: sun.java2d.NullSurfaceData cannot be cast to sun.java2d.opengl.OGLSurfaceData
avu
parents: 39013
diff changeset
   106
                graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
0b738aef65d0 8158495: CCE: sun.java2d.NullSurfaceData cannot be cast to sun.java2d.opengl.OGLSurfaceData
avu
parents: 39013
diff changeset
   107
                                          RenderingHints.VALUE_ANTIALIAS_ON);
0b738aef65d0 8158495: CCE: sun.java2d.NullSurfaceData cannot be cast to sun.java2d.opengl.OGLSurfaceData
avu
parents: 39013
diff changeset
   108
                graphics.fillPolygon(new int[] {0, 10, 10, 0},
0b738aef65d0 8158495: CCE: sun.java2d.NullSurfaceData cannot be cast to sun.java2d.opengl.OGLSurfaceData
avu
parents: 39013
diff changeset
   109
                                     new int [] {0, 0, 10, 10}, 4);
39013
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
   110
            }
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
   111
        });
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
   112
        t1.start();
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
   113
        t2.start();
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
   114
        t3.start();
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
   115
        t4.start();
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
   116
        t1.join();
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
   117
        t2.join();
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
   118
        t3.join();
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
   119
        t4.join();
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
   120
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
   121
        if (failed != null) {
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
   122
            System.err.println("Test failed");
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
   123
            failed.printStackTrace();
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
   124
        }
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
   125
    }
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
   126
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
   127
    private static boolean isComplete() {
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
   128
        return endtime - System.nanoTime() < 0 || failed != null;
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
   129
    }
d6a023d500ef 8158072: Need a test for JDK-7172749
serb
parents:
diff changeset
   130
}