Merge remote-tracking branch 'pq/simple-fixes'
[profile/ivi/weston.git] / tests / event-test.c
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
29 #include <string.h>
30
31 #include "test-runner.h"
32
33 static void
34 handle_surface(struct test_client *client)
35 {
36         uint32_t id;
37         struct wl_resource *resource;
38         struct weston_surface *surface;
39         struct weston_layer *layer = client->data;
40         struct wl_input_device *device;
41
42         assert(sscanf(client->buf, "surface %u", &id) == 1);
43         fprintf(stderr, "got surface id %u\n", id);
44         resource = wl_client_get_object(client->client, id);
45         assert(resource);
46         assert(strcmp(resource->object.interface->name, "wl_surface") == 0);
47
48         surface = (struct weston_surface *) resource;
49
50         weston_surface_configure(surface, 100, 100, 200, 200);
51         weston_surface_assign_output(surface);
52         weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1.0);
53         wl_list_insert(&layer->surface_list, &surface->layer_link);
54         weston_surface_damage(surface);
55
56         device = client->compositor->input_device;
57         client->compositor->focus = 1; /* Make it work even if pointer is
58                                         * outside X window. */
59         notify_motion(device, 100, 150, 150);
60
61         test_client_send(client, "bye\n");
62 }
63
64 TEST(event_test)
65 {
66         struct test_client *client;
67         struct weston_layer *layer;
68
69         client = test_client_launch(compositor);
70         client->terminate = 1;
71
72         test_client_send(client, "create-surface\n");
73         client->handle = handle_surface;
74
75         layer = malloc(sizeof *layer);
76         assert(layer);
77         weston_layer_init(layer, &compositor->cursor_layer.link);
78         client->data = layer;
79 }