Following on from b8c16c995b, extend the family tree being tested by
place_above and place_below a little, ensuring that subsurfaces can't be
placed above or below surfaces which are related to them, but aren't
their immediate parent or sibling.

Signed-off-by: Daniel Stone <[email protected]>
Cc: Arnaud Vrac <[email protected]>
Cc: Pekka Paalanen <[email protected]>
---
 tests/subsurface-test.c | 142 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 142 insertions(+)

diff --git a/tests/subsurface-test.c b/tests/subsurface-test.c
index 03ff539..edb0842 100644
--- a/tests/subsurface-test.c
+++ b/tests/subsurface-test.c
@@ -272,6 +272,77 @@ TEST(test_subsurface_place_above_nested_parent)
        client_roundtrip(client);
 }
 
+TEST(test_subsurface_place_above_grandparent)
+{
+       struct client *client;
+       struct compound_surface com;
+       struct wl_surface *grandchild;
+       struct wl_subsurface *sub;
+       struct wl_subcompositor *subco;
+
+       client = create_client_and_test_surface(100, 50, 123, 77);
+       assert(client);
+
+       populate_compound_surface(&com, client);
+
+       subco = get_subcompositor(client);
+       grandchild = wl_compositor_create_surface(client->wl_compositor);
+       sub = wl_subcompositor_get_subsurface(subco, grandchild, com.child[0]);
+
+       /* can't place a subsurface above its grandparent */
+       wl_subsurface_place_above(sub, com.parent);
+
+       expect_protocol_error(client, &wl_subsurface_interface,
+                             WL_SUBSURFACE_ERROR_BAD_SURFACE);
+}
+
+TEST(test_subsurface_place_above_great_aunt)
+{
+       struct client *client;
+       struct compound_surface com;
+       struct wl_surface *grandchild;
+       struct wl_subsurface *sub;
+       struct wl_subcompositor *subco;
+
+       client = create_client_and_test_surface(100, 50, 123, 77);
+       assert(client);
+
+       populate_compound_surface(&com, client);
+
+       subco = get_subcompositor(client);
+       grandchild = wl_compositor_create_surface(client->wl_compositor);
+       sub = wl_subcompositor_get_subsurface(subco, grandchild, com.child[0]);
+
+       /* can't place a subsurface above its parents' siblings */
+       wl_subsurface_place_above(sub, com.child[1]);
+
+       expect_protocol_error(client, &wl_subsurface_interface,
+                             WL_SUBSURFACE_ERROR_BAD_SURFACE);
+}
+
+TEST(test_subsurface_place_above_child)
+{
+       struct client *client;
+       struct compound_surface com;
+       struct wl_surface *grandchild;
+       struct wl_subcompositor *subco;
+
+       client = create_client_and_test_surface(100, 50, 123, 77);
+       assert(client);
+
+       populate_compound_surface(&com, client);
+
+       subco = get_subcompositor(client);
+       grandchild = wl_compositor_create_surface(client->wl_compositor);
+       wl_subcompositor_get_subsurface(subco, grandchild, com.child[0]);
+
+       /* can't place a subsurface above its own child subsurface */
+       wl_subsurface_place_above(com.sub[0], grandchild);
+
+       expect_protocol_error(client, &wl_subsurface_interface,
+                             WL_SUBSURFACE_ERROR_BAD_SURFACE);
+}
+
 TEST(test_subsurface_place_below_nested_parent)
 {
        struct client *client;
@@ -294,6 +365,77 @@ TEST(test_subsurface_place_below_nested_parent)
        client_roundtrip(client);
 }
 
+TEST(test_subsurface_place_below_grandparent)
+{
+       struct client *client;
+       struct compound_surface com;
+       struct wl_surface *grandchild;
+       struct wl_subsurface *sub;
+       struct wl_subcompositor *subco;
+
+       client = create_client_and_test_surface(100, 50, 123, 77);
+       assert(client);
+
+       populate_compound_surface(&com, client);
+
+       subco = get_subcompositor(client);
+       grandchild = wl_compositor_create_surface(client->wl_compositor);
+       sub = wl_subcompositor_get_subsurface(subco, grandchild, com.child[0]);
+
+       /* can't place a subsurface below its grandparent */
+       wl_subsurface_place_below(sub, com.parent);
+
+       expect_protocol_error(client, &wl_subsurface_interface,
+                             WL_SUBSURFACE_ERROR_BAD_SURFACE);
+}
+
+TEST(test_subsurface_place_below_great_aunt)
+{
+       struct client *client;
+       struct compound_surface com;
+       struct wl_surface *grandchild;
+       struct wl_subsurface *sub;
+       struct wl_subcompositor *subco;
+
+       client = create_client_and_test_surface(100, 50, 123, 77);
+       assert(client);
+
+       populate_compound_surface(&com, client);
+
+       subco = get_subcompositor(client);
+       grandchild = wl_compositor_create_surface(client->wl_compositor);
+       sub = wl_subcompositor_get_subsurface(subco, grandchild, com.child[0]);
+
+       /* can't place a subsurface below its parents' siblings */
+       wl_subsurface_place_below(sub, com.child[1]);
+
+       expect_protocol_error(client, &wl_subsurface_interface,
+                             WL_SUBSURFACE_ERROR_BAD_SURFACE);
+}
+
+TEST(test_subsurface_place_below_child)
+{
+       struct client *client;
+       struct compound_surface com;
+       struct wl_surface *grandchild;
+       struct wl_subcompositor *subco;
+
+       client = create_client_and_test_surface(100, 50, 123, 77);
+       assert(client);
+
+       populate_compound_surface(&com, client);
+
+       subco = get_subcompositor(client);
+       grandchild = wl_compositor_create_surface(client->wl_compositor);
+       wl_subcompositor_get_subsurface(subco, grandchild, com.child[0]);
+
+       /* can't place a subsurface below its own child subsurface */
+       wl_subsurface_place_below(com.sub[0], grandchild);
+
+       expect_protocol_error(client, &wl_subsurface_interface,
+                             WL_SUBSURFACE_ERROR_BAD_SURFACE);
+}
+
 TEST(test_subsurface_place_above_stranger)
 {
        struct client *client;
-- 
2.9.3

_______________________________________________
wayland-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/wayland-devel

Reply via email to