Skip to content

Commit

Permalink
lib: Add test for event_inc_int()
Browse files Browse the repository at this point in the history
  • Loading branch information
mrannanj committed Aug 27, 2018
1 parent 0e63438 commit f7ab09b
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions src/lib/test-event-filter.c
Expand Up @@ -98,8 +98,55 @@ static void test_event_filter_clear_parent_fields(void)
test_end();
}

static void test_event_filter_inc_int(void)
{
struct event_filter *filter;
struct event_filter_field filter_fields[] = {
{ .key = "int", .value = "14" },
{ .key = NULL, .value = NULL }
};
const struct event_filter_query query = {
.fields = filter_fields,
};
const struct failure_context failure_ctx = {
.type = LOG_TYPE_DEBUG
};

test_begin("event filter: create and update keys with event_inc_int");

struct event *root = event_create(NULL);

filter = event_filter_create();
event_filter_add(filter, &query);

const struct event_field *f = event_find_field(root, "int");
test_assert(f == NULL);
test_assert(!event_filter_match(filter, root, &failure_ctx));

event_inc_int(root, "int", 7);
test_assert(!event_filter_match(filter, root, &failure_ctx));
f = event_find_field(root, "int");
test_assert(f != NULL);
test_assert_strcmp(f->key, "int");
test_assert(f->value_type == EVENT_FIELD_VALUE_TYPE_INTMAX);
test_assert(f->value.intmax == 7);

event_inc_int(root, "int", 7);
test_assert(event_filter_match(filter, root, &failure_ctx));
f = event_find_field(root, "int");
test_assert(f != NULL);
test_assert_strcmp(f->key, "int");
test_assert(f->value_type == EVENT_FIELD_VALUE_TYPE_INTMAX);
test_assert(f->value.intmax == 14);

event_filter_unref(&filter);
event_unref(&root);
test_end();
}

void test_event_filter(void)
{
test_event_filter_override_parent_fields();
test_event_filter_clear_parent_fields();
test_event_filter_inc_int();
}

0 comments on commit f7ab09b

Please sign in to comment.