blob: f5c02ff8a07ec9fc989aa4a56fbdcab3939a3d04 [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 *
4 * Permission to use, copy, modify, distribute, and sell this software and
5 * its documentation for any purpose is hereby granted without fee, provided
6 * that the above copyright notice appear in all copies and that both that
7 * copyright notice and this permission notice appear in supporting
8 * documentation, and that the name of the copyright holders not be used in
9 * advertising or publicity pertaining to distribution of the software
10 * without specific, written prior permission. The copyright holders make
11 * no representations about the suitability of this software for any
12 * purpose. It is provided "as is" without express or implied warranty.
13 *
14 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
15 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
17 * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
18 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
19 * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
20 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21 */
22
Jan Arne Petersenb00e6632012-08-21 18:28:49 +020023#include <string.h>
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -050024#include <stdio.h>
25#include <linux/input.h>
26#include "weston-test-client-helper.h"
27#include "../clients/text-client-protocol.h"
Jan Arne Petersenb00e6632012-08-21 18:28:49 +020028
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -050029struct text_model_state {
30 int activated;
31 int deactivated;
Jan Arne Petersenb00e6632012-08-21 18:28:49 +020032};
33
34static void
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -050035text_model_commit_string(void *data,
36 struct text_model *text_model,
Jan Arne Petersend5a97ae2013-02-19 19:26:55 +010037 uint32_t serial,
38 const char *text)
Jan Arne Petersenb00e6632012-08-21 18:28:49 +020039{
Jan Arne Petersenb00e6632012-08-21 18:28:49 +020040}
41
42static void
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -050043text_model_preedit_string(void *data,
44 struct text_model *text_model,
Jan Arne Petersend5a97ae2013-02-19 19:26:55 +010045 uint32_t serial,
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -050046 const char *text,
Jan Arne Petersend5a97ae2013-02-19 19:26:55 +010047 const char *commit)
Jan Arne Petersenb00e6632012-08-21 18:28:49 +020048{
Jan Arne Petersenb00e6632012-08-21 18:28:49 +020049}
50
51static void
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -050052text_model_delete_surrounding_text(void *data,
53 struct text_model *text_model,
Jan Arne Petersend5a97ae2013-02-19 19:26:55 +010054 uint32_t serial,
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -050055 int32_t index,
56 uint32_t length)
Jan Arne Petersenb00e6632012-08-21 18:28:49 +020057{
Jan Arne Petersenb00e6632012-08-21 18:28:49 +020058}
59
60static void
Jan Arne Petersend5a97ae2013-02-19 19:26:55 +010061text_model_cursor_position(void *data,
62 struct text_model *text_model,
63 uint32_t serial,
64 int32_t index,
65 int32_t anchor)
66{
67}
68
69static void
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -050070text_model_preedit_styling(void *data,
Jan Arne Petersend5a97ae2013-02-19 19:26:55 +010071 struct text_model *text_model,
72 uint32_t serial,
73 uint32_t index,
74 uint32_t length,
75 uint32_t style)
76{
77}
78
79static void
80text_model_preedit_cursor(void *data,
81 struct text_model *text_model,
82 uint32_t serial,
83 int32_t index)
Jan Arne Petersenb00e6632012-08-21 18:28:49 +020084{
Jan Arne Petersenb00e6632012-08-21 18:28:49 +020085}
86
87static void
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -050088text_model_modifiers_map(void *data,
89 struct text_model *text_model,
90 struct wl_array *map)
Jan Arne Petersenb00e6632012-08-21 18:28:49 +020091{
Jan Arne Petersenb00e6632012-08-21 18:28:49 +020092}
93
94static void
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -050095text_model_keysym(void *data,
96 struct text_model *text_model,
97 uint32_t serial,
98 uint32_t time,
99 uint32_t sym,
100 uint32_t state,
101 uint32_t modifiers)
Jan Arne Petersenb00e6632012-08-21 18:28:49 +0200102{
Jan Arne Petersenb00e6632012-08-21 18:28:49 +0200103}
104
105static void
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -0500106text_model_enter(void *data,
107 struct text_model *text_model,
108 struct wl_surface *surface)
109
110{
111 struct text_model_state *state = data;
112
113 fprintf(stderr, "%s\n", __FUNCTION__);
114
115 state->activated += 1;
116}
117
118static void
119text_model_leave(void *data,
120 struct text_model *text_model)
121{
122 struct text_model_state *state = data;
123
124 state->deactivated += 1;
125}
126
Jan Arne Petersend5a97ae2013-02-19 19:26:55 +0100127static void
128text_model_input_panel_state(void *data,
129 struct text_model *text_model,
130 uint32_t state)
131{
132}
133
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -0500134static const struct text_model_listener text_model_listener = {
135 text_model_commit_string,
136 text_model_preedit_string,
137 text_model_delete_surrounding_text,
Jan Arne Petersend5a97ae2013-02-19 19:26:55 +0100138 text_model_cursor_position,
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -0500139 text_model_preedit_styling,
Jan Arne Petersend5a97ae2013-02-19 19:26:55 +0100140 text_model_preedit_cursor,
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -0500141 text_model_modifiers_map,
142 text_model_keysym,
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -0500143 text_model_enter,
Jan Arne Petersend5a97ae2013-02-19 19:26:55 +0100144 text_model_leave,
145 text_model_input_panel_state
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -0500146};
147
Jan Arne Petersenb00e6632012-08-21 18:28:49 +0200148TEST(text_test)
149{
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -0500150 struct client *client;
151 struct global *global;
152 struct text_model_factory *factory;
153 struct text_model *text_model;
154 struct text_model_state state;
Jan Arne Petersenb00e6632012-08-21 18:28:49 +0200155
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -0500156 client = client_create(100, 100, 100, 100);
157 assert(client);
Jan Arne Petersenb00e6632012-08-21 18:28:49 +0200158
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -0500159 factory = NULL;
160 wl_list_for_each(global, &client->global_list, link) {
161 if (strcmp(global->interface, "text_model_factory") == 0)
162 factory = wl_registry_bind(client->wl_registry,
163 global->name,
164 &text_model_factory_interface, 1);
165 }
Jan Arne Petersenb00e6632012-08-21 18:28:49 +0200166
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -0500167 assert(factory);
Jan Arne Petersenb00e6632012-08-21 18:28:49 +0200168
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -0500169 memset(&state, 0, sizeof state);
170 text_model = text_model_factory_create_text_model(factory);
171 text_model_add_listener(text_model, &text_model_listener, &state);
172
173 /* Make sure our test surface has keyboard focus. */
174 wl_test_activate_surface(client->test->wl_test,
175 client->surface->wl_surface);
Pekka Paalanenf2aa64f2012-12-12 14:26:41 +0200176 client_roundtrip(client);
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -0500177 assert(client->input->keyboard->focus == client->surface);
178
179 /* Activate test model and make sure we get enter event. */
Jan Arne Petersend5a97ae2013-02-19 19:26:55 +0100180 text_model_activate(text_model, 0, client->input->wl_seat,
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -0500181 client->surface->wl_surface);
Pekka Paalanenf2aa64f2012-12-12 14:26:41 +0200182 client_roundtrip(client);
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -0500183 assert(state.activated == 1 && state.deactivated == 0);
184
185 /* Deactivate test model and make sure we get leave event. */
186 text_model_deactivate(text_model, client->input->wl_seat);
Pekka Paalanenf2aa64f2012-12-12 14:26:41 +0200187 client_roundtrip(client);
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -0500188 assert(state.activated == 1 && state.deactivated == 1);
189
190 /* Activate test model again. */
Jan Arne Petersend5a97ae2013-02-19 19:26:55 +0100191 text_model_activate(text_model, 0, client->input->wl_seat,
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -0500192 client->surface->wl_surface);
Pekka Paalanenf2aa64f2012-12-12 14:26:41 +0200193 client_roundtrip(client);
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -0500194 assert(state.activated == 2 && state.deactivated == 1);
195
196 /* Take keyboard focus away and verify we get leave event. */
197 wl_test_activate_surface(client->test->wl_test, NULL);
Pekka Paalanenf2aa64f2012-12-12 14:26:41 +0200198 client_roundtrip(client);
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -0500199 assert(state.activated == 2 && state.deactivated == 2);
Jan Arne Petersenb00e6632012-08-21 18:28:49 +0200200}