Add module test for scancode index conversions
This commit is contained in:
parent
c91ef80ca9
commit
43d6db45ed
@ -7,6 +7,40 @@
|
||||
|
||||
#include "test_common.h"
|
||||
|
||||
// Max supported scancode value
|
||||
#define MAX_SUPPORTED_SCANCODE 0x1ff
|
||||
|
||||
// Checks conversions to-and-from scancode indexes
|
||||
START_TEST(test_scancode__scancode_to_index)
|
||||
{
|
||||
int i;
|
||||
// In the range 0x00 - 0x7f, scancodes are the same as indexes
|
||||
for (i = 0x0; i <= 0x7f; ++i)
|
||||
{
|
||||
ck_assert_int_eq(scancode_to_index(i), i);
|
||||
ck_assert_int_eq(scancode_from_index(i), i);
|
||||
}
|
||||
|
||||
// Scancodes from 0x80 - 0xff are not supported
|
||||
for (i = 0x80; i <= 0xff; ++i)
|
||||
{
|
||||
ck_assert_int_eq(scancode_to_index(i), -1);
|
||||
}
|
||||
|
||||
// 0x100 - 0x17f map to 0x80 - 0xff
|
||||
for (i = 0x100; i <= 0x17f; ++i)
|
||||
{
|
||||
ck_assert_int_eq(scancode_to_index(i), i - 0x80);
|
||||
ck_assert_int_eq(scancode_from_index(i - 0x80), i);
|
||||
}
|
||||
|
||||
// Scancodes from 0x180 - MAX_SUPPORTED_SCANCODE are not supported
|
||||
for (i = 0x180; i <= MAX_SUPPORTED_SCANCODE; ++i)
|
||||
{
|
||||
ck_assert_int_eq(scancode_to_index(i), -1);
|
||||
}
|
||||
}
|
||||
|
||||
// Checks all returned evdev scancodes are mapped to a keycode
|
||||
START_TEST(test_scancode__keycode_sets)
|
||||
{
|
||||
@ -31,6 +65,8 @@ START_TEST(test_scancode__evdev_all_values_returned)
|
||||
iter = 0;
|
||||
while ((scancode = scancode_get_next(&iter)) != 0)
|
||||
{
|
||||
ck_assert_int_ge(scancode, 0);
|
||||
ck_assert_int_le(scancode, MAX_SUPPORTED_SCANCODE);
|
||||
unsigned short keycode = scancode_to_x11_keycode(scancode);
|
||||
ck_assert_int_ne(keycode, 0);
|
||||
}
|
||||
@ -40,8 +76,8 @@ END_TEST
|
||||
// Checks all invalid evdev scancodes return 0
|
||||
START_TEST(test_scancode__evdev_bad_values_mapped_to_0)
|
||||
{
|
||||
// Store valid scancodes which are between 0 and 0x1ff
|
||||
int valid[512] = {0};
|
||||
// Store valid scancodes which are between 0 and MAX_SUPPORTED_SCANCODE
|
||||
char valid[MAX_SUPPORTED_SCANCODE + 1] = {0};
|
||||
unsigned int iter;
|
||||
unsigned int scancode;
|
||||
|
||||
@ -50,10 +86,12 @@ START_TEST(test_scancode__evdev_bad_values_mapped_to_0)
|
||||
iter = 0;
|
||||
while ((scancode = scancode_get_next(&iter)) != 0)
|
||||
{
|
||||
ck_assert_int_ge(scancode, 0);
|
||||
ck_assert_int_le(scancode, MAX_SUPPORTED_SCANCODE);
|
||||
valid[scancode] = 1;
|
||||
}
|
||||
|
||||
for (scancode = 0 ; scancode < 512; ++scancode)
|
||||
for (scancode = 0 ; scancode <= MAX_SUPPORTED_SCANCODE; ++scancode)
|
||||
{
|
||||
if (!valid[scancode])
|
||||
{
|
||||
@ -74,6 +112,8 @@ START_TEST(test_scancode__base_all_values_returned)
|
||||
iter = 0;
|
||||
while ((scancode = scancode_get_next(&iter)) != 0)
|
||||
{
|
||||
ck_assert_int_ge(scancode, 0);
|
||||
ck_assert_int_le(scancode, MAX_SUPPORTED_SCANCODE);
|
||||
unsigned short keycode = scancode_to_x11_keycode(scancode);
|
||||
ck_assert_int_ne(keycode, 0);
|
||||
}
|
||||
@ -83,8 +123,8 @@ END_TEST
|
||||
// Checks all invalid base scancodes return 0
|
||||
START_TEST(test_scancode__base_bad_values_mapped_to_0)
|
||||
{
|
||||
// Store valid scancodes which are between 0 and 0x1ff
|
||||
int valid[512] = {0};
|
||||
// Store valid scancodes which are between 0 and MAX_SUPPORTED_SCANCODE
|
||||
char valid[MAX_SUPPORTED_SCANCODE + 1] = {0};
|
||||
unsigned int iter;
|
||||
unsigned int scancode;
|
||||
|
||||
@ -93,10 +133,12 @@ START_TEST(test_scancode__base_bad_values_mapped_to_0)
|
||||
iter = 0;
|
||||
while ((scancode = scancode_get_next(&iter)) != 0)
|
||||
{
|
||||
ck_assert_int_ge(scancode, 0);
|
||||
ck_assert_int_le(scancode, MAX_SUPPORTED_SCANCODE);
|
||||
valid[scancode] = 1;
|
||||
}
|
||||
|
||||
for (scancode = 0 ; scancode < 512; ++scancode)
|
||||
for (scancode = 0 ; scancode <= MAX_SUPPORTED_SCANCODE; ++scancode)
|
||||
{
|
||||
if (!valid[scancode])
|
||||
{
|
||||
@ -118,6 +160,7 @@ make_suite_test_scancode(void)
|
||||
|
||||
tc = tcase_create("scancode");
|
||||
suite_add_tcase(s, tc);
|
||||
tcase_add_test(tc, test_scancode__scancode_to_index);
|
||||
tcase_add_test(tc, test_scancode__keycode_sets);
|
||||
tcase_add_test(tc, test_scancode__evdev_all_values_returned);
|
||||
tcase_add_test(tc, test_scancode__evdev_bad_values_mapped_to_0);
|
||||
|
Loading…
Reference in New Issue
Block a user