]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: event-filter - Implement event_filter_merge() unit test
authorJosef 'Jeff' Sipek <jeff.sipek@open-xchange.com>
Wed, 20 Jan 2021 16:15:18 +0000 (11:15 -0500)
committerjeff.sipek <jeff.sipek@open-xchange.com>
Thu, 21 Jan 2021 14:41:28 +0000 (14:41 +0000)
src/lib/Makefile.am
src/lib/test-event-filter-merge.c [new file with mode: 0644]
src/lib/test-lib.inc

index 645b4336aa3525dc8e33ed5b9067661f745ca6d1..912f5582f8ac7a31ef4ac616d4b1b97bae509863 100644 (file)
@@ -380,6 +380,7 @@ test_lib_SOURCES = \
        test-event-category-register.c \
        test-event-filter.c \
        test-event-filter-expr.c \
+       test-event-filter-merge.c \
        test-event-filter-parser.c \
        test-event-flatten.c \
        test-event-log.c \
diff --git a/src/lib/test-event-filter-merge.c b/src/lib/test-event-filter-merge.c
new file mode 100644 (file)
index 0000000..c29e533
--- /dev/null
@@ -0,0 +1,64 @@
+/* Copyright (c) 2021 Dovecot authors, see the included COPYING file */
+
+#include "test-lib.h"
+#include "str.h"
+#include "event-filter.h"
+
+static void filter_merge(const char *parent_str, const char *child_str)
+{
+       struct event_filter *parent, *child;
+       const char *error;
+       string_t *out = t_str_new(128);
+
+       test_begin(t_strdup_printf("parent %s, child %s",
+                                  (parent_str == NULL) ? "NULL" : parent_str,
+                                  (child_str == NULL) ? "NULL" : child_str));
+
+       parent = event_filter_create();
+       child = event_filter_create();
+
+       /* prime the filters with an expression */
+       if (parent_str != NULL)
+               test_assert(event_filter_parse(parent_str, parent, &error) == 0);
+       if (child_str != NULL)
+               test_assert(event_filter_parse(child_str, child, &error) == 0);
+
+       /* merge */
+       event_filter_merge(parent, child);
+
+       /* export - to visit/deref everything in the filter */
+       event_filter_export(parent, out);
+       event_filter_export(child, out);
+
+       event_filter_unref(&parent);
+       event_filter_unref(&child);
+
+       test_end();
+}
+
+void test_event_filter_merge(void)
+{
+       static const char *inputs[] = {
+               NULL,
+               /* event name */
+               "event=\"bar\"",
+               "event=\"\"",
+               /* category */
+               "category=\"bar\"",
+               "category=\"\"",
+               /* source location */
+               "source_location=\"bar:123\"",
+               "source_location=\"bar\"",
+               "source_location=\"\"",
+               /* field */
+               "foo=\"bar\"",
+               "foo=\"\"",
+       };
+       unsigned int i, j;
+
+       for (i = 0; i < N_ELEMENTS(inputs); i++) {
+               for (j = 0; j < N_ELEMENTS(inputs); j++) T_BEGIN {
+                       filter_merge(inputs[i], inputs[j]);
+               } T_END;
+       }
+}
index db959561f75701ba6bfa1e4246bc742625947612..76df782757bebdfd821e736bd8abc13e56ee9a9d 100644 (file)
@@ -22,6 +22,7 @@ TEST(test_event_category_register)
 FATAL(fatal_event_category_register)
 TEST(test_event_filter)
 TEST(test_event_filter_expr)
+TEST(test_event_filter_merge)
 TEST(test_event_filter_parser)
 TEST(test_event_flatten)
 TEST(test_event_log)