[PATCH libevdev 6/6] test: add evbit check for uinput devices

Peter Hutterer peter.hutterer at who-t.net
Tue Aug 13 03:39:55 PDT 2013


Compare the original device with the new one, make sure they have the same bits set.

Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
 test/test-uinput.c | 28 ++++++++++++++++++++++++++--
 1 file changed, 26 insertions(+), 2 deletions(-)

diff --git a/test/test-uinput.c b/test/test-uinput.c
index c1ffc3a..449099f 100644
--- a/test/test-uinput.c
+++ b/test/test-uinput.c
@@ -34,10 +34,12 @@
 
 START_TEST(test_uinput_create_device)
 {
-	struct libevdev *dev;
+	struct libevdev *dev, *dev2;
 	struct libevdev_uinput *uidev;
-	int fd;
+	int fd, fd2;
+	unsigned int type, code;
 	int rc;
+	char *devnode;
 
 	dev = libevdev_new();
 	ck_assert(dev != NULL);
@@ -56,9 +58,31 @@ START_TEST(test_uinput_create_device)
 
 	ck_assert_int_eq(libevdev_uinput_get_fd(uidev), fd);
 
+	devnode = uinput_devnode_from_syspath(libevdev_uinput_get_syspath(uidev));
+	ck_assert(devnode != NULL);
+
+	fd2 = open(devnode, O_RDONLY);
+	ck_assert_int_gt(fd2, -1);
+	rc = libevdev_new_from_fd(fd2, &dev2);
+	ck_assert_int_eq(rc, 0);
+
+	for (type = 0; type < EV_MAX; type++) {
+		int max = libevdev_get_event_type_max(type);
+		if (max == -1)
+			continue;
+
+		for (code = 0; code < max; code++) {
+			ck_assert_int_eq(libevdev_has_event_code(dev, type, code),
+					 libevdev_has_event_code(dev2, type, code));
+		}
+	}
+
 	libevdev_free(dev);
+	libevdev_free(dev2);
 	libevdev_uinput_destroy(uidev);
 	close(fd);
+	close(fd2);
+	free(devnode);
 }
 END_TEST
 
-- 
1.8.2.1



More information about the Input-tools mailing list