001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: /**
018: * @author Pavel Dolgov
019: * @version $Revision$
020: */package java.awt;
021:
022: import java.awt.event.ActionEvent;
023: import java.awt.event.ActionListener;
024: import java.awt.event.InputEvent;
025: import java.awt.event.KeyEvent;
026:
027: import junit.framework.TestCase;
028:
029: public class ButtonRTest extends TestCase {
030:
031: public void testShowAndPack() {
032: Frame frm = new Frame("Test");
033: Button btnClose = new Button("MyClose");
034: btnClose.setBounds(10, 10, 80, 22);
035: frm.add(btnClose);
036: frm.setVisible(true);
037: frm.pack();
038:
039: try {
040: Thread.sleep(100);
041: } catch (InterruptedException e) {
042: throw new RuntimeException(e);
043: }
044: frm.dispose();
045: }
046:
047: // Regression test for HARMONY-2305
048: // Currently fails on Linux version of RI
049: public void testHarmony2305() throws Exception {
050: final Frame f = new Frame();
051: final Button b1 = new Button("B1"); //$NON-NLS-1$
052: final Button b2 = new Button("B2"); //$NON-NLS-1$
053: final AL l1 = new AL();
054: final AL l2 = new AL();
055: final Robot r = new Robot();
056:
057: try {
058: b1.addActionListener(l1);
059: b2.addActionListener(l2);
060: f.add(BorderLayout.WEST, b1);
061: f.add(BorderLayout.EAST, b2);
062: f.setSize(100, 100);
063: f.setVisible(true);
064:
065: r.setAutoWaitForIdle(true);
066: r.setAutoDelay(500);
067: r.mouseMove(b1.getLocation().x + 3, b1.getLocation().y + 3);
068: r.mousePress(InputEvent.BUTTON1_MASK);
069: r.mouseRelease(InputEvent.BUTTON1_MASK);
070: assertNotNull(l1.e);
071: assertEquals("B1", l1.e.getActionCommand()); //$NON-NLS-1$
072:
073: assertNull(l2.e);
074: r.keyPress(KeyEvent.VK_SPACE);
075: r.mouseMove(b2.getLocation().x + 3, b2.getLocation().y + 3);
076: r.mousePress(InputEvent.BUTTON1_MASK);
077: r.mouseRelease(InputEvent.BUTTON1_MASK);
078: assertNull(l2.e);
079: } finally {
080: f.dispose();
081: }
082: }
083:
084: // Regression test for HARMONY-3701
085: public void testHarmony3701() throws Exception {
086: setName("testHarmony3701"); //$NON-NLS-1$
087: testHarmony2305();
088: testHarmony2305();
089: }
090:
091: public void testDeadLoop4887() {
092: final int count[] = new int[1];
093: Button b = new Button() {
094: public void paint(Graphics g) {
095: count[0]++;
096: setEnabled(true);
097: setLabel("button1");
098: }
099: };
100:
101: Tools.checkDeadLoop(b, count);
102: }
103:
104: static class AL implements ActionListener {
105: ActionEvent e;
106:
107: public void actionPerformed(final ActionEvent e) {
108: this.e = e;
109: }
110: }
111:
112: }
|