Skip to content

Commit e8c9452

Browse files
committed
8284767: Create an automated test for JDK-4422535
Backport-of: 5ae4320921b15dcc198d0c71416cd46e5b5c2f85
1 parent 79d0185 commit e8c9452

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
* Copyright (c) 2002, 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+
* @bug 4422535
27+
* @summary setCurrentAccessibleValue returns true only for an Integer
28+
* @run main SetCurrentAccessibleValueTest
29+
*/
30+
31+
import java.math.BigDecimal;
32+
import java.math.BigInteger;
33+
34+
import javax.swing.JButton;
35+
import javax.swing.JComponent;
36+
import javax.swing.JInternalFrame;
37+
import javax.swing.JProgressBar;
38+
import javax.swing.JScrollBar;
39+
import javax.swing.JSlider;
40+
import javax.swing.JSplitPane;
41+
import javax.swing.SwingUtilities;
42+
43+
public class SetCurrentAccessibleValueTest {
44+
45+
public static void doTest() {
46+
JComponent[] jComponents =
47+
{ new JButton(), new JInternalFrame(), new JSplitPane(),
48+
new JScrollBar(), new JProgressBar(), new JSlider() };
49+
50+
for (JComponent jComponent : jComponents) {
51+
testIt(jComponent, (Float.valueOf(5)));
52+
testIt(jComponent, (Double.valueOf(37.266)));
53+
testIt(jComponent, (Integer.valueOf(10)));
54+
testIt(jComponent, (Long.valueOf(123L)));
55+
testIt(jComponent, (Short.valueOf((short) 123)));
56+
testIt(jComponent, (BigInteger.ONE));
57+
testIt(jComponent, (new BigDecimal(BigInteger.ONE)));
58+
}
59+
60+
}
61+
62+
static void testIt(JComponent jComponent, Number number) {
63+
if (!jComponent.getAccessibleContext().getAccessibleValue()
64+
.setCurrentAccessibleValue(number)) {
65+
throw new RuntimeException(jComponent.getClass().getName()
66+
+ " Accessible Value implementation doesn't accept "
67+
+ number.getClass().getName());
68+
}
69+
}
70+
71+
public static void main(String[] args) throws Exception {
72+
SwingUtilities.invokeAndWait(() -> doTest());
73+
System.out.println("Test Passed");
74+
}
75+
}
76+

0 commit comments

Comments
 (0)