blob: cf520ccc11e81b761760dd052f93d714d0659cb9 [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright (c) 2007 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any questions.
22 */
23
24/*
25 @test
26 @bug 6480024
27 @library ../../../regtesthelpers
28 @build Util Sysout AbstractTest
29 @summary stack overflow on mouse wheel rotation
30 @author Andrei Dmitriev: area=awt.event
31 @run main InfiniteRecursion
32*/
33
34/**
35 * InfiniteRecursion.java
36 *
37 * summary: put a JButton into JFrame.
38 * Add MouseWheelListener to JFrame.
39 * Add MouseListener to JButton.
40 * Rotating a wheel over the JButton would result in stack overflow.
41 */
42
43import java.awt.*;
44import java.awt.event.*;
45import javax.swing.*;
46import test.java.awt.regtesthelpers.Util;
47import test.java.awt.regtesthelpers.AbstractTest;
48import test.java.awt.regtesthelpers.Sysout;
49
50public class InfiniteRecursion {
51 final static Robot robot = Util.createRobot();
52 final static int MOVE_COUNT = 5;
53 static int actualEvents = 0;
54
55 public static void main(String []s)
56 {
57 JFrame frame = new JFrame("A test frame");
58 frame.setSize(200, 200);
59 frame.addMouseWheelListener(new MouseWheelListener() {
60 public void mouseWheelMoved(MouseWheelEvent e) {
61 System.out.println("Wheel moved on FRAME : "+e);
62 actualEvents++;
63 }
64 });
65
66 JButton jButton = new JButton();
67 /*
68 outputBox.addMouseWheelListener(new MouseWheelListener() {
69 public void mouseWheelMoved(MouseWheelEvent e){}
70 });
71 */
72 jButton.addMouseListener(new MouseAdapter() {
73 public void mousePressed(MouseEvent e) {
74 System.out.println("MousePressed on jButton : "+e);
75 }
76
77 });
78 frame.add(jButton);
79
80 frame.setVisible(true);
81
82 Util.waitForIdle(robot);
83
84 Util.pointOnComp(jButton, robot);
85 Util.waitForIdle(robot);
86
87 for (int i = 0; i < MOVE_COUNT; i++){
88 robot.mouseWheel(1);
89 robot.delay(10);
90 }
91
92 for (int i = 0; i < MOVE_COUNT; i++){
93 robot.mouseWheel(-1);
94 robot.delay(10);
95 }
96
97
98 Util.waitForIdle(robot);
99 if (actualEvents != MOVE_COUNT * 2) {
100 AbstractTest.fail("Expected events count: "+ MOVE_COUNT+" Actual events count: "+ actualEvents);
101 }
102 }
103}