summaryrefslogtreecommitdiffstats
path: root/libnetdata/storage_number/tests/test_storage_number.c
blob: 19309e5c26b0c66d31e59f91928786cf6eb01d90 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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_printing(void **state)
{
    (void)state;

    char value[50];

    print_netdata_double(value, 0);
    assert_string_equal(value, "0");

    print_netdata_double(value, 0.0000001);
    assert_string_equal(value, "0.0000001");

    print_netdata_double(value, 0.00000009);
    assert_string_equal(value, "0.0000001");

    print_netdata_double(value, 0.000000001);
    assert_string_equal(value, "0");

    print_netdata_double(value, 99.99999999999999999);
    assert_string_equal(value, "100");

    print_netdata_double(value, -99.99999999999999999);
    assert_string_equal(value, "-100");

    print_netdata_double(value, 123.4567890123456789);
    assert_string_equal(value, "123.456789");

    print_netdata_double(value, 9999.9999999);
    assert_string_equal(value, "9999.9999999");

    print_netdata_double(value, -9999.9999999);
    assert_string_equal(value, "-9999.9999999");

    print_netdata_double(value, unpack_storage_number(pack_storage_number(16.777218L, SN_DEFAULT_FLAGS)));
    assert_string_equal(value, "16.77722");
}

int main(void)
{
    const struct CMUnitTest tests[] = {
        cmocka_unit_test(test_number_printing)
    };

    return cmocka_run_group_tests_name("storage_number", tests, NULL, NULL);
}