Pekka Paalanen | e844bf2 | 2013-04-25 13:57:43 +0300 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright © 2012 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 <string.h> |
| 24 | |
| 25 | #include "weston-test-client-helper.h" |
| 26 | #include "subsurface-client-protocol.h" |
| 27 | |
| 28 | #define NUM_SUBSURFACES 3 |
| 29 | |
| 30 | struct compound_surface { |
| 31 | struct wl_subcompositor *subco; |
| 32 | struct wl_surface *parent; |
| 33 | struct wl_surface *child[NUM_SUBSURFACES]; |
| 34 | struct wl_subsurface *sub[NUM_SUBSURFACES]; |
| 35 | }; |
| 36 | |
| 37 | static struct wl_subcompositor * |
| 38 | get_subcompositor(struct client *client) |
| 39 | { |
| 40 | struct global *g; |
| 41 | struct global *global_sub = NULL; |
| 42 | struct wl_subcompositor *sub; |
| 43 | |
| 44 | wl_list_for_each(g, &client->global_list, link) { |
| 45 | if (strcmp(g->interface, "wl_subcompositor")) |
| 46 | continue; |
| 47 | |
| 48 | if (global_sub) |
| 49 | assert(0 && "multiple wl_subcompositor objects"); |
| 50 | |
| 51 | global_sub = g; |
| 52 | } |
| 53 | |
| 54 | assert(global_sub && "no wl_subcompositor found"); |
| 55 | |
| 56 | assert(global_sub->version == 1); |
| 57 | |
| 58 | sub = wl_registry_bind(client->wl_registry, global_sub->name, |
| 59 | &wl_subcompositor_interface, 1); |
| 60 | assert(sub); |
| 61 | |
| 62 | return sub; |
| 63 | } |
| 64 | |
| 65 | static void |
| 66 | populate_compound_surface(struct compound_surface *com, struct client *client) |
| 67 | { |
| 68 | int i; |
| 69 | |
| 70 | com->subco = get_subcompositor(client); |
| 71 | |
| 72 | com->parent = wl_compositor_create_surface(client->wl_compositor); |
| 73 | |
| 74 | for (i = 0; i < NUM_SUBSURFACES; i++) { |
| 75 | com->child[i] = |
| 76 | wl_compositor_create_surface(client->wl_compositor); |
| 77 | com->sub[i] = |
| 78 | wl_subcompositor_get_subsurface(com->subco, |
| 79 | com->child[i], |
| 80 | com->parent); |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | TEST(test_subsurface_basic_protocol) |
| 85 | { |
| 86 | struct client *client; |
| 87 | struct compound_surface com1; |
| 88 | struct compound_surface com2; |
| 89 | |
| 90 | client = client_create(100, 50, 123, 77); |
| 91 | assert(client); |
| 92 | |
| 93 | populate_compound_surface(&com1, client); |
| 94 | populate_compound_surface(&com2, client); |
| 95 | |
| 96 | client_roundtrip(client); |
| 97 | } |
| 98 | |
| 99 | TEST(test_subsurface_position_protocol) |
| 100 | { |
| 101 | struct client *client; |
| 102 | struct compound_surface com; |
| 103 | int i; |
| 104 | |
| 105 | client = client_create(100, 50, 123, 77); |
| 106 | assert(client); |
| 107 | |
| 108 | populate_compound_surface(&com, client); |
| 109 | for (i = 0; i < NUM_SUBSURFACES; i++) |
| 110 | wl_subsurface_set_position(com.sub[i], |
| 111 | (i + 2) * 20, (i + 2) * 10); |
| 112 | |
| 113 | client_roundtrip(client); |
| 114 | } |
| 115 | |
| 116 | TEST(test_subsurface_placement_protocol) |
| 117 | { |
| 118 | struct client *client; |
| 119 | struct compound_surface com; |
| 120 | |
| 121 | client = client_create(100, 50, 123, 77); |
| 122 | assert(client); |
| 123 | |
| 124 | populate_compound_surface(&com, client); |
| 125 | |
| 126 | wl_subsurface_place_above(com.sub[0], com.child[1]); |
| 127 | wl_subsurface_place_above(com.sub[1], com.parent); |
| 128 | wl_subsurface_place_below(com.sub[2], com.child[0]); |
| 129 | wl_subsurface_place_below(com.sub[1], com.parent); |
| 130 | |
| 131 | client_roundtrip(client); |
| 132 | } |
| 133 | |
| 134 | FAIL_TEST(test_subsurface_paradox) |
| 135 | { |
| 136 | struct client *client; |
| 137 | struct wl_surface *parent; |
| 138 | struct wl_subcompositor *subco; |
| 139 | |
| 140 | client = client_create(100, 50, 123, 77); |
| 141 | assert(client); |
| 142 | |
| 143 | subco = get_subcompositor(client); |
| 144 | parent = wl_compositor_create_surface(client->wl_compositor); |
| 145 | |
| 146 | /* surface is its own parent */ |
| 147 | wl_subcompositor_get_subsurface(subco, parent, parent); |
| 148 | |
| 149 | client_roundtrip(client); |
| 150 | } |
| 151 | |
| 152 | FAIL_TEST(test_subsurface_identical_link) |
| 153 | { |
| 154 | struct client *client; |
| 155 | struct compound_surface com; |
| 156 | |
| 157 | client = client_create(100, 50, 123, 77); |
| 158 | assert(client); |
| 159 | |
| 160 | populate_compound_surface(&com, client); |
| 161 | |
| 162 | /* surface is already a subsurface */ |
| 163 | wl_subcompositor_get_subsurface(com.subco, com.child[0], com.parent); |
| 164 | |
| 165 | client_roundtrip(client); |
| 166 | } |
| 167 | |
| 168 | FAIL_TEST(test_subsurface_change_link) |
| 169 | { |
| 170 | struct client *client; |
| 171 | struct compound_surface com; |
| 172 | struct wl_surface *stranger; |
| 173 | |
| 174 | client = client_create(100, 50, 123, 77); |
| 175 | assert(client); |
| 176 | |
| 177 | stranger = wl_compositor_create_surface(client->wl_compositor); |
| 178 | populate_compound_surface(&com, client); |
| 179 | |
| 180 | /* surface is already a subsurface */ |
| 181 | wl_subcompositor_get_subsurface(com.subco, com.child[0], stranger); |
| 182 | |
| 183 | client_roundtrip(client); |
| 184 | } |
| 185 | |
| 186 | TEST(test_subsurface_nesting) |
| 187 | { |
| 188 | struct client *client; |
| 189 | struct compound_surface com; |
| 190 | struct wl_surface *stranger; |
| 191 | |
| 192 | client = client_create(100, 50, 123, 77); |
| 193 | assert(client); |
| 194 | |
| 195 | stranger = wl_compositor_create_surface(client->wl_compositor); |
| 196 | populate_compound_surface(&com, client); |
| 197 | |
| 198 | /* parent is a sub-surface */ |
| 199 | wl_subcompositor_get_subsurface(com.subco, stranger, com.child[0]); |
| 200 | |
| 201 | client_roundtrip(client); |
| 202 | } |
| 203 | |
| 204 | TEST(test_subsurface_nesting_parent) |
| 205 | { |
| 206 | struct client *client; |
| 207 | struct compound_surface com; |
| 208 | struct wl_surface *stranger; |
| 209 | |
| 210 | client = client_create(100, 50, 123, 77); |
| 211 | assert(client); |
| 212 | |
| 213 | stranger = wl_compositor_create_surface(client->wl_compositor); |
| 214 | populate_compound_surface(&com, client); |
| 215 | |
| 216 | /* surface is already a parent */ |
| 217 | wl_subcompositor_get_subsurface(com.subco, com.parent, stranger); |
| 218 | |
| 219 | client_roundtrip(client); |
| 220 | } |
| 221 | |
| 222 | FAIL_TEST(test_subsurface_place_above_stranger) |
| 223 | { |
| 224 | struct client *client; |
| 225 | struct compound_surface com; |
| 226 | struct wl_surface *stranger; |
| 227 | |
| 228 | client = client_create(100, 50, 123, 77); |
| 229 | assert(client); |
| 230 | |
| 231 | stranger = wl_compositor_create_surface(client->wl_compositor); |
| 232 | populate_compound_surface(&com, client); |
| 233 | |
| 234 | /* bad sibling */ |
| 235 | wl_subsurface_place_above(com.sub[0], stranger); |
| 236 | |
| 237 | client_roundtrip(client); |
| 238 | } |
| 239 | |
| 240 | FAIL_TEST(test_subsurface_place_below_stranger) |
| 241 | { |
| 242 | struct client *client; |
| 243 | struct compound_surface com; |
| 244 | struct wl_surface *stranger; |
| 245 | |
| 246 | client = client_create(100, 50, 123, 77); |
| 247 | assert(client); |
| 248 | |
| 249 | stranger = wl_compositor_create_surface(client->wl_compositor); |
| 250 | populate_compound_surface(&com, client); |
| 251 | |
| 252 | /* bad sibling */ |
| 253 | wl_subsurface_place_below(com.sub[0], stranger); |
| 254 | |
| 255 | client_roundtrip(client); |
| 256 | } |
| 257 | |
| 258 | FAIL_TEST(test_subsurface_place_above_foreign) |
| 259 | { |
| 260 | struct client *client; |
| 261 | struct compound_surface com1; |
| 262 | struct compound_surface com2; |
| 263 | |
| 264 | client = client_create(100, 50, 123, 77); |
| 265 | assert(client); |
| 266 | |
| 267 | populate_compound_surface(&com1, client); |
| 268 | populate_compound_surface(&com2, client); |
| 269 | |
| 270 | /* bad sibling */ |
| 271 | wl_subsurface_place_above(com1.sub[0], com2.child[0]); |
| 272 | |
| 273 | client_roundtrip(client); |
| 274 | } |
| 275 | |
| 276 | FAIL_TEST(test_subsurface_place_below_foreign) |
| 277 | { |
| 278 | struct client *client; |
| 279 | struct compound_surface com1; |
| 280 | struct compound_surface com2; |
| 281 | |
| 282 | client = client_create(100, 50, 123, 77); |
| 283 | assert(client); |
| 284 | |
| 285 | populate_compound_surface(&com1, client); |
| 286 | populate_compound_surface(&com2, client); |
| 287 | |
| 288 | /* bad sibling */ |
| 289 | wl_subsurface_place_below(com1.sub[0], com2.child[0]); |
| 290 | |
| 291 | client_roundtrip(client); |
| 292 | } |
| 293 | |
| 294 | TEST(test_subsurface_destroy_protocol) |
| 295 | { |
| 296 | struct client *client; |
| 297 | struct compound_surface com; |
| 298 | |
| 299 | client = client_create(100, 50, 123, 77); |
| 300 | assert(client); |
| 301 | |
| 302 | populate_compound_surface(&com, client); |
| 303 | |
| 304 | /* not needed anymore */ |
| 305 | wl_subcompositor_destroy(com.subco); |
| 306 | |
| 307 | /* detach child from parent */ |
| 308 | wl_subsurface_destroy(com.sub[0]); |
| 309 | |
| 310 | /* destroy: child, parent */ |
| 311 | wl_surface_destroy(com.child[1]); |
| 312 | wl_surface_destroy(com.parent); |
| 313 | |
| 314 | /* destroy: parent, child */ |
| 315 | wl_surface_destroy(com.child[2]); |
| 316 | |
| 317 | /* destroy: sub, child */ |
| 318 | wl_surface_destroy(com.child[0]); |
| 319 | |
| 320 | /* 2x destroy: child, sub */ |
| 321 | wl_subsurface_destroy(com.sub[2]); |
| 322 | wl_subsurface_destroy(com.sub[1]); |
| 323 | |
| 324 | client_roundtrip(client); |
| 325 | } |