Skip to content

Commit 021bf63

Browse files
author
Alexander Zuev
committedOct 1, 2024
8340458: Open source additional Component tests (part 2)
Reviewed-by: psadhukhan
1 parent 9a7817b commit 021bf63

File tree

4 files changed

+502
-0
lines changed

4 files changed

+502
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
/*
2+
* Copyright (c) 1998, 2024, Oracle and/or its affiliates. All rights reserved.
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+
*
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.
22+
*/
23+
24+
/*
25+
* @test
26+
* @bug 4148334
27+
* @summary tests that background color is initially set correctly.
28+
* @requires os.family == "windows"
29+
* @key headful
30+
* @run main InitialBackgroundSettingTest
31+
*/
32+
import java.awt.Button;
33+
import java.awt.Choice;
34+
import java.awt.Color;
35+
import java.awt.EventQueue;
36+
import java.awt.Frame;
37+
import java.awt.GridLayout;
38+
import java.awt.List;
39+
import java.awt.TextArea;
40+
import java.awt.TextField;
41+
import java.awt.Scrollbar;
42+
import java.lang.reflect.InvocationTargetException;
43+
44+
public class InitialBackgroundSettingTest {
45+
Frame frame;
46+
TextField tf;
47+
TextArea ta;
48+
Choice choice;
49+
List list;
50+
Scrollbar bar;
51+
Button button;
52+
53+
public static void main(String[] args) throws InterruptedException,
54+
InvocationTargetException {
55+
InitialBackgroundSettingTest test= new InitialBackgroundSettingTest();
56+
try {
57+
EventQueue.invokeAndWait(test::setupGUI);
58+
EventQueue.invokeAndWait(test::test);
59+
} finally {
60+
EventQueue.invokeAndWait(test::dispose);
61+
}
62+
}
63+
64+
public void setupGUI () {
65+
frame = new Frame("InitialBackgroundSettingTest frame");
66+
tf = new TextField("I am the TextField");
67+
ta = new TextArea("I am the TextArea");
68+
choice = new Choice();
69+
list = new List();
70+
bar = new Scrollbar(Scrollbar.HORIZONTAL);
71+
button = new Button("I am the button");
72+
frame.setBackground(Color.red);
73+
frame.setLayout(new GridLayout(7, 1));
74+
frame.add(button);
75+
frame.add(bar);
76+
frame.add(choice);
77+
frame.add(list);
78+
frame.add(tf);
79+
frame.add(ta);
80+
frame.setVisible(true);
81+
frame.setBounds (400, 0, 300, 300);
82+
}
83+
84+
public void test() {
85+
boolean passed = true;
86+
System.out.println("Button background color is:" +
87+
button.getBackground());
88+
if (Color.red.equals(button.getBackground())) {
89+
System.err.println("Button background is red");
90+
passed = false;
91+
}
92+
System.out.println("Scrollbar background color is:" +
93+
bar.getBackground());
94+
if (Color.red.equals(bar.getBackground())) {
95+
System.err.println("ScrollBar background is red");
96+
passed = false;
97+
}
98+
System.out.println("Choice background color is:" +
99+
choice.getBackground());
100+
if (Color.red.equals(choice.getBackground())) {
101+
System.err.println("Choice background is red");
102+
passed = false;
103+
}
104+
System.out.println("List background color is:" +
105+
list.getBackground());
106+
if (Color.red.equals(list.getBackground())) {
107+
System.err.println("List background is red");
108+
passed = false;
109+
}
110+
System.out.println("TextField background color is:" +
111+
tf.getBackground());
112+
if (Color.red.equals(tf.getBackground())) {
113+
System.err.println("TextField background is red");
114+
passed = false;
115+
}
116+
System.out.println("TextArea background color is:" +
117+
ta.getBackground());
118+
if (Color.red.equals(ta.getBackground())) {
119+
System.err.println("TextArea background is red");
120+
passed = false;
121+
}
122+
123+
if (!passed) {
124+
throw new RuntimeException("One or more component inherited" +
125+
" background from a Frame");
126+
}
127+
}
128+
129+
public void dispose() {
130+
frame.dispose();
131+
}
132+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
/*
2+
* Copyright (c) 2005, 2024, Oracle and/or its affiliates. All rights reserved.
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+
*
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.
22+
*/
23+
24+
/*
25+
* @test
26+
* @bug 6347994
27+
* @summary REG: Scrollbar, Choice, Checkbox flickers and grays out when scrolling, XToolkit
28+
* @library /java/awt/regtesthelpers
29+
* @build PassFailJFrame
30+
* @run main/manual FlickeringOnScroll
31+
*/
32+
33+
import java.awt.BorderLayout;
34+
import java.awt.Checkbox;
35+
import java.awt.Choice;
36+
import java.awt.Dimension;
37+
import java.awt.FlowLayout;
38+
import java.awt.Frame;
39+
import java.awt.MenuItem;
40+
import java.awt.Panel;
41+
import java.awt.PopupMenu;
42+
import java.awt.Scrollbar;
43+
import java.awt.TextArea;
44+
import java.awt.event.MouseAdapter;
45+
import java.awt.event.MouseEvent;
46+
import java.lang.reflect.InvocationTargetException;
47+
48+
public class FlickeringOnScroll extends Frame {
49+
50+
static final String INSTRUCTIONS = """
51+
There are five components in the frame:
52+
Scrollbars(vertical and horizontal), a Choice,
53+
a Checkbox and a TextArea
54+
1) Drag the thumbs of each Scrollbar.
55+
2) Do the same with Choice's scrollbar.
56+
3) Focus on Checkbox and press left mouse button or SPACE repeatedly.
57+
4) Right click inside TextArea and navigate through all menu items
58+
in PopupMenu using the arrow keys.
59+
If you notice some component or its scrollbar flickers on
60+
key/mouse press or drag, press Fail. Otherwise press Pass.
61+
""";
62+
63+
public FlickeringOnScroll() {
64+
Choice ch = new Choice();
65+
ch.add("Praveen");
66+
ch.add("Mohan");
67+
ch.add("Rakesh");
68+
ch.add("Menon");
69+
ch.add("Girish");
70+
ch.add("Ramachandran");
71+
ch.add("Elancheran");
72+
ch.add("Subramanian");
73+
ch.add("Raju");
74+
ch.add("Pallath");
75+
ch.add("Mayank");
76+
ch.add("Joshi");
77+
ch.add("Sundar");
78+
ch.add("Srinivas");
79+
ch.add("Mandalika");
80+
Checkbox chb = new Checkbox ("Checkbox", false);
81+
TextArea ta = new TextArea("Text Area");
82+
Panel panel = new Panel();
83+
PopupMenu popup = new PopupMenu("Popup");
84+
MenuItem mi1 = new MenuItem("mi1");
85+
MenuItem mi2 = new MenuItem("mi2");
86+
MenuItem mi3 = new MenuItem("mi3");
87+
MenuItem mi4 = new MenuItem("mi4");
88+
89+
setTitle("Flickering Scroll Area Testing Frame");
90+
setLayout(new FlowLayout());
91+
add(ch);
92+
add(chb);
93+
add(ta);
94+
95+
panel.setLayout(new BorderLayout());
96+
panel.setPreferredSize(new Dimension(200, 200));
97+
add(panel);
98+
panel.add("Center",new java.awt.Label("Scrollbar flickering test..." ,java.awt.Label.CENTER));
99+
panel.add("South",new Scrollbar(Scrollbar.HORIZONTAL, 0, 100, 0, 255));
100+
panel.add("East",new Scrollbar(Scrollbar.VERTICAL, 0, 100, 0, 255));
101+
102+
ta.add(popup);
103+
popup.add (mi1);
104+
popup.add (mi2);
105+
popup.add (mi3);
106+
popup.add (mi4);
107+
108+
ta.addMouseListener(new MouseAdapter() {
109+
public void mousePressed(MouseEvent me) {
110+
if (me.isPopupTrigger()) {
111+
if (popup != null) {
112+
popup.show(me.getComponent(), me.getX(), me.getY());
113+
}
114+
}
115+
}
116+
public void mouseReleased(MouseEvent me) {
117+
if (me.isPopupTrigger()) {
118+
if (popup != null) {
119+
popup.show(me.getComponent(), me.getX(), me.getY());
120+
}
121+
}
122+
}
123+
});
124+
125+
pack();
126+
}
127+
128+
public static void main(String[] args) throws InterruptedException,
129+
InvocationTargetException {
130+
PassFailJFrame.builder()
131+
.title("Scroll Area Flickering Repaint")
132+
.testUI(FlickeringOnScroll::new)
133+
.instructions(INSTRUCTIONS)
134+
.columns(40)
135+
.logArea()
136+
.build()
137+
.awaitAndCheck();
138+
}
139+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*
2+
* Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved.
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+
*
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.
22+
*/
23+
24+
/*
25+
* @test
26+
* @bug 4079435
27+
* @summary Calling repaint() in focus handlers messes up the window.
28+
* @library /java/awt/regtesthelpers
29+
* @build PassFailJFrame
30+
* @run main/manual FocusRepaintTest
31+
*/
32+
33+
import java.awt.Button;
34+
import java.awt.FlowLayout;
35+
import java.awt.Frame;
36+
import java.awt.event.FocusEvent;
37+
import java.awt.event.FocusListener;
38+
import java.lang.reflect.InvocationTargetException;
39+
40+
public class FocusRepaintTest extends Frame implements FocusListener {
41+
static final String INSTRUCTIONS = """
42+
Hit the tab key repeatedly in the Test window.
43+
If any of the buttons disappear press Fail, otherwise press Pass.
44+
""";
45+
46+
public FocusRepaintTest() {
47+
setTitle("Test");
48+
setLayout(new FlowLayout());
49+
setSize(200, 100);
50+
Button b1 = new Button("Close");
51+
Button b2 = new Button("Button");
52+
add(b1);
53+
add(b2);
54+
b1.setSize(50, 30);
55+
b2.setSize(50, 30);
56+
b1.addFocusListener(this);
57+
b2.addFocusListener(this);
58+
}
59+
60+
public void focusGained(FocusEvent e) {
61+
Button b = (Button) e.getSource();
62+
PassFailJFrame.log("Focus gained for " + b.getLabel());
63+
b.repaint();
64+
}
65+
66+
public void focusLost(FocusEvent e) {
67+
Button b = (Button) e.getSource();
68+
PassFailJFrame.log("Focus lost for " + b.getLabel());
69+
b.repaint();
70+
}
71+
72+
public static void main(String[] args) throws InterruptedException,
73+
InvocationTargetException {
74+
PassFailJFrame.builder()
75+
.title("Focus Repaint")
76+
.testUI(FocusRepaintTest::new)
77+
.instructions(INSTRUCTIONS)
78+
.columns(40)
79+
.logArea()
80+
.build()
81+
.awaitAndCheck();
82+
}
83+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
/*
2+
* Copyright (c) 1998, 2024, Oracle and/or its affiliates. All rights reserved.
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+
*
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.
22+
*/
23+
24+
/*
25+
* @test
26+
* @bug 4185460
27+
* @summary Container list the indentation is 2x the indent param value
28+
* @key headful
29+
* @run main ListDoubleIndentTest
30+
*/
31+
32+
import java.awt.BorderLayout;
33+
import java.awt.Button;
34+
import java.awt.EventQueue;
35+
import java.awt.Frame;
36+
37+
import java.io.BufferedReader;
38+
import java.io.InputStreamReader;
39+
import java.io.IOException;
40+
import java.io.PipedInputStream;
41+
import java.io.PrintStream;
42+
import java.io.PipedOutputStream;
43+
44+
import java.lang.reflect.InvocationTargetException;
45+
import java.util.Vector;
46+
47+
public class ListDoubleIndentTest {
48+
public static void main(final String[] args) throws InterruptedException,
49+
InvocationTargetException {
50+
EventQueue.invokeAndWait(new ListDoubleIndentTest()::performTest);
51+
}
52+
53+
public void performTest() {
54+
boolean bReturn = false;
55+
int iCompCount = 0;
56+
int iNotEqual = 0;
57+
int iIndentWrong = 0;
58+
System.out.println("Test: Check indentation");
59+
Vector v = new Vector();
60+
String sLine;
61+
String sReturn;
62+
String sExpTrim;
63+
Button b1, b2, b3, b4, b5;
64+
Frame f = null;
65+
66+
try {
67+
f = new Frame("ListDoubleIndentTest");
68+
69+
f.add(b1 = new Button("North"), BorderLayout.NORTH, 0);
70+
f.add(b2 = new Button("South"), BorderLayout.SOUTH, 1);
71+
f.add(b3 = new Button("East"), BorderLayout.EAST, 2);
72+
f.add(b4 = new Button("West"), BorderLayout.WEST, 3);
73+
f.add(b5 = new Button("Center"), BorderLayout.CENTER, -1);
74+
75+
String[] sExpected = {f.toString(), b1.toString(), b2.toString(),
76+
b3.toString(), b4.toString(), b5.toString()};
77+
78+
iCompCount = f.getComponentCount();
79+
System.out.println("Component count: " + iCompCount);
80+
81+
for (int j = 0; j <= 10; j++) {
82+
PipedInputStream pin = new PipedInputStream();
83+
PrintStream output = new PrintStream(new PipedOutputStream(pin), true);
84+
BufferedReader input = new BufferedReader(new InputStreamReader(pin));
85+
86+
f.list(output, j);
87+
88+
output.flush();
89+
output.close();
90+
91+
while ((sLine = input.readLine()) != null) {
92+
v.addElement(sLine);
93+
}
94+
95+
for (int i = 0; i < v.size(); i++) {
96+
sReturn = (String)v.elementAt(i);
97+
sExpTrim = sExpected[i].trim();
98+
99+
if (!(sExpTrim.equals(sReturn.trim()))) {
100+
System.out.println("iNotEqual");
101+
++iNotEqual;
102+
}
103+
104+
int iSpace = sReturn.lastIndexOf(' ') + 1;
105+
106+
if (i == 0) {
107+
System.out.println("Indent set at: " + j);
108+
System.out.println("Indent return: " + iSpace);
109+
if (iSpace != j) {
110+
System.out.println("iIndentWrong1");
111+
++iIndentWrong;
112+
}
113+
} else {
114+
if (iSpace != (j + 1)) {
115+
System.out.println(iSpace + "; " + j);
116+
++iIndentWrong;
117+
}
118+
}
119+
System.out.println(sReturn);
120+
}
121+
v.removeAllElements();
122+
v.trimToSize();
123+
}
124+
125+
if (iNotEqual == 0 && iIndentWrong == 0) {
126+
bReturn = true;
127+
} else {
128+
bReturn = false;
129+
}
130+
131+
} catch(IOException e) {
132+
bReturn = false;
133+
System.out.println ("Unexpected Exception thrown: " + e.getMessage());
134+
e.printStackTrace();
135+
} finally {
136+
if (f != null) {
137+
f.dispose();
138+
}
139+
}
140+
141+
if (bReturn) {
142+
System.out.println("Test for Container.list Passed");
143+
} else {
144+
System.out.println("Test for Container.list Failed");
145+
throw new RuntimeException("Test FAILED");
146+
}
147+
}
148+
}

0 commit comments

Comments
 (0)
Please sign in to comment.