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 #include <glib.h>
2
3 #include <crm/common/xml.h>
4 #include <crm/pengine/rules_internal.h>
5
6 static void
7 run_one_test(const char *t, const char *x, int expected) {
8 crm_time_t *tm = crm_time_new(t);
9 xmlNodePtr xml = string2xml(x);
10
11 g_assert_cmpint(pe_cron_range_satisfied(tm, xml), ==, expected);
12
13 crm_time_free(tm);
14 xmlFreeNode(xml);
15 }
16
17 static void
18 no_time_given(void) {
19 g_assert_cmpint(pe_cron_range_satisfied(NULL, NULL), ==, pcmk_rc_op_unsatisfied);
20 }
21
22 static void
23 any_time_satisfies_empty_spec(void) {
24 crm_time_t *tm = crm_time_new(NULL);
25
26 g_assert_cmpint(pe_cron_range_satisfied(tm, NULL), ==, pcmk_rc_ok);
27
28 crm_time_free(tm);
29 }
30
31 static void
32 time_satisfies_year_spec(void) {
33 run_one_test("2020-01-01", "<date_spec id='spec' years='2020'/>", pcmk_rc_ok);
34 }
35
36 static void
37 time_after_year_spec(void) {
38 run_one_test("2020-01-01", "<date_spec id='spec' years='2019'/>", pcmk_rc_after_range);
39 }
40
41 static void
42 time_satisfies_year_range(void) {
43 run_one_test("2020-01-01", "<date_spec id='spec' years='2010-2030'/>", pcmk_rc_ok);
44 }
45
46 static void
47 time_before_year_range(void) {
48 run_one_test("2000-01-01", "<date_spec id='spec' years='2010-2030'/>", pcmk_rc_before_range);
49 }
50
51 static void
52 time_after_year_range(void) {
53 run_one_test("2020-01-01", "<date_spec id='spec' years='2010-2015'/>", pcmk_rc_after_range);
54 }
55
56 static void
57 range_without_start_year_passes(void) {
58 run_one_test("2010-01-01", "<date_spec id='spec' years='-2020'/>", pcmk_rc_ok);
59 }
60
61 static void
62 range_without_end_year_passes(void) {
63 run_one_test("2010-01-01", "<date_spec id='spec' years='2000-'/>", pcmk_rc_ok);
64 run_one_test("2000-10-01", "<date_spec id='spec' years='2000-'/>", pcmk_rc_ok);
65 }
66
67 static void
68 yeardays_satisfies(void) {
69 run_one_test("2020-01-30", "<date_spec id='spec' yeardays='30'/>", pcmk_rc_ok);
70 }
71
72 static void
73 time_after_yeardays_spec(void) {
74 run_one_test("2020-02-15", "<date_spec id='spec' yeardays='40'/>", pcmk_rc_after_range);
75 }
76
77 static void
78 yeardays_feb_29_satisfies(void) {
79 run_one_test("2016-02-29", "<date_spec id='spec' yeardays='60'/>", pcmk_rc_ok);
80 }
81
82 static void
83 exact_ymd_satisfies(void) {
84 run_one_test("2001-12-31", "<date_spec id='spec' years='2001' months='12' monthdays='31'/>", pcmk_rc_ok);
85 }
86
87 static void
88 range_in_month_satisfies(void) {
89 run_one_test("2001-06-10", "<date_spec id='spec' years='2001' months='6' monthdays='1-10'/>", pcmk_rc_ok);
90 }
91
92 static void
93 exact_ymd_after_range(void) {
94 run_one_test("2001-12-31", "<date_spec id='spec' years='2001' months='12' monthdays='30'/>", pcmk_rc_after_range);
95 }
96
97 static void
98 time_after_monthdays_range(void) {
99 run_one_test("2001-06-10", "<date_spec id='spec' years='2001' months='6' monthdays='11-15'/>", pcmk_rc_before_range);
100 }
101
102 int main(int argc, char **argv) {
103 g_test_init(&argc, &argv, NULL);
104
105 g_test_add_func("/pengine/rules/cron_range/no_time_given", no_time_given);
106 g_test_add_func("/pengine/rules/cron_range/empty_spec", any_time_satisfies_empty_spec);
107 g_test_add_func("/pengine/rules/cron_range/year/time_satisfies", time_satisfies_year_spec);
108 g_test_add_func("/pengine/rules/cron_range/year/time_after", time_after_year_spec);
109 g_test_add_func("/pengine/rules/cron_range/range/time_satisfies_year", time_satisfies_year_range);
110 g_test_add_func("/pengine/rules/cron_range/range/time_before_year", time_before_year_range);
111 g_test_add_func("/pengine/rules/cron_range/range/time_after_year", time_after_year_range);
112 g_test_add_func("/pengine/rules/cron_range/range/no_start_year_passes", range_without_start_year_passes);
113 g_test_add_func("/pengine/rules/cron_range/range/no_end_year_passes", range_without_end_year_passes);
114
115 g_test_add_func("/pengine/rules/cron_range/yeardays/satisfies", yeardays_satisfies);
116 g_test_add_func("/pengine/rules/cron_range/yeardays/time_after", time_after_yeardays_spec);
117 g_test_add_func("/pengine/rules/cron_range/yeardays/feb_29_sasitfies", yeardays_feb_29_satisfies);
118
119 g_test_add_func("/pengine/rules/cron_range/exact/ymd_satisfies", exact_ymd_satisfies);
120 g_test_add_func("/pengine/rules/cron_range/range/in_month_satisfies", range_in_month_satisfies);
121 g_test_add_func("/pengine/rules/cron_range/exact/ymd_after_range", exact_ymd_after_range);
122 g_test_add_func("/pengine/rules/cron_range/range/in_month_after", time_after_monthdays_range);
123 return g_test_run();
124 }