tests/test-driver: Add way to send generic properties to client
This will make it rather convenient to send arbitrary strings, e.g. file paths, to the client test case. Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2417>
This commit is contained in:
parent
89d036cca0
commit
a8c2df6fb5
@ -42,6 +42,8 @@ struct _MetaWaylandTestDriver
|
||||
struct wl_global *test_driver;
|
||||
|
||||
GList *resources;
|
||||
|
||||
GHashTable *properties;
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE (MetaWaylandTestDriver, meta_wayland_test_driver,
|
||||
@ -115,6 +117,8 @@ bind_test_driver (struct wl_client *client,
|
||||
{
|
||||
MetaWaylandTestDriver *test_driver = user_data;
|
||||
struct wl_resource *resource;
|
||||
GHashTableIter iter;
|
||||
gpointer key, value;
|
||||
|
||||
resource = wl_resource_create (client, &test_driver_interface,
|
||||
version, id);
|
||||
@ -122,6 +126,10 @@ bind_test_driver (struct wl_client *client,
|
||||
test_driver, test_driver_destructor);
|
||||
|
||||
test_driver->resources = g_list_prepend (test_driver->resources, resource);
|
||||
|
||||
g_hash_table_iter_init (&iter, test_driver->properties);
|
||||
while (g_hash_table_iter_next (&iter, &key, &value))
|
||||
test_driver_send_property (resource, key, value);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -130,6 +138,7 @@ meta_wayland_test_driver_finalize (GObject *object)
|
||||
MetaWaylandTestDriver *test_driver = META_WAYLAND_TEST_DRIVER (object);
|
||||
|
||||
g_clear_pointer (&test_driver->test_driver, wl_global_destroy);
|
||||
g_clear_pointer (&test_driver->properties, g_hash_table_unref);
|
||||
|
||||
G_OBJECT_CLASS (meta_wayland_test_driver_parent_class)->finalize (object);
|
||||
}
|
||||
@ -156,6 +165,8 @@ meta_wayland_test_driver_class_init (MetaWaylandTestDriverClass *klass)
|
||||
static void
|
||||
meta_wayland_test_driver_init (MetaWaylandTestDriver *test_driver)
|
||||
{
|
||||
test_driver->properties = g_hash_table_new_full (g_str_hash, g_str_equal,
|
||||
g_free, g_free);
|
||||
}
|
||||
|
||||
MetaWaylandTestDriver *
|
||||
@ -187,3 +198,13 @@ meta_wayland_test_driver_emit_sync_event (MetaWaylandTestDriver *test_driver,
|
||||
test_driver_send_sync_event (resource, serial);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
meta_wayland_test_driver_set_property (MetaWaylandTestDriver *test_driver,
|
||||
const char *name,
|
||||
const char *value)
|
||||
{
|
||||
g_hash_table_replace (test_driver->properties,
|
||||
g_strdup (name),
|
||||
g_strdup (value));
|
||||
}
|
||||
|
@ -30,4 +30,8 @@ MetaWaylandTestDriver * meta_wayland_test_driver_new (MetaWaylandCompositor *com
|
||||
void meta_wayland_test_driver_emit_sync_event (MetaWaylandTestDriver *test_driver,
|
||||
uint32_t serial);
|
||||
|
||||
void meta_wayland_test_driver_set_property (MetaWaylandTestDriver *test_driver,
|
||||
const char *name,
|
||||
const char *value);
|
||||
|
||||
#endif /* META_WAYLAND_TEST_DRIVER_H */
|
||||
|
@ -14,5 +14,10 @@
|
||||
<event name="sync_event">
|
||||
<arg name="sequence" type="uint"/>
|
||||
</event>
|
||||
|
||||
<event name="property">
|
||||
<arg name="name" type="string"/>
|
||||
<arg name="value" type="string"/>
|
||||
</event>
|
||||
</interface>
|
||||
</protocol>
|
||||
|
@ -121,8 +121,22 @@ test_driver_handle_sync_event (void *user_data,
|
||||
g_signal_emit (display, signals[SYNC_EVENT], 0, serial);
|
||||
}
|
||||
|
||||
static void
|
||||
test_driver_handle_property (void *user_data,
|
||||
struct test_driver *test_driver,
|
||||
const char *name,
|
||||
const char *value)
|
||||
{
|
||||
WaylandDisplay *display = WAYLAND_DISPLAY (user_data);
|
||||
|
||||
g_hash_table_replace (display->properties,
|
||||
g_strdup (name),
|
||||
g_strdup (value));
|
||||
}
|
||||
|
||||
static const struct test_driver_listener test_driver_listener = {
|
||||
test_driver_handle_sync_event,
|
||||
test_driver_handle_property,
|
||||
};
|
||||
|
||||
static void
|
||||
@ -198,6 +212,8 @@ wayland_display_new (WaylandDisplayCapabilities capabilities)
|
||||
display = g_object_new (wayland_display_get_type (), NULL);
|
||||
|
||||
display->capabilities = capabilities;
|
||||
display->properties = g_hash_table_new_full (g_str_hash, g_str_equal,
|
||||
g_free, g_free);
|
||||
display->display = wl_display_connect (NULL);
|
||||
g_assert_nonnull (display->display);
|
||||
|
||||
@ -224,6 +240,7 @@ wayland_display_finalize (GObject *object)
|
||||
WaylandDisplay *display = WAYLAND_DISPLAY (object);
|
||||
|
||||
wl_display_disconnect (display->display);
|
||||
g_clear_pointer (&display->properties, g_hash_table_unref);
|
||||
|
||||
G_OBJECT_CLASS (wayland_display_parent_class)->finalize (object);
|
||||
}
|
||||
@ -347,3 +364,10 @@ draw_surface (WaylandDisplay *display,
|
||||
|
||||
wl_surface_attach (surface, buffer, 0, 0);
|
||||
}
|
||||
|
||||
const char *
|
||||
lookup_property_value (WaylandDisplay *display,
|
||||
const char *name)
|
||||
{
|
||||
return g_hash_table_lookup (display->properties, name);
|
||||
}
|
||||
|
@ -28,6 +28,8 @@ typedef struct _WaylandDisplay
|
||||
struct xdg_wm_base *xdg_wm_base;
|
||||
struct wl_shm *shm;
|
||||
struct test_driver *test_driver;
|
||||
|
||||
GHashTable *properties;
|
||||
} WaylandDisplay;
|
||||
|
||||
G_DECLARE_FINAL_TYPE (WaylandDisplay, wayland_display,
|
||||
@ -44,4 +46,7 @@ void draw_surface (WaylandDisplay *display,
|
||||
int height,
|
||||
uint32_t color);
|
||||
|
||||
const char * lookup_property_value (WaylandDisplay *display,
|
||||
const char *name);
|
||||
|
||||
#endif /* WAYLAND_TEST_CLIENT_UTILS_H */
|
||||
|
Loading…
Reference in New Issue
Block a user