root/lib/cluster/tests/cpg/pcmk_cpg_set_deliver_fn_test.c

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

DEFINITIONS

This source file includes following definitions.
  1. deliver_fn1
  2. deliver_fn2
  3. null_cluster
  4. null_fn
  5. previous_fn_null
  6. previous_fn_nonnull

   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 <stdint.h>                         // uint32_t
  13 #include <sys/types.h>                      // size_t
  14 
  15 #include <crm/cluster.h>                    // pcmk_cluster_t, etc.
  16 #include <crm/common/unittest_internal.h>
  17 
  18 #if SUPPORT_COROSYNC
  19 #include <corosync/cpg.h>                   // cpg_handle_t, struct cpg_name
  20 
  21 static void
  22 deliver_fn1(cpg_handle_t handle, const struct cpg_name *group_name,
     /* [previous][next][first][last][top][bottom][index][help] */
  23             uint32_t nodeid, uint32_t pid, void *msg, size_t msg_len)
  24 {
  25     return;
  26 }
  27 
  28 static void
  29 deliver_fn2(cpg_handle_t handle, const struct cpg_name *group_name,
     /* [previous][next][first][last][top][bottom][index][help] */
  30             uint32_t nodeid, uint32_t pid, void *msg, size_t msg_len)
  31 {
  32     return;
  33 }
  34 
  35 static void
  36 null_cluster(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  37 {
  38     assert_int_equal(pcmk_cpg_set_deliver_fn(NULL, NULL), EINVAL);
  39     assert_int_equal(pcmk_cpg_set_deliver_fn(NULL, deliver_fn1), EINVAL);
  40 }
  41 
  42 static void
  43 null_fn(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  44 {
  45     pcmk_cluster_t cluster = {
  46         .cpg = {
  47             .cpg_deliver_fn = NULL,
  48         },
  49     };
  50 
  51     assert_int_equal(pcmk_cpg_set_deliver_fn(&cluster, NULL), pcmk_rc_ok);
  52     assert_ptr_equal(cluster.cpg.cpg_deliver_fn, NULL);
  53 
  54     cluster.cpg.cpg_deliver_fn = deliver_fn1;
  55     assert_int_equal(pcmk_cpg_set_deliver_fn(&cluster, NULL), pcmk_rc_ok);
  56     assert_ptr_equal(cluster.cpg.cpg_deliver_fn, NULL);
  57 }
  58 
  59 static void
  60 previous_fn_null(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  61 {
  62     pcmk_cluster_t cluster = {
  63         .cpg = {
  64             .cpg_deliver_fn = NULL,
  65         },
  66     };
  67 
  68     assert_int_equal(pcmk_cpg_set_deliver_fn(&cluster, deliver_fn1),
  69                      pcmk_rc_ok);
  70     assert_ptr_equal(cluster.cpg.cpg_deliver_fn, deliver_fn1);
  71 }
  72 
  73 static void
  74 previous_fn_nonnull(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  75 {
  76     pcmk_cluster_t cluster = {
  77         .cpg = {
  78             .cpg_deliver_fn = deliver_fn2,
  79         },
  80     };
  81 
  82     assert_int_equal(pcmk_cpg_set_deliver_fn(&cluster, deliver_fn1),
  83                      pcmk_rc_ok);
  84     assert_ptr_equal(cluster.cpg.cpg_deliver_fn, deliver_fn1);
  85 }
  86 
  87 PCMK__UNIT_TEST(NULL, NULL,
  88                 cmocka_unit_test(null_cluster),
  89                 cmocka_unit_test(null_fn),
  90                 cmocka_unit_test(previous_fn_null),
  91                 cmocka_unit_test(previous_fn_nonnull))
  92 #else
  93 PCMK__UNIT_TEST(NULL, NULL)
  94 #endif  // SUPPORT_COROSYNC

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