source: trunk/autoquest-misc-test/src/test/java/de/ugoe/cs/quest/keyboardmaps/KeyboardMapTest.java @ 922

Last change on this file since 922 was 922, checked in by sherbold, 12 years ago
  • renaming of packages from de.ugoe.cs.quest to de.ugoe.cs.autoquest
File size: 14.8 KB
Line 
1package de.ugoe.cs.quest.keyboardmaps;
2
3import static org.junit.Assert.*;
4
5import java.util.Locale;
6import java.util.logging.Level;
7
8import org.junit.Before;
9import org.junit.Test;
10
11import de.ugoe.cs.autoquest.keyboardmaps.KeyboardMap;
12import de.ugoe.cs.autoquest.keyboardmaps.KeyboardMapFactory;
13import de.ugoe.cs.autoquest.keyboardmaps.VirtualKey;
14import de.ugoe.cs.util.console.TextConsole;
15
16/**
17 * TODO comment
18 *
19 * @version $Revision: $ $Date: 11.07.2012$
20 * @author 2012, last modified by $Author: patrick$
21 */
22public class KeyboardMapTest {
23
24    /**
25     *
26     */
27    @Before
28    public void setUp() {
29        new TextConsole(Level.FINEST);
30    }
31
32    /**
33     * TODO: comment
34     *
35     */
36    @Test
37    public void testInitialization() {
38        KeyboardMap map = KeyboardMapFactory.createKeyboardMap(Locale.ENGLISH);
39        assertNotNull(map);
40
41        map = KeyboardMapFactory.createKeyboardMap(Locale.FRENCH);
42        assertNotNull(map);
43
44        map = KeyboardMapFactory.createKeyboardMap(Locale.GERMAN);
45        assertNotNull(map);
46
47        map = KeyboardMapFactory.createKeyboardMap(Locale.ITALIAN);
48        assertNotNull(map);
49
50        map = KeyboardMapFactory.createKeyboardMap(Locale.JAPANESE);
51        assertNotNull(map);
52
53        map = KeyboardMapFactory.createKeyboardMap(Locale.KOREAN);
54        assertNotNull(map);
55
56        try {
57            map = KeyboardMapFactory.createKeyboardMap(Locale.CHINESE);
58            fail("expected exception did not occur");
59        }
60        catch (IllegalArgumentException e) {
61            // was expected and is ignored
62        }
63
64        try {
65            map = KeyboardMapFactory.createKeyboardMap(Locale.SIMPLIFIED_CHINESE);
66            fail("expected exception did not occur");
67        }
68        catch (IllegalArgumentException e) {
69            // was expected and is ignored
70        }
71
72        try {
73            map = KeyboardMapFactory.createKeyboardMap(Locale.TRADITIONAL_CHINESE);
74            fail("expected exception did not occur");
75        }
76        catch (IllegalArgumentException e) {
77            // was expected and is ignored
78        }
79
80        map = KeyboardMapFactory.createKeyboardMap(Locale.FRANCE);
81        assertNotNull(map);
82
83        map = KeyboardMapFactory.createKeyboardMap(Locale.GERMANY);
84        assertNotNull(map);
85
86        map = KeyboardMapFactory.createKeyboardMap(Locale.ITALY);
87        assertNotNull(map);
88
89        map = KeyboardMapFactory.createKeyboardMap(Locale.JAPAN);
90        assertNotNull(map);
91
92        map = KeyboardMapFactory.createKeyboardMap(Locale.KOREA);
93        assertNotNull(map);
94
95        try {
96            map = KeyboardMapFactory.createKeyboardMap(Locale.CHINA);
97            fail("expected exception did not occur");
98        }
99        catch (IllegalArgumentException e) {
100            // was expected and is ignored
101        }
102
103        try {
104            map = KeyboardMapFactory.createKeyboardMap(Locale.PRC);
105            fail("expected exception did not occur");
106        }
107        catch (IllegalArgumentException e) {
108            // was expected and is ignored
109        }
110
111        try {
112            map = KeyboardMapFactory.createKeyboardMap(Locale.TAIWAN);
113            fail("expected exception did not occur");
114        }
115        catch (IllegalArgumentException e) {
116            // was expected and is ignored
117        }
118
119        map = KeyboardMapFactory.createKeyboardMap(Locale.UK);
120        assertNotNull(map);
121
122        map = KeyboardMapFactory.createKeyboardMap(Locale.US);
123        assertNotNull(map);
124
125        map = KeyboardMapFactory.createKeyboardMap(Locale.CANADA);
126        assertNotNull(map);
127
128        map = KeyboardMapFactory.createKeyboardMap(Locale.CANADA_FRENCH);
129        assertNotNull(map);
130
131        map = KeyboardMapFactory.createKeyboardMap(Locale.GERMAN);
132        assertNotNull(map);
133
134    }
135
136    /**
137     * TODO: comment
138     *
139     */
140    @Test
141    public void testGermanKeyboardMap() {
142        KeyboardMap map = KeyboardMapFactory.createKeyboardMap(Locale.GERMAN);
143        assertNotNull(map);
144
145        assertCombinations(map, VirtualKey.DIGIT_1, '1', '!', '¹', '¡', true);
146        assertCombinations(map, VirtualKey.EXCLAMATION_MARK, '1', '!', '¹', '¡', true);
147        assertCombinations(map, VirtualKey.INVERTED_EXCLAMATION_MARK, '1', '!', '¹', '¡', true);
148
149        assertCombinations(map, VirtualKey.DIGIT_2, '2', '"', '²', '⅛', true);
150        assertCombinations(map, VirtualKey.QUOTEDBL, '2', '"', '²', '⅛', true);
151
152        assertCombinations(map, VirtualKey.DIGIT_3, '3', '§', '³', '£', true);
153
154        assertCombinations(map, VirtualKey.DIGIT_4, '4', '$', '¼', '¤', true);
155        assertCombinations(map, VirtualKey.DOLLAR, '4', '$', '¼', '¤', true);
156
157        assertCombinations(map, VirtualKey.DIGIT_5, '5', '%', '½', '⅜', true);
158
159        assertCombinations(map, VirtualKey.DIGIT_6, '6', '&', '¾', '⅝', true);
160        assertCombinations(map, VirtualKey.AMPERSAND, '6', '&', '¾', '⅝', true);
161
162        assertCombinations(map, VirtualKey.DIGIT_7, '7', '/', '{', '⅞', true);
163        assertCombinations(map, VirtualKey.SLASH, '7', '/', '{', '⅞', true);
164        assertCombinations(map, VirtualKey.BRACELEFT, '7', '/', '{', '⅞', true);
165
166        assertCombinations(map, VirtualKey.DIGIT_8, '8', '(', '[', '™', true);
167        assertCombinations(map, VirtualKey.LEFT_PARENTHESIS, '8', '(', '[', '™', true);
168        assertCombinations(map, VirtualKey.OPEN_BRACKET, '8', '(', '[', '™', true);
169
170        assertCombinations(map, VirtualKey.DIGIT_9, '9', ')', ']', '±', true);
171        assertCombinations(map, VirtualKey.RIGHT_PARENTHESIS, '9', ')', ']', '±', true);
172        assertCombinations(map, VirtualKey.CLOSE_BRACKET, '9', ')', ']', '±', true);
173
174        assertCombinations(map, VirtualKey.DIGIT_0, '0', '=', '}', 0, true);
175        assertCombinations(map, VirtualKey.EQUALS, '0', '=', '}', 0, true);
176        assertCombinations(map, VirtualKey.BRACERIGHT, '0', '=', '}', 0, true);
177
178        assertCombinations(map, VirtualKey.BACK_SLASH, 'ß', '?', '\\', '¿', true);
179
180        assertCombinations(map, VirtualKey.LETTER_Q, 'q', 'Q', '@', 'Ω', true);
181        assertCombinations(map, VirtualKey.AT, 'q', 'Q', '@', 'Ω', true);
182
183        assertCombinations(map, VirtualKey.LETTER_W, 'w', 'W', 0, 0, true);
184
185        assertCombinations(map, VirtualKey.LETTER_E, 'e', 'E', '€', 0, true);
186        assertCombinations(map, VirtualKey.EURO_SIGN, 'e', 'E', '€', 0, true);
187
188        assertCombinations(map, VirtualKey.LETTER_R, 'r', 'R', 0, '®', true);
189
190        assertCombinations(map, VirtualKey.LETTER_T, 't', 'T', 'ŧ', 'Ŧ', true);
191
192        assertCombinations(map, VirtualKey.LETTER_Z, 'z', 'Z', '←', '¥', true);
193
194        assertCombinations(map, VirtualKey.LETTER_U, 'u', 'U', '↓', '↑', true);
195
196        assertCombinations(map, VirtualKey.LETTER_I, 'i', 'I', '→', 'ı', true);
197
198        assertCombinations(map, VirtualKey.LETTER_O, 'o', 'O', 'ø', 'Ø', true);
199
200        assertCombinations(map, VirtualKey.LETTER_P, 'p', 'P', 'þ', 'Þ', true);
201
202        assertCombinations(map, VirtualKey.LETTER_A, 'a', 'A', 'æ', 'Æ', true);
203
204        assertCombinations(map, VirtualKey.LETTER_S, 's', 'S', 0, 0, true);
205
206        assertCombinations(map, VirtualKey.LETTER_D, 'd', 'D', 'ð', 'Ð', true);
207
208        assertCombinations(map, VirtualKey.LETTER_F, 'f', 'F', 'đ', 'ª', true);
209
210        assertCombinations(map, VirtualKey.LETTER_G, 'g', 'G', 'ŋ', 'Ŋ', true);
211
212        assertCombinations(map, VirtualKey.LETTER_H, 'h', 'H', 'ħ', 'Ħ', true);
213
214        assertCombinations(map, VirtualKey.LETTER_J, 'j', 'J', 0, 0, true);
215
216        assertCombinations(map, VirtualKey.LETTER_K, 'k', 'K', 'ĸ', 0, true);
217
218        assertCombinations(map, VirtualKey.LETTER_L, 'l', 'L', 0, 0, true);
219
220        assertCombinations(map, VirtualKey.LETTER_Y, 'y', 'Y', '»', 0, true);
221
222        assertCombinations(map, VirtualKey.LETTER_X, 'x', 'X', '«', 0, true);
223
224        assertCombinations(map, VirtualKey.LETTER_C, 'c', 'C', '¢', '©', true);
225
226        assertCombinations(map, VirtualKey.LETTER_V, 'v', 'V', '„', 0, true);
227
228        assertCombinations(map, VirtualKey.LETTER_B, 'b', 'B', '“', 0, true);
229
230        assertCombinations(map, VirtualKey.LETTER_N, 'n', 'N', 0, 0, true);
231
232        assertCombinations(map, VirtualKey.LETTER_M, 'm', 'M', 'µ', 'º', true);
233
234        assertCombinations(map, VirtualKey.NUMPAD_0, '0', 0, 0, 0, false);
235
236        assertCombinations(map, VirtualKey.NUMPAD_1, '1', 0, 0, 0, false);
237
238        assertCombinations(map, VirtualKey.NUMPAD_2, '2', 0, 0, 0, false);
239
240        assertCombinations(map, VirtualKey.NUMPAD_3, '3', 0, 0, 0, false);
241
242        assertCombinations(map, VirtualKey.NUMPAD_4, '4', 0, 0, 0, false);
243
244        assertCombinations(map, VirtualKey.NUMPAD_5, '5', 0, 0, 0, false);
245
246        assertCombinations(map, VirtualKey.NUMPAD_6, '6', 0, 0, 0, false);
247
248        assertCombinations(map, VirtualKey.NUMPAD_7, '7', 0, 0, 0, false);
249
250        assertCombinations(map, VirtualKey.NUMPAD_8, '8', 0, 0, 0, false);
251
252        assertCombinations(map, VirtualKey.NUMPAD_9, '9', 0, 0, 0, false);
253
254        assertCombinations(map, VirtualKey.SEPARATOR, ',', 0, 0, 0, false);
255        assertCombinations(map, VirtualKey.DECIMAL, ',', 0, 0, 0, false);
256
257        assertCombinations(map, VirtualKey.CIRCUMFLEX, '^', '°', '¬', 0, true);
258
259        assertCombinations(map, VirtualKey.TAB, '\t', 0, '\t', 0, true);
260
261        assertCombinations(map, VirtualKey.SPACE, ' ', ' ', ' ', ' ', true);
262
263        assertCombinations(map, VirtualKey.COMMA, ',', ';', '·', '×', true);
264        assertCombinations(map, VirtualKey.SEMICOLON, ',', ';', '·', '×', true);
265        assertCombinations(map, VirtualKey.MULTIPLY, ',', ';', '·', '×', true);
266
267        assertCombinations(map, VirtualKey.MINUS, '-', '_', 0, 0, true);
268        assertCombinations(map, VirtualKey.UNDERSCORE, '-', '_', 0, 0, true);
269
270        assertCombinations(map, VirtualKey.PERIOD, '.', ':', '…', '÷', true);
271        assertCombinations(map, VirtualKey.COLON, '.', ':', '…', '÷', true);
272        assertCombinations(map, VirtualKey.DIVIDE, '.', ':', '…', '÷', true);
273
274        assertCombinations(map, VirtualKey.PLUS, '+', '*', '~', 0, true);
275        assertCombinations(map, VirtualKey.ASTERISK, '+', '*', '~', 0, true);
276        assertCombinations(map, VirtualKey.DEAD_TILDE, '+', '*', '~', 0, true);
277
278        assertCombinations(map, VirtualKey.LESS, '<', '>', '|', '¦', true);
279        assertCombinations(map, VirtualKey.GREATER, '<', '>', '|', '¦', true);
280
281        assertCombinations(map, VirtualKey.NUMBER_SIGN, '#', '\'', 0, 0, true);
282
283        /*
284         * DEAD_GRAVE(KeyEvent.VK_DEAD_GRAVE), DEAD_ACUTE(KeyEvent.VK_DEAD_ACUTE),
285         * DEAD_CIRCUMFLEX(KeyEvent.VK_DEAD_CIRCUMFLEX), DEAD_TILDE(KeyEvent.VK_DEAD_TILDE),
286         * DEAD_MACRON(KeyEvent.VK_DEAD_MACRON), DEAD_BREVE(KeyEvent.VK_DEAD_BREVE),
287         * DEAD_ABOVEDOT(KeyEvent.VK_DEAD_ABOVEDOT), DEAD_DIAERESIS(KeyEvent.VK_DEAD_DIAERESIS),
288         * DEAD_ABOVERING(KeyEvent.VK_DEAD_ABOVERING),
289         * DEAD_DOUBLEACUTE(KeyEvent.VK_DEAD_DOUBLEACUTE), DEAD_CARON(KeyEvent.VK_DEAD_CARON),
290         * DEAD_CEDILLA(KeyEvent.VK_DEAD_CEDILLA), DEAD_OGONEK(KeyEvent.VK_DEAD_OGONEK),
291         * DEAD_IOTA(KeyEvent.VK_DEAD_IOTA), DEAD_VOICED_SOUND(KeyEvent.VK_DEAD_VOICED_SOUND),
292         * DEAD_SEMIVOICED_SOUND(KeyEvent.VK_DEAD_SEMIVOICED_SOUND),
293         */
294    }
295
296    /**
297   *
298   */
299    private void assertCombinations(KeyboardMap map,
300                                    VirtualKey  key,
301                                    int         normal,
302                                    int         withShift,
303                                    int         withAltGr,
304                                    int         withShiftAndAltGr,
305                                    boolean     numLockIndependent)
306    {
307        if (numLockIndependent) {
308            if (normal != 0) {
309                assertCombination("normal", normal, map, key, false, false, false);
310            }
311
312            if (withShift != 0) {
313                assertCombination("shift", withShift, map, key, false, true, false);
314            }
315
316            if (withAltGr != 0) {
317                assertCombination("altgr", withAltGr, map, key, false, false, true);
318            }
319
320            if (withShiftAndAltGr != 0) {
321                assertCombination("shift and altgr", withShiftAndAltGr, map, key, false, true, true);
322            }
323        }
324        else {
325            assertInvalidCombination("normal", normal, map, key, false, false, false);
326            assertInvalidCombination("shift", withShift, map, key, false, true, false);
327            assertInvalidCombination("altgr", withAltGr, map, key, false, false, true);
328            assertInvalidCombination
329              ("shift and altgr", withShiftAndAltGr, map, key, false, true, true);
330        }
331
332        if (normal != 0) {
333            assertCombination("numlock", normal, map, key, true, false, false);
334        }
335
336        if (withShift != 0) {
337            assertCombination("numlock and shift", withShift, map, key, true, true, false);
338        }
339
340        if (withAltGr != 0) {
341            assertCombination("numlock and altgr", withAltGr, map, key, true, false, true);
342        }
343
344        if (withShiftAndAltGr != 0) {
345            assertCombination
346              ("numlock, shift and altgr", withShiftAndAltGr, map, key, true, true, true);
347        }
348    }
349
350    /**
351     * TODO: comment
352     *
353     * @param string
354     * @param normal
355     * @param characterFor
356     */
357    private void assertCombination(String      type,
358                                   int         expectedChar,
359                                   KeyboardMap map,
360                                   VirtualKey  key,
361                                   boolean     numlock,
362                                   boolean     shift,
363                                   boolean     altgr)
364    {
365        String message = "checked for " + type + ": expected '" + ((char) expectedChar) + "'";
366
367        char retrievedChar;
368        try {
369            retrievedChar = map.getCharacterFor(key, numlock, shift, altgr, false);
370        }
371        catch (IllegalArgumentException e) {
372            fail("no character found. " + message);
373            return;
374        }
375
376        message += " but got '" + retrievedChar + "'";
377
378        assertEquals(message, expectedChar, retrievedChar);
379    }
380
381    /**
382     * TODO: comment
383     *
384     * @param string
385     * @param normal
386     * @param characterFor
387     */
388    private void assertInvalidCombination(String      type,
389                                          int         expectedChar,
390                                          KeyboardMap map,
391                                          VirtualKey  key,
392                                          boolean     numlock,
393                                          boolean     shift,
394                                          boolean     altgr)
395    {
396        char retrievedChar;
397        try {
398            retrievedChar = map.getCharacterFor(key, numlock, shift, altgr, false);
399            assertEquals(Character.UNASSIGNED, retrievedChar);
400        }
401        catch (IllegalArgumentException e) {
402            // this is ok and checked for
403        }
404
405    }
406
407}
Note: See TracBrowser for help on using the repository browser.