Signed-off-by: Jonas Ådahl <[email protected]>
---
 COPYING          |   2 +-
 test/Makefile.am |  14 ++++++-
 test/keyboard.c  | 117 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 test/litest.c    |   6 +++
 test/litest.h    |   3 ++
 test/pointer.c   |  85 ++++++++++++++++++++++++++++++++++++++++
 6 files changed, 225 insertions(+), 2 deletions(-)
 create mode 100644 test/keyboard.c

diff --git a/COPYING b/COPYING
index 67329c5..8bbb3c3 100644
--- a/COPYING
+++ b/COPYING
@@ -2,7 +2,7 @@ Copyright © 2008-2012 Kristian Høgsberg
 Copyright © 2010-2012 Intel Corporation
 Copyright © 2010-2011 Benjamin Franzke
 Copyright © 2011-2012 Collabora, Ltd.
-Copyright © 2013 Jonas Ådahl
+Copyright © 2013-2014 Jonas Ådahl
 Copyright © 2013-2014 Red Hat, Inc.
 
 Permission to use, copy, modify, distribute, and sell this software and its
diff --git a/test/Makefile.am b/test/Makefile.am
index 1a628de..533280a 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -18,7 +18,14 @@ liblitest_la_SOURCES = \
        litest-wacom-touch.c \
        litest.c
 
-run_tests = test-udev test-path test-pointer test-touch test-log test-touchpad
+run_tests = \
+       test-udev \
+       test-path \
+       test-pointer \
+       test-touch \
+       test-log \
+       test-touchpad \
+       test-keyboard
 build_tests = \
        test-build-cxx \
        test-build-linker \
@@ -58,6 +65,11 @@ test_touchpad_CFLAGS = $(AM_CPPFLAGS)
 test_touchpad_LDADD = $(TEST_LIBS)
 test_touchpad_LDFLAGS = -static
 
+test_keyboard_SOURCES = keyboard.c
+test_keyboard_CFLAGS = $(AM_CPPFLAGS)
+test_keyboard_LDADD = $(TEST_LIBS)
+test_keyboard_LDFLAGS = -static
+
 # build-test only
 test_build_pedantic_c99_SOURCES = build-pedantic.c
 test_build_pedantic_c99_CFLAGS = $(TEST_CFLAGS) -std=c99 -pedantic -Werror
diff --git a/test/keyboard.c b/test/keyboard.c
new file mode 100644
index 0000000..f813067
--- /dev/null
+++ b/test/keyboard.c
@@ -0,0 +1,117 @@
+/*
+ * Copyright © 2014 Jonas Ådahl <[email protected]>
+ *
+ * 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 the copyright holders not be used in
+ * advertising or publicity pertaining to distribution of the software
+ * without specific, written prior permission.  The copyright holders make
+ * no representations about the suitability of this software for any
+ * purpose.  It is provided "as is" without express or implied warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
+ * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS 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 "config.h"
+
+#include <check.h>
+#include <stdio.h>
+
+#include "litest.h"
+
+START_TEST(keyboard_seat_key_count)
+{
+       const int num_devices = 4;
+       struct litest_device *devices[num_devices];
+       struct libinput *libinput;
+       struct libinput_event *ev;
+       struct libinput_event_keyboard *kev;
+       int i;
+       int seat_key_count;
+       int expected_key_button_count = 0;
+       char device_name[255];
+
+       libinput = litest_create_context();
+       for (i = 0; i < num_devices; ++i) {
+               sprintf(device_name, "Generic keyboard (%d)", i);
+               devices[i] = litest_add_device_with_overrides(libinput,
+                                                             LITEST_KEYBOARD,
+                                                             device_name,
+                                                             NULL, NULL, NULL);
+       }
+
+       for (i = 0; i < num_devices; ++i)
+               litest_keyboard_key(devices[i], KEY_A, true);
+
+       libinput_dispatch(libinput);
+       while ((ev = libinput_get_event(libinput))) {
+               if (libinput_event_get_type(ev) !=
+                   LIBINPUT_EVENT_KEYBOARD_KEY) {
+                       libinput_dispatch(libinput);
+                       continue;
+               }
+
+               kev = libinput_event_get_keyboard_event(ev);
+               ck_assert_notnull(kev);
+               ck_assert_int_eq(libinput_event_keyboard_get_key(kev), KEY_A);
+               ck_assert_int_eq(libinput_event_keyboard_get_key_state(kev),
+                                LIBINPUT_KEYBOARD_KEY_STATE_PRESSED);
+
+               ++expected_key_button_count;
+               seat_key_count =
+                       libinput_event_keyboard_get_seat_key_count(kev);
+               ck_assert_int_eq(expected_key_button_count, seat_key_count);
+
+               libinput_dispatch(libinput);
+       }
+
+       ck_assert_int_eq(seat_key_count, num_devices);
+
+       for (i = 0; i < num_devices; ++i)
+               litest_keyboard_key(devices[i], KEY_A, false);
+
+       libinput_dispatch(libinput);
+       while ((ev = libinput_get_event(libinput))) {
+               if (libinput_event_get_type(ev) !=
+                   LIBINPUT_EVENT_KEYBOARD_KEY) {
+                       libinput_dispatch(libinput);
+                       continue;
+               }
+
+               kev = libinput_event_get_keyboard_event(ev);
+               ck_assert_notnull(kev);
+               ck_assert_int_eq(libinput_event_keyboard_get_key(kev), KEY_A);
+               ck_assert_int_eq(libinput_event_keyboard_get_key_state(kev),
+                                LIBINPUT_KEYBOARD_KEY_STATE_RELEASED);
+
+               --expected_key_button_count;
+               seat_key_count =
+                       libinput_event_keyboard_get_seat_key_count(kev);
+               ck_assert_int_eq(expected_key_button_count, seat_key_count);
+
+               libinput_dispatch(libinput);
+       }
+
+       ck_assert_int_eq(seat_key_count, 0);
+
+       for (i = 0; i < num_devices; ++i)
+               litest_delete_device(devices[i]);
+       libinput_destroy(libinput);
+}
+END_TEST
+
+int
+main(int argc, char **argv)
+{
+       litest_add_no_device("keyboard:seat key count", 
keyboard_seat_key_count);
+
+       return litest_run(argc, argv);
+}
diff --git a/test/litest.c b/test/litest.c
index f329312..fd1e053 100644
--- a/test/litest.c
+++ b/test/litest.c
@@ -683,6 +683,12 @@ litest_button_click(struct litest_device *d, unsigned int 
button, bool is_press)
                litest_event(d, ev->type, ev->code, ev->value);
 }
 
+void
+litest_keyboard_key(struct litest_device *d, unsigned int key, bool is_press)
+{
+       litest_button_click(d, key, is_press);
+}
+
 int litest_scale(const struct litest_device *d, unsigned int axis, int val)
 {
        int min, max;
diff --git a/test/litest.h b/test/litest.h
index 1533287..cb4478d 100644
--- a/test/litest.h
+++ b/test/litest.h
@@ -120,6 +120,9 @@ void litest_touch_move_to(struct litest_device *d,
 void litest_button_click(struct litest_device *d,
                         unsigned int button,
                         bool is_press);
+void litest_keyboard_key(struct litest_device *d,
+                        unsigned int key,
+                        bool is_press);
 void litest_drain_events(struct libinput *li);
 
 struct libevdev_uinput * litest_create_uinput_device(const char *name,
diff --git a/test/pointer.c b/test/pointer.c
index 59fe818..b172c2a 100644
--- a/test/pointer.c
+++ b/test/pointer.c
@@ -22,6 +22,7 @@
 
 #include <config.h>
 
+#include <stdio.h>
 #include <check.h>
 #include <errno.h>
 #include <fcntl.h>
@@ -183,11 +184,95 @@ START_TEST(pointer_scroll_wheel)
 }
 END_TEST
 
+START_TEST(pointer_seat_button_count)
+{
+       const int num_devices = 4;
+       struct litest_device *devices[num_devices];
+       struct libinput *libinput;
+       struct libinput_event *ev;
+       struct libinput_event_pointer *tev;
+       int i;
+       int seat_button_count;
+       int expected_seat_button_count = 0;
+       char device_name[255];
+
+       libinput = litest_create_context();
+       for (i = 0; i < num_devices; ++i) {
+               sprintf(device_name, "Generic mouse (%d)", i);
+               devices[i] = litest_add_device_with_overrides(libinput,
+                                                             LITEST_MOUSE,
+                                                             device_name,
+                                                             NULL, NULL, NULL);
+       }
+
+       for (i = 0; i < num_devices; ++i)
+               litest_button_click(devices[i], BTN_LEFT, true);
+
+       libinput_dispatch(libinput);
+       while ((ev = libinput_get_event(libinput))) {
+               if (libinput_event_get_type(ev) !=
+                   LIBINPUT_EVENT_POINTER_BUTTON) {
+                       libinput_dispatch(libinput);
+                       continue;
+               }
+
+               tev = libinput_event_get_pointer_event(ev);
+               ck_assert_notnull(tev);
+               ck_assert_int_eq(libinput_event_pointer_get_button(tev),
+                                BTN_LEFT);
+               ck_assert_int_eq(libinput_event_pointer_get_button_state(tev),
+                                LIBINPUT_POINTER_BUTTON_STATE_PRESSED);
+
+               ++expected_seat_button_count;
+               seat_button_count =
+                       libinput_event_pointer_get_seat_button_count(tev);
+               ck_assert_int_eq(expected_seat_button_count, seat_button_count);
+
+               libinput_dispatch(libinput);
+       }
+
+       ck_assert_int_eq(seat_button_count, num_devices);
+
+       for (i = 0; i < num_devices; ++i)
+               litest_button_click(devices[i], BTN_LEFT, false);
+
+       libinput_dispatch(libinput);
+       while ((ev = libinput_get_event(libinput))) {
+               if (libinput_event_get_type(ev) !=
+                   LIBINPUT_EVENT_POINTER_BUTTON) {
+                       libinput_dispatch(libinput);
+                       continue;
+               }
+
+               tev = libinput_event_get_pointer_event(ev);
+               ck_assert_notnull(tev);
+               ck_assert_int_eq(libinput_event_pointer_get_button(tev),
+                                BTN_LEFT);
+               ck_assert_int_eq(libinput_event_pointer_get_button_state(tev),
+                                LIBINPUT_POINTER_BUTTON_STATE_RELEASED);
+
+               --expected_seat_button_count;
+               seat_button_count =
+                       libinput_event_pointer_get_seat_button_count(tev);
+               ck_assert_int_eq(expected_seat_button_count, seat_button_count);
+
+               libinput_dispatch(libinput);
+       }
+
+       ck_assert_int_eq(seat_button_count, 0);
+
+       for (i = 0; i < num_devices; ++i)
+               litest_delete_device(devices[i]);
+       libinput_destroy(libinput);
+}
+END_TEST
+
 int main (int argc, char **argv) {
 
        litest_add("pointer:motion", pointer_motion_relative, LITEST_POINTER, 
LITEST_ANY);
        litest_add("pointer:button", pointer_button, LITEST_BUTTON, 
LITEST_CLICKPAD);
        litest_add("pointer:scroll", pointer_scroll_wheel, LITEST_WHEEL, 
LITEST_ANY);
+       litest_add_no_device("pointer:seat button count", 
pointer_seat_button_count);
 
        return litest_run(argc, argv);
 }
-- 
1.8.3.2

_______________________________________________
wayland-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/wayland-devel

Reply via email to