From: Josef 'Jeff' Sipek Date: Wed, 20 Jan 2021 16:15:18 +0000 (-0500) Subject: lib: event-filter - Implement event_filter_merge() unit test X-Git-Tag: 2.3.14.rc1~85 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=429a12a38bc99d3a45e00366245f001a8b286caf;p=thirdparty%2Fdovecot%2Fcore.git lib: event-filter - Implement event_filter_merge() unit test --- diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am index 645b4336aa..912f5582f8 100644 --- a/src/lib/Makefile.am +++ b/src/lib/Makefile.am @@ -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 index 0000000000..c29e53352a --- /dev/null +++ b/src/lib/test-event-filter-merge.c @@ -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; + } +} diff --git a/src/lib/test-lib.inc b/src/lib/test-lib.inc index db959561f7..76df782757 100644 --- a/src/lib/test-lib.inc +++ b/src/lib/test-lib.inc @@ -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)