source: josm/trunk/test/unit/org/openstreetmap/josm/tools/KeyboardUtilsTest.java@ 18037

Last change on this file since 18037 was 18037, checked in by Don-vip, 3 years ago

fix #21064 - Add JUnit 5 extension for preferences (patch by taylor.smock)

  • Property svn:eol-style set to native
File size: 4.8 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.tools;
3
4import static org.junit.jupiter.api.Assertions.assertEquals;
5
6import java.awt.event.KeyEvent;
7import java.util.ArrayList;
8import java.util.Arrays;
9import java.util.LinkedHashMap;
10import java.util.List;
11import java.util.Locale;
12import java.util.Map;
13import java.util.Map.Entry;
14
15import org.junit.jupiter.api.Test;
16
17/**
18 * Unit tests of {@link KeyboardUtils} class.
19 */
20class KeyboardUtilsTest {
21 /**
22 * Checks that definition of extended characters is correct
23 */
24 @Test
25 void testExtendedCharacters() {
26 Map<Integer, Character> map = new LinkedHashMap<>();
27 KeyboardUtils.addLatinCharacters(map);
28 KeyboardUtils.addSymbolCharacters(map);
29 KeyboardUtils.addArabicCharacters(map);
30 KeyboardUtils.addArmenianCharacters(map);
31 KeyboardUtils.addCyrillicCharacters(map);
32 KeyboardUtils.addGeorgianCharacters(map);
33 KeyboardUtils.addGreekCharacters(map);
34 KeyboardUtils.addHebrewCharacters(map);
35 KeyboardUtils.addJapaneseCharacters(map);
36 KeyboardUtils.addThaiCharacters(map);
37 for (Entry<Integer, Character> e : map.entrySet()) {
38 assertEquals(e.getKey().intValue(), KeyboardUtils.EXTENDED_KEYCODE_FLAG | (int) e.getValue());
39 }
40 }
41
42 /**
43 * Unit test of {@link KeyboardUtils#getCharactersForKey} - E00 character
44 */
45 @Test
46 void testGetCharactersForKeyE00() {
47 char deadCircumflex = (char) KeyEvent.VK_DEAD_CIRCUMFLEX;
48 char deadCaron = (char) KeyEvent.VK_DEAD_CARON;
49 char deadCircumflex2 = 0x2C6;
50 char deadCaron2 = 0x2C7;
51 testgetCharactersForKeyE00("ar", 'ذ', '>');
52 if (PlatformManager.isPlatformUnixoid()) {
53 testgetCharactersForKeyE00("fr_FR", '²', '$', 'œ');
54 testgetCharactersForKeyE00("fr_CA", '#', '$', 'œ', '/');
55 } else {
56 testgetCharactersForKeyE00("fr_FR", '²', '$');
57 testgetCharactersForKeyE00("fr_CA", '#', '$', '/');
58 }
59 testgetCharactersForKeyE00("sq", '\\');
60 testgetCharactersForKeyE00("it", '\\');
61 testgetCharactersForKeyE00("pt", '\\');
62 testgetCharactersForKeyE00("pt_BR", '\'');
63 testgetCharactersForKeyE00("de", deadCircumflex, deadCircumflex2);
64 testgetCharactersForKeyE00("cs", ';');
65 testgetCharactersForKeyE00("he", ';');
66 testgetCharactersForKeyE00("iw", ';');
67 testgetCharactersForKeyE00("hu", '0');
68 testgetCharactersForKeyE00("pl");
69 testgetCharactersForKeyE00("bs", '¸');
70 testgetCharactersForKeyE00("hr", '¸');
71 testgetCharactersForKeyE00("sl", '¸');
72 testgetCharactersForKeyE00("sr", '¸');
73 testgetCharactersForKeyE00("ro", ']');
74 testgetCharactersForKeyE00("da", '½');
75 testgetCharactersForKeyE00("fo", '½');
76 testgetCharactersForKeyE00("nl", '@');
77 testgetCharactersForKeyE00("et", deadCaron, deadCaron2);
78 testgetCharactersForKeyE00("is", '°');
79 testgetCharactersForKeyE00("es", '|');
80 testgetCharactersForKeyE00("es_ES", 'º');
81 testgetCharactersForKeyE00("tr", '"', '*');
82 testgetCharactersForKeyE00("de_LU", deadCircumflex, deadCircumflex2, '²', '§');
83 if (PlatformManager.isPlatformUnixoid()) {
84 testgetCharactersForKeyE00("fr_LU", '$', 'œ', '²', '§');
85 testgetCharactersForKeyE00("fr_CH", '²', '$', 'œ', '§');
86 } else {
87 testgetCharactersForKeyE00("fr_LU", '$', '²', '§');
88 testgetCharactersForKeyE00("fr_CH", '²', '$', '§');
89 }
90 testgetCharactersForKeyE00("de_CH", deadCircumflex, deadCircumflex2, '§');
91 testgetCharactersForKeyE00("de_LI", deadCircumflex, deadCircumflex2, '§');
92 testgetCharactersForKeyE00("fi_FI", '§');
93 testgetCharactersForKeyE00("sv_SE", '§');
94 testgetCharactersForKeyE00("no_NO", '|');
95 testgetCharactersForKeyE00("sv_NO", '|');
96 }
97
98 private static void testgetCharactersForKeyE00(String locale, Character... expected) {
99 if (locale.contains("_")) {
100 String[] l = locale.split("_", -1);
101 testgetCharactersForKeyE00(new Locale(l[0], l[1]), expected);
102 } else {
103 testgetCharactersForKeyE00(new Locale(locale), expected);
104 }
105 }
106
107 private static void testgetCharactersForKeyE00(Locale locale, Character... expected) {
108 List<Character> realExpected = new ArrayList<>(Arrays.asList(expected));
109 // Add characters common to all cases
110 if (PlatformManager.isPlatformOsx()) {
111 realExpected.add('§');
112 }
113 char deadGrave = (char) KeyEvent.VK_DEAD_GRAVE;
114 char deadGrave2 = 0x2CB;
115 realExpected.addAll(Arrays.asList('`', deadGrave, deadGrave2));
116 assertEquals(realExpected, KeyboardUtils.getCharactersForKey('E', 0, locale));
117 }
118}
Note: See TracBrowser for help on using the repository browser.