Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/swing/JTextField/MissingCharsKorean/MissingCharsKorean.java
41154 views
1
/*
2
* Copyright (c) 2017, 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
* @test
25
* @bug 8180370
26
* @summary Checks whether non-alpha chars are skipped while entering KoreanText
27
* @requires (os.family == "mac")
28
* @run main/manual MissingCharsKorean
29
*/
30
31
/**
32
* This test requires a manual intervention as the keyboard layout has to be
33
* changed to 2-set Korean. Once the keyboard layout has been selected, click on
34
* Start Test to start the automated tests. Along with testing for non-alpha
35
* chars, this test also ensures that the MarkedText property is not broken by
36
* running cases where different glyphs are combined and also cases where
37
* combined glyphs are broken.
38
*/
39
40
import java.awt.AWTException;
41
import java.awt.Font;
42
import java.awt.BorderLayout;
43
import java.awt.Dimension;
44
import java.awt.FlowLayout;
45
import java.awt.Robot;
46
import java.awt.event.WindowAdapter;
47
import java.awt.event.WindowEvent;
48
import javax.swing.JButton;
49
import javax.swing.JFrame;
50
import javax.swing.JPanel;
51
import javax.swing.JTextArea;
52
import javax.swing.SwingUtilities;
53
import javax.swing.WindowConstants;
54
import java.awt.event.KeyEvent;
55
import java.util.concurrent.CountDownLatch;
56
import javax.swing.JLabel;
57
import javax.swing.JTextField;
58
59
public class MissingCharsKorean {
60
private static boolean testPassed = false;
61
private static boolean startTest = false;
62
private static int expectedResults[] = null;
63
private static int inKeyCodes[][] = null;
64
65
private static JFrame frame = null;
66
private static JLabel lblTestStatus = null;
67
private static JTextField textFieldMain = null;
68
private static String testResult;
69
70
private static final CountDownLatch testStartLatch = new CountDownLatch(1);
71
72
public static void main(String[] args) throws Exception {
73
SwingUtilities.invokeAndWait(() -> {
74
setupUI();
75
});
76
77
testStartLatch.await();
78
79
if (startTest) {
80
glyphTest();
81
82
frame.dispose();
83
84
if (testPassed) {
85
System.out.println(testResult);
86
} else {
87
throw new RuntimeException("Korean text missing characters : "
88
+ testResult);
89
}
90
} else {
91
throw new RuntimeException("User has not executed the test");
92
}
93
}
94
95
private static void setupUI() {
96
String description = " 1. Go to \"System Preferences -> Keyboard -> "
97
+ "Input Sources\" and add \"2-Set Korean\""
98
+ " from Korean language group \n"
99
+ " 2. Set current IM to \"2-Set Korean\" \n"
100
+ " 3. Try typing in the text field to ensure"
101
+ " that Korean keyboard has been successfully"
102
+ " selected \n"
103
+ " 4. Now click on \"Start Test\" button \n";
104
String title = "Missing Characters Korean Test (Mac OS)";
105
106
frame = new JFrame(title);
107
108
JPanel mainPanel = new JPanel(new BorderLayout());
109
110
JPanel textEditPanel = new JPanel(new FlowLayout());
111
112
textFieldMain = new JTextField(20);
113
Font font = new Font("Source Han Serif K", Font.BOLD,12);
114
textFieldMain.setFont(font);
115
116
textEditPanel.add(textFieldMain);
117
118
mainPanel.add(textEditPanel, BorderLayout.CENTER);
119
120
JTextArea textArea = new JTextArea(description);
121
textArea.setEditable(false);
122
final JButton btnStartTest = new JButton("Start Test");
123
final JButton btnCancelTest = new JButton("Cancel Test");
124
125
btnStartTest.addActionListener((e) -> {
126
btnStartTest.setEnabled(false);
127
btnCancelTest.setEnabled(false);
128
startTest = true;
129
testStartLatch.countDown();
130
});
131
132
btnCancelTest.addActionListener((e) -> {
133
frame.dispose();
134
testStartLatch.countDown();
135
});
136
mainPanel.add(textArea, BorderLayout.NORTH);
137
138
JPanel buttonPanel = new JPanel(new FlowLayout());
139
buttonPanel.add(btnStartTest);
140
buttonPanel.add(btnCancelTest);
141
mainPanel.add(buttonPanel, BorderLayout.SOUTH);
142
143
lblTestStatus = new JLabel("");
144
lblTestStatus.setMinimumSize(new Dimension(150, 20));
145
lblTestStatus.setPreferredSize(new Dimension(150, 20));
146
lblTestStatus.setVisible(true);
147
textEditPanel.add(lblTestStatus);
148
149
frame.add(mainPanel);
150
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
151
frame.pack();
152
frame.setLocationRelativeTo(null);
153
154
frame.addWindowListener(new WindowAdapter() {
155
@Override
156
public void windowClosing(WindowEvent e) {
157
testStartLatch.countDown();
158
}
159
@Override
160
public void windowOpened( WindowEvent e ){
161
textFieldMain.requestFocusInWindow();
162
}
163
});
164
165
frame.setVisible(true);
166
}
167
168
private static void glyphTest() {
169
try {
170
Robot robotKeySimulator = new Robot();
171
performTasks(robotKeySimulator);
172
} catch (AWTException e) {
173
System.err.print("Creation Of Robot Failed : " + e.getMessage());
174
testPassed = false;
175
}
176
}
177
178
public static void performTasks(Robot robotForKeyInput) {
179
int taskCount = 0;
180
181
lblTestStatus.setText("Running Tests..");
182
robotForKeyInput.setAutoDelay(500);
183
184
while (setKeyInput(taskCount)) {
185
textFieldMain.setText("");
186
textFieldMain.requestFocusInWindow();
187
enterInput(robotForKeyInput, inKeyCodes);
188
taskCount++;
189
190
try {
191
SwingUtilities.invokeAndWait(() -> {
192
validateInput();
193
});
194
} catch (Exception e) {
195
System.err.print("validateInput Failed : " + e.getMessage());
196
testPassed = false;
197
break;
198
}
199
200
if (!testPassed) {
201
break;
202
}
203
setTaskStatus(false, taskCount);
204
}
205
setTaskStatus(true, taskCount);
206
}
207
208
private static boolean setKeyInput(int iCount) {
209
boolean inputSet = true;
210
211
switch(iCount) {
212
case 0:
213
// Input Korean q (#12610) /(#47)
214
expectedResults = new int[]{ 12610, 47 };
215
inKeyCodes = new int[][] { {KeyEvent.VK_Q},
216
{KeyEvent.VK_SLASH}
217
};
218
break;
219
220
case 1:
221
// Input Korean q (#12610) /(#47) gh (#54840) \(#92)
222
expectedResults = new int[]{ 12610, 47, 54840, 92 };
223
inKeyCodes = new int[][] { {KeyEvent.VK_Q},
224
{KeyEvent.VK_SLASH},
225
{KeyEvent.VK_G},
226
{KeyEvent.VK_H},
227
{KeyEvent.VK_BACK_SLASH}
228
};
229
break;
230
231
case 2:
232
// Input Korean q (#12610) /(#47) ghq (#54857) \(#92)
233
expectedResults = new int[]{ 12610, 47, 54857, 92 };
234
inKeyCodes = new int[][] { {KeyEvent.VK_Q},
235
{KeyEvent.VK_SLASH},
236
{KeyEvent.VK_G},
237
{KeyEvent.VK_H},
238
{KeyEvent.VK_Q},
239
{KeyEvent.VK_BACK_SLASH}
240
};
241
break;
242
243
case 3:
244
// Input Korean q (#12610) /(#47) gh (#54840) \(#92)
245
expectedResults = new int[]{ 12610, 47, 54840, 92 };
246
inKeyCodes = new int[][] { {KeyEvent.VK_Q},
247
{KeyEvent.VK_SLASH},
248
{KeyEvent.VK_G},
249
{KeyEvent.VK_H},
250
{KeyEvent.VK_Q},
251
{KeyEvent.VK_BACK_SPACE},
252
{KeyEvent.VK_BACK_SLASH}
253
};
254
break;
255
256
case 4:
257
// Input Korean q (#12610) /(#47) g (#12622) \(#92)
258
expectedResults = new int[]{ 12610, 47, 12622, 92 };
259
inKeyCodes = new int[][] { {KeyEvent.VK_Q},
260
{KeyEvent.VK_SLASH},
261
{KeyEvent.VK_G},
262
{KeyEvent.VK_H},
263
{KeyEvent.VK_Q},
264
{KeyEvent.VK_BACK_SPACE},
265
{KeyEvent.VK_BACK_SPACE},
266
{KeyEvent.VK_BACK_SLASH}
267
};
268
break;
269
270
default:
271
inputSet = false;
272
break;
273
}
274
275
return inputSet;
276
}
277
278
private static void enterInput(Robot robotKeyInput, int keyInputs[][]) {
279
for (int i = 0; i < keyInputs.length; i++) {
280
String strKeyInput = "KeyPress=>";
281
final int noOfKeyInputs = keyInputs[i].length;
282
for (int j = 0; j < noOfKeyInputs; j++) {
283
robotKeyInput.keyPress(keyInputs[i][j]);
284
strKeyInput += (Integer.toHexString(keyInputs[i][j])) + ":";
285
}
286
287
strKeyInput += "KeyRelease=>";
288
for (int j = noOfKeyInputs - 1; j >= 0; j--) {
289
robotKeyInput.keyRelease(keyInputs[i][j]);
290
strKeyInput += (Integer.toHexString(keyInputs[i][j])) + ":";
291
}
292
System.out.println(strKeyInput);
293
}
294
}
295
296
private static void validateInput() {
297
testPassed = false;
298
299
if (expectedResults != null) {
300
String strCurr = textFieldMain.getText();
301
if (expectedResults.length == strCurr.length()) {
302
testPassed = true;
303
304
for (int i = 0; i < strCurr.length(); i++) {
305
final int charActual = strCurr.charAt(i);
306
if (charActual != expectedResults[i]) {
307
System.err.println("<" + i + "> Actual = " + charActual
308
+ " Expected = " + expectedResults[i]);
309
testPassed = false;
310
break;
311
}
312
}
313
}
314
}
315
}
316
317
public static void setTaskStatus(boolean allTasksPerformed, int taskCount) {
318
if (testPassed) {
319
if (allTasksPerformed) {
320
testResult = "All Tests Passed";
321
} else {
322
testResult = "Test " + Integer.toString(taskCount)
323
+ " Passed";
324
}
325
} else {
326
testResult = "Test " + Integer.toString(taskCount)
327
+ " Failed";
328
}
329
lblTestStatus.setText(testResult);
330
}
331
}
332
333