blob: 62a54e0d4290575404675a878a97cdd77869c137 [file] [log] [blame]
Alexandros Frantzis27d7c392018-10-19 12:14:11 +03001/*
2 * Copyright © 2018 Collabora, Ltd.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sublicense, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial
14 * portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 * SOFTWARE.
24 */
25
26#include "config.h"
27
28#include <string.h>
29
30#include "linux-explicit-synchronization-unstable-v1-client-protocol.h"
31#include "weston-test-client-helper.h"
32#include "wayland-server-protocol.h"
33
34static struct zwp_linux_explicit_synchronization_v1 *
35get_linux_explicit_synchronization(struct client *client)
36{
37 struct global *g;
38 struct global *global_sync = NULL;
39 struct zwp_linux_explicit_synchronization_v1 *sync = NULL;
40
41 wl_list_for_each(g, &client->global_list, link) {
42 if (strcmp(g->interface,
43 zwp_linux_explicit_synchronization_v1_interface.name))
44 continue;
45
46 if (global_sync)
47 assert(!"Multiple linux explicit sync objects");
48
49 global_sync = g;
50 }
51
52 assert(global_sync);
53 assert(global_sync->version == 1);
54
55 sync = wl_registry_bind(
56 client->wl_registry, global_sync->name,
57 &zwp_linux_explicit_synchronization_v1_interface, 1);
58 assert(sync);
59
60 return sync;
61}
62
63static struct client *
64create_test_client(void)
65{
66 struct client *cl = create_client_and_test_surface(0, 0, 100, 100);
67 assert(cl);
68 return cl;
69}
70
71TEST(second_surface_synchronization_on_surface_raises_error)
72{
73 struct client *client = create_test_client();
74 struct zwp_linux_explicit_synchronization_v1 *sync =
75 get_linux_explicit_synchronization(client);
76 struct zwp_linux_surface_synchronization_v1 *surface_sync1;
77 struct zwp_linux_surface_synchronization_v1 *surface_sync2;
78
79 surface_sync1 =
80 zwp_linux_explicit_synchronization_v1_get_synchronization(
81 sync, client->surface->wl_surface);
82 client_roundtrip(client);
83
84 /* Second surface_synchronization creation should fail */
85 surface_sync2 =
86 zwp_linux_explicit_synchronization_v1_get_synchronization(
87 sync, client->surface->wl_surface);
88 expect_protocol_error(
89 client,
90 &zwp_linux_explicit_synchronization_v1_interface,
91 ZWP_LINUX_EXPLICIT_SYNCHRONIZATION_V1_ERROR_SYNCHRONIZATION_EXISTS);
92
93 zwp_linux_surface_synchronization_v1_destroy(surface_sync2);
94 zwp_linux_surface_synchronization_v1_destroy(surface_sync1);
95 zwp_linux_explicit_synchronization_v1_destroy(sync);
96}