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.MenuComponent.AccessibleAWTMenuComponent;
023: import java.util.Locale;
024:
025: import javax.accessibility.Accessible;
026: import javax.accessibility.AccessibleContext;
027: import javax.accessibility.AccessibleRole;
028: import javax.accessibility.AccessibleStateSet;
029:
030: import junit.framework.TestCase;
031:
032: /**
033: * AccessibleAWTMenuComponentTest
034: */
035: @SuppressWarnings("serial")
036: public class AccessibleAWTMenuComponentTest extends TestCase {
037:
038: class MyMenuComponent extends MenuComponent implements Accessible {
039: AccessibleContext ac;
040:
041: @Override
042: public AccessibleContext getAccessibleContext() {
043: if (ac == null) {
044: ac = new AccessibleAWTMenuComponent() {
045: };
046: }
047: return ac;
048: }
049: }
050:
051: private MenuComponent menuComp;
052: private AccessibleAWTMenuComponent aMenuComp;
053:
054: @Override
055: protected void setUp() throws Exception {
056: super .setUp();
057: menuComp = new MyMenuComponent();
058: aMenuComp = (AccessibleAWTMenuComponent) menuComp
059: .getAccessibleContext();
060: // aMenuComp = menuComp.new AccessibleAWTMenuComponent(){};
061: }
062:
063: public final void testAccessibleAWTMenuComponent() {
064: assertNotNull(aMenuComp);
065: assertNull(new MenuComponent() {
066: }.getAccessibleContext());
067: }
068:
069: public final void testContains() {
070: assertFalse(aMenuComp.contains(new Point()));
071: }
072:
073: public final void testGetAccessibleAt() {
074: assertNull(aMenuComp.getAccessibleAt(new Point()));
075: }
076:
077: public final void testGetBackground() {
078: assertNull(aMenuComp.getBackground());
079: }
080:
081: public final void testGetBounds() {
082: assertNull(aMenuComp.getBounds());
083: }
084:
085: public final void testGetCursor() {
086: assertNull(aMenuComp.getCursor());
087: }
088:
089: public final void testGetFont() {
090: assertNull(aMenuComp.getFont());
091: Font font = Font.decode("Arial");
092: menuComp.setFont(font);
093: assertSame(font, aMenuComp.getFont());
094: }
095:
096: public final void testGetFontMetrics() {
097: Font font = Font.decode("Dialog");
098: menuComp.setFont(font);
099: assertSame(font, aMenuComp.getFont());
100: assertNull(aMenuComp.getFontMetrics(font));
101:
102: }
103:
104: public final void testGetForeground() {
105: assertNull(aMenuComp.getForeground());
106: }
107:
108: public final void testGetLocation() {
109: assertNull(aMenuComp.getLocation());
110: }
111:
112: public final void testGetLocationOnScreen() {
113: assertNull(aMenuComp.getLocationOnScreen());
114: }
115:
116: public final void testGetSize() {
117: assertNull(aMenuComp.getSize());
118: }
119:
120: public final void testIsEnabled() {
121: assertTrue(aMenuComp.isEnabled());
122: }
123:
124: public final void testIsFocusTraversable() {
125: assertTrue(aMenuComp.isFocusTraversable());
126: }
127:
128: public final void testIsShowing() {
129: assertTrue(aMenuComp.isShowing());
130: }
131:
132: public final void testIsVisible() {
133: assertTrue(aMenuComp.isVisible());
134: }
135:
136: public final void testSetFont() {
137: Font font = Font.decode(null);
138: aMenuComp.setFont(font);
139: assertSame(font, aMenuComp.getFont());
140: assertSame("setFont() is delegated to MenuComponent", font,
141: menuComp.getFont());
142: }
143:
144: public final void testAddAccessibleSelection() {
145: int idx = 0;
146: aMenuComp.addAccessibleSelection(idx); //does nothing
147: assertEquals(0, aMenuComp.getAccessibleSelectionCount());
148: assertNull(aMenuComp.getAccessibleSelection(idx));
149: }
150:
151: public final void testClearAccessibleSelection() {
152: aMenuComp.addAccessibleSelection(0);
153: aMenuComp.addAccessibleSelection(1);
154: assertEquals(0, aMenuComp.getAccessibleSelectionCount());
155: aMenuComp.clearAccessibleSelection(); // does nothing
156: assertEquals(0, aMenuComp.getAccessibleSelectionCount());
157: assertNull(aMenuComp.getAccessibleSelection(0));
158: }
159:
160: /*
161: * Class under test for javax.accessibility.Accessible getAccessibleSelection(int)
162: */
163: public final void testGetAccessibleSelectionint() {
164: assertNull(aMenuComp.getAccessibleSelection(0));
165: }
166:
167: public final void testGetAccessibleSelectionCount() {
168: assertEquals(0, aMenuComp.getAccessibleSelectionCount());
169: }
170:
171: public final void testIsAccessibleChildSelected() {
172: assertFalse(aMenuComp.isAccessibleChildSelected(0));
173: }
174:
175: public final void testRemoveAccessibleSelection() {
176: aMenuComp.addAccessibleSelection(0);
177: aMenuComp.addAccessibleSelection(1);
178: assertEquals(0, aMenuComp.getAccessibleSelectionCount());
179: aMenuComp.removeAccessibleSelection(0); // does nothing
180: assertEquals(0, aMenuComp.getAccessibleSelectionCount());
181: assertNull(aMenuComp.getAccessibleSelection(0));
182: }
183:
184: public final void testSelectAllAccessibleSelection() {
185: assertEquals(0, aMenuComp.getAccessibleSelectionCount());
186: aMenuComp.selectAllAccessibleSelection(); // does nothing
187: assertEquals(0, aMenuComp.getAccessibleSelectionCount());
188: assertNull(aMenuComp.getAccessibleSelection(0));
189: }
190:
191: public final void testGetAccessibleChild() {
192: assertNull(aMenuComp.getAccessibleChild(0));
193: }
194:
195: public final void testGetAccessibleChildrenCount() {
196: assertEquals(0, aMenuComp.getAccessibleChildrenCount());
197: }
198:
199: public final void testGetAccessibleComponent() {
200: assertSame(aMenuComp, aMenuComp.getAccessibleComponent());
201: }
202:
203: public final void testGetAccessibleDescription() {
204: assertNull(aMenuComp.getAccessibleDescription());
205: String descr = "description";
206: aMenuComp.setAccessibleDescription(descr);
207: assertEquals(descr, aMenuComp.getAccessibleDescription());
208: }
209:
210: public final void testGetAccessibleIndexInParent() {
211: assertEquals(-1, aMenuComp.getAccessibleIndexInParent());
212: Menu menu = new Menu();
213: MenuItem item1 = new MenuItem("1");
214: MenuItem item2 = new MenuItem("2");
215: menu.add(item2);
216: menu.add(item1);
217: aMenuComp = item1.new AccessibleAWTMenuComponent() {
218: };
219: assertEquals(1, aMenuComp.getAccessibleIndexInParent());
220: }
221:
222: public final void testGetAccessibleName() {
223: String name = "name";
224: String aName = "accessible name";
225: menuComp.setName(name);
226: assertNull(aMenuComp.getAccessibleName());
227: aMenuComp.setAccessibleName(aName);
228: assertEquals(aName, aMenuComp.getAccessibleName());
229:
230: }
231:
232: public final void testGetAccessibleParent() {
233: assertNull(aMenuComp.getAccessibleParent());
234: MenuBar menubar = new MenuBar();
235: Menu menu = new Menu("1");
236: menubar.add(menu);
237: aMenuComp = menu.new AccessibleAWTMenuComponent() {
238: };
239: assertSame(menubar, aMenuComp.getAccessibleParent());
240: }
241:
242: public final void testGetAccessibleRole() {
243: assertSame(AccessibleRole.AWT_COMPONENT, aMenuComp
244: .getAccessibleRole());
245: }
246:
247: /*
248: * Class under test for javax.accessibility.AccessibleSelection getAccessibleSelection()
249: */
250: public final void testGetAccessibleSelection() {
251: assertSame(aMenuComp, aMenuComp.getAccessibleSelection());
252: }
253:
254: public final void testGetAccessibleStateSet() {
255: AccessibleStateSet set = aMenuComp.getAccessibleStateSet();
256: assertNotNull(set);
257: assertEquals("accessible state set is empty", 0,
258: set.toArray().length);
259: }
260:
261: public final void testGetLocale() {
262: Locale locale = Locale.getDefault();
263: assertSame(locale, aMenuComp.getLocale());
264: Locale.setDefault(locale = Locale.TAIWAN);
265: assertSame(locale, aMenuComp.getLocale());
266: }
267:
268: }
|