blob: 2ed5d79a62913cc70a573c7b691116859d1446e0 [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_1
32*/
33
34/**
35 * InfiniteRecursion_1.java
36 *
37 * summary: put a JButton into JPanel and then put JPanel into JFrame.
38 * Add MouseWheelListener to JFrame.
39 * Add MouseListener to JPanel.
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_1 {
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 JPanel outputBox = new JPanel();
59 JButton jButton = new JButton();
60
61 frame.setSize(200, 200);
62 frame.addMouseWheelListener(new MouseWheelListener() {
63 public void mouseWheelMoved(MouseWheelEvent e)
64 {
65 System.out.println("Wheel moved on FRAME : "+e);
66 actualEvents++;
67 }
68 });
69
70 outputBox.addMouseListener(new MouseAdapter() {
71 public void mousePressed(MouseEvent e)
72 {
73 System.out.println("MousePressed on OUTBOX : "+e);
74 }
75
76 });
77 frame.add(outputBox);
78 outputBox.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 Util.waitForIdle(robot);
98 if (actualEvents != MOVE_COUNT * 2) {
99 AbstractTest.fail("Expected events count: "+ MOVE_COUNT+" Actual events count: "+ actualEvents);
100 }
101 }
102}