Skip to content

Commit e53ac1a

Browse files
committed
8283015: Create a test for JDK-4715496
Backport-of: bfd9c2b30f17d3341cbe7f48d13d36708e5fafbf
1 parent 77297fb commit e53ac1a

File tree

1 file changed

+90
-0
lines changed

1 file changed

+90
-0
lines changed
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/*
2+
* Copyright (c) 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 4715496
28+
* @summary AccessibleJTableCell.getAccessible name incorrectly returns
29+
* cell instance string instead of cell text.
30+
* @run main AccessibleJTableCellNameTest
31+
*/
32+
33+
import java.awt.Robot;
34+
35+
import javax.accessibility.Accessible;
36+
import javax.swing.JFrame;
37+
import javax.swing.JTable;
38+
import javax.swing.SwingUtilities;
39+
40+
public class AccessibleJTableCellNameTest {
41+
private static JTable jTable;
42+
private static JFrame jFrame;
43+
private static volatile Accessible accessible;
44+
45+
private static Object[][] rowData = {
46+
{ "01", "02", "03", "04", "05" },
47+
{ "11", "12", "13", "14", "15" },
48+
{ "21", "22", "23", "24", "25" },
49+
{ "31", "32", "33", "34", "35" },
50+
{ "41", "42", "43", "44", "45" } };
51+
52+
private static Object[] colNames = { "1", "2", "3", "4", "5" };
53+
54+
private static void doTest() throws Exception {
55+
try {
56+
SwingUtilities.invokeAndWait(() -> createGUI());
57+
Robot robot = new Robot();
58+
robot.setAutoDelay(500);
59+
robot.waitForIdle();
60+
61+
SwingUtilities.invokeAndWait(() -> {
62+
for (int i = 0; i <= colNames.length - 1; i++) {
63+
Accessible accessible = jTable.getAccessibleContext().getAccessibleTable()
64+
.getAccessibleColumnHeader().getAccessibleAt(0, i);
65+
66+
if (!(accessible.getAccessibleContext().getAccessibleName().equals(colNames[i]))) {
67+
throw new RuntimeException(
68+
"AccessibleJTableCell.getAccessibleName returns correct name for header cells");
69+
}
70+
}
71+
});
72+
} finally {
73+
SwingUtilities.invokeAndWait(() -> jFrame.dispose());
74+
}
75+
}
76+
77+
private static void createGUI() {
78+
jTable = new JTable(rowData, colNames);
79+
jFrame = new JFrame();
80+
jFrame.setBounds(100, 100, 300, 300);
81+
jFrame.getContentPane().add(jTable);
82+
jFrame.setVisible(true);
83+
}
84+
85+
public static void main(String args[]) throws Exception {
86+
doTest();
87+
System.out.println("Test Passed");
88+
}
89+
}
90+

0 commit comments

Comments
 (0)