From 43ea7c79785e4ea3518b2d122b6e47891ab478d9 Mon Sep 17 00:00:00 2001 From: nsensfel Date: Tue, 7 Jan 2020 17:30:40 +0100 Subject: Adds compatibility test. --- src/compatibility_test.c | 93 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 src/compatibility_test.c (limited to 'src/compatibility_test.c') diff --git a/src/compatibility_test.c b/src/compatibility_test.c new file mode 100644 index 0000000..1741e07 --- /dev/null +++ b/src/compatibility_test.c @@ -0,0 +1,93 @@ +/**** POSIX *******************************************************************/ +#include + +/**** LIBEVDEV ****************************************************************/ +#include + +/**** RELABSD *****************************************************************/ +#include + +#include + +#include +#include + +/******************************************************************************/ +/**** LOCAL FUNCTIONS *********************************************************/ +/******************************************************************************/ +static int test_for_axis_and_print_info +( + const struct libevdev * const restrict libevdev +) +{ + int i, device_has_rel; + unsigned int rel_code; + + device_has_rel = 0; + + for (i = 0; i < RELABSD_AXIS_VALID_AXES_COUNT; ++i) + { + rel_code = relabsd_axis_name_to_evdev_rel((enum relabsd_axis_name) i); + + if (libevdev_has_event_code(libevdev, EV_REL, rel_code)) + { + printf + ( + "Relative axis: %s\n", + relabsd_axis_name_to_string((enum relabsd_axis_name) i) + ); + + device_has_rel = 1; + } + } + + return device_has_rel; +} + +/******************************************************************************/ +/**** EXPORTED FUNCTIONS ******************************************************/ +/******************************************************************************/ +int relabsd_compatibility_test_main +( + const int argc, + const char * const argv [const static argc], + struct relabsd_parameters parameters [const restrict static 1] +) +{ + struct relabsd_physical_device device; + int is_compatible; + struct libevdev * libevdev; + + if (relabsd_parameters_parse_options(argc, argv, parameters) < 0) + { + return -1; + } + + if + ( + relabsd_physical_device_open + ( + relabsd_parameters_get_physical_device_file_name(parameters), + &device + ) + < 0 + ) + { + return -1; + } + + libevdev = relabsd_physical_device_get_libevdev(&device); + is_compatible = test_for_axis_and_print_info (libevdev); + + if (!is_compatible) + { + return 0; + } + + if (relabsd_parameters_are_compatible_with(libevdev, parameters)) + { + return 2; + } + + return 1; +} -- cgit v1.2.3-70-g09d2