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-2022 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 General Public License version 2
   7  * or later (GPLv2+) WITHOUT ANY WARRANTY.
   8  */
   9 
  10 #include <crm_internal.h>
  11 
  12 #include <glib.h>
  13 
  14 #include <crm/msg_xml.h>
  15 #include <crm/common/unittest_internal.h>
  16 #include <crm/common/xml.h>
  17 #include <crm/pengine/rules_internal.h>
  18 
  19 static void
  20 run_one_test(const char *t, const char *x, int expected) {
     /* [previous][next][first][last][top][bottom][index][help] */
  21     crm_time_t *tm = crm_time_new(t);
  22     xmlNodePtr xml = string2xml(x);
  23 
  24     assert_int_equal(pe_cron_range_satisfied(tm, xml), expected);
  25 
  26     crm_time_free(tm);
  27     free_xml(xml);
  28 }
  29 
  30 static void
  31 no_time_given(void **state) {
     /* [previous][next][first][last][top][bottom][index][help] */
  32     assert_int_equal(pe_cron_range_satisfied(NULL, NULL), pcmk_rc_op_unsatisfied);
  33 }
  34 
  35 static void
  36 any_time_satisfies_empty_spec(void **state) {
     /* [previous][next][first][last][top][bottom][index][help] */
  37     crm_time_t *tm = crm_time_new(NULL);
  38 
  39     assert_int_equal(pe_cron_range_satisfied(tm, NULL), pcmk_rc_ok);
  40 
  41     crm_time_free(tm);
  42 }
  43 
  44 static void
  45 time_satisfies_year_spec(void **state) {
     /* [previous][next][first][last][top][bottom][index][help] */
  46     run_one_test("2020-01-01",
  47                  "<date_spec " XML_ATTR_ID "='spec' years='2020'/>",
  48                  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",
  54                  "<date_spec " XML_ATTR_ID "='spec' years='2019'/>",
  55                  pcmk_rc_after_range);
  56 }
  57 
  58 static void
  59 time_satisfies_year_range(void **state) {
     /* [previous][next][first][last][top][bottom][index][help] */
  60     run_one_test("2020-01-01",
  61                  "<date_spec " XML_ATTR_ID "='spec' years='2010-2030'/>",
  62                  pcmk_rc_ok);
  63 }
  64 
  65 static void
  66 time_before_year_range(void **state) {
     /* [previous][next][first][last][top][bottom][index][help] */
  67     run_one_test("2000-01-01",
  68                  "<date_spec " XML_ATTR_ID "='spec' years='2010-2030'/>",
  69                  pcmk_rc_before_range);
  70 }
  71 
  72 static void
  73 time_after_year_range(void **state) {
     /* [previous][next][first][last][top][bottom][index][help] */
  74     run_one_test("2020-01-01",
  75                  "<date_spec " XML_ATTR_ID "='spec' years='2010-2015'/>",
  76                  pcmk_rc_after_range);
  77 }
  78 
  79 static void
  80 range_without_start_year_passes(void **state) {
     /* [previous][next][first][last][top][bottom][index][help] */
  81     run_one_test("2010-01-01",
  82                  "<date_spec " XML_ATTR_ID "='spec' years='-2020'/>",
  83                  pcmk_rc_ok);
  84 }
  85 
  86 static void
  87 range_without_end_year_passes(void **state) {
     /* [previous][next][first][last][top][bottom][index][help] */
  88     run_one_test("2010-01-01",
  89                  "<date_spec " XML_ATTR_ID "='spec' years='2000-'/>",
  90                  pcmk_rc_ok);
  91     run_one_test("2000-10-01",
  92                  "<date_spec " XML_ATTR_ID "='spec' years='2000-'/>",
  93                  pcmk_rc_ok);
  94 }
  95 
  96 static void
  97 yeardays_satisfies(void **state) {
     /* [previous][next][first][last][top][bottom][index][help] */
  98     run_one_test("2020-01-30",
  99                  "<date_spec " XML_ATTR_ID "='spec' yeardays='30'/>",
 100                  pcmk_rc_ok);
 101 }
 102 
 103 static void
 104 time_after_yeardays_spec(void **state) {
     /* [previous][next][first][last][top][bottom][index][help] */
 105     run_one_test("2020-02-15",
 106                  "<date_spec " XML_ATTR_ID "='spec' yeardays='40'/>",
 107                  pcmk_rc_after_range);
 108 }
 109 
 110 static void
 111 yeardays_feb_29_satisfies(void **state) {
     /* [previous][next][first][last][top][bottom][index][help] */
 112     run_one_test("2016-02-29",
 113                  "<date_spec " XML_ATTR_ID "='spec' yeardays='60'/>",
 114                  pcmk_rc_ok);
 115 }
 116 
 117 static void
 118 exact_ymd_satisfies(void **state) {
     /* [previous][next][first][last][top][bottom][index][help] */
 119     run_one_test("2001-12-31",
 120                  "<date_spec " XML_ATTR_ID "='spec' years='2001' months='12' "
 121                  "monthdays='31'/>",
 122                  pcmk_rc_ok);
 123 }
 124 
 125 static void
 126 range_in_month_satisfies(void **state) {
     /* [previous][next][first][last][top][bottom][index][help] */
 127     run_one_test("2001-06-10",
 128                  "<date_spec " XML_ATTR_ID "='spec' years='2001' months='6' "
 129                  "monthdays='1-10'/>",
 130                  pcmk_rc_ok);
 131 }
 132 
 133 static void
 134 exact_ymd_after_range(void **state) {
     /* [previous][next][first][last][top][bottom][index][help] */
 135     run_one_test("2001-12-31",
 136                  "<date_spec " XML_ATTR_ID "='spec' years='2001' months='12' "
 137                  "monthdays='30'/>",
 138                  pcmk_rc_after_range);
 139 }
 140 
 141 static void
 142 time_after_monthdays_range(void **state) {
     /* [previous][next][first][last][top][bottom][index][help] */
 143     run_one_test("2001-06-10",
 144                  "<date_spec " XML_ATTR_ID "='spec' years='2001' months='6' "
 145                  "monthdays='11-15'/>",
 146                  pcmk_rc_before_range);
 147 }
 148 
 149 PCMK__UNIT_TEST(NULL, NULL,
 150                 cmocka_unit_test(no_time_given),
 151                 cmocka_unit_test(any_time_satisfies_empty_spec),
 152                 cmocka_unit_test(time_satisfies_year_spec),
 153                 cmocka_unit_test(time_after_year_spec),
 154                 cmocka_unit_test(time_satisfies_year_range),
 155                 cmocka_unit_test(time_before_year_range),
 156                 cmocka_unit_test(time_after_year_range),
 157                 cmocka_unit_test(range_without_start_year_passes),
 158                 cmocka_unit_test(range_without_end_year_passes),
 159                 cmocka_unit_test(yeardays_satisfies),
 160                 cmocka_unit_test(time_after_yeardays_spec),
 161                 cmocka_unit_test(yeardays_feb_29_satisfies),
 162                 cmocka_unit_test(exact_ymd_satisfies),
 163                 cmocka_unit_test(range_in_month_satisfies),
 164                 cmocka_unit_test(exact_ymd_after_range),
 165                 cmocka_unit_test(time_after_monthdays_range))

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