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 Apr 5, 2024
1 parent 75091ef commit 653a463
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 @@ -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;

Expand All @@ -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",
Expand Down
21 changes: 21 additions & 0 deletions tests/notification.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
1 change: 1 addition & 0 deletions tests/notification.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
1 change: 1 addition & 0 deletions tests/test-portals.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 ();
Expand Down

0 comments on commit 653a463

Please sign in to comment.