This source file includes following definitions.
- null_invalid
- nonnull_end_invalid
- no_id
- years_invalid
- all_valid
1
2
3
4
5
6
7
8
9
10 #include <crm_internal.h>
11
12 #include <glib.h>
13
14 #include <crm/common/unittest_internal.h>
15
16 #include <crm/common/iso8601.h>
17 #include <crm/common/xml.h>
18 #include "../../crmcommon_private.h"
19
20 #define MONTHS_TO_SECONDS "months=\"2\" weeks=\"3\" days=\"-1\" " \
21 "hours=\"1\" minutes=\"1\" seconds=\"1\" />"
22
23 #define ALL_VALID "<duration id=\"duration1\" years=\"1\" " MONTHS_TO_SECONDS
24
25 #define NO_ID "<duration years=\"1\" " MONTHS_TO_SECONDS
26
27 #define YEARS_INVALID "<duration id=\"duration1\" years=\"not-a-number\" " \
28 MONTHS_TO_SECONDS
29
30 static void
31 null_invalid(void **state)
32 {
33 xmlNode *duration = pcmk__xml_parse(ALL_VALID);
34 crm_time_t *start = crm_time_new("2024-01-01 15:00:00");
35 crm_time_t *end = NULL;
36
37 assert_int_equal(pcmk__unpack_duration(NULL, NULL, NULL), EINVAL);
38 assert_int_equal(pcmk__unpack_duration(duration, NULL, NULL), EINVAL);
39 assert_int_equal(pcmk__unpack_duration(duration, start, NULL), EINVAL);
40 assert_int_equal(pcmk__unpack_duration(duration, NULL, &end), EINVAL);
41 assert_int_equal(pcmk__unpack_duration(NULL, start, NULL), EINVAL);
42 assert_int_equal(pcmk__unpack_duration(NULL, start, &end), EINVAL);
43 assert_int_equal(pcmk__unpack_duration(NULL, NULL, &end), EINVAL);
44
45 crm_time_free(start);
46 free_xml(duration);
47 }
48
49 static void
50 nonnull_end_invalid(void **state)
51 {
52 xmlNode *duration = pcmk__xml_parse(ALL_VALID);
53 crm_time_t *start = crm_time_new("2024-01-01 15:00:00");
54 crm_time_t *end = crm_time_new("2024-01-01 15:00:01");
55
56 assert_int_equal(pcmk__unpack_duration(duration, start, &end), EINVAL);
57
58 crm_time_free(start);
59 crm_time_free(end);
60 free_xml(duration);
61 }
62
63 static void
64 no_id(void **state)
65 {
66 xmlNode *duration = pcmk__xml_parse(NO_ID);
67 crm_time_t *start = crm_time_new("2024-01-01 15:00:00");
68 crm_time_t *end = NULL;
69 crm_time_t *reference = crm_time_new("2025-03-21 16:01:01");
70
71 assert_int_equal(pcmk__unpack_duration(duration, start, &end), pcmk_rc_ok);
72 assert_int_equal(crm_time_compare(end, reference), 0);
73
74 crm_time_free(start);
75 crm_time_free(end);
76 crm_time_free(reference);
77 free_xml(duration);
78 }
79
80 static void
81 years_invalid(void **state)
82 {
83 xmlNode *duration = pcmk__xml_parse(YEARS_INVALID);
84 crm_time_t *start = crm_time_new("2024-01-01 15:00:00");
85 crm_time_t *end = NULL;
86 crm_time_t *reference = crm_time_new("2024-03-21 16:01:01");
87
88 assert_int_equal(pcmk__unpack_duration(duration, start, &end),
89 pcmk_rc_unpack_error);
90 assert_int_equal(crm_time_compare(end, reference), 0);
91
92 crm_time_free(start);
93 crm_time_free(end);
94 crm_time_free(reference);
95 free_xml(duration);
96 }
97
98 static void
99 all_valid(void **state)
100 {
101 xmlNode *duration = pcmk__xml_parse(ALL_VALID);
102 crm_time_t *start = crm_time_new("2024-01-01 15:00:00");
103 crm_time_t *end = NULL;
104 crm_time_t *reference = crm_time_new("2025-03-21 16:01:01");
105
106 assert_int_equal(pcmk__unpack_duration(duration, start, &end), pcmk_rc_ok);
107 assert_int_equal(crm_time_compare(end, reference), 0);
108
109 crm_time_free(start);
110 crm_time_free(end);
111 crm_time_free(reference);
112 free_xml(duration);
113 }
114
115 PCMK__UNIT_TEST(pcmk__xml_test_setup_group, pcmk__xml_test_teardown_group,
116 cmocka_unit_test(null_invalid),
117 cmocka_unit_test(nonnull_end_invalid),
118 cmocka_unit_test(no_id),
119 cmocka_unit_test(years_invalid),
120 cmocka_unit_test(all_valid))