[PATCH libevdev 2/2] Add libevdev_new_from_libevdev() tests

David Herrmann dh.herrmann at gmail.com
Mon Nov 4 06:51:19 PST 2013


Add a sub-test to test-libevdev-init.c to test the new copy-constructor
and its semantics.

Signed-off-by: David Herrmann <dh.herrmann at gmail.com>
---
 test/test-libevdev-init.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 66 insertions(+)

diff --git a/test/test-libevdev-init.c b/test/test-libevdev-init.c
index bf0b874..6963b86 100644
--- a/test/test-libevdev-init.c
+++ b/test/test-libevdev-init.c
@@ -48,6 +48,71 @@ START_TEST(test_free_device)
 }
 END_TEST
 
+START_TEST(test_copy_device)
+{
+	struct libevdev *dev, *dev2;
+	unsigned int type, code;
+	int rc;
+
+	dev = libevdev_new();
+	ck_assert(dev != NULL);
+
+	libevdev_set_name(dev, TEST_DEVICE_NAME);
+	libevdev_set_phys(dev, "phys" TEST_DEVICE_NAME);
+	libevdev_set_uniq(dev, "uniq" TEST_DEVICE_NAME);
+	libevdev_set_id_product(dev, 2);
+	libevdev_set_id_vendor(dev, 3);
+	libevdev_set_id_bustype(dev, 4);
+	libevdev_set_id_version(dev, 5);
+	libevdev_enable_property(dev, INPUT_PROP_DIRECT);
+	libevdev_enable_event_type(dev, EV_SYN);
+	libevdev_enable_event_type(dev, EV_REL);
+	libevdev_enable_event_code(dev, EV_REL, REL_X, NULL);
+	libevdev_enable_event_code(dev, EV_REL, REL_Y, NULL);
+	libevdev_enable_event_code(dev, EV_REL, REL_MAX, NULL);
+
+	dev2 = NULL;
+	rc = libevdev_new_from_libevdev(dev, &dev2);
+	ck_assert(rc == 0);
+	ck_assert(dev2 != NULL);
+
+	ck_assert(libevdev_get_fd(dev2) < 0);
+	ck_assert(libevdev_has_event_pending(dev2) == -EBADF);
+
+	ck_assert(libevdev_get_name(dev) != libevdev_get_name(dev2));
+	ck_assert(!strcmp(libevdev_get_name(dev), libevdev_get_name(dev2)));
+	ck_assert(!strcmp(TEST_DEVICE_NAME, libevdev_get_name(dev2)));
+	ck_assert(libevdev_get_phys(dev) != libevdev_get_phys(dev2));
+	ck_assert(!strcmp(libevdev_get_phys(dev), libevdev_get_phys(dev2)));
+	ck_assert(!strcmp("phys" TEST_DEVICE_NAME, libevdev_get_phys(dev2)));
+	ck_assert(libevdev_get_uniq(dev) != libevdev_get_uniq(dev2));
+	ck_assert(!strcmp(libevdev_get_uniq(dev), libevdev_get_uniq(dev2)));
+	ck_assert(!strcmp("uniq" TEST_DEVICE_NAME, libevdev_get_uniq(dev2)));
+
+	ck_assert(libevdev_get_id_product(dev) == libevdev_get_id_product(dev2));
+	ck_assert(libevdev_get_id_vendor(dev) == libevdev_get_id_vendor(dev2));
+	ck_assert(libevdev_get_id_bustype(dev) == libevdev_get_id_bustype(dev2));
+	ck_assert(libevdev_get_id_version(dev) == libevdev_get_id_version(dev2));
+	ck_assert(libevdev_get_driver_version(dev) == libevdev_get_driver_version(dev2));
+
+	ck_assert(libevdev_has_property(dev, INPUT_PROP_DIRECT));
+
+	for (type = 0; type < EV_CNT; type++) {
+		int max = libevdev_event_type_get_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(dev2);
+	libevdev_free(dev);
+}
+END_TEST
+
 START_TEST(test_init_from_invalid_fd)
 {
 	int rc;
@@ -374,6 +439,7 @@ libevdev_init_test(void)
 	TCase *tc = tcase_create("device init");
 	tcase_add_test(tc, test_new_device);
 	tcase_add_test(tc, test_free_device);
+	tcase_add_test(tc, test_copy_device);
 	tcase_add_test(tc, test_init_from_invalid_fd);
 	tcase_add_test(tc, test_init_and_change_fd);
 	suite_add_tcase(s, tc);
-- 
1.8.4.2



More information about the Input-tools mailing list