summaryrefslogtreecommitdiffstats
path: root/test/test-draglock.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 13:45:25 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 13:45:25 +0000
commit6419b48ac77919b8a46352634a63698ec477390e (patch)
tree9a29a93fad7139bb44de35b4428393663542121f /test/test-draglock.c
parentInitial commit. (diff)
downloadxserver-xorg-input-libinput-6419b48ac77919b8a46352634a63698ec477390e.tar.xz
xserver-xorg-input-libinput-6419b48ac77919b8a46352634a63698ec477390e.zip
Adding upstream version 0.30.0.upstream/0.30.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'test/test-draglock.c')
-rw-r--r--test/test-draglock.c540
1 files changed, 540 insertions, 0 deletions
diff --git a/test/test-draglock.c b/test/test-draglock.c
new file mode 100644
index 0000000..96ef5bb
--- /dev/null
+++ b/test/test-draglock.c
@@ -0,0 +1,540 @@
+/*
+ * Copyright © 2013-2015 Red Hat, Inc.
+ *
+ * Permission to use, copy, modify, distribute, and sell this software
+ * and its documentation for any purpose is hereby granted without
+ * fee, provided that the above copyright notice appear in all copies
+ * and that both that copyright notice and this permission notice
+ * appear in supporting documentation, and that the name of Red Hat
+ * not be used in advertising or publicity pertaining to distribution
+ * of the software without specific, written prior permission. Red
+ * Hat makes no representations about the suitability of this software
+ * for any purpose. It is provided "as is" without express or implied
+ * warranty.
+ *
+ * THE AUTHORS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
+ * NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
+ * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+ * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include "draglock.h"
+
+#include <assert.h>
+#include <string.h>
+
+static void
+test_config_empty(void)
+{
+ struct draglock dl;
+ int rc;
+
+ rc = draglock_init_from_string(&dl, NULL);
+ assert(dl.mode == DRAGLOCK_DISABLED);
+ assert(rc == 0);
+}
+
+static void
+test_config_invalid(void)
+{
+ struct draglock dl;
+ int rc;
+
+ /* no trailing space */
+ rc = draglock_init_from_string(&dl, "1 ");
+ assert(rc != 0);
+ assert(dl.mode == DRAGLOCK_DISABLED);
+
+ rc = draglock_init_from_string(&dl, "256");
+ assert(rc != 0);
+ assert(dl.mode == DRAGLOCK_DISABLED);
+
+ rc = draglock_init_from_string(&dl, "-1");
+ assert(rc != 0);
+ assert(dl.mode == DRAGLOCK_DISABLED);
+
+ rc = draglock_init_from_string(&dl, "1 2 3");
+ assert(rc != 0);
+ assert(dl.mode == DRAGLOCK_DISABLED);
+
+ rc = draglock_init_from_string(&dl, "0 2");
+ assert(rc != 0);
+ assert(dl.mode == DRAGLOCK_DISABLED);
+
+ rc = draglock_init_from_string(&dl, "0 0");
+ assert(rc != 0);
+ assert(dl.mode == DRAGLOCK_DISABLED);
+}
+
+static void
+test_config_disable(void)
+{
+ struct draglock dl;
+ int rc;
+
+ rc = draglock_init_from_string(&dl, "");
+ assert(rc == 0);
+ assert(dl.mode == DRAGLOCK_DISABLED);
+
+ rc = draglock_init_from_string(&dl, "0");
+ assert(rc == 0);
+ assert(dl.mode == DRAGLOCK_DISABLED);
+}
+
+static void
+test_config_meta_button(void)
+{
+ struct draglock dl;
+ int rc;
+
+ rc = draglock_init_from_string(&dl, "1");
+ assert(rc == 0);
+ assert(dl.mode == DRAGLOCK_META);
+ assert(dl.meta_button == 1);
+
+ rc = draglock_init_from_string(&dl, "2");
+ assert(rc == 0);
+ assert(dl.mode == DRAGLOCK_META);
+ assert(dl.meta_button == 2);
+
+ rc = draglock_init_from_string(&dl, "10");
+ assert(rc == 0);
+ assert(dl.mode == DRAGLOCK_META);
+ assert(dl.meta_button == 10);
+}
+
+static void
+test_config_button_pairs(void)
+{
+ struct draglock dl;
+ int rc;
+
+ rc = draglock_init_from_string(&dl, "1 1");
+ assert(rc == 0);
+ assert(dl.mode == DRAGLOCK_PAIRS);
+
+ rc = draglock_init_from_string(&dl, "1 2 3 4 5 6 7 8");
+ assert(rc == 0);
+ assert(dl.mode == DRAGLOCK_PAIRS);
+
+ rc = draglock_init_from_string(&dl, "1 2 3 4 5 0 7 8");
+ assert(rc == 0);
+ assert(dl.mode == DRAGLOCK_PAIRS);
+
+ /* all disabled */
+ rc = draglock_init_from_string(&dl, "1 0 3 0 5 0 7 0");
+ assert(rc == 0);
+ assert(dl.mode == DRAGLOCK_DISABLED);
+}
+
+static void
+test_config_get(void)
+{
+ struct draglock dl;
+ int rc;
+ const int sz = 32;
+ int map[sz];
+
+ draglock_init_from_string(&dl, "");
+ rc = draglock_get_meta(&dl);
+ assert(rc == 0);
+ rc = draglock_get_pairs(&dl, map, sz);
+ assert(rc == 0);
+
+ draglock_init_from_string(&dl, "8");
+ rc = draglock_get_meta(&dl);
+ assert(rc == 8);
+ rc = draglock_get_pairs(&dl, map, sz);
+ assert(rc == 0);
+
+ draglock_init_from_string(&dl, "1 2 3 4 5 6");
+ rc = draglock_get_meta(&dl);
+ assert(rc == 0);
+ rc = draglock_get_pairs(&dl, map, sz);
+ assert(rc == 5);
+ assert(map[0] == 0);
+ assert(map[1] == 2);
+ assert(map[2] == 0);
+ assert(map[3] == 4);
+ assert(map[4] == 0);
+ assert(map[5] == 6);
+}
+
+static void
+test_set_meta(void)
+{
+ struct draglock dl;
+ int rc;
+
+ draglock_init_from_string(&dl, "");
+
+ rc = draglock_set_meta(&dl, 0);
+ assert(rc == 0);
+ assert(dl.mode == DRAGLOCK_DISABLED);
+
+ rc = draglock_set_meta(&dl, 1);
+ assert(rc == 0);
+ assert(dl.mode == DRAGLOCK_META);
+
+ rc = draglock_set_meta(&dl, -1);
+ assert(rc == 1);
+ rc = draglock_set_meta(&dl, 32);
+ assert(rc == 1);
+}
+
+static void
+test_set_pairs(void)
+{
+ struct draglock dl;
+ int rc;
+ const int sz = 32;
+ int map[sz];
+
+ draglock_init_from_string(&dl, "");
+ memset(map, 0, sizeof(map));
+
+ rc = draglock_set_pairs(&dl, map, sz);
+ assert(rc == 0);
+ assert(dl.mode == DRAGLOCK_DISABLED);
+
+ rc = draglock_set_pairs(&dl, map, 1);
+ assert(rc == 0);
+ assert(dl.mode == DRAGLOCK_DISABLED);
+
+ map[0] = 1;
+ rc = draglock_set_pairs(&dl, map, 1);
+ assert(rc == 1);
+
+ map[0] = 0;
+ map[1] = 2;
+ rc = draglock_set_pairs(&dl, map, sz);
+ assert(rc == 0);
+ assert(dl.mode == DRAGLOCK_PAIRS);
+
+ map[0] = 0;
+ map[1] = 0;
+ map[10] = 8;
+ rc = draglock_set_pairs(&dl, map, sz);
+ assert(rc == 0);
+ assert(dl.mode == DRAGLOCK_PAIRS);
+}
+
+static void
+test_filter_meta_passthrough(void)
+{
+ struct draglock dl;
+ int rc;
+ int button, press;
+ int i;
+
+ rc = draglock_init_from_string(&dl, "10");
+
+ for (i = 0; i < 10; i++) {
+ button = i;
+ press = 1;
+
+ rc = draglock_filter_button(&dl, &button, &press);
+ assert(rc == 0);
+ assert(button == i);
+ assert(press == 1);
+
+ press = 1;
+ rc = draglock_filter_button(&dl, &button, &press);
+ assert(rc == 0);
+ assert(button == i);
+ assert(press == 1);
+ }
+}
+
+static void
+test_filter_meta_click_meta_only(void)
+{
+ struct draglock dl;
+ int rc;
+ int button, press;
+
+ rc = draglock_init_from_string(&dl, "10");
+
+ button = 10;
+ press = 1;
+
+ rc = draglock_filter_button(&dl, &button, &press);
+ assert(rc == 0);
+ assert(button == 0);
+
+ button = 10;
+ press = 0;
+ rc = draglock_filter_button(&dl, &button, &press);
+ assert(rc == 0);
+ assert(button == 0);
+}
+
+static void
+test_filter_meta(void)
+{
+ struct draglock dl;
+ int rc;
+ int button, press;
+ int i;
+
+ rc = draglock_init_from_string(&dl, "10");
+
+ for (i = 1; i < 10; i++) {
+ /* meta down */
+ button = 10;
+ press = 1;
+ rc = draglock_filter_button(&dl, &button, &press);
+ assert(rc == 0);
+ assert(button == 0);
+
+ /* meta up */
+ button = 10;
+ press = 0;
+ rc = draglock_filter_button(&dl, &button, &press);
+ assert(rc == 0);
+ assert(button == 0);
+
+ /* button down -> passthrough */
+ button = i;
+ press = 1;
+ rc = draglock_filter_button(&dl, &button, &press);
+ assert(rc == 0);
+ assert(button == i);
+
+ /* button up -> eaten */
+ button = i;
+ press = 0;
+ rc = draglock_filter_button(&dl, &button, &press);
+ assert(rc == 0);
+ assert(button == 0);
+
+ /* button down -> eaten */
+ button = i;
+ press = 1;
+ rc = draglock_filter_button(&dl, &button, &press);
+ assert(rc == 0);
+ assert(button == 0);
+
+ /* button up -> passthrough */
+ button = i;
+ press = 0;
+ rc = draglock_filter_button(&dl, &button, &press);
+ assert(rc == 0);
+ assert(button == i);
+ assert(press == 0);
+ }
+}
+
+static void
+test_filter_meta_extra_click(void)
+{
+ struct draglock dl;
+ int rc;
+ int button, press;
+ int i;
+
+ rc = draglock_init_from_string(&dl, "10");
+
+ for (i = 1; i < 10; i++) {
+ /* meta down */
+ button = 10;
+ press = 1;
+ rc = draglock_filter_button(&dl, &button, &press);
+ assert(rc == 0);
+ assert(button == 0);
+
+ /* meta up */
+ button = 10;
+ press = 0;
+ rc = draglock_filter_button(&dl, &button, &press);
+ assert(rc == 0);
+ assert(button == 0);
+
+ /* button down -> passthrough */
+ button = i;
+ press = 1;
+ rc = draglock_filter_button(&dl, &button, &press);
+ assert(rc == 0);
+ assert(button == i);
+
+ /* button up -> eaten */
+ button = i;
+ press = 0;
+ rc = draglock_filter_button(&dl, &button, &press);
+ assert(rc == 0);
+ assert(button == 0);
+
+ /* meta down */
+ button = 10;
+ press = 1;
+ rc = draglock_filter_button(&dl, &button, &press);
+ assert(rc == 0);
+ assert(button == 0);
+
+ /* meta up */
+ button = 10;
+ press = 0;
+ rc = draglock_filter_button(&dl, &button, &press);
+ assert(rc == 0);
+ assert(button == 0);
+
+ /* button down -> eaten */
+ button = i;
+ press = 1;
+ rc = draglock_filter_button(&dl, &button, &press);
+ assert(rc == 0);
+ assert(button == 0);
+
+ /* button up -> passthrough */
+ button = i;
+ press = 0;
+ rc = draglock_filter_button(&dl, &button, &press);
+ assert(rc == 0);
+ assert(button == i);
+ assert(press == 0);
+ }
+}
+
+static void
+test_filter_meta_interleaved(void)
+{
+ struct draglock dl;
+ int rc;
+ int button, press;
+ int i;
+
+ rc = draglock_init_from_string(&dl, "10");
+
+ for (i = 1; i < 10; i++) {
+ /* meta down */
+ button = 10;
+ press = 1;
+ rc = draglock_filter_button(&dl, &button, &press);
+ assert(rc == 0);
+ assert(button == 0);
+
+ /* meta up */
+ button = 10;
+ press = 0;
+ rc = draglock_filter_button(&dl, &button, &press);
+ assert(rc == 0);
+ assert(button == 0);
+
+ /* button down -> passthrough */
+ button = i;
+ press = 1;
+ rc = draglock_filter_button(&dl, &button, &press);
+ assert(rc == 0);
+ assert(button == i);
+
+ /* button up -> eaten */
+ button = i;
+ press = 0;
+ rc = draglock_filter_button(&dl, &button, &press);
+ assert(rc == 0);
+ assert(button == 0);
+ }
+
+ for (i = 0; i < 10; i++) {
+ /* button down -> eaten */
+ button = i;
+ press = 1;
+ rc = draglock_filter_button(&dl, &button, &press);
+ assert(rc == 0);
+ assert(button == 0);
+
+ /* button up -> passthrough */
+ button = i;
+ press = 0;
+ rc = draglock_filter_button(&dl, &button, &press);
+ assert(rc == 0);
+ assert(button == i);
+ assert(press == 0);
+ }
+}
+
+static void
+test_filter_pairs(void)
+{
+ struct draglock dl;
+ int rc;
+ int button, press;
+ int i;
+
+ rc = draglock_init_from_string(&dl, "1 11 2 0 3 13 4 0 5 15 6 0 7 17 8 0 9 19");
+
+ for (i = 1; i < 10; i++) {
+ button = i;
+ press = 1;
+
+ rc = draglock_filter_button(&dl, &button, &press);
+ assert(rc == 0);
+ if (i % 2)
+ assert(button == i + 10);
+ else
+ assert(button == i);
+ assert(press == 1);
+
+ button = i;
+ press = 0;
+ rc = draglock_filter_button(&dl, &button, &press);
+ assert(rc == 0);
+ if (i % 2) {
+ assert(button == 0);
+ } else {
+ assert(button == i);
+ assert(press == 0);
+ }
+ }
+
+ for (i = 1; i < 10; i++) {
+ button = i;
+ press = 1;
+
+ rc = draglock_filter_button(&dl, &button, &press);
+ assert(rc == 0);
+ if (i % 2) {
+ assert(button == 0);
+ } else {
+ assert(button == i);
+ assert(press == 1);
+ }
+
+ button = i;
+ press = 0;
+ rc = draglock_filter_button(&dl, &button, &press);
+ assert(rc == 0);
+ if (i % 2)
+ assert(button == i + 10);
+ else
+ assert(button == i);
+ assert(press == 0);
+ }
+}
+
+int
+main(int argc, char **argv)
+{
+ test_config_empty();
+ test_config_invalid();
+ test_config_disable();
+ test_config_meta_button();
+ test_config_button_pairs();
+
+ test_config_get();
+ test_set_meta();
+ test_set_pairs();
+
+ test_filter_meta_passthrough();
+ test_filter_meta_click_meta_only();
+ test_filter_meta();
+ test_filter_meta_extra_click();
+ test_filter_meta_interleaved();
+
+ test_filter_pairs();
+
+ return 0;
+}