root/lib/cluster/tests/cluster/pcmk_cluster_set_destroy_fn_test.c

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

DEFINITIONS

This source file includes following definitions.
  1. destroy_fn1
  2. destroy_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 <glib.h>                           // gpointer
  13 
  14 #include <crm/cluster.h>                    // pcmk_cluster_t, etc.
  15 #include <crm/common/unittest_internal.h>
  16 
  17 static void
  18 destroy_fn1(gpointer arg)
     /* [previous][next][first][last][top][bottom][index][help] */
  19 {
  20     return;
  21 }
  22 
  23 static void
  24 destroy_fn2(gpointer arg)
     /* [previous][next][first][last][top][bottom][index][help] */
  25 {
  26     return;
  27 }
  28 
  29 static void
  30 null_cluster(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  31 {
  32     assert_int_equal(pcmk_cluster_set_destroy_fn(NULL, NULL), EINVAL);
  33     assert_int_equal(pcmk_cluster_set_destroy_fn(NULL, destroy_fn1), EINVAL);
  34 }
  35 
  36 static void
  37 null_fn(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  38 {
  39     pcmk_cluster_t cluster = {
  40         .destroy = NULL,
  41     };
  42 
  43     assert_int_equal(pcmk_cluster_set_destroy_fn(&cluster, NULL), pcmk_rc_ok);
  44     assert_ptr_equal(cluster.destroy, NULL);
  45 
  46     cluster.destroy = destroy_fn1;
  47     assert_int_equal(pcmk_cluster_set_destroy_fn(&cluster, NULL), pcmk_rc_ok);
  48     assert_ptr_equal(cluster.destroy, NULL);
  49 }
  50 
  51 static void
  52 previous_fn_null(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  53 {
  54     pcmk_cluster_t cluster = {
  55         .destroy = NULL,
  56     };
  57 
  58     assert_int_equal(pcmk_cluster_set_destroy_fn(&cluster, destroy_fn1),
  59                      pcmk_rc_ok);
  60     assert_ptr_equal(cluster.destroy, destroy_fn1);
  61 }
  62 
  63 static void
  64 previous_fn_nonnull(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  65 {
  66     pcmk_cluster_t cluster = {
  67         .destroy = destroy_fn2,
  68     };
  69 
  70     assert_int_equal(pcmk_cluster_set_destroy_fn(&cluster, destroy_fn1),
  71                      pcmk_rc_ok);
  72     assert_ptr_equal(cluster.destroy, destroy_fn1);
  73 }
  74 
  75 PCMK__UNIT_TEST(NULL, NULL,
  76                 cmocka_unit_test(null_cluster),
  77                 cmocka_unit_test(null_fn),
  78                 cmocka_unit_test(previous_fn_null),
  79                 cmocka_unit_test(previous_fn_nonnull))

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