2 #include <winpr/crypto.h>
3 #include <freerdp/locale/keyboard.h>
5 static BOOL test_scancode_name(
void)
7 const DWORD scancodes[] = { RDP_SCANCODE_ESCAPE,
18 RDP_SCANCODE_OEM_MINUS,
19 RDP_SCANCODE_OEM_PLUS,
20 RDP_SCANCODE_BACKSPACE,
35 RDP_SCANCODE_LCONTROL,
57 RDP_SCANCODE_OEM_COMMA,
58 RDP_SCANCODE_OEM_PERIOD,
61 RDP_SCANCODE_MULTIPLY,
64 RDP_SCANCODE_CAPSLOCK,
76 RDP_SCANCODE_SCROLLLOCK,
80 RDP_SCANCODE_SUBTRACT,
109 RDP_SCANCODE_HIRAGANA,
110 RDP_SCANCODE_HANJA_KANJI,
111 RDP_SCANCODE_KANA_HANGUL,
112 RDP_SCANCODE_ABNT_C1,
114 RDP_SCANCODE_CONVERT_JP,
115 RDP_SCANCODE_NONCONVERT_JP,
117 RDP_SCANCODE_BACKSLASH_JP,
118 RDP_SCANCODE_ABNT_C2,
121 RDP_SCANCODE_RETURN_KP,
122 RDP_SCANCODE_RCONTROL,
124 RDP_SCANCODE_PRINTSCREEN,
142 RDP_SCANCODE_POWER_JP,
143 RDP_SCANCODE_SLEEP_JP,
144 RDP_SCANCODE_NUMLOCK_EXTENDED,
145 RDP_SCANCODE_RSHIFT_EXTENDED,
146 RDP_SCANCODE_VOLUME_MUTE,
147 RDP_SCANCODE_VOLUME_DOWN,
148 RDP_SCANCODE_VOLUME_UP,
149 RDP_SCANCODE_MEDIA_NEXT_TRACK,
150 RDP_SCANCODE_MEDIA_PREV_TRACK,
151 RDP_SCANCODE_MEDIA_STOP,
152 RDP_SCANCODE_MEDIA_PLAY_PAUSE,
153 RDP_SCANCODE_BROWSER_BACK,
154 RDP_SCANCODE_BROWSER_FORWARD,
155 RDP_SCANCODE_BROWSER_REFRESH,
156 RDP_SCANCODE_BROWSER_STOP,
157 RDP_SCANCODE_BROWSER_SEARCH,
158 RDP_SCANCODE_BROWSER_FAVORITES,
159 RDP_SCANCODE_BROWSER_HOME,
160 RDP_SCANCODE_LAUNCH_MAIL,
161 RDP_SCANCODE_LAUNCH_MEDIA_SELECT,
162 RDP_SCANCODE_LAUNCH_APP1,
163 RDP_SCANCODE_LAUNCH_APP2 };
164 for (
size_t x = 0; x < ARRAYSIZE(scancodes); x++)
166 const DWORD code = scancodes[x];
167 const char* sc = freerdp_keyboard_scancode_name(code);
170 (void)fprintf(stderr,
"Failed to run freerdp_keyboard_scancode_name(%" PRIu32
")\n",
179 static BOOL test_layouts(DWORD types)
184 if (!layouts || (count == 0))
186 (void)fprintf(stderr,
187 "freerdp_keyboard_get_layouts(type: %" PRIu32
") -> %" PRIuz
188 " elements, layouts: %p:\n",
189 types, count, layouts);
193 for (
size_t x = 0; x < count; x++)
196 if ((cur->code == 0) || (!cur->name) || (strnlen(cur->name, 2) == 0))
198 (void)fprintf(stderr,
199 "freerdp_keyboard_get_layouts(type: %" PRIu32
") -> %" PRIuz
200 " elements, failed:\n",
202 (void)fprintf(stderr,
"[%" PRIuz
"]: code= %" PRIu32
", name = %s\n", x, cur->code,
207 const char* name = freerdp_keyboard_get_layout_name_from_id(cur->code);
210 (void)fprintf(stderr,
211 "freerdp_keyboard_get_layouts(type: %" PRIu32
") -> %" PRIuz
212 " elements, failed:\n",
214 (void)fprintf(stderr,
215 "[%" PRIuz
"]: freerdp_keyboard_get_layouts(%" PRIu32
") -> NULL\n", x,
220 if (strcmp(name, cur->name) != 0) {
221 (void)fprintf(stderr,
"freerdp_keyboard_get_layouts(type: %" PRIu32
") -> %" PRIuz
" elements, failed:\n", types, count);
222 (void)fprintf(stderr,
"[%" PRIuz
"]: freerdp_keyboard_get_layouts(%" PRIu32
") -> %s != %s\n", x, cur->code, name, cur->name);
227 const DWORD
id = freerdp_keyboard_get_layout_id_from_name(cur->name);
231 (void)fprintf(stderr,
232 "freerdp_keyboard_get_layouts(type: %" PRIu32
") -> %" PRIuz
233 " elements, failed:\n",
235 (void)fprintf(stderr,
236 "[%" PRIuz
"]: freerdp_keyboard_get_layout_id_from_name(%s) -> %" PRIu32
238 x, cur->name,
id, cur->code);
245 freerdp_keyboard_layouts_free(layouts, count);
249 static DWORD get_random(DWORD offset)
252 winpr_RAND(&x,
sizeof(x));
253 x = x % UINT32_MAX - offset;
258 static BOOL test_scancode_cnv(
void)
260 for (DWORD x = 0; x < UINT8_MAX; x++)
262 const DWORD sc = freerdp_keyboard_get_rdp_scancode_from_x11_keycode(x);
263 const BOOL ex = RDP_SCANCODE_EXTENDED(sc);
264 const DWORD kk = freerdp_keyboard_get_x11_keycode_from_rdp_scancode(sc, ex);
267 (void)fprintf(stderr,
268 "[%" PRIu32
"]: keycode->scancode->keycode failed: %" PRIu32
269 " -> %" PRIu32
" -> %" PRIu32
"\n",
275 for (DWORD x = 0; x < 23; x++)
277 DWORD x = get_random(UINT8_MAX);
279 const DWORD sc = freerdp_keyboard_get_rdp_scancode_from_x11_keycode(x);
280 const DWORD kk = freerdp_keyboard_get_x11_keycode_from_rdp_scancode(sc, FALSE);
281 const DWORD kkex = freerdp_keyboard_get_x11_keycode_from_rdp_scancode(sc, TRUE);
282 if ((sc != 0) || (kk != 0) || (kkex != 0))
284 (void)fprintf(stderr,
285 "[%" PRIu32
"]: invalid scancode %" PRIu32
", keycode %" PRIu32
286 " or keycode extended %" PRIu32
" has a value != 0\n",
294 static BOOL test_codepages(
void)
297 for (DWORD column = 0; column < 4; column++)
300 RDP_CODEPAGE* cp = freerdp_keyboard_get_matching_codepages(column, NULL, &count);
301 if (!cp || (count == 0))
303 (void)fprintf(stderr,
304 "freerdp_keyboard_get_matching_codepages(%" PRIu32
", NULL) failed!\n",
308 freerdp_codepages_free(cp);
311 for (DWORD x = 0; x < 23; x++)
313 DWORD column = get_random(4);
315 RDP_CODEPAGE* cp = freerdp_keyboard_get_matching_codepages(column, NULL, &count);
316 freerdp_codepages_free(cp);
317 if (cp || (count != 0))
319 (void)fprintf(stderr,
320 "freerdp_keyboard_get_matching_codepages(%" PRIu32
321 ", NULL) returned not NULL!\n",
333 static BOOL test_init(
void)
335 const DWORD kbd = freerdp_keyboard_init(0);
338 (void)fprintf(stderr,
"freerdp_keyboard_init(0) returned invalid layout 0\n");
342 const DWORD kbdex = freerdp_keyboard_init_ex(0, NULL);
345 (void)fprintf(stderr,
"freerdp_keyboard_init_ex(0, NULL) returned invalid layout 0\n");
353 "freerdp_keyboard_init(0) != freerdp_keyboard_init_ex(0, NULL): returned %" PRIu32
365 int TestLocaleKeyboard(
int argc,
char* argv[])
370 if (!test_scancode_name())
373 if (!test_layouts(RDP_KEYBOARD_LAYOUT_TYPE_STANDARD))
375 if (!test_layouts(RDP_KEYBOARD_LAYOUT_TYPE_VARIANT))
377 if (!test_layouts(RDP_KEYBOARD_LAYOUT_TYPE_IME))
379 if (!test_layouts(RDP_KEYBOARD_LAYOUT_TYPE_STANDARD | RDP_KEYBOARD_LAYOUT_TYPE_VARIANT))
381 if (!test_layouts(RDP_KEYBOARD_LAYOUT_TYPE_STANDARD | RDP_KEYBOARD_LAYOUT_TYPE_IME))
383 if (!test_layouts(RDP_KEYBOARD_LAYOUT_TYPE_VARIANT | RDP_KEYBOARD_LAYOUT_TYPE_IME))
385 if (!test_layouts(RDP_KEYBOARD_LAYOUT_TYPE_STANDARD | RDP_KEYBOARD_LAYOUT_TYPE_VARIANT |
386 RDP_KEYBOARD_LAYOUT_TYPE_IME))
388 if (test_layouts(UINT32_MAX &
389 ~(RDP_KEYBOARD_LAYOUT_TYPE_STANDARD | RDP_KEYBOARD_LAYOUT_TYPE_VARIANT |
390 RDP_KEYBOARD_LAYOUT_TYPE_IME)))
392 if (!test_scancode_cnv())
394 if (!test_codepages())