|
| 1 | +// SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | + |
| 3 | +#include "../../libnetdata.h" |
| 4 | +#include "../../required_dummies.h" |
| 5 | +#include <setjmp.h> |
| 6 | +#include <cmocka.h> |
| 7 | + |
| 8 | +static void test_number_pinting(void **state) |
| 9 | +{ |
| 10 | + (void)state; |
| 11 | + |
| 12 | + char value[50]; |
| 13 | + |
| 14 | + print_calculated_number(value, 0); |
| 15 | + assert_string_equal(value, "0"); |
| 16 | + |
| 17 | + print_calculated_number(value, 0.0000001); |
| 18 | + assert_string_equal(value, "0.0000001"); |
| 19 | + |
| 20 | + print_calculated_number(value, 0.00000009); |
| 21 | + assert_string_equal(value, "0.0000001"); |
| 22 | + |
| 23 | + print_calculated_number(value, 0.000000001); |
| 24 | + assert_string_equal(value, "0"); |
| 25 | + |
| 26 | + print_calculated_number(value, 99.99999999999999999); |
| 27 | + assert_string_equal(value, "100"); |
| 28 | + |
| 29 | + print_calculated_number(value, -99.99999999999999999); |
| 30 | + assert_string_equal(value, "-100"); |
| 31 | + |
| 32 | + print_calculated_number(value, 123.4567890123456789); |
| 33 | + assert_string_equal(value, "123.456789"); |
| 34 | + |
| 35 | + print_calculated_number(value, 9999.9999999); |
| 36 | + assert_string_equal(value, "9999.9999999"); |
| 37 | + |
| 38 | + print_calculated_number(value, -9999.9999999); |
| 39 | + assert_string_equal(value, "-9999.9999999"); |
| 40 | +} |
| 41 | + |
| 42 | +int main(void) |
| 43 | +{ |
| 44 | + const struct CMUnitTest tests[] = { |
| 45 | + cmocka_unit_test(test_number_pinting) |
| 46 | + }; |
| 47 | + |
| 48 | + return cmocka_run_group_tests_name("storage_number", tests, NULL, NULL); |
| 49 | +} |
0 commit comments