tests/wayland: Make test driver properties table multi typed

Store values as GVariant's. This will allow to add other types property
types than strings.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3859>
This commit is contained in:
Jonas Ådahl 2024-11-14 22:19:56 +01:00 committed by Sebastian Wick
parent 29850b7345
commit a0877dc071
3 changed files with 38 additions and 11 deletions

View File

@ -329,7 +329,23 @@ bind_test_driver (struct wl_client *client,
g_hash_table_iter_init (&iter, test_driver->properties); g_hash_table_iter_init (&iter, test_driver->properties);
while (g_hash_table_iter_next (&iter, &key, &value)) while (g_hash_table_iter_next (&iter, &key, &value))
test_driver_send_property (resource, key, value); {
GVariant *variant = value;
if (g_variant_is_of_type (value, G_VARIANT_TYPE_STRING))
{
test_driver_send_property (resource,
key,
g_variant_get_string (variant, NULL));
}
else
{
g_autofree char *variant_string = NULL;
variant_string = g_variant_print (variant, TRUE);
g_warning ("Unhandled test driver variant '%s'", variant_string);
}
}
} }
static void static void
@ -375,7 +391,8 @@ static void
meta_wayland_test_driver_init (MetaWaylandTestDriver *test_driver) meta_wayland_test_driver_init (MetaWaylandTestDriver *test_driver)
{ {
test_driver->properties = g_hash_table_new_full (g_str_hash, g_str_equal, test_driver->properties = g_hash_table_new_full (g_str_hash, g_str_equal,
g_free, g_free); g_free,
(GDestroyNotify) g_variant_unref);
} }
MetaWaylandTestDriver * MetaWaylandTestDriver *
@ -416,7 +433,7 @@ meta_wayland_test_driver_set_property (MetaWaylandTestDriver *test_driver,
{ {
g_hash_table_replace (test_driver->properties, g_hash_table_replace (test_driver->properties,
g_strdup (name), g_strdup (name),
g_strdup (value)); g_variant_new_string (value));
} }
static void static void

View File

@ -198,7 +198,7 @@ create_gbm_device (WaylandDisplay *display)
const char *gpu_path; const char *gpu_path;
int fd; int fd;
gpu_path = lookup_property_value (display, "gpu-path"); gpu_path = lookup_property_string (display, "gpu-path");
if (!gpu_path) if (!gpu_path)
return NULL; return NULL;
@ -244,7 +244,7 @@ test_driver_handle_property (void *user_data,
g_hash_table_replace (display->properties, g_hash_table_replace (display->properties,
g_strdup (name), g_strdup (name),
g_strdup (value)); g_variant_new_string (value));
} }
static const struct test_driver_listener test_driver_listener = { static const struct test_driver_listener test_driver_listener = {
@ -411,7 +411,8 @@ wayland_display_new_full (WaylandDisplayCapabilities capabilities,
display->capabilities = capabilities; display->capabilities = capabilities;
display->properties = g_hash_table_new_full (g_str_hash, g_str_equal, display->properties = g_hash_table_new_full (g_str_hash, g_str_equal,
g_free, g_free); g_free,
(GDestroyNotify) g_variant_unref);
display->formats = g_hash_table_new_full (NULL, NULL, NULL, g_free); display->formats = g_hash_table_new_full (NULL, NULL, NULL, g_free);
display->display = wayland_display; display->display = wayland_display;
@ -689,10 +690,19 @@ wayland_surface_set_opaque (WaylandSurface *surface)
} }
const char * const char *
lookup_property_value (WaylandDisplay *display, lookup_property_string (WaylandDisplay *display,
const char *name) const char *name)
{ {
return g_hash_table_lookup (display->properties, name); GVariant *variant;
const char *value;
variant = g_hash_table_lookup (display->properties, name);
if (!variant)
return NULL;
g_variant_get (variant, "&s", &value);
return value;
} }
static void static void

View File

@ -124,8 +124,8 @@ void draw_surface (WaylandDisplay *display,
int height, int height,
uint32_t color); uint32_t color);
const char * lookup_property_value (WaylandDisplay *display, const char * lookup_property_string (WaylandDisplay *display,
const char *name); const char *name);
void wait_for_effects_completed (WaylandDisplay *display, void wait_for_effects_completed (WaylandDisplay *display,
struct wl_surface *surface); struct wl_surface *surface);