Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/jdk17u
Path: blob/master/test/jdk/javax/accessibility/4170173/AccessibleJTextAfterIndexTest.java
66644 views
1
/*
2
* Copyright (c) 2010, 2022, 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
/*
25
* @test
26
* @key headful
27
* @bug 4170173
28
* @summary AccessibleJTextComponent.getAfterIndex works incorrectly
29
* @run main AccessibleJTextAfterIndexTest
30
*/
31
32
import javax.accessibility.AccessibleText;
33
import javax.swing.JEditorPane;
34
import javax.swing.JTextArea;
35
import javax.swing.JTextField;
36
import javax.swing.SwingUtilities;
37
38
public class AccessibleJTextAfterIndexTest {
39
40
public static void doTest() {
41
JTextField jTextField =
42
new JTextField("Test1 Test2 Test3. Test4 Test5. Test6");
43
JTextArea jTextArea = new JTextArea("Test1 Test2 Test3.\nTest4 Test5");
44
JEditorPane jEditorPane =
45
new JEditorPane("text/plain", "Test1 Test2 Test3.\nTest4 Test5");
46
47
String actualAccessibleText = jTextField.getAccessibleContext()
48
.getAccessibleText().getAfterIndex(AccessibleText.CHARACTER, 5);
49
if (!(actualAccessibleText.equals("T"))) {
50
throw new RuntimeException(
51
"JTextField -" + "getAfterIndex() CHARACTER parameter"
52
+ " expected:--T--, actual:--" + actualAccessibleText + "--");
53
}
54
55
actualAccessibleText = jTextField.getAccessibleContext()
56
.getAccessibleText().getAfterIndex(AccessibleText.WORD, 5);
57
if (!(actualAccessibleText.equals("Test2"))) {
58
throw new RuntimeException(
59
"JTextField - " + "getAfterIndex() WORD parameter"
60
+ " expected:--Test2--, actual:--" + actualAccessibleText + "--");
61
}
62
63
actualAccessibleText = jTextField.getAccessibleContext()
64
.getAccessibleText().getAfterIndex(AccessibleText.SENTENCE, 5);
65
if (!(actualAccessibleText.equals("Test4 Test5. "))) {
66
throw new RuntimeException("JTextField - "
67
+ "getAfterIndex() SENTENCE parameter"
68
+ " expected:--Test4 Test5. --, actual:--" + actualAccessibleText + "--");
69
}
70
71
actualAccessibleText = jTextArea.getAccessibleContext()
72
.getAccessibleText().getAfterIndex(AccessibleText.CHARACTER, 5);
73
if (!(actualAccessibleText.equals("T"))) {
74
throw new RuntimeException(
75
"JTextArea - " + "getAfterIndex() CHARACTER parameter"
76
+ " expected:--T--, actual:--" + actualAccessibleText + "--");
77
}
78
79
actualAccessibleText = jTextArea.getAccessibleContext()
80
.getAccessibleText().getAfterIndex(AccessibleText.WORD, 5);
81
if (!(actualAccessibleText.equals("Test2"))) {
82
throw new RuntimeException(
83
"JTextArea - " + "getAfterIndex() WORD parameter"
84
+ " expected:--Test2--, actual:--" + actualAccessibleText + "--");
85
}
86
87
actualAccessibleText = jTextArea.getAccessibleContext()
88
.getAccessibleText().getAfterIndex(AccessibleText.SENTENCE, 5);
89
if (!(actualAccessibleText.equals("Test4 Test5\n"))) {
90
throw new RuntimeException("JTextArea - "
91
+ "getAfterIndex() SENTENCE parameter"
92
+ " expected:--Test4 Test5\n--, actual:--" + actualAccessibleText + "--");
93
}
94
95
actualAccessibleText = jEditorPane.getAccessibleContext()
96
.getAccessibleText().getAfterIndex(AccessibleText.CHARACTER, 5);
97
if (!(actualAccessibleText.equals("T"))) {
98
throw new RuntimeException(
99
"JEditorPane - " + "getAfterIndex() CHARACTER parameter"
100
+ " expected:--T--, actual:--" + actualAccessibleText +"--");
101
}
102
103
actualAccessibleText = jEditorPane.getAccessibleContext()
104
.getAccessibleText().getAfterIndex(AccessibleText.WORD, 5);
105
if (!(actualAccessibleText.equals("Test2"))) {
106
throw new RuntimeException(
107
"JEditorPane - " + "getAfterIndex() WORD parameter"
108
+ " expected:--Test2--, actual:--" + actualAccessibleText + "--");
109
}
110
111
actualAccessibleText = jEditorPane.getAccessibleContext()
112
.getAccessibleText().getAfterIndex(AccessibleText.SENTENCE, 5);
113
if (!(actualAccessibleText.equals("Test4 Test5\n"))) {
114
throw new RuntimeException("JEditorPane - "
115
+ "getAfterIndex() Sentence parameter"
116
+ " expected:--Test4 Test5\n--, actual:--" + actualAccessibleText +"--");
117
}
118
}
119
120
public static void main(String[] args) throws Exception {
121
SwingUtilities.invokeAndWait(() -> doTest());
122
System.out.println("Test Passed");
123
}
124
}
125
126