blob: 41bf750691b2344a344a3dba7d213bde8d5437d7 [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
Jan Arne Petersenece6b5a2013-04-18 16:47:15 +0200134static void
135text_model_language(void *data,
136 struct text_model *text_model,
137 uint32_t serial,
138 const char *language)
139{
140}
141
142static void
143text_model_text_direction(void *data,
144 struct text_model *text_model,
145 uint32_t serial,
146 uint32_t direction)
147{
148}
149
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -0500150static const struct text_model_listener text_model_listener = {
151 text_model_commit_string,
152 text_model_preedit_string,
153 text_model_delete_surrounding_text,
Jan Arne Petersend5a97ae2013-02-19 19:26:55 +0100154 text_model_cursor_position,
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -0500155 text_model_preedit_styling,
Jan Arne Petersend5a97ae2013-02-19 19:26:55 +0100156 text_model_preedit_cursor,
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -0500157 text_model_modifiers_map,
158 text_model_keysym,
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -0500159 text_model_enter,
Jan Arne Petersend5a97ae2013-02-19 19:26:55 +0100160 text_model_leave,
Jan Arne Petersenece6b5a2013-04-18 16:47:15 +0200161 text_model_input_panel_state,
162 text_model_language,
163 text_model_text_direction
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -0500164};
165
Jan Arne Petersenb00e6632012-08-21 18:28:49 +0200166TEST(text_test)
167{
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -0500168 struct client *client;
169 struct global *global;
170 struct text_model_factory *factory;
171 struct text_model *text_model;
172 struct text_model_state state;
Jan Arne Petersenb00e6632012-08-21 18:28:49 +0200173
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -0500174 client = client_create(100, 100, 100, 100);
175 assert(client);
Jan Arne Petersenb00e6632012-08-21 18:28:49 +0200176
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -0500177 factory = NULL;
178 wl_list_for_each(global, &client->global_list, link) {
179 if (strcmp(global->interface, "text_model_factory") == 0)
180 factory = wl_registry_bind(client->wl_registry,
181 global->name,
182 &text_model_factory_interface, 1);
183 }
Jan Arne Petersenb00e6632012-08-21 18:28:49 +0200184
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -0500185 assert(factory);
Jan Arne Petersenb00e6632012-08-21 18:28:49 +0200186
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -0500187 memset(&state, 0, sizeof state);
188 text_model = text_model_factory_create_text_model(factory);
189 text_model_add_listener(text_model, &text_model_listener, &state);
190
191 /* Make sure our test surface has keyboard focus. */
192 wl_test_activate_surface(client->test->wl_test,
193 client->surface->wl_surface);
Pekka Paalanenf2aa64f2012-12-12 14:26:41 +0200194 client_roundtrip(client);
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -0500195 assert(client->input->keyboard->focus == client->surface);
196
197 /* Activate test model and make sure we get enter event. */
Jan Arne Petersend5a97ae2013-02-19 19:26:55 +0100198 text_model_activate(text_model, 0, client->input->wl_seat,
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -0500199 client->surface->wl_surface);
Pekka Paalanenf2aa64f2012-12-12 14:26:41 +0200200 client_roundtrip(client);
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -0500201 assert(state.activated == 1 && state.deactivated == 0);
202
203 /* Deactivate test model and make sure we get leave event. */
204 text_model_deactivate(text_model, client->input->wl_seat);
Pekka Paalanenf2aa64f2012-12-12 14:26:41 +0200205 client_roundtrip(client);
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -0500206 assert(state.activated == 1 && state.deactivated == 1);
207
208 /* Activate test model again. */
Jan Arne Petersend5a97ae2013-02-19 19:26:55 +0100209 text_model_activate(text_model, 0, client->input->wl_seat,
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -0500210 client->surface->wl_surface);
Pekka Paalanenf2aa64f2012-12-12 14:26:41 +0200211 client_roundtrip(client);
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -0500212 assert(state.activated == 2 && state.deactivated == 1);
213
214 /* Take keyboard focus away and verify we get leave event. */
215 wl_test_activate_surface(client->test->wl_test, NULL);
Pekka Paalanenf2aa64f2012-12-12 14:26:41 +0200216 client_roundtrip(client);
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -0500217 assert(state.activated == 2 && state.deactivated == 2);
Jan Arne Petersenb00e6632012-08-21 18:28:49 +0200218}