X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Futils_vl_lookup_test.c;h=b3765e9f41d74b1067b2085d52995bdd940e865a;hb=7747e2ad9a86c2307094cd4ca3f753e46329c7a5;hp=6a2676a89e1d8ccee1cddc6735d2f5e7d9335ff7;hpb=092e0c8763ef268918fb8117be9579d375ac8cfc;p=collectd.git diff --git a/src/utils_vl_lookup_test.c b/src/utils_vl_lookup_test.c index 6a2676a8..b3765e9f 100644 --- a/src/utils_vl_lookup_test.c +++ b/src/utils_vl_lookup_test.c @@ -24,15 +24,16 @@ * Florian Forster **/ -#include "testing.h" #include "collectd.h" + +#include "testing.h" #include "utils_vl_lookup.h" static _Bool expect_new_obj = 0; static _Bool have_new_obj = 0; -static identifier_t last_class_ident; -static identifier_t last_obj_ident; +static lookup_identifier_t last_class_ident; +static lookup_identifier_t last_obj_ident; static data_source_t dsrc_test = { "value", DS_TYPE_DERIVE, 0.0, NAN }; static data_set_t const ds_test = { "test", 1, &dsrc_test }; @@ -44,8 +45,8 @@ static int lookup_obj_callback (data_set_t const *ds, value_list_t const *vl, void *user_class, void *user_obj) { - identifier_t *class = user_class; - identifier_t *obj = user_obj; + lookup_identifier_t *class = user_class; + lookup_identifier_t *obj = user_obj; OK1(expect_new_obj == have_new_obj, (expect_new_obj ? "New obj is created." : "Updating existing obj.")); @@ -62,13 +63,13 @@ static int lookup_obj_callback (data_set_t const *ds, static void *lookup_class_callback (data_set_t const *ds, value_list_t const *vl, void *user_class) { - identifier_t *class = user_class; - identifier_t *obj; + lookup_identifier_t *class = user_class; + lookup_identifier_t *obj; - OK(expect_new_obj); + assert (expect_new_obj); memcpy (&last_class_ident, class, sizeof (last_class_ident)); - + obj = malloc (sizeof (*obj)); strncpy (obj->host, vl->host, sizeof (obj->host)); strncpy (obj->plugin, vl->plugin, sizeof (obj->plugin)); @@ -81,16 +82,15 @@ static void *lookup_class_callback (data_set_t const *ds, return ((void *) obj); } -static void checked_lookup_add (lookup_t *obj, /* {{{ */ +static int checked_lookup_add (lookup_t *obj, /* {{{ */ char const *host, char const *plugin, char const *plugin_instance, char const *type, char const *type_instance, unsigned int group_by) { - identifier_t ident; + lookup_identifier_t ident; void *user_class; - memset (&ident, 0, sizeof (ident)); strncpy (ident.host, host, sizeof (ident.host)); strncpy (ident.plugin, plugin, sizeof (ident.plugin)); strncpy (ident.plugin_instance, plugin_instance, sizeof (ident.plugin_instance)); @@ -101,7 +101,8 @@ static void checked_lookup_add (lookup_t *obj, /* {{{ */ memmove (user_class, &ident, sizeof (ident)); OK(lookup_add (obj, &ident, group_by, user_class) == 0); -} /* }}} void test_add */ + return 0; +} /* }}} int checked_lookup_add */ static int checked_lookup_search (lookup_t *obj, char const *host, @@ -129,20 +130,11 @@ static int checked_lookup_search (lookup_t *obj, return (status); } -static lookup_t *checked_lookup_create (void) -{ - lookup_t *obj = lookup_create ( - lookup_class_callback, - lookup_obj_callback, - (void *) free, - (void *) free); - OK(obj != NULL); - return (obj); -} - DEF_TEST(group_by_specific_host) { - lookup_t *obj = checked_lookup_create (); + lookup_t *obj; + CHECK_NOT_NULL (obj = lookup_create ( + lookup_class_callback, lookup_obj_callback, (void *) free, (void *) free)); checked_lookup_add (obj, "/.*/", "test", "", "test", "/.*/", LU_GROUP_BY_HOST); checked_lookup_search (obj, "host0", "test", "", "test", "0", @@ -160,7 +152,9 @@ DEF_TEST(group_by_specific_host) DEF_TEST(group_by_any_host) { - lookup_t *obj = checked_lookup_create (); + lookup_t *obj; + CHECK_NOT_NULL (obj = lookup_create ( + lookup_class_callback, lookup_obj_callback, (void *) free, (void *) free)); checked_lookup_add (obj, "/.*/", "/.*/", "/.*/", "test", "/.*/", LU_GROUP_BY_HOST); checked_lookup_search (obj, "host0", "plugin0", "", "test", "0", @@ -186,9 +180,12 @@ DEF_TEST(group_by_any_host) DEF_TEST(multiple_lookups) { - lookup_t *obj = checked_lookup_create (); + lookup_t *obj; int status; + CHECK_NOT_NULL (obj = lookup_create ( + lookup_class_callback, lookup_obj_callback, (void *) free, (void *) free)); + checked_lookup_add (obj, "/.*/", "plugin0", "", "test", "/.*/", LU_GROUP_BY_HOST); checked_lookup_add (obj, "/.*/", "/.*/", "", "test", "ti0", LU_GROUP_BY_HOST); @@ -211,7 +208,9 @@ DEF_TEST(multiple_lookups) DEF_TEST(regex) { - lookup_t *obj = checked_lookup_create (); + lookup_t *obj; + CHECK_NOT_NULL (obj = lookup_create ( + lookup_class_callback, lookup_obj_callback, (void *) free, (void *) free)); checked_lookup_add (obj, "/^db[0-9]\\./", "cpu", "/.*/", "cpu", "/.*/", LU_GROUP_BY_TYPE_INSTANCE);