jdk/test/sun/java2d/DirectX/DrawBitmaskToSurfaceTest.java
author goetz
Tue, 14 Jun 2016 10:44:59 +0200
changeset 39056 d99e63b6d962
parent 10778 679a05f08d57
permissions -rw-r--r--
8159690: [TESTBUG] Mark headful tests with @key headful. Reviewed-by: simonis, alexsch
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10778
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
     1
/*
39056
d99e63b6d962 8159690: [TESTBUG] Mark headful tests with @key headful.
goetz
parents: 10778
diff changeset
     2
 * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
10778
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
     4
 *
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
     7
 * published by the Free Software Foundation.
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
     8
 *
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    13
 * accompanied this code).
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    14
 *
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    18
 *
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    21
 * questions.
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    22
 */
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    23
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    24
/*
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    25
 * @test
39056
d99e63b6d962 8159690: [TESTBUG] Mark headful tests with @key headful.
goetz
parents: 10778
diff changeset
    26
 * @key headful
10778
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    27
 * @bug     6997116
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    28
 * @summary Test verifies that rendering of images with bitmap transparency
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    29
 *          to a D3D surface does not cause an ClassCastException.
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    30
 *
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    31
 * @run main/othervm -Dsun.java2d.d3d=True DrawBitmaskToSurfaceTest
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    32
 */
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    33
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    34
import java.awt.Graphics;
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    35
import java.awt.Image;
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    36
import java.awt.image.BufferedImage;
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    37
import java.awt.image.IndexColorModel;
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    38
import java.util.concurrent.CountDownLatch;
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    39
import javax.swing.JFrame;
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    40
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    41
public class DrawBitmaskToSurfaceTest extends JFrame {
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    42
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    43
    private final Image src;
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    44
    private static java.util.concurrent.CountDownLatch latch = null;
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    45
    private static Throwable theError = null;
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    46
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    47
    public DrawBitmaskToSurfaceTest() {
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    48
        src = createTestImage();
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    49
    }
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    50
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    51
    private static Image createTestImage() {
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    52
        byte[] r = new byte[]{(byte)0x00, (byte)0x80, (byte)0xff, (byte)0xff};
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    53
        byte[] g = new byte[]{(byte)0x00, (byte)0x80, (byte)0xff, (byte)0x00};
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    54
        byte[] b = new byte[]{(byte)0x00, (byte)0x80, (byte)0xff, (byte)0x00};
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    55
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    56
        IndexColorModel icm = new IndexColorModel(2, 4, r, g, b, 3);
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    57
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    58
        BufferedImage img = new BufferedImage(100, 100,
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    59
                                              BufferedImage.TYPE_BYTE_INDEXED,
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    60
                                              icm);
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    61
        return img;
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    62
    }
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    63
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    64
    @Override
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    65
    public void paint(final Graphics g) {
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    66
        try {
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    67
            System.err.println("paint frame....");
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    68
            g.drawImage(src, 30, 30, this);
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    69
        } catch (Throwable e) {
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    70
            theError = e;
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    71
        } finally {
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    72
            if (latch != null) {
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    73
                latch.countDown();
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    74
            }
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    75
        }
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    76
    }
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    77
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    78
    public static void main(final String[] args) throws Exception {
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    79
        final JFrame frame = new DrawBitmaskToSurfaceTest();
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    80
        frame.setBounds(10, 350, 200, 200);
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    81
        frame.setVisible(true);
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    82
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    83
        Thread.sleep(2000);
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    84
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    85
        System.err.println("Change frame bounds...");
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    86
        latch = new CountDownLatch(1);
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    87
        frame.setBounds(10, 350, 90, 90);
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    88
        frame.repaint();
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    89
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    90
        try {
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    91
            if (latch.getCount() > 0) {
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    92
                latch.await();
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    93
            }
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    94
        } catch (InterruptedException e) {
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    95
        }
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    96
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    97
        frame.dispose();
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    98
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    99
        if (theError != null) {
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
   100
            throw new RuntimeException("Test failed.", theError);
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
   101
        }
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
   102
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
   103
        System.err.println("Test passed");
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
   104
    }
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
   105
}