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

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