mirror of
https://gitlab.freedesktop.org/libinput/libinput.git
synced 2025-12-20 04:30:06 +01:00
test: Test seat wide button and key count helpers
Signed-off-by: Jonas Ådahl <jadahl@gmail.com> Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
parent
6207216702
commit
3f349026cf
6 changed files with 225 additions and 8 deletions
2
COPYING
2
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
|
||||
|
|
|
|||
|
|
@ -19,13 +19,14 @@ liblitest_la_SOURCES = \
|
|||
litest.c
|
||||
|
||||
run_tests = \
|
||||
test-udev \
|
||||
test-path \
|
||||
test-pointer \
|
||||
test-touch \
|
||||
test-log \
|
||||
test-touchpad \
|
||||
test-misc
|
||||
test-udev \
|
||||
test-path \
|
||||
test-pointer \
|
||||
test-touch \
|
||||
test-log \
|
||||
test-touchpad \
|
||||
test-misc \
|
||||
test-keyboard
|
||||
build_tests = \
|
||||
test-build-cxx \
|
||||
test-build-linker \
|
||||
|
|
@ -70,6 +71,11 @@ test_misc_CFLAGS = $(AM_CPPFLAGS)
|
|||
test_misc_LDADD = $(TEST_LIBS)
|
||||
test_misc_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
|
||||
|
|
|
|||
117
test/keyboard.c
Normal file
117
test/keyboard.c
Normal file
|
|
@ -0,0 +1,117 @@
|
|||
/*
|
||||
* Copyright © 2014 Jonas Ådahl <jadahl@gmail.com>
|
||||
*
|
||||
* 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);
|
||||
}
|
||||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -119,6 +119,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,
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue