text-test.c 5.85 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"
Pekka Paalanen's avatar
Pekka Paalanen committed
34 35 36 37 38 39 40 41 42 43 44 45
#include "weston-test-fixture-compositor.h"

static enum test_result_code
fixture_setup(struct weston_test_harness *harness)
{
	struct compositor_setup setup;

	compositor_setup_defaults(&setup);

	return weston_test_harness_execute_as_client(harness, &setup);
}
DECLARE_FIXTURE_SETUP(fixture_setup);
46

47
struct text_input_state {
48 49
	int activated;
	int deactivated;
50 51 52
};

static void
53
text_input_commit_string(void *data,
54
			 struct zwp_text_input_v1 *text_input,
Jan Arne Petersen's avatar
Jan Arne Petersen committed
55 56
			 uint32_t serial,
			 const char *text)
57 58 59 60
{
}

static void
61
text_input_preedit_string(void *data,
62
			  struct zwp_text_input_v1 *text_input,
Jan Arne Petersen's avatar
Jan Arne Petersen committed
63
			  uint32_t serial,
64
			  const char *text,
Jan Arne Petersen's avatar
Jan Arne Petersen committed
65
			  const char *commit)
66 67 68 69
{
}

static void
70
text_input_delete_surrounding_text(void *data,
71
				   struct zwp_text_input_v1 *text_input,
72 73
				   int32_t index,
				   uint32_t length)
74 75 76
{
}

Jan Arne Petersen's avatar
Jan Arne Petersen committed
77
static void
78
text_input_cursor_position(void *data,
79
			   struct zwp_text_input_v1 *text_input,
Jan Arne Petersen's avatar
Jan Arne Petersen committed
80 81 82 83 84
			   int32_t index,
			   int32_t anchor)
{
}

85
static void
86
text_input_preedit_styling(void *data,
87
			   struct zwp_text_input_v1 *text_input,
Jan Arne Petersen's avatar
Jan Arne Petersen committed
88 89 90 91 92 93 94
			   uint32_t index,
			   uint32_t length,
			   uint32_t style)
{
}

static void
95
text_input_preedit_cursor(void *data,
96
			  struct zwp_text_input_v1 *text_input,
Jan Arne Petersen's avatar
Jan Arne Petersen committed
97
			  int32_t index)
98 99 100 101
{
}

static void
102
text_input_modifiers_map(void *data,
103
			 struct zwp_text_input_v1 *text_input,
104
			 struct wl_array *map)
105 106 107 108
{
}

static void
109
text_input_keysym(void *data,
110
		  struct zwp_text_input_v1 *text_input,
111 112 113 114 115
		  uint32_t serial,
		  uint32_t time,
		  uint32_t sym,
		  uint32_t state,
		  uint32_t modifiers)
116 117 118 119
{
}

static void
120
text_input_enter(void *data,
121
		 struct zwp_text_input_v1 *text_input,
122 123
		 struct wl_surface *surface)

124
{
125
	struct text_input_state *state = data;
126

127
	testlog("%s\n", __FUNCTION__);
128

129
	state->activated += 1;
130 131 132
}

static void
133
text_input_leave(void *data,
134
		 struct zwp_text_input_v1 *text_input)
135
{
136
	struct text_input_state *state = data;
137 138

	state->deactivated += 1;
139 140
}

Jan Arne Petersen's avatar
Jan Arne Petersen committed
141
static void
142
text_input_input_panel_state(void *data,
143
			     struct zwp_text_input_v1 *text_input,
Jan Arne Petersen's avatar
Jan Arne Petersen committed
144 145 146 147
			     uint32_t state)
{
}

148
static void
149
text_input_language(void *data,
150
		    struct zwp_text_input_v1 *text_input,
151 152 153 154 155 156
		    uint32_t serial,
		    const char *language)
{
}

static void
157
text_input_text_direction(void *data,
158
			  struct zwp_text_input_v1 *text_input,
159 160 161 162 163
			  uint32_t serial,
			  uint32_t direction)
{
}

164
static const struct zwp_text_input_v1_listener text_input_listener = {
165 166 167 168 169 170 171 172 173 174 175 176 177
	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
178 179
};

180 181
TEST(text_test)
{
182 183
	struct client *client;
	struct global *global;
184 185
	struct zwp_text_input_manager_v1 *factory;
	struct zwp_text_input_v1 *text_input;
186
	struct text_input_state state;
187

188
	client = create_client_and_test_surface(100, 100, 100, 100);
189 190 191 192
	assert(client);

	factory = NULL;
	wl_list_for_each(global, &client->global_list, link) {
193
		if (strcmp(global->interface, "zwp_text_input_manager_v1") == 0)
194 195
			factory = wl_registry_bind(client->wl_registry,
						   global->name,
196
						   &zwp_text_input_manager_v1_interface, 1);
197 198 199 200 201
	}

	assert(factory);

	memset(&state, 0, sizeof state);
202 203 204 205
	text_input = zwp_text_input_manager_v1_create_text_input(factory);
	zwp_text_input_v1_add_listener(text_input,
				       &text_input_listener,
				       &state);
206 207

	/* Make sure our test surface has keyboard focus. */
208
	weston_test_activate_surface(client->test->weston_test,
209
				 client->surface->wl_surface);
210
	client_roundtrip(client);
211 212 213
	assert(client->input->keyboard->focus == client->surface);

	/* Activate test model and make sure we get enter event. */
214 215
	zwp_text_input_v1_activate(text_input, client->input->wl_seat,
				   client->surface->wl_surface);
216
	client_roundtrip(client);
217 218 219
	assert(state.activated == 1 && state.deactivated == 0);

	/* Deactivate test model and make sure we get leave event. */
220
	zwp_text_input_v1_deactivate(text_input, client->input->wl_seat);
221
	client_roundtrip(client);
222 223 224
	assert(state.activated == 1 && state.deactivated == 1);

	/* Activate test model again. */
225 226
	zwp_text_input_v1_activate(text_input, client->input->wl_seat,
				   client->surface->wl_surface);
227
	client_roundtrip(client);
228 229 230
	assert(state.activated == 2 && state.deactivated == 1);

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