U. Artie Eoff | 840d5f9 | 2012-10-01 15:21:16 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2012 Intel Corporation |
| 3 | * |
Bryce Harrington | 2cc9297 | 2015-06-11 15:39:40 -0700 | [diff] [blame^] | 4 | * 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 Eoff | 840d5f9 | 2012-10-01 15:21:16 -0700 | [diff] [blame] | 11 | * |
Bryce Harrington | 2cc9297 | 2015-06-11 15:39:40 -0700 | [diff] [blame^] | 12 | * 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 Eoff | 840d5f9 | 2012-10-01 15:21:16 -0700 | [diff] [blame] | 24 | */ |
| 25 | |
Bryce Harrington | 12cc405 | 2014-11-19 17:18:33 -0800 | [diff] [blame] | 26 | #include "config.h" |
| 27 | |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 28 | #include "weston-test-client-helper.h" |
U. Artie Eoff | 840d5f9 | 2012-10-01 15:21:16 -0700 | [diff] [blame] | 29 | |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 30 | TEST(simple_keyboard_test) |
U. Artie Eoff | 840d5f9 | 2012-10-01 15:21:16 -0700 | [diff] [blame] | 31 | { |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 32 | struct client *client; |
| 33 | struct surface *expect_focus = NULL; |
| 34 | struct keyboard *keyboard; |
| 35 | uint32_t expect_key = 0; |
| 36 | uint32_t expect_state = 0; |
U. Artie Eoff | 840d5f9 | 2012-10-01 15:21:16 -0700 | [diff] [blame] | 37 | |
Pekka Paalanen | 4ac06ff | 2015-03-26 12:56:10 +0200 | [diff] [blame] | 38 | client = create_client_and_test_surface(10, 10, 1, 1); |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 39 | assert(client); |
U. Artie Eoff | 840d5f9 | 2012-10-01 15:21:16 -0700 | [diff] [blame] | 40 | |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 41 | keyboard = client->input->keyboard; |
| 42 | |
| 43 | while(1) { |
| 44 | assert(keyboard->key == expect_key); |
| 45 | assert(keyboard->state == expect_state); |
| 46 | assert(keyboard->focus == expect_focus); |
| 47 | |
| 48 | if (keyboard->state == WL_KEYBOARD_KEY_STATE_PRESSED) { |
| 49 | expect_state = WL_KEYBOARD_KEY_STATE_RELEASED; |
Derek Foreman | f6a6592 | 2015-02-24 09:32:14 -0600 | [diff] [blame] | 50 | weston_test_send_key(client->test->weston_test, |
| 51 | expect_key, expect_state); |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 52 | } else if (keyboard->focus) { |
| 53 | expect_focus = NULL; |
Derek Foreman | f6a6592 | 2015-02-24 09:32:14 -0600 | [diff] [blame] | 54 | weston_test_activate_surface( |
| 55 | client->test->weston_test, NULL); |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 56 | } else if (expect_key < 10) { |
| 57 | expect_key++; |
| 58 | expect_focus = client->surface; |
| 59 | expect_state = WL_KEYBOARD_KEY_STATE_PRESSED; |
Derek Foreman | f6a6592 | 2015-02-24 09:32:14 -0600 | [diff] [blame] | 60 | weston_test_activate_surface( |
| 61 | client->test->weston_test, |
| 62 | expect_focus->wl_surface); |
| 63 | weston_test_send_key(client->test->weston_test, |
| 64 | expect_key, expect_state); |
U. Artie Eoff | 1ba9b38 | 2012-12-07 13:50:32 -0800 | [diff] [blame] | 65 | } else { |
| 66 | break; |
| 67 | } |
Kristian Høgsberg | 1f4d8e9 | 2012-12-11 22:00:50 -0500 | [diff] [blame] | 68 | |
Pekka Paalanen | f2aa64f | 2012-12-12 14:26:41 +0200 | [diff] [blame] | 69 | client_roundtrip(client); |
U. Artie Eoff | 840d5f9 | 2012-10-01 15:21:16 -0700 | [diff] [blame] | 70 | } |
U. Artie Eoff | 840d5f9 | 2012-10-01 15:21:16 -0700 | [diff] [blame] | 71 | } |