summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 2e0fdac)
raw | patch | inline | side by side (parent: 2e0fdac)
author | Florian Forster <octo@collectd.org> | |
Fri, 10 Jul 2015 11:14:43 +0000 (13:14 +0200) | ||
committer | Florian Forster <octo@collectd.org> | |
Fri, 10 Jul 2015 11:14:43 +0000 (13:14 +0200) |
* The tests for common and meta_data logged "not ok" but didn't signal
failure because OK1() didn't include a return(-1) line. Adding this line
caused some restructuring of the utils_vl_lookup test, because it used
that macro in non-int functions.
* Fix DBLEQ() to work correctly with an expected NaN. Previously, the
if condition would fall through to the "expect != actual" part, which
is true for "NaN != NaN".
* Let the mock cdtime() return a non-zero value, as the (invalid) zero
value is used in parse_values() to detect whether the time has been
parsed already. This lead to the "N:..." tests failing.
* Correct the expected behavior of meta_data_add_*() when keys already
exist: they're replaced rather than causing an error.
failure because OK1() didn't include a return(-1) line. Adding this line
caused some restructuring of the utils_vl_lookup test, because it used
that macro in non-int functions.
* Fix DBLEQ() to work correctly with an expected NaN. Previously, the
if condition would fall through to the "expect != actual" part, which
is true for "NaN != NaN".
* Let the mock cdtime() return a non-zero value, as the (invalid) zero
value is used in parse_values() to detect whether the time has been
parsed already. This lead to the "N:..." tests failing.
* Correct the expected behavior of meta_data_add_*() when keys already
exist: they're replaced rather than causing an error.
index 21602d558b824edec19593530fc5bc463352b468..0ee4e7e0eb2c6823e81f32063ceff48eaca8c127 100644 (file)
--- a/src/daemon/common_test.c
+++ b/src/daemon/common_test.c
};
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);
index 0ce8324bc7b853dc35100f2a5a2e7625924a7233..6d61107d50a6bf97b285739b735edf1c2730eec5 100644 (file)
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;
index 5edfe6f922a751c2df1a29a245cd83ad9e5c938f..2bde4d3d8b39623804dc2f548c6892e0fd1e213a 100644 (file)
cdtime_t cdtime (void)
{
- return (0);
+ return (1542455354518929408);
}
diff --git a/src/testing.h b/src/testing.h
index d22af4c2cc610788b24b8cef0b50268a3e7752a4..805449f7b933dad837f42b56137b613263e00fb8 100644 (file)
--- a/src/testing.h
+++ b/src/testing.h
#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 { \
index 6a2676a89e1d8ccee1cddc6735d2f5e7d9335ff7..41cc0a41af3a26c2ac7841178ca88289cd284f01 100644 (file)
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);