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 Michael Danilov
019: * @version $Revision$
020: */package java.awt.event;
021:
022: import java.awt.Button;
023:
024: import junit.framework.TestCase;
025:
026: @SuppressWarnings("serial")
027: public class InputEventTest extends TestCase {
028:
029: public final void testInputEvent() {
030: Button button = new Button("Button"); //$NON-NLS-1$
031: InputEvent event = new InputEvent(button, 0, 1000000000,
032: InputEvent.ALT_MASK | InputEvent.BUTTON1_MASK) {
033: };
034:
035: assertEquals(event.getSource(), button);
036: assertEquals(event.getID(), 0);
037: assertEquals(event.getWhen(), 1000000000);
038: assertEquals(event.getModifiers(), InputEvent.ALT_MASK
039: | InputEvent.BUTTON1_MASK);
040: }
041:
042: public final void testConsuming() {
043: Button button = new Button("Button"); //$NON-NLS-1$
044: InputEvent event = new InputEvent(button, 0, 1000000000,
045: InputEvent.ALT_DOWN_MASK | InputEvent.BUTTON1_MASK) {
046: };
047:
048: assertFalse(event.isConsumed());
049: event.consume();
050: assertTrue(event.isConsumed());
051: }
052:
053: public final void testGetModifiers() {
054: Button button = new Button("Button"); //$NON-NLS-1$
055: InputEvent event = new InputEvent(button, 0, 1000000000,
056: InputEvent.MASKS | InputEvent.DOWN_MASKS) {
057: };
058:
059: assertEquals(InputEvent.MASKS, event.getModifiers());
060: }
061:
062: public final void testGetModifiersEx() {
063: Button button = new Button("Button"); //$NON-NLS-1$
064: InputEvent event = new InputEvent(button, 0, 1000000000,
065: InputEvent.MASKS | InputEvent.DOWN_MASKS) {
066: };
067:
068: assertEquals(InputEvent.DOWN_MASKS, event.getModifiersEx());
069: }
070:
071: public final void testIsAltDown() {
072: Button button = new Button("Button"); //$NON-NLS-1$
073: InputEvent event = new InputEvent(button, 0, 1000000000, 0) {
074: };
075:
076: assertFalse(event.isAltDown());
077: event = new InputEvent(button, 0, 1000000000,
078: InputEvent.ALT_DOWN_MASK) {
079: };
080: assertTrue(event.isAltDown());
081: }
082:
083: public final void testIsAltGraphDown() {
084: Button button = new Button("Button"); //$NON-NLS-1$
085: InputEvent event = new InputEvent(button, 0, 1000000000, 0) {
086: };
087:
088: assertFalse(event.isAltGraphDown());
089: event = new InputEvent(button, 0, 1000000000,
090: InputEvent.ALT_GRAPH_DOWN_MASK) {
091: };
092: assertTrue(event.isAltGraphDown());
093: }
094:
095: public final void testIsControlDown() {
096: Button button = new Button("Button"); //$NON-NLS-1$
097: InputEvent event = new InputEvent(button, 0, 1000000000, 0) {
098: };
099:
100: assertFalse(event.isControlDown());
101: event = new InputEvent(button, 0, 1000000000,
102: InputEvent.CTRL_DOWN_MASK) {
103: };
104: assertTrue(event.isControlDown());
105: }
106:
107: public final void testIsMetaDown() {
108: Button button = new Button("Button"); //$NON-NLS-1$
109: InputEvent event = new InputEvent(button, 0, 1000000000, 0) {
110: };
111:
112: assertFalse(event.isMetaDown());
113: event = new InputEvent(button, 0, 1000000000,
114: InputEvent.META_DOWN_MASK) {
115: };
116: assertTrue(event.isMetaDown());
117: }
118:
119: public final void testIsShiftDown() {
120: Button button = new Button("Button"); //$NON-NLS-1$
121: InputEvent event = new InputEvent(button, 0, 1000000000, 0) {
122: };
123:
124: assertFalse(event.isShiftDown());
125: event = new InputEvent(button, 0, 1000000000,
126: InputEvent.SHIFT_DOWN_MASK) {
127: };
128: assertTrue(event.isShiftDown());
129: }
130:
131: public final void testGetModifiersExText() {
132: assertTrue(InputEvent.getModifiersExText(
133: InputEvent.ALT_DOWN_MASK).indexOf("Alt") != -1); //$NON-NLS-1$
134: assertTrue(InputEvent.getModifiersExText(
135: InputEvent.ALT_GRAPH_DOWN_MASK).indexOf("Alt Graph") != -1); //$NON-NLS-1$
136: assertTrue(InputEvent.getModifiersExText(
137: InputEvent.CTRL_DOWN_MASK).indexOf("Ctrl") != -1); //$NON-NLS-1$
138: assertTrue(InputEvent.getModifiersExText(
139: InputEvent.SHIFT_DOWN_MASK).indexOf("Shift") != -1); //$NON-NLS-1$
140: assertTrue(InputEvent.getModifiersExText(
141: InputEvent.META_DOWN_MASK).indexOf("Meta") != -1); //$NON-NLS-1$
142: assertTrue(InputEvent.getModifiersExText(
143: InputEvent.BUTTON1_DOWN_MASK).indexOf("Button1") != -1); //$NON-NLS-1$
144: assertTrue(InputEvent.getModifiersExText(
145: InputEvent.BUTTON2_DOWN_MASK).indexOf("Button2") != -1); //$NON-NLS-1$
146: assertTrue(InputEvent.getModifiersExText(
147: InputEvent.BUTTON3_DOWN_MASK).indexOf("Button3") != -1); //$NON-NLS-1$
148: }
149: }
|