This source file includes following definitions.
- bad_input
- good_input
- overflow
- main
1
2
3
4
5
6
7
8
9
10 #include <crm_internal.h>
11
12 #include <stdarg.h>
13 #include <stddef.h>
14 #include <stdint.h>
15 #include <setjmp.h>
16 #include <cmocka.h>
17
18 static void
19 bad_input(void **state) {
20 assert_int_equal(crm_get_msec(NULL), PCMK__PARSE_INT_DEFAULT);
21 assert_int_equal(crm_get_msec(" "), PCMK__PARSE_INT_DEFAULT);
22 assert_int_equal(crm_get_msec("abcxyz"), PCMK__PARSE_INT_DEFAULT);
23 assert_int_equal(crm_get_msec("100xs"), PCMK__PARSE_INT_DEFAULT);
24 assert_int_equal(crm_get_msec(" 100 xs "), PCMK__PARSE_INT_DEFAULT);
25 assert_int_equal(crm_get_msec("-100ms"), PCMK__PARSE_INT_DEFAULT);
26 }
27
28 static void
29 good_input(void **state) {
30 assert_int_equal(crm_get_msec("100"), 100000);
31 assert_int_equal(crm_get_msec(" 100 "), 100000);
32 assert_int_equal(crm_get_msec("\t100\n"), 100000);
33
34 assert_int_equal(crm_get_msec("100ms"), 100);
35 assert_int_equal(crm_get_msec("100 MSEC"), 100);
36 assert_int_equal(crm_get_msec("1000US"), 1);
37 assert_int_equal(crm_get_msec("1000usec"), 1);
38 assert_int_equal(crm_get_msec("12s"), 12000);
39 assert_int_equal(crm_get_msec("12 sec"), 12000);
40 assert_int_equal(crm_get_msec("1m"), 60000);
41 assert_int_equal(crm_get_msec("13 min"), 780000);
42 assert_int_equal(crm_get_msec("2\th"), 7200000);
43 assert_int_equal(crm_get_msec("1 hr"), 3600000);
44 }
45
46 static void
47 overflow(void **state) {
48 assert_int_equal(crm_get_msec("9223372036854775807s"), LLONG_MAX);
49 }
50
51 int
52 main(int argc, char **argv)
53 {
54 const struct CMUnitTest tests[] = {
55 cmocka_unit_test(bad_input),
56 cmocka_unit_test(good_input),
57 cmocka_unit_test(overflow),
58 };
59
60 cmocka_set_message_output(CM_OUTPUT_TAP);
61 return cmocka_run_group_tests(tests, NULL, NULL);
62 }