};
int status = parse_values (cases[i].buffer, &vl, &ds);
- OK(status == cases[i].status);
+ EXPECT_INTEQ (cases[i].status, status);
if (status != 0)
continue;
- OK(cases[i].value == vl.values[0].gauge);
+ DBLEQ (cases[i].value, vl.values[0].gauge);
}
return (0);
OK1 (b, "b evaluates to true");
/* retrieving the wrong type always fails */
- OK (meta_data_get_boolean (m, "string", &b) != 0);
- OK (meta_data_get_string (m, "signed_int", &s) != 0);
- OK (meta_data_get_string (m, "unsigned_int", &s) != 0);
- OK (meta_data_get_string (m, "double", &s) != 0);
- OK (meta_data_get_string (m, "boolean", &s) != 0);
+ EXPECT_INTEQ (-2, meta_data_get_boolean (m, "string", &b));
+ EXPECT_INTEQ (-2, meta_data_get_string (m, "signed_int", &s));
+ EXPECT_INTEQ (-2, meta_data_get_string (m, "unsigned_int", &s));
+ EXPECT_INTEQ (-2, meta_data_get_string (m, "double", &s));
+ EXPECT_INTEQ (-2, meta_data_get_string (m, "boolean", &s));
- /* adding existing keys fails */
- OK (meta_data_add_signed_int (m, "string", 666) != 0);
- OK (meta_data_add_signed_int (m, "signed_int", 666) != 0);
+ /* replace existing keys */
+ CHECK_ZERO (meta_data_add_signed_int (m, "string", 666));
+ OK(meta_data_type (m, "string") == MD_TYPE_SIGNED_INT);
- /* deleting, then adding a key works */
+ CHECK_ZERO (meta_data_add_signed_int (m, "signed_int", 666));
+ CHECK_ZERO (meta_data_get_signed_int (m, "signed_int", &si));
+ EXPECT_INTEQ (666, (int) si);
+
+ /* deleting keys */
CHECK_ZERO (meta_data_delete (m, "signed_int"));
- CHECK_ZERO (meta_data_add_signed_int (m, "signed_int", 42));
+ EXPECT_INTEQ (-2, meta_data_delete (m, "doesnt exist"));
meta_data_destroy (m);
return 0;
cdtime_t cdtime (void)
{
- return (0);
+ return (1542455354518929408);
}
#define OK1(cond, text) do { \
_Bool result = (cond); \
printf ("%s %i - %s\n", result ? "ok" : "not ok", ++check_count__, text); \
+ if (!result) { return -1; } \
} while (0)
#define OK(cond) OK1(cond, #cond)
} while (0)
#define DBLEQ(expect, actual) do { \
- if ((isnan (expect) && !isnan (actual)) || ((expect) != (actual))) {\
+ double e = (expect); double a = (actual); \
+ if (isnan (e) && !isnan (a)) { \
printf ("not ok %i - %s incorrect: expected %.15g, got %.15g\n", \
- ++check_count__, #actual, expect, actual); \
+ ++check_count__, #actual, e, a); \
+ return (-1); \
+ } else if (!isnan (e) && (((e-a) < -1e-12) || ((e-a) > 1e-12))) { \
+ printf ("not ok %i - %s incorrect: expected %.15g, got %.15g\n", \
+ ++check_count__, #actual, e, a); \
return (-1); \
} \
- printf ("ok %i - %s evaluates to %.15g\n", ++check_count__, #actual, expect); \
+ printf ("ok %i - %s evaluates to %.15g\n", ++check_count__, #actual, e); \
} while (0)
#define CHECK_NOT_NULL(expr) do { \
identifier_t *class = user_class;
identifier_t *obj;
- OK(expect_new_obj);
+ assert (expect_new_obj);
memcpy (&last_class_ident, class, sizeof (last_class_ident));
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,
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,
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",
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",
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);
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);