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 assert_int_equal(crm_get_msec("3.xs"), PCMK__PARSE_INT_DEFAULT);
24 assert_int_equal(crm_get_msec(" 3. xs "), PCMK__PARSE_INT_DEFAULT);
25 assert_int_equal(crm_get_msec("3.14xs"), PCMK__PARSE_INT_DEFAULT);
26 assert_int_equal(crm_get_msec(" 3.14 xs "), PCMK__PARSE_INT_DEFAULT);
27 }
28
29 static void
30 good_input(void **state) {
31 assert_int_equal(crm_get_msec("100"), 100000);
32 assert_int_equal(crm_get_msec(" 100 "), 100000);
33 assert_int_equal(crm_get_msec("\t100\n"), 100000);
34
35 assert_int_equal(crm_get_msec("100ms"), 100);
36 assert_int_equal(crm_get_msec(" 100 ms "), 100);
37 assert_int_equal(crm_get_msec("100 MSEC"), 100);
38 assert_int_equal(crm_get_msec("1000US"), 1);
39 assert_int_equal(crm_get_msec("1000usec"), 1);
40 assert_int_equal(crm_get_msec("12s"), 12000);
41 assert_int_equal(crm_get_msec("12 sec"), 12000);
42 assert_int_equal(crm_get_msec("1m"), 60000);
43 assert_int_equal(crm_get_msec("13 min"), 780000);
44 assert_int_equal(crm_get_msec("2\th"), 7200000);
45 assert_int_equal(crm_get_msec("1 hr"), 3600000);
46
47 assert_int_equal(crm_get_msec("3."), 3000);
48 assert_int_equal(crm_get_msec(" 3. ms "), 3);
49 assert_int_equal(crm_get_msec("3.14"), 3000);
50 assert_int_equal(crm_get_msec(" 3.14 ms "), 3);
51
52
53 assert_int_equal(crm_get_msec("3.14."), 3000);
54 assert_int_equal(crm_get_msec(" 3.14. ms "), 3);
55 assert_int_equal(crm_get_msec("3.14.159"), 3000);
56 assert_int_equal(crm_get_msec(" 3.14.159 "), 3000);
57 assert_int_equal(crm_get_msec("3.14.159ms"), 3);
58 assert_int_equal(crm_get_msec(" 3.14.159 ms "), 3);
59
60
61 assert_int_equal(crm_get_msec(" 100 mshr "), 100);
62 assert_int_equal(crm_get_msec(" 100 ms hr "), 100);
63 assert_int_equal(crm_get_msec(" 100 sasdf "), 100000);
64 assert_int_equal(crm_get_msec(" 100 s asdf "), 100000);
65 assert_int_equal(crm_get_msec(" 3.14 shour "), 3000);
66 assert_int_equal(crm_get_msec(" 3.14 s hour "), 3000);
67 assert_int_equal(crm_get_msec(" 3.14 ms!@#$ "), 3);
68 }
69
70 static void
71 overflow(void **state) {
72 assert_int_equal(crm_get_msec("9223372036854775807s"), LLONG_MAX);
73 }
74
75 PCMK__UNIT_TEST(NULL, NULL,
76 cmocka_unit_test(bad_input),
77 cmocka_unit_test(good_input),
78 cmocka_unit_test(overflow))