001: /*
002: * @(#)KeyCaptureEventIUTest.java
003: *
004: * Copyright (C) 2002-2003 Matt Albrecht
005: * groboclown@users.sourceforge.net
006: * http://groboutils.sourceforge.net
007: *
008: * Permission is hereby granted, free of charge, to any person obtaining a
009: * copy of this software and associated documentation files (the "Software"),
010: * to deal in the Software without restriction, including without limitation
011: * the rights to use, copy, modify, merge, publish, distribute, sublicense,
012: * and/or sell copies of the Software, and to permit persons to whom the
013: * Software is furnished to do so, subject to the following conditions:
014: *
015: * The above copyright notice and this permission notice shall be included in
016: * all copies or substantial portions of the Software.
017: *
018: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
019: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
020: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
021: * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
022: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
023: * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
024: * DEALINGS IN THE SOFTWARE.
025: */
026:
027: package net.sourceforge.groboutils.uicapture.v1.event;
028:
029: import java.awt.Robot;
030: import java.awt.event.InputEvent;
031: import java.awt.event.KeyEvent;
032:
033: import net.sourceforge.groboutils.autodoc.v1.AutoDoc;
034: import junit.framework.Test;
035: import junit.framework.TestCase;
036: import junit.framework.TestSuite;
037:
038: /**
039: * Tests the CaptureEvent class.
040: *
041: * @author Matt Albrecht <a href="mailto:groboclown@users.sourceforge.net">groboclown@users.sourceforge.net</a>
042: * @since Jan 6, 2002
043: * @version $Date: 2003/02/10 22:52:34 $
044: */
045: public class KeyCaptureEventIUTest extends CaptureEventIUTest {
046: //-------------------------------------------------------------------------
047: // Standard JUnit Class-specific declarations
048:
049: private static final Class THIS_CLASS = KeyCaptureEventIUTest.class;
050: private static final AutoDoc DOC = new AutoDoc(THIS_CLASS);
051:
052: public KeyCaptureEventIUTest(String name) {
053: super (name);
054: }
055:
056: //-------------------------------------------------------------------------
057: // Tests
058:
059: public void testNoEventConstructorKey() {
060: KeyCaptureEvent ce = createKeyCaptureEvent();
061: assertEquals(
062: "Null event at constructor must return a null event.",
063: ce.getKeyEvent(), null);
064: assertEquals("Event creation must return the same keyCode", ce
065: .getKeyCode(), this .keyCodeMan);
066: }
067:
068: public void testEventConstructorKey() {
069: KeyEvent ie = createKeyEvent();
070: KeyCaptureEvent ce = createKeyCaptureEvent(ie);
071: assertTrue(
072: "Event passed in creation must be the same event returned.",
073: ce.getKeyEvent() == ie);
074: assertEquals(
075: "Event passed in creation must be the same event returned.",
076: ce.getKeyCode(), this .keyCodeImplicit);
077: }
078:
079: protected int eventType = -3;
080: protected int keyCodeMan = KeyEvent.VK_T;
081: protected int keyCodeImplicit = KeyEvent.VK_S;
082:
083: protected CaptureEvent createCaptureEvent(InputEvent ie) {
084: return createKeyCaptureEvent((KeyEvent) ie);
085: }
086:
087: protected CaptureEvent createCaptureEvent() {
088: return createKeyCaptureEvent();
089: }
090:
091: protected InputEvent createInputEvent() {
092: return createKeyEvent();
093: }
094:
095: protected KeyCaptureEvent createKeyCaptureEvent(KeyEvent ie) {
096: return new KeyCaptureEvent(this .eventType, ie) {
097: public void performEvent(Robot r) {
098: // do nothing
099: }
100: };
101: }
102:
103: protected KeyCaptureEvent createKeyCaptureEvent() {
104: return new KeyCaptureEvent(this .eventType, this .keyCodeMan) {
105: public void performEvent(Robot r) {
106: // do nothing
107: }
108: };
109: }
110:
111: protected KeyEvent createKeyEvent() {
112: return new KeyEvent(createComponent(), 1, 2L, 0,
113: this .keyCodeImplicit);
114: }
115:
116: //-------------------------------------------------------------------------
117: // Standard JUnit declarations
118:
119: public static Test suite() {
120: TestSuite suite = new TestSuite(THIS_CLASS);
121:
122: return suite;
123: }
124:
125: public static void main(String[] args) {
126: String[] name = { THIS_CLASS.getName() };
127:
128: // junit.textui.TestRunner.main( name );
129: // junit.swingui.TestRunner.main( name );
130:
131: junit.textui.TestRunner.main(name);
132: }
133:
134: /**
135: *
136: * @exception Exception thrown under any exceptional condition.
137: */
138: protected void setUp() throws Exception {
139: super .setUp();
140:
141: // set ourself up
142: }
143:
144: /**
145: *
146: * @exception Exception thrown under any exceptional condition.
147: */
148: protected void tearDown() throws Exception {
149: // tear ourself down
150:
151: super.tearDown();
152: }
153: }
|