jdk/test/java/awt/Graphics/DrawImageBG/SystemBgColorTest.java
author serb
Tue, 12 Nov 2013 20:24:25 +0400
changeset 21596 0e3a39f29dbc
parent 2951 08bcd34c5e50
child 23010 6dadb192ad81
permissions -rw-r--r--
8027696: Incorrect copyright header in the tests Reviewed-by: alanb, malenkov, mullan
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
21596
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 2951
diff changeset
     1
/*
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 2951
diff changeset
     2
 * Copyright (c) 2007, 2009, Oracle and/or its affiliates. All rights reserved.
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 2951
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 2951
diff changeset
     4
 *
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 2951
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 2951
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 2951
diff changeset
     7
 * published by the Free Software Foundation.
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 2951
diff changeset
     8
 *
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 2951
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 2951
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 2951
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 2951
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 2951
diff changeset
    13
 * accompanied this code).
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 2951
diff changeset
    14
 *
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 2951
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 2951
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 2951
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 2951
diff changeset
    18
 *
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 2951
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 2951
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 2951
diff changeset
    21
 * questions.
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 2951
diff changeset
    22
 */
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 2951
diff changeset
    23
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 * @test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * @bug     4614845
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * @summary Test drawImage(bgcolor) gets correct RGB from SystemColor objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * @run     main SystemBgColorTest
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.awt.image.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
public class SystemBgColorTest {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
    public static final int TESTW = 10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
    public static final int TESTH = 10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
    static SystemColor systemColorObjects [] = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
        SystemColor.desktop,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
        SystemColor.activeCaption,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
        SystemColor.activeCaptionText,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
        SystemColor.activeCaptionBorder,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
        SystemColor.inactiveCaption,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
        SystemColor.inactiveCaptionText,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
        SystemColor.inactiveCaptionBorder,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
        SystemColor.window,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
        SystemColor.windowBorder,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
        SystemColor.windowText,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
        SystemColor.menu,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
        SystemColor.menuText,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        SystemColor.text,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
        SystemColor.textText,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
        SystemColor.textHighlight,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        SystemColor.textHighlightText,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
        SystemColor.textInactiveText,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        SystemColor.control,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        SystemColor.controlText,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        SystemColor.controlHighlight,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        SystemColor.controlLtHighlight,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        SystemColor.controlShadow,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        SystemColor.controlDkShadow,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        SystemColor.scrollbar,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        SystemColor.info,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        SystemColor.infoText
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    static boolean counterrors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    static int errcount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    public static void error(String problem) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        if (counterrors) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
            errcount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
            throw new RuntimeException(problem);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    public static void main(String argv[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        counterrors = (argv.length > 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        test(BufferedImage.TYPE_INT_ARGB);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        test(BufferedImage.TYPE_INT_RGB);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        if (errcount > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
            throw new RuntimeException(errcount+" errors");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    static int cmap[] = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        0x00000000,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        0xffffffff,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    public static void test(int dsttype) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        BufferedImage src =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
            new BufferedImage(TESTW, TESTH, BufferedImage.TYPE_INT_ARGB);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        test(src, dsttype);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        IndexColorModel icm = new IndexColorModel(8, 2, cmap, 0, true, 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
                                                  DataBuffer.TYPE_BYTE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        src = new BufferedImage(TESTW, TESTH,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
                                BufferedImage.TYPE_BYTE_INDEXED, icm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        test(src, dsttype);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    public static void test(Image src, int dsttype) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        BufferedImage dst =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
            new BufferedImage(TESTW, TESTH, dsttype);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        for (int i = 0; i < systemColorObjects.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            test(src, dst, systemColorObjects[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    public static void test(Image src, BufferedImage dst, Color bg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        Graphics g = dst.getGraphics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        g.setColor(Color.white);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        g.fillRect(0, 0, TESTW, TESTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        g.drawImage(src, 0, 0, bg, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        if (dst.getRGB(0, 0) != bg.getRGB()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            error("bad bg pixel for: "+bg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
}