From 653a463674ac3812b211ea8a911d91ba191560a9 Mon Sep 17 00:00:00 2001 From: Julian Sparber Date: Tue, 26 Mar 2024 16:05:39 +0100 Subject: [PATCH] test: Implement tests for supported-options property in notification --- tests/backend/notification.c | 46 ++++++++++++++++++++++++++++++++++++ tests/notification.c | 21 ++++++++++++++++ tests/notification.h | 1 + tests/test-portals.c | 1 + 4 files changed, 69 insertions(+) diff --git a/tests/backend/notification.c b/tests/backend/notification.c index 9cce1e476..b8e18fb91 100644 --- a/tests/backend/notification.c +++ b/tests/backend/notification.c @@ -8,6 +8,8 @@ #include "notification.h" +static GFileMonitor *config_monitor; + typedef struct { XdpDbusImplNotification *impl; char *app_id; @@ -123,10 +125,45 @@ handle_remove_notification (XdpDbusImplNotification *object, return TRUE; } +static void +update_supported_options (GFileMonitor *monitor, + GFile *file, + GFile *other_file, + GFileMonitorEvent event_type, + XdpDbusImplNotification *object) +{ + g_autofree char *path = NULL; + g_autoptr(GKeyFile) keyfile = NULL; + g_autofree char *options_s = NULL; + g_autoptr(GVariant) options = NULL; + g_autoptr(GError) error = NULL; + + if (!g_file_query_exists (file, NULL)) + return; + + path = g_file_get_path (file); + + keyfile = g_key_file_new (); + g_key_file_load_from_file (keyfile, path, 0, &error); + g_assert_no_error (error); + + options_s = g_key_file_get_string (keyfile, "notification", "supported-options", NULL); + + if (!options_s) + return; + + options = g_variant_parse (G_VARIANT_TYPE_VARDICT, options_s, NULL, NULL, &error); + g_assert_no_error (error); + + xdp_dbus_impl_notification_set_supported_options (object, options); +} + void notification_init (GDBusConnection *bus, const char *object_path) { + const char *dir; + g_autoptr(GFile) config_file = NULL; g_autoptr(GError) error = NULL; GDBusInterfaceSkeleton *helper; @@ -135,6 +172,15 @@ notification_init (GDBusConnection *bus, g_signal_connect (helper, "handle-add-notification", G_CALLBACK (handle_add_notification), NULL); g_signal_connect (helper, "handle-remove-notification", G_CALLBACK (handle_remove_notification), NULL); + dir = g_getenv ("XDG_DATA_HOME"); + config_file = g_file_new_build_filename (dir, "notification", NULL); + config_monitor = g_file_monitor_file (config_file, G_FILE_MONITOR_NONE, NULL, NULL); + + g_signal_connect (config_monitor, + "changed", + G_CALLBACK (update_supported_options), + helper); + if (!g_dbus_interface_skeleton_export (helper, bus, object_path, &error)) { g_error ("Failed to export %s skeleton: %s\n", diff --git a/tests/notification.c b/tests/notification.c index ec57f4a05..71ca9db8e 100644 --- a/tests/notification.c +++ b/tests/notification.c @@ -453,3 +453,24 @@ test_notification_actions (void) run_notification_test ("test5", notification_s, NULL, TRUE); } + +void +test_notification_supported_properties (void) +{ + g_autoptr(XdpPortal) portal = NULL; + g_autoptr(GKeyFile) keyfile = NULL; + g_autoptr(GError) error = NULL; + g_autofree char *path = NULL; + + keyfile = g_key_file_new (); + + g_key_file_set_string (keyfile, "notification", "supported-options", "{ 'something': <'sdfs'> }"); //supported_options); + + path = g_build_filename (outdir, "notification", NULL); + g_key_file_save_to_file (keyfile, path, &error); + g_assert_no_error (error); + + portal = xdp_portal_new (); + + xdp_portal_get_supported_options (portal); +} diff --git a/tests/notification.h b/tests/notification.h index 36cb43dd0..0c2eb8889 100644 --- a/tests/notification.h +++ b/tests/notification.h @@ -13,3 +13,4 @@ void test_notification_desktop_file_id (void); void test_notification_display_hint (void); void test_notification_content_type (void); void test_notification_actions (void); +void test_notification_supported_properties (void); diff --git a/tests/test-portals.c b/tests/test-portals.c index 02abfc82b..5ad58b105 100644 --- a/tests/test-portals.c +++ b/tests/test-portals.c @@ -612,6 +612,7 @@ main (int argc, char **argv) g_test_add_func ("/portal/notification/display-hint", test_notification_display_hint); g_test_add_func ("/portal/notification/content-type", test_notification_content_type); g_test_add_func ("/portal/notification/actions", test_notification_actions); + g_test_add_func ("/portal/notification/supported-properties", test_notification_supported_properties); #endif global_setup ();