root/lib/pengine/tests/rules/pe_cron_range_satisfied_test.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. run_one_test
  2. no_time_given
  3. any_time_satisfies_empty_spec
  4. time_satisfies_year_spec
  5. time_after_year_spec
  6. time_satisfies_year_range
  7. time_before_year_range
  8. time_after_year_range
  9. range_without_start_year_passes
  10. range_without_end_year_passes
  11. yeardays_satisfies
  12. time_after_yeardays_spec
  13. yeardays_feb_29_satisfies
  14. exact_ymd_satisfies
  15. range_in_month_satisfies
  16. exact_ymd_after_range
  17. time_after_monthdays_range
  18. main

   1 /*
   2  * Copyright 2020-2021 the Pacemaker project contributors
   3  *
   4  * The version control history for this file may have further details.
   5  *
   6  * This source code is licensed under the GNU Lesser General Public License
   7  * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY.
   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) {
     /* [previous][next][first][last][top][bottom][index][help] */
  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) {
     /* [previous][next][first][last][top][bottom][index][help] */
  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) {
     /* [previous][next][first][last][top][bottom][index][help] */
  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) {
     /* [previous][next][first][last][top][bottom][index][help] */
  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) {
     /* [previous][next][first][last][top][bottom][index][help] */
  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) {
     /* [previous][next][first][last][top][bottom][index][help] */
  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) {
     /* [previous][next][first][last][top][bottom][index][help] */
  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) {
     /* [previous][next][first][last][top][bottom][index][help] */
  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) {
     /* [previous][next][first][last][top][bottom][index][help] */
  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) {
     /* [previous][next][first][last][top][bottom][index][help] */
  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) {
     /* [previous][next][first][last][top][bottom][index][help] */
  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) {
     /* [previous][next][first][last][top][bottom][index][help] */
  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) {
     /* [previous][next][first][last][top][bottom][index][help] */
  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) {
     /* [previous][next][first][last][top][bottom][index][help] */
  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) {
     /* [previous][next][first][last][top][bottom][index][help] */
 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) {
     /* [previous][next][first][last][top][bottom][index][help] */
 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) {
     /* [previous][next][first][last][top][bottom][index][help] */
 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) {
     /* [previous][next][first][last][top][bottom][index][help] */
 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 }

/* [previous][next][first][last][top][bottom][index][help] */