pacemaker  2.1.7-0f7f88312f
Scalable High-Availability cluster resource manager
crm_get_msec_test.c
Go to the documentation of this file.
1 /*
2  * Copyright 2021 the Pacemaker project contributors
3  *
4  * The version control history for this file may have further details.
5  *
6  * This source code is licensed under the GNU General Public License version 2
7  * or later (GPLv2+) WITHOUT ANY WARRANTY.
8  */
9 
10 #include <crm_internal.h>
11 
13 
14 static void
15 bad_input(void **state) {
16  assert_int_equal(crm_get_msec(NULL), PCMK__PARSE_INT_DEFAULT);
17  assert_int_equal(crm_get_msec(" "), PCMK__PARSE_INT_DEFAULT);
18  assert_int_equal(crm_get_msec("abcxyz"), PCMK__PARSE_INT_DEFAULT);
19  assert_int_equal(crm_get_msec("100xs"), PCMK__PARSE_INT_DEFAULT);
20  assert_int_equal(crm_get_msec(" 100 xs "), PCMK__PARSE_INT_DEFAULT);
21  assert_int_equal(crm_get_msec("-100ms"), PCMK__PARSE_INT_DEFAULT);
22 }
23 
24 static void
25 good_input(void **state) {
26  assert_int_equal(crm_get_msec("100"), 100000);
27  assert_int_equal(crm_get_msec(" 100 "), 100000);
28  assert_int_equal(crm_get_msec("\t100\n"), 100000);
29 
30  assert_int_equal(crm_get_msec("100ms"), 100);
31  assert_int_equal(crm_get_msec("100 MSEC"), 100);
32  assert_int_equal(crm_get_msec("1000US"), 1);
33  assert_int_equal(crm_get_msec("1000usec"), 1);
34  assert_int_equal(crm_get_msec("12s"), 12000);
35  assert_int_equal(crm_get_msec("12 sec"), 12000);
36  assert_int_equal(crm_get_msec("1m"), 60000);
37  assert_int_equal(crm_get_msec("13 min"), 780000);
38  assert_int_equal(crm_get_msec("2\th"), 7200000);
39  assert_int_equal(crm_get_msec("1 hr"), 3600000);
40 }
41 
42 static void
43 overflow(void **state) {
44  assert_int_equal(crm_get_msec("9223372036854775807s"), LLONG_MAX);
45 }
46 
47 PCMK__UNIT_TEST(NULL, NULL,
48  cmocka_unit_test(bad_input),
49  cmocka_unit_test(good_input),
50  cmocka_unit_test(overflow))
long long crm_get_msec(const char *input)
Parse a time+units string and return milliseconds equivalent.
Definition: strings.c:364
PCMK__UNIT_TEST(NULL, NULL, cmocka_unit_test(bad_input), cmocka_unit_test(not_found), cmocka_unit_test(find_attrB), cmocka_unit_test(find_attrA_matching))
#define PCMK__PARSE_INT_DEFAULT