tests: Refactor get_subcompositor

We open code this in several tests. Move a single implementation to
weston-test-client-helper instead.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
This commit is contained in:
Derek Foreman 2025-09-24 10:38:39 -05:00
parent e4be014f93
commit 5eb5c4991d
5 changed files with 50 additions and 103 deletions

View file

@ -48,34 +48,6 @@ fixture_setup(struct weston_test_harness *harness)
} }
DECLARE_FIXTURE_SETUP(fixture_setup); DECLARE_FIXTURE_SETUP(fixture_setup);
static struct wl_subcompositor *
get_subcompositor(struct client *client)
{
struct global *g;
struct global *global_sub = NULL;
struct wl_subcompositor *sub;
wl_list_for_each(g, &client->global_list, link) {
if (strcmp(g->interface, "wl_subcompositor"))
continue;
if (global_sub)
test_assert_not_reached("multiple wl_subcompositor objects");
global_sub = g;
}
test_assert_ptr_not_null(global_sub);
test_assert_u32_eq(global_sub->version, 1);
sub = wl_registry_bind(client->wl_registry, global_sub->name,
&wl_subcompositor_interface, 1);
test_assert_ptr_not_null(sub);
return sub;
}
static struct xdg_wm_base * static struct xdg_wm_base *
get_xdg_wm_base(struct client *client) get_xdg_wm_base(struct client *client)
{ {
@ -114,7 +86,7 @@ TEST(test_role_conflict_sub_wlshell)
client = create_client_and_test_surface(100, 50, 123, 77); client = create_client_and_test_surface(100, 50, 123, 77);
test_assert_ptr_not_null(client); test_assert_ptr_not_null(client);
subco = get_subcompositor(client); subco = client_get_subcompositor(client);
xdg_wm_base = get_xdg_wm_base(client); xdg_wm_base = get_xdg_wm_base(client);
child = wl_compositor_create_surface(client->wl_compositor); child = wl_compositor_create_surface(client->wl_compositor);
@ -152,7 +124,7 @@ TEST(test_role_conflict_wlshell_sub)
client = create_client_and_test_surface(100, 50, 123, 77); client = create_client_and_test_surface(100, 50, 123, 77);
test_assert_ptr_not_null(client); test_assert_ptr_not_null(client);
subco = get_subcompositor(client); subco = client_get_subcompositor(client);
xdg_wm_base = get_xdg_wm_base(client); xdg_wm_base = get_xdg_wm_base(client);
child = wl_compositor_create_surface(client->wl_compositor); child = wl_compositor_create_surface(client->wl_compositor);

View file

@ -71,34 +71,6 @@ fixture_setup(struct weston_test_harness *harness, const struct setup_args *arg)
} }
DECLARE_FIXTURE_SETUP_WITH_ARG(fixture_setup, my_setup_args, meta); DECLARE_FIXTURE_SETUP_WITH_ARG(fixture_setup, my_setup_args, meta);
static struct wl_subcompositor *
get_subcompositor(struct client *client)
{
struct global *g;
struct global *global_sub = NULL;
struct wl_subcompositor *sub;
wl_list_for_each(g, &client->global_list, link) {
if (strcmp(g->interface, "wl_subcompositor"))
continue;
if (global_sub)
test_assert_not_reached("multiple wl_subcompositor objects");
global_sub = g;
}
test_assert_ptr_not_null(global_sub);
test_assert_u32_eq(global_sub->version, 1);
sub = wl_registry_bind(client->wl_registry, global_sub->name,
&wl_subcompositor_interface, 1);
test_assert_ptr_not_null(sub);
return sub;
}
static int static int
check_screen(struct client *client, check_screen(struct client *client,
const char *ref_image, const char *ref_image,
@ -150,7 +122,7 @@ TEST(subsurface_recursive_unmap)
client = create_client_and_test_surface(100, 50, 100, 100); client = create_client_and_test_surface(100, 50, 100, 100);
test_assert_ptr_not_null(client); test_assert_ptr_not_null(client);
subco = get_subcompositor(client); subco = client_get_subcompositor(client);
/* move the pointer clearly away from our screenshooting area */ /* move the pointer clearly away from our screenshooting area */
weston_test_move_pointer(client->test->weston_test, 0, 1, 0, 2, 30); weston_test_move_pointer(client->test->weston_test, 0, 1, 0, 2, 30);
@ -242,7 +214,7 @@ TEST(subsurface_z_order)
client = create_client_and_test_surface(100, 50, 100, 100); client = create_client_and_test_surface(100, 50, 100, 100);
test_assert_ptr_not_null(client); test_assert_ptr_not_null(client);
subco = get_subcompositor(client); subco = client_get_subcompositor(client);
/* move the pointer clearly away from our screenshooting area */ /* move the pointer clearly away from our screenshooting area */
weston_test_move_pointer(client->test->weston_test, 0, 1, 0, 2, 30); weston_test_move_pointer(client->test->weston_test, 0, 1, 0, 2, 30);
@ -333,7 +305,7 @@ TEST(subsurface_sync_damage_buffer)
client = create_client_and_test_surface(100, 50, 100, 100); client = create_client_and_test_surface(100, 50, 100, 100);
test_assert_ptr_not_null(client); test_assert_ptr_not_null(client);
subco = get_subcompositor(client); subco = client_get_subcompositor(client);
/* move the pointer clearly away from our screenshooting area */ /* move the pointer clearly away from our screenshooting area */
weston_test_move_pointer(client->test->weston_test, 0, 1, 0, 2, 30); weston_test_move_pointer(client->test->weston_test, 0, 1, 0, 2, 30);
@ -405,7 +377,7 @@ TEST(subsurface_empty_mapping)
client = create_client_and_test_surface(100, 50, 100, 100); client = create_client_and_test_surface(100, 50, 100, 100);
test_assert_ptr_not_null(client); test_assert_ptr_not_null(client);
subco = get_subcompositor(client); subco = client_get_subcompositor(client);
viewporter = bind_to_singleton_global(client, viewporter = bind_to_singleton_global(client,
&wp_viewporter_interface, 1); &wp_viewporter_interface, 1);
@ -533,7 +505,7 @@ TEST(subsurface_desync_commit)
client = create_client_and_test_surface(100, 50, 100, 100); client = create_client_and_test_surface(100, 50, 100, 100);
test_assert_ptr_not_null(client); test_assert_ptr_not_null(client);
subco = get_subcompositor(client); subco = client_get_subcompositor(client);
/* make the parent surface red */ /* make the parent surface red */
surf[0] = client->surface->wl_surface; surf[0] = client->surface->wl_surface;

View file

@ -56,40 +56,12 @@ struct compound_surface {
struct wl_subsurface *sub[NUM_SUBSURFACES]; struct wl_subsurface *sub[NUM_SUBSURFACES];
}; };
static struct wl_subcompositor *
get_subcompositor(struct client *client)
{
struct global *g;
struct global *global_sub = NULL;
struct wl_subcompositor *sub;
wl_list_for_each(g, &client->global_list, link) {
if (strcmp(g->interface, "wl_subcompositor"))
continue;
if (global_sub)
test_assert_not_reached("multiple wl_subcompositor objects");
global_sub = g;
}
test_assert_ptr_not_null(global_sub);
test_assert_u32_eq(global_sub->version, 1);
sub = wl_registry_bind(client->wl_registry, global_sub->name,
&wl_subcompositor_interface, 1);
test_assert_ptr_not_null(sub);
return sub;
}
static void static void
populate_compound_surface(struct compound_surface *com, struct client *client) populate_compound_surface(struct compound_surface *com, struct client *client)
{ {
int i; int i;
com->subco = get_subcompositor(client); com->subco = client_get_subcompositor(client);
com->parent = wl_compositor_create_surface(client->wl_compositor); com->parent = wl_compositor_create_surface(client->wl_compositor);
@ -195,7 +167,7 @@ TEST(test_subsurface_paradox)
client = create_client_and_test_surface(100, 50, 123, 77); client = create_client_and_test_surface(100, 50, 123, 77);
test_assert_ptr_not_null(client); test_assert_ptr_not_null(client);
subco = get_subcompositor(client); subco = client_get_subcompositor(client);
parent = wl_compositor_create_surface(client->wl_compositor); parent = wl_compositor_create_surface(client->wl_compositor);
/* surface is its own parent */ /* surface is its own parent */
@ -326,7 +298,7 @@ TEST(test_subsurface_loop_paradox)
client = create_client_and_test_surface(100, 50, 123, 77); client = create_client_and_test_surface(100, 50, 123, 77);
test_assert_ptr_not_null(client); test_assert_ptr_not_null(client);
subco = get_subcompositor(client); subco = client_get_subcompositor(client);
surface[0] = wl_compositor_create_surface(client->wl_compositor); surface[0] = wl_compositor_create_surface(client->wl_compositor);
surface[1] = wl_compositor_create_surface(client->wl_compositor); surface[1] = wl_compositor_create_surface(client->wl_compositor);
surface[2] = wl_compositor_create_surface(client->wl_compositor); surface[2] = wl_compositor_create_surface(client->wl_compositor);
@ -363,7 +335,7 @@ TEST(test_subsurface_place_above_nested_parent)
populate_compound_surface(&com, client); populate_compound_surface(&com, client);
subco = get_subcompositor(client); subco = client_get_subcompositor(client);
grandchild = wl_compositor_create_surface(client->wl_compositor); grandchild = wl_compositor_create_surface(client->wl_compositor);
sub = wl_subcompositor_get_subsurface(subco, grandchild, com.child[0]); sub = wl_subcompositor_get_subsurface(subco, grandchild, com.child[0]);
@ -393,7 +365,7 @@ TEST(test_subsurface_place_above_grandparent)
populate_compound_surface(&com, client); populate_compound_surface(&com, client);
subco = get_subcompositor(client); subco = client_get_subcompositor(client);
grandchild = wl_compositor_create_surface(client->wl_compositor); grandchild = wl_compositor_create_surface(client->wl_compositor);
sub = wl_subcompositor_get_subsurface(subco, grandchild, com.child[0]); sub = wl_subcompositor_get_subsurface(subco, grandchild, com.child[0]);
@ -425,7 +397,7 @@ TEST(test_subsurface_place_above_great_aunt)
populate_compound_surface(&com, client); populate_compound_surface(&com, client);
subco = get_subcompositor(client); subco = client_get_subcompositor(client);
grandchild = wl_compositor_create_surface(client->wl_compositor); grandchild = wl_compositor_create_surface(client->wl_compositor);
sub = wl_subcompositor_get_subsurface(subco, grandchild, com.child[0]); sub = wl_subcompositor_get_subsurface(subco, grandchild, com.child[0]);
@ -457,7 +429,7 @@ TEST(test_subsurface_place_above_child)
populate_compound_surface(&com, client); populate_compound_surface(&com, client);
subco = get_subcompositor(client); subco = client_get_subcompositor(client);
grandchild = wl_compositor_create_surface(client->wl_compositor); grandchild = wl_compositor_create_surface(client->wl_compositor);
sub = wl_subcompositor_get_subsurface(subco, grandchild, com.child[0]); sub = wl_subcompositor_get_subsurface(subco, grandchild, com.child[0]);
@ -489,7 +461,7 @@ TEST(test_subsurface_place_below_nested_parent)
populate_compound_surface(&com, client); populate_compound_surface(&com, client);
subco = get_subcompositor(client); subco = client_get_subcompositor(client);
grandchild = wl_compositor_create_surface(client->wl_compositor); grandchild = wl_compositor_create_surface(client->wl_compositor);
sub = wl_subcompositor_get_subsurface(subco, grandchild, com.child[0]); sub = wl_subcompositor_get_subsurface(subco, grandchild, com.child[0]);
@ -519,7 +491,7 @@ TEST(test_subsurface_place_below_grandparent)
populate_compound_surface(&com, client); populate_compound_surface(&com, client);
subco = get_subcompositor(client); subco = client_get_subcompositor(client);
grandchild = wl_compositor_create_surface(client->wl_compositor); grandchild = wl_compositor_create_surface(client->wl_compositor);
sub = wl_subcompositor_get_subsurface(subco, grandchild, com.child[0]); sub = wl_subcompositor_get_subsurface(subco, grandchild, com.child[0]);
@ -551,7 +523,7 @@ TEST(test_subsurface_place_below_great_aunt)
populate_compound_surface(&com, client); populate_compound_surface(&com, client);
subco = get_subcompositor(client); subco = client_get_subcompositor(client);
grandchild = wl_compositor_create_surface(client->wl_compositor); grandchild = wl_compositor_create_surface(client->wl_compositor);
sub = wl_subcompositor_get_subsurface(subco, grandchild, com.child[0]); sub = wl_subcompositor_get_subsurface(subco, grandchild, com.child[0]);
@ -583,7 +555,7 @@ TEST(test_subsurface_place_below_child)
populate_compound_surface(&com, client); populate_compound_surface(&com, client);
subco = get_subcompositor(client); subco = client_get_subcompositor(client);
grandchild = wl_compositor_create_surface(client->wl_compositor); grandchild = wl_compositor_create_surface(client->wl_compositor);
sub = wl_subcompositor_get_subsurface(subco, grandchild, com.child[0]); sub = wl_subcompositor_get_subsurface(subco, grandchild, com.child[0]);
@ -746,7 +718,7 @@ create_subsurface_tree(struct client *client, struct wl_surface **surfs,
struct wl_subcompositor *subco; struct wl_subcompositor *subco;
int i; int i;
subco = get_subcompositor(client); subco = client_get_subcompositor(client);
for (i = 0; i < n; i++) for (i = 0; i < n; i++)
surfs[i] = wl_compositor_create_surface(client->wl_compositor); surfs[i] = wl_compositor_create_surface(client->wl_compositor);

View file

@ -2597,3 +2597,31 @@ client_release_breakpoint(struct client *client,
suite_data->breakpoints.in_client_break = false; suite_data->breakpoints.in_client_break = false;
wet_test_post_sem(&suite_data->breakpoints.server_release); wet_test_post_sem(&suite_data->breakpoints.server_release);
} }
struct wl_subcompositor *
client_get_subcompositor(struct client *client)
{
struct global *g;
struct global *global_sub = NULL;
struct wl_subcompositor *sub;
wl_list_for_each(g, &client->global_list, link) {
if (strcmp(g->interface, "wl_subcompositor"))
continue;
if (global_sub)
test_assert_not_reached("multiple wl_subcompositor objects");
global_sub = g;
}
test_assert_ptr_not_null(global_sub);
test_assert_u32_eq(global_sub->version, 1);
sub = wl_registry_bind(client->wl_registry, global_sub->name,
&wl_subcompositor_interface, 1);
test_assert_ptr_not_null(sub);
return sub;
}

View file

@ -423,4 +423,7 @@ void
assert_surface_matches(struct wet_testsuite_data *suite_data, assert_surface_matches(struct wet_testsuite_data *suite_data,
struct weston_surface *s, struct surface *c); struct weston_surface *s, struct surface *c);
struct wl_subcompositor *
client_get_subcompositor(struct client *client);
#endif #endif