01: package abbot.tester;
02:
03: import java.awt.event.*;
04: import javax.swing.KeyStroke;
05:
06: import junit.framework.*;
07: import junit.extensions.abbot.*;
08:
09: public class MapGeneratorTest extends TestCase {
10:
11: private static final int NONE = 0;
12: private static final int SHIFT = KeyEvent.SHIFT_MASK;
13: // NOTE: these mappings are only valid for the en_US locale
14: private static final Object[][] mappings = {
15: { new Character('a'),
16: KeyStroke.getKeyStroke(KeyEvent.VK_A, NONE) },
17: { new Character('A'),
18: KeyStroke.getKeyStroke(KeyEvent.VK_A, SHIFT) },
19: { new Character('g'),
20: KeyStroke.getKeyStroke(KeyEvent.VK_G, NONE) },
21: { new Character('G'),
22: KeyStroke.getKeyStroke(KeyEvent.VK_G, SHIFT) },
23: { new Character('k'),
24: KeyStroke.getKeyStroke(KeyEvent.VK_K, NONE) },
25: { new Character('K'),
26: KeyStroke.getKeyStroke(KeyEvent.VK_K, SHIFT) },
27: { new Character('z'),
28: KeyStroke.getKeyStroke(KeyEvent.VK_Z, NONE) },
29: { new Character('Z'),
30: KeyStroke.getKeyStroke(KeyEvent.VK_Z, SHIFT) },
31: { new Character('0'),
32: KeyStroke.getKeyStroke(KeyEvent.VK_0, NONE) },
33: { new Character('1'),
34: KeyStroke.getKeyStroke(KeyEvent.VK_1, NONE) },
35: { new Character('2'),
36: KeyStroke.getKeyStroke(KeyEvent.VK_2, NONE) },
37: { new Character('3'),
38: KeyStroke.getKeyStroke(KeyEvent.VK_3, NONE) },
39: { new Character('4'),
40: KeyStroke.getKeyStroke(KeyEvent.VK_4, NONE) },
41: { new Character('5'),
42: KeyStroke.getKeyStroke(KeyEvent.VK_5, NONE) },
43: { new Character('6'),
44: KeyStroke.getKeyStroke(KeyEvent.VK_6, NONE) },
45: { new Character('7'),
46: KeyStroke.getKeyStroke(KeyEvent.VK_7, NONE) },
47: { new Character('8'),
48: KeyStroke.getKeyStroke(KeyEvent.VK_8, NONE) },
49: { new Character('9'),
50: KeyStroke.getKeyStroke(KeyEvent.VK_9, NONE) },
51: { new Character('/'),
52: KeyStroke.getKeyStroke(KeyEvent.VK_SLASH, NONE) },
53: { new Character('?'),
54: KeyStroke.getKeyStroke(KeyEvent.VK_SLASH, SHIFT) },
55: {
56: new Character('`'),
57: KeyStroke
58: .getKeyStroke(KeyEvent.VK_BACK_QUOTE, NONE) },
59: {
60: new Character('~'),
61: KeyStroke.getKeyStroke(KeyEvent.VK_BACK_QUOTE,
62: SHIFT) }, };
63:
64: public void testCharacterLookup() {
65: for (int m = 0; m < mappings.length; m++) {
66: KeyStroke ks = (KeyStroke) mappings[m][1];
67: assertEquals(
68: "wrong character for '" + mappings[m][1] + "'",
69: mappings[m][0], new Character(KeyStrokeMap
70: .getChar(ks)));
71: }
72: }
73:
74: public void testKeyCodeLookup() {
75: for (int m = 0; m < mappings.length; m++) {
76: Character ch = (Character) mappings[m][0];
77: assertEquals(
78: "wrong KeyStroke for '" + mappings[m][0] + "'",
79: mappings[m][1], KeyStrokeMap.getKeyStroke(ch
80: .charValue()));
81: }
82: }
83:
84: public MapGeneratorTest(String name) {
85: super (name);
86: }
87:
88: public static void main(String[] args) {
89: TestHelper.runTests(args, MapGeneratorTest.class);
90: }
91: }
|