1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
|
/*
* Copyright (C) 2023 Phosh.mobi e.V.
*
* SPDX-License-Identifier: GPL-3.0-or-later
*
* Author: Guido Günther <agx@sigxcpu.org>
*/
#include "notifications/notify-feedback.c"
#include <gio/gdesktopappinfo.h>
static void
test_phosh_notify_feedback_screen_wakeup (void)
{
g_autoptr (PhoshNotification) noti = NULL;
g_autoptr (GAppInfo) info = NULL;
g_autoptr (GDateTime) now = g_date_time_new_now_local ();
g_autoptr (PhoshNotificationList) list = phosh_notification_list_new ();
g_autoptr (PhoshNotifyFeedback) notify_feedback = phosh_notify_feedback_new (list);
g_autoptr (GSettings) settings = g_settings_new ("sm.puri.phosh.notifications");
info = G_APP_INFO (g_desktop_app_info_new ("demo.app.Second.desktop"));
noti = phosh_notification_new (0,
"should-not-be-seen",
info,
"Hey",
"Testing",
NULL,
NULL,
PHOSH_NOTIFICATION_URGENCY_NORMAL,
NULL,
FALSE,
FALSE,
NULL,
NULL,
now);
g_assert_false (phosh_notify_feedback_check_screen_wakeup (notify_feedback, noti));
/* urgency */
g_settings_set_flags (settings, "wakeup-screen-triggers", PHOSH_NOTIFY_SCREEN_WAKEUP_FLAG_URGENCY);
g_settings_set_enum (settings, "wakeup-screen-urgency", PHOSH_NOTIFICATION_URGENCY_NORMAL);
g_assert_true (phosh_notify_feedback_check_screen_wakeup (notify_feedback, noti));
g_settings_set_flags (settings, "wakeup-screen-triggers", PHOSH_NOTIFY_SCREEN_WAKEUP_FLAG_URGENCY);
g_settings_set_enum (settings, "wakeup-screen-urgency", PHOSH_NOTIFICATION_URGENCY_NORMAL);
/* category */
g_settings_set_flags (settings, "wakeup-screen-triggers", PHOSH_NOTIFY_SCREEN_WAKEUP_FLAG_CATEGORY);
g_settings_set_strv (settings, "wakeup-screen-categories",
(const char *const[]) { "im", "foo.bar", "baz" , NULL });
g_assert_false (phosh_notify_feedback_check_screen_wakeup (notify_feedback, noti));
/* Exact match without specific */
phosh_notification_set_category (noti, "im");
g_assert_true (phosh_notify_feedback_check_screen_wakeup (notify_feedback, noti));
/* Exact match with specific but config only specifies class */
phosh_notification_set_category (noti, "im.received");
g_assert_true (phosh_notify_feedback_check_screen_wakeup (notify_feedback, noti));
/* No match */
phosh_notification_set_category (noti, "doesnotexist");
g_assert_false (phosh_notify_feedback_check_screen_wakeup (notify_feedback, noti));
/* Exact match with specific and config has specific too */
phosh_notification_set_category (noti, "foo.bar");
g_assert_true (phosh_notify_feedback_check_screen_wakeup (notify_feedback, noti));
}
static void
test_phosh_notify_feedback_find_event_inactive (void)
{
g_assert_cmpstr (find_event_inactive ("doesnotexist"), ==, "notification-missed-generic");
g_assert_cmpstr (find_event_inactive (NULL), ==, "notification-missed-generic");
g_assert_cmpstr (find_event_inactive ("call.unanswered"), ==, "phone-missed-call");
g_assert_cmpstr (find_event_inactive ("im.received"), ==, "message-missed-instant");
}
static void
test_phosh_notify_feedback_find_event_active (void)
{
gboolean important = FALSE;
g_assert_cmpstr (find_event_active ("doesnotexist", &important), ==, "notification-new-generic");
g_assert_false (important);
g_assert_cmpstr (find_event_active (NULL, &important), ==, "notification-new-generic");
g_assert_false (important);
g_assert_cmpstr (find_event_active ("im.received", &important), ==, "message-new-instant");
g_assert_false (important);
g_assert_cmpstr (find_event_active ("x-phosh-cellbroadcast.danger.severe", &important), ==,
"message-new-cellbroadcast");
g_assert_true (important);
}
int
main (int argc, char **argv)
{
g_test_init (&argc, &argv, NULL);
g_test_add_func ("/phosh/notifyfeedback/check-screen-wakeup",
test_phosh_notify_feedback_screen_wakeup);
g_test_add_func ("/phosh/notifyfeedback/find-event-inactive",
test_phosh_notify_feedback_find_event_inactive);
g_test_add_func ("/phosh/notifyfeedback/find-event-active",
test_phosh_notify_feedback_find_event_active);
return g_test_run ();
}
|