Skip to content

Commit ad7c475

Browse files
author
Alexander Zuev
committed
8353655: Clean up and open source KeyEvent related tests (Part 1)
Reviewed-by: abhiscxk
1 parent 1b4b317 commit ad7c475

File tree

3 files changed

+316
-0
lines changed

3 files changed

+316
-0
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* Copyright (c) 2000, 2025, 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 4308606
27+
* @summary Tests whether the keys on the numeric keyboard work
28+
* correctly under French input locale.
29+
* @key i18n
30+
* @library /java/awt/regtesthelpers
31+
* @build PassFailJFrame
32+
* @run main/manual FrenchKeyboard
33+
*/
34+
35+
import java.awt.BorderLayout;
36+
import java.awt.Frame;
37+
import java.awt.TextField;
38+
import java.lang.reflect.InvocationTargetException;
39+
40+
public class FrenchKeyboard extends Frame {
41+
static String INSTRUCTIONS = """
42+
This test is intended for computers with French input method. If French
43+
input method can not be enabled or your keyboard does not have a numeric
44+
keypad press "Pass" to skip the test.
45+
Make sure that French input method is active and the NumLock is on.
46+
Click on the text field in the window called "Check your keys"
47+
and type once of each of the following keys on the numeric keypad:
48+
/*-+1234567890
49+
If all the expected characters are displayed exactly once press "Pass".
50+
If any characters do not display or display multiple times press "Fail".
51+
""";
52+
53+
public FrenchKeyboard() {
54+
super("Check your keys");
55+
setLayout(new BorderLayout());
56+
TextField tf = new TextField(30);
57+
add(tf, BorderLayout.CENTER);
58+
pack();
59+
}
60+
61+
public static void main(String[] args) throws InterruptedException,
62+
InvocationTargetException {
63+
PassFailJFrame.builder()
64+
.title("FrenchKeyboard Instructions")
65+
.instructions(INSTRUCTIONS)
66+
.testUI(FrenchKeyboard::new)
67+
.build()
68+
.awaitAndCheck();
69+
}
70+
}
71+
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
/*
2+
* Copyright (c) 1999, 2025, 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 4268912 4115514
27+
* summary Ensures that KeyEvent has right results for the following
28+
* non-numpad keys: Home/Eng/PageUp/PageDn
29+
* @library /java/awt/regtesthelpers
30+
* @build PassFailJFrame
31+
* @run main/manual HomeEndKeyTest
32+
*/
33+
34+
import java.awt.BorderLayout;
35+
import java.awt.Frame;
36+
import java.awt.TextField;
37+
import java.awt.event.KeyEvent;
38+
import java.awt.event.KeyListener;
39+
import java.lang.reflect.InvocationTargetException;
40+
41+
42+
public class HomeEndKeyTest extends Frame implements KeyListener {
43+
static String INSTRUCTIONS = """
44+
Before starting this test make sure that system shortcuts and
45+
keybindings for the keys in the list below are disabled.
46+
For example pressing "Print Screen" key should not launch
47+
screen capturing software.
48+
Click on the text field in the window named "Check keyCode values"
49+
and one by one start typing the keys in the list below.
50+
(If you do not have some of the keys on your keyboard skip it
51+
and move to the next line).
52+
After clicking each key look at the log area - the printed name
53+
and key code should correspond to the ones for the key you typed.
54+
Note that on some systems the graphical symbol for the key
55+
can be printed instead of the symbolic name.
56+
If you do not encounter unexpected key codes for the keys you typed,
57+
press "Pass". Otherwise press "Fail".
58+
59+
Key Keycode
60+
-------------------------
61+
PrintScreen 154
62+
ScrollLock 145
63+
Pause 19
64+
65+
Insert 155
66+
Del 127
67+
Home 36
68+
End 35
69+
PageUp 33
70+
PageDown 34
71+
72+
Left Arrow 37
73+
Up Arrow 38
74+
Right Arrow 39
75+
Down Arrow 40
76+
""";
77+
78+
public HomeEndKeyTest() {
79+
super("Check KeyCode values");
80+
setLayout(new BorderLayout());
81+
TextField tf = new TextField(30);
82+
tf.addKeyListener(this);
83+
add(tf, BorderLayout.CENTER);
84+
pack();
85+
}
86+
87+
public void keyPressed(KeyEvent evt) {
88+
printKey(evt);
89+
}
90+
91+
public void keyTyped(KeyEvent ignore) {
92+
}
93+
94+
public void keyReleased(KeyEvent evt) {
95+
printKey(evt);
96+
}
97+
98+
protected void printKey(KeyEvent evt) {
99+
String str;
100+
switch (evt.getID()) {
101+
case KeyEvent.KEY_PRESSED:
102+
str = "KEY_PRESSED";
103+
break;
104+
case KeyEvent.KEY_RELEASED:
105+
str = "KEY_RELEASED";
106+
break;
107+
default:
108+
str = "unknown type";
109+
}
110+
111+
str = str + ":name=" + KeyEvent.getKeyText(evt.getKeyCode()) +
112+
" keyCode=" + evt.getKeyCode();
113+
PassFailJFrame.log(str);
114+
}
115+
116+
public static void main(String[] args) throws InterruptedException,
117+
InvocationTargetException {
118+
PassFailJFrame.builder()
119+
.title("HomeEndKeyTest Instructions")
120+
.instructions(INSTRUCTIONS)
121+
.logArea(20)
122+
.testUI(HomeEndKeyTest::new)
123+
.build()
124+
.awaitAndCheck();
125+
}
126+
}
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
/*
2+
* Copyright (c) 1998, 2025, 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 4083691
27+
* @summary Ensures that KeyEvent has right results for the following
28+
* keys \*-+
29+
* @library /java/awt/regtesthelpers
30+
* @build PassFailJFrame
31+
* @run main/manual NumpadTest
32+
*/
33+
34+
import java.awt.BorderLayout;
35+
import java.awt.Frame;
36+
import java.awt.TextField;
37+
import java.awt.event.KeyEvent;
38+
import java.awt.event.KeyListener;
39+
import java.lang.reflect.InvocationTargetException;
40+
41+
42+
public class NumpadTest extends Frame implements KeyListener {
43+
static String INSTRUCTIONS = """
44+
This test requires a keyboard with a numeric keypad (numpad).
45+
If your keyboard does not have a numpad press "Pass" to skip testing.
46+
Make sure NumLock is on.
47+
Click on the text field in the window named "Check KeyChar values".
48+
Then, type the following keys/characters in the TextField.
49+
using the numpad keys:
50+
/*-+
51+
52+
Verify that the keyChar and keyCode is correct for each key pressed.
53+
Remember that the keyCode for the KEY_TYPED event should be zero.
54+
Also verify that the character you typed appears in the TextField.
55+
56+
Key Name keyChar Keycode
57+
-------------------------------------
58+
/ Divide / 47 111
59+
* Multiply * 42 106
60+
- Subtract - 45 109
61+
+ Add + 43 107
62+
63+
Now repeat with the NumLock off.
64+
65+
If all keycodes are valid and expected characters appear
66+
in the text field press "Pass". Otherwise press "Fail".
67+
""";
68+
69+
public NumpadTest() {
70+
super("Check KeyChar values");
71+
setLayout(new BorderLayout());
72+
TextField tf = new TextField(30);
73+
tf.addKeyListener(this);
74+
add(tf, BorderLayout.CENTER);
75+
pack();
76+
}
77+
public void keyPressed(KeyEvent evt) {
78+
printKey(evt);
79+
}
80+
81+
public void keyTyped(KeyEvent evt) {
82+
printKey(evt);
83+
}
84+
85+
public void keyReleased(KeyEvent evt) {
86+
printKey(evt);
87+
}
88+
89+
protected void printKey(KeyEvent evt) {
90+
switch (evt.getID()) {
91+
case KeyEvent.KEY_TYPED:
92+
break;
93+
case KeyEvent.KEY_PRESSED:
94+
break;
95+
case KeyEvent.KEY_RELEASED:
96+
break;
97+
default:
98+
return;
99+
}
100+
101+
if (evt.isActionKey()) {
102+
PassFailJFrame.log("params= " + evt.paramString() + " KeyChar: " +
103+
(int) evt.getKeyChar() + " Action Key");
104+
} else {
105+
PassFailJFrame.log("params= " + evt.paramString() + " KeyChar: " +
106+
(int) evt.getKeyChar());
107+
}
108+
}
109+
110+
public static void main(String[] args) throws InterruptedException, InvocationTargetException {
111+
PassFailJFrame.builder()
112+
.title("NumpadTest Instructions")
113+
.instructions(INSTRUCTIONS)
114+
.logArea(20)
115+
.testUI(NumpadTest::new)
116+
.build()
117+
.awaitAndCheck();
118+
}
119+
}

0 commit comments

Comments
 (0)