This source file includes following definitions.
- bad_input
- good_input
- overflow
1
2
3
4
5
6
7
8
9
10 #include <crm_internal.h>
11
12 #include <crm/common/unittest_internal.h>
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))