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 Alexander T. Simbirtsev
019: * @version $Revision$
020: * Created on 11.02.2005
021:
022: */package javax.swing;
023:
024: import java.awt.Point;
025: import java.awt.image.BufferedImage;
026: import javax.accessibility.AccessibleRelationSet;
027: import javax.accessibility.AccessibleState;
028: import javax.accessibility.AccessibleText;
029:
030: public class AccessibleJButtonTest extends BasicSwingTestCase {
031: protected AbstractButton button;
032:
033: private JButton.AccessibleJButton aContext;
034:
035: @Override
036: protected void setUp() throws Exception {
037: super .setUp();
038: button = new JButton();
039: aContext = (JButton.AccessibleJButton) button
040: .getAccessibleContext();
041: }
042:
043: @Override
044: protected void tearDown() throws Exception {
045: button = null;
046: aContext = null;
047: super .tearDown();
048: }
049:
050: public static void main(final String[] args) {
051: }
052:
053: public void testGetAccessibleActionCount() {
054: assertEquals("AccessibleActionCount", 1, aContext
055: .getAccessibleActionCount());
056: }
057:
058: public void testGetAccessibleValue() {
059: assertEquals("AccessibleAction", aContext, aContext
060: .getAccessibleAction());
061: }
062:
063: public void testGetAccessibleKeyBinding() {
064: assertNull("AccessibleKeyBinding ", aContext
065: .getAccessibleKeyBinding());
066: }
067:
068: public void testGetAccessibleText() {
069: assertNull("AccessibleText ", aContext.getAccessibleText());
070: }
071:
072: public void testGetToolTipText() {
073: String text1 = "do what you feel";
074: String text2 = "what you need to do";
075: button.setText(text1);
076: assertNull("ToolTipText ", aContext.getToolTipText());
077: button.setToolTipText(text2);
078: assertEquals("ToolTipText ", text2, aContext.getToolTipText());
079: }
080:
081: public void testGetAccessibleIcon() {
082: ImageIcon icon1 = new ImageIcon(new BufferedImage(10, 10,
083: BufferedImage.TYPE_BYTE_GRAY));
084: ImageIcon icon2 = new ImageIcon(new BufferedImage(10, 10,
085: BufferedImage.TYPE_BYTE_GRAY));
086: assertNull("AccessibleIcon", aContext.getAccessibleIcon());
087: button.setIcon(icon1);
088: assertEquals("number of AccessibleIcons", 1, aContext
089: .getAccessibleIcon().length);
090: assertEquals("AccessibleIcon", icon1.getAccessibleContext(),
091: aContext.getAccessibleIcon()[0]);
092: button.setDisabledIcon(icon2);
093: assertEquals("number of AccessibleIcons", 1, aContext
094: .getAccessibleIcon().length);
095: assertEquals("AccessibleIcon", icon1.getAccessibleContext(),
096: aContext.getAccessibleIcon()[0]);
097: }
098:
099: public void testGetAccessibleStateSet() {
100: assertNotNull("AccessibleStateSet is not null", aContext
101: .getAccessibleStateSet());
102: assertTrue("AccessibleStateSet contains ENABLED", aContext
103: .getAccessibleStateSet().contains(
104: AccessibleState.ENABLED));
105: assertTrue("AccessibleStateSet contains FOCUSABLE", aContext
106: .getAccessibleStateSet().contains(
107: AccessibleState.FOCUSABLE));
108: assertTrue("AccessibleStateSet contains VISIBLE", aContext
109: .getAccessibleStateSet().contains(
110: AccessibleState.VISIBLE));
111: assertTrue("AccessibleStateSet contains OPAQUE", aContext
112: .getAccessibleStateSet().contains(
113: AccessibleState.OPAQUE));
114: button.setSelected(true);
115: assertNotNull("AccessibleStateSet is not null", aContext
116: .getAccessibleStateSet());
117: assertTrue("AccessibleStateSet contains ENABLED", aContext
118: .getAccessibleStateSet().contains(
119: AccessibleState.ENABLED));
120: assertTrue("AccessibleStateSet contains FOCUSABLE", aContext
121: .getAccessibleStateSet().contains(
122: AccessibleState.FOCUSABLE));
123: assertTrue("AccessibleStateSet contains VISIBLE", aContext
124: .getAccessibleStateSet().contains(
125: AccessibleState.VISIBLE));
126: assertTrue("AccessibleStateSet contains OPAQUE", aContext
127: .getAccessibleStateSet().contains(
128: AccessibleState.OPAQUE));
129: assertTrue("AccessibleStateSet contains CHECKED", aContext
130: .getAccessibleStateSet().contains(
131: AccessibleState.CHECKED));
132: button.setEnabled(false);
133: assertNotNull("AccessibleStateSet is not null", aContext
134: .getAccessibleStateSet());
135: assertFalse("AccessibleStateSet doesn't contain ENABLED",
136: aContext.getAccessibleStateSet().contains(
137: AccessibleState.ENABLED));
138: assertTrue("AccessibleStateSet contains FOCUSABLE", aContext
139: .getAccessibleStateSet().contains(
140: AccessibleState.FOCUSABLE));
141: assertTrue("AccessibleStateSet contains VISIBLE", aContext
142: .getAccessibleStateSet().contains(
143: AccessibleState.VISIBLE));
144: assertTrue("AccessibleStateSet contains OPAQUE", aContext
145: .getAccessibleStateSet().contains(
146: AccessibleState.OPAQUE));
147: assertTrue("AccessibleStateSet contains CHECKED", aContext
148: .getAccessibleStateSet().contains(
149: AccessibleState.CHECKED));
150: button.setVisible(false);
151: assertNotNull("AccessibleStateSet is not null", aContext
152: .getAccessibleStateSet());
153: assertFalse("AccessibleStateSet doesn't contain ENABLED",
154: aContext.getAccessibleStateSet().contains(
155: AccessibleState.ENABLED));
156: assertTrue("AccessibleStateSet contains FOCUSABLE", aContext
157: .getAccessibleStateSet().contains(
158: AccessibleState.FOCUSABLE));
159: assertFalse("AccessibleStateSet doesn't contain VISIBLE",
160: aContext.getAccessibleStateSet().contains(
161: AccessibleState.VISIBLE));
162: assertTrue("AccessibleStateSet contains OPAQUE", aContext
163: .getAccessibleStateSet().contains(
164: AccessibleState.OPAQUE));
165: assertTrue("AccessibleStateSet contains CHECKED", aContext
166: .getAccessibleStateSet().contains(
167: AccessibleState.CHECKED));
168: }
169:
170: public void testDoAccessibleAction() {
171: assertTrue("AccessibleAction result", aContext
172: .doAccessibleAction(0));
173: assertFalse("AccessibleAction result", aContext
174: .doAccessibleAction(1));
175: assertFalse("AccessibleAction result", aContext
176: .doAccessibleAction(-1));
177: }
178:
179: public void testGetAccessibleName() {
180: String name = "namemeams";
181: assertEquals("AccessibleName", "", aContext.getAccessibleName());
182: button.setText(name);
183: assertEquals("AccessibleName", name, aContext
184: .getAccessibleName());
185: }
186:
187: public void testGetAccessibleRelationSet() {
188: AccessibleRelationSet relations = aContext
189: .getAccessibleRelationSet();
190: assertNotNull("AccessibleRelationSet isn't null", relations);
191: assertEquals("AccessibleRelationSet size", 0, relations.size());
192: }
193:
194: public void testGetAccessibleAction() {
195: assertEquals("AccessibleAction", aContext, aContext
196: .getAccessibleAction());
197: }
198:
199: public void testGetAccessibleActionDescription() {
200: assertEquals("AccessibleActionDescription", "click", aContext
201: .getAccessibleActionDescription(0));
202: assertNull("AccessibleActionDescription", aContext
203: .getAccessibleActionDescription(1));
204: }
205:
206: public void testGetCurrentAccessibleValue() {
207: button.setSelected(false);
208: assertEquals("CurrentAccessibleValue", new Integer(0), aContext
209: .getCurrentAccessibleValue());
210: button.setSelected(true);
211: assertEquals("CurrentAccessibleValue", new Integer(1), aContext
212: .getCurrentAccessibleValue());
213: }
214:
215: public void testGetMaximumAccessibleValue() {
216: assertEquals("MaximumAccessibleValue", new Integer(1), aContext
217: .getMaximumAccessibleValue());
218: }
219:
220: public void testGetMinimumAccessibleValue() {
221: assertEquals("MinimumAccessibleValue", new Integer(0), aContext
222: .getMinimumAccessibleValue());
223: }
224:
225: /**
226: * this method now inherits all functionality now from JComponent.AccessibleComponent
227: */
228: public void testGetTitledBorderText() {
229: }
230:
231: public void testSetCurrentAccessibleValue() {
232: PropertyChangeController listener = new PropertyChangeController();
233: aContext.addPropertyChangeListener(listener);
234: assertTrue("returned value", aContext
235: .setCurrentAccessibleValue(new Integer(100)));
236: assertEquals("CurrentAccessibleValue", new Integer(1), aContext
237: .getCurrentAccessibleValue());
238: assertTrue("button selected state", button.isSelected());
239: listener.checkPropertyFired(aContext, "AccessibleState", null,
240: AccessibleState.SELECTED);
241: listener.checkPropertyFired(aContext, "AccessibleValue",
242: new Integer(0), new Integer(1));
243: listener.reset();
244: assertTrue("returned value", aContext
245: .setCurrentAccessibleValue(new Integer(0)));
246: assertEquals("CurrentAccessibleValue", new Integer(0), aContext
247: .getCurrentAccessibleValue());
248: assertFalse("button selected state", button.isSelected());
249: listener.checkPropertyFired(aContext, "AccessibleState",
250: AccessibleState.SELECTED, null);
251: listener.checkPropertyFired(aContext, "AccessibleValue",
252: new Integer(1), new Integer(0));
253: listener.reset();
254: assertTrue("returned value", aContext
255: .setCurrentAccessibleValue(new Integer(0)));
256: assertFalse("no event's fired ", listener.isChanged());
257: }
258:
259: public void testGetCaretPosition() {
260: assertEquals("CaretPosition", -1, aContext.getCaretPosition());
261: button.setText("text");
262: assertEquals("CaretPosition", -1, aContext.getCaretPosition());
263: }
264:
265: public void testGetCharCount() {
266: assertEquals("CharCount", 0, aContext.getCharCount());
267: button.setText("text");
268: assertEquals("CharCount", 4, aContext.getCharCount());
269: }
270:
271: public void testGetSelectionEnd() {
272: assertEquals("SelectionEnd", -1, aContext.getSelectionEnd());
273: button.setText("text");
274: assertEquals("SelectionEnd", -1, aContext.getSelectionEnd());
275: button.setSelected(true);
276: assertEquals("SelectionEnd", -1, aContext.getSelectionEnd());
277: }
278:
279: public void testGetSelectionStart() {
280: assertEquals("SelectionStart", -1, aContext.getSelectionStart());
281: button.setText("text");
282: assertEquals("SelectionStart", -1, aContext.getSelectionStart());
283: button.setSelected(true);
284: assertEquals("SelectionStart", -1, aContext.getSelectionStart());
285: }
286:
287: public void testGetIndexAtPoint() {
288: assertEquals("IndexAtPoint", -1, aContext
289: .getIndexAtPoint(new Point(0, 0)));
290: button.setText("text");
291: assertEquals("IndexAtPoint", -1, aContext
292: .getIndexAtPoint(new Point(2, 2)));
293: }
294:
295: public void testGetCharacterBounds() {
296: assertNull("CharacterBounds", aContext.getCharacterBounds(0));
297: button.setText("text");
298: assertNull("CharacterBounds", aContext.getCharacterBounds(1));
299: }
300:
301: public void testGetSelectedText() {
302: assertNull("SelectedText", aContext.getSelectedText());
303: button.setText("text");
304: assertNull("SelectedText", aContext.getSelectedText());
305: button.setSelected(true);
306: assertNull("SelectedText", aContext.getSelectedText());
307: }
308:
309: public void testGetAfterIndex() {
310: assertNull("AfterIndex", aContext.getAfterIndex(
311: AccessibleText.CHARACTER, 0));
312: assertNull("AfterIndex", aContext.getAfterIndex(
313: AccessibleText.WORD, 0));
314: assertNull("AfterIndex", aContext.getAfterIndex(
315: AccessibleText.SENTENCE, 0));
316: button.setText("Just give me the light. and start the show");
317: assertNull("AfterIndex", aContext.getAfterIndex(
318: AccessibleText.CHARACTER, 6));
319: }
320:
321: public void testGetAtIndex() {
322: assertNull("AtIndex", aContext.getAtIndex(
323: AccessibleText.CHARACTER, 0));
324: assertNull("AtIndex", aContext.getAtIndex(AccessibleText.WORD,
325: 0));
326: assertNull("AtIndex", aContext.getAtIndex(
327: AccessibleText.SENTENCE, 0));
328: button.setText("Just give me the light. and start the show");
329: assertNull("AtIndex", aContext.getAtIndex(
330: AccessibleText.CHARACTER, 6));
331: }
332:
333: public void testGetBeforeIndex() {
334: assertNull("BeforeIndex", aContext.getBeforeIndex(
335: AccessibleText.CHARACTER, 0));
336: assertNull("BeforeIndex", aContext.getBeforeIndex(
337: AccessibleText.WORD, 0));
338: assertNull("BeforeIndex", aContext.getBeforeIndex(
339: AccessibleText.SENTENCE, 0));
340: button.setText("Just give me the light. and start the show");
341: assertNull("BeforeIndex", aContext.getBeforeIndex(
342: AccessibleText.CHARACTER, 6));
343: }
344:
345: public void testGetCharacterAttribute() {
346: assertNull("CharacterAttribute", aContext
347: .getCharacterAttribute(0));
348: button.setText("text");
349: assertNull("CharacterAttribute", aContext
350: .getCharacterAttribute(1));
351: }
352: }
|