From: elene-margalit Date: Mon, 17 Aug 2020 15:33:22 +0000 (+0200) Subject: Added unit test for metric_reset. X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=2930dffb85cdd7b80d37d24b920938bd79e541b1;p=thirdparty%2Fcollectd.git Added unit test for metric_reset. --- diff --git a/src/daemon/metric_test.c b/src/daemon/metric_test.c index 128162046..174f51c3c 100644 --- a/src/daemon/metric_test.c +++ b/src/daemon/metric_test.c @@ -25,7 +25,6 @@ */ #include "collectd.h" - #include "metric.h" #include "testing.h" @@ -260,10 +259,44 @@ DEF_TEST(metric_family_append) { return 0; } +DEF_TEST(metric_reset) { + struct { + value_t value; + } cases[] = { + { + .value.distribution = distribution_new_linear(10, 25), + }, + { + .value.distribution = distribution_new_exponential(10, 3, 2), + }, + { + .value.distribution = + distribution_new_custom(6, (double[]){5, 10, 20, 30, 50}), + }, + }; + + metric_family_t m_fam = { + .type = METRIC_TYPE_DISTRIBUTION, + }; + metric_family_t *metric_fam = &m_fam; + + for (size_t i = 0; i < (sizeof(cases) / sizeof(cases[0])); i++) { + printf("## Case %zu: \n", i); + + metric_t m = { + .family = metric_fam, + .value.distribution = cases[i].value.distribution, + }; + + EXPECT_EQ_INT(metric_reset(&m), 0); + } + return 0; +} + int main(void) { RUN_TEST(metric_label_set); RUN_TEST(metric_identity); RUN_TEST(metric_family_append); - + RUN_TEST(metric_reset); END_TEST; }