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