From: Timo Sirainen Date: Thu, 16 Aug 2018 09:27:06 +0000 (+0300) Subject: lib: test-event-filter - Test overriding parent fields X-Git-Tag: 2.3.4~140 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=682fce2e320b1f02c059e3ed44ee5e3688df754a;p=thirdparty%2Fdovecot%2Fcore.git lib: test-event-filter - Test overriding parent fields --- diff --git a/src/lib/test-event-filter.c b/src/lib/test-event-filter.c index eb9621a96e..73a53367f2 100644 --- a/src/lib/test-event-filter.c +++ b/src/lib/test-event-filter.c @@ -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(); }