U. Artie Eoff | 58990ca | 2012-09-28 06:39:32 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright © 2012 Intel Corporation |
| 3 | * |
| 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 | |
| 23 | #include <stdlib.h> |
| 24 | #include <stdio.h> |
| 25 | #include <sys/socket.h> |
| 26 | #include <assert.h> |
| 27 | #include <unistd.h> |
| 28 | #include <string.h> |
| 29 | #include <linux/input.h> |
| 30 | |
| 31 | #include "test-runner.h" |
| 32 | |
| 33 | struct context { |
| 34 | struct weston_layer *layer; |
| 35 | struct weston_seat *seat; |
| 36 | struct weston_surface *surface; |
| 37 | }; |
| 38 | |
| 39 | static void |
| 40 | handle_button_up(struct test_client *); |
| 41 | |
| 42 | static void |
| 43 | handle_button_down(struct test_client *client) |
| 44 | { |
| 45 | struct context *context = client->data; |
| 46 | uint32_t mask; |
| 47 | |
| 48 | assert(sscanf(client->buf, "%u", &mask) == 1); |
| 49 | |
| 50 | assert(mask == 1); |
| 51 | |
| 52 | notify_button(context->seat, 100, BTN_LEFT, |
| 53 | WL_POINTER_BUTTON_STATE_RELEASED); |
| 54 | |
| 55 | test_client_send(client, "send-button-state\n"); |
| 56 | client->handle = handle_button_up; |
| 57 | } |
| 58 | |
| 59 | static void |
| 60 | handle_button_up(struct test_client *client) |
| 61 | { |
| 62 | struct context *context = client->data; |
| 63 | static int once = 0; |
| 64 | uint32_t mask; |
| 65 | |
| 66 | assert(sscanf(client->buf, "%u", &mask) == 1); |
| 67 | |
| 68 | assert(mask == 0); |
| 69 | |
| 70 | if (!once++) { |
| 71 | notify_button(context->seat, 100, BTN_LEFT, |
| 72 | WL_POINTER_BUTTON_STATE_PRESSED); |
| 73 | |
| 74 | test_client_send(client, "send-button-state\n"); |
| 75 | client->handle = handle_button_down; |
| 76 | } else { |
| 77 | test_client_send(client, "bye\n"); |
| 78 | client->handle = NULL; |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | static void |
| 83 | handle_surface(struct test_client *client) |
| 84 | { |
| 85 | uint32_t id; |
| 86 | struct context *context = client->data; |
| 87 | struct wl_resource *resource; |
| 88 | struct wl_list *seat_list; |
| 89 | |
| 90 | assert(sscanf(client->buf, "surface %u", &id) == 1); |
| 91 | fprintf(stderr, "server: got surface id %u\n", id); |
| 92 | resource = wl_client_get_object(client->client, id); |
| 93 | assert(resource); |
| 94 | assert(strcmp(resource->object.interface->name, "wl_surface") == 0); |
| 95 | |
| 96 | context->surface = (struct weston_surface *) resource; |
| 97 | weston_surface_set_color(context->surface, 0.0, 0.0, 0.0, 1.0); |
| 98 | |
| 99 | context->layer = malloc(sizeof *context->layer); |
| 100 | assert(context->layer); |
| 101 | weston_layer_init(context->layer, |
| 102 | &client->compositor->cursor_layer.link); |
| 103 | wl_list_insert(&context->layer->surface_list, |
| 104 | &context->surface->layer_link); |
| 105 | |
| 106 | seat_list = &client->compositor->seat_list; |
| 107 | assert(wl_list_length(seat_list) == 1); |
| 108 | context->seat = container_of(seat_list->next, struct weston_seat, link); |
| 109 | |
| 110 | client->compositor->focus = 1; /* Make it work even if pointer is |
| 111 | * outside X window. */ |
| 112 | |
| 113 | weston_surface_configure(context->surface, 100, 100, 100, 100); |
| 114 | weston_surface_update_transform(context->surface); |
| 115 | weston_surface_damage(context->surface); |
| 116 | |
| 117 | notify_pointer_focus(context->seat, context->surface->output, |
| 118 | wl_fixed_from_int(150), wl_fixed_from_int(150)); |
| 119 | |
| 120 | test_client_send(client, "send-button-state\n"); |
| 121 | client->handle = handle_button_up; |
| 122 | } |
| 123 | |
| 124 | TEST(button_test) |
| 125 | { |
| 126 | struct context *context; |
| 127 | struct test_client *client; |
| 128 | |
| 129 | client = test_client_launch(compositor, "test-client"); |
| 130 | client->terminate = 1; |
| 131 | |
| 132 | test_client_send(client, "create-surface\n"); |
| 133 | client->handle = handle_surface; |
| 134 | |
| 135 | context = calloc(1, sizeof *context); |
| 136 | assert(context); |
| 137 | client->data = context; |
| 138 | } |