author | erikj |
Tue, 12 Sep 2017 19:03:39 +0200 | |
changeset 47216 | 71c04702a3d5 |
parent 28087 | jdk/test/java/awt/List/SetBackgroundTest/SetBackgroundTest.java@622b2f420bc3 |
child 49096 | eaef201ec301 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
5506 | 2 |
* Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
5506 | 19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
2 | 22 |
*/ |
23 |
||
24 |
/* |
|
25 |
@test |
|
26 |
@bug 6246467 |
|
27 |
@summary List does not honor user specified background, foreground colors on XToolkit |
|
28 |
@author Dmitry Cherepanov area=awt.list |
|
28087
622b2f420bc3
8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents:
5506
diff
changeset
|
29 |
@library ../../../../lib/testlibrary |
622b2f420bc3
8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents:
5506
diff
changeset
|
30 |
@build ExtendedRobot |
2 | 31 |
@run main SetBackgroundTest |
32 |
*/ |
|
33 |
||
34 |
/** |
|
35 |
* SetBackgroundTest.java |
|
36 |
* |
|
37 |
* summary: |
|
38 |
*/ |
|
39 |
||
40 |
import java.awt.*; |
|
41 |
import java.awt.event.*; |
|
42 |
||
43 |
public class SetBackgroundTest |
|
44 |
{ |
|
45 |
||
46 |
private static boolean isXAWT = (Toolkit.getDefaultToolkit().getClass().getName().equals("sun.awt.X11.XToolkit")); |
|
28087
622b2f420bc3
8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents:
5506
diff
changeset
|
47 |
private static ExtendedRobot robot = null; |
2 | 48 |
private static Frame frame = null; |
49 |
||
50 |
private static final Color color = Color.red; |
|
51 |
private static Color roughColor = null; |
|
52 |
||
53 |
private static void initRoughColor(){ |
|
54 |
||
55 |
Canvas canvas = new Canvas(); |
|
56 |
canvas.setBackground(color); |
|
57 |
frame.add(canvas, BorderLayout.CENTER); |
|
58 |
frame.validate(); |
|
28087
622b2f420bc3
8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents:
5506
diff
changeset
|
59 |
robot.waitForIdle(500); |
2 | 60 |
|
61 |
Point loc = canvas.getLocationOnScreen(); |
|
62 |
Color robotColor = robot.getPixelColor(loc.x + canvas.getWidth()/2, loc.y + canvas.getHeight()/2); |
|
63 |
roughColor = robotColor; |
|
64 |
||
28087
622b2f420bc3
8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents:
5506
diff
changeset
|
65 |
System.out.println(" --- init rough color ... "); |
622b2f420bc3
8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents:
5506
diff
changeset
|
66 |
System.out.println(" color = "+color); |
622b2f420bc3
8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents:
5506
diff
changeset
|
67 |
System.out.println(" roughColor = "+roughColor); |
2 | 68 |
|
69 |
frame.remove(canvas); |
|
28087
622b2f420bc3
8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents:
5506
diff
changeset
|
70 |
robot.waitForIdle(500); |
2 | 71 |
} |
72 |
||
73 |
||
74 |
private static void test() { |
|
75 |
if (!isXAWT){ |
|
28087
622b2f420bc3
8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents:
5506
diff
changeset
|
76 |
System.out.println(" this is XAWT-only test. "); |
2 | 77 |
return; |
78 |
} |
|
79 |
||
80 |
frame = new Frame(); |
|
81 |
frame.setBounds(400,400,200,200); |
|
82 |
frame.setLayout(new BorderLayout()); |
|
83 |
frame.setVisible(true); |
|
84 |
||
85 |
||
86 |
try{ |
|
28087
622b2f420bc3
8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents:
5506
diff
changeset
|
87 |
robot = new ExtendedRobot(); |
2 | 88 |
}catch(AWTException e){ |
89 |
throw new RuntimeException(e.getMessage()); |
|
90 |
} |
|
91 |
||
28087
622b2f420bc3
8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents:
5506
diff
changeset
|
92 |
robot.waitForIdle(500); |
622b2f420bc3
8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents:
5506
diff
changeset
|
93 |
|
2 | 94 |
initRoughColor(); |
95 |
Component[] components = new Component[] { |
|
96 |
new Button(), new Checkbox(), new Label(), new List(3, false), |
|
97 |
new TextArea(), new TextField(), new Choice() |
|
98 |
}; |
|
99 |
||
100 |
for (Component component : components) { |
|
101 |
testComponent(new Panel(), component, color); |
|
102 |
} |
|
103 |
||
28087
622b2f420bc3
8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents:
5506
diff
changeset
|
104 |
robot.waitForIdle(1500); |
2 | 105 |
frame.dispose(); |
106 |
} |
|
107 |
||
108 |
private static void testComponent(Container container, Component component, Color color){ |
|
109 |
||
110 |
component.setBackground(color); |
|
111 |
||
112 |
container.setLayout(new BorderLayout()); |
|
113 |
container.add(component, BorderLayout.CENTER); |
|
114 |
frame.add(container, BorderLayout.CENTER); |
|
115 |
frame.add("Center", container); |
|
116 |
frame.validate(); |
|
28087
622b2f420bc3
8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents:
5506
diff
changeset
|
117 |
robot.waitForIdle(500); |
2 | 118 |
|
119 |
Point loc = component.getLocationOnScreen(); |
|
120 |
Color robotColor = robot.getPixelColor(loc.x + component.getWidth()/2, loc.y + component.getHeight()/2); |
|
121 |
||
28087
622b2f420bc3
8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents:
5506
diff
changeset
|
122 |
System.out.println(" --- test ... "); |
622b2f420bc3
8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents:
5506
diff
changeset
|
123 |
System.out.println(" container = "+container); |
622b2f420bc3
8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents:
5506
diff
changeset
|
124 |
System.out.println(" component = "+component); |
622b2f420bc3
8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents:
5506
diff
changeset
|
125 |
System.out.println(" color = "+color); |
622b2f420bc3
8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents:
5506
diff
changeset
|
126 |
System.out.println(" roughColor = "+roughColor); |
622b2f420bc3
8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents:
5506
diff
changeset
|
127 |
System.out.println(" robotColor = "+robotColor); |
2 | 128 |
|
129 |
if(robotColor.getRGB() != roughColor.getRGB()){ |
|
130 |
throw new RuntimeException(" the case failed. "); |
|
131 |
} else { |
|
28087
622b2f420bc3
8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents:
5506
diff
changeset
|
132 |
System.out.println(" the case passed. "); |
2 | 133 |
} |
134 |
||
135 |
container.remove(component); |
|
136 |
frame.remove(container); |
|
28087
622b2f420bc3
8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents:
5506
diff
changeset
|
137 |
robot.waitForIdle(500); |
2 | 138 |
} |
28087
622b2f420bc3
8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents:
5506
diff
changeset
|
139 |
public static void main( String args[] ) throws Exception |
2 | 140 |
{ |
28087
622b2f420bc3
8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents:
5506
diff
changeset
|
141 |
test(); |
2 | 142 |
} |
143 |
} |
|
144 |