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