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

   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 <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) {
     /* [previous][next][first][last][top][bottom][index][help] */
  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) {
     /* [previous][next][first][last][top][bottom][index][help] */
  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) {
     /* [previous][next][first][last][top][bottom][index][help] */
  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) {
     /* [previous][next][first][last][top][bottom][index][help] */
  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) {
     /* [previous][next][first][last][top][bottom][index][help] */
  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) {
     /* [previous][next][first][last][top][bottom][index][help] */
  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) {
     /* [previous][next][first][last][top][bottom][index][help] */
  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) {
     /* [previous][next][first][last][top][bottom][index][help] */
  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) {
     /* [previous][next][first][last][top][bottom][index][help] */
  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) {
     /* [previous][next][first][last][top][bottom][index][help] */
  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) {
     /* [previous][next][first][last][top][bottom][index][help] */
  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) {
     /* [previous][next][first][last][top][bottom][index][help] */
  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) {
     /* [previous][next][first][last][top][bottom][index][help] */
  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) {
     /* [previous][next][first][last][top][bottom][index][help] */
  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) {
     /* [previous][next][first][last][top][bottom][index][help] */
 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) {
     /* [previous][next][first][last][top][bottom][index][help] */
 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) {
     /* [previous][next][first][last][top][bottom][index][help] */
 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))

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