Add tests for notification color hints

This commit is contained in:
Benedikt Heine 2018-12-04 03:25:39 +01:00
parent b10bb292c6
commit caffb0b10c
3 changed files with 65 additions and 0 deletions

View File

@ -5,6 +5,8 @@
#include <assert.h> #include <assert.h>
#include <gio/gio.h> #include <gio/gio.h>
#include "queues.h"
void wake_up_void(void) { } void wake_up_void(void) { }
GVariant *dbus_invoke(const char *method, GVariant *params) GVariant *dbus_invoke(const char *method, GVariant *params)
@ -181,6 +183,48 @@ TEST test_basic_notification(void)
PASS(); 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) TEST test_server_caps(enum markup_mode markup)
{ {
GVariant *reply; GVariant *reply;
@ -223,6 +267,7 @@ gpointer run_threaded_tests(gpointer data)
RUN_TEST(test_basic_notification); RUN_TEST(test_basic_notification);
RUN_TEST(test_invalid_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_FULL);
RUN_TESTp(test_server_caps, MARKUP_STRIP); RUN_TESTp(test_server_caps, MARKUP_STRIP);
RUN_TESTp(test_server_caps, MARKUP_NO); RUN_TESTp(test_server_caps, MARKUP_NO);

View File

@ -6,6 +6,23 @@
#include "greatest.h" #include "greatest.h"
#include "queues.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) TEST test_queue_length(void)
{ {
queues_init(); queues_init();

View File

@ -50,5 +50,8 @@ static inline struct notification *test_notification(const char *name, gint64 ti
return n; return n;
} }
/* Retrieve a notification by its id. Solely for debugging purposes */
struct notification *queues_debug_find_notification_by_id(int id);
#endif #endif
/* vim: set tabstop=8 shiftwidth=8 expandtab textwidth=0: */ /* vim: set tabstop=8 shiftwidth=8 expandtab textwidth=0: */