From caffb0b10c6dbd32e4b413499ccd517077599c3e Mon Sep 17 00:00:00 2001 From: Benedikt Heine Date: Tue, 4 Dec 2018 03:25:39 +0100 Subject: [PATCH] Add tests for notification color hints --- test/dbus.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ test/queues.c | 17 +++++++++++++++++ test/queues.h | 3 +++ 3 files changed, 65 insertions(+) diff --git a/test/dbus.c b/test/dbus.c index 37965ae..e0f6529 100644 --- a/test/dbus.c +++ b/test/dbus.c @@ -5,6 +5,8 @@ #include #include +#include "queues.h" + void wake_up_void(void) { } GVariant *dbus_invoke(const char *method, GVariant *params) @@ -181,6 +183,48 @@ TEST test_basic_notification(void) PASS(); } +TEST test_dbus_notify_colors(void) +{ + const char *color_frame = "I allow all string values for frame!"; + const char *color_bg = "I allow all string values for background!"; + const char *color_fg = "I allow all string values for foreground!"; + struct notification *n; + struct dbus_notification *n_dbus; + + gsize len = queues_length_waiting(); + + n_dbus = dbus_notification_new(); + n_dbus->app_name = "dunstteststack"; + n_dbus->app_icon = "NONE"; + n_dbus->summary = "test_dbus_notify_colors"; + n_dbus->body = "Summary of it"; + g_hash_table_insert(n_dbus->hints, + g_strdup("frcolor"), + g_variant_ref_sink(g_variant_new_string(color_frame))); + g_hash_table_insert(n_dbus->hints, + g_strdup("bgcolor"), + g_variant_ref_sink(g_variant_new_string(color_bg))); + g_hash_table_insert(n_dbus->hints, + g_strdup("fgcolor"), + g_variant_ref_sink(g_variant_new_string(color_fg))); + + guint id; + ASSERT(dbus_notification_fire(n_dbus, &id)); + ASSERT(id != 0); + + ASSERT_EQ(queues_length_waiting(), len+1); + + n = queues_debug_find_notification_by_id(id); + + ASSERT_STR_EQ(n->colors.frame, color_frame); + ASSERT_STR_EQ(n->colors.fg, color_fg); + ASSERT_STR_EQ(n->colors.bg, color_bg); + + dbus_notification_free(n_dbus); + + PASS(); +} + TEST test_server_caps(enum markup_mode markup) { GVariant *reply; @@ -223,6 +267,7 @@ gpointer run_threaded_tests(gpointer data) RUN_TEST(test_basic_notification); RUN_TEST(test_invalid_notification); + RUN_TEST(test_dbus_notify_colors); RUN_TESTp(test_server_caps, MARKUP_FULL); RUN_TESTp(test_server_caps, MARKUP_STRIP); RUN_TESTp(test_server_caps, MARKUP_NO); diff --git a/test/queues.c b/test/queues.c index de69578..1ba8216 100644 --- a/test/queues.c +++ b/test/queues.c @@ -6,6 +6,23 @@ #include "greatest.h" #include "queues.h" +struct notification *queues_debug_find_notification_by_id(int id) +{ + assert(id > 0); + + GQueue *allqueues[] = { displayed, waiting, history }; + for (int i = 0; i < sizeof(allqueues)/sizeof(GQueue*); i++) { + for (GList *iter = g_queue_peek_head_link(allqueues[i]); iter; + iter = iter->next) { + struct notification *cur = iter->data; + if (cur->id == id) + return cur; + } + } + + return NULL; +} + TEST test_queue_length(void) { queues_init(); diff --git a/test/queues.h b/test/queues.h index 67b68a7..c9c049f 100644 --- a/test/queues.h +++ b/test/queues.h @@ -50,5 +50,8 @@ static inline struct notification *test_notification(const char *name, gint64 ti return n; } +/* Retrieve a notification by its id. Solely for debugging purposes */ +struct notification *queues_debug_find_notification_by_id(int id); + #endif /* vim: set tabstop=8 shiftwidth=8 expandtab textwidth=0: */