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 Dmitry A. Durnev
019: * @version $Revision$
020: */package java.awt;
021:
022: import java.awt.Button.AccessibleAWTButton;
023: import java.awt.event.ActionEvent;
024: import java.awt.event.ActionListener;
025:
026: import javax.accessibility.AccessibleAction;
027: import javax.accessibility.AccessibleContext;
028: import javax.accessibility.AccessibleRole;
029: import javax.accessibility.AccessibleValue;
030:
031: import junit.framework.TestCase;
032:
033: /**
034: * AccessibleAWTButtonTest
035: */
036: public class AccessibleAWTButtonTest extends TestCase {
037: private Button button;
038: private AccessibleContext ac;
039: private ActionEvent action;
040: private Robot robot;
041:
042: @Override
043: protected void setUp() throws Exception {
044: super .setUp();
045: button = new Button();
046: ac = button.getAccessibleContext();
047: action = null;
048: robot = new Robot();
049: assertNotNull(ac);
050: }
051:
052: public final void testGetAccessibleName() {
053: assertEquals("", ac.getAccessibleName());
054: String label = "button";
055: button.setLabel(label);
056: assertEquals(label, ac.getAccessibleName());
057: }
058:
059: public final void testGetAccessibleAction() {
060: AccessibleAction aa = ac.getAccessibleAction();
061: assertNotNull(aa);
062: assertTrue(aa instanceof AccessibleAWTButton);
063: }
064:
065: public final void testGetAccessibleRole() {
066: assertSame(AccessibleRole.PUSH_BUTTON, ac.getAccessibleRole());
067: }
068:
069: public final void testGetAccessibleValue() {
070: AccessibleValue av = ac.getAccessibleValue();
071: assertNotNull(av);
072: assertTrue(av instanceof AccessibleAWTButton);
073: }
074:
075: public final void testAccessibleAWTButton() {
076: assertNotNull(button.new AccessibleAWTButton());
077: }
078:
079: public final void testGetAccessibleActionCount() {
080: assertEquals("button has 1 accessible action", 1, ac
081: .getAccessibleAction().getAccessibleActionCount());
082: }
083:
084: public final void testGetAccessibleActionDescription() {
085: AccessibleAction aa = ac.getAccessibleAction();
086: assertNull(aa.getAccessibleActionDescription(-1));
087: assertEquals("click", aa.getAccessibleActionDescription(0));
088: assertNull(aa.getAccessibleActionDescription(1));
089: }
090:
091: private void waitForAction() {
092: int time = 0;
093: int timeout = 32;
094: int threshold = 60000;
095: while ((action == null) && (time < threshold)) {
096: robot.delay(timeout);
097: time += timeout;
098: timeout <<= 1;
099: }
100: }
101:
102: public final void testDoAccessibleAction() {
103: button.addActionListener(new ActionListener() {
104:
105: public void actionPerformed(ActionEvent ae) {
106: action = ae;
107:
108: }
109: });
110: assertFalse(ac.getAccessibleAction().doAccessibleAction(-1));
111: assertFalse(ac.getAccessibleAction().doAccessibleAction(1));
112: assertTrue(ac.getAccessibleAction().doAccessibleAction(0));
113:
114: waitForAction();
115: assertNotNull(action);
116: assertEquals(0, action.getModifiers());
117: assertEquals(0l, action.getWhen());
118: }
119:
120: public final void testGetCurrentAccessibleValue() {
121: AccessibleValue av = ac.getAccessibleValue();
122: assertEquals(new Integer(0), av.getCurrentAccessibleValue());
123: }
124:
125: public final void testSetCurrentAccessibleValue() {
126: AccessibleValue av = ac.getAccessibleValue();
127: Integer value = new Integer(-1);
128: assertFalse(av.setCurrentAccessibleValue(value));
129: assertEquals(new Integer(0), av.getCurrentAccessibleValue());
130: assertFalse(av.setCurrentAccessibleValue(new Integer(
131: Integer.MAX_VALUE)));
132: assertEquals(new Integer(0), av.getCurrentAccessibleValue());
133: }
134:
135: public final void testGetMinimumAccessibleValue() {
136: AccessibleValue av = ac.getAccessibleValue();
137: assertEquals(new Integer(0), av.getMinimumAccessibleValue());
138: }
139:
140: public final void testGetMaximumAccessibleValue() {
141: AccessibleValue av = ac.getAccessibleValue();
142: assertEquals(0, av.getMaximumAccessibleValue().intValue());
143: }
144:
145: }
|