blob: c7d175b9e2f94d5260dad39bcb6b71df1bd650ae [file] [log] [blame]
Pekka Paalanen3c5f1c72014-10-01 16:34:48 +03001/*
2 * Copyright © 2014 Collabora, Ltd.
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 "config.h"
24
25#include <stdio.h>
26#include <string.h>
27#include <assert.h>
28
29#include "weston-test-client-helper.h"
30
31static struct wl_subcompositor *
32get_subcompositor(struct client *client)
33{
34 struct global *g;
35 struct global *global_sub = NULL;
36 struct wl_subcompositor *sub;
37
38 wl_list_for_each(g, &client->global_list, link) {
39 if (strcmp(g->interface, "wl_subcompositor"))
40 continue;
41
42 if (global_sub)
43 assert(0 && "multiple wl_subcompositor objects");
44
45 global_sub = g;
46 }
47
48 assert(global_sub && "no wl_subcompositor found");
49
50 assert(global_sub->version == 1);
51
52 sub = wl_registry_bind(client->wl_registry, global_sub->name,
53 &wl_subcompositor_interface, 1);
54 assert(sub);
55
56 return sub;
57}
58
59static struct wl_shell *
60get_wl_shell(struct client *client)
61{
62 struct global *g;
63 struct global *global = NULL;
64 struct wl_shell *shell;
65
66 wl_list_for_each(g, &client->global_list, link) {
67 if (strcmp(g->interface, "wl_shell"))
68 continue;
69
70 if (global)
71 assert(0 && "multiple wl_shell objects");
72
73 global = g;
74 }
75
76 assert(global && "no wl_shell found");
77
78 shell = wl_registry_bind(client->wl_registry, global->name,
79 &wl_shell_interface, 1);
80 assert(shell);
81
82 return shell;
83}
84
85TEST(test_role_conflict_sub_wlshell)
86{
87 struct client *client;
88 struct wl_subcompositor *subco;
89 struct wl_surface *child;
90 struct wl_subsurface *sub;
91 struct wl_shell *shell;
92 struct wl_shell_surface *shsurf;
93
94 client = client_create(100, 50, 123, 77);
95 assert(client);
96
97 subco = get_subcompositor(client);
98 shell = get_wl_shell(client);
99
100 child = wl_compositor_create_surface(client->wl_compositor);
101 assert(child);
102 sub = wl_subcompositor_get_subsurface(subco, child,
103 client->surface->wl_surface);
104 assert(sub);
105
106 shsurf = wl_shell_get_shell_surface(shell, child);
107 assert(shsurf);
108
109 expect_protocol_error(client, &wl_shell_interface,
110 WL_SHELL_ERROR_ROLE);
111}
112
113TEST(test_role_conflict_wlshell_sub)
114{
115 struct client *client;
116 struct wl_subcompositor *subco;
117 struct wl_surface *child;
118 struct wl_subsurface *sub;
119 struct wl_shell *shell;
120 struct wl_shell_surface *shsurf;
121
122 client = client_create(100, 50, 123, 77);
123 assert(client);
124
125 subco = get_subcompositor(client);
126 shell = get_wl_shell(client);
127
128 child = wl_compositor_create_surface(client->wl_compositor);
129 assert(child);
130 shsurf = wl_shell_get_shell_surface(shell, child);
131 assert(shsurf);
132
133 sub = wl_subcompositor_get_subsurface(subco, child,
134 client->surface->wl_surface);
135 assert(sub);
136
137 expect_protocol_error(client, &wl_subcompositor_interface,
138 WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE);
139}