Skip to content

Commit d930cc5

Browse files
manukumarvsaivanov-jdk
authored andcommitted
8162380: [TEST_BUG] MouseEvent/.../AltGraphModifierTest.java has only "Fail" button
Backport-of: 34c3ac0316dbd29ae670db51bd9230a1e77382d9
1 parent 8b686d9 commit d930cc5

File tree

2 files changed

+44
-213
lines changed

2 files changed

+44
-213
lines changed

test/jdk/ProblemList.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -803,7 +803,6 @@ java/awt/event/MouseEvent/SpuriousExitEnter/SpuriousExitEnter_2.java 7131438,802
803803
java/awt/Modal/WsDisabledStyle/CloseBlocker/CloseBlocker.java 7187741 linux-all,macosx-all
804804
java/awt/xembed/server/TestXEmbedServerJava.java 8001150,8004031 generic-all
805805
java/awt/Modal/PrintDialogsTest/PrintDialogsTest.java 8068378 generic-all
806-
java/awt/event/MouseEvent/AltGraphModifierTest/AltGraphModifierTest.java 8162380 generic-all
807806
java/awt/image/VolatileImage/VolatileImageConfigurationTest.java 8171069 macosx-all,linux-all
808807
java/awt/Modal/InvisibleParentTest/InvisibleParentTest.java 8172245 linux-all
809808
java/awt/Frame/FrameStateTest/FrameStateTest.java 8203920 macosx-all,linux-all
Lines changed: 44 additions & 212 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -22,238 +22,70 @@
2222
*/
2323

2424
/*
25-
@test
26-
@bug 8041928 8158616
27-
@requires (os.family != "mac")
28-
@summary Confirm that the Alt-Gr Modifier bit is set correctly.
29-
@run main/manual AltGraphModifierTest
25+
* @test
26+
* @bug 8041928 8158616
27+
* @requires (os.family != "mac")
28+
* @summary Confirm that the Alt-Gr Modifier bit is set correctly.
29+
* @library /java/awt/regtesthelpers
30+
* @build PassFailJFrame
31+
* @run main/manual AltGraphModifierTest
3032
*/
3133

32-
import java.awt.Button;
33-
import java.awt.Dialog;
3434
import java.awt.Frame;
35-
import java.awt.Panel;
36-
import java.awt.TextArea;
37-
import java.awt.event.ActionEvent;
38-
import java.awt.event.ActionListener;
3935
import java.awt.event.InputEvent;
4036
import java.awt.event.MouseAdapter;
4137
import java.awt.event.MouseEvent;
4238

4339
public class AltGraphModifierTest {
44-
private static void init() throws Exception {
45-
String[] instructions
46-
= {
47-
"This test is for verifying Alt-Gr modifier of an event.",
48-
"Linux :-",
49-
"1. Please check if Alt-Gr key is present on keyboard.",
50-
"2. If present, press the Alt-Gr key and perform",
51-
" mouse click on the TestWindow.",
52-
"3. Navigate to System Settings-> Keyboard-> Shortcuts->",
53-
" Typing.",
54-
"4. Select an option for the Alternative Characters Key",
55-
" For example. Right Alt",
56-
"5. Close the settings and navigate to test",
57-
"6. Press Right Alt Key & perform mouse click on the",
58-
" TestWindow",
59-
"7. Test will exit by itself with appropriate result.",
60-
" ",
61-
};
6240

63-
Sysout.createDialog();
64-
Sysout.printInstructions(instructions);
41+
public static void main(String[] args) throws Exception {
42+
String INSTRUCTIONS = """
43+
This test is for verifying Alt-Gr modifier of an event.
44+
Please check if Alt-Gr key is present on keyboard.
45+
If not present, press Pass.
46+
On Windows:
47+
Press Alt-Gr or Right Alt key and simultaneously
48+
perform mouse click on the "TestWindow".
49+
On Linux:
50+
Navigate to
51+
System Settings-> Keyboard-> Special Character Entry
52+
Select "Right Alt" option for the "Alternate Characters Key"
53+
Close the settings and navigate to test
54+
Press Right Alt Key & simultaneously
55+
perform mouse click on the "TestWindow".
56+
57+
If the system does not have such setting, press Pass.
58+
After the test, change the Setting of "Alternate Characters Key"
59+
back to "Layout default".
60+
61+
If "Alt-Gr Modifier bit is set" message is displayed in logArea,
62+
press Pass else press Fail.
63+
""";
64+
65+
PassFailJFrame.builder()
66+
.instructions(INSTRUCTIONS)
67+
.columns(35)
68+
.testUI(AltGraphModifierTest::initTestWindow)
69+
.logArea()
70+
.build()
71+
.awaitAndCheck();
6572
}
6673

67-
static Frame mainFrame;
68-
public static void initTestWindow() {
69-
mainFrame = new Frame();
74+
public static Frame initTestWindow() {
75+
Frame mainFrame = new Frame();
7076
mainFrame.setTitle("TestWindow");
7177
mainFrame.setBounds(700, 10, 300, 300);
7278
mainFrame.addMouseListener(new MouseAdapter() {
7379
@Override
7480
public void mousePressed(MouseEvent e) {
7581
int ex = e.getModifiersEx();
7682
if ((ex & InputEvent.ALT_GRAPH_DOWN_MASK) == 0) {
77-
AltGraphModifierTest.fail("Alt-Gr Modifier bit is not set.");
83+
PassFailJFrame.log("Alt-Gr Modifier bit is not set.");
7884
} else {
79-
AltGraphModifierTest.pass();
85+
PassFailJFrame.log("Alt-Gr Modifier bit is set");
8086
}
8187
}
8288
});
83-
mainFrame.setVisible(true);
84-
}
85-
86-
public static void dispose() {
87-
Sysout.dispose();
88-
mainFrame.dispose();
89-
}
90-
91-
/**
92-
* ***************************************************
93-
* Standard Test Machinery Section DO NOT modify anything in this section --
94-
* it's a standard chunk of code which has all of the synchronisation
95-
* necessary for the test harness. By keeping it the same in all tests, it
96-
* is easier to read and understand someone else's test, as well as insuring
97-
* that all tests behave correctly with the test harness. There is a section
98-
* following this for test-defined classes
99-
* ****************************************************
100-
*/
101-
private static boolean theTestPassed = false;
102-
private static boolean testGeneratedInterrupt = false;
103-
private static String failureMessage = "";
104-
private static Thread mainThread = null;
105-
final private static int sleepTime = 300000;
106-
107-
public static void main(String args[]) throws Exception {
108-
mainThread = Thread.currentThread();
109-
try {
110-
init();
111-
initTestWindow();
112-
} catch (Exception e) {
113-
e.printStackTrace();
114-
}
115-
try {
116-
mainThread.sleep(sleepTime);
117-
} catch (InterruptedException e) {
118-
dispose();
119-
if (testGeneratedInterrupt && !theTestPassed) {
120-
throw new Exception(failureMessage);
121-
}
122-
}
123-
if (!testGeneratedInterrupt) {
124-
dispose();
125-
throw new RuntimeException("Timed out after " + sleepTime / 1000
126-
+ " seconds");
127-
}
128-
}
129-
130-
public static synchronized void pass() {
131-
theTestPassed = true;
132-
testGeneratedInterrupt = true;
133-
mainThread.interrupt();
134-
}
135-
136-
public static synchronized void fail(String whyFailed) {
137-
theTestPassed = false;
138-
testGeneratedInterrupt = true;
139-
failureMessage = whyFailed;
140-
mainThread.interrupt();
141-
}
142-
}
143-
144-
// *********** End Standard Test Machinery Section **********
145-
/**
146-
* **************************************************
147-
* Standard Test Machinery DO NOT modify anything below -- it's a standard chunk
148-
* of code whose purpose is to make user interaction uniform, and thereby make
149-
* it simpler to read and understand someone else's test.
150-
* **************************************************
151-
*/
152-
/**
153-
* This is part of the standard test machinery. It creates a dialog (with the
154-
* instructions), and is the interface for sending text messages to the user. To
155-
* print the instructions, send an array of strings to Sysout.createDialog
156-
* WithInstructions method. Put one line of instructions per array entry. To
157-
* display a message for the tester to see, simply call Sysout.println with the
158-
* string to be displayed. This mimics System.out.println but works within the
159-
* test harness as well as standalone.
160-
*/
161-
class Sysout {
162-
private static TestDialog dialog;
163-
private static Frame frame;
164-
165-
public static void createDialog() {
166-
frame = new Frame();
167-
dialog = new TestDialog(frame, "Instructions");
168-
String[] defInstr = {"Instructions will appear here. ", ""};
169-
dialog.printInstructions(defInstr);
170-
dialog.show();
171-
println("Any messages for the tester will display here.");
172-
}
173-
174-
public static void printInstructions(String[] instructions) {
175-
dialog.printInstructions(instructions);
176-
}
177-
178-
public static void println(String messageIn) {
179-
dialog.displayMessage(messageIn);
180-
}
181-
182-
public static void dispose() {
183-
dialog.dispose();
184-
frame.dispose();
185-
}
186-
}
187-
188-
/**
189-
* This is part of the standard test machinery. It provides a place for the test
190-
* instructions to be displayed, and a place for interactive messages to the
191-
* user to be displayed. To have the test instructions displayed, see Sysout. To
192-
* have a message to the user be displayed, see Sysout. Do not call anything in
193-
* this dialog directly.
194-
*/
195-
class TestDialog extends Dialog implements ActionListener {
196-
TextArea instructionsText;
197-
TextArea messageText;
198-
int maxStringLength = 80;
199-
Panel buttonP;
200-
Button failB;
201-
202-
// DO NOT call this directly, go through Sysout
203-
public TestDialog(Frame frame, String name) {
204-
super(frame, name);
205-
int scrollBoth = TextArea.SCROLLBARS_BOTH;
206-
instructionsText = new TextArea("", 15, maxStringLength, scrollBoth);
207-
add("North", instructionsText);
208-
209-
messageText = new TextArea("", 5, maxStringLength, scrollBoth);
210-
add("Center", messageText);
211-
212-
buttonP = new Panel();
213-
failB = new Button("Fail");
214-
failB.setActionCommand("fail");
215-
failB.addActionListener(this);
216-
buttonP.add("Center", failB);
217-
218-
add("South", buttonP);
219-
pack();
220-
setVisible(true);
221-
}
222-
223-
// DO NOT call this directly, go through Sysout
224-
public void printInstructions(String[] instructions) {
225-
instructionsText.setText("");
226-
String printStr, remainingStr;
227-
for (int i = 0; i < instructions.length; i++) {
228-
remainingStr = instructions[i];
229-
while (remainingStr.length() > 0) {
230-
if (remainingStr.length() >= maxStringLength) {
231-
int posOfSpace = remainingStr.
232-
lastIndexOf(' ', maxStringLength - 1);
233-
234-
if (posOfSpace <= 0) {
235-
posOfSpace = maxStringLength - 1;
236-
}
237-
238-
printStr = remainingStr.substring(0, posOfSpace + 1);
239-
remainingStr = remainingStr.substring(posOfSpace + 1);
240-
}
241-
else {
242-
printStr = remainingStr;
243-
remainingStr = "";
244-
}
245-
instructionsText.append(printStr + "\n");
246-
}
247-
}
248-
}
249-
250-
public void displayMessage(String messageIn) {
251-
messageText.append(messageIn + "\n");
252-
}
253-
254-
public void actionPerformed(ActionEvent e) {
255-
if (e.getActionCommand() == "fail") {
256-
AltGraphModifierTest.fail("User Clicked Fail");
257-
}
89+
return mainFrame;
25890
}
25991
}

0 commit comments

Comments
 (0)