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
- main
1
2
3
4
5
6
7
8
9
10 #include <glib.h>
11
12 #include <crm/common/xml.h>
13 #include <crm/pengine/rules_internal.h>
14
15 #include <stdarg.h>
16 #include <stddef.h>
17 #include <stdint.h>
18 #include <setjmp.h>
19 #include <cmocka.h>
20
21 static void
22 run_one_test(const char *t, const char *x, int expected) {
23 crm_time_t *tm = crm_time_new(t);
24 xmlNodePtr xml = string2xml(x);
25
26 assert_int_equal(pe_cron_range_satisfied(tm, xml), expected);
27
28 crm_time_free(tm);
29 free_xml(xml);
30 }
31
32 static void
33 no_time_given(void **state) {
34 assert_int_equal(pe_cron_range_satisfied(NULL, NULL), pcmk_rc_op_unsatisfied);
35 }
36
37 static void
38 any_time_satisfies_empty_spec(void **state) {
39 crm_time_t *tm = crm_time_new(NULL);
40
41 assert_int_equal(pe_cron_range_satisfied(tm, NULL), pcmk_rc_ok);
42
43 crm_time_free(tm);
44 }
45
46 static void
47 time_satisfies_year_spec(void **state) {
48 run_one_test("2020-01-01", "<date_spec id='spec' years='2020'/>", pcmk_rc_ok);
49 }
50
51 static void
52 time_after_year_spec(void **state) {
53 run_one_test("2020-01-01", "<date_spec id='spec' years='2019'/>", pcmk_rc_after_range);
54 }
55
56 static void
57 time_satisfies_year_range(void **state) {
58 run_one_test("2020-01-01", "<date_spec id='spec' years='2010-2030'/>", pcmk_rc_ok);
59 }
60
61 static void
62 time_before_year_range(void **state) {
63 run_one_test("2000-01-01", "<date_spec id='spec' years='2010-2030'/>", pcmk_rc_before_range);
64 }
65
66 static void
67 time_after_year_range(void **state) {
68 run_one_test("2020-01-01", "<date_spec id='spec' years='2010-2015'/>", pcmk_rc_after_range);
69 }
70
71 static void
72 range_without_start_year_passes(void **state) {
73 run_one_test("2010-01-01", "<date_spec id='spec' years='-2020'/>", pcmk_rc_ok);
74 }
75
76 static void
77 range_without_end_year_passes(void **state) {
78 run_one_test("2010-01-01", "<date_spec id='spec' years='2000-'/>", pcmk_rc_ok);
79 run_one_test("2000-10-01", "<date_spec id='spec' years='2000-'/>", pcmk_rc_ok);
80 }
81
82 static void
83 yeardays_satisfies(void **state) {
84 run_one_test("2020-01-30", "<date_spec id='spec' yeardays='30'/>", pcmk_rc_ok);
85 }
86
87 static void
88 time_after_yeardays_spec(void **state) {
89 run_one_test("2020-02-15", "<date_spec id='spec' yeardays='40'/>", pcmk_rc_after_range);
90 }
91
92 static void
93 yeardays_feb_29_satisfies(void **state) {
94 run_one_test("2016-02-29", "<date_spec id='spec' yeardays='60'/>", pcmk_rc_ok);
95 }
96
97 static void
98 exact_ymd_satisfies(void **state) {
99 run_one_test("2001-12-31", "<date_spec id='spec' years='2001' months='12' monthdays='31'/>", pcmk_rc_ok);
100 }
101
102 static void
103 range_in_month_satisfies(void **state) {
104 run_one_test("2001-06-10", "<date_spec id='spec' years='2001' months='6' monthdays='1-10'/>", pcmk_rc_ok);
105 }
106
107 static void
108 exact_ymd_after_range(void **state) {
109 run_one_test("2001-12-31", "<date_spec id='spec' years='2001' months='12' monthdays='30'/>", pcmk_rc_after_range);
110 }
111
112 static void
113 time_after_monthdays_range(void **state) {
114 run_one_test("2001-06-10", "<date_spec id='spec' years='2001' months='6' monthdays='11-15'/>", pcmk_rc_before_range);
115 }
116
117 int main(int argc, char **argv) {
118 const struct CMUnitTest tests[] = {
119 cmocka_unit_test(no_time_given),
120 cmocka_unit_test(any_time_satisfies_empty_spec),
121 cmocka_unit_test(time_satisfies_year_spec),
122 cmocka_unit_test(time_after_year_spec),
123 cmocka_unit_test(time_satisfies_year_range),
124 cmocka_unit_test(time_before_year_range),
125 cmocka_unit_test(time_after_year_range),
126 cmocka_unit_test(range_without_start_year_passes),
127 cmocka_unit_test(range_without_end_year_passes),
128
129 cmocka_unit_test(yeardays_satisfies),
130 cmocka_unit_test(time_after_yeardays_spec),
131 cmocka_unit_test(yeardays_feb_29_satisfies),
132
133 cmocka_unit_test(exact_ymd_satisfies),
134 cmocka_unit_test(range_in_month_satisfies),
135 cmocka_unit_test(exact_ymd_after_range),
136 cmocka_unit_test(time_after_monthdays_range),
137 };
138
139 cmocka_set_message_output(CM_OUTPUT_TAP);
140 return cmocka_run_group_tests(tests, NULL, NULL);
141 }