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