From: Florian Forster Date: Thu, 25 Jun 2015 09:31:19 +0000 (+0200) Subject: src/daemon/common.c: Add parse_values() unit test. X-Git-Tag: collectd-5.6.0~669^2~1 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=c0a95e555ed8b58af9ff9e476ce1c13241a21ae3;p=collectd.git src/daemon/common.c: Add parse_values() unit test. --- diff --git a/src/daemon/common_test.c b/src/daemon/common_test.c index 1fa8f324..f75621a6 100644 --- a/src/daemon/common_test.c +++ b/src/daemon/common_test.c @@ -231,6 +231,62 @@ DEF_TEST(strunescape) return (0); } +DEF_TEST(parse_values) +{ + struct { + char buffer[64]; + int status; + gauge_t value; + } cases[] = { + {"1435044576:42", 0, 42.0}, + {"1435044576:42:23", -1, NAN}, + {"1435044576:U", 0, NAN}, + {"N:12.3", 0, 12.3}, + {"N:42.0:23", -1, NAN}, + {"N:U", 0, NAN}, + {"T:42.0", -1, NAN}, + }; + + size_t i; + for (i = 0; i < STATIC_ARRAY_SIZE (cases); i++) + { + data_source_t dsrc = { + .name = "value", + .type = DS_TYPE_GAUGE, + .min = 0.0, + .max = NAN, + }; + data_set_t ds = { + .type = "example", + .ds_num = 1, + .ds = &dsrc, + }; + + value_t v = { + .gauge = NAN, + }; + value_list_t vl = { + .values = &v, + .values_len = 1, + .time = 0, + .interval = 0, + .host = "example.com", + .plugin = "common_test", + .type = "example", + .meta = NULL, + }; + + int status = parse_values (cases[i].buffer, &vl, &ds); + OK(status == cases[i].status); + if (status != 0) + continue; + + OK(cases[i].value == vl.values[0].gauge); + } + + return (0); +} + int main (void) { RUN_TEST(sstrncpy); @@ -239,6 +295,7 @@ int main (void) RUN_TEST(strsplit); RUN_TEST(strjoin); RUN_TEST(strunescape); + RUN_TEST(parse_values); END_TEST; }