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