Skip to content

Commit 7e98f59

Browse files
author
Alisen Chung
committedOct 17, 2024
8340987: Open some TextArea awt tests 1
Reviewed-by: prr, abhiscxk
1 parent d915ac2 commit 7e98f59

File tree

4 files changed

+312
-0
lines changed

4 files changed

+312
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* Copyright (c) 2004, 2024, 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.BorderLayout;
25+
import java.awt.Frame;
26+
import java.awt.TextArea;
27+
28+
/*
29+
* @test
30+
* @bug 6192116
31+
* @summary Auto-scrolling does not work properly for TextArea when appending some text, on XToolkit
32+
* @library /java/awt/regtesthelpers
33+
* @build PassFailJFrame
34+
* @run main/manual TextAreaAppendScrollTest2
35+
*/
36+
37+
public class TextAreaAppendScrollTest2 extends Frame {
38+
TextArea area;
39+
private static final String INSTRUCTIONS = """
40+
Press pass if you see exclamation marks in the bottom of textarea.
41+
Press fail if you don't.
42+
""";
43+
44+
public static void main(String[] args) throws Exception {
45+
PassFailJFrame.builder()
46+
.title("TextAreaAppendScrollTest2")
47+
.instructions(INSTRUCTIONS)
48+
.rows((int) INSTRUCTIONS.lines().count() + 2)
49+
.columns(40)
50+
.testUI(TextAreaAppendScrollTest2::new)
51+
.build()
52+
.awaitAndCheck();
53+
}
54+
55+
public TextAreaAppendScrollTest2() {
56+
setLayout(new BorderLayout());
57+
area = new TextArea("AWT is cool ", 3, 3, TextArea.SCROLLBARS_NONE);
58+
add("Center", area);
59+
setSize(200, 200);
60+
StringBuilder coolStr = new StringBuilder("");
61+
// I count 15 lines with 12 cools per line
62+
for (int i = 0; i < 12 * 15; i++) {
63+
coolStr.append("cool ");
64+
}
65+
coolStr.append("!!!!!!!");
66+
area.append(coolStr.toString());
67+
}
68+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* Copyright (c) 1998, 2024, 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.Frame;
25+
import java.awt.TextArea;
26+
27+
/*
28+
* @test
29+
* @bug 4118915
30+
* @summary Test appending to a TextArea after the peer is created
31+
* @library /java/awt/regtesthelpers
32+
* @build PassFailJFrame
33+
* @run main/manual TextAreaAppendTest
34+
*/
35+
36+
public class TextAreaAppendTest {
37+
private static final String INSTRUCTIONS = """
38+
If all four lines are visible in TextArea, the test passed.
39+
If the last two lines have only one character visible, the test failed.
40+
""";
41+
42+
public static void main(String[] args) throws Exception {
43+
PassFailJFrame.builder()
44+
.title("TextAreaAppendTest")
45+
.instructions(INSTRUCTIONS)
46+
.rows((int) INSTRUCTIONS.lines().count() + 2)
47+
.columns(40)
48+
.testUI(TextAreaAppendTest::createGUI)
49+
.build()
50+
.awaitAndCheck();
51+
}
52+
53+
public static Frame createGUI() {
54+
Frame f = new Frame("TextAreaAppendTest");
55+
TextArea ta = new TextArea();
56+
f.add(ta);
57+
ta.append("line 1 (added before drawing)\n");
58+
ta.append("line 2 (added before drawing)\n");
59+
60+
f.pack();
61+
f.show();
62+
63+
ta.append("line 3 (added after drawing)\n");
64+
ta.append("line 4 (added after drawing)\n");
65+
66+
return f;
67+
}
68+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
/*
2+
* Copyright (c) 2003, 2024, 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.Button;
25+
import java.awt.FlowLayout;
26+
import java.awt.Frame;
27+
import java.awt.GridLayout;
28+
import java.awt.Panel;
29+
import java.awt.TextArea;
30+
import java.awt.TextField;
31+
import java.awt.event.ActionEvent;
32+
import java.awt.event.ActionListener;
33+
34+
/*
35+
* @test
36+
* @bug 4800187
37+
* @summary REGRESSION:show the wrong selection when there are \r characters in the text
38+
* @library /java/awt/regtesthelpers
39+
* @build PassFailJFrame
40+
* @run main/manual TextAreaCRLFAutoDetectManualTest
41+
*/
42+
43+
public class TextAreaCRLFAutoDetectManualTest {
44+
static int flag = 1;
45+
46+
private static final String INSTRUCTIONS = """
47+
Please click the button several times.
48+
If you see the text '679' selected on the left TextArea
49+
and the same text on the right TextArea
50+
each time you press the button,
51+
the test passed, else failed.
52+
""";
53+
54+
public static void main(String[] args) throws Exception {
55+
PassFailJFrame.builder()
56+
.title("TextAreaCRLFAutoDetectManualTest")
57+
.instructions(INSTRUCTIONS)
58+
.rows((int) INSTRUCTIONS.lines().count() + 2)
59+
.columns(40)
60+
.testUI(TextAreaCRLFAutoDetectManualTest::createGUI)
61+
.build()
62+
.awaitAndCheck();
63+
}
64+
65+
public static Frame createGUI() {
66+
Frame f = new Frame("TextAreaCRLFAutoDetectManualTest");
67+
68+
TextArea ta1 = new TextArea(5, 20);
69+
TextArea ta2 = new TextArea(5, 20);
70+
71+
TextField tf1 = new TextField("123", 20);
72+
TextField tf2 = new TextField("567", 20);
73+
TextField tf3 = new TextField("90", 20);
74+
75+
Button b = new Button("Click Me Several Times");
76+
77+
b.addActionListener(new ActionListener() {
78+
public void actionPerformed(ActionEvent evt) {
79+
ta1.setText("");
80+
ta2.setText("");
81+
flag++;
82+
String eoln = ((flag % 2) != 0) ? "\r\n" : "\n";
83+
ta1.setText(eoln + tf1.getText() + eoln + tf2.getText() + eoln + tf3.getText() + eoln);
84+
ta1.select(6, 10);
85+
ta2.setText(ta1.getSelectedText());
86+
ta1.requestFocus();
87+
}
88+
});
89+
90+
f.setLayout(new FlowLayout());
91+
92+
Panel tfpanel = new Panel();
93+
tfpanel.setLayout(new GridLayout(3, 1));
94+
tfpanel.add(tf1);
95+
tfpanel.add(tf2);
96+
tfpanel.add(tf3);
97+
f.add(tfpanel);
98+
99+
f.add(ta1);
100+
f.add(ta2);
101+
f.add(b);
102+
103+
f.pack();
104+
return f;
105+
}
106+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* Copyright (c) 2000, 2024, 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.BorderLayout;
25+
import java.awt.Frame;
26+
import java.awt.TextArea;
27+
28+
/*
29+
* @test
30+
* @bug 4341196
31+
* @summary Tests that TextArea can handle more than 64K of text
32+
* @library /java/awt/regtesthelpers
33+
* @build PassFailJFrame
34+
* @run main/manual TextAreaLimit
35+
*/
36+
37+
public class TextAreaLimit extends Frame {
38+
static TextArea text;
39+
private static final String INSTRUCTIONS = """
40+
You will see a text area with 40000 lines of text
41+
each with its own line number. If you see the caret after line 39999
42+
then test passes. Otherwise it fails.
43+
""";
44+
45+
public static void main(String[] args) throws Exception {
46+
PassFailJFrame.builder()
47+
.title("TextAreaLimit")
48+
.instructions(INSTRUCTIONS)
49+
.rows((int) INSTRUCTIONS.lines().count() + 2)
50+
.columns(40)
51+
.testUI(TextAreaLimit::new)
52+
.build()
53+
.awaitAndCheck();
54+
}
55+
56+
public TextAreaLimit() {
57+
setLayout(new BorderLayout());
58+
59+
text = new TextArea();
60+
add(text);
61+
StringBuffer buf = new StringBuffer();
62+
for (int i = 0; i < 40000; i++) {
63+
buf.append(i + "\n");
64+
}
65+
text.setText(buf.toString());
66+
text.setCaretPosition(buf.length());
67+
text.requestFocus();
68+
setSize(200, 200);
69+
}
70+
}

0 commit comments

Comments
 (0)
Please sign in to comment.