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;
|
struct wl_global *test_driver;
|
||||||
|
|
||||||
GList *resources;
|
GList *resources;
|
||||||
|
|
||||||
|
GHashTable *properties;
|
||||||
};
|
};
|
||||||
|
|
||||||
G_DEFINE_TYPE (MetaWaylandTestDriver, meta_wayland_test_driver,
|
G_DEFINE_TYPE (MetaWaylandTestDriver, meta_wayland_test_driver,
|
||||||
@ -115,6 +117,8 @@ bind_test_driver (struct wl_client *client,
|
|||||||
{
|
{
|
||||||
MetaWaylandTestDriver *test_driver = user_data;
|
MetaWaylandTestDriver *test_driver = user_data;
|
||||||
struct wl_resource *resource;
|
struct wl_resource *resource;
|
||||||
|
GHashTableIter iter;
|
||||||
|
gpointer key, value;
|
||||||
|
|
||||||
resource = wl_resource_create (client, &test_driver_interface,
|
resource = wl_resource_create (client, &test_driver_interface,
|
||||||
version, id);
|
version, id);
|
||||||
@ -122,6 +126,10 @@ bind_test_driver (struct wl_client *client,
|
|||||||
test_driver, test_driver_destructor);
|
test_driver, test_driver_destructor);
|
||||||
|
|
||||||
test_driver->resources = g_list_prepend (test_driver->resources, resource);
|
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
|
static void
|
||||||
@ -130,6 +138,7 @@ meta_wayland_test_driver_finalize (GObject *object)
|
|||||||
MetaWaylandTestDriver *test_driver = META_WAYLAND_TEST_DRIVER (object);
|
MetaWaylandTestDriver *test_driver = META_WAYLAND_TEST_DRIVER (object);
|
||||||
|
|
||||||
g_clear_pointer (&test_driver->test_driver, wl_global_destroy);
|
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);
|
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
|
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,
|
||||||
|
g_free, g_free);
|
||||||
}
|
}
|
||||||
|
|
||||||
MetaWaylandTestDriver *
|
MetaWaylandTestDriver *
|
||||||
@ -187,3 +198,13 @@ meta_wayland_test_driver_emit_sync_event (MetaWaylandTestDriver *test_driver,
|
|||||||
test_driver_send_sync_event (resource, serial);
|
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,
|
void meta_wayland_test_driver_emit_sync_event (MetaWaylandTestDriver *test_driver,
|
||||||
uint32_t serial);
|
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 */
|
#endif /* META_WAYLAND_TEST_DRIVER_H */
|
||||||
|
@ -14,5 +14,10 @@
|
|||||||
<event name="sync_event">
|
<event name="sync_event">
|
||||||
<arg name="sequence" type="uint"/>
|
<arg name="sequence" type="uint"/>
|
||||||
</event>
|
</event>
|
||||||
|
|
||||||
|
<event name="property">
|
||||||
|
<arg name="name" type="string"/>
|
||||||
|
<arg name="value" type="string"/>
|
||||||
|
</event>
|
||||||
</interface>
|
</interface>
|
||||||
</protocol>
|
</protocol>
|
||||||
|
@ -121,8 +121,22 @@ test_driver_handle_sync_event (void *user_data,
|
|||||||
g_signal_emit (display, signals[SYNC_EVENT], 0, serial);
|
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 = {
|
static const struct test_driver_listener test_driver_listener = {
|
||||||
test_driver_handle_sync_event,
|
test_driver_handle_sync_event,
|
||||||
|
test_driver_handle_property,
|
||||||
};
|
};
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -198,6 +212,8 @@ wayland_display_new (WaylandDisplayCapabilities capabilities)
|
|||||||
display = g_object_new (wayland_display_get_type (), NULL);
|
display = g_object_new (wayland_display_get_type (), NULL);
|
||||||
|
|
||||||
display->capabilities = capabilities;
|
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);
|
display->display = wl_display_connect (NULL);
|
||||||
g_assert_nonnull (display->display);
|
g_assert_nonnull (display->display);
|
||||||
|
|
||||||
@ -224,6 +240,7 @@ wayland_display_finalize (GObject *object)
|
|||||||
WaylandDisplay *display = WAYLAND_DISPLAY (object);
|
WaylandDisplay *display = WAYLAND_DISPLAY (object);
|
||||||
|
|
||||||
wl_display_disconnect (display->display);
|
wl_display_disconnect (display->display);
|
||||||
|
g_clear_pointer (&display->properties, g_hash_table_unref);
|
||||||
|
|
||||||
G_OBJECT_CLASS (wayland_display_parent_class)->finalize (object);
|
G_OBJECT_CLASS (wayland_display_parent_class)->finalize (object);
|
||||||
}
|
}
|
||||||
@ -347,3 +364,10 @@ draw_surface (WaylandDisplay *display,
|
|||||||
|
|
||||||
wl_surface_attach (surface, buffer, 0, 0);
|
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 xdg_wm_base *xdg_wm_base;
|
||||||
struct wl_shm *shm;
|
struct wl_shm *shm;
|
||||||
struct test_driver *test_driver;
|
struct test_driver *test_driver;
|
||||||
|
|
||||||
|
GHashTable *properties;
|
||||||
} WaylandDisplay;
|
} WaylandDisplay;
|
||||||
|
|
||||||
G_DECLARE_FINAL_TYPE (WaylandDisplay, wayland_display,
|
G_DECLARE_FINAL_TYPE (WaylandDisplay, wayland_display,
|
||||||
@ -44,4 +46,7 @@ void draw_surface (WaylandDisplay *display,
|
|||||||
int height,
|
int height,
|
||||||
uint32_t color);
|
uint32_t color);
|
||||||
|
|
||||||
|
const char * lookup_property_value (WaylandDisplay *display,
|
||||||
|
const char *name);
|
||||||
|
|
||||||
#endif /* WAYLAND_TEST_CLIENT_UTILS_H */
|
#endif /* WAYLAND_TEST_CLIENT_UTILS_H */
|
||||||
|
Loading…
Reference in New Issue
Block a user