test: Make sure the sysname of a device is correct
authorPeter Hutterer <peter.hutterer@who-t.net>
Tue, 28 Jan 2014 05:54:34 +0000 (15:54 +1000)
committerPeter Hutterer <peter.hutterer@who-t.net>
Fri, 31 Jan 2014 04:57:18 +0000 (14:57 +1000)
Currently this means start with "event" and don't contain /.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Jonas Ã…dahl <jadahl@gmail.com>
test/path.c
test/udev.c

index 12787f6a4111e657eefb0317b904c49fecc0a445..875cd88ebedecafdcff33bbdb09f4019d1e61f90 100644 (file)
@@ -187,6 +187,28 @@ START_TEST(path_added_device)
 }
 END_TEST
 
+START_TEST(path_device_sysname)
+{
+       struct litest_device *dev = litest_current_device();
+       struct libinput_event *ev;
+       struct libinput_device *device;
+       const char *sysname;
+
+       libinput_dispatch(dev->libinput);
+
+       while ((ev = libinput_get_event(dev->libinput))) {
+               if (libinput_event_get_type(ev) != LIBINPUT_EVENT_DEVICE_ADDED)
+                       continue;
+
+               device = libinput_event_get_device(ev);
+               sysname = libinput_device_get_sysname(device);
+               ck_assert(sysname != NULL && strlen(sysname) > 1);
+               ck_assert(strchr(sysname, '/') == NULL);
+               ck_assert_int_eq(strncmp(sysname, "event", 5), 0);
+       }
+}
+END_TEST
+
 START_TEST(path_suspend)
 {
        struct libinput *li;
@@ -304,6 +326,7 @@ int main (int argc, char **argv) {
        litest_add("path:suspend", path_double_resume, LITEST_ANY, LITEST_ANY);
        litest_add("path:seat events", path_added_seat, LITEST_ANY, LITEST_ANY);
        litest_add("path:device events", path_added_device, LITEST_ANY, LITEST_ANY);
+       litest_add("path:device events", path_device_sysname, LITEST_ANY, LITEST_ANY);
 
        return litest_run(argc, argv);
 }
index f61dd24739d79c41b36ee2623b84008318d07d50..235d10ef3189dc33c502e5c595d52e2933adb90b 100644 (file)
@@ -294,6 +294,39 @@ START_TEST(udev_suspend_resume)
 }
 END_TEST
 
+START_TEST(udev_device_sysname)
+{
+       struct libinput *li;
+       struct libinput_event *ev;
+       struct libinput_device *device;
+       const char *sysname;
+       struct udev *udev;
+
+       udev = udev_new();
+       ck_assert(udev != NULL);
+
+       li = libinput_create_from_udev(&simple_interface, NULL, udev, "seat0");
+       ck_assert(li != NULL);
+
+       libinput_dispatch(li);
+
+       while ((ev = libinput_get_event(li))) {
+               if (libinput_event_get_type(ev) != LIBINPUT_EVENT_DEVICE_ADDED)
+                       continue;
+
+               device = libinput_event_get_device(ev);
+               sysname = libinput_device_get_sysname(device);
+               ck_assert(sysname != NULL && strlen(sysname) > 1);
+               ck_assert(strchr(sysname, '/') == NULL);
+               ck_assert_int_eq(strncmp(sysname, "event", 5), 0);
+               libinput_event_destroy(ev);
+       }
+
+       libinput_destroy(li);
+       udev_unref(udev);
+}
+END_TEST
+
 int main (int argc, char **argv) {
 
        litest_add_no_device("udev:create", udev_create_NULL);
@@ -305,6 +338,7 @@ int main (int argc, char **argv) {
        litest_add("udev:suspend", udev_double_suspend, LITEST_ANY, LITEST_ANY);
        litest_add("udev:suspend", udev_double_resume, LITEST_ANY, LITEST_ANY);
        litest_add("udev:suspend", udev_suspend_resume, LITEST_ANY, LITEST_ANY);
+       litest_add("udev:device events", udev_device_sysname, LITEST_ANY, LITEST_ANY);
 
        return litest_run(argc, argv);
 }