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.beans.PropertyChangeEvent;
024: import javax.accessibility.Accessible;
025: import javax.accessibility.AccessibleContext;
026: import javax.accessibility.AccessibleRole;
027: import javax.accessibility.AccessibleSelection;
028: import javax.accessibility.AccessibleState;
029: import junit.framework.TestCase;
030:
031: /**
032: * AccessibleAWTListTest
033: */
034: public class AccessibleAWTListTest extends TestCase {
035: List list;
036: AccessibleContext ac;
037: protected PropertyChangeEvent lastPropEvent;
038:
039: @Override
040: protected void setUp() throws Exception {
041: super .setUp();
042: list = new List();
043: ac = list.getAccessibleContext();
044: assertNotNull(ac);
045: }
046:
047: public final void testGetAccessibleChildrenCount() {
048: assertEquals(0, ac.getAccessibleChildrenCount());
049: list.add("item1");
050: list.add("item2");
051: assertEquals(2, ac.getAccessibleChildrenCount());
052: }
053:
054: public final void testGetAccessibleChild() {
055: assertNull(ac.getAccessibleChild(0));
056: list.add("item");
057: Accessible aChild = ac.getAccessibleChild(0);
058: assertNotNull(aChild);
059: assertTrue(aChild instanceof AccessibleAWTList.AccessibleAWTListChild);
060: assertNotNull(aChild = ac.getAccessibleChild(-2));
061: assertTrue(aChild instanceof AccessibleAWTList.AccessibleAWTListChild);
062: assertNull(ac.getAccessibleChild(1));
063: }
064:
065: public final void testGetAccessibleRole() {
066: assertSame(AccessibleRole.LIST, ac.getAccessibleRole());
067: }
068:
069: public final void testGetAccessibleStateSet() {
070: final AccessibleState STATE = AccessibleState.MULTISELECTABLE;
071: assertFalse(ac.getAccessibleStateSet().contains(STATE));
072: list.setMultipleMode(true);
073: assertTrue(ac.getAccessibleStateSet().contains(STATE));
074: list.setMultipleMode(false);
075: assertFalse(ac.getAccessibleStateSet().contains(STATE));
076:
077: }
078:
079: public final void testGetAccessibleAt() {
080: list.add("item1");
081: Point p = new Point();
082: assertNull(ac.getAccessibleComponent().getAccessibleAt(p));
083: }
084:
085: public final void testAccessibleAWTList() {
086: AccessibleAWTList aList = list.new AccessibleAWTList();
087: assertNotNull(aList);
088: // constructor has side-effect: listeners are added:
089: assertSame(aList, list.getItemListeners()[1]);
090: assertSame(aList, list.getActionListeners()[1]);
091: }
092:
093: public final void testGetAccessibleSelectionCount() {
094: list.add("item1");
095: list.add("item2");
096: AccessibleSelection as = ac.getAccessibleSelection();
097: assertEquals(0, as.getAccessibleSelectionCount());
098: list.select(0);
099: assertEquals(1, as.getAccessibleSelectionCount());
100: list.select(1);
101: assertEquals(1, as.getAccessibleSelectionCount());
102: list.setMultipleMode(true);
103: list.select(0);
104: assertEquals(2, as.getAccessibleSelectionCount());
105: }
106:
107: public final void testClearAccessibleSelection() {
108: list.add("item1");
109: list.add("item2");
110: list.setMultipleMode(true);
111: AccessibleSelection as = ac.getAccessibleSelection();
112: list.select(0);
113: list.select(1);
114: assertEquals(2, list.getSelectedItems().length);
115: as.clearAccessibleSelection();
116: assertEquals(0, list.getSelectedItems().length);
117: assertEquals(0, as.getAccessibleSelectionCount());
118:
119: }
120:
121: public final void testSelectAllAccessibleSelection() {
122: AccessibleSelection as = ac.getAccessibleSelection();
123: list.add("item1");
124: list.add("item2");
125: assertEquals(0, list.getSelectedItems().length);
126: as.selectAllAccessibleSelection();
127: assertEquals(1, list.getSelectedItems().length);
128: assertEquals("item1", list.getSelectedItem());
129: as.selectAllAccessibleSelection();
130: assertEquals(1, list.getSelectedItems().length);
131: assertEquals("item1", list.getSelectedItem());
132: list.setMultipleMode(true);
133: as.selectAllAccessibleSelection();
134: assertEquals(2, list.getSelectedItems().length);
135:
136: }
137:
138: public final void testAddAccessibleSelection() {
139: AccessibleSelection as = ac.getAccessibleSelection();
140: list.add("item1");
141: list.add("item2");
142: assertEquals(0, list.getSelectedItems().length);
143: as.addAccessibleSelection(1);
144: assertEquals(1, list.getSelectedItems().length);
145: assertEquals("item2", list.getSelectedItem());
146: as.addAccessibleSelection(0);
147: assertEquals(1, list.getSelectedItems().length);
148: assertEquals("item1", list.getSelectedItem());
149: list.setMultipleMode(true);
150: as.addAccessibleSelection(1);
151: assertEquals(2, list.getSelectedItems().length);
152: }
153:
154: public final void testRemoveAccessibleSelection() {
155: AccessibleSelection as = ac.getAccessibleSelection();
156: list.add("item1");
157: list.add("item2");
158: assertEquals(0, list.getSelectedItems().length);
159: as.removeAccessibleSelection(0);
160: as.removeAccessibleSelection(1);
161: assertEquals(0, list.getSelectedItems().length);
162: list.select(0);
163: assertEquals(1, list.getSelectedItems().length);
164: as.removeAccessibleSelection(1);
165: assertEquals(1, list.getSelectedItems().length);
166: as.removeAccessibleSelection(0);
167: assertEquals(0, list.getSelectedItems().length);
168: }
169:
170: public final void testIsAccessibleChildSelected() {
171: AccessibleSelection as = ac.getAccessibleSelection();
172: list.add("item1");
173: list.add("item2");
174: assertFalse(as.isAccessibleChildSelected(0));
175: assertFalse(as.isAccessibleChildSelected(1));
176: list.select(1);
177: assertFalse(as.isAccessibleChildSelected(0));
178: assertTrue(as.isAccessibleChildSelected(1));
179: list.select(0);
180: assertFalse(as.isAccessibleChildSelected(1));
181: assertTrue(as.isAccessibleChildSelected(0));
182: }
183:
184: /*
185: * Class under test for javax.accessibility.Accessible getAccessibleSelection(int)
186: */
187: public final void testGetAccessibleSelectionint() {
188: AccessibleSelection as = ac.getAccessibleSelection();
189: list.add("item1");
190: list.add("item2");
191: assertNull(as.getAccessibleSelection(-1));
192: assertNull(as.getAccessibleSelection(0));
193: assertNull(as.getAccessibleSelection(1));
194: list.select(1);
195: assertNull(as.getAccessibleSelection(-1));
196: assertTrue(as.getAccessibleSelection(0) instanceof AccessibleAWTList.AccessibleAWTListChild);
197: assertNull(as.getAccessibleSelection(1));
198: }
199:
200: public final void testGetAccessibleSelection() {
201: assertSame(ac, ac.getAccessibleSelection());
202: }
203:
204: public final void testItemStateChanged() {
205: // not implemented
206: }
207:
208: public final void testActionPerformed() {
209: // not implemented
210: }
211:
212: }
|