mirror of
https://gitlab.freedesktop.org/libinput/libinput.git
synced 2026-01-06 04:50:12 +01:00
test: add two path tests for invalid devices
One test for an actual file (so far we only tested /tmp, the directory) and one for a kernel dev that returns a udev device and thus gets one step further in the error handling code. Plus, I saw test code doing this (opening /dev/uinput) and it crashed (for other reasons), so we might as well test it. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
parent
a60afbeec3
commit
00a9b05da7
1 changed files with 60 additions and 0 deletions
60
test/path.c
60
test/path.c
|
|
@ -27,6 +27,7 @@
|
|||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <libinput.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "litest.h"
|
||||
|
|
@ -98,6 +99,63 @@ START_TEST(path_create_invalid)
|
|||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST(path_create_invalid_kerneldev)
|
||||
{
|
||||
struct libinput *li;
|
||||
struct libinput_device *device;
|
||||
const char *path = "/dev/uinput";
|
||||
|
||||
open_func_count = 0;
|
||||
close_func_count = 0;
|
||||
|
||||
li = libinput_path_create_context(&simple_interface, NULL);
|
||||
ck_assert(li != NULL);
|
||||
device = libinput_path_add_device(li, path);
|
||||
ck_assert(device == NULL);
|
||||
|
||||
ck_assert_int_eq(open_func_count, 1);
|
||||
ck_assert_int_eq(close_func_count, 1);
|
||||
|
||||
libinput_unref(li);
|
||||
ck_assert_int_eq(close_func_count, 1);
|
||||
|
||||
open_func_count = 0;
|
||||
close_func_count = 0;
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST(path_create_invalid_file)
|
||||
{
|
||||
struct libinput *li;
|
||||
struct libinput_device *device;
|
||||
char path[] = "/tmp/litest_path_XXXXXX";
|
||||
int fd;
|
||||
|
||||
fd = mkstemp(path);
|
||||
ck_assert_int_ge(fd, 0);
|
||||
close(fd);
|
||||
|
||||
open_func_count = 0;
|
||||
close_func_count = 0;
|
||||
|
||||
li = libinput_path_create_context(&simple_interface, NULL);
|
||||
unlink(path);
|
||||
|
||||
ck_assert(li != NULL);
|
||||
device = libinput_path_add_device(li, path);
|
||||
ck_assert(device == NULL);
|
||||
|
||||
ck_assert_int_eq(open_func_count, 0);
|
||||
ck_assert_int_eq(close_func_count, 0);
|
||||
|
||||
libinput_unref(li);
|
||||
ck_assert_int_eq(close_func_count, 0);
|
||||
|
||||
open_func_count = 0;
|
||||
close_func_count = 0;
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST(path_create_destroy)
|
||||
{
|
||||
struct libinput *li;
|
||||
|
|
@ -882,6 +940,8 @@ litest_setup_tests(void)
|
|||
{
|
||||
litest_add_no_device("path:create", path_create_NULL);
|
||||
litest_add_no_device("path:create", path_create_invalid);
|
||||
litest_add_no_device("path:create", path_create_invalid_file);
|
||||
litest_add_no_device("path:create", path_create_invalid_kerneldev);
|
||||
litest_add_no_device("path:create", path_create_destroy);
|
||||
litest_add_no_device("path:create", path_set_user_data);
|
||||
litest_add_no_device("path:suspend", path_suspend);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue