root/lib/common/tests/iso8601/pcmk__set_time_if_earlier_test.c

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

DEFINITIONS

This source file includes following definitions.
  1. null_ok
  2. target_undefined
  3. source_earlier
  4. source_later

   1 /*
   2  * Copyright 2024 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 <crm/common/unittest_internal.h>
  13 
  14 #include <crm/common/iso8601.h>
  15 #include "../../crmcommon_private.h"
  16 
  17 static void
  18 null_ok(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  19 {
  20     crm_time_t *target = crm_time_new("2024-01-01 00:30:00 +01:00");
  21     crm_time_t *target_copy = pcmk_copy_time(target);
  22 
  23     // Should do nothing (just checking it doesn't assert or crash)
  24     pcmk__set_time_if_earlier(NULL, NULL);
  25     pcmk__set_time_if_earlier(NULL, target);
  26 
  27     // Shouldn't assert, crash, or change target
  28     pcmk__set_time_if_earlier(target, NULL);
  29     assert_int_equal(crm_time_compare(target, target_copy), 0);
  30 
  31     crm_time_free(target);
  32     crm_time_free(target_copy);
  33 }
  34 
  35 static void
  36 target_undefined(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  37 {
  38     crm_time_t *source = crm_time_new("2024-01-01 00:29:59 +01:00");
  39     crm_time_t *target = crm_time_new_undefined();
  40 
  41     pcmk__set_time_if_earlier(target, source);
  42     assert_int_equal(crm_time_compare(target, source), 0);
  43 
  44     crm_time_free(source);
  45     crm_time_free(target);
  46 }
  47 
  48 static void
  49 source_earlier(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  50 {
  51     crm_time_t *source = crm_time_new("2024-01-01 00:29:59 +01:00");
  52     crm_time_t *target = crm_time_new("2024-01-01 00:30:00 +01:00");
  53 
  54     pcmk__set_time_if_earlier(target, source);
  55     assert_int_equal(crm_time_compare(target, source), 0);
  56 
  57     crm_time_free(source);
  58     crm_time_free(target);
  59 }
  60 
  61 static void
  62 source_later(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  63 {
  64     crm_time_t *source = crm_time_new("2024-01-01 00:31:00 +01:00");
  65     crm_time_t *target = crm_time_new("2024-01-01 00:30:00 +01:00");
  66     crm_time_t *target_copy = pcmk_copy_time(target);
  67 
  68     pcmk__set_time_if_earlier(target, source);
  69     assert_int_equal(crm_time_compare(target, target_copy), 0);
  70 
  71     crm_time_free(source);
  72     crm_time_free(target);
  73     crm_time_free(target_copy);
  74 }
  75 
  76 PCMK__UNIT_TEST(NULL, NULL,
  77                 cmocka_unit_test(null_ok),
  78                 cmocka_unit_test(target_undefined),
  79                 cmocka_unit_test(source_earlier),
  80                 cmocka_unit_test(source_later))

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