blob: 6b4ba19db64e0ac0cecf4709623f1eafce6fc348 [file] [log] [blame]
U. Artie Eoff840d5f92012-10-01 15:21:16 -07001/*
2 * Copyright © 2012 Intel Corporation
3 *
Bryce Harrington2cc92972015-06-11 15:39:40 -07004 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sublicense, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
U. Artie Eoff840d5f92012-10-01 15:21:16 -070011 *
Bryce Harrington2cc92972015-06-11 15:39:40 -070012 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial
14 * portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 * SOFTWARE.
U. Artie Eoff840d5f92012-10-01 15:21:16 -070024 */
25
Bryce Harrington12cc4052014-11-19 17:18:33 -080026#include "config.h"
27
Jussi Kukkonen649bbce2016-07-19 14:16:27 +030028#include <stdint.h>
29
U. Artie Eoff1ba9b382012-12-07 13:50:32 -080030#include "weston-test-client-helper.h"
U. Artie Eoff840d5f92012-10-01 15:21:16 -070031
U. Artie Eoff1ba9b382012-12-07 13:50:32 -080032TEST(simple_keyboard_test)
U. Artie Eoff840d5f92012-10-01 15:21:16 -070033{
U. Artie Eoff1ba9b382012-12-07 13:50:32 -080034 struct client *client;
35 struct surface *expect_focus = NULL;
36 struct keyboard *keyboard;
37 uint32_t expect_key = 0;
38 uint32_t expect_state = 0;
U. Artie Eoff840d5f92012-10-01 15:21:16 -070039
Pekka Paalanen4ac06ff2015-03-26 12:56:10 +020040 client = create_client_and_test_surface(10, 10, 1, 1);
U. Artie Eoff1ba9b382012-12-07 13:50:32 -080041 assert(client);
U. Artie Eoff840d5f92012-10-01 15:21:16 -070042
U. Artie Eoff1ba9b382012-12-07 13:50:32 -080043 keyboard = client->input->keyboard;
44
Dawid Gajownik74a635b2015-08-06 17:12:19 -030045 while (1) {
U. Artie Eoff1ba9b382012-12-07 13:50:32 -080046 assert(keyboard->key == expect_key);
47 assert(keyboard->state == expect_state);
48 assert(keyboard->focus == expect_focus);
49
50 if (keyboard->state == WL_KEYBOARD_KEY_STATE_PRESSED) {
51 expect_state = WL_KEYBOARD_KEY_STATE_RELEASED;
Derek Foremanf6a65922015-02-24 09:32:14 -060052 weston_test_send_key(client->test->weston_test,
53 expect_key, expect_state);
U. Artie Eoff1ba9b382012-12-07 13:50:32 -080054 } else if (keyboard->focus) {
55 expect_focus = NULL;
Derek Foremanf6a65922015-02-24 09:32:14 -060056 weston_test_activate_surface(
57 client->test->weston_test, NULL);
U. Artie Eoff1ba9b382012-12-07 13:50:32 -080058 } else if (expect_key < 10) {
59 expect_key++;
60 expect_focus = client->surface;
61 expect_state = WL_KEYBOARD_KEY_STATE_PRESSED;
Derek Foremanf6a65922015-02-24 09:32:14 -060062 weston_test_activate_surface(
63 client->test->weston_test,
64 expect_focus->wl_surface);
65 weston_test_send_key(client->test->weston_test,
66 expect_key, expect_state);
U. Artie Eoff1ba9b382012-12-07 13:50:32 -080067 } else {
68 break;
69 }
Kristian Høgsberg1f4d8e92012-12-11 22:00:50 -050070
Pekka Paalanenf2aa64f2012-12-12 14:26:41 +020071 client_roundtrip(client);
U. Artie Eoff840d5f92012-10-01 15:21:16 -070072 }
U. Artie Eoff840d5f92012-10-01 15:21:16 -070073}