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:
Peter Hutterer 2016-03-03 08:33:22 +10:00
parent a60afbeec3
commit 00a9b05da7

View file

@ -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);