blob: f11b834e04ce088600460d67884b6139b8f4fab5 [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * @test
3 * @bug 4614845
4 * @summary Test drawImage(bgcolor) gets correct RGB from SystemColor objects.
5 * @run main SystemBgColorTest
6 */
7
8import java.awt.*;
9import java.awt.image.*;
10
11public class SystemBgColorTest {
12 public static final int TESTW = 10;
13 public static final int TESTH = 10;
14
15 static SystemColor systemColorObjects [] = {
16 SystemColor.desktop,
17 SystemColor.activeCaption,
18 SystemColor.activeCaptionText,
19 SystemColor.activeCaptionBorder,
20 SystemColor.inactiveCaption,
21 SystemColor.inactiveCaptionText,
22 SystemColor.inactiveCaptionBorder,
23 SystemColor.window,
24 SystemColor.windowBorder,
25 SystemColor.windowText,
26 SystemColor.menu,
27 SystemColor.menuText,
28 SystemColor.text,
29 SystemColor.textText,
30 SystemColor.textHighlight,
31 SystemColor.textHighlightText,
32 SystemColor.textInactiveText,
33 SystemColor.control,
34 SystemColor.controlText,
35 SystemColor.controlHighlight,
36 SystemColor.controlLtHighlight,
37 SystemColor.controlShadow,
38 SystemColor.controlDkShadow,
39 SystemColor.scrollbar,
40 SystemColor.info,
41 SystemColor.infoText
42 };
43
44 static boolean counterrors;
45 static int errcount;
46
47 public static void error(String problem) {
48 if (counterrors) {
49 errcount++;
50 } else {
51 throw new RuntimeException(problem);
52 }
53 }
54
55 public static void main(String argv[]) {
56 counterrors = (argv.length > 0);
57 test(BufferedImage.TYPE_INT_ARGB);
58 test(BufferedImage.TYPE_INT_RGB);
59 if (errcount > 0) {
60 throw new RuntimeException(errcount+" errors");
61 }
62 System.exit(0); // For 1.3 and earlier VMs...
63 }
64
65 static int cmap[] = {
66 0x00000000,
67 0xffffffff,
68 };
69
70 public static void test(int dsttype) {
71 BufferedImage src =
72 new BufferedImage(TESTW, TESTH, BufferedImage.TYPE_INT_ARGB);
73 test(src, dsttype);
74 IndexColorModel icm = new IndexColorModel(8, 2, cmap, 0, true, 0,
75 DataBuffer.TYPE_BYTE);
76 src = new BufferedImage(TESTW, TESTH,
77 BufferedImage.TYPE_BYTE_INDEXED, icm);
78 test(src, dsttype);
79 }
80
81 public static void test(Image src, int dsttype) {
82 BufferedImage dst =
83 new BufferedImage(TESTW, TESTH, dsttype);
84 for (int i = 0; i < systemColorObjects.length; i++) {
85 test(src, dst, systemColorObjects[i]);
86 }
87 }
88
89 public static void test(Image src, BufferedImage dst, Color bg) {
90 Graphics g = dst.getGraphics();
91 g.setColor(Color.white);
92 g.fillRect(0, 0, TESTW, TESTH);
93 g.drawImage(src, 0, 0, bg, null);
94 if (dst.getRGB(0, 0) != bg.getRGB()) {
95 error("bad bg pixel for: "+bg);
96 }
97 }
98}