[PATCH libinput 7/7] test: add pad mode group tests

Peter Hutterer peter.hutterer at who-t.net
Mon Jun 6 06:50:44 UTC 2016


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

diff --git a/test/pad.c b/test/pad.c
index 63bd2d7..9dea0fe 100644
--- a/test/pad.c
+++ b/test/pad.c
@@ -407,6 +407,164 @@ START_TEST(pad_left_handed_ring)
 }
 END_TEST
 
+START_TEST(pad_mode_groups)
+{
+	struct litest_device *dev = litest_current_device();
+	struct libinput_device *device = dev->libinput_device;
+	struct libinput_tablet_pad_mode_group* group;
+	int ngroups;
+
+	ngroups = libinput_device_tablet_pad_get_num_mode_groups(device);
+	ck_assert_int_ge(ngroups, 1);
+
+	group = libinput_device_tablet_pad_get_mode_group(device, 0);
+	ck_assert_notnull(group);
+	ck_assert_int_eq(libinput_tablet_pad_mode_group_get_index(group),
+			 0);
+
+	group = libinput_device_tablet_pad_get_mode_group(device, ngroups);
+	ck_assert(group == NULL);
+	group = libinput_device_tablet_pad_get_mode_group(device, ngroups + 1);
+	ck_assert(group == NULL);
+}
+END_TEST
+
+START_TEST(pad_mode_group_mode)
+{
+	struct litest_device *dev = litest_current_device();
+	struct libinput_device *device = dev->libinput_device;
+	struct libinput_tablet_pad_mode_group* group;
+	int ngroups;
+	unsigned int nmodes, mode;
+
+	ngroups = libinput_device_tablet_pad_get_num_mode_groups(device);
+	ck_assert_int_ge(ngroups, 1);
+
+	group = libinput_device_tablet_pad_get_mode_group(device, 0);
+
+	nmodes = libinput_tablet_pad_mode_group_get_num_modes(group);
+	ck_assert_int_ge(nmodes, 1);
+	mode = libinput_tablet_pad_mode_group_get_mode(group);
+	ck_assert_int_lt(mode, nmodes);
+}
+END_TEST
+
+START_TEST(pad_mode_group_has)
+{
+	struct litest_device *dev = litest_current_device();
+	struct libinput_device *device = dev->libinput_device;
+	struct libinput_tablet_pad_mode_group* group;
+	int ngroups, nbuttons, nrings, nstrips;
+	int i, b, r, s;
+
+	ngroups = libinput_device_tablet_pad_get_num_mode_groups(device);
+	ck_assert_int_ge(ngroups, 1);
+
+	nbuttons = libinput_device_tablet_pad_get_num_buttons(device);
+	nrings = libinput_device_tablet_pad_get_num_rings(device);
+	nstrips = libinput_device_tablet_pad_get_num_strips(device);
+
+	for (b = 0; b < nbuttons; b++) {
+		bool found = false;
+		for (i = 0; i < ngroups; i++) {
+			group = libinput_device_tablet_pad_get_mode_group(device,
+									  i);
+			if (libinput_tablet_pad_mode_group_has_button(group,
+								      b)) {
+				ck_assert(!found);
+				found = true;
+			}
+		}
+		ck_assert(found);
+	}
+
+	for (s = 0; s < nstrips; s++) {
+		bool found = false;
+		for (i = 0; i < ngroups; i++) {
+			group = libinput_device_tablet_pad_get_mode_group(device,
+									  i);
+			if (libinput_tablet_pad_mode_group_has_strip(group,
+								     s)) {
+				ck_assert(!found);
+				found = true;
+			}
+		}
+		ck_assert(found);
+	}
+
+	for (r = 0; r < nrings; r++) {
+		bool found = false;
+		for (i = 0; i < ngroups; i++) {
+			group = libinput_device_tablet_pad_get_mode_group(device,
+									  i);
+			if (libinput_tablet_pad_mode_group_has_ring(group,
+								    r)) {
+				ck_assert(!found);
+				found = true;
+			}
+		}
+		ck_assert(found);
+	}
+}
+END_TEST
+
+START_TEST(pad_mode_group_has_invalid)
+{
+	struct litest_device *dev = litest_current_device();
+	struct libinput_device *device = dev->libinput_device;
+	struct libinput_tablet_pad_mode_group* group;
+	int ngroups, nbuttons, nrings, nstrips;
+	int i;
+	int rc;
+
+	ngroups = libinput_device_tablet_pad_get_num_mode_groups(device);
+	ck_assert_int_ge(ngroups, 1);
+
+	nbuttons = libinput_device_tablet_pad_get_num_buttons(device);
+	nrings = libinput_device_tablet_pad_get_num_rings(device);
+	nstrips = libinput_device_tablet_pad_get_num_strips(device);
+
+	for (i = 0; i < ngroups; i++) {
+		group = libinput_device_tablet_pad_get_mode_group(device, i);
+		rc = libinput_tablet_pad_mode_group_has_button(group,
+							       nbuttons);
+		ck_assert_int_eq(rc, 0);
+		rc = libinput_tablet_pad_mode_group_has_button(group,
+							       nbuttons + 1);
+		ck_assert_int_eq(rc, 0);
+		rc = libinput_tablet_pad_mode_group_has_button(group,
+							       0x1000000);
+		ck_assert_int_eq(rc, 0);
+	}
+
+	for (i = 0; i < ngroups; i++) {
+		group = libinput_device_tablet_pad_get_mode_group(device, i);
+		rc = libinput_tablet_pad_mode_group_has_strip(group,
+							      nstrips);
+		ck_assert_int_eq(rc, 0);
+		rc = libinput_tablet_pad_mode_group_has_strip(group,
+							       nstrips + 1);
+		ck_assert_int_eq(rc, 0);
+		rc = libinput_tablet_pad_mode_group_has_strip(group,
+							       0x1000000);
+		ck_assert_int_eq(rc, 0);
+	}
+
+	for (i = 0; i < ngroups; i++) {
+		group = libinput_device_tablet_pad_get_mode_group(device, i);
+		rc = libinput_tablet_pad_mode_group_has_ring(group,
+							     nrings);
+		ck_assert_int_eq(rc, 0);
+		rc = libinput_tablet_pad_mode_group_has_ring(group,
+							     nrings + 1);
+		ck_assert_int_eq(rc, 0);
+		rc = libinput_tablet_pad_mode_group_has_ring(group,
+							     0x1000000);
+		ck_assert_int_eq(rc, 0);
+	}
+}
+END_TEST
+
 void
 litest_setup_tests(void)
 {
@@ -428,4 +586,9 @@ litest_setup_tests(void)
 	litest_add_for_device("pad:left_handed", pad_no_left_handed, LITEST_WACOM_INTUOS3_PAD);
 	litest_add_for_device("pad:left_handed", pad_left_handed_ring, LITEST_WACOM_INTUOS5_PAD);
 	/* None of the current strip tablets are left-handed */
+
+	litest_add("pad:modes", pad_mode_groups, LITEST_TABLET_PAD, LITEST_ANY);
+	litest_add("pad:modes", pad_mode_group_mode, LITEST_TABLET_PAD, LITEST_ANY);
+	litest_add("pad:modes", pad_mode_group_has, LITEST_TABLET_PAD, LITEST_ANY);
+	litest_add("pad:modes", pad_mode_group_has_invalid, LITEST_TABLET_PAD, LITEST_ANY);
 }
-- 
2.7.4



More information about the wayland-devel mailing list