tests: client-helper: Add various globals by default

To make them more easily available for tests.

Signed-off-by: Robert Mader <robert.mader@collabora.com>
This commit is contained in:
Robert Mader 2025-09-24 13:56:53 +02:00
parent a60169e239
commit a1c0d33700
5 changed files with 41 additions and 29 deletions

View file

@ -30,7 +30,11 @@ lib_test_client = static_library(
[
'weston-test-client-helper.c',
'weston-test-fixture-compositor.c',
'xdg-client-helper.c',
'xdg-client-helper.c',
presentation_time_client_protocol_h,
presentation_time_protocol_c,
single_pixel_buffer_v1_client_protocol_h,
single_pixel_buffer_v1_protocol_c,
weston_test_client_protocol_h,
weston_test_protocol_c,
weston_output_capture_client_protocol_h,
@ -203,14 +207,7 @@ tests = [
],
},
{ 'name': 'pointer-shot', },
{
'name': 'presentation',
'sources': [
'presentation-test.c',
presentation_time_client_protocol_h,
presentation_time_protocol_c,
],
},
{ 'name': 'presentation', },
{
'name': 'roles',
'sources': [
@ -219,14 +216,7 @@ tests = [
xdg_shell_protocol_c,
],
},
{
'name': 'single-pixel-buffer',
'sources': [
'single-pixel-buffer-test.c',
single_pixel_buffer_v1_client_protocol_h,
single_pixel_buffer_v1_protocol_c,
]
},
{ 'name': 'single-pixel-buffer', },
{ 'name': 'string', },
{ 'name': 'subsurface', },
{ 'name': 'subsurface-shot', },

View file

@ -35,7 +35,6 @@
#include "shared/xalloc.h"
#include "shared/timespec-util.h"
#include "weston-test-client-helper.h"
#include "presentation-time-client-protocol.h"
#include "weston-test-fixture-compositor.h"
#include "weston-test-assert.h"

View file

@ -74,7 +74,6 @@ DECLARE_FIXTURE_SETUP_WITH_ARG(fixture_setup, my_setup_args, meta);
TEST(solid_buffer_argb_u32)
{
struct client *client;
struct wp_single_pixel_buffer_manager_v1 *mgr;
struct wp_viewport *viewport;
struct wl_buffer *buffer;
int done;
@ -85,10 +84,7 @@ TEST(solid_buffer_argb_u32)
viewport = client_create_viewport(client);
wp_viewport_set_destination(viewport, 128, 128);
mgr = bind_to_singleton_global(client,
&wp_single_pixel_buffer_manager_v1_interface,
1);
buffer = wp_single_pixel_buffer_manager_v1_create_u32_rgba_buffer(mgr,
buffer = wp_single_pixel_buffer_manager_v1_create_u32_rgba_buffer(client->single_pixel_manager,
0xcfffffff, /* r */
0x8fffffff, /* g */
0x4fffffff, /* b */
@ -109,7 +105,6 @@ TEST(solid_buffer_argb_u32)
wl_buffer_destroy(buffer);
wp_viewport_destroy(viewport);
wp_single_pixel_buffer_manager_v1_destroy(mgr);
client_destroy(client);
return RESULT_OK;

View file

@ -881,6 +881,10 @@ handle_global(void *data, struct wl_registry *registry,
client->wl_compositor =
wl_registry_bind(registry, id,
&wl_compositor_interface, version);
} else if (strcmp(interface, wl_subcompositor_interface.name) == 0) {
client->wl_subcompositor =
wl_registry_bind(registry, id,
&wl_subcompositor_interface, version);
} else if (strcmp(interface, "wl_seat") == 0) {
input = xzalloc(sizeof *input);
input->client = client;
@ -901,6 +905,19 @@ handle_global(void *data, struct wl_registry *registry,
&zwp_linux_dmabuf_v1_interface, 3);
zwp_linux_dmabuf_v1_add_listener(client->dmabuf,
&dmabuf_listener, client);
} else if (strcmp(interface, wp_viewporter_interface.name) == 0) {
client->viewporter = wl_registry_bind(registry, id,
&wp_viewporter_interface,
1);
} else if (strcmp(interface, wp_presentation_interface.name) == 0) {
client->presentation =
wl_registry_bind(registry, id,
&wp_presentation_interface, 1);
} else if (strcmp(interface, wp_single_pixel_buffer_manager_v1_interface.name) == 0) {
client->single_pixel_manager =
wl_registry_bind(registry, id,
&wp_single_pixel_buffer_manager_v1_interface,
1);
} else if (strcmp(interface, "wl_output") == 0) {
output = xzalloc(sizeof *output);
output->wl_output =
@ -1226,8 +1243,16 @@ client_destroy(struct client *client)
wl_shm_destroy(client->wl_shm);
if (client->dmabuf)
zwp_linux_dmabuf_v1_destroy(client->dmabuf);
if (client->viewporter)
wp_viewporter_destroy(client->viewporter);
if (client->presentation)
wp_presentation_destroy(client->presentation);
if (client->single_pixel_manager)
wp_single_pixel_buffer_manager_v1_destroy(client->single_pixel_manager);
if (client->wl_compositor)
wl_compositor_destroy(client->wl_compositor);
if (client->wl_subcompositor)
wl_subcompositor_destroy(client->wl_subcompositor);
if (client->wl_registry)
wl_registry_destroy(client->wl_registry);
@ -2291,15 +2316,11 @@ bind_to_singleton_global(struct client *client,
struct wp_viewport *
client_create_viewport(struct client *client)
{
struct wp_viewporter *viewporter;
struct wp_viewport *viewport;
viewporter = bind_to_singleton_global(client,
&wp_viewporter_interface, 1);
viewport = wp_viewporter_get_viewport(viewporter,
viewport = wp_viewporter_get_viewport(client->viewporter,
client->surface->wl_surface);
test_assert_ptr_not_null(viewport);
wp_viewporter_destroy(viewporter);
return viewport;
}

View file

@ -35,7 +35,9 @@
#include <wayland-client-protocol.h>
#include "linux-dmabuf-unstable-v1-client-protocol.h"
#include "presentation-time-client-protocol.h"
#include "shared/client-buffer-util.h"
#include "single-pixel-buffer-v1-client-protocol.h"
#include "weston-test-runner.h"
#include "weston-test-client-protocol.h"
#include "viewporter-client-protocol.h"
@ -54,8 +56,13 @@ struct client {
struct wl_registry *wl_registry;
struct wl_compositor *wl_compositor;
struct wl_subcompositor *wl_subcompositor;
struct wl_shm *wl_shm;
struct zwp_linux_dmabuf_v1 *dmabuf;
struct wp_presentation *presentation;
struct wp_single_pixel_buffer_manager_v1 *single_pixel_manager;
struct wp_viewporter *viewporter;
struct test *test;
/* the seat that is actually used for input events */
struct input *input;