text-test.c 5.56 KB
Newer Older
1
/*
2
 * Copyright © 2012 Intel Corporation
3
 *
4 5 6 7 8 9 10
 * Permission is hereby granted, free of charge, to any person obtaining
 * a copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
11
 *
12 13 14 15 16 17 18 19 20 21 22 23
 * The above copyright notice and this permission notice (including the
 * next paragraph) shall be included in all copies or substantial
 * portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
24 25
 */

26 27
#include "config.h"

28
#include <string.h>
29
#include <stdint.h>
30
#include <stdio.h>
31

32
#include "weston-test-client-helper.h"
33
#include "text-input-unstable-v1-client-protocol.h"
34

35
struct text_input_state {
36 37
	int activated;
	int deactivated;
38 39 40
};

static void
41
text_input_commit_string(void *data,
42
			 struct zwp_text_input_v1 *text_input,
Jan Arne Petersen's avatar
Jan Arne Petersen committed
43 44
			 uint32_t serial,
			 const char *text)
45 46 47 48
{
}

static void
49
text_input_preedit_string(void *data,
50
			  struct zwp_text_input_v1 *text_input,
Jan Arne Petersen's avatar
Jan Arne Petersen committed
51
			  uint32_t serial,
52
			  const char *text,
Jan Arne Petersen's avatar
Jan Arne Petersen committed
53
			  const char *commit)
54 55 56 57
{
}

static void
58
text_input_delete_surrounding_text(void *data,
59
				   struct zwp_text_input_v1 *text_input,
60 61
				   int32_t index,
				   uint32_t length)
62 63 64
{
}

Jan Arne Petersen's avatar
Jan Arne Petersen committed
65
static void
66
text_input_cursor_position(void *data,
67
			   struct zwp_text_input_v1 *text_input,
Jan Arne Petersen's avatar
Jan Arne Petersen committed
68 69 70 71 72
			   int32_t index,
			   int32_t anchor)
{
}

73
static void
74
text_input_preedit_styling(void *data,
75
			   struct zwp_text_input_v1 *text_input,
Jan Arne Petersen's avatar
Jan Arne Petersen committed
76 77 78 79 80 81 82
			   uint32_t index,
			   uint32_t length,
			   uint32_t style)
{
}

static void
83
text_input_preedit_cursor(void *data,
84
			  struct zwp_text_input_v1 *text_input,
Jan Arne Petersen's avatar
Jan Arne Petersen committed
85
			  int32_t index)
86 87 88 89
{
}

static void
90
text_input_modifiers_map(void *data,
91
			 struct zwp_text_input_v1 *text_input,
92
			 struct wl_array *map)
93 94 95 96
{
}

static void
97
text_input_keysym(void *data,
98
		  struct zwp_text_input_v1 *text_input,
99 100 101 102 103
		  uint32_t serial,
		  uint32_t time,
		  uint32_t sym,
		  uint32_t state,
		  uint32_t modifiers)
104 105 106 107
{
}

static void
108
text_input_enter(void *data,
109
		 struct zwp_text_input_v1 *text_input,
110 111
		 struct wl_surface *surface)

112
{
113
	struct text_input_state *state = data;
114

115
	fprintf(stderr, "%s\n", __FUNCTION__);
116

117
	state->activated += 1;
118 119 120
}

static void
121
text_input_leave(void *data,
122
		 struct zwp_text_input_v1 *text_input)
123
{
124
	struct text_input_state *state = data;
125 126

	state->deactivated += 1;
127 128
}

Jan Arne Petersen's avatar
Jan Arne Petersen committed
129
static void
130
text_input_input_panel_state(void *data,
131
			     struct zwp_text_input_v1 *text_input,
Jan Arne Petersen's avatar
Jan Arne Petersen committed
132 133 134 135
			     uint32_t state)
{
}

136
static void
137
text_input_language(void *data,
138
		    struct zwp_text_input_v1 *text_input,
139 140 141 142 143 144
		    uint32_t serial,
		    const char *language)
{
}

static void
145
text_input_text_direction(void *data,
146
			  struct zwp_text_input_v1 *text_input,
147 148 149 150 151
			  uint32_t serial,
			  uint32_t direction)
{
}

152
static const struct zwp_text_input_v1_listener text_input_listener = {
153 154 155 156 157 158 159 160 161 162 163 164 165
	text_input_enter,
	text_input_leave,
	text_input_modifiers_map,
	text_input_input_panel_state,
	text_input_preedit_string,
	text_input_preedit_styling,
	text_input_preedit_cursor,
	text_input_commit_string,
	text_input_cursor_position,
	text_input_delete_surrounding_text,
	text_input_keysym,
	text_input_language,
	text_input_text_direction
166 167
};

168 169
TEST(text_test)
{
170 171
	struct client *client;
	struct global *global;
172 173
	struct zwp_text_input_manager_v1 *factory;
	struct zwp_text_input_v1 *text_input;
174
	struct text_input_state state;
175

176
	client = create_client_and_test_surface(100, 100, 100, 100);
177 178 179 180
	assert(client);

	factory = NULL;
	wl_list_for_each(global, &client->global_list, link) {
181
		if (strcmp(global->interface, "zwp_text_input_manager_v1") == 0)
182 183
			factory = wl_registry_bind(client->wl_registry,
						   global->name,
184
						   &zwp_text_input_manager_v1_interface, 1);
185 186 187 188 189
	}

	assert(factory);

	memset(&state, 0, sizeof state);
190 191 192 193
	text_input = zwp_text_input_manager_v1_create_text_input(factory);
	zwp_text_input_v1_add_listener(text_input,
				       &text_input_listener,
				       &state);
194 195

	/* Make sure our test surface has keyboard focus. */
196
	weston_test_activate_surface(client->test->weston_test,
197
				 client->surface->wl_surface);
198
	client_roundtrip(client);
199 200 201
	assert(client->input->keyboard->focus == client->surface);

	/* Activate test model and make sure we get enter event. */
202 203
	zwp_text_input_v1_activate(text_input, client->input->wl_seat,
				   client->surface->wl_surface);
204
	client_roundtrip(client);
205 206 207
	assert(state.activated == 1 && state.deactivated == 0);

	/* Deactivate test model and make sure we get leave event. */
208
	zwp_text_input_v1_deactivate(text_input, client->input->wl_seat);
209
	client_roundtrip(client);
210 211 212
	assert(state.activated == 1 && state.deactivated == 1);

	/* Activate test model again. */
213 214
	zwp_text_input_v1_activate(text_input, client->input->wl_seat,
				   client->surface->wl_surface);
215
	client_roundtrip(client);
216 217 218
	assert(state.activated == 2 && state.deactivated == 1);

	/* Take keyboard focus away and verify we get leave event. */
219
	weston_test_activate_surface(client->test->weston_test, NULL);
220
	client_roundtrip(client);
221
	assert(state.activated == 2 && state.deactivated == 2);
222
}