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.List.AccessibleAWTList;
023: import java.awt.List.AccessibleAWTList.AccessibleAWTListChild;
024: import java.awt.event.FocusEvent;
025: import java.util.Locale;
026: import javax.accessibility.AccessibleComponent;
027: import javax.accessibility.AccessibleContext;
028: import javax.accessibility.AccessibleRole;
029: import javax.accessibility.AccessibleState;
030: import junit.framework.TestCase;
031:
032: /**
033: * AccessibleAWTListChildTest
034: */
035: public class AccessibleAWTListChildTest extends TestCase {
036:
037: List list;
038: AccessibleContext ac;
039: AccessibleContext ac1, ac2, ac3;
040: AccessibleComponent aComp1, aComp2, aComp3;
041: protected FocusEvent lastFocusEvent;
042:
043: @Override
044: protected void setUp() throws Exception {
045: super .setUp();
046: list = new List();
047: ac = list.getAccessibleContext();
048: list.add("item1");
049: list.add("item2");
050: list.add("item3");
051: ac1 = ac.getAccessibleChild(0).getAccessibleContext();
052: aComp1 = ac1.getAccessibleComponent();
053: ac2 = ac.getAccessibleChild(1).getAccessibleContext();
054: aComp2 = ac2.getAccessibleComponent();
055: ac3 = ac.getAccessibleChild(2).getAccessibleContext();
056: aComp3 = ac3.getAccessibleComponent();
057: lastFocusEvent = null;
058: }
059:
060: public final void testGetAccessibleChildrenCount() {
061: assertEquals(0, ac2.getAccessibleChildrenCount());
062: }
063:
064: public final void testGetAccessibleIndexInParent() {
065: assertEquals(0, ac1.getAccessibleIndexInParent());
066: assertEquals(2, ac3.getAccessibleIndexInParent());
067: }
068:
069: public final void testGetLocale() {
070: Locale locale = Locale.GERMANY;
071: list.setLocale(locale);
072: assertSame(locale, ac2.getLocale());
073: assertSame(list.getLocale(), ac1.getLocale());
074: }
075:
076: public final void testGetAccessibleChild() {
077: assertNull(ac1.getAccessibleChild(0));
078: }
079:
080: public final void testGetAccessibleRole() {
081: assertSame(AccessibleRole.LIST_ITEM, ac2.getAccessibleRole());
082: assertSame(AccessibleRole.LIST_ITEM, ac3.getAccessibleRole());
083: }
084:
085: public final void testGetAccessibleStateSet() {
086: final AccessibleState SELECTED = AccessibleState.SELECTED;
087: assertFalse(ac2.getAccessibleStateSet().contains(SELECTED));
088: list.select(1);
089: assertTrue(ac2.getAccessibleStateSet().contains(SELECTED));
090: assertFalse(ac1.getAccessibleStateSet().contains(SELECTED));
091: assertFalse(ac3.getAccessibleStateSet().contains(SELECTED));
092: }
093:
094: public final void testAddFocusListener() {
095: // does nothing?
096: }
097:
098: public final void testContains() {
099: list.setSize(100, 100);
100: // always false(not implemented yet?)
101: assertFalse(aComp1.contains(new Point(5, 5)));
102: }
103:
104: public final void testGetAccessibleAt() {
105: list.setSize(100, 100);
106: Point p = new Point(5, 5);
107: // always null
108: assertNull(aComp1.getAccessibleAt(p));
109: assertNull(aComp3.getAccessibleAt(p));
110: }
111:
112: public final void testGetBackground() {
113: assertEquals(list.getBackground(), aComp1.getBackground());
114: Color bkColor = Color.CYAN;
115: list.setBackground(bkColor);
116: assertEquals(bkColor, aComp1.getBackground());
117: assertEquals(bkColor, aComp2.getBackground());
118: assertEquals(bkColor, aComp3.getBackground());
119: }
120:
121: public final void testGetBounds() {
122: Rectangle r = new Rectangle();
123: assertNull(aComp1.getBounds());
124: r.setBounds(5, 6, 7, 8);
125: list.setBounds(r);
126: // always null(unimplemented yet)
127: assertNull(aComp1.getBounds());
128: }
129:
130: public final void testGetCursor() {
131: Cursor cursor = Cursor
132: .getPredefinedCursor(Cursor.CROSSHAIR_CURSOR);
133: list.setCursor(cursor);
134: assertSame(cursor, aComp1.getCursor());
135: assertSame(cursor, aComp2.getCursor());
136: }
137:
138: public final void testGetFont() {
139: Font font = Font.decode("Arial");
140: list.setFont(font);
141: assertSame(font, aComp2.getFont());
142: }
143:
144: public final void testGetFontMetrics() {
145: Frame f = new Frame();
146: f.add(list);
147: f.addNotify();
148: Font font = list.getFont();
149: assertSame(list.getFontMetrics(font), aComp3
150: .getFontMetrics(font));
151: f.dispose();
152: }
153:
154: public final void testGetForeground() {
155: assertEquals(list.getForeground(), aComp1.getForeground());
156: Color color = Color.BLUE;
157: list.setForeground(color);
158: assertEquals(color, aComp1.getForeground());
159: assertEquals(color, aComp3.getForeground());
160: }
161:
162: public final void testGetLocation() {
163: assertNull(aComp1.getLocation());
164: Point loc = new Point(50, 75);
165: list.setLocation(loc);
166: // always null(unimplemented yet)
167: assertNull(aComp1.getLocation());
168: assertNull(aComp2.getLocation());
169: }
170:
171: @SuppressWarnings("deprecation")
172: public final void testGetLocationOnScreen() {
173: assertNull(aComp1.getLocationOnScreen());
174: Frame f = new Frame();
175: f.setLayout(null);
176: f.add(list);
177: Point p = new Point(50, 50);
178: f.setLocation(p);
179: f.show();
180: // always null(unimplemented yet)
181: assertNull(aComp2.getLocationOnScreen());
182: f.dispose();
183: }
184:
185: public final void testGetSize() {
186: assertNull(aComp1.getSize());
187: Dimension size = new Dimension(30, 40);
188: list.setSize(size);
189: // always null(unimplemented yet)
190: assertNull(aComp2.getSize());
191: }
192:
193: public final void testIsEnabled() {
194: assertTrue(aComp1.isEnabled());
195: list.setEnabled(false);
196: assertFalse(aComp1.isEnabled());
197: assertFalse(aComp2.isEnabled());
198: assertFalse(aComp3.isEnabled());
199: list.setEnabled(true);
200: assertTrue(aComp2.isEnabled());
201: }
202:
203: public final void testIsFocusTraversable() {
204: assertFalse(aComp1.isFocusTraversable());
205: assertFalse(aComp2.isFocusTraversable());
206: assertFalse(aComp3.isFocusTraversable());
207: list.setFocusable(true);
208: // always false !
209: assertFalse(aComp1.isFocusTraversable());
210: assertFalse(aComp2.isFocusTraversable());
211: assertFalse(aComp3.isFocusTraversable());
212: }
213:
214: @SuppressWarnings("deprecation")
215: public final void testIsShowing() {
216: assertFalse(aComp3.isShowing());
217: Frame f = new Frame();
218: f.add(list);
219: assertFalse(aComp2.isShowing());
220: f.show();
221: assertTrue(list.isShowing());
222: // always false !
223: assertFalse(aComp1.isShowing());
224: assertFalse(aComp2.isShowing());
225: assertFalse(aComp3.isShowing());
226: f.dispose();
227:
228: }
229:
230: public final void testIsVisible() {
231: assertTrue(list.isVisible());
232: // always false
233: assertFalse(aComp1.isVisible());
234: // assertTrue(ac1.getAccessibleStateSet().contains(AccessibleState.VISIBLE));
235: assertFalse(aComp2.isVisible());
236: assertFalse(aComp3.isVisible());
237: }
238:
239: public final void testRemoveFocusListener() {
240: // does nothing?
241: }
242:
243: public final void testRequestFocus() {
244: // does nothing?
245: }
246:
247: public final void testSetBackground() {
248: Color color = Color.DARK_GRAY;
249: assertFalse(list.isBackgroundSet());
250: aComp3.setBackground(color);
251: assertEquals(color, aComp1.getBackground());
252: assertEquals(color, aComp2.getBackground());
253: assertEquals(color, aComp3.getBackground());
254: assertTrue("setBackground() is delegated to List", list
255: .isBackgroundSet());
256: assertEquals(color, list.getBackground());
257: }
258:
259: public final void testSetBounds() {
260: Rectangle bounds = new Rectangle(1, 2, 3, 4);
261: aComp2.setBounds(bounds); // does nothing
262: assertNull(aComp2.getBounds());
263:
264: }
265:
266: public final void testSetCursor() {
267: Cursor cursor = Cursor.getPredefinedCursor(Cursor.HAND_CURSOR);
268: assertFalse(list.isCursorSet());
269: aComp1.setCursor(cursor);
270: assertSame(cursor, aComp1.getCursor());
271: assertSame(cursor, aComp3.getCursor());
272: assertTrue("setCursor() is delegated to List", list
273: .isCursorSet());
274: assertSame(cursor, list.getCursor());
275: }
276:
277: public final void testSetEnabled() {
278: assertTrue(list.isEnabled());
279: aComp3.setEnabled(false);
280: assertFalse(aComp3.isEnabled());
281: assertFalse(aComp1.isEnabled());
282: assertFalse("setEnabled() is delegated to List", list
283: .isEnabled());
284: }
285:
286: public final void testSetFont() {
287: Font font = Font.decode(null);
288: assertFalse(list.isFontSet());
289: aComp2.setFont(font);
290: assertSame(font, aComp2.getFont());
291: assertSame(font, aComp1.getFont());
292: assertTrue("setFont() is delegated to List", list.isFontSet());
293: assertSame(font, list.getFont());
294: }
295:
296: public final void testSetForeground() {
297: Color color = Color.LIGHT_GRAY;
298: assertFalse(list.isForegroundSet());
299: aComp2.setForeground(color);
300: assertEquals(color, aComp1.getForeground());
301: assertEquals(color, aComp2.getForeground());
302: assertEquals(color, aComp3.getForeground());
303: assertTrue("setBackground() is delegated to List", list
304: .isForegroundSet());
305: assertEquals(color, list.getForeground());
306: }
307:
308: public final void testSetLocation() {
309: Point location = new Point(1, 2);
310: aComp2.setLocation(location); // does nothing
311: assertNull(aComp2.getLocation());
312: }
313:
314: public final void testSetSize() {
315: Dimension size = new Dimension(3, 4);
316: aComp3.setSize(size);// does nothing
317: assertNull(aComp3.getSize());
318: }
319:
320: public final void testSetVisible() {
321: assertTrue(list.isVisible());
322: aComp2.setVisible(false);
323: assertFalse(aComp1.isVisible());
324: assertFalse("setVisible() is delegated to Component", list
325: .isVisible());
326: aComp1.setVisible(true);
327: assertTrue(list.isVisible());
328: assertFalse(aComp1.isVisible());
329: }
330:
331: public final void testAccessibleAWTListChild() {
332: AccessibleAWTList aal = (AccessibleAWTList) ac;
333: AccessibleAWTListChild aalc = aal.new AccessibleAWTListChild(
334: list, 1);
335: assertEquals(1, aalc.getAccessibleIndexInParent());
336: assertSame(list, aalc.getAccessibleParent());
337: List list1 = new List();
338: aalc = aal.new AccessibleAWTListChild(list1, 1);
339: // check that operations are delegated to
340: // parent directly, but not through calling super
341: aalc.setEnabled(false);
342: assertTrue(list.isEnabled());
343: assertFalse(list1.isEnabled());
344: }
345:
346: public final void testGetAccessibleContext() {
347: assertNotNull(ac1);
348: assertNotNull(ac2);
349: assertNotNull(ac3);
350: }
351:
352: }
|