2 * Copyright © 2012 Intel Corporation
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.
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.
25 #include <sys/socket.h>
31 #include "test-runner.h"
33 struct text_test_data {
34 struct weston_layer *layer;
36 unsigned int expected_activated_count;
37 unsigned int expected_deactivated_count;
39 const char *next_command;
40 void (*next_handle)(struct test_client *client);
44 pre_assert_state(struct test_client *client,
45 unsigned int expected_activated_count,
46 unsigned int expected_deactivated_count)
48 unsigned int activated_count, deactivated_count;
50 assert(sscanf(client->buf, "activated %u deactivated %u", &activated_count, &deactivated_count) == 2);
51 fprintf(stderr, "Text model activations: %u deactivations: %u\n", activated_count, deactivated_count);
52 assert(activated_count == expected_activated_count);
53 assert(deactivated_count == expected_deactivated_count);
57 handle_assert_state(struct test_client *client)
59 struct text_test_data *data = client->data;
61 pre_assert_state(client, data->expected_activated_count, data->expected_deactivated_count);
63 test_client_send(client, data->next_command);
64 client->handle = data->next_handle;
68 post_assert_state(struct test_client *client,
69 unsigned int expected_activated_count,
70 unsigned int expected_deactivated_count,
71 const char *next_command,
72 void (*next_handle)(struct test_client *client))
74 struct text_test_data *data = client->data;
76 data->expected_activated_count = expected_activated_count;
77 data->expected_deactivated_count = expected_deactivated_count;
79 data->next_command = next_command;
80 data->next_handle = next_handle;
82 test_client_send(client, "assert-state\n");
83 client->handle = handle_assert_state;
86 static struct weston_seat*
87 get_seat(struct test_client *client)
89 struct wl_list *seat_list;
90 struct weston_seat *seat;
92 seat_list = &client->compositor->seat_list;
93 assert(wl_list_length(seat_list) == 1);
94 seat = container_of(seat_list->next, struct weston_seat, link);
100 handle_surface_unfocus(struct test_client *client)
102 struct weston_seat *seat;
104 seat = get_seat(client);
106 pre_assert_state(client, 2, 1);
108 /* Unfocus the surface */
109 wl_keyboard_set_focus(&seat->keyboard, NULL);
111 post_assert_state(client, 2, 2, "bye\n", NULL);
115 handle_reactivate_text_model(struct test_client *client)
117 pre_assert_state(client, 1, 1);
119 /* text_model is activated */
121 post_assert_state(client, 2, 1,
122 "assert-state\n", handle_surface_unfocus);
126 handle_deactivate_text_model(struct test_client *client)
128 pre_assert_state(client, 1, 0);
130 /* text_model is deactivated */
132 post_assert_state(client, 1, 1,
133 "activate-text-model\n", handle_reactivate_text_model);
137 handle_activate_text_model(struct test_client *client)
139 pre_assert_state(client, 0, 0);
141 /* text_model is activated */
143 post_assert_state(client, 1, 0,
144 "deactivate-text-model\n", handle_deactivate_text_model);
148 handle_text_model(struct test_client *client)
151 struct wl_resource *resource;
153 assert(sscanf(client->buf, "text_model %u", &id) == 1);
154 fprintf(stderr, "got text_model id %u\n", id);
155 resource = wl_client_get_object(client->client, id);
157 assert(strcmp(resource->object.interface->name, "text_model") == 0);
159 test_client_send(client, "activate-text-model\n");
160 client->handle = handle_activate_text_model;
164 handle_surface(struct test_client *client)
167 struct wl_resource *resource;
168 struct weston_surface *surface;
169 struct text_test_data *data = client->data;
170 struct weston_seat *seat;
172 assert(sscanf(client->buf, "surface %u", &id) == 1);
173 fprintf(stderr, "got surface id %u\n", id);
174 resource = wl_client_get_object(client->client, id);
176 assert(strcmp(resource->object.interface->name, "wl_surface") == 0);
178 surface = (struct weston_surface *) resource;
180 weston_surface_configure(surface, 100, 100, 200, 200);
181 weston_surface_update_transform(surface);
182 weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1.0);
184 data->layer = malloc(sizeof *data->layer);
185 weston_layer_init(data->layer, &client->compositor->cursor_layer.link);
186 wl_list_insert(&data->layer->surface_list, &surface->layer_link);
187 weston_surface_damage(surface);
189 seat = get_seat(client);
190 client->compositor->focus = 1; /* Make it work even if pointer is
191 * outside X window. */
192 wl_keyboard_set_focus(&seat->keyboard, &surface->surface);
194 test_client_send(client, "create-text-model\n");
195 client->handle = handle_text_model;
200 struct test_client *client;
201 struct text_test_data *data;
203 client = test_client_launch(compositor, "test-text-client");
204 client->terminate = 1;
206 test_client_send(client, "create-surface\n");
207 client->handle = handle_surface;
209 data = malloc(sizeof *data);