]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: test-event-filter - Test overriding parent fields
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Thu, 16 Aug 2018 09:27:06 +0000 (12:27 +0300)
committerVille Savolainen <ville.savolainen@dovecot.fi>
Tue, 13 Nov 2018 13:03:15 +0000 (15:03 +0200)
src/lib/test-event-filter.c

index eb9621a96e15b0a00aacc6cb7fc53f2e2eff9438..73a53367f24a394a411f5c17f7fbc113b6d362b9 100644 (file)
@@ -4,6 +4,60 @@
 #include "ioloop.h"
 #include "event-filter.h"
 
+static void test_event_filter_override_parent_fields(void)
+{
+       struct event_filter *filter;
+       struct event_filter_field parent_query_fields[] = {
+               { .key = "str", .value = "parent_str" },
+               { .key = "int1", .value = "0" },
+               { .key = "int2", .value = "5" },
+               { .key = NULL, .value = NULL }
+       };
+       const struct event_filter_query parent_query = {
+               .fields = parent_query_fields,
+       };
+       struct event_filter_field child_query_fields[] = {
+               { .key = "str", .value = "child_str" },
+               { .key = "int1", .value = "6" },
+               { .key = "int2", .value = "0" },
+               { .key = NULL, .value = NULL }
+       };
+       const struct event_filter_query child_query = {
+               .fields = child_query_fields,
+       };
+       const struct failure_context failure_ctx = {
+               .type = LOG_TYPE_DEBUG
+       };
+
+       test_begin("event filter: override parent fields");
+
+       struct event *parent = event_create(NULL);
+       event_add_str(parent, "str", "parent_str");
+       event_add_int(parent, "int1", 0);
+       event_add_int(parent, "int2", 5);
+
+       struct event *child = event_create(NULL);
+       event_add_str(child, "str", "child_str");
+       event_add_int(child, "int1", 6);
+       event_add_int(child, "int2", 0);
+
+       filter = event_filter_create();
+       event_filter_add(filter, &parent_query);
+       test_assert(event_filter_match(filter, parent, &failure_ctx));
+       test_assert(!event_filter_match(filter, child, &failure_ctx));
+       event_filter_unref(&filter);
+
+       filter = event_filter_create();
+       event_filter_add(filter, &child_query);
+       test_assert(event_filter_match(filter, child, &failure_ctx));
+       test_assert(!event_filter_match(filter, parent, &failure_ctx));
+       event_filter_unref(&filter);
+
+       event_unref(&parent);
+       event_unref(&child);
+       test_end();
+}
+
 static void test_event_filter_clear_parent_fields(void)
 {
        struct event_filter *filter;
@@ -46,5 +100,6 @@ static void test_event_filter_clear_parent_fields(void)
 
 void test_event_filter(void)
 {
+       test_event_filter_override_parent_fields();
        test_event_filter_clear_parent_fields();
 }