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

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