From 5eb5c4991d07b9f41f1236a6ef06c4a2ece47d1b Mon Sep 17 00:00:00 2001 From: Derek Foreman Date: Wed, 24 Sep 2025 10:38:39 -0500 Subject: [PATCH] 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 --- tests/roles-test.c | 32 ++----------------- tests/subsurface-shot-test.c | 38 +++------------------- tests/subsurface-test.c | 52 +++++++------------------------ tests/weston-test-client-helper.c | 28 +++++++++++++++++ tests/weston-test-client-helper.h | 3 ++ 5 files changed, 50 insertions(+), 103 deletions(-) diff --git a/tests/roles-test.c b/tests/roles-test.c index 92370ddaf..88d90c044 100644 --- a/tests/roles-test.c +++ b/tests/roles-test.c @@ -48,34 +48,6 @@ fixture_setup(struct weston_test_harness *harness) } 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 * 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); test_assert_ptr_not_null(client); - subco = get_subcompositor(client); + subco = client_get_subcompositor(client); xdg_wm_base = get_xdg_wm_base(client); 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); test_assert_ptr_not_null(client); - subco = get_subcompositor(client); + subco = client_get_subcompositor(client); xdg_wm_base = get_xdg_wm_base(client); child = wl_compositor_create_surface(client->wl_compositor); diff --git a/tests/subsurface-shot-test.c b/tests/subsurface-shot-test.c index 5da72ec38..b9071f7a7 100644 --- a/tests/subsurface-shot-test.c +++ b/tests/subsurface-shot-test.c @@ -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); -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 check_screen(struct client *client, const char *ref_image, @@ -150,7 +122,7 @@ TEST(subsurface_recursive_unmap) client = create_client_and_test_surface(100, 50, 100, 100); test_assert_ptr_not_null(client); - subco = get_subcompositor(client); + subco = client_get_subcompositor(client); /* move the pointer clearly away from our screenshooting area */ 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); test_assert_ptr_not_null(client); - subco = get_subcompositor(client); + subco = client_get_subcompositor(client); /* move the pointer clearly away from our screenshooting area */ 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); test_assert_ptr_not_null(client); - subco = get_subcompositor(client); + subco = client_get_subcompositor(client); /* move the pointer clearly away from our screenshooting area */ 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); test_assert_ptr_not_null(client); - subco = get_subcompositor(client); + subco = client_get_subcompositor(client); viewporter = bind_to_singleton_global(client, &wp_viewporter_interface, 1); @@ -533,7 +505,7 @@ TEST(subsurface_desync_commit) client = create_client_and_test_surface(100, 50, 100, 100); test_assert_ptr_not_null(client); - subco = get_subcompositor(client); + subco = client_get_subcompositor(client); /* make the parent surface red */ surf[0] = client->surface->wl_surface; diff --git a/tests/subsurface-test.c b/tests/subsurface-test.c index 24dea5b2c..973146689 100644 --- a/tests/subsurface-test.c +++ b/tests/subsurface-test.c @@ -56,40 +56,12 @@ struct compound_surface { 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 populate_compound_surface(struct compound_surface *com, struct client *client) { int i; - com->subco = get_subcompositor(client); + com->subco = client_get_subcompositor(client); 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); test_assert_ptr_not_null(client); - subco = get_subcompositor(client); + subco = client_get_subcompositor(client); parent = wl_compositor_create_surface(client->wl_compositor); /* surface is its own parent */ @@ -326,7 +298,7 @@ TEST(test_subsurface_loop_paradox) client = create_client_and_test_surface(100, 50, 123, 77); 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[1] = 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); - subco = get_subcompositor(client); + subco = client_get_subcompositor(client); grandchild = wl_compositor_create_surface(client->wl_compositor); 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); - subco = get_subcompositor(client); + subco = client_get_subcompositor(client); grandchild = wl_compositor_create_surface(client->wl_compositor); 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); - subco = get_subcompositor(client); + subco = client_get_subcompositor(client); grandchild = wl_compositor_create_surface(client->wl_compositor); 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); - subco = get_subcompositor(client); + subco = client_get_subcompositor(client); grandchild = wl_compositor_create_surface(client->wl_compositor); 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); - subco = get_subcompositor(client); + subco = client_get_subcompositor(client); grandchild = wl_compositor_create_surface(client->wl_compositor); 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); - subco = get_subcompositor(client); + subco = client_get_subcompositor(client); grandchild = wl_compositor_create_surface(client->wl_compositor); 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); - subco = get_subcompositor(client); + subco = client_get_subcompositor(client); grandchild = wl_compositor_create_surface(client->wl_compositor); 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); - subco = get_subcompositor(client); + subco = client_get_subcompositor(client); grandchild = wl_compositor_create_surface(client->wl_compositor); 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; int i; - subco = get_subcompositor(client); + subco = client_get_subcompositor(client); for (i = 0; i < n; i++) surfs[i] = wl_compositor_create_surface(client->wl_compositor); diff --git a/tests/weston-test-client-helper.c b/tests/weston-test-client-helper.c index 66c41c4f2..6b09a351a 100644 --- a/tests/weston-test-client-helper.c +++ b/tests/weston-test-client-helper.c @@ -2597,3 +2597,31 @@ client_release_breakpoint(struct client *client, suite_data->breakpoints.in_client_break = false; 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; +} diff --git a/tests/weston-test-client-helper.h b/tests/weston-test-client-helper.h index 7de02ebc1..3244acc76 100644 --- a/tests/weston-test-client-helper.h +++ b/tests/weston-test-client-helper.h @@ -423,4 +423,7 @@ void assert_surface_matches(struct wet_testsuite_data *suite_data, struct weston_surface *s, struct surface *c); +struct wl_subcompositor * +client_get_subcompositor(struct client *client); + #endif