This source file includes following definitions.
- empty_arg
- invalid_arg
- overflow
- valid_arg
1
2
3
4
5
6
7
8
9
10 #include <crm_internal.h>
11
12 #include <crm/common/unittest_internal.h>
13
14 #include <crm/common/iso8601.h>
15 #include "crmcommon_private.h"
16
17 static void
18 empty_arg(void **state)
19 {
20 assert_null(crm_time_parse_duration(NULL));
21 assert_null(crm_time_parse_duration(""));
22 }
23
24 static void
25 invalid_arg(void **state)
26 {
27
28 assert_null(crm_time_parse_duration("X3Y6M4DT12H30M5S"));
29
30
31 assert_null(crm_time_parse_duration("P"));
32 assert_null(crm_time_parse_duration("P 3Y6M4DT12H30M5S"));
33 assert_null(crm_time_parse_duration("PX3Y6M4DT12H30M5S"));
34
35
36 assert_null(crm_time_parse_duration("P3Y6M4DT12H30M5"));
37 assert_null(crm_time_parse_duration("P3Y6M4DT12H30M5X"));
38 assert_null(crm_time_parse_duration("P3X6M4DT12H30M5S"));
39 assert_null(crm_time_parse_duration("PT"));
40 assert_null(crm_time_parse_duration("P/"));
41
42 #if 0
43
44
45
46 assert_null(crm_time_parse_duration("P6M3Y4DT12H30M5S"));
47 assert_null(crm_time_parse_duration("P6M3DT12HY430M5S"));
48
49
50 assert_null(crm_time_parse_duration("P6Y4M3D1MT12H30M5S"));
51
52
53 assert_null(crm_time_parse_duration("P6Y4M3W3D1MT12H30M5S"));
54 assert_null(crm_time_parse_duration("P3WT12H30M5S"));
55 #endif
56 }
57
58 static void
59 overflow(void **state)
60 {
61
62 assert_null(crm_time_parse_duration("P2147483648Y6M4DT12H30M5S"));
63 assert_null(crm_time_parse_duration("P3Y2147483648M4DT12H30M5S"));
64 assert_null(crm_time_parse_duration("P3Y6M2147483648DT12H30M5S"));
65 assert_null(crm_time_parse_duration("P3Y6M4DT2147483648H30M5S"));
66 assert_null(crm_time_parse_duration("P3Y6M4DT12H2147483648M5S"));
67 assert_null(crm_time_parse_duration("P3Y6M4DT12H30MP2147483648S"));
68
69
70 assert_null(crm_time_parse_duration("P-2147483648Y6M4DT12H30M5S"));
71 assert_null(crm_time_parse_duration("P3Y-2147483648M4DT12H30M5S"));
72 assert_null(crm_time_parse_duration("P3Y6M-2147483648DT12H30M5S"));
73 assert_null(crm_time_parse_duration("P3Y6M4DT-2147483648H30M5S"));
74 assert_null(crm_time_parse_duration("P3Y6M4DT12H-2147483648M5S"));
75 assert_null(crm_time_parse_duration("P3Y6M4DT12H30MP-2147483648S"));
76 }
77
78 static void
79 valid_arg(void **state)
80 {
81
82 assert_non_null(crm_time_parse_duration("P3Y6M4DT12H30M5S"));
83 assert_non_null(crm_time_parse_duration("P3Y6M4DT12H30M-5S"));
84 assert_non_null(crm_time_parse_duration("P3Y6M4DT12H-30M5S"));
85 assert_non_null(crm_time_parse_duration("P3Y6M4DT-12H30M5S"));
86 assert_non_null(crm_time_parse_duration("P3Y6M-4DT12H30M5S"));
87 assert_non_null(crm_time_parse_duration("P3Y-6M4DT12H30M5S"));
88 assert_non_null(crm_time_parse_duration("P3Y6M4DT12H30M"));
89 assert_non_null(crm_time_parse_duration("P3Y6M4D"));
90 assert_non_null(crm_time_parse_duration("P1M"));
91 assert_non_null(crm_time_parse_duration("PT1M"));
92 assert_non_null(crm_time_parse_duration("P7W"));
93
94 #if 0
95
96
97
98 assert_non_null(crm_time_parse_duration("P3Y6M4DT12H30.5M"));
99 assert_non_null(crm_time_parse_duration("P3Y6M4DT12H30,5M"));
100
101
102 assert_non_null(crm_time_parse_duration("P0003-02-01T11:10:09");
103 #endif
104 }
105
106 PCMK__UNIT_TEST(NULL, NULL,
107 cmocka_unit_test(empty_arg),
108 cmocka_unit_test(invalid_arg),
109 cmocka_unit_test(overflow),
110 cmocka_unit_test(valid_arg));