blob: 8994d105ccd8d115be4bfcb35f2483d674434d27 [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,
37 const char *text,
38 uint32_t index)
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,
45 const char *text,
46 uint32_t index)
Jan Arne Petersenb00e6632012-08-21 18:28:49 +020047{
Jan Arne Petersenb00e6632012-08-21 18:28:49 +020048}
49
50static void
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -050051text_model_delete_surrounding_text(void *data,
52 struct text_model *text_model,
53 int32_t index,
54 uint32_t length)
Jan Arne Petersenb00e6632012-08-21 18:28:49 +020055{
Jan Arne Petersenb00e6632012-08-21 18:28:49 +020056}
57
58static void
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -050059text_model_preedit_styling(void *data,
60 struct text_model *text_model)
Jan Arne Petersenb00e6632012-08-21 18:28:49 +020061{
Jan Arne Petersenb00e6632012-08-21 18:28:49 +020062}
63
64static void
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -050065text_model_modifiers_map(void *data,
66 struct text_model *text_model,
67 struct wl_array *map)
Jan Arne Petersenb00e6632012-08-21 18:28:49 +020068{
Jan Arne Petersenb00e6632012-08-21 18:28:49 +020069}
70
71static void
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -050072text_model_keysym(void *data,
73 struct text_model *text_model,
74 uint32_t serial,
75 uint32_t time,
76 uint32_t sym,
77 uint32_t state,
78 uint32_t modifiers)
Jan Arne Petersenb00e6632012-08-21 18:28:49 +020079{
Jan Arne Petersenb00e6632012-08-21 18:28:49 +020080}
81
82static void
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -050083text_model_selection_replacement(void *data,
84 struct text_model *text_model)
Jan Arne Petersenb00e6632012-08-21 18:28:49 +020085{
Jan Arne Petersenb00e6632012-08-21 18:28:49 +020086}
87
88static void
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -050089text_model_direction(void *data,
90 struct text_model *text_model)
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_locale(void *data,
96 struct text_model *text_model)
Jan Arne Petersenb00e6632012-08-21 18:28:49 +020097{
Jan Arne Petersenb00e6632012-08-21 18:28:49 +020098}
99
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -0500100static void
101text_model_enter(void *data,
102 struct text_model *text_model,
103 struct wl_surface *surface)
104
105{
106 struct text_model_state *state = data;
107
108 fprintf(stderr, "%s\n", __FUNCTION__);
109
110 state->activated += 1;
111}
112
113static void
114text_model_leave(void *data,
115 struct text_model *text_model)
116{
117 struct text_model_state *state = data;
118
119 state->deactivated += 1;
120}
121
122static const struct text_model_listener text_model_listener = {
123 text_model_commit_string,
124 text_model_preedit_string,
125 text_model_delete_surrounding_text,
126 text_model_preedit_styling,
127 text_model_modifiers_map,
128 text_model_keysym,
129 text_model_selection_replacement,
130 text_model_direction,
131 text_model_locale,
132 text_model_enter,
133 text_model_leave
134};
135
Jan Arne Petersenb00e6632012-08-21 18:28:49 +0200136TEST(text_test)
137{
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -0500138 struct client *client;
139 struct global *global;
140 struct text_model_factory *factory;
141 struct text_model *text_model;
142 struct text_model_state state;
Jan Arne Petersenb00e6632012-08-21 18:28:49 +0200143
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -0500144 client = client_create(100, 100, 100, 100);
145 assert(client);
Jan Arne Petersenb00e6632012-08-21 18:28:49 +0200146
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -0500147 factory = NULL;
148 wl_list_for_each(global, &client->global_list, link) {
149 if (strcmp(global->interface, "text_model_factory") == 0)
150 factory = wl_registry_bind(client->wl_registry,
151 global->name,
152 &text_model_factory_interface, 1);
153 }
Jan Arne Petersenb00e6632012-08-21 18:28:49 +0200154
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -0500155 assert(factory);
Jan Arne Petersenb00e6632012-08-21 18:28:49 +0200156
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -0500157 memset(&state, 0, sizeof state);
158 text_model = text_model_factory_create_text_model(factory);
159 text_model_add_listener(text_model, &text_model_listener, &state);
160
161 /* Make sure our test surface has keyboard focus. */
162 wl_test_activate_surface(client->test->wl_test,
163 client->surface->wl_surface);
Pekka Paalanenf2aa64f2012-12-12 14:26:41 +0200164 client_roundtrip(client);
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -0500165 assert(client->input->keyboard->focus == client->surface);
166
167 /* Activate test model and make sure we get enter event. */
168 text_model_activate(text_model, client->input->wl_seat,
169 client->surface->wl_surface);
Pekka Paalanenf2aa64f2012-12-12 14:26:41 +0200170 client_roundtrip(client);
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -0500171 assert(state.activated == 1 && state.deactivated == 0);
172
173 /* Deactivate test model and make sure we get leave event. */
174 text_model_deactivate(text_model, client->input->wl_seat);
Pekka Paalanenf2aa64f2012-12-12 14:26:41 +0200175 client_roundtrip(client);
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -0500176 assert(state.activated == 1 && state.deactivated == 1);
177
178 /* Activate test model again. */
179 text_model_activate(text_model, client->input->wl_seat,
180 client->surface->wl_surface);
Pekka Paalanenf2aa64f2012-12-12 14:26:41 +0200181 client_roundtrip(client);
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -0500182 assert(state.activated == 2 && state.deactivated == 1);
183
184 /* Take keyboard focus away and verify we get leave event. */
185 wl_test_activate_surface(client->test->wl_test, NULL);
Pekka Paalanenf2aa64f2012-12-12 14:26:41 +0200186 client_roundtrip(client);
Kristian Høgsberg1cb3df42012-12-11 23:03:56 -0500187 assert(state.activated == 2 && state.deactivated == 2);
Jan Arne Petersenb00e6632012-08-21 18:28:49 +0200188}