|
1 | 1 | /* |
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. |
3 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 | 4 | * |
5 | 5 | * This code is free software; you can redistribute it and/or modify it |
|
22 | 22 | */ |
23 | 23 |
|
24 | 24 | /* |
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 |
30 | 32 | */ |
31 | 33 |
|
32 | | -import java.awt.Button; |
33 | | -import java.awt.Dialog; |
34 | 34 | 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; |
39 | 35 | import java.awt.event.InputEvent; |
40 | 36 | import java.awt.event.MouseAdapter; |
41 | 37 | import java.awt.event.MouseEvent; |
42 | 38 |
|
43 | 39 | 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 | | - }; |
62 | 40 |
|
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(); |
65 | 72 | } |
66 | 73 |
|
67 | | - static Frame mainFrame; |
68 | | - public static void initTestWindow() { |
69 | | - mainFrame = new Frame(); |
| 74 | + public static Frame initTestWindow() { |
| 75 | + Frame mainFrame = new Frame(); |
70 | 76 | mainFrame.setTitle("TestWindow"); |
71 | 77 | mainFrame.setBounds(700, 10, 300, 300); |
72 | 78 | mainFrame.addMouseListener(new MouseAdapter() { |
73 | 79 | @Override |
74 | 80 | public void mousePressed(MouseEvent e) { |
75 | 81 | int ex = e.getModifiersEx(); |
76 | 82 | 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."); |
78 | 84 | } else { |
79 | | - AltGraphModifierTest.pass(); |
| 85 | + PassFailJFrame.log("Alt-Gr Modifier bit is set"); |
80 | 86 | } |
81 | 87 | } |
82 | 88 | }); |
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; |
258 | 90 | } |
259 | 91 | } |
0 commit comments