From: Florian Forster Date: Fri, 19 Jun 2020 09:31:35 +0000 (+0200) Subject: common: Add test for format_values(). X-Git-Tag: 6.0.0-rc0~148^2~3 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=513fb1e1fdfb3e4af64e4a7e3a68714e60fe0beb;p=thirdparty%2Fcollectd.git common: Add test for format_values(). --- diff --git a/src/utils/common/common_test.c b/src/utils/common/common_test.c index b8b3b4f7a..e3a424666 100644 --- a/src/utils/common/common_test.c +++ b/src/utils/common/common_test.c @@ -375,6 +375,44 @@ DEF_TEST(value_to_rate) { return 0; } +DEF_TEST(format_values) { + struct { + int ds_type; + value_t value; + char const *want; + } cases[] = { + {DS_TYPE_GAUGE, (value_t){.gauge = 47.11}, "1592558427.435:47.11"}, + {DS_TYPE_GAUGE, (value_t){.gauge = NAN}, "1592558427.435:nan"}, + {DS_TYPE_DERIVE, (value_t){.derive = 42}, "1592558427.435:42"}, + {DS_TYPE_COUNTER, (value_t){.counter = 18446744073709551615LLU}, + "1592558427.435:18446744073709551615"}, + }; + + for (size_t i = 0; i < STATIC_ARRAY_SIZE(cases); i++) { + char buf[1024]; + + data_set_t ds = { + .type = "testing", + .ds_num = 1, + .ds = + &(data_source_t){ + .type = cases[i].ds_type, + }, + }; + value_list_t vl = { + .type = "testing", + .values = &cases[i].value, + .values_len = 1, + .time = 1709996590700628541, + }; + + EXPECT_EQ_INT(0, format_values(buf, sizeof(buf), &ds, &vl, false)); + EXPECT_EQ_STR(cases[i].want, buf); + } + + return 0; +} + int main(void) { RUN_TEST(sstrncpy); RUN_TEST(sstrdup); @@ -385,6 +423,7 @@ int main(void) { RUN_TEST(strunescape); RUN_TEST(parse_values); RUN_TEST(value_to_rate); + RUN_TEST(format_values); END_TEST; }