8340458: Open source additional Component tests (part 2)
Reviewed-by: psadhukhan
This commit is contained in:
parent
9a7817b137
commit
021bf63035
@ -0,0 +1,132 @@
|
||||
/*
|
||||
* Copyright (c) 1998, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 4148334
|
||||
* @summary tests that background color is initially set correctly.
|
||||
* @requires os.family == "windows"
|
||||
* @key headful
|
||||
* @run main InitialBackgroundSettingTest
|
||||
*/
|
||||
import java.awt.Button;
|
||||
import java.awt.Choice;
|
||||
import java.awt.Color;
|
||||
import java.awt.EventQueue;
|
||||
import java.awt.Frame;
|
||||
import java.awt.GridLayout;
|
||||
import java.awt.List;
|
||||
import java.awt.TextArea;
|
||||
import java.awt.TextField;
|
||||
import java.awt.Scrollbar;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
public class InitialBackgroundSettingTest {
|
||||
Frame frame;
|
||||
TextField tf;
|
||||
TextArea ta;
|
||||
Choice choice;
|
||||
List list;
|
||||
Scrollbar bar;
|
||||
Button button;
|
||||
|
||||
public static void main(String[] args) throws InterruptedException,
|
||||
InvocationTargetException {
|
||||
InitialBackgroundSettingTest test= new InitialBackgroundSettingTest();
|
||||
try {
|
||||
EventQueue.invokeAndWait(test::setupGUI);
|
||||
EventQueue.invokeAndWait(test::test);
|
||||
} finally {
|
||||
EventQueue.invokeAndWait(test::dispose);
|
||||
}
|
||||
}
|
||||
|
||||
public void setupGUI () {
|
||||
frame = new Frame("InitialBackgroundSettingTest frame");
|
||||
tf = new TextField("I am the TextField");
|
||||
ta = new TextArea("I am the TextArea");
|
||||
choice = new Choice();
|
||||
list = new List();
|
||||
bar = new Scrollbar(Scrollbar.HORIZONTAL);
|
||||
button = new Button("I am the button");
|
||||
frame.setBackground(Color.red);
|
||||
frame.setLayout(new GridLayout(7, 1));
|
||||
frame.add(button);
|
||||
frame.add(bar);
|
||||
frame.add(choice);
|
||||
frame.add(list);
|
||||
frame.add(tf);
|
||||
frame.add(ta);
|
||||
frame.setVisible(true);
|
||||
frame.setBounds (400, 0, 300, 300);
|
||||
}
|
||||
|
||||
public void test() {
|
||||
boolean passed = true;
|
||||
System.out.println("Button background color is:" +
|
||||
button.getBackground());
|
||||
if (Color.red.equals(button.getBackground())) {
|
||||
System.err.println("Button background is red");
|
||||
passed = false;
|
||||
}
|
||||
System.out.println("Scrollbar background color is:" +
|
||||
bar.getBackground());
|
||||
if (Color.red.equals(bar.getBackground())) {
|
||||
System.err.println("ScrollBar background is red");
|
||||
passed = false;
|
||||
}
|
||||
System.out.println("Choice background color is:" +
|
||||
choice.getBackground());
|
||||
if (Color.red.equals(choice.getBackground())) {
|
||||
System.err.println("Choice background is red");
|
||||
passed = false;
|
||||
}
|
||||
System.out.println("List background color is:" +
|
||||
list.getBackground());
|
||||
if (Color.red.equals(list.getBackground())) {
|
||||
System.err.println("List background is red");
|
||||
passed = false;
|
||||
}
|
||||
System.out.println("TextField background color is:" +
|
||||
tf.getBackground());
|
||||
if (Color.red.equals(tf.getBackground())) {
|
||||
System.err.println("TextField background is red");
|
||||
passed = false;
|
||||
}
|
||||
System.out.println("TextArea background color is:" +
|
||||
ta.getBackground());
|
||||
if (Color.red.equals(ta.getBackground())) {
|
||||
System.err.println("TextArea background is red");
|
||||
passed = false;
|
||||
}
|
||||
|
||||
if (!passed) {
|
||||
throw new RuntimeException("One or more component inherited" +
|
||||
" background from a Frame");
|
||||
}
|
||||
}
|
||||
|
||||
public void dispose() {
|
||||
frame.dispose();
|
||||
}
|
||||
}
|
@ -0,0 +1,139 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 6347994
|
||||
* @summary REG: Scrollbar, Choice, Checkbox flickers and grays out when scrolling, XToolkit
|
||||
* @library /java/awt/regtesthelpers
|
||||
* @build PassFailJFrame
|
||||
* @run main/manual FlickeringOnScroll
|
||||
*/
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Checkbox;
|
||||
import java.awt.Choice;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.Frame;
|
||||
import java.awt.MenuItem;
|
||||
import java.awt.Panel;
|
||||
import java.awt.PopupMenu;
|
||||
import java.awt.Scrollbar;
|
||||
import java.awt.TextArea;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
public class FlickeringOnScroll extends Frame {
|
||||
|
||||
static final String INSTRUCTIONS = """
|
||||
There are five components in the frame:
|
||||
Scrollbars(vertical and horizontal), a Choice,
|
||||
a Checkbox and a TextArea
|
||||
1) Drag the thumbs of each Scrollbar.
|
||||
2) Do the same with Choice's scrollbar.
|
||||
3) Focus on Checkbox and press left mouse button or SPACE repeatedly.
|
||||
4) Right click inside TextArea and navigate through all menu items
|
||||
in PopupMenu using the arrow keys.
|
||||
If you notice some component or its scrollbar flickers on
|
||||
key/mouse press or drag, press Fail. Otherwise press Pass.
|
||||
""";
|
||||
|
||||
public FlickeringOnScroll() {
|
||||
Choice ch = new Choice();
|
||||
ch.add("Praveen");
|
||||
ch.add("Mohan");
|
||||
ch.add("Rakesh");
|
||||
ch.add("Menon");
|
||||
ch.add("Girish");
|
||||
ch.add("Ramachandran");
|
||||
ch.add("Elancheran");
|
||||
ch.add("Subramanian");
|
||||
ch.add("Raju");
|
||||
ch.add("Pallath");
|
||||
ch.add("Mayank");
|
||||
ch.add("Joshi");
|
||||
ch.add("Sundar");
|
||||
ch.add("Srinivas");
|
||||
ch.add("Mandalika");
|
||||
Checkbox chb = new Checkbox ("Checkbox", false);
|
||||
TextArea ta = new TextArea("Text Area");
|
||||
Panel panel = new Panel();
|
||||
PopupMenu popup = new PopupMenu("Popup");
|
||||
MenuItem mi1 = new MenuItem("mi1");
|
||||
MenuItem mi2 = new MenuItem("mi2");
|
||||
MenuItem mi3 = new MenuItem("mi3");
|
||||
MenuItem mi4 = new MenuItem("mi4");
|
||||
|
||||
setTitle("Flickering Scroll Area Testing Frame");
|
||||
setLayout(new FlowLayout());
|
||||
add(ch);
|
||||
add(chb);
|
||||
add(ta);
|
||||
|
||||
panel.setLayout(new BorderLayout());
|
||||
panel.setPreferredSize(new Dimension(200, 200));
|
||||
add(panel);
|
||||
panel.add("Center",new java.awt.Label("Scrollbar flickering test..." ,java.awt.Label.CENTER));
|
||||
panel.add("South",new Scrollbar(Scrollbar.HORIZONTAL, 0, 100, 0, 255));
|
||||
panel.add("East",new Scrollbar(Scrollbar.VERTICAL, 0, 100, 0, 255));
|
||||
|
||||
ta.add(popup);
|
||||
popup.add (mi1);
|
||||
popup.add (mi2);
|
||||
popup.add (mi3);
|
||||
popup.add (mi4);
|
||||
|
||||
ta.addMouseListener(new MouseAdapter() {
|
||||
public void mousePressed(MouseEvent me) {
|
||||
if (me.isPopupTrigger()) {
|
||||
if (popup != null) {
|
||||
popup.show(me.getComponent(), me.getX(), me.getY());
|
||||
}
|
||||
}
|
||||
}
|
||||
public void mouseReleased(MouseEvent me) {
|
||||
if (me.isPopupTrigger()) {
|
||||
if (popup != null) {
|
||||
popup.show(me.getComponent(), me.getX(), me.getY());
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
pack();
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws InterruptedException,
|
||||
InvocationTargetException {
|
||||
PassFailJFrame.builder()
|
||||
.title("Scroll Area Flickering Repaint")
|
||||
.testUI(FlickeringOnScroll::new)
|
||||
.instructions(INSTRUCTIONS)
|
||||
.columns(40)
|
||||
.logArea()
|
||||
.build()
|
||||
.awaitAndCheck();
|
||||
}
|
||||
}
|
@ -0,0 +1,83 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 4079435
|
||||
* @summary Calling repaint() in focus handlers messes up the window.
|
||||
* @library /java/awt/regtesthelpers
|
||||
* @build PassFailJFrame
|
||||
* @run main/manual FocusRepaintTest
|
||||
*/
|
||||
|
||||
import java.awt.Button;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.Frame;
|
||||
import java.awt.event.FocusEvent;
|
||||
import java.awt.event.FocusListener;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
public class FocusRepaintTest extends Frame implements FocusListener {
|
||||
static final String INSTRUCTIONS = """
|
||||
Hit the tab key repeatedly in the Test window.
|
||||
If any of the buttons disappear press Fail, otherwise press Pass.
|
||||
""";
|
||||
|
||||
public FocusRepaintTest() {
|
||||
setTitle("Test");
|
||||
setLayout(new FlowLayout());
|
||||
setSize(200, 100);
|
||||
Button b1 = new Button("Close");
|
||||
Button b2 = new Button("Button");
|
||||
add(b1);
|
||||
add(b2);
|
||||
b1.setSize(50, 30);
|
||||
b2.setSize(50, 30);
|
||||
b1.addFocusListener(this);
|
||||
b2.addFocusListener(this);
|
||||
}
|
||||
|
||||
public void focusGained(FocusEvent e) {
|
||||
Button b = (Button) e.getSource();
|
||||
PassFailJFrame.log("Focus gained for " + b.getLabel());
|
||||
b.repaint();
|
||||
}
|
||||
|
||||
public void focusLost(FocusEvent e) {
|
||||
Button b = (Button) e.getSource();
|
||||
PassFailJFrame.log("Focus lost for " + b.getLabel());
|
||||
b.repaint();
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws InterruptedException,
|
||||
InvocationTargetException {
|
||||
PassFailJFrame.builder()
|
||||
.title("Focus Repaint")
|
||||
.testUI(FocusRepaintTest::new)
|
||||
.instructions(INSTRUCTIONS)
|
||||
.columns(40)
|
||||
.logArea()
|
||||
.build()
|
||||
.awaitAndCheck();
|
||||
}
|
||||
}
|
@ -0,0 +1,148 @@
|
||||
/*
|
||||
* Copyright (c) 1998, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 4185460
|
||||
* @summary Container list the indentation is 2x the indent param value
|
||||
* @key headful
|
||||
* @run main ListDoubleIndentTest
|
||||
*/
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Button;
|
||||
import java.awt.EventQueue;
|
||||
import java.awt.Frame;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.IOException;
|
||||
import java.io.PipedInputStream;
|
||||
import java.io.PrintStream;
|
||||
import java.io.PipedOutputStream;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.Vector;
|
||||
|
||||
public class ListDoubleIndentTest {
|
||||
public static void main(final String[] args) throws InterruptedException,
|
||||
InvocationTargetException {
|
||||
EventQueue.invokeAndWait(new ListDoubleIndentTest()::performTest);
|
||||
}
|
||||
|
||||
public void performTest() {
|
||||
boolean bReturn = false;
|
||||
int iCompCount = 0;
|
||||
int iNotEqual = 0;
|
||||
int iIndentWrong = 0;
|
||||
System.out.println("Test: Check indentation");
|
||||
Vector v = new Vector();
|
||||
String sLine;
|
||||
String sReturn;
|
||||
String sExpTrim;
|
||||
Button b1, b2, b3, b4, b5;
|
||||
Frame f = null;
|
||||
|
||||
try {
|
||||
f = new Frame("ListDoubleIndentTest");
|
||||
|
||||
f.add(b1 = new Button("North"), BorderLayout.NORTH, 0);
|
||||
f.add(b2 = new Button("South"), BorderLayout.SOUTH, 1);
|
||||
f.add(b3 = new Button("East"), BorderLayout.EAST, 2);
|
||||
f.add(b4 = new Button("West"), BorderLayout.WEST, 3);
|
||||
f.add(b5 = new Button("Center"), BorderLayout.CENTER, -1);
|
||||
|
||||
String[] sExpected = {f.toString(), b1.toString(), b2.toString(),
|
||||
b3.toString(), b4.toString(), b5.toString()};
|
||||
|
||||
iCompCount = f.getComponentCount();
|
||||
System.out.println("Component count: " + iCompCount);
|
||||
|
||||
for (int j = 0; j <= 10; j++) {
|
||||
PipedInputStream pin = new PipedInputStream();
|
||||
PrintStream output = new PrintStream(new PipedOutputStream(pin), true);
|
||||
BufferedReader input = new BufferedReader(new InputStreamReader(pin));
|
||||
|
||||
f.list(output, j);
|
||||
|
||||
output.flush();
|
||||
output.close();
|
||||
|
||||
while ((sLine = input.readLine()) != null) {
|
||||
v.addElement(sLine);
|
||||
}
|
||||
|
||||
for (int i = 0; i < v.size(); i++) {
|
||||
sReturn = (String)v.elementAt(i);
|
||||
sExpTrim = sExpected[i].trim();
|
||||
|
||||
if (!(sExpTrim.equals(sReturn.trim()))) {
|
||||
System.out.println("iNotEqual");
|
||||
++iNotEqual;
|
||||
}
|
||||
|
||||
int iSpace = sReturn.lastIndexOf(' ') + 1;
|
||||
|
||||
if (i == 0) {
|
||||
System.out.println("Indent set at: " + j);
|
||||
System.out.println("Indent return: " + iSpace);
|
||||
if (iSpace != j) {
|
||||
System.out.println("iIndentWrong1");
|
||||
++iIndentWrong;
|
||||
}
|
||||
} else {
|
||||
if (iSpace != (j + 1)) {
|
||||
System.out.println(iSpace + "; " + j);
|
||||
++iIndentWrong;
|
||||
}
|
||||
}
|
||||
System.out.println(sReturn);
|
||||
}
|
||||
v.removeAllElements();
|
||||
v.trimToSize();
|
||||
}
|
||||
|
||||
if (iNotEqual == 0 && iIndentWrong == 0) {
|
||||
bReturn = true;
|
||||
} else {
|
||||
bReturn = false;
|
||||
}
|
||||
|
||||
} catch(IOException e) {
|
||||
bReturn = false;
|
||||
System.out.println ("Unexpected Exception thrown: " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (f != null) {
|
||||
f.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
if (bReturn) {
|
||||
System.out.println("Test for Container.list Passed");
|
||||
} else {
|
||||
System.out.println("Test for Container.list Failed");
|
||||
throw new RuntimeException("Test FAILED");
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user