From 1b4ca786cd89332dc6188f538f519b29e5fe4e9e Mon Sep 17 00:00:00 2001 From: Benedikt Heine Date: Thu, 15 Nov 2018 16:03:38 +0100 Subject: [PATCH] Test notification_format_message --- test/notification.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/test/notification.c b/test/notification.c index 6738f84..43a0010 100644 --- a/test/notification.c +++ b/test/notification.c @@ -117,6 +117,17 @@ TEST test_notification_referencing(void) PASS(); } +TEST test_notification_format_message(struct notification *n, const char *format, const char *exp) +{ + n->format = format; + notification_format_message(n); + + ASSERT_STR_EQ(exp, n->msg); + + PASS(); +} + + SUITE(suite_notification) { cmdline_load(0, NULL); @@ -147,6 +158,37 @@ SUITE(suite_notification) RUN_TEST(test_notification_replace_single_field); RUN_TEST(test_notification_referencing); + // TEST notification_format_message + a = notification_create(); + a->appname = g_strdup("MyApp"); + a->summary = g_strdup("I've got a summary!"); + a->body = g_strdup("Look at my shiny "); + a->icon = g_strdup("/this/is/my/icoknpath.png"); + a->progress = 95; + + const char *strings[] = { + "%a", "MyApp", + "%s", "I've got a summary!", + "%b", "Look at my shiny ", + "%I", "icoknpath.png", + "%i", "/this/is/my/icoknpath.png", + "%p", "[ 95%]", + "%n", "95", + "%%", "%", + "%", "%", + "%UNKNOWN", "%UNKNOWN", + NULL + }; + + const char **in = strings; + const char **out = strings+1; + while (*in && *out) { + RUN_TESTp(test_notification_format_message, a, *in, *out); + in +=2; + out+=2; + } + g_clear_pointer(&a, notification_unref); + g_clear_pointer(&settings.icon_path, g_free); g_free(config_path); }