This source file includes following definitions.
- run_one_test
- no_time_given
- any_time_satisfies_empty_spec
- time_satisfies_year_spec
- time_after_year_spec
- time_satisfies_year_range
- time_before_year_range
- time_after_year_range
- range_without_start_year_passes
- range_without_end_year_passes
- yeardays_satisfies
- time_after_yeardays_spec
- yeardays_feb_29_satisfies
- exact_ymd_satisfies
- range_in_month_satisfies
- exact_ymd_after_range
- time_after_monthdays_range
1
2
3
4
5
6
7
8
9
10 #include <crm_internal.h>
11
12 #include <glib.h>
13
14 #include <crm/msg_xml.h>
15 #include <crm/common/unittest_internal.h>
16 #include <crm/common/xml.h>
17 #include <crm/pengine/rules_internal.h>
18
19 static void
20 run_one_test(const char *t, const char *x, int expected) {
21 crm_time_t *tm = crm_time_new(t);
22 xmlNodePtr xml = string2xml(x);
23
24 assert_int_equal(pe_cron_range_satisfied(tm, xml), expected);
25
26 crm_time_free(tm);
27 free_xml(xml);
28 }
29
30 static void
31 no_time_given(void **state) {
32 assert_int_equal(pe_cron_range_satisfied(NULL, NULL), pcmk_rc_op_unsatisfied);
33 }
34
35 static void
36 any_time_satisfies_empty_spec(void **state) {
37 crm_time_t *tm = crm_time_new(NULL);
38
39 assert_int_equal(pe_cron_range_satisfied(tm, NULL), pcmk_rc_ok);
40
41 crm_time_free(tm);
42 }
43
44 static void
45 time_satisfies_year_spec(void **state) {
46 run_one_test("2020-01-01",
47 "<date_spec " XML_ATTR_ID "='spec' years='2020'/>",
48 pcmk_rc_ok);
49 }
50
51 static void
52 time_after_year_spec(void **state) {
53 run_one_test("2020-01-01",
54 "<date_spec " XML_ATTR_ID "='spec' years='2019'/>",
55 pcmk_rc_after_range);
56 }
57
58 static void
59 time_satisfies_year_range(void **state) {
60 run_one_test("2020-01-01",
61 "<date_spec " XML_ATTR_ID "='spec' years='2010-2030'/>",
62 pcmk_rc_ok);
63 }
64
65 static void
66 time_before_year_range(void **state) {
67 run_one_test("2000-01-01",
68 "<date_spec " XML_ATTR_ID "='spec' years='2010-2030'/>",
69 pcmk_rc_before_range);
70 }
71
72 static void
73 time_after_year_range(void **state) {
74 run_one_test("2020-01-01",
75 "<date_spec " XML_ATTR_ID "='spec' years='2010-2015'/>",
76 pcmk_rc_after_range);
77 }
78
79 static void
80 range_without_start_year_passes(void **state) {
81 run_one_test("2010-01-01",
82 "<date_spec " XML_ATTR_ID "='spec' years='-2020'/>",
83 pcmk_rc_ok);
84 }
85
86 static void
87 range_without_end_year_passes(void **state) {
88 run_one_test("2010-01-01",
89 "<date_spec " XML_ATTR_ID "='spec' years='2000-'/>",
90 pcmk_rc_ok);
91 run_one_test("2000-10-01",
92 "<date_spec " XML_ATTR_ID "='spec' years='2000-'/>",
93 pcmk_rc_ok);
94 }
95
96 static void
97 yeardays_satisfies(void **state) {
98 run_one_test("2020-01-30",
99 "<date_spec " XML_ATTR_ID "='spec' yeardays='30'/>",
100 pcmk_rc_ok);
101 }
102
103 static void
104 time_after_yeardays_spec(void **state) {
105 run_one_test("2020-02-15",
106 "<date_spec " XML_ATTR_ID "='spec' yeardays='40'/>",
107 pcmk_rc_after_range);
108 }
109
110 static void
111 yeardays_feb_29_satisfies(void **state) {
112 run_one_test("2016-02-29",
113 "<date_spec " XML_ATTR_ID "='spec' yeardays='60'/>",
114 pcmk_rc_ok);
115 }
116
117 static void
118 exact_ymd_satisfies(void **state) {
119 run_one_test("2001-12-31",
120 "<date_spec " XML_ATTR_ID "='spec' years='2001' months='12' "
121 "monthdays='31'/>",
122 pcmk_rc_ok);
123 }
124
125 static void
126 range_in_month_satisfies(void **state) {
127 run_one_test("2001-06-10",
128 "<date_spec " XML_ATTR_ID "='spec' years='2001' months='6' "
129 "monthdays='1-10'/>",
130 pcmk_rc_ok);
131 }
132
133 static void
134 exact_ymd_after_range(void **state) {
135 run_one_test("2001-12-31",
136 "<date_spec " XML_ATTR_ID "='spec' years='2001' months='12' "
137 "monthdays='30'/>",
138 pcmk_rc_after_range);
139 }
140
141 static void
142 time_after_monthdays_range(void **state) {
143 run_one_test("2001-06-10",
144 "<date_spec " XML_ATTR_ID "='spec' years='2001' months='6' "
145 "monthdays='11-15'/>",
146 pcmk_rc_before_range);
147 }
148
149 PCMK__UNIT_TEST(NULL, NULL,
150 cmocka_unit_test(no_time_given),
151 cmocka_unit_test(any_time_satisfies_empty_spec),
152 cmocka_unit_test(time_satisfies_year_spec),
153 cmocka_unit_test(time_after_year_spec),
154 cmocka_unit_test(time_satisfies_year_range),
155 cmocka_unit_test(time_before_year_range),
156 cmocka_unit_test(time_after_year_range),
157 cmocka_unit_test(range_without_start_year_passes),
158 cmocka_unit_test(range_without_end_year_passes),
159 cmocka_unit_test(yeardays_satisfies),
160 cmocka_unit_test(time_after_yeardays_spec),
161 cmocka_unit_test(yeardays_feb_29_satisfies),
162 cmocka_unit_test(exact_ymd_satisfies),
163 cmocka_unit_test(range_in_month_satisfies),
164 cmocka_unit_test(exact_ymd_after_range),
165 cmocka_unit_test(time_after_monthdays_range))