summaryrefslogtreecommitdiffstats
path: root/libnetdata/storage_number/tests
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 11:08:07 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 11:08:07 +0000
commitc69cb8cc094cc916adbc516b09e944cd3d137c01 (patch)
treef2878ec41fb6d0e3613906c6722fc02b934eeb80 /libnetdata/storage_number/tests
parentInitial commit. (diff)
downloadnetdata-c69cb8cc094cc916adbc516b09e944cd3d137c01.tar.xz
netdata-c69cb8cc094cc916adbc516b09e944cd3d137c01.zip
Adding upstream version 1.29.3.upstream/1.29.3upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'libnetdata/storage_number/tests')
-rw-r--r--libnetdata/storage_number/tests/Makefile.am4
-rw-r--r--libnetdata/storage_number/tests/test_storage_number.c52
2 files changed, 56 insertions, 0 deletions
diff --git a/libnetdata/storage_number/tests/Makefile.am b/libnetdata/storage_number/tests/Makefile.am
new file mode 100644
index 0000000..babdcf0
--- /dev/null
+++ b/libnetdata/storage_number/tests/Makefile.am
@@ -0,0 +1,4 @@
+# SPDX-License-Identifier: GPL-3.0-or-later
+
+AUTOMAKE_OPTIONS = subdir-objects
+MAINTAINERCLEANFILES = $(srcdir)/Makefile.in
diff --git a/libnetdata/storage_number/tests/test_storage_number.c b/libnetdata/storage_number/tests/test_storage_number.c
new file mode 100644
index 0000000..0e13208
--- /dev/null
+++ b/libnetdata/storage_number/tests/test_storage_number.c
@@ -0,0 +1,52 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+#include "../../libnetdata.h"
+#include "../../required_dummies.h"
+#include <setjmp.h>
+#include <cmocka.h>
+
+static void test_number_pinting(void **state)
+{
+ (void)state;
+
+ char value[50];
+
+ print_calculated_number(value, 0);
+ assert_string_equal(value, "0");
+
+ print_calculated_number(value, 0.0000001);
+ assert_string_equal(value, "0.0000001");
+
+ print_calculated_number(value, 0.00000009);
+ assert_string_equal(value, "0.0000001");
+
+ print_calculated_number(value, 0.000000001);
+ assert_string_equal(value, "0");
+
+ print_calculated_number(value, 99.99999999999999999);
+ assert_string_equal(value, "100");
+
+ print_calculated_number(value, -99.99999999999999999);
+ assert_string_equal(value, "-100");
+
+ print_calculated_number(value, 123.4567890123456789);
+ assert_string_equal(value, "123.456789");
+
+ print_calculated_number(value, 9999.9999999);
+ assert_string_equal(value, "9999.9999999");
+
+ print_calculated_number(value, -9999.9999999);
+ assert_string_equal(value, "-9999.9999999");
+
+ print_calculated_number(value, unpack_storage_number(pack_storage_number(16.777218L, SN_EXISTS)));
+ assert_string_equal(value, "16.77722");
+}
+
+int main(void)
+{
+ const struct CMUnitTest tests[] = {
+ cmocka_unit_test(test_number_pinting)
+ };
+
+ return cmocka_run_group_tests_name("storage_number", tests, NULL, NULL);
+}