Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/swing/JTextArea/8148555/JTextAreaEmojiTest.java
41153 views
1
/*
2
* Copyright (c) 2015, 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
import java.awt.Color;
25
import java.awt.GridBagConstraints;
26
import java.awt.GridBagLayout;
27
import java.awt.event.ActionEvent;
28
import java.awt.event.ActionListener;
29
import javax.swing.BorderFactory;
30
import javax.swing.JButton;
31
import javax.swing.JFrame;
32
import javax.swing.JPanel;
33
import javax.swing.JTextArea;
34
import javax.swing.SwingUtilities;
35
import static javax.swing.WindowConstants.EXIT_ON_CLOSE;
36
import java.util.concurrent.CountDownLatch;
37
import java.util.concurrent.TimeUnit;
38
39
/* @test
40
* @key headful
41
* @bug 8148555 8181782
42
* @summary verifies JTextArea emoji enter exception. Emoji is not supported.
43
* @requires (os.family=="mac")
44
* @run main/manual JTextAreaEmojiTest
45
*/
46
public class JTextAreaEmojiTest implements
47
ActionListener {
48
49
private static GridBagLayout layout;
50
private static JPanel textAreaPanel;
51
private static JPanel mainControlPanel;
52
private static JPanel instructionPanel;
53
private static JPanel resultButtonPanel;
54
private static JPanel controlPanel;
55
private static JTextArea instructionTextArea;
56
private static JTextArea emojiTextArea;
57
private static JButton passButton;
58
private static JButton failButton;
59
60
private static JFrame mainFrame;
61
private static final CountDownLatch testRunLatch = new CountDownLatch(1);
62
63
public static void main(String[] args) throws Exception {
64
65
JTextAreaEmojiTest test = new JTextAreaEmojiTest();
66
boolean status = testRunLatch.await(5, TimeUnit.MINUTES);
67
68
if (!status) {
69
throw new RuntimeException("Test timed out");
70
}
71
}
72
73
public JTextAreaEmojiTest() throws Exception {
74
createControlPanelUI();
75
}
76
77
public final void createControlPanelUI() throws Exception {
78
SwingUtilities.invokeAndWait(new Runnable() {
79
@Override
80
public void run() {
81
layout = new GridBagLayout();
82
mainControlPanel = new JPanel(layout);
83
instructionPanel = new JPanel(layout);
84
resultButtonPanel = new JPanel(layout);
85
textAreaPanel = new JPanel(layout);
86
controlPanel = new JPanel(layout);
87
88
GridBagConstraints gbc = new GridBagConstraints();
89
String instructions
90
= "1) Text Area size should be zero"
91
+ "\n2) Select one emoji from Character Viewer"
92
+ "\n3) If Text Area size increases displaying"
93
+ "Blank or supported emoji for default font, click pass"
94
+ "\n4) Else press fail";
95
instructionTextArea = new JTextArea();
96
instructionTextArea.setText(instructions);
97
instructionTextArea.setEnabled(false);
98
instructionTextArea.setDisabledTextColor(Color.black);
99
instructionTextArea.setBackground(Color.white);
100
instructionTextArea.setBorder(
101
BorderFactory.createLineBorder(Color.black));
102
gbc.gridx = 0;
103
gbc.gridy = 0;
104
gbc.fill = GridBagConstraints.HORIZONTAL;
105
instructionPanel.add(instructionTextArea, gbc);
106
107
emojiTextArea = new JTextArea();
108
emojiTextArea.setEnabled(true);
109
emojiTextArea.setDisabledTextColor(Color.black);
110
emojiTextArea.setBackground(Color.white);
111
emojiTextArea.setBorder(
112
BorderFactory.createLineBorder(Color.black));
113
gbc.gridx = 0;
114
gbc.gridy = 1;
115
gbc.fill = GridBagConstraints.HORIZONTAL;
116
textAreaPanel.add(emojiTextArea, gbc);
117
118
passButton = new JButton("Pass");
119
passButton.setActionCommand("Pass");
120
passButton.addActionListener(JTextAreaEmojiTest.this);
121
failButton = new JButton("Fail");
122
failButton.setActionCommand("Fail");
123
failButton.addActionListener(JTextAreaEmojiTest.this);
124
gbc.gridx = 0;
125
gbc.gridy = 0;
126
resultButtonPanel.add(passButton, gbc);
127
gbc.gridx = 1;
128
gbc.gridy = 0;
129
resultButtonPanel.add(failButton, gbc);
130
131
gbc.gridx = 0;
132
gbc.gridy = 0;
133
mainControlPanel.add(instructionPanel, gbc);
134
gbc.gridx = 0;
135
gbc.gridy = 1;
136
mainControlPanel.add(textAreaPanel, gbc);
137
gbc.gridx = 0;
138
gbc.gridy = 2;
139
mainControlPanel.add(resultButtonPanel, gbc);
140
141
mainControlPanel.add(controlPanel, gbc);
142
mainFrame = new JFrame("Control Panel");
143
mainFrame.add(mainControlPanel);
144
mainFrame.pack();
145
mainFrame.setDefaultCloseOperation(EXIT_ON_CLOSE);
146
mainFrame.setVisible(true);
147
}
148
});
149
}
150
151
@Override
152
public void actionPerformed(ActionEvent evt) {
153
if (evt.getSource() instanceof JButton) {
154
JButton btn = (JButton) evt.getSource();
155
156
switch (btn.getActionCommand()) {
157
case "Pass":
158
break;
159
case "Fail":
160
throw new AssertionError("Test case has failed!");
161
}
162
163
cleanUp();
164
}
165
}
166
167
private static void cleanUp() {
168
mainFrame.dispose();
169
testRunLatch.countDown();
170
}
171
}
172
173