blob: 65e00d5246d55d0261e8cb6aefe663fff2173c1e [file] [log] [blame]
Jan Arne Petersenb00e6632012-08-21 18:28:49 +02001/*
Jan Arne Petersen4c265182012-09-09 23:08:30 +02002 * Copyright © 2012 Intel Corporation
Jan Arne Petersenb00e6632012-08-21 18:28:49 +02003 *
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:
Jan Arne Petersenb00e6632012-08-21 18:28:49 +020011 *
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.
Jan Arne Petersenb00e6632012-08-21 18:28:49 +020024 */
25
Andrew Wedgbury9cd661e2014-04-07 12:40:35 +010026#include "config.h"
27
Jan Arne Petersenb00e6632012-08-21 18:28:49 +020028#include <string.h>
Jussi Kukkonen649bbce2016-07-19 14:16:27 +030029#include <stdint.h>
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -050030#include <stdio.h>
Bryce Harringtona7680262014-11-19 17:18:34 -080031
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -050032#include "weston-test-client-helper.h"
Jonas Ådahl3bcba342015-11-17 16:00:29 +080033#include "text-input-unstable-v1-client-protocol.h"
Pekka Paalanen701676d2019-11-13 15:45:10 +020034#include "weston-test-fixture-compositor.h"
35
36static enum test_result_code
37fixture_setup(struct weston_test_harness *harness)
38{
39 struct compositor_setup setup;
40
41 compositor_setup_defaults(&setup);
42
43 return weston_test_harness_execute_as_client(harness, &setup);
44}
45DECLARE_FIXTURE_SETUP(fixture_setup);
Jan Arne Petersenb00e6632012-08-21 18:28:49 +020046
Jan Arne Petersen78d00e42013-04-18 16:47:24 +020047struct text_input_state {
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -050048 int activated;
49 int deactivated;
Jan Arne Petersenb00e6632012-08-21 18:28:49 +020050};
51
52static void
Jan Arne Petersen78d00e42013-04-18 16:47:24 +020053text_input_commit_string(void *data,
Jonas Ådahl3bcba342015-11-17 16:00:29 +080054 struct zwp_text_input_v1 *text_input,
Jan Arne Petersend5a97ae2013-02-19 19:26:55 +010055 uint32_t serial,
56 const char *text)
Jan Arne Petersenb00e6632012-08-21 18:28:49 +020057{
Jan Arne Petersenb00e6632012-08-21 18:28:49 +020058}
59
60static void
Jan Arne Petersen78d00e42013-04-18 16:47:24 +020061text_input_preedit_string(void *data,
Jonas Ådahl3bcba342015-11-17 16:00:29 +080062 struct zwp_text_input_v1 *text_input,
Jan Arne Petersend5a97ae2013-02-19 19:26:55 +010063 uint32_t serial,
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -050064 const char *text,
Jan Arne Petersend5a97ae2013-02-19 19:26:55 +010065 const char *commit)
Jan Arne Petersenb00e6632012-08-21 18:28:49 +020066{
Jan Arne Petersenb00e6632012-08-21 18:28:49 +020067}
68
69static void
Jan Arne Petersen78d00e42013-04-18 16:47:24 +020070text_input_delete_surrounding_text(void *data,
Jonas Ådahl3bcba342015-11-17 16:00:29 +080071 struct zwp_text_input_v1 *text_input,
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -050072 int32_t index,
73 uint32_t length)
Jan Arne Petersenb00e6632012-08-21 18:28:49 +020074{
Jan Arne Petersenb00e6632012-08-21 18:28:49 +020075}
76
77static void
Jan Arne Petersen78d00e42013-04-18 16:47:24 +020078text_input_cursor_position(void *data,
Jonas Ådahl3bcba342015-11-17 16:00:29 +080079 struct zwp_text_input_v1 *text_input,
Jan Arne Petersend5a97ae2013-02-19 19:26:55 +010080 int32_t index,
81 int32_t anchor)
82{
83}
84
85static void
Jan Arne Petersen78d00e42013-04-18 16:47:24 +020086text_input_preedit_styling(void *data,
Jonas Ådahl3bcba342015-11-17 16:00:29 +080087 struct zwp_text_input_v1 *text_input,
Jan Arne Petersend5a97ae2013-02-19 19:26:55 +010088 uint32_t index,
89 uint32_t length,
90 uint32_t style)
91{
92}
93
94static void
Jan Arne Petersen78d00e42013-04-18 16:47:24 +020095text_input_preedit_cursor(void *data,
Jonas Ådahl3bcba342015-11-17 16:00:29 +080096 struct zwp_text_input_v1 *text_input,
Jan Arne Petersend5a97ae2013-02-19 19:26:55 +010097 int32_t index)
Jan Arne Petersenb00e6632012-08-21 18:28:49 +020098{
Jan Arne Petersenb00e6632012-08-21 18:28:49 +020099}
100
101static void
Jan Arne Petersen78d00e42013-04-18 16:47:24 +0200102text_input_modifiers_map(void *data,
Jonas Ådahl3bcba342015-11-17 16:00:29 +0800103 struct zwp_text_input_v1 *text_input,
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -0500104 struct wl_array *map)
Jan Arne Petersenb00e6632012-08-21 18:28:49 +0200105{
Jan Arne Petersenb00e6632012-08-21 18:28:49 +0200106}
107
108static void
Jan Arne Petersen78d00e42013-04-18 16:47:24 +0200109text_input_keysym(void *data,
Jonas Ådahl3bcba342015-11-17 16:00:29 +0800110 struct zwp_text_input_v1 *text_input,
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -0500111 uint32_t serial,
112 uint32_t time,
113 uint32_t sym,
114 uint32_t state,
115 uint32_t modifiers)
Jan Arne Petersenb00e6632012-08-21 18:28:49 +0200116{
Jan Arne Petersenb00e6632012-08-21 18:28:49 +0200117}
118
119static void
Jan Arne Petersen78d00e42013-04-18 16:47:24 +0200120text_input_enter(void *data,
Jonas Ådahl3bcba342015-11-17 16:00:29 +0800121 struct zwp_text_input_v1 *text_input,
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -0500122 struct wl_surface *surface)
123
124{
Jan Arne Petersen78d00e42013-04-18 16:47:24 +0200125 struct text_input_state *state = data;
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -0500126
Pekka Paalanen12a138d2019-11-06 15:59:33 +0200127 testlog("%s\n", __FUNCTION__);
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -0500128
129 state->activated += 1;
130}
131
132static void
Jan Arne Petersen78d00e42013-04-18 16:47:24 +0200133text_input_leave(void *data,
Jonas Ådahl3bcba342015-11-17 16:00:29 +0800134 struct zwp_text_input_v1 *text_input)
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -0500135{
Jan Arne Petersen78d00e42013-04-18 16:47:24 +0200136 struct text_input_state *state = data;
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -0500137
138 state->deactivated += 1;
139}
140
Jan Arne Petersend5a97ae2013-02-19 19:26:55 +0100141static void
Jan Arne Petersen78d00e42013-04-18 16:47:24 +0200142text_input_input_panel_state(void *data,
Jonas Ådahl3bcba342015-11-17 16:00:29 +0800143 struct zwp_text_input_v1 *text_input,
Jan Arne Petersend5a97ae2013-02-19 19:26:55 +0100144 uint32_t state)
145{
146}
147
Jan Arne Petersenece6b5a2013-04-18 16:47:15 +0200148static void
Jan Arne Petersen78d00e42013-04-18 16:47:24 +0200149text_input_language(void *data,
Jonas Ådahl3bcba342015-11-17 16:00:29 +0800150 struct zwp_text_input_v1 *text_input,
Jan Arne Petersenece6b5a2013-04-18 16:47:15 +0200151 uint32_t serial,
152 const char *language)
153{
154}
155
156static void
Jan Arne Petersen78d00e42013-04-18 16:47:24 +0200157text_input_text_direction(void *data,
Jonas Ådahl3bcba342015-11-17 16:00:29 +0800158 struct zwp_text_input_v1 *text_input,
Jan Arne Petersenece6b5a2013-04-18 16:47:15 +0200159 uint32_t serial,
160 uint32_t direction)
161{
162}
163
Jonas Ådahl3bcba342015-11-17 16:00:29 +0800164static const struct zwp_text_input_v1_listener text_input_listener = {
Jan Arne Petersen78d00e42013-04-18 16:47:24 +0200165 text_input_enter,
166 text_input_leave,
167 text_input_modifiers_map,
168 text_input_input_panel_state,
169 text_input_preedit_string,
170 text_input_preedit_styling,
171 text_input_preedit_cursor,
172 text_input_commit_string,
173 text_input_cursor_position,
174 text_input_delete_surrounding_text,
175 text_input_keysym,
176 text_input_language,
177 text_input_text_direction
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -0500178};
179
Jan Arne Petersenb00e6632012-08-21 18:28:49 +0200180TEST(text_test)
181{
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -0500182 struct client *client;
183 struct global *global;
Jonas Ådahl3bcba342015-11-17 16:00:29 +0800184 struct zwp_text_input_manager_v1 *factory;
185 struct zwp_text_input_v1 *text_input;
Jan Arne Petersen78d00e42013-04-18 16:47:24 +0200186 struct text_input_state state;
Jan Arne Petersenb00e6632012-08-21 18:28:49 +0200187
Pekka Paalanen4ac06ff2015-03-26 12:56:10 +0200188 client = create_client_and_test_surface(100, 100, 100, 100);
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -0500189 assert(client);
Jan Arne Petersenb00e6632012-08-21 18:28:49 +0200190
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -0500191 factory = NULL;
192 wl_list_for_each(global, &client->global_list, link) {
Jonas Ådahl3bcba342015-11-17 16:00:29 +0800193 if (strcmp(global->interface, "zwp_text_input_manager_v1") == 0)
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -0500194 factory = wl_registry_bind(client->wl_registry,
195 global->name,
Jonas Ådahl3bcba342015-11-17 16:00:29 +0800196 &zwp_text_input_manager_v1_interface, 1);
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -0500197 }
Jan Arne Petersenb00e6632012-08-21 18:28:49 +0200198
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -0500199 assert(factory);
Jan Arne Petersenb00e6632012-08-21 18:28:49 +0200200
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -0500201 memset(&state, 0, sizeof state);
Jonas Ådahl3bcba342015-11-17 16:00:29 +0800202 text_input = zwp_text_input_manager_v1_create_text_input(factory);
203 zwp_text_input_v1_add_listener(text_input,
204 &text_input_listener,
205 &state);
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -0500206
207 /* Make sure our test surface has keyboard focus. */
Derek Foremanf6a65922015-02-24 09:32:14 -0600208 weston_test_activate_surface(client->test->weston_test,
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -0500209 client->surface->wl_surface);
Pekka Paalanenf2aa64f2012-12-12 14:26:41 +0200210 client_roundtrip(client);
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -0500211 assert(client->input->keyboard->focus == client->surface);
212
213 /* Activate test model and make sure we get enter event. */
Jonas Ådahl3bcba342015-11-17 16:00:29 +0800214 zwp_text_input_v1_activate(text_input, client->input->wl_seat,
215 client->surface->wl_surface);
Pekka Paalanenf2aa64f2012-12-12 14:26:41 +0200216 client_roundtrip(client);
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -0500217 assert(state.activated == 1 && state.deactivated == 0);
218
219 /* Deactivate test model and make sure we get leave event. */
Jonas Ådahl3bcba342015-11-17 16:00:29 +0800220 zwp_text_input_v1_deactivate(text_input, client->input->wl_seat);
Pekka Paalanenf2aa64f2012-12-12 14:26:41 +0200221 client_roundtrip(client);
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -0500222 assert(state.activated == 1 && state.deactivated == 1);
223
224 /* Activate test model again. */
Jonas Ådahl3bcba342015-11-17 16:00:29 +0800225 zwp_text_input_v1_activate(text_input, client->input->wl_seat,
226 client->surface->wl_surface);
Pekka Paalanenf2aa64f2012-12-12 14:26:41 +0200227 client_roundtrip(client);
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -0500228 assert(state.activated == 2 && state.deactivated == 1);
229
230 /* Take keyboard focus away and verify we get leave event. */
Derek Foremanf6a65922015-02-24 09:32:14 -0600231 weston_test_activate_surface(client->test->weston_test, NULL);
Pekka Paalanenf2aa64f2012-12-12 14:26:41 +0200232 client_roundtrip(client);
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -0500233 assert(state.activated == 2 && state.deactivated == 2);
Pekka Paalanen56a8d692021-06-18 13:05:08 +0300234
235 zwp_text_input_v1_destroy(text_input);
236 zwp_text_input_manager_v1_destroy(factory);
237 client_destroy(client);
Jan Arne Petersenb00e6632012-08-21 18:28:49 +0200238}