• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright © 2014 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 <stdio.h>
29 #include <string.h>
30 #include <assert.h>
31 
32 #include "weston-test-client-helper.h"
33 #include "weston-test-fixture-compositor.h"
34 
35 static enum test_result_code
fixture_setup(struct weston_test_harness * harness)36 fixture_setup(struct weston_test_harness *harness)
37 {
38 	struct compositor_setup setup;
39 
40 	compositor_setup_defaults(&setup);
41 	setup.logging_scopes = "log,proto,test-harness-plugin";
42 
43 	return weston_test_harness_execute_as_client(harness, &setup);
44 }
45 DECLARE_FIXTURE_SETUP(fixture_setup);
46 
47 static struct wl_subcompositor *
get_subcompositor(struct client * client)48 get_subcompositor(struct client *client)
49 {
50 	struct global *g;
51 	struct global *global_sub = NULL;
52 	struct wl_subcompositor *sub;
53 
54 	wl_list_for_each(g, &client->global_list, link) {
55 		if (strcmp(g->interface, "wl_subcompositor"))
56 			continue;
57 
58 		if (global_sub)
59 			assert(0 && "multiple wl_subcompositor objects");
60 
61 		global_sub = g;
62 	}
63 
64 	assert(global_sub && "no wl_subcompositor found");
65 
66 	assert(global_sub->version == 1);
67 
68 	sub = wl_registry_bind(client->wl_registry, global_sub->name,
69 			       &wl_subcompositor_interface, 1);
70 	assert(sub);
71 
72 	return sub;
73 }
74 
75 static struct wl_shell *
get_wl_shell(struct client * client)76 get_wl_shell(struct client *client)
77 {
78 	struct global *g;
79 	struct global *global = NULL;
80 	struct wl_shell *shell;
81 
82 	wl_list_for_each(g, &client->global_list, link) {
83 		if (strcmp(g->interface, "wl_shell"))
84 			continue;
85 
86 		if (global)
87 			assert(0 && "multiple wl_shell objects");
88 
89 		global = g;
90 	}
91 
92 	assert(global && "no wl_shell found");
93 
94 	shell = wl_registry_bind(client->wl_registry, global->name,
95 				 &wl_shell_interface, 1);
96 	assert(shell);
97 
98 	return shell;
99 }
100 
TEST(test_role_conflict_sub_wlshell)101 TEST(test_role_conflict_sub_wlshell)
102 {
103 	struct client *client;
104 	struct wl_subcompositor *subco;
105 	struct wl_surface *child;
106 	struct wl_subsurface *sub;
107 	struct wl_shell *shell;
108 	struct wl_shell_surface *shsurf;
109 
110 	client = create_client_and_test_surface(100, 50, 123, 77);
111 	assert(client);
112 
113 	subco = get_subcompositor(client);
114 	shell = get_wl_shell(client);
115 
116 	child = wl_compositor_create_surface(client->wl_compositor);
117 	assert(child);
118 	sub = wl_subcompositor_get_subsurface(subco, child,
119 					      client->surface->wl_surface);
120 	assert(sub);
121 
122 	shsurf = wl_shell_get_shell_surface(shell, child);
123 	assert(shsurf);
124 
125 	expect_protocol_error(client, &wl_shell_interface,
126 			      WL_SHELL_ERROR_ROLE);
127 }
128 
TEST(test_role_conflict_wlshell_sub)129 TEST(test_role_conflict_wlshell_sub)
130 {
131 	struct client *client;
132 	struct wl_subcompositor *subco;
133 	struct wl_surface *child;
134 	struct wl_subsurface *sub;
135 	struct wl_shell *shell;
136 	struct wl_shell_surface *shsurf;
137 
138 	client = create_client_and_test_surface(100, 50, 123, 77);
139 	assert(client);
140 
141 	subco = get_subcompositor(client);
142 	shell = get_wl_shell(client);
143 
144 	child = wl_compositor_create_surface(client->wl_compositor);
145 	assert(child);
146 	shsurf = wl_shell_get_shell_surface(shell, child);
147 	assert(shsurf);
148 
149 	sub = wl_subcompositor_get_subsurface(subco, child,
150 					      client->surface->wl_surface);
151 	assert(sub);
152 
153 	expect_protocol_error(client, &wl_subcompositor_interface,
154 			      WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE);
155 }
156