2012-10-02 02:21:16 +04:00
|
|
|
/*
|
|
|
|
* Copyright © 2012 Intel Corporation
|
|
|
|
*
|
2015-06-12 01:39:40 +03:00
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining
|
|
|
|
* a copy of this software and associated documentation files (the
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
|
|
* permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
* the following conditions:
|
2012-10-02 02:21:16 +04:00
|
|
|
*
|
2015-06-12 01:39:40 +03:00
|
|
|
* The above copyright notice and this permission notice (including the
|
|
|
|
* next paragraph) shall be included in all copies or substantial
|
|
|
|
* portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
|
|
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
* SOFTWARE.
|
2012-10-02 02:21:16 +04:00
|
|
|
*/
|
|
|
|
|
2014-11-20 04:18:33 +03:00
|
|
|
#include "config.h"
|
|
|
|
|
2016-07-19 14:16:27 +03:00
|
|
|
#include <stdint.h>
|
|
|
|
|
2018-02-20 15:05:50 +03:00
|
|
|
#include "input-timestamps-helper.h"
|
2017-12-13 14:27:57 +03:00
|
|
|
#include "shared/timespec-util.h"
|
2012-12-08 01:50:32 +04:00
|
|
|
#include "weston-test-client-helper.h"
|
2019-11-13 16:45:10 +03:00
|
|
|
#include "weston-test-fixture-compositor.h"
|
|
|
|
|
|
|
|
static enum test_result_code
|
|
|
|
fixture_setup(struct weston_test_harness *harness)
|
|
|
|
{
|
|
|
|
struct compositor_setup setup;
|
|
|
|
|
|
|
|
compositor_setup_defaults(&setup);
|
|
|
|
|
|
|
|
return weston_test_harness_execute_as_client(harness, &setup);
|
|
|
|
}
|
|
|
|
DECLARE_FIXTURE_SETUP(fixture_setup);
|
2012-10-02 02:21:16 +04:00
|
|
|
|
2017-12-13 14:27:57 +03:00
|
|
|
static const struct timespec t1 = { .tv_sec = 1, .tv_nsec = 1000001 };
|
|
|
|
static const struct timespec t2 = { .tv_sec = 2, .tv_nsec = 2000001 };
|
2018-02-20 15:05:50 +03:00
|
|
|
static const struct timespec t_other = { .tv_sec = 123, .tv_nsec = 456 };
|
2017-12-13 14:27:57 +03:00
|
|
|
|
|
|
|
static struct client *
|
|
|
|
create_client_with_keyboard_focus(void)
|
|
|
|
{
|
|
|
|
struct client *cl = create_client_and_test_surface(10, 10, 1, 1);
|
|
|
|
assert(cl);
|
|
|
|
|
|
|
|
weston_test_activate_surface(cl->test->weston_test,
|
|
|
|
cl->surface->wl_surface);
|
|
|
|
client_roundtrip(cl);
|
|
|
|
|
|
|
|
return cl;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
send_key(struct client *client, const struct timespec *time,
|
|
|
|
uint32_t key, uint32_t state)
|
|
|
|
{
|
|
|
|
uint32_t tv_sec_hi, tv_sec_lo, tv_nsec;
|
|
|
|
|
|
|
|
timespec_to_proto(time, &tv_sec_hi, &tv_sec_lo, &tv_nsec);
|
|
|
|
weston_test_send_key(client->test->weston_test, tv_sec_hi, tv_sec_lo,
|
|
|
|
tv_nsec, key, state);
|
|
|
|
client_roundtrip(client);
|
|
|
|
}
|
|
|
|
|
2012-12-08 01:50:32 +04:00
|
|
|
TEST(simple_keyboard_test)
|
2012-10-02 02:21:16 +04:00
|
|
|
{
|
2017-12-13 14:27:57 +03:00
|
|
|
struct client *client = create_client_with_keyboard_focus();
|
|
|
|
struct keyboard *keyboard = client->input->keyboard;
|
|
|
|
struct surface *expect_focus = client->surface;
|
2012-12-08 01:50:32 +04:00
|
|
|
uint32_t expect_key = 0;
|
|
|
|
uint32_t expect_state = 0;
|
|
|
|
|
2015-08-06 23:12:19 +03:00
|
|
|
while (1) {
|
2012-12-08 01:50:32 +04:00
|
|
|
assert(keyboard->key == expect_key);
|
|
|
|
assert(keyboard->state == expect_state);
|
|
|
|
assert(keyboard->focus == expect_focus);
|
|
|
|
|
|
|
|
if (keyboard->state == WL_KEYBOARD_KEY_STATE_PRESSED) {
|
|
|
|
expect_state = WL_KEYBOARD_KEY_STATE_RELEASED;
|
2017-12-13 14:27:57 +03:00
|
|
|
send_key(client, &t1, expect_key, expect_state);
|
2012-12-08 01:50:32 +04:00
|
|
|
} else if (keyboard->focus) {
|
|
|
|
expect_focus = NULL;
|
2015-02-24 18:32:14 +03:00
|
|
|
weston_test_activate_surface(
|
|
|
|
client->test->weston_test, NULL);
|
2017-12-13 14:27:57 +03:00
|
|
|
client_roundtrip(client);
|
2012-12-08 01:50:32 +04:00
|
|
|
} else if (expect_key < 10) {
|
|
|
|
expect_key++;
|
|
|
|
expect_focus = client->surface;
|
|
|
|
expect_state = WL_KEYBOARD_KEY_STATE_PRESSED;
|
2015-02-24 18:32:14 +03:00
|
|
|
weston_test_activate_surface(
|
|
|
|
client->test->weston_test,
|
|
|
|
expect_focus->wl_surface);
|
2017-12-13 14:27:57 +03:00
|
|
|
send_key(client, &t1, expect_key, expect_state);
|
2012-12-08 01:50:32 +04:00
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
2012-10-02 02:21:16 +04:00
|
|
|
}
|
|
|
|
}
|
2017-12-13 14:27:57 +03:00
|
|
|
|
|
|
|
TEST(keyboard_key_event_time)
|
|
|
|
{
|
|
|
|
struct client *client = create_client_with_keyboard_focus();
|
|
|
|
struct keyboard *keyboard = client->input->keyboard;
|
2018-02-20 15:05:50 +03:00
|
|
|
struct input_timestamps *input_ts =
|
|
|
|
input_timestamps_create_for_keyboard(client);
|
2017-12-13 14:27:57 +03:00
|
|
|
|
|
|
|
send_key(client, &t1, 1, WL_KEYBOARD_KEY_STATE_PRESSED);
|
|
|
|
assert(keyboard->key_time_msec == timespec_to_msec(&t1));
|
2018-02-20 15:05:50 +03:00
|
|
|
assert(timespec_eq(&keyboard->key_time_timespec, &t1));
|
2017-12-13 14:27:57 +03:00
|
|
|
|
|
|
|
send_key(client, &t2, 1, WL_KEYBOARD_KEY_STATE_RELEASED);
|
|
|
|
assert(keyboard->key_time_msec == timespec_to_msec(&t2));
|
2018-02-20 15:05:50 +03:00
|
|
|
assert(timespec_eq(&keyboard->key_time_timespec, &t2));
|
|
|
|
|
|
|
|
input_timestamps_destroy(input_ts);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(keyboard_timestamps_stop_after_input_timestamps_object_is_destroyed)
|
|
|
|
{
|
|
|
|
struct client *client = create_client_with_keyboard_focus();
|
|
|
|
struct keyboard *keyboard = client->input->keyboard;
|
|
|
|
struct input_timestamps *input_ts =
|
|
|
|
input_timestamps_create_for_keyboard(client);
|
|
|
|
|
|
|
|
send_key(client, &t1, 1, WL_KEYBOARD_KEY_STATE_PRESSED);
|
|
|
|
assert(keyboard->key_time_msec == timespec_to_msec(&t1));
|
|
|
|
assert(timespec_eq(&keyboard->key_time_timespec, &t1));
|
|
|
|
|
|
|
|
input_timestamps_destroy(input_ts);
|
|
|
|
|
|
|
|
send_key(client, &t2, 1, WL_KEYBOARD_KEY_STATE_RELEASED);
|
|
|
|
assert(keyboard->key_time_msec == timespec_to_msec(&t2));
|
|
|
|
assert(timespec_is_zero(&keyboard->key_time_timespec));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(keyboard_timestamps_stop_after_client_releases_wl_keyboard)
|
|
|
|
{
|
|
|
|
struct client *client = create_client_with_keyboard_focus();
|
|
|
|
struct keyboard *keyboard = client->input->keyboard;
|
|
|
|
struct input_timestamps *input_ts =
|
|
|
|
input_timestamps_create_for_keyboard(client);
|
|
|
|
|
|
|
|
send_key(client, &t1, 1, WL_KEYBOARD_KEY_STATE_PRESSED);
|
|
|
|
assert(keyboard->key_time_msec == timespec_to_msec(&t1));
|
|
|
|
assert(timespec_eq(&keyboard->key_time_timespec, &t1));
|
|
|
|
|
|
|
|
wl_keyboard_release(client->input->keyboard->wl_keyboard);
|
|
|
|
|
|
|
|
/* Set input_timestamp to an arbitrary value (different from t1, t2
|
|
|
|
* and 0) and check that it is not changed by sending the event.
|
|
|
|
* This is preferred over just checking for 0, since 0 is used
|
|
|
|
* internally for resetting the timestamp after handling an input
|
|
|
|
* event and checking for it here may lead to false negatives. */
|
|
|
|
keyboard->input_timestamp = t_other;
|
|
|
|
send_key(client, &t2, 1, WL_KEYBOARD_KEY_STATE_RELEASED);
|
|
|
|
assert(timespec_eq(&keyboard->input_timestamp, &t_other));
|
|
|
|
|
|
|
|
input_timestamps_destroy(input_ts);
|
2017-12-13 14:27:57 +03:00
|
|
|
}
|