~ubuntu-branches/ubuntu/utopic/wayland/utopic

« back to all changes in this revision

Viewing changes to tests/resources-test.c

  • Committer: Package Import Robot
  • Author(s): Hector Oron, Timo Aaltonen, Hector Oron
  • Date: 2013-10-11 11:23:38 UTC
  • mfrom: (1.1.7)
  • Revision ID: package-import@ubuntu.com-20131011112338-tjsp43i3jwguenpb
Tags: 1.3.0-1
[ Timo Aaltonen ]
* control: Bump the libwayland0 C/R to (<< 1.1.0) so that it covers
  the ubuntu version too, and add it to -cursor.

[ Hector Oron ]
* New upstream stable release (1.3.0).
* Add myself to Uploaders.
* Switch to Debian source format 3.0 quilt.
* d/libwayland-dev.install:
  - install wayland documentation

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright © 2013 Marek Chalupa
 
3
 *
 
4
 * Permission to use, copy, modify, distribute, and sell this software and its
 
5
 * documentation for any purpose is hereby granted without fee, provided that
 
6
 * the above copyright notice appear in all copies and that both that copyright
 
7
 * notice and this permission notice appear in supporting documentation, and
 
8
 * that the name of the copyright holders not be used in advertising or
 
9
 * publicity pertaining to distribution of the software without specific,
 
10
 * written prior permission.  The copyright holders make no representations
 
11
 * about the suitability of this software for any purpose.  It is provided "as
 
12
 * is" without express or implied warranty.
 
13
 *
 
14
 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
 
15
 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
 
16
 * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
 
17
 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
 
18
 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
 
19
 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
 
20
 * OF THIS SOFTWARE.
 
21
 */
 
22
 
 
23
#include <assert.h>
 
24
#include <sys/socket.h>
 
25
#include <unistd.h>
 
26
 
 
27
#include "wayland-server.h"
 
28
#include "test-runner.h"
 
29
 
 
30
TEST(create_resource_tst)
 
31
{
 
32
        struct wl_display *display;
 
33
        struct wl_client *client;
 
34
        struct wl_resource *res;
 
35
        struct wl_list *link;
 
36
        int s[2];
 
37
        uint32_t id;
 
38
 
 
39
        assert(socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0, s) == 0);
 
40
        display = wl_display_create();
 
41
        assert(display);
 
42
        client = wl_client_create(display, s[0]);
 
43
        assert(client);
 
44
 
 
45
        res = wl_resource_create(client, &wl_display_interface, 4, 0);
 
46
        assert(res);
 
47
 
 
48
        /* setters/getters */
 
49
        assert(wl_resource_get_version(res) == 4);
 
50
 
 
51
        assert(client == wl_resource_get_client(res));
 
52
        id = wl_resource_get_id(res);
 
53
        assert(wl_client_get_object(client, id) == res);
 
54
 
 
55
        link = wl_resource_get_link(res);
 
56
        assert(link);
 
57
        assert(wl_resource_from_link(link) == res);
 
58
 
 
59
        wl_resource_set_user_data(res, (void *) 0xbee);
 
60
        assert(wl_resource_get_user_data(res) == (void *) 0xbee);
 
61
 
 
62
        wl_resource_destroy(res);
 
63
        wl_client_destroy(client);
 
64
        wl_display_destroy(display);
 
65
        close(s[1]);
 
66
}
 
67
 
 
68
static void
 
69
res_destroy_func(struct wl_resource *res)
 
70
{
 
71
        assert(res);
 
72
 
 
73
        _Bool *destr = wl_resource_get_user_data(res);
 
74
        *destr = 1;
 
75
}
 
76
 
 
77
static _Bool notify_called = 0;
 
78
static void
 
79
destroy_notify(struct wl_listener *l, void *data)
 
80
{
 
81
        assert(l && data);
 
82
        notify_called = 1;
 
83
}
 
84
 
 
85
TEST(destroy_res_tst)
 
86
{
 
87
        struct wl_display *display;
 
88
        struct wl_client *client;
 
89
        struct wl_resource *res;
 
90
        int s[2];
 
91
        unsigned id;
 
92
        struct wl_list *link;
 
93
 
 
94
        _Bool destroyed = 0;
 
95
        struct wl_listener destroy_listener = {
 
96
                .notify = &destroy_notify
 
97
        };
 
98
 
 
99
        assert(socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0, s) == 0);
 
100
        display = wl_display_create();
 
101
        assert(display);
 
102
        client = wl_client_create(display, s[0]);
 
103
        assert(client);
 
104
 
 
105
        res = wl_resource_create(client, &wl_display_interface, 4, 0);
 
106
        assert(res);
 
107
        wl_resource_set_implementation(res, NULL, &destroyed, res_destroy_func);
 
108
        wl_resource_add_destroy_listener(res, &destroy_listener);
 
109
 
 
110
        /* without implementation this should be ignored .. */
 
111
        wl_resource_post_event(res, 0);
 
112
 
 
113
        id = wl_resource_get_id(res);
 
114
        link = wl_resource_get_link(res);
 
115
        assert(link);
 
116
 
 
117
        wl_resource_destroy(res);
 
118
        assert(destroyed);
 
119
        assert(notify_called); /* check if signal was emitted */
 
120
        assert(wl_client_get_object(client, id) == NULL);
 
121
 
 
122
        res = wl_resource_create(client, &wl_display_interface, 2, 0);
 
123
        assert(res);
 
124
        destroyed = 0;
 
125
        notify_called = 0;
 
126
        wl_resource_set_destructor(res, res_destroy_func);
 
127
        wl_resource_set_user_data(res, &destroyed);
 
128
        wl_resource_add_destroy_listener(res, &destroy_listener);
 
129
        /* client should destroy the resource upon its destruction */
 
130
        wl_client_destroy(client);
 
131
        assert(destroyed);
 
132
        assert(notify_called);
 
133
 
 
134
        wl_display_destroy(display);
 
135
        close(s[1]);
 
136
}
 
137
 
 
138
TEST(create_resource_with_same_id)
 
139
{
 
140
        struct wl_display *display;
 
141
        struct wl_client *client;
 
142
        struct wl_resource *res, *res2;
 
143
        int s[2];
 
144
        uint32_t id;
 
145
 
 
146
        assert(socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0, s) == 0);
 
147
        display = wl_display_create();
 
148
        assert(display);
 
149
        client = wl_client_create(display, s[0]);
 
150
        assert(client);
 
151
 
 
152
        res = wl_resource_create(client, &wl_display_interface, 2, 0);
 
153
        assert(res);
 
154
        id = wl_resource_get_id(res);
 
155
        assert(wl_client_get_object(client, id) == res);
 
156
 
 
157
        /* this one should replace the old one */
 
158
        res2 = wl_resource_create(client, &wl_display_interface, 1, id);
 
159
        assert(wl_client_get_object(client, id) == res2);
 
160
 
 
161
        wl_resource_destroy(res2);
 
162
        wl_resource_destroy(res);
 
163
 
 
164
        wl_client_destroy(client);
 
165
        wl_display_destroy(display);
 
166
        close(s[1]);
 
167
}