Skip to content

Commit

Permalink
test: Implement tests for supported-options property in notification
Browse files Browse the repository at this point in the history
  • Loading branch information
jsparber committed Oct 14, 2024
1 parent 4bd0619 commit e0ce073
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 0 deletions.
46 changes: 46 additions & 0 deletions tests/backend/notification.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

#include "notification.h"

static GFileMonitor *config_monitor;

typedef struct {
XdpDbusImplNotification *impl;
char *app_id;
Expand Down Expand Up @@ -124,10 +126,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;

Expand All @@ -136,6 +173,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",
Expand Down
21 changes: 21 additions & 0 deletions tests/notification.c
Original file line number Diff line number Diff line change
Expand Up @@ -555,3 +555,24 @@ test_notification_category (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'> }");

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);
}
1 change: 1 addition & 0 deletions tests/notification.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ void test_notification_sound (void);
void test_notification_desktop_file_id (void);
void test_notification_display_hint (void);
void test_notification_category (void);
void test_notification_supported_properties (void);
1 change: 1 addition & 0 deletions tests/test-portals.c
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,7 @@ main (int argc, char **argv)
g_test_add_func ("/portal/notification/desktop-file-id", test_notification_desktop_file_id);
g_test_add_func ("/portal/notification/display-hint", test_notification_display_hint);
g_test_add_func ("/portal/notification/category", test_notification_category);
g_test_add_func ("/portal/notification/supported-properties", test_notification_supported_properties);
#endif

global_setup ();
Expand Down

0 comments on commit e0ce073

Please sign in to comment.